diff options
author | NIIBE Yutaka <gniibe@fsij.org> | 2015-09-09 09:47:25 +0900 |
---|---|---|
committer | NIIBE Yutaka <gniibe@fsij.org> | 2015-09-09 09:47:25 +0900 |
commit | 06e4459c21f239f9a95d42b24aa6ad29485e9608 (patch) | |
tree | b4356085031521661b0353a5b3e343a43f37a059 | |
parent | baef99bf11db42df18e2155e14fe774260747c91 (diff) |
factoring: systick
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | chopstx.c | 56 |
2 files changed, 44 insertions, 17 deletions
@@ -1,3 +1,8 @@ +2015-09-09 Niibe Yutaka <gniibe@fsij.org> + + * chopstx.c (chx_systick_reset, chx_systick_reload) + (chx_systick_get): Factor out systick functions. + 2015-09-08 Niibe Yutaka <gniibe@fsij.org> * chopstx.c (chx_request_preemption): Add PRIO argument and check @@ -80,7 +80,42 @@ #else #error "no support for this arch" #endif + +/* + * Lower layer architecture specific functions. + * + * system tick, interrupt, and exception handlings. + */ + +/* + * SysTick registers. + */ +static volatile uint32_t *const SYST_CSR = (uint32_t *const)0xE000E010; +static volatile uint32_t *const SYST_RVR = (uint32_t *const)0xE000E014; +static volatile uint32_t *const SYST_CVR = (uint32_t *const)0xE000E018; + +static void +chx_systick_reset (void) +{ + *SYST_RVR = 0; + *SYST_CVR = 0; + *SYST_CSR = 7; +} + +static void +chx_systick_reload (uint32_t ticks) +{ + *SYST_RVR = ticks; + *SYST_CVR = 0; /* write (any) to clear the counter to reload. */ + *SYST_RVR = 0; +} +static uint32_t +chx_systick_get (void) +{ + return *SYST_CVR; +} + /** * chx_fatal - Fatal error point. * @err_code: Error code @@ -189,13 +224,6 @@ static struct NVIC *const NVIC = (struct NVIC *const)0xE000E100; #define USB_LP_CAN1_RX0_IRQn 20 -/* - * SysTick registers. - */ -static volatile uint32_t *const SYST_CSR = (uint32_t *const)0xE000E010; -static volatile uint32_t *const SYST_RVR = (uint32_t *const)0xE000E014; -static volatile uint32_t *const SYST_CVR = (uint32_t *const)0xE000E018; - #ifndef MHZ #define MHZ 72 #endif @@ -597,11 +625,7 @@ static void chx_set_timer (struct chx_thread *q, uint32_t ticks) { if (q == (struct chx_thread *)&q_timer) - { - *SYST_RVR = ticks; - *SYST_CVR = 0; /* write (any) to clear the counter to reload. */ - *SYST_RVR = 0; - } + chx_systick_reload (ticks); else q->v = ticks; } @@ -610,7 +634,7 @@ static void chx_timer_insert (struct chx_thread *tp, uint32_t usec) { uint32_t ticks = usec_to_ticks (usec); - uint32_t next_ticks = *SYST_CVR; + uint32_t next_ticks = chx_systick_get (); struct chx_thread *q; for (q = q_timer.next; q != (struct chx_thread *)&q_timer; q = q->next) @@ -651,7 +675,7 @@ chx_timer_dequeue (struct chx_thread *tp) chx_set_timer (tp_prev, 0); /* Cancel timer*/ else { /* Update timer. */ - uint32_t next_ticks = *SYST_CVR + tp->v; + uint32_t next_ticks = chx_systick_get () + tp->v; chx_set_timer (tp_prev, next_ticks); } @@ -773,9 +797,7 @@ chx_handle_intr (void) void chx_systick_init (void) { - *SYST_RVR = 0; - *SYST_CVR = 0; - *SYST_CSR = 7; + chx_systic_reset (); if ((CHX_FLAGS_MAIN & CHOPSTX_SCHED_RR)) { |