comparison Small_CPU/Src/scheduler.c @ 416:bcf447646e07

Merged in Ideenmodellierer/ostc4/Improment_NVM (pull request #37) Improment NVM
author heinrichsweikamp <bitbucket@heinrichsweikamp.com>
date Wed, 15 Jan 2020 10:53:15 +0000
parents 6886aeeca454
children 4b000e2386c2
comparison
equal deleted inserted replaced
403:6f30f2011667 416:bcf447646e07
40 #include "calc_crush.h" 40 #include "calc_crush.h"
41 #include "stm32f4xx_hal_rtc_ex.h" 41 #include "stm32f4xx_hal_rtc_ex.h"
42 #include "decom.h" 42 #include "decom.h"
43 #include "tm_stm32f4_otp.h" 43 #include "tm_stm32f4_otp.h"
44 44
45 /* uncomment to enable restoting of last known date in case of a power loss (RTC looses timing data) */
46 /* #define RESTORE_LAST_KNOWN_DATE */
45 47
46 #define INVALID_PREASURE_VALUE (100.0f) 48 #define INVALID_PREASURE_VALUE (100.0f)
47 #define START_DIVE_MOUNTAIN_MODE_BAR (0.88f) 49 #define START_DIVE_MOUNTAIN_MODE_BAR (0.88f)
48 #define START_DIVE_IMMEDIATLY_BAR (1.16f) 50 #define START_DIVE_IMMEDIATLY_BAR (1.16f)
49 51
1198 lineWrite->time_rtc_tr = lineRead->time_rtc_tr; 1200 lineWrite->time_rtc_tr = lineRead->time_rtc_tr;
1199 lineWrite->value_int32 = lineRead->value_int32; 1201 lineWrite->value_int32 = lineRead->value_int32;
1200 } 1202 }
1201 1203
1202 1204
1205 void scheduletranslateDate(uint32_t datetmpreg, RTC_DateTypeDef *sDate)
1206 {
1207 datetmpreg = (uint32_t)(datetmpreg & RTC_DR_RESERVED_MASK);
1208
1209 /* Fill the structure fields with the read parameters */
1210 sDate->Year = (uint8_t)((datetmpreg & (RTC_DR_YT | RTC_DR_YU)) >> 16);
1211 sDate->Month = (uint8_t)((datetmpreg & (RTC_DR_MT | RTC_DR_MU)) >> 8);
1212 sDate->Date = (uint8_t)(datetmpreg & (RTC_DR_DT | RTC_DR_DU));
1213 sDate->WeekDay = (uint8_t)((datetmpreg & (RTC_DR_WDU)) >> 13);
1214
1215 /* Convert the date structure parameters to Binary format */
1216 sDate->Year = (uint8_t)RTC_Bcd2ToByte(sDate->Year);
1217 sDate->Month = (uint8_t)RTC_Bcd2ToByte(sDate->Month);
1218 sDate->Date = (uint8_t)RTC_Bcd2ToByte(sDate->Date);
1219 }
1220
1221 void scheduleCheckDate(void)
1222 {
1223 uint32_t localdate;
1224 RTC_DateTypeDef sDate;
1225 localdate = (uint32_t)(RTCHandle.Instance->DR & RTC_DR_RESERVED_MASK);
1226 scheduletranslateDate(localdate, &sDate);
1227
1228 /* RTC start in year 2000 in case of a power loss. Use the operation counter time stamp to bring at last date to a more realistic value */
1229 if(sDate.Year < 15)
1230 {
1231 scheduletranslateDate(DeviceDataFlash.hoursOfOperation.date_rtc_dr, &sDate);
1232 if(sDate.Year > 16)
1233 {
1234 RTC_SetDate(sDate);
1235 }
1236 }
1237
1238 }
1239
1203 void scheduleUpdateDeviceData(void) 1240 void scheduleUpdateDeviceData(void)
1204 { 1241 {
1205 /* first step, main CPU */ 1242 /* first step, main CPU */
1206 1243
1207 if(deviceDataFlashValid) 1244 if(deviceDataFlashValid)
1208 { 1245 {
1209 /* max values */ 1246 /* max values */
1247 if(global.deviceData.hoursOfOperation.value_int32 < DeviceDataFlash.hoursOfOperation.value_int32)
1248 {
1249 scheduleCopyDeviceData(&global.deviceData.hoursOfOperation, &DeviceDataFlash.hoursOfOperation);
1250 #ifdef RESTORE_LAST_KNOWN_DATE
1251 scheduleCheckDate();
1252 #endif
1253 }
1210 if(global.deviceData.batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32) 1254 if(global.deviceData.batteryChargeCompleteCycles.value_int32 < DeviceDataFlash.batteryChargeCompleteCycles.value_int32)
1211 { 1255 {
1212 scheduleCopyDeviceData(&global.deviceData.batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles); 1256 scheduleCopyDeviceData(&global.deviceData.batteryChargeCompleteCycles, &DeviceDataFlash.batteryChargeCompleteCycles);
1213 } 1257 }
1214 if(global.deviceData.batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32) 1258 if(global.deviceData.batteryChargeCycles.value_int32 < DeviceDataFlash.batteryChargeCycles.value_int32)
1224 scheduleCopyDeviceData(&global.deviceData.depthMaximum, &DeviceDataFlash.depthMaximum); 1268 scheduleCopyDeviceData(&global.deviceData.depthMaximum, &DeviceDataFlash.depthMaximum);
1225 } 1269 }
1226 if(global.deviceData.diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32) 1270 if(global.deviceData.diveCycles.value_int32 < DeviceDataFlash.diveCycles.value_int32)
1227 { 1271 {
1228 scheduleCopyDeviceData(&global.deviceData.diveCycles, &DeviceDataFlash.diveCycles); 1272 scheduleCopyDeviceData(&global.deviceData.diveCycles, &DeviceDataFlash.diveCycles);
1229 }
1230 if(global.deviceData.hoursOfOperation.value_int32 < DeviceDataFlash.hoursOfOperation.value_int32)
1231 {
1232 scheduleCopyDeviceData(&global.deviceData.hoursOfOperation, &DeviceDataFlash.hoursOfOperation);
1233 } 1273 }
1234 1274
1235 /* min values */ 1275 /* min values */
1236 if(global.deviceData.temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32) 1276 if(global.deviceData.temperatureMinimum.value_int32 > DeviceDataFlash.temperatureMinimum.value_int32)
1237 { 1277 {
1284 deviceDataSubSeconds++; 1324 deviceDataSubSeconds++;
1285 if(deviceDataSubSeconds > 10) 1325 if(deviceDataSubSeconds > 10)
1286 { 1326 {
1287 deviceDataSubSeconds = 0; 1327 deviceDataSubSeconds = 0;
1288 global.deviceData.hoursOfOperation.value_int32++; 1328 global.deviceData.hoursOfOperation.value_int32++;
1329 scheduleSetDate(&global.deviceData.hoursOfOperation);
1289 } 1330 }
1290 break; 1331 break;
1291 1332
1292 case MODE_SLEEP: 1333 case MODE_SLEEP:
1293 case MODE_SHUTDOWN: 1334 case MODE_SHUTDOWN: