Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
stm32_libraries
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
humanoides
tools
stm32_libraries
Commits
b33a2e4e
Commit
b33a2e4e
authored
8 years ago
by
Sergi Hernandez
Browse files
Options
Downloads
Patches
Plain Diff
Added documentation for the stm32_time module.
parent
89b2841b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
utils/include/stm32_time.h
+149
-0
149 additions, 0 deletions
utils/include/stm32_time.h
with
149 additions
and
0 deletions
utils/include/stm32_time.h
+
149
−
0
View file @
b33a2e4e
/** @file */
#ifndef _STM32_TIME_H
#ifndef _STM32_TIME_H
#define _STM32_TIME_H
#define _STM32_TIME_H
/**
* \brief Structure to handle blocking time delays and timeouts using a timer
*
* This structure is a wrapper around any timer in order to handle time delays
* and timeouts in a unified way. This structure requires a function to get the
* accumulated number of counts of a timer and the number of timer counts per
* micro-second of the timer.
*
* A single structure can only be used to handle a single timeout or delay,
* but several structures can share a single timer without any performance
* decrease.
*
* A time structure is first initialized by calling the time_init() function.
* Using this structure, it is possible to implement delays in
* seconds (time_delay_s()), milli-seconds (time_delay_ms()) and micro-seconds
* (time_delay_us()), and also start (time_set_timeout()) and cancel
* (time_cancel_timeout()) timeout, as well as checks its status (time_is_timeout()).
*
*/
typedef
struct
typedef
struct
{
{
/**
* \brief Target number of timer counts for the delay or timeout
*
* Absolute number of timer counts that must be reached to unblock any of the
* delay functions or activate the timeout feature. This value is internally
* computed taking into account the current number of counts and the desired
* time when any of the following functions are called:
* * time_set_timeout()
* * time_delay_s()
* * time_delay_ms()
* * time_delay_us()
*
*/
unsigned
long
long
int
target_time
;
unsigned
long
long
int
target_time
;
/**
* \brief Number of timer counts per each micro-second
*
* This parameter holds the number of timer counts per each micro-second. This
* parameter depends on the configuration of the associated timer and its value
* must be provided when calling the time_init() function. This value should not
* be modified afterwards.
*
*/
int
counts_per_us
;
int
counts_per_us
;
/**
* \brief Function pointer to get the accumulated number of counts of the timer
*
* The associated timer must provide a function which does not accept any parameters
* and returns the accumulated number of timer counts since the last reset as an
* unsigned long long variable (8 bytes in most architectures).
*
* This pointer must be provided at initilaization time when the time_init() function
* is called, and should not be modified afterwards.
*
*/
unsigned
long
long
int
(
*
get_time
)(
void
);
unsigned
long
long
int
(
*
get_time
)(
void
);
}
TTime
;
}
TTime
;
/* public functions */
/* public functions */
/**
* \brief Function to initialize a time structure
*
* This function initializes a time structure. This function must be called before
* calling any other function.
*
* \param time pointer to a valid TTime structure to be initialized. If
* memory is not pre-allocated before calling this function, its
* behavior is unpredictable.
* \param counts_per_us number of timer counts per micro-second. This value
* must coincide with the actual value of the associated timer.
* \param get_time pointer to a function to get the accumulated number of
* timer counts since the last reset. This function must be implemented
* by the associated timer module.
*/
void
time_init
(
TTime
*
time
,
int
counts_per_us
,
unsigned
long
long
int
(
*
get_time
)(
void
));
void
time_init
(
TTime
*
time
,
int
counts_per_us
,
unsigned
long
long
int
(
*
get_time
)(
void
));
/**
* \brief Function to set the desired timeout in micro-seconds
*
* This functions sets the desired time to generate a timeout event if it is not
* canceller by the time_cancel_timeout() function. After calling this function,
* the time_is_timeout() function will return true if the current time is past
* the time when this function was called plus the desired timeout value.
*
* If this function is called when there is an active timeout, the timeout
* condition is updated by the provided timeout value. This function activates
* the timeout, but it does not block. The time_is_timeout() function should be
* be used to check the state of the timeout, and the time_cancel_timeout()
* function to cancel it.
*
* \param time pointer to a valid TTime structure to be initialized. If
* memory is not pre-allocated before calling this function, its
* behavior is unpredictable.
* \param timeout_us value of the desired timeout in micro-seconds.
*/
void
time_set_timeout
(
TTime
*
time
,
long
int
timeout_us
);
void
time_set_timeout
(
TTime
*
time
,
long
int
timeout_us
);
/**
* \brief Function to check if the desired time has elapsed
*
* This function checks whether the current time is past the time when the
* time_set_timeout() function was called plus the desired timeout or not.
* If this function will always return false if it is called when no timeout
* has been activated by calling the time_set_timeout()
*
* \param time pointer to a valid TTime structure to be initialized. If
* memory is not pre-allocated before calling this function, its
* behavior is unpredictable.
*
* \return true if the timeout condition is active of false if the timeout
* is not yet active or there is no timeout active.
*/
unsigned
char
time_is_timeout
(
TTime
*
time
);
unsigned
char
time_is_timeout
(
TTime
*
time
);
/**
* \brief Function to cancel the current timeout
*
* This function cancels any timeout condition currently active. If no timeout
* is active when this function is called, nothing happens.
*
* \param time pointer to a valid TTime structure to be initialized. If
* memory is not pre-allocated before calling this function, its
* behavior is unpredictable.
*/
void
time_cancel_timeout
(
TTime
*
time
);
void
time_cancel_timeout
(
TTime
*
time
);
/**
* \brief Function to wait a given time in micro-seconds
*
* This function blocks until the specifierd time in micro-seconds has elapsed.
* If this function is called when there is an active timeout, the timeout is
* automatically cancelled.
*
* \param time pointer to a valid TTime structure to be initialized. If
* memory is not pre-allocated before calling this function, its
* behavior is unpredictable.
* \param delay_us value of the desired delay in micro-seconds
*/
void
time_delay_us
(
TTime
*
time
,
int
delay_us
);
void
time_delay_us
(
TTime
*
time
,
int
delay_us
);
/**
* \brief Function to wait a given time in milli-seconds
*
* This function blocks until the specifierd time in milli-seconds has elapsed.
* If this function is called when there is an active timeout, the timeout is
* automatically cancelled.
*
* \param time pointer to a valid TTime structure to be initialized. If
* memory is not pre-allocated before calling this function, its
* behavior is unpredictable.
* \param delay_ms value of the desired delay in milli-seconds
*/
void
time_delay_ms
(
TTime
*
time
,
int
delay_ms
);
void
time_delay_ms
(
TTime
*
time
,
int
delay_ms
);
/**
* \brief Function to wait a given time in seconds
*
* This function blocks until the specifierd time in seconds has elapsed.
* If this function is called when there is an active timeout, the timeout is
* automatically cancelled.
*
* \param time pointer to a valid TTime structure to be initialized. If
* memory is not pre-allocated before calling this function, its
* behavior is unpredictable.
* \param delay_s value of the desired delay in seconds
*/
void
time_delay_s
(
TTime
*
time
,
int
delay_s
);
void
time_delay_s
(
TTime
*
time
,
int
delay_s
);
#endif
#endif
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment