Definition in file cycle_counter.h.
#include "compiler.h"
Go to the source code of this file.
Data Structures | |
struct | t_cpu_time |
Structure holding private information, automatically initialized by the cpu_set_timeout() function. More... | |
Defines | |
#define | CPU_TIMER_STATE_REACHED 1 |
#define | CPU_TIMER_STATE_STARTED 0 |
#define | CPU_TIMER_STATE_STOPPED 2 |
#define | Get_sys_compare() ( Get_system_register(AVR32_COMPARE) ) |
#define | Get_sys_count() ( Get_system_register(AVR32_COUNT) ) |
#define | Set_sys_compare(x) ( Set_system_register(AVR32_COMPARE, (x)) ) |
#define | Set_sys_count(x) ( Set_system_register(AVR32_COUNT, (x)) ) |
Functions | |
__inline__ U32 | cpu_cy_2_ms (unsigned long cy, unsigned long fcpu_hz) |
Convert CPU cycles into milli-seconds. | |
__inline__ U32 | cpu_cy_2_us (unsigned long cy, unsigned long fcpu_hz) |
Convert CPU cycles into micro-seconds. | |
__inline__ void | cpu_delay_cy (unsigned long delay) |
Waits during at least the specified delay (in CPU cycles) before returning. | |
__inline__ void | cpu_delay_ms (unsigned long delay, unsigned long fcpu_hz) |
Waits during at least the specified delay (in millisecond) before returning. | |
__inline__ void | cpu_delay_us (unsigned long delay, unsigned long fcpu_hz) |
Waits during at least the specified delay (in microsecond) before returning. | |
__inline__ unsigned long | cpu_is_timeout (t_cpu_time *cpu_time) |
Test if a timer variable reached its timeout. | |
__inline__ unsigned long | cpu_is_timer_stopped (t_cpu_time *cpu_time) |
Test if a timer is stopped. | |
__inline__ U32 | cpu_ms_2_cy (unsigned long ms, unsigned long fcpu_hz) |
Convert milli-seconds into CPU cycles. | |
__inline__ void | cpu_set_timeout (unsigned long delay, t_cpu_time *cpu_time) |
Set a timer variable. | |
__inline__ void | cpu_stop_timeout (t_cpu_time *cpu_time) |
Stop a timeout detection. | |
__inline__ U32 | cpu_us_2_cy (unsigned long us, unsigned long fcpu_hz) |
Convert micro-seconds into CPU cycles. |
#define CPU_TIMER_STATE_REACHED 1 |
#define CPU_TIMER_STATE_STARTED 0 |
#define CPU_TIMER_STATE_STOPPED 2 |
Definition at line 66 of file cycle_counter.h.
Referenced by cpu_is_timeout(), cpu_is_timer_stopped(), and cpu_stop_timeout().
#define Get_sys_compare | ( | ) | ( Get_system_register(AVR32_COMPARE) ) |
#define Get_sys_count | ( | ) | ( Get_system_register(AVR32_COUNT) ) |
#define Set_sys_compare | ( | x | ) | ( Set_system_register(AVR32_COMPARE, (x)) ) |
#define Set_sys_count | ( | x | ) | ( Set_system_register(AVR32_COUNT, (x)) ) |
Definition at line 302 of file cycle_counter.h.
__inline__ U32 cpu_cy_2_ms | ( | unsigned long | cy, | |
unsigned long | fcpu_hz | |||
) |
Convert CPU cycles into milli-seconds.
cy,: | Number of CPU cycles. | |
fcpu_hz,: | CPU frequency in Hz. |
Definition at line 115 of file cycle_counter.h.
__inline__ U32 cpu_cy_2_us | ( | unsigned long | cy, | |
unsigned long | fcpu_hz | |||
) |
Convert CPU cycles into micro-seconds.
cy,: | Number of CPU cycles. | |
fcpu_hz,: | CPU frequency in Hz. |
Definition at line 132 of file cycle_counter.h.
__inline__ void cpu_delay_cy | ( | unsigned long | delay | ) |
Waits during at least the specified delay (in CPU cycles) before returning.
delay,: | Number of CPU cycles to wait. |
Definition at line 293 of file cycle_counter.h.
References cpu_is_timeout(), and cpu_set_timeout().
00294 { 00295 t_cpu_time timer; 00296 cpu_set_timeout( delay, &timer); 00297 while( !cpu_is_timeout(&timer) ); 00298 }
__inline__ void cpu_delay_ms | ( | unsigned long | delay, | |
unsigned long | fcpu_hz | |||
) |
Waits during at least the specified delay (in millisecond) before returning.
delay,: | Number of millisecond to wait. | |
fcpu_hz,: | CPU frequency in Hz. |
Definition at line 262 of file cycle_counter.h.
References cpu_is_timeout(), cpu_ms_2_cy(), and cpu_set_timeout().
00263 { 00264 t_cpu_time timer; 00265 cpu_set_timeout( cpu_ms_2_cy(delay, fcpu_hz), &timer); 00266 while( !cpu_is_timeout(&timer) ); 00267 }
__inline__ void cpu_delay_us | ( | unsigned long | delay, | |
unsigned long | fcpu_hz | |||
) |
Waits during at least the specified delay (in microsecond) before returning.
delay,: | Number of microsecond to wait. | |
fcpu_hz,: | CPU frequency in Hz. |
Definition at line 278 of file cycle_counter.h.
References cpu_is_timeout(), cpu_set_timeout(), and cpu_us_2_cy().
00279 { 00280 t_cpu_time timer; 00281 cpu_set_timeout( cpu_us_2_cy(delay, fcpu_hz), &timer); 00282 while( !cpu_is_timeout(&timer) ); 00283 }
__inline__ unsigned long cpu_is_timeout | ( | t_cpu_time * | cpu_time | ) |
Test if a timer variable reached its timeout.
Once the timeout is reached, the function will always return TRUE, until the cpu_stop_timeout() function is called.
Ex: t_cpu_time timer; cpu_set_timeout( 10, FOSC0, &timer ); // timeout in 10 ms if( cpu_is_timeout(&timer) ) cpu_stop_timeout(&timer); ../..
cpu_time,: | (input) internal information used by the timer API. |
Definition at line 180 of file cycle_counter.h.
References CPU_TIMER_STATE_REACHED, CPU_TIMER_STATE_STOPPED, t_cpu_time::delay_end_cycle, t_cpu_time::delay_start_cycle, and t_cpu_time::timer_state.
Referenced by cpu_delay_cy(), cpu_delay_ms(), and cpu_delay_us().
00181 { 00182 unsigned long current_cycle_count = Get_system_register(AVR32_COUNT); 00183 00184 if( cpu_time->timer_state==CPU_TIMER_STATE_STOPPED ) 00185 return FALSE; 00186 00187 // Test if the timeout as already occured. 00188 else if (cpu_time->timer_state == CPU_TIMER_STATE_REACHED) 00189 return TRUE; 00190 00191 // If the ending cycle count of this timeout is wrapped, ... 00192 else if (cpu_time->delay_start_cycle > cpu_time->delay_end_cycle) 00193 { 00194 if (current_cycle_count < cpu_time->delay_start_cycle && current_cycle_count > cpu_time->delay_end_cycle) 00195 { 00196 cpu_time->timer_state = CPU_TIMER_STATE_REACHED; 00197 return TRUE; 00198 } 00199 return FALSE; 00200 } 00201 else 00202 { 00203 if (current_cycle_count < cpu_time->delay_start_cycle || current_cycle_count > cpu_time->delay_end_cycle) 00204 { 00205 cpu_time->timer_state = CPU_TIMER_STATE_REACHED; 00206 return TRUE; 00207 } 00208 return FALSE; 00209 } 00210 }
__inline__ unsigned long cpu_is_timer_stopped | ( | t_cpu_time * | cpu_time | ) |
Test if a timer is stopped.
cpu_time,: | (input) internal information used by the timer API. |
Definition at line 243 of file cycle_counter.h.
References CPU_TIMER_STATE_STOPPED, and t_cpu_time::timer_state.
00244 { 00245 00246 if( cpu_time->timer_state==CPU_TIMER_STATE_STOPPED ) 00247 return TRUE; 00248 else 00249 return FALSE; 00250 }
__inline__ U32 cpu_ms_2_cy | ( | unsigned long | ms, | |
unsigned long | fcpu_hz | |||
) |
Convert milli-seconds into CPU cycles.
ms,: | Number of millisecond. | |
fcpu_hz,: | CPU frequency in Hz. |
Definition at line 81 of file cycle_counter.h.
Referenced by cpu_delay_ms().
__inline__ void cpu_set_timeout | ( | unsigned long | delay, | |
t_cpu_time * | cpu_time | |||
) |
Set a timer variable.
Ex: t_cpu_time timer; cpu_set_timeout( cpu_ms_2_cy(10, FOSC0), &timer ); // timeout in 10 ms if( cpu_is_timeout(&timer) ) cpu_stop_timeout(&timer); ../..
delay,: | (input) delay in CPU cycles before timeout. | |
cpu_time,: | (output) internal information used by the timer API. |
Definition at line 153 of file cycle_counter.h.
References CPU_TIMER_STATE_STARTED, t_cpu_time::delay_end_cycle, t_cpu_time::delay_start_cycle, and t_cpu_time::timer_state.
Referenced by cpu_delay_cy(), cpu_delay_ms(), and cpu_delay_us().
00154 { 00155 cpu_time->delay_start_cycle = Get_system_register(AVR32_COUNT); 00156 cpu_time->delay_end_cycle = cpu_time->delay_start_cycle + delay; 00157 cpu_time->timer_state = CPU_TIMER_STATE_STARTED; 00158 }
__inline__ void cpu_stop_timeout | ( | t_cpu_time * | cpu_time | ) |
Stop a timeout detection.
Ex: t_cpu_time timer; cpu_set_timeout( 10, FOSC0, &timer ); // timeout in 10 ms if( cpu_is_timeout(&timer) ) cpu_stop_timeout(&timer); ../..
cpu_time,: | (input) internal information used by the timer API. |
Definition at line 227 of file cycle_counter.h.
References CPU_TIMER_STATE_STOPPED, and t_cpu_time::timer_state.
00228 { 00229 cpu_time->timer_state = CPU_TIMER_STATE_STOPPED; 00230 }
__inline__ U32 cpu_us_2_cy | ( | unsigned long | us, | |
unsigned long | fcpu_hz | |||
) |
Convert micro-seconds into CPU cycles.
us,: | Number of microsecond. | |
fcpu_hz,: | CPU frequency in Hz. |
Definition at line 98 of file cycle_counter.h.
Referenced by cpu_delay_us().