init

Dependencies:   aconno_I2C Lis2dh12 WatchdogTimer

Committer:
pathfindr
Date:
Mon Nov 12 10:56:23 2018 +0000
Revision:
5:8f8951127724
Parent:
4:8d8e9bfa82e4
Child:
6:388d3c7efdd9
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pathfindr 0:94b743e06998 1 #include "main.h"
pathfindr 0:94b743e06998 2 #include "board.h"
pathfindr 0:94b743e06998 3 #include "modes.h"
pathfindr 0:94b743e06998 4
pathfindr 5:8f8951127724 5 //include "nrf_soc.h"
pathfindr 4:8d8e9bfa82e4 6
pathfindr 2:fd554f01abdf 7 //#include "ATCommand.h"
pathfindr 2:fd554f01abdf 8
pathfindr 0:94b743e06998 9 //LowPowerTicker ticker; //no impact on power consumption
pathfindr 0:94b743e06998 10
pathfindr 0:94b743e06998 11 //------------------------------------------------------------------------------
pathfindr 0:94b743e06998 12 //Function declarations- Local
pathfindr 0:94b743e06998 13 //------------------------------------------------------------------------------
pathfindr 4:8d8e9bfa82e4 14 static void mainStateEngine(void);
pathfindr 0:94b743e06998 15 static void mode_mtu(void);
pathfindr 4:8d8e9bfa82e4 16 static void selftest(void);
pathfindr 2:fd554f01abdf 17 static void LEDon(void);
pathfindr 0:94b743e06998 18 static void LEDoff(void);
pathfindr 0:94b743e06998 19
pathfindr 0:94b743e06998 20 //------------------------------------------------------------------------------
pathfindr 0:94b743e06998 21 //Var declarations- Local
pathfindr 0:94b743e06998 22 //------------------------------------------------------------------------------
pathfindr 0:94b743e06998 23 bool accel_healthy = false;
pathfindr 4:8d8e9bfa82e4 24 bool firstBoot = false;
pathfindr 4:8d8e9bfa82e4 25 bool requireSoftReset = false;
pathfindr 0:94b743e06998 26
pathfindr 0:94b743e06998 27 //------------------------------------------------------------------------------
pathfindr 4:8d8e9bfa82e4 28 //Var declarations- RETAINED NOINIT RAM
pathfindr 0:94b743e06998 29 //------------------------------------------------------------------------------
pathfindr 4:8d8e9bfa82e4 30 #if defined ( __CC_ARM )
pathfindr 4:8d8e9bfa82e4 31 /** THIS IS THE MBED ONLINE COMPILER TOOLCHAIN*/
pathfindr 4:8d8e9bfa82e4 32 static uint8_t RET_mode __attribute__((section("noinit"),zero_init));
pathfindr 4:8d8e9bfa82e4 33 static uint32_t RET_unixtime __attribute__((section("noinit"),zero_init));
pathfindr 4:8d8e9bfa82e4 34 #elif defined ( __GNUC__ )
pathfindr 4:8d8e9bfa82e4 35 #elif defined ( __ICCARM__ )
pathfindr 4:8d8e9bfa82e4 36 #endif
pathfindr 4:8d8e9bfa82e4 37
pathfindr 0:94b743e06998 38 char RET_pf_identifier[9]; //includes null byte at end
pathfindr 0:94b743e06998 39 int RET_interval_setting = 720;
pathfindr 0:94b743e06998 40 int RET_interval_hours_failsafe = 24;
pathfindr 0:94b743e06998 41 int RET_motioncheck_interval_seconds = 60;
pathfindr 0:94b743e06998 42 int RET_gps_timeout = 180;
pathfindr 0:94b743e06998 43 int RET_gsm_timeout = 120;
pathfindr 0:94b743e06998 44 bool RET_gsmtimedout = false;
pathfindr 0:94b743e06998 45 int RET_beacon_scan = 0;
pathfindr 0:94b743e06998 46 int RET_accel_awake_thr = 11;
pathfindr 0:94b743e06998 47 int RET_accel_awake_triggercount = 0;
pathfindr 0:94b743e06998 48 int RET_accel_alarm_thr = 127;
pathfindr 0:94b743e06998 49 unsigned long RET_unixtime_configrun = 0;
pathfindr 0:94b743e06998 50 unsigned long RET_unixtime_lastpost = 0;
pathfindr 0:94b743e06998 51 unsigned long RET_unixtime_nextpost = 0;
pathfindr 0:94b743e06998 52 unsigned long RET_unixtime_nextpost_failsafe = 0;
pathfindr 0:94b743e06998 53 unsigned long RET_unixtime_framestart = 0;
pathfindr 0:94b743e06998 54 unsigned long RET_motionstarttime = 0;
pathfindr 0:94b743e06998 55 unsigned long RET_motionstoptime = 0;
pathfindr 0:94b743e06998 56 int RET_gsm_failcount = 0;
pathfindr 0:94b743e06998 57 int RET_serverresponse_failcount = 0;
pathfindr 0:94b743e06998 58 int RET_motionconsecutive = 0;
pathfindr 0:94b743e06998 59 int RET_no_motionconsecutive = 0;
pathfindr 0:94b743e06998 60 bool RET_wethinkinmotion = false;
pathfindr 0:94b743e06998 61 bool RET_wethinkhasmoved = false;
pathfindr 0:94b743e06998 62 bool RET_haveservertime = false;
pathfindr 0:94b743e06998 63 float RET_operationTimeHours = 0;
pathfindr 0:94b743e06998 64 float RET_operationFrameTimeHours = 0;
pathfindr 0:94b743e06998 65 int RET_operationCount = 0;
pathfindr 0:94b743e06998 66 char RET_operationTimeString[100];
pathfindr 0:94b743e06998 67
pathfindr 0:94b743e06998 68
pathfindr 0:94b743e06998 69 //------------------------------------------------------------------------------
pathfindr 0:94b743e06998 70 //Pin states
pathfindr 0:94b743e06998 71 //------------------------------------------------------------------------------
pathfindr 0:94b743e06998 72 DigitalOut led1(p11);
pathfindr 0:94b743e06998 73 DigitalOut vreg_en(p29);
pathfindr 0:94b743e06998 74 DigitalOut gsm_pwkey(p28);
pathfindr 4:8d8e9bfa82e4 75 DigitalOut lis3dh_cs(p22);
pathfindr 0:94b743e06998 76
pathfindr 0:94b743e06998 77 //------------------------------------------------------------------------------
pathfindr 0:94b743e06998 78 //Peripherals
pathfindr 0:94b743e06998 79 //------------------------------------------------------------------------------
pathfindr 4:8d8e9bfa82e4 80 //BLE myble;
pathfindr 4:8d8e9bfa82e4 81 #if NEED_CONSOLE_OUTPUT
pathfindr 4:8d8e9bfa82e4 82 Serial uart(p6, p8, 115200);
pathfindr 4:8d8e9bfa82e4 83 #endif
pathfindr 4:8d8e9bfa82e4 84 //ATSerial atserial(p6,p8,115200);
pathfindr 4:8d8e9bfa82e4 85 WatchdogTimer watchdog(65.0); //Do not set to less than 4500ms or can cause issues with softdevice
pathfindr 2:fd554f01abdf 86
pathfindr 0:94b743e06998 87
pathfindr 0:94b743e06998 88
pathfindr 4:8d8e9bfa82e4 89 void gotoSleep(long sleep_milliseconds) {
pathfindr 2:fd554f01abdf 90 //accelerometer.configureForSleep();
pathfindr 4:8d8e9bfa82e4 91
pathfindr 4:8d8e9bfa82e4 92 if (requireSoftReset) { //dont need to clear this var as reset changes it back to false
pathfindr 4:8d8e9bfa82e4 93 RET_unixtime = time(NULL); //save unixtime for reset
pathfindr 4:8d8e9bfa82e4 94 //NVIC_SystemReset();
pathfindr 4:8d8e9bfa82e4 95 system_reset();
pathfindr 4:8d8e9bfa82e4 96 }
pathfindr 4:8d8e9bfa82e4 97 ThisThread::sleep_for(sleep_milliseconds);
pathfindr 0:94b743e06998 98 }
pathfindr 0:94b743e06998 99
pathfindr 2:fd554f01abdf 100 void LED1on(long flash_milliseconds = 0) {
pathfindr 0:94b743e06998 101 led1 = 0;
pathfindr 2:fd554f01abdf 102 if (flash_milliseconds > 0) {
pathfindr 2:fd554f01abdf 103 ThisThread::sleep_for(flash_milliseconds);
pathfindr 0:94b743e06998 104 led1 = 1;
pathfindr 0:94b743e06998 105 }
pathfindr 0:94b743e06998 106 }
pathfindr 0:94b743e06998 107 void LED1off() {
pathfindr 0:94b743e06998 108 led1 = 1;
pathfindr 0:94b743e06998 109 }
pathfindr 0:94b743e06998 110
pathfindr 4:8d8e9bfa82e4 111 void resetState() {
pathfindr 4:8d8e9bfa82e4 112 firstBoot = true;
pathfindr 4:8d8e9bfa82e4 113 RET_mode = 0;
pathfindr 4:8d8e9bfa82e4 114 RET_unixtime = 0;
pathfindr 4:8d8e9bfa82e4 115 set_time(RET_unixtime);
pathfindr 4:8d8e9bfa82e4 116 }
pathfindr 4:8d8e9bfa82e4 117
pathfindr 0:94b743e06998 118 int main() {
pathfindr 4:8d8e9bfa82e4 119 led1 = 1;
pathfindr 4:8d8e9bfa82e4 120
pathfindr 4:8d8e9bfa82e4 121 //CHECK IF THIS IS RESET
pathfindr 4:8d8e9bfa82e4 122 //0x00000004 == soft reset //0x00000002 == watchdog //0x00000001 == button/hardreset
pathfindr 4:8d8e9bfa82e4 123 if (NRF_POWER->RESETREAS != 0xffffffff) {
pathfindr 4:8d8e9bfa82e4 124 switch(NRF_POWER->RESETREAS) {
pathfindr 4:8d8e9bfa82e4 125 case 0x00000001 :
pathfindr 4:8d8e9bfa82e4 126 DEBUG("reset_reason: 0x%08x. - Hard Reset\n",NRF_POWER->RESETREAS);
pathfindr 4:8d8e9bfa82e4 127 resetState();
pathfindr 4:8d8e9bfa82e4 128 break;
pathfindr 4:8d8e9bfa82e4 129 case 0x00000002 :
pathfindr 4:8d8e9bfa82e4 130 DEBUG("reset_reason: 0x%08x. - Watchdog\n",NRF_POWER->RESETREAS);
pathfindr 4:8d8e9bfa82e4 131 set_time(RET_unixtime);
pathfindr 4:8d8e9bfa82e4 132 break;
pathfindr 4:8d8e9bfa82e4 133 case 0x00000004 :
pathfindr 4:8d8e9bfa82e4 134 DEBUG("reset_reason: 0x%08x. - Soft reset\n",NRF_POWER->RESETREAS);
pathfindr 4:8d8e9bfa82e4 135 set_time(RET_unixtime);
pathfindr 4:8d8e9bfa82e4 136 break;
pathfindr 4:8d8e9bfa82e4 137 }
pathfindr 4:8d8e9bfa82e4 138 NRF_POWER->RESETREAS = 0xffffffff;
pathfindr 4:8d8e9bfa82e4 139 }
pathfindr 4:8d8e9bfa82e4 140
pathfindr 0:94b743e06998 141 while(true) {
pathfindr 4:8d8e9bfa82e4 142 //GOTO TO SLEEP
pathfindr 4:8d8e9bfa82e4 143 if (!firstBoot) gotoSleep(60000);
pathfindr 5:8f8951127724 144 LED1on(20);
pathfindr 4:8d8e9bfa82e4 145 watchdog.kick();
pathfindr 4:8d8e9bfa82e4 146
pathfindr 4:8d8e9bfa82e4 147 //MAIN STATE ENGINE
pathfindr 4:8d8e9bfa82e4 148 mainStateEngine();
pathfindr 0:94b743e06998 149 }
pathfindr 0:94b743e06998 150 }
pathfindr 0:94b743e06998 151
pathfindr 2:fd554f01abdf 152 bool GSMon() {
pathfindr 2:fd554f01abdf 153 //power on GSM
pathfindr 2:fd554f01abdf 154 vreg_en = 1;
pathfindr 2:fd554f01abdf 155 ThisThread::sleep_for(500);
pathfindr 2:fd554f01abdf 156 gsm_pwkey = 0;
pathfindr 2:fd554f01abdf 157 ThisThread::sleep_for(1500);
pathfindr 2:fd554f01abdf 158 gsm_pwkey = 1;
pathfindr 2:fd554f01abdf 159 LED1on(1000);
pathfindr 2:fd554f01abdf 160 }
pathfindr 0:94b743e06998 161
pathfindr 4:8d8e9bfa82e4 162
pathfindr 4:8d8e9bfa82e4 163 void mainStateEngine() {
pathfindr 2:fd554f01abdf 164
pathfindr 4:8d8e9bfa82e4 165 //TEST AREA
pathfindr 4:8d8e9bfa82e4 166 LIS3DH accelerometer(p23, p19, p24, p22, LIS3DH_DR_NR_LP_25HZ, LIS3DH_FS_8G);
pathfindr 4:8d8e9bfa82e4 167 requireSoftReset = true;
pathfindr 5:8f8951127724 168 if (!accelerometer.selfTest()) {
pathfindr 4:8d8e9bfa82e4 169 LED1on(100);
pathfindr 4:8d8e9bfa82e4 170 }
pathfindr 4:8d8e9bfa82e4 171 accelerometer.configureForSleep();
pathfindr 5:8f8951127724 172 //ThisThread::sleep_for(10000);
pathfindr 2:fd554f01abdf 173
pathfindr 0:94b743e06998 174
pathfindr 4:8d8e9bfa82e4 175
pathfindr 4:8d8e9bfa82e4 176
pathfindr 4:8d8e9bfa82e4 177
pathfindr 4:8d8e9bfa82e4 178
pathfindr 0:94b743e06998 179
pathfindr 0:94b743e06998 180 bool accel_awake;
pathfindr 2:fd554f01abdf 181
pathfindr 4:8d8e9bfa82e4 182 RET_mode = MODE_SETUP;
pathfindr 0:94b743e06998 183
pathfindr 4:8d8e9bfa82e4 184 switch(RET_mode) {
pathfindr 0:94b743e06998 185 case MODE_SETUP :
pathfindr 0:94b743e06998 186
pathfindr 2:fd554f01abdf 187 //selftest();
pathfindr 0:94b743e06998 188 break;
pathfindr 0:94b743e06998 189
pathfindr 0:94b743e06998 190 case MODE_INTERVAL :
pathfindr 0:94b743e06998 191
pathfindr 0:94b743e06998 192 break;
pathfindr 0:94b743e06998 193
pathfindr 0:94b743e06998 194 case MODE_INTELLIGENT :
pathfindr 0:94b743e06998 195
pathfindr 0:94b743e06998 196 break;
pathfindr 0:94b743e06998 197
pathfindr 0:94b743e06998 198 case MODE_MTU :
pathfindr 2:fd554f01abdf 199 //mode_mtu();
pathfindr 0:94b743e06998 200 break;
pathfindr 0:94b743e06998 201
pathfindr 0:94b743e06998 202 case MODE_DORMANT :
pathfindr 0:94b743e06998 203
pathfindr 0:94b743e06998 204 break;
pathfindr 0:94b743e06998 205
pathfindr 0:94b743e06998 206 default :
pathfindr 4:8d8e9bfa82e4 207 RET_mode = MODE_SETUP;
pathfindr 0:94b743e06998 208 }
pathfindr 0:94b743e06998 209
pathfindr 0:94b743e06998 210 }
pathfindr 0:94b743e06998 211
pathfindr 0:94b743e06998 212
pathfindr 0:94b743e06998 213
pathfindr 2:fd554f01abdf 214 /*
pathfindr 0:94b743e06998 215 void initMotion() {
pathfindr 0:94b743e06998 216 //CHECK FOR ANY MOTION
pathfindr 0:94b743e06998 217 if (!accelerometer.selfTest()) {
pathfindr 0:94b743e06998 218 if (exceptions.find("A.") < 0) {
pathfindr 0:94b743e06998 219 exceptions += "A.";
pathfindr 0:94b743e06998 220 }
pathfindr 0:94b743e06998 221 DEBUG("Couldnt start accelerometer");
pathfindr 0:94b743e06998 222 } else {
pathfindr 0:94b743e06998 223 accel_healthy = true;
pathfindr 0:94b743e06998 224 }
pathfindr 0:94b743e06998 225 }
pathfindr 0:94b743e06998 226
pathfindr 0:94b743e06998 227 void mode_mtu() {
pathfindr 0:94b743e06998 228 bool accel_awake = accelerometer.getINT2();
pathfindr 0:94b743e06998 229
pathfindr 0:94b743e06998 230 //CHECK FOR MOTION
pathfindr 0:94b743e06998 231 if (accel_awake == true) {
pathfindr 0:94b743e06998 232 LED1on(50);
pathfindr 0:94b743e06998 233 RET_motionconsecutive ++;
pathfindr 0:94b743e06998 234 RET_no_motionconsecutive = 0;
pathfindr 0:94b743e06998 235
pathfindr 0:94b743e06998 236 //this is needed to ensure accel_awake_triggercount is 1 or higher for mode 2
pathfindr 0:94b743e06998 237 if (RET_accel_awake_triggercount == 0) {
pathfindr 0:94b743e06998 238 RET_accel_awake_triggercount = 1;
pathfindr 0:94b743e06998 239 }
pathfindr 0:94b743e06998 240
pathfindr 0:94b743e06998 241 if (RET_motionconsecutive == RET_accel_awake_triggercount && RET_wethinkinmotion == false) {
pathfindr 0:94b743e06998 242 RET_wethinkinmotion = true;
pathfindr 0:94b743e06998 243 RET_motionstarttime = (time(NULL) - ((RET_accel_awake_triggercount+1) * RET_motioncheck_interval_seconds));
pathfindr 0:94b743e06998 244 long eventEpoch = RET_motionstarttime;
pathfindr 0:94b743e06998 245 long epochoffsetminutes = ((eventEpoch - RET_unixtime_framestart) / 60);
pathfindr 0:94b743e06998 246
pathfindr 0:94b743e06998 247 char buf[20];
pathfindr 0:94b743e06998 248 sprintf(buf,"1.%i!", epochoffsetminutes);
pathfindr 0:94b743e06998 249 strcat(RET_operationTimeString, buf);
pathfindr 0:94b743e06998 250 RET_operationCount ++;
pathfindr 0:94b743e06998 251
pathfindr 0:94b743e06998 252 DEBUG("%s", RET_operationTimeString);
pathfindr 0:94b743e06998 253
pathfindr 0:94b743e06998 254 LEDon(100);
pathfindr 0:94b743e06998 255 LEDon(100);
pathfindr 0:94b743e06998 256 LEDon(100);
pathfindr 0:94b743e06998 257 LEDon(100);
pathfindr 0:94b743e06998 258 }
pathfindr 0:94b743e06998 259 } else if (accel_awake == false) {
pathfindr 0:94b743e06998 260 RET_no_motionconsecutive ++;
pathfindr 0:94b743e06998 261 RET_motionconsecutive = 0;
pathfindr 0:94b743e06998 262 if (RET_no_motionconsecutive == RET_accel_awake_triggercount && RET_wethinkinmotion == true) {
pathfindr 0:94b743e06998 263 RET_wethinkinmotion = false;
pathfindr 0:94b743e06998 264 // log engine stop
pathfindr 0:94b743e06998 265 RET_motionstoptime = (time(NULL) - ((RET_accel_awake_triggercount+1) * RET_motioncheck_interval_seconds));
pathfindr 0:94b743e06998 266 long eventEpoch = RET_motionstoptime;
pathfindr 0:94b743e06998 267 long epochoffsetminutes = ((eventEpoch - RET_unixtime_framestart) / 60);
pathfindr 0:94b743e06998 268
pathfindr 0:94b743e06998 269 char buf[20];
pathfindr 0:94b743e06998 270 sprintf(buf,"0.%i!", epochoffsetminutes);
pathfindr 0:94b743e06998 271 strcat(RET_operationTimeString, buf);
pathfindr 0:94b743e06998 272
pathfindr 0:94b743e06998 273 RET_operationFrameTimeHours = (float(RET_motionstoptime - RET_motionstarttime) / 3600.0);
pathfindr 0:94b743e06998 274 RET_operationTimeHours += RET_operationFrameTimeHours;
pathfindr 0:94b743e06998 275
pathfindr 0:94b743e06998 276 //test by posting on every stop event
pathfindr 0:94b743e06998 277 //doOperationTimePost = true;
pathfindr 0:94b743e06998 278
pathfindr 0:94b743e06998 279 DEBUG("%i", RET_operationTimeHours);
pathfindr 0:94b743e06998 280 LEDon(500);
pathfindr 0:94b743e06998 281 }
pathfindr 0:94b743e06998 282 }
pathfindr 0:94b743e06998 283
pathfindr 0:94b743e06998 284
pathfindr 0:94b743e06998 285 // Check time interval for location run
pathfindr 0:94b743e06998 286 if (time(NULL) > RET_unixtime_nextpost_failsafe) {
pathfindr 0:94b743e06998 287 //setfailsafetime(); //these must be before gpsPost, incase gpsPost fails, then stuck in broadcast loop
pathfindr 0:94b743e06998 288 //gpsPost();
pathfindr 0:94b743e06998 289 }
pathfindr 0:94b743e06998 290
pathfindr 0:94b743e06998 291 //Check for operatingTime post time or if data buffer is full for force post
pathfindr 0:94b743e06998 292 if (RET_operationFrameTimeHours > 0.0) {
pathfindr 0:94b743e06998 293 if (time(NULL) > RET_unixtime_nextpost || strlen(RET_operationTimeString) > 60) {
pathfindr 0:94b743e06998 294 //only bother if we actual have data to post
pathfindr 0:94b743e06998 295 //setwaketime(); //these must be before gpsPost, incase gpsPost fails, then stuck in broadcast loop
pathfindr 0:94b743e06998 296 //uploadOperationTimeData();
pathfindr 0:94b743e06998 297 }
pathfindr 0:94b743e06998 298 }
pathfindr 0:94b743e06998 299
pathfindr 0:94b743e06998 300 }
pathfindr 2:fd554f01abdf 301 */
pathfindr 0:94b743e06998 302
pathfindr 0:94b743e06998 303
pathfindr 0:94b743e06998 304
pathfindr 0:94b743e06998 305
pathfindr 2:fd554f01abdf 306 /*
pathfindr 0:94b743e06998 307
pathfindr 0:94b743e06998 308 int selftest() {
pathfindr 0:94b743e06998 309 int result = 0;
pathfindr 0:94b743e06998 310 int tests = 0;
pathfindr 0:94b743e06998 311 int testscore = 0;
pathfindr 0:94b743e06998 312 led1 = 0;
pathfindr 0:94b743e06998 313 string failures;
pathfindr 0:94b743e06998 314
pathfindr 0:94b743e06998 315 //Accelerometer
pathfindr 0:94b743e06998 316 tests ++;
pathfindr 0:94b743e06998 317 if (accelerometer.read_id() == 51){
pathfindr 0:94b743e06998 318 testscore ++;
pathfindr 0:94b743e06998 319 } else {
pathfindr 0:94b743e06998 320 //Accelerometer Fail
pathfindr 0:94b743e06998 321 failures += 'Ac,';
pathfindr 0:94b743e06998 322 };
pathfindr 0:94b743e06998 323
pathfindr 0:94b743e06998 324 return result;
pathfindr 2:fd554f01abdf 325 }
pathfindr 4:8d8e9bfa82e4 326 */
pathfindr 4:8d8e9bfa82e4 327
pathfindr 4:8d8e9bfa82e4 328
pathfindr 4:8d8e9bfa82e4 329 /*
pathfindr 4:8d8e9bfa82e4 330 void readRegs(uint8_t addr, uint8_t * data, int len) {
pathfindr 4:8d8e9bfa82e4 331 lis3dh_cs = 0;
pathfindr 4:8d8e9bfa82e4 332 for (int i = 0 ; i < len ; i++ ) {
pathfindr 4:8d8e9bfa82e4 333 spi.write((addr+i)|0x80) ; // specify address to read
pathfindr 4:8d8e9bfa82e4 334 data[i] = spi.write((addr+i)|0x80) ;
pathfindr 4:8d8e9bfa82e4 335 }
pathfindr 4:8d8e9bfa82e4 336 spi.write(0x00) ; // to terminate read mode
pathfindr 4:8d8e9bfa82e4 337 lis3dh_cs = 1;
pathfindr 4:8d8e9bfa82e4 338 }
pathfindr 4:8d8e9bfa82e4 339
pathfindr 4:8d8e9bfa82e4 340 uint8_t read_reg(uint8_t addr)
pathfindr 4:8d8e9bfa82e4 341 {
pathfindr 4:8d8e9bfa82e4 342 uint8_t data[1] ;
pathfindr 4:8d8e9bfa82e4 343 readRegs(addr, data, 1) ;
pathfindr 4:8d8e9bfa82e4 344 return( data[0] ) ;
pathfindr 4:8d8e9bfa82e4 345 }
pathfindr 4:8d8e9bfa82e4 346 */
pathfindr 4:8d8e9bfa82e4 347
pathfindr 4:8d8e9bfa82e4 348
pathfindr 4:8d8e9bfa82e4 349
pathfindr 4:8d8e9bfa82e4 350
pathfindr 4:8d8e9bfa82e4 351
pathfindr 4:8d8e9bfa82e4 352
pathfindr 4:8d8e9bfa82e4 353
pathfindr 4:8d8e9bfa82e4 354
pathfindr 4:8d8e9bfa82e4 355
pathfindr 4:8d8e9bfa82e4 356
pathfindr 4:8d8e9bfa82e4 357
pathfindr 4:8d8e9bfa82e4 358
pathfindr 4:8d8e9bfa82e4 359 /*
pathfindr 4:8d8e9bfa82e4 360 //OPTION 1
pathfindr 4:8d8e9bfa82e4 361 // Switch on both RAM banks when in System OFF mode.
pathfindr 4:8d8e9bfa82e4 362 NRF_POWER->RAMON |= (POWER_RAMON_OFFRAM0_RAM0On << POWER_RAMON_OFFRAM0_Pos) |
pathfindr 4:8d8e9bfa82e4 363 (POWER_RAMON_OFFRAM1_RAM1On << POWER_RAMON_OFFRAM1_Pos);
pathfindr 4:8d8e9bfa82e4 364
pathfindr 4:8d8e9bfa82e4 365 // Enter System OFF and wait for wake up from GPIO detect signal.
pathfindr 4:8d8e9bfa82e4 366 NRF_POWER->SYSTEMOFF = 0x1;
pathfindr 4:8d8e9bfa82e4 367
pathfindr 4:8d8e9bfa82e4 368
pathfindr 4:8d8e9bfa82e4 369 //spi.close();
pathfindr 4:8d8e9bfa82e4 370
pathfindr 4:8d8e9bfa82e4 371 //delete spi;
pathfindr 4:8d8e9bfa82e4 372 //spi_disable();
pathfindr 4:8d8e9bfa82e4 373
pathfindr 4:8d8e9bfa82e4 374 //spi_free(spi);
pathfindr 4:8d8e9bfa82e4 375
pathfindr 4:8d8e9bfa82e4 376 //nrf_drv_spi_uninit(spi);
pathfindr 4:8d8e9bfa82e4 377 //nordic_nrf5_spi_initialized[instance] = false;
pathfindr 4:8d8e9bfa82e4 378 //HFCLKSTOP = 0x1;
pathfindr 4:8d8e9bfa82e4 379
pathfindr 4:8d8e9bfa82e4 380 NRF_SPI0->ENABLE = 0;
pathfindr 4:8d8e9bfa82e4 381 NRF_SPI1->ENABLE = 0;
pathfindr 4:8d8e9bfa82e4 382 NRF_SPI2->ENABLE = 0;
pathfindr 4:8d8e9bfa82e4 383 NRF_TWI0->ENABLE = 0;
pathfindr 4:8d8e9bfa82e4 384 NRF_TWI1->ENABLE = 0;
pathfindr 4:8d8e9bfa82e4 385
pathfindr 4:8d8e9bfa82e4 386 sd_clock_hfclk_release();
pathfindr 4:8d8e9bfa82e4 387 NRF_POWER->SYSTEMOFF=1;
pathfindr 4:8d8e9bfa82e4 388 //NRF_SPI0->POWER = 0;
pathfindr 4:8d8e9bfa82e4 389
pathfindr 4:8d8e9bfa82e4 390 //OPTION 3
pathfindr 4:8d8e9bfa82e4 391
pathfindr 4:8d8e9bfa82e4 392 *(volatile uint32_t *)0x40003FFC = 0;
pathfindr 4:8d8e9bfa82e4 393 *(volatile uint32_t *)0x40003FFC;
pathfindr 4:8d8e9bfa82e4 394 *(volatile uint32_t *)0x40003FFC = 1;
pathfindr 4:8d8e9bfa82e4 395
pathfindr 4:8d8e9bfa82e4 396 NRF_SPI0->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos);
pathfindr 4:8d8e9bfa82e4 397 NRF_SPI1->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos);
pathfindr 4:8d8e9bfa82e4 398
pathfindr 4:8d8e9bfa82e4 399
pathfindr 4:8d8e9bfa82e4 400 if (sleep_manager_can_deep_sleep()) {
pathfindr 4:8d8e9bfa82e4 401 ThisThread::sleep_for(10000);
pathfindr 4:8d8e9bfa82e4 402 } else {
pathfindr 4:8d8e9bfa82e4 403 led1 = 0;
pathfindr 4:8d8e9bfa82e4 404 wait(50.0);
pathfindr 4:8d8e9bfa82e4 405 }
pathfindr 4:8d8e9bfa82e4 406
pathfindr 4:8d8e9bfa82e4 407 //system_reset();
pathfindr 4:8d8e9bfa82e4 408 */
pathfindr 4:8d8e9bfa82e4 409
pathfindr 4:8d8e9bfa82e4 410
pathfindr 4:8d8e9bfa82e4 411 //time_t unixtime = time(NULL);
pathfindr 4:8d8e9bfa82e4 412 //DEBUG("got: %i, %d, %d \n", RET_mode, RET_unixtime, unixtime);
pathfindr 4:8d8e9bfa82e4 413