Timer
The mxos RTOS Timer API enables: system timer initialization, start, stop, and destroy functions.
The operating system has at least one timer for generating interrupts, performing task scheduling,
⊕ mxos-demos SDK를 참조한다.
1. Timer API
mxos_init_timer | Initialize an RTOS timer |
mxos_start_timer | Start an RTOS timer |
mxos_stop_timer | Stop a running RTOS timer |
mxos_reload_timer | Reload a desired RTOS timer |
mxos_deinit_timer | Destroy an RTOS timer |
mxos_is_timer_running | Query if an RTOS timer is running |
2. os_timer.c code
#include "mxos.h"
#define os_timer_log(M, ...) custom_log("OS", M, ##__VA_ARGS__)
mxos_timer_t timer_handle;
void destroy_timer( void );
void alarm( void* arg );
void destroy_timer( void )
{
mxos_stop_timer( &timer_handle );
mxos_deinit_timer( &timer_handle );
}
void alarm( void* arg )
{
int* count = (int*)arg;
os_timer_log("time is coming,value = %d", (*count)++ );
if( *count == 10 )
destroy_timer();
}
int application_start( void )
{
OSStatus err = kNoErr;
os_timer_log("timer demo");
int arg = 0;
err = mxos_init_timer(&timer_handle, 1000, alarm, &arg);
require_noerr(err, exit);
err = mxos_start_timer(&timer_handle);
require_noerr(err, exit);
mxos_thread_sleep( mxos_NEVER_TIMEOUT );
exit:
if( err != kNoErr )
os_timer_log( "Thread exit with err: %d", err );
mxos_rtos_delete_thread( NULL );
return err;
}
A timer interrupt of 1 second is created by creating and starting a system timer.
Each time an interrupt is incremented, the variable count is incremented by one until it is incremented to 10,
stopping the timer and destroying it.
♦ Main function code annotations:
1) Call the mxos API to create an RTOS timer: err = mxos_init_timer(&timer_handle, 1000, alarm, &arg);
2) Call the mxos API to start an RTOS timer: err = mxos_start_timer(&timer_handle);
3) Call the mxos API to stop an RTOS timer: mxos_stop_timer( &timer_handle );
4) Call the mxos API to destroy an RTOS timer: mxos_deinit_timer( &timer_handle );
이상 끝 ~~~