| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #include "Timers.h"
- #define TIMER 0x900D0000
- volatile uint32_t *timer_ctl = (uint32_t *) (TIMER + 0x08);
- volatile uint32_t *timer_load = (uint32_t *) (TIMER);
- volatile uint32_t *timer_value = (uint32_t *) (TIMER + 0x04);
- uint32_t timer_ctl_bkp[2], timer_load_bkp[2];
- #define TIMERS Nspire::Timers
- void TIMERS::init(uint32_t timer)
- {
- timer_ctl_bkp[timer] = timer_ctl[8 * timer];
- timer_load_bkp[timer] = timer_load[8 * timer];
- }
- void TIMERS::restore(uint32_t timer)
- {
- timer_ctl[8 * timer] &= ~(1 << 7);
- timer_ctl[8 * timer] = timer_ctl_bkp[timer] & ~(1 << 7);
- timer_load[8 * timer] = timer_load_bkp[timer];
- timer_ctl[8 * timer] = timer_ctl_bkp[timer];
- }
- void TIMERS::mode(uint32_t timer, bool free_run, bool oneshot, bool interrupt,
- uint32_t div, bool full_width_counter)
- {
- uint32_t mode = 0;
- if (!free_run)
- mode |= (1 << 6);
- if (oneshot)
- mode |= (1 << 0);
- if (interrupt)
- mode |= (1 << 5);
- if (full_width_counter)
- mode |= (1 << 1);
- switch (div)
- {
- case 256:
- mode |= (1 << 3);
- break;
- case 16:
- mode |= (1 << 2);
- break;
- }
- timer_ctl[8 * timer] &= ~(1 << 7);
- timer_ctl[8 * timer] = mode;
- timer_ctl[8 * timer] |= (1 << 7);
- }
- void TIMERS::load(uint32_t timer, uint32_t value)
- {
- timer_load[8 * timer] = 0xFFFFFFFF - value;
- }
- uint32_t TIMERS::read(uint32_t timer)
- {
- return 0xFFFFFFFF - timer_value[8 * timer];
- }
|