Version one of final code
Dependencies: ARCH_GPRS_V2_HW Blinker GPRSInterface HTTPClient_GPRS SDFileSystem USBDevice mbed RTC_WorkingLibrary
Fork of finalV1 by
SLEEP/ARCH_GPRS_Sleep.cpp@2:5e5c2a000d25, 2015-04-22 (annotated)
- Committer:
- mbotkinl
- Date:
- Wed Apr 22 16:46:48 2015 +0000
- Revision:
- 2:5e5c2a000d25
- Parent:
- 0:a2a4d0d432b3
added timestamp from RTC;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbotkinl | 0:a2a4d0d432b3 | 1 | #include "mbed.h" |
mbotkinl | 0:a2a4d0d432b3 | 2 | #include "ARCH_GPRS_Sleep.h" |
mbotkinl | 0:a2a4d0d432b3 | 3 | #include "ARCH_GPRS_V2_HW.h" |
mbotkinl | 0:a2a4d0d432b3 | 4 | |
mbotkinl | 0:a2a4d0d432b3 | 5 | void Stalker3_0_sleep::gotoSleep() // goto sleep mode, untill wdt interrupt |
mbotkinl | 0:a2a4d0d432b3 | 6 | { |
mbotkinl | 0:a2a4d0d432b3 | 7 | LPC_PMU->PCON |= 0x01; /* ????????? */ |
mbotkinl | 0:a2a4d0d432b3 | 8 | LPC_SYSCON->PDSLEEPCFG |= (1UL << 3); /* ??BOD??????? */ |
mbotkinl | 0:a2a4d0d432b3 | 9 | SCB->SCR &= ~(1UL << 2); /* ?????? */ |
mbotkinl | 0:a2a4d0d432b3 | 10 | __wfi(); |
mbotkinl | 0:a2a4d0d432b3 | 11 | } |
mbotkinl | 0:a2a4d0d432b3 | 12 | |
mbotkinl | 0:a2a4d0d432b3 | 13 | void Stalker3_0_sleep::wdtClkSetup(unsigned long clksrc) |
mbotkinl | 0:a2a4d0d432b3 | 14 | { |
mbotkinl | 0:a2a4d0d432b3 | 15 | /* Freq = 0.5Mhz, div_sel is 0x1F, divided by 64. WDT_OSC should be 7.8125khz */ |
mbotkinl | 0:a2a4d0d432b3 | 16 | LPC_SYSCON->WDTOSCCTRL = (0x1<<5)|0x1F; |
mbotkinl | 0:a2a4d0d432b3 | 17 | LPC_SYSCON->PDRUNCFG &= ~(0x1<<6); /* Let WDT clock run */ |
mbotkinl | 0:a2a4d0d432b3 | 18 | |
mbotkinl | 0:a2a4d0d432b3 | 19 | /* Enables clock for WDT */ |
mbotkinl | 0:a2a4d0d432b3 | 20 | LPC_SYSCON->SYSAHBCLKCTRL |= (1<<15); |
mbotkinl | 0:a2a4d0d432b3 | 21 | LPC_WWDT->CLKSEL = clksrc; /* Select clock source */ |
mbotkinl | 0:a2a4d0d432b3 | 22 | |
mbotkinl | 0:a2a4d0d432b3 | 23 | } |
mbotkinl | 0:a2a4d0d432b3 | 24 | |
mbotkinl | 0:a2a4d0d432b3 | 25 | void Stalker3_0_sleep::wdtInit(long tc) // init wdt |
mbotkinl | 0:a2a4d0d432b3 | 26 | { |
mbotkinl | 0:a2a4d0d432b3 | 27 | uint32_t regVal; |
mbotkinl | 0:a2a4d0d432b3 | 28 | |
mbotkinl | 0:a2a4d0d432b3 | 29 | LPC_WWDT->TC = tc; |
mbotkinl | 0:a2a4d0d432b3 | 30 | |
mbotkinl | 0:a2a4d0d432b3 | 31 | regVal = WDEN; |
mbotkinl | 0:a2a4d0d432b3 | 32 | LPC_WWDT->MOD = regVal; |
mbotkinl | 0:a2a4d0d432b3 | 33 | |
mbotkinl | 0:a2a4d0d432b3 | 34 | LPC_WWDT->FEED = 0xAA; /* Feeding sequence */ |
mbotkinl | 0:a2a4d0d432b3 | 35 | LPC_WWDT->FEED = 0x55; |
mbotkinl | 0:a2a4d0d432b3 | 36 | |
mbotkinl | 0:a2a4d0d432b3 | 37 | NVIC_EnableIRQ(WDT_IRQn); |
mbotkinl | 0:a2a4d0d432b3 | 38 | NVIC_SetPriority(WDT_IRQn, 2); |
mbotkinl | 0:a2a4d0d432b3 | 39 | return; |
mbotkinl | 0:a2a4d0d432b3 | 40 | |
mbotkinl | 0:a2a4d0d432b3 | 41 | } |
mbotkinl | 0:a2a4d0d432b3 | 42 | |
mbotkinl | 0:a2a4d0d432b3 | 43 | void Stalker3_0_sleep::init() |
mbotkinl | 0:a2a4d0d432b3 | 44 | { |
mbotkinl | 0:a2a4d0d432b3 | 45 | |
mbotkinl | 0:a2a4d0d432b3 | 46 | } |
mbotkinl | 0:a2a4d0d432b3 | 47 | |
mbotkinl | 0:a2a4d0d432b3 | 48 | void Stalker3_0_sleep::sleep(long ts) // sleep for ts (s) |
mbotkinl | 0:a2a4d0d432b3 | 49 | { |
mbotkinl | 0:a2a4d0d432b3 | 50 | |
mbotkinl | 0:a2a4d0d432b3 | 51 | workMode = MODE_SLEEP; |
mbotkinl | 0:a2a4d0d432b3 | 52 | wdtInit(0x2dc6c0); |
mbotkinl | 0:a2a4d0d432b3 | 53 | |
mbotkinl | 0:a2a4d0d432b3 | 54 | for(int i=0; i<ts; i++) |
mbotkinl | 0:a2a4d0d432b3 | 55 | { |
mbotkinl | 0:a2a4d0d432b3 | 56 | gotoSleep(); |
mbotkinl | 0:a2a4d0d432b3 | 57 | } |
mbotkinl | 0:a2a4d0d432b3 | 58 | |
mbotkinl | 0:a2a4d0d432b3 | 59 | workMode = MODE_WORKING; |
mbotkinl | 0:a2a4d0d432b3 | 60 | feed(); |
mbotkinl | 0:a2a4d0d432b3 | 61 | } |
mbotkinl | 0:a2a4d0d432b3 | 62 | |
mbotkinl | 0:a2a4d0d432b3 | 63 | void Stalker3_0_sleep::wakeUp() // wake up from sleep |
mbotkinl | 0:a2a4d0d432b3 | 64 | { |
mbotkinl | 0:a2a4d0d432b3 | 65 | |
mbotkinl | 0:a2a4d0d432b3 | 66 | } |
mbotkinl | 0:a2a4d0d432b3 | 67 | |
mbotkinl | 0:a2a4d0d432b3 | 68 | void Stalker3_0_sleep::feed() // watch dog feed |
mbotkinl | 0:a2a4d0d432b3 | 69 | { |
mbotkinl | 0:a2a4d0d432b3 | 70 | LPC_WWDT->FEED = 0xAA; /* Feeding sequence */ |
mbotkinl | 0:a2a4d0d432b3 | 71 | LPC_WWDT->FEED = 0x55; |
mbotkinl | 0:a2a4d0d432b3 | 72 | return; |
mbotkinl | 0:a2a4d0d432b3 | 73 | } |
mbotkinl | 0:a2a4d0d432b3 | 74 | |
mbotkinl | 0:a2a4d0d432b3 | 75 | Stalker3_0_sleep wdt_sleep; |
mbotkinl | 0:a2a4d0d432b3 | 76 | |
mbotkinl | 0:a2a4d0d432b3 | 77 | extern "C"{ |
mbotkinl | 0:a2a4d0d432b3 | 78 | |
mbotkinl | 0:a2a4d0d432b3 | 79 | void WDT_IRQHandler(void) |
mbotkinl | 0:a2a4d0d432b3 | 80 | { |
mbotkinl | 0:a2a4d0d432b3 | 81 | |
mbotkinl | 0:a2a4d0d432b3 | 82 | if(wdt_sleep.workMode == MODE_WORKING) // WORKING MODE, AND NO FEET WDT, RESET!!! |
mbotkinl | 0:a2a4d0d432b3 | 83 | { |
mbotkinl | 0:a2a4d0d432b3 | 84 | NVIC_SystemReset(); |
mbotkinl | 0:a2a4d0d432b3 | 85 | } |
mbotkinl | 0:a2a4d0d432b3 | 86 | LPC_WWDT->MOD &= ~WDTOF; /* clear the time-out flag and interrupt flag */ |
mbotkinl | 0:a2a4d0d432b3 | 87 | LPC_WWDT->MOD &= ~WDINT; /* clear the time-out flag and interrupt flag */ |
mbotkinl | 0:a2a4d0d432b3 | 88 | wdt_sleep.wdtInit(0x2dc6c0); |
mbotkinl | 0:a2a4d0d432b3 | 89 | } |
mbotkinl | 0:a2a4d0d432b3 | 90 | } |