Browse Source

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.
pull/3137/merge
Glenn Ruben Bakke 7 years ago
committed by Damien George
parent
commit
91fcde73d2
  1. 18
      ports/nrf/drivers/ticker.c
  2. 7
      ports/nrf/drivers/ticker.h

18
ports/nrf/drivers/ticker.c

@ -39,11 +39,10 @@
#define SlowTicker_IRQHandler SWI0_IRQHandler
// Ticker callback function called every MACRO_TICK
static volatile callback_ptr slow_ticker;
void ticker_init(callback_ptr slow_ticker_callback) {
slow_ticker = slow_ticker_callback;
static volatile uint8_t m_num_of_slow_tickers = 0;
static volatile callback_ptr m_slow_tickers[2] = {NULL, NULL};
void ticker_init0(void) {
NRF_TIMER_Type *ticker = FastTicker;
#ifdef NRF51
ticker->POWER = 1;
@ -70,6 +69,10 @@ void ticker_init(callback_ptr slow_ticker_callback) {
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
* 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) {
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

7
ports/nrf/drivers/ticker.h

@ -10,14 +10,13 @@
typedef void (*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_stop(void);
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_low_priority_callback(callback_ptr callback, int id);
void ticker_register_low_pri_callback(callback_ptr callback);
#define CYCLES_PER_MICROSECONDS 16
@ -27,4 +26,4 @@ int set_low_priority_callback(callback_ptr callback, int id);
#define MICROSECONDS_PER_MACRO_TICK 6000
#define MILLISECONDS_PER_MACRO_TICK 6
#endif // __MICROPY_INCLUDED_LIB_TICKER_H__
#endif // __MICROPY_INCLUDED_LIB_TICKER_H__

Loading…
Cancel
Save