diff options
Diffstat (limited to 'os/hal')
-rw-r--r-- | os/hal/ports/TIVA/LLD/st_lld.c | 6 | ||||
-rw-r--r-- | os/hal/ports/TIVA/LLD/st_lld.h | 82 |
2 files changed, 54 insertions, 34 deletions
diff --git a/os/hal/ports/TIVA/LLD/st_lld.c b/os/hal/ports/TIVA/LLD/st_lld.c index 6e83c10..6b47503 100644 --- a/os/hal/ports/TIVA/LLD/st_lld.c +++ b/os/hal/ports/TIVA/LLD/st_lld.c @@ -73,8 +73,8 @@ #warning "WGPT5" #define ST_HANDLER TIVA_WGPT5A_HANDLER #define ST_NUMBER TIVA_WGPT5A_NUMBER -//#define ST_CLOCK_SRC (80000000) -#define ST_CLOCK_SRC (16000000) +#define ST_CLOCK_SRC (80000000) +//#define ST_CLOCK_SRC (16000000) #define ST_ENABLE_CLOCK() (SYSCTL->RCGCWTIMER |= (1 << 5)) #else @@ -203,7 +203,7 @@ OSAL_IRQ_HANDLER(ST_HANDLER) OSAL_IRQ_PROLOGUE(); mis = TIVA_ST_TIM->MIS; - TIVA_ST_TIM->ICR = 0xffffffff; + TIVA_ST_TIM->ICR = mis; if (mis & GPTM_IMR_TATOIM) { temp = 3; diff --git a/os/hal/ports/TIVA/LLD/st_lld.h b/os/hal/ports/TIVA/LLD/st_lld.h index 49bd91d..0db601a 100644 --- a/os/hal/ports/TIVA/LLD/st_lld.h +++ b/os/hal/ports/TIVA/LLD/st_lld.h @@ -77,7 +77,7 @@ #if OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING -#error "Tickless system tick mode is not working yet! Please use the periodic system tick mode." +//#error "Tickless system tick mode is not working yet! Please use the periodic system tick mode." #if (TIVA_ST_USE_WIDE_TIMER == TRUE) @@ -193,6 +193,9 @@ extern "C" { /* Driver inline functions. */ /*===========================================================================*/ +#define OSAL_ST_FREQUENCY 10000 +#define ST_CLOCK_SRC 80000000 + /** * @brief Returns the time counter value. * @@ -203,7 +206,8 @@ extern "C" { static inline systime_t st_lld_get_counter(void) { #if OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING - return (systime_t) TIVA_ST_TIM->TAV; + return (systime_t) TIVA_ST_TIM->TAV/((ST_CLOCK_SRC / OSAL_ST_FREQUENCY) - 1); + //return (systime_t) ((TIVA_ST_TIM->TAV >> 16) | (TIVA_ST_TIM->TAPV << 16))/((ST_CLOCK_SRC / OSAL_ST_FREQUENCY) - 1); #else return (systime_t) 0; #endif @@ -221,17 +225,25 @@ static inline systime_t st_lld_get_counter(void) static inline void st_lld_start_alarm(systime_t time) { #if OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING - uint64_t temp; - - temp = (uint64_t) time * TIVA_ST_TIM_PRESCALER; - - TIVA_ST_TIM->TAMATCHR = (uint32_t) temp; - - temp = temp >> 32; - - TIVA_ST_TIM->TAPMR = (uint16_t) temp; - - TIVA_ST_TIM->ICR = 0xffffffff; +// uint64_t temp; +// +// temp = (uint64_t) time * TIVA_ST_TIM_PRESCALER; +// +// TIVA_ST_TIM->TAMATCHR = (uint32_t) temp; +// +// temp = temp >> 32; +// +// TIVA_ST_TIM->TAPMR = (uint16_t) temp; +// +// TIVA_ST_TIM->ICR = 0xffffffff; +// TIVA_ST_TIM->IMR = GPTM_IMR_TAMIM; + + uint64_t settime = time * ((ST_CLOCK_SRC / OSAL_ST_FREQUENCY) - 1); + + TIVA_ST_TIM->TAPMR = (uint16_t) ((settime >> 32) & 0xffff); + TIVA_ST_TIM->TAMATCHR = (uint32_t) (settime); + + TIVA_ST_TIM->ICR = TIVA_ST_TIM->MIS; TIVA_ST_TIM->IMR = GPTM_IMR_TAMIM; #else (void)time; @@ -260,15 +272,20 @@ static inline void st_lld_stop_alarm(void) static inline void st_lld_set_alarm(systime_t time) { #if OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING - uint64_t temp; - - temp = (uint64_t) time * TIVA_ST_TIM_PRESCALER; - - TIVA_ST_TIM->TAMATCHR = (uint32_t) temp; - - temp = temp >> 32; - - TIVA_ST_TIM->TAPMR = (uint16_t) temp; +// uint64_t temp; +// +// temp = (uint64_t) time * TIVA_ST_TIM_PRESCALER; +// +// TIVA_ST_TIM->TAMATCHR = (uint32_t) temp; +// +// temp = temp >> 32; +// +// TIVA_ST_TIM->TAPMR = (uint16_t) temp; + + uint64_t settime = time * ((ST_CLOCK_SRC / OSAL_ST_FREQUENCY) - 1); + + TIVA_ST_TIM->TAPMR = (uint16_t) ((settime >> 32) & 0xffff); + TIVA_ST_TIM->TAMATCHR = (uint32_t) (settime); #else (void)time; #endif @@ -284,15 +301,18 @@ static inline void st_lld_set_alarm(systime_t time) static inline systime_t st_lld_get_alarm(void) { #if OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING - uint64_t temp; - - temp = TIVA_ST_TIM->TAPR; - temp = temp << 32; - temp = TIVA_ST_TIM->TAR; - - temp = temp / TIVA_ST_TIM_PRESCALER; - - return (systime_t) temp; +// uint64_t temp; +// +// temp = TIVA_ST_TIM->TAPR; +// temp = temp << 32; +// temp = TIVA_ST_TIM->TAR; +// +// temp = temp / TIVA_ST_TIM_PRESCALER; +// +// return (systime_t) temp; + + //return (systime_t) (TIVA_ST_TIM->TAPR << 16 | TIVA_ST_TIM->TAR >> 16); + return (systime_t) ((TIVA_ST_TIM->TAV >> 16) | (TIVA_ST_TIM->TAPV << 16))/((ST_CLOCK_SRC / OSAL_ST_FREQUENCY) - 1); #else return (systime_t) 0; #endif |