seeedstudio ARCH GPRS Test for GPRS function
Fork of ARCH_GPRS_Demo by
ARCH GPRS Introduction
- Arch GPRS is a wireless network module based on EG-10, it can achive remote data colletion function to communicate with outside world by GPRS network.
- Arch GPRS has standard Arduino interface and Grove connectors. It’s convenient to connect existing Shields and Grove products to Arch GPRS.
- You can use the solar panel to charge for battery, and own to its low-power design, so Arch GPRS can work normally in outdoor.
- For more information, please visit http://www.seeedstudio.com/depot/arch-gprs-p-1657.html?cPath=6_11
main.cpp
/* main.cpp 2013 Copyright (c) Seeed Technology Inc. All right reserved. Author:lawliet zou(lawliet.zou@gmail.com) 2013-7-21 This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "mbed.h" #include "string.h" #include "gprs.h" #define SEND_SMS_TEST 0 #define CALL_UP_TEST 0 #define ANSWER_TEST 0 #define READ_SMS_TEST 0 #define PHONE_NUMBER "150****9566" #define PINPWR P1_2 // power on EG 10, low enable #define PINONOFF P1_7 // switch of EG10, low enable, low for 2s to turn on EG10 DigitalOut eg10_pwr(PINPWR); DigitalOut eg10_on(PINONOFF); GPRS gprsTest(P0_19, P0_18, 115200, PHONE_NUMBER); void EG10_PowerUp(void) { eg10_pwr = 1; eg10_on = 1; wait(2); eg10_pwr = 0; eg10_on = 0; wait(2); eg10_on = 1; wait(2); } int main(void) { EG10_PowerUp(); while(0 != gprsTest.init()) { wait(2); } #if CALL_UP_TEST gprsTest.callUp(PHONE_NUMBER); #endif #if SEND_SMS_TEST gprsTest.sendSMS(PHONE_NUMBER,"hello,lawliet"); #endif #if ANSWER_TEST || READ_SMS_TEST while(1) { int messageType = gprsTest.loopHandle(); if(MESSAGE_RING == messageType) { gprsTest.answer(); } else if(MESSAGE_SMS == messageType) { char smsMessage[SMS_MAX_LENGTH]; gprsTest.getSMS(smsMessage); } } #endif return 0; }
Diff: SLEEP/ARCH_GPRS_Sleep.cpp
- Revision:
- 0:6d297fe482af
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SLEEP/ARCH_GPRS_Sleep.cpp Fri Aug 23 02:31:06 2013 +0000 @@ -0,0 +1,90 @@ +#include "mbed.h" +#include "ARCH_GPRS_Sleep.h" +#include "ARCH_GPRS_HW.h" + +void Stalker3_0_sleep::gotoSleep() // goto sleep mode, untill wdt interrupt +{ + LPC_PMU->PCON |= 0x01; /* ????????? */ + LPC_SYSCON->PDSLEEPCFG |= (1UL << 3); /* ??BOD??????? */ + SCB->SCR &= ~(1UL << 2); /* ?????? */ + __wfi(); +} + +void Stalker3_0_sleep::wdtClkSetup(unsigned long clksrc) +{ + /* Freq = 0.5Mhz, div_sel is 0x1F, divided by 64. WDT_OSC should be 7.8125khz */ + LPC_SYSCON->WDTOSCCTRL = (0x1<<5)|0x1F; + LPC_SYSCON->PDRUNCFG &= ~(0x1<<6); /* Let WDT clock run */ + + /* Enables clock for WDT */ + LPC_SYSCON->SYSAHBCLKCTRL |= (1<<15); + LPC_WWDT->CLKSEL = clksrc; /* Select clock source */ + +} + +void Stalker3_0_sleep::wdtInit(long tc) // init wdt +{ + uint32_t regVal; + + LPC_WWDT->TC = tc; + + regVal = WDEN; + LPC_WWDT->MOD = regVal; + + LPC_WWDT->FEED = 0xAA; /* Feeding sequence */ + LPC_WWDT->FEED = 0x55; + + NVIC_EnableIRQ(WDT_IRQn); + NVIC_SetPriority(WDT_IRQn, 2); + return; + +} + +void Stalker3_0_sleep::init() +{ + +} + +void Stalker3_0_sleep::sleep(long ts) // sleep for ts (s) +{ + + workMode = MODE_SLEEP; + wdtInit(0x2dc6c0); + + for(int i=0; i<ts; i++) + { + gotoSleep(); + } + + workMode = MODE_WORKING; + feed(); +} + +void Stalker3_0_sleep::wakeUp() // wake up from sleep +{ + +} + +void Stalker3_0_sleep::feed() // watch dog feed +{ + LPC_WWDT->FEED = 0xAA; /* Feeding sequence */ + LPC_WWDT->FEED = 0x55; + return; +} + +Stalker3_0_sleep wdt_sleep; + +extern "C"{ + + void WDT_IRQHandler(void) + { + + if(wdt_sleep.workMode == MODE_WORKING) // WORKING MODE, AND NO FEET WDT, RESET!!! + { + NVIC_SystemReset(); + } + LPC_WWDT->MOD &= ~WDTOF; /* clear the time-out flag and interrupt flag */ + LPC_WWDT->MOD &= ~WDINT; /* clear the time-out flag and interrupt flag */ + wdt_sleep.wdtInit(0x2dc6c0); + } +}