Add the timer value wraparound processing to common wait processing

Timer value wraparound operation had not been considered in common wait process.
By defining the EXPIRE_US non-zero value, wraparound operation is enabled.
The EXPIRE_US will be define the value of each vender-specific.
If EXPIRE_US is 0, the common wait process is same as before.
pull/782/head
Masao Hamanaka 2014-12-11 14:32:09 +09:00
parent 2e1ba4df65
commit cd8f65c94b
2 changed files with 21 additions and 3 deletions

View File

@ -16,6 +16,12 @@
#include "wait_api.h" #include "wait_api.h"
#include "us_ticker_api.h" #include "us_ticker_api.h"
#if defined(TARGET_RZ_A1H)
#define EXPIRE_US (128849020)
#else
#define EXPIRE_US (0)
#endif
void wait(float s) { void wait(float s) {
wait_us(s * 1000000.0f); wait_us(s * 1000000.0f);
} }
@ -26,5 +32,17 @@ void wait_ms(int ms) {
void wait_us(int us) { void wait_us(int us) {
uint32_t start = us_ticker_read(); uint32_t start = us_ticker_read();
while ((us_ticker_read() - start) < (uint32_t)us); uint32_t expire_time = 0;
uint32_t now;
#if (EXPIRE_US > 0)
uint32_t last = start;
#endif
do {
now = us_ticker_read();
#if (EXPIRE_US > 0)
if ( last > now ) expire_time += EXPIRE_US;
last = now;
#endif
} while ((now + expire_time - start) < (uint32_t)us);
} }

View File

@ -39,9 +39,9 @@ void us_ticker_init(void) {
/* set Counter Clock(us) */ /* set Counter Clock(us) */
if (false == RZ_A1_IsClockMode0()) { if (false == RZ_A1_IsClockMode0()) {
count_clock = (double)(CM1_RENESAS_RZ_A1_P0_CLK / US_TICKER_CLOCK_US_DEV); count_clock = ((double)CM1_RENESAS_RZ_A1_P0_CLK / (double)US_TICKER_CLOCK_US_DEV);
} else { } else {
count_clock = (double)(CM0_RENESAS_RZ_A1_P0_CLK / US_TICKER_CLOCK_US_DEV); count_clock = ((double)CM0_RENESAS_RZ_A1_P0_CLK / (double)US_TICKER_CLOCK_US_DEV);
} }
/* Power Control for Peripherals */ /* Power Control for Peripherals */