Fork of original library to fix mbed 5 deprecation warnings
Dependencies: LPC1114_WakeInterruptIn
Fork of WakeUp by
Device/WakeUp_LPC812.cpp@23:884e86933aaa, 2017-04-10 (annotated)
- Committer:
- RobMeades
- Date:
- Mon Apr 10 13:05:23 2017 +0000
- Revision:
- 23:884e86933aaa
- Parent:
- 7:bb411115f814
Fix deprecation warnings.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Sissors | 1:92f4c2b52771 | 1 | #ifdef TARGET_LPC812 |
Sissors | 1:92f4c2b52771 | 2 | |
Sissors | 0:fc439458a359 | 3 | #include "WakeUp.h" |
Sissors | 0:fc439458a359 | 4 | |
RobMeades | 23:884e86933aaa | 5 | Callback<void()> WakeUp::cbk; |
Sissors | 0:fc439458a359 | 6 | float WakeUp::cycles_per_ms = 10.0; |
Sissors | 0:fc439458a359 | 7 | |
Sissors | 0:fc439458a359 | 8 | void WakeUp::set_ms(uint32_t ms) |
Sissors | 0:fc439458a359 | 9 | { |
Sissors | 0:fc439458a359 | 10 | //Enable clock to register interface: |
Sissors | 0:fc439458a359 | 11 | LPC_SYSCON->SYSAHBCLKCTRL |= 1<<9; |
Sissors | 0:fc439458a359 | 12 | |
Sissors | 0:fc439458a359 | 13 | //Clear the counter: |
Sissors | 0:fc439458a359 | 14 | LPC_WKT->CTRL |= 1<<2; |
Sissors | 0:fc439458a359 | 15 | if (ms != 0) { |
Sissors | 0:fc439458a359 | 16 | //Enable clock to register interface: |
Sissors | 0:fc439458a359 | 17 | LPC_SYSCON->SYSAHBCLKCTRL |= 1<<9; |
Sissors | 0:fc439458a359 | 18 | |
Sissors | 0:fc439458a359 | 19 | //Set 10kHz timer as source, and just to be sure clear status bit |
Sissors | 0:fc439458a359 | 20 | LPC_WKT->CTRL = 3; |
Sissors | 0:fc439458a359 | 21 | |
Sissors | 0:fc439458a359 | 22 | //Enable the 10kHz timer |
Sissors | 0:fc439458a359 | 23 | LPC_PMU->DPDCTRL |= (1<<2) | (1<<3); |
Sissors | 0:fc439458a359 | 24 | |
Sissors | 0:fc439458a359 | 25 | //Set interrupts |
Sissors | 0:fc439458a359 | 26 | NVIC_SetVector(WKT_IRQn, (uint32_t)WakeUp::irq_handler); |
Sissors | 0:fc439458a359 | 27 | NVIC_EnableIRQ(WKT_IRQn); |
Sissors | 0:fc439458a359 | 28 | |
Sissors | 0:fc439458a359 | 29 | //Load the timer |
Sissors | 0:fc439458a359 | 30 | LPC_WKT->COUNT = (uint32_t)((float)ms * cycles_per_ms); |
Sissors | 0:fc439458a359 | 31 | |
Sissors | 0:fc439458a359 | 32 | } else { |
Sissors | 0:fc439458a359 | 33 | //Disable clock to register interface: |
Sissors | 0:fc439458a359 | 34 | LPC_SYSCON->SYSAHBCLKCTRL &= ~(1<<9); |
Sissors | 0:fc439458a359 | 35 | |
Sissors | 0:fc439458a359 | 36 | //Disable the 10kHz timer |
Sissors | 0:fc439458a359 | 37 | LPC_PMU->DPDCTRL &= ~((1<<2) | (1<<3)); |
Sissors | 0:fc439458a359 | 38 | } |
Sissors | 0:fc439458a359 | 39 | } |
Sissors | 0:fc439458a359 | 40 | |
Sissors | 0:fc439458a359 | 41 | void WakeUp::irq_handler(void) |
Sissors | 0:fc439458a359 | 42 | { |
Sissors | 0:fc439458a359 | 43 | //Clear status |
Sissors | 0:fc439458a359 | 44 | LPC_WKT->CTRL |= 2; |
Sissors | 0:fc439458a359 | 45 | |
Sissors | 0:fc439458a359 | 46 | //Disable clock to register interface: |
Sissors | 0:fc439458a359 | 47 | LPC_SYSCON->SYSAHBCLKCTRL &= ~(1<<9); |
Sissors | 0:fc439458a359 | 48 | |
Sissors | 0:fc439458a359 | 49 | //Disable the 10kHz timer |
Sissors | 0:fc439458a359 | 50 | LPC_PMU->DPDCTRL &= ~((1<<2) | (1<<3)); |
Sissors | 0:fc439458a359 | 51 | |
RobMeades | 23:884e86933aaa | 52 | if (cbk) { |
RobMeades | 23:884e86933aaa | 53 | cbk.call(); |
RobMeades | 23:884e86933aaa | 54 | } |
Sissors | 0:fc439458a359 | 55 | } |
Sissors | 0:fc439458a359 | 56 | |
Sissors | 0:fc439458a359 | 57 | void WakeUp::calibrate(void) |
Sissors | 0:fc439458a359 | 58 | { |
Sissors | 0:fc439458a359 | 59 | cycles_per_ms = 10.0; |
Sissors | 0:fc439458a359 | 60 | set_ms(1100); |
Sissors | 0:fc439458a359 | 61 | wait_ms(100); |
Sissors | 0:fc439458a359 | 62 | |
Sissors | 0:fc439458a359 | 63 | uint32_t prevread = LPC_WKT->COUNT; |
Sissors | 0:fc439458a359 | 64 | uint32_t read = LPC_WKT->COUNT; |
Sissors | 0:fc439458a359 | 65 | while( read != prevread) { |
Sissors | 0:fc439458a359 | 66 | prevread = read; |
Sissors | 0:fc439458a359 | 67 | read = LPC_WKT->COUNT; |
Sissors | 0:fc439458a359 | 68 | } |
Sissors | 0:fc439458a359 | 69 | |
Sissors | 0:fc439458a359 | 70 | uint32_t ticks = 11000 - read; |
Sissors | 0:fc439458a359 | 71 | |
Sissors | 0:fc439458a359 | 72 | cycles_per_ms = ticks / 100.0; |
Sissors | 0:fc439458a359 | 73 | set_ms(0); |
Sissors | 0:fc439458a359 | 74 | } |
Sissors | 0:fc439458a359 | 75 | |
Sissors | 1:92f4c2b52771 | 76 | #endif |