Skip to content
Snippets Groups Projects
Commit 91fcde73 authored by Glenn Ruben Bakke's avatar Glenn Ruben Bakke Committed by Damien George
Browse files

nrf/drivers/ticker: Rework ticker functions for microbit display/music.

- Rename init function to ticker_init0.
- Implement ticker_register_low_pri_callback (recycle of unused
  set_low_priority_callback function which was unimplemented).
- Add support for registering 2 low pri callbacks.  For now, one intended
  for microbit display, and one for modmusic.
parent 7c74b7da
No related branches found
No related tags found
No related merge requests found
...@@ -39,11 +39,10 @@ ...@@ -39,11 +39,10 @@
#define SlowTicker_IRQHandler SWI0_IRQHandler #define SlowTicker_IRQHandler SWI0_IRQHandler
// Ticker callback function called every MACRO_TICK // Ticker callback function called every MACRO_TICK
static volatile callback_ptr slow_ticker; static volatile uint8_t m_num_of_slow_tickers = 0;
static volatile callback_ptr m_slow_tickers[2] = {NULL, NULL};
void ticker_init(callback_ptr slow_ticker_callback) {
slow_ticker = slow_ticker_callback;
void ticker_init0(void) {
NRF_TIMER_Type *ticker = FastTicker; NRF_TIMER_Type *ticker = FastTicker;
#ifdef NRF51 #ifdef NRF51
ticker->POWER = 1; ticker->POWER = 1;
...@@ -70,6 +69,10 @@ void ticker_init(callback_ptr slow_ticker_callback) { ...@@ -70,6 +69,10 @@ void ticker_init(callback_ptr slow_ticker_callback) {
hal_irq_enable(SlowTicker_IRQn); hal_irq_enable(SlowTicker_IRQn);
} }
void ticker_register_low_pri_callback(callback_ptr slow_ticker_callback) {
m_slow_tickers[m_num_of_slow_tickers++] = slow_ticker_callback;
}
/* Start and stop timer 1 including workarounds for Anomaly 73 for Timer /* Start and stop timer 1 including workarounds for Anomaly 73 for Timer
* http://www.nordicsemi.com/eng/content/download/29490/494569/file/nRF51822-PAN%20v3.0.pdf * http://www.nordicsemi.com/eng/content/download/29490/494569/file/nRF51822-PAN%20v3.0.pdf
*/ */
...@@ -156,7 +159,12 @@ int clear_ticker_callback(uint32_t index) { ...@@ -156,7 +159,12 @@ int clear_ticker_callback(uint32_t index) {
void SlowTicker_IRQHandler(void) void SlowTicker_IRQHandler(void)
{ {
slow_ticker();
for (int i = 0; i < m_num_of_slow_tickers; i++) {
if (m_slow_tickers[i] != NULL) {
m_slow_tickers[i]();
}
}
} }
#endif // MICROPY_PY_MACHINE_SOFT_PWM #endif // MICROPY_PY_MACHINE_SOFT_PWM
...@@ -10,14 +10,13 @@ ...@@ -10,14 +10,13 @@
typedef void (*callback_ptr)(void); typedef void (*callback_ptr)(void);
typedef int32_t (*ticker_callback_ptr)(void); typedef int32_t (*ticker_callback_ptr)(void);
void ticker_init(callback_ptr slow_ticker_callback); void ticker_init0();
void ticker_start(void); void ticker_start(void);
void ticker_stop(void); void ticker_stop(void);
int clear_ticker_callback(uint32_t index); int clear_ticker_callback(uint32_t index);
int set_ticker_callback(uint32_t index, ticker_callback_ptr func, int32_t initial_delay_us); int set_ticker_callback(uint32_t index, ticker_callback_ptr func, int32_t initial_delay_us);
int set_low_priority_callback(callback_ptr callback, int id); void ticker_register_low_pri_callback(callback_ptr callback);
#define CYCLES_PER_MICROSECONDS 16 #define CYCLES_PER_MICROSECONDS 16
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment