working version

Dependencies:   mbed mbed-rtos SimpleDMA FreescaleIAP eeprom

Fork of CDMS_CODE_FM_28JAN2017 by samp Srinivasan

Committer:
samp1234
Date:
Tue Feb 21 06:30:56 2017 +0000
Revision:
353:e1803e801e20
Parent:
352:022c513aee03
Child:
354:eb6c863756a8
with all final changes

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chaithanyarss 328:2242ebc71be8 1 #ifndef FMS_ALL_INCLUDED
chaithanyarss 328:2242ebc71be8 2 #define FMS_ALL_INCLUDED
chaithanyarss 257:7d404e9dc9e2 3
chaithanyarss 257:7d404e9dc9e2 4 // Includes MMS RAM functions also
chaithanyarss 257:7d404e9dc9e2 5
chaithanyarss 257:7d404e9dc9e2 6 /*===================================================FMS Functions=================================================*/
chaithanyarss 257:7d404e9dc9e2 7
ee12b079 209:63e9c8f8b5d2 8
ee12b079 245:da9d1bd999da 9 //Run processes
ee12b079 209:63e9c8f8b5d2 10 void P_PL_INIT();
ee12b079 209:63e9c8f8b5d2 11 void P_PL_MAIN();
ee12b079 209:63e9c8f8b5d2 12 void P_COM_INIT();
ee12b079 209:63e9c8f8b5d2 13 void P_CDMS_HK_MAIN();
ee12b079 209:63e9c8f8b5d2 14 void P_PL_RCV_SC_DATA();
ee12b079 209:63e9c8f8b5d2 15 void P_CDMS_INIT_SD();
ee12b079 245:da9d1bd999da 16
ee12b079 245:da9d1bd999da 17 // Switch ON/OFF functions
ee12b079 209:63e9c8f8b5d2 18 void CDMS_SD_SW_ON();
ee12b079 209:63e9c8f8b5d2 19 void CDMS_SD_SW_OFF();
ee12b079 245:da9d1bd999da 20 void CDMS_RTC_ON();
ee12b079 245:da9d1bd999da 21 void CDMS_RTC_OFF();
ee12b079 209:63e9c8f8b5d2 22 void SW_ON_BAE();
ee12b079 209:63e9c8f8b5d2 23 void SW_OFF_BAE();
ee12b079 209:63e9c8f8b5d2 24 void SW_ON_PL_BEE();
ee12b079 209:63e9c8f8b5d2 25 void SW_OFF_PL_BEE();
ee12b079 209:63e9c8f8b5d2 26 void SW_ON_PL_EPS();
ee12b079 209:63e9c8f8b5d2 27 void SW_OFF_PL_EPS();
ee12b079 209:63e9c8f8b5d2 28 void SW_ON_V_A_EN();
ee12b079 209:63e9c8f8b5d2 29 void SW_OFF_V_A_EN();
ee12b079 245:da9d1bd999da 30
ee12b079 245:da9d1bd999da 31 // RST functions
ee12b079 209:63e9c8f8b5d2 32 void RST_SD();
ee12b079 245:da9d1bd999da 33 void SW_RST_BAE();
ee12b079 245:da9d1bd999da 34 void SW_RST_PL_BEE();
ee12b079 209:63e9c8f8b5d2 35 void RST_BAE();
ee12b079 209:63e9c8f8b5d2 36 void RST_PL_BEE();
chaithanyarss 257:7d404e9dc9e2 37 void CDMS_RESET();
ee12b079 245:da9d1bd999da 38 void SYS_PWR_RESET(); // Have to be decided with EPS team.
aniruddhv 262:752c8689944a 39 void sys_pwr_reset(void const *args);
ee12b079 245:da9d1bd999da 40 void EPS_V_A_EN();
ee12b079 245:da9d1bd999da 41 void EPS_V_C_EN();
ee12b079 245:da9d1bd999da 42
ee12b079 209:63e9c8f8b5d2 43 void RST_HK_COUNTER();
chaithanyarss 257:7d404e9dc9e2 44 int8_t CDMS_RD_SD_HK(uint8_t *);
chaithanyarss 257:7d404e9dc9e2 45 void CDMS_CALIB_RTC(uint8_t *);
chaithanyarss 257:7d404e9dc9e2 46 void TOTAL_RESET_WITH_CDMS();
chaithanyarss 257:7d404e9dc9e2 47
aniruddhv 262:752c8689944a 48 void sys_pwr_reset(void const *args){
aniruddhv 262:752c8689944a 49 SYS_PWR_RESET();
aniruddhv 262:752c8689944a 50 }
ee12b079 245:da9d1bd999da 51
ee12b079 209:63e9c8f8b5d2 52 void P_PL_INIT()
ee12b079 209:63e9c8f8b5d2 53 {
ee12b079 209:63e9c8f8b5d2 54
ee12b079 209:63e9c8f8b5d2 55 }
ee12b079 209:63e9c8f8b5d2 56
ee12b079 209:63e9c8f8b5d2 57 void P_PL_MAIN()
ee12b079 209:63e9c8f8b5d2 58 {
chaithanyarss 257:7d404e9dc9e2 59 FCTN_CDMS_PL_MAIN((void *)NULL);
ee12b079 209:63e9c8f8b5d2 60 }
ee12b079 209:63e9c8f8b5d2 61
ee12b079 209:63e9c8f8b5d2 62 void P_COM_INIT()
ee12b079 209:63e9c8f8b5d2 63 {
ee12b079 245:da9d1bd999da 64 P_COM_INIT;
ee12b079 209:63e9c8f8b5d2 65 }
ee12b079 209:63e9c8f8b5d2 66
ee12b079 209:63e9c8f8b5d2 67 void P_CDMS_HK_MAIN()
ee12b079 209:63e9c8f8b5d2 68 {
ee12b079 245:da9d1bd999da 69 FCTN_CDMS_HK_MAIN((void *)NULL);
ee12b079 209:63e9c8f8b5d2 70 }
ee12b079 209:63e9c8f8b5d2 71
ee12b079 209:63e9c8f8b5d2 72 void P_PL_RCV_SC_DATA()
ee12b079 209:63e9c8f8b5d2 73 {
ee12b079 245:da9d1bd999da 74
ee12b079 209:63e9c8f8b5d2 75 }
ee12b079 209:63e9c8f8b5d2 76
ee12b079 209:63e9c8f8b5d2 77 void P_CDMS_INIT_SD()
ee12b079 209:63e9c8f8b5d2 78 {
ee12b079 209:63e9c8f8b5d2 79 FCTN_CDMS_SD_INIT();
ee12b079 209:63e9c8f8b5d2 80 }
ee12b079 209:63e9c8f8b5d2 81
ee12b079 209:63e9c8f8b5d2 82 void CDMS_SD_SW_ON()
ee12b079 209:63e9c8f8b5d2 83 {
samp1234 352:022c513aee03 84 SD_CARD_fromuC_ENA3 = 1;
samp1234 352:022c513aee03 85 SD_CARD_fromISO_ENA4 = 1;
ee12b079 289:9bd62b69874c 86 SD_SW_EN_DS = 1;
chaithanyarss 261:1e54415b34d3 87 SD_STATUS = DEVICE_POWERED;
chaithanyarss 351:a89a46894ec0 88 WRITE_TO_EEPROM(2,DEVICE_POWERED);
chaithanyarss 261:1e54415b34d3 89 gPC.printf("sw on sd\n");
ee12b079 209:63e9c8f8b5d2 90 }
ee12b079 209:63e9c8f8b5d2 91
ee12b079 209:63e9c8f8b5d2 92 void CDMS_SD_SW_OFF()
ee12b079 209:63e9c8f8b5d2 93 {
samp1234 352:022c513aee03 94 SD_CARD_fromuC_ENA3 = 0;
samp1234 352:022c513aee03 95 SD_CARD_fromISO_ENA4 = 0;
ee12b079 289:9bd62b69874c 96 SD_SW_EN_DS = 0;
chaithanyarss 261:1e54415b34d3 97 SD_STATUS = DEVICE_DISABLED;
chaithanyarss 351:a89a46894ec0 98 WRITE_TO_EEPROM(2,DEVICE_DISABLED);
chaithanyarss 261:1e54415b34d3 99 gPC.printf("sw off sd\n");
ee12b079 209:63e9c8f8b5d2 100 }
ee12b079 209:63e9c8f8b5d2 101
ee12b079 245:da9d1bd999da 102 void CDMS_RTC_ON()
ee12b079 209:63e9c8f8b5d2 103 {
chaithanyarss 257:7d404e9dc9e2 104 //FCTN_CDMS_INIT_RTC();
chaithanyarss 257:7d404e9dc9e2 105 SPI_mutex.lock();
chaithanyarss 257:7d404e9dc9e2 106 gCS_RTC=1;
chaithanyarss 257:7d404e9dc9e2 107 gCS_RTC=0;
chaithanyarss 257:7d404e9dc9e2 108 spi.write(0x81); //register address with write flag
chaithanyarss 257:7d404e9dc9e2 109 spi.write(0x00);//disabling stop bit in the seconds register
samp1234 353:e1803e801e20 110 gCS_RTC=1;
samp1234 353:e1803e801e20 111 gCS_RTC=0;
samp1234 353:e1803e801e20 112 spi.write(0x8C); //register address with write flag
samp1234 353:e1803e801e20 113 spi.write(0x00);//enabling halt bit in the seconds register
samp1234 353:e1803e801e20 114 gCS_RTC=1;
samp1234 353:e1803e801e20 115 EN_RTC = 0x01;
samp1234 353:e1803e801e20 116 // CDMS_RTC_DISABLE =1;
samp1234 353:e1803e801e20 117 WRITE_TO_EEPROM(6,1);
chaithanyarss 257:7d404e9dc9e2 118 SPI_mutex.unlock();
chaithanyarss 261:1e54415b34d3 119 gPC.printf("sw on rtc\n");
ee12b079 209:63e9c8f8b5d2 120 }
ee12b079 209:63e9c8f8b5d2 121
ee12b079 245:da9d1bd999da 122 void CDMS_RTC_OFF()
ee12b079 209:63e9c8f8b5d2 123 {
chaithanyarss 257:7d404e9dc9e2 124 SPI_mutex.lock();
chaithanyarss 257:7d404e9dc9e2 125 gCS_RTC=1;
chaithanyarss 257:7d404e9dc9e2 126 gCS_RTC=0;
chaithanyarss 257:7d404e9dc9e2 127 spi.write(0x81); //register address with write flag
chaithanyarss 257:7d404e9dc9e2 128 spi.write(0x80);//enabling stop bit in the seconds register
samp1234 353:e1803e801e20 129 gCS_RTC=1;
samp1234 353:e1803e801e20 130 gCS_RTC=0;
samp1234 353:e1803e801e20 131 spi.write(0x8C); //register address with write flag
samp1234 353:e1803e801e20 132 spi.write(0x40);//enabling halt bit in the seconds register
samp1234 353:e1803e801e20 133 gCS_RTC=1;
samp1234 353:e1803e801e20 134
samp1234 353:e1803e801e20 135 EN_RTC = 0x00;
samp1234 353:e1803e801e20 136 // CDMS_RTC_DISABLE = 0;
samp1234 353:e1803e801e20 137 WRITE_TO_EEPROM(6,0);
chaithanyarss 257:7d404e9dc9e2 138 SPI_mutex.unlock();
chaithanyarss 261:1e54415b34d3 139 gPC.printf("sw off rtc\n");
ee12b079 209:63e9c8f8b5d2 140 }
ee12b079 209:63e9c8f8b5d2 141
ee12b079 245:da9d1bd999da 142 void SW_ON_BAE()
ee12b079 245:da9d1bd999da 143 {
ee12b079 289:9bd62b69874c 144 BAE_SW_EN_DS = 1;
chaithanyarss 261:1e54415b34d3 145 BAE_STATUS = DEVICE_POWERED;
chaithanyarss 351:a89a46894ec0 146 WRITE_TO_EEPROM(1,DEVICE_POWERED);
chaithanyarss 261:1e54415b34d3 147 gPC.printf("sw on bae\n");
ee12b079 245:da9d1bd999da 148 }
ee12b079 245:da9d1bd999da 149
ee12b079 245:da9d1bd999da 150 void SW_OFF_BAE()
ee12b079 245:da9d1bd999da 151 {
ee12b079 289:9bd62b69874c 152 BAE_SW_EN_DS = 0;
chaithanyarss 261:1e54415b34d3 153 BAE_STATUS = DEVICE_DISABLED;
chaithanyarss 351:a89a46894ec0 154 WRITE_TO_EEPROM(1,DEVICE_DISABLED);
chaithanyarss 261:1e54415b34d3 155 gPC.printf("sw off bae\n");
ee12b079 245:da9d1bd999da 156 }
ee12b079 245:da9d1bd999da 157
ee12b079 245:da9d1bd999da 158 void SW_ON_PL_BEE()
ee12b079 245:da9d1bd999da 159 {
chaithanyarss 261:1e54415b34d3 160 PYLD_DFF_CLK = 0;
chaithanyarss 261:1e54415b34d3 161 PYLD_DFF = 1;
chaithanyarss 261:1e54415b34d3 162 wait_us(1);
chaithanyarss 261:1e54415b34d3 163 PYLD_DFF_CLK = 1;
chaithanyarss 261:1e54415b34d3 164 wait_us(1);
chaithanyarss 261:1e54415b34d3 165 PYLD_DFF_CLK = 0;
chaithanyarss 261:1e54415b34d3 166 wait_us(1);
chaithanyarss 261:1e54415b34d3 167 PL_STATUS = DEVICE_POWERED;
chaithanyarss 351:a89a46894ec0 168 WRITE_TO_EEPROM(3,DEVICE_POWERED);
ee12b079 245:da9d1bd999da 169 }
ee12b079 245:da9d1bd999da 170
ee12b079 245:da9d1bd999da 171 void SW_OFF_PL_BEE()
ee12b079 245:da9d1bd999da 172 {
ee12b079 245:da9d1bd999da 173 PYLD_DFF_CLK = 0;
ee12b079 245:da9d1bd999da 174 PYLD_DFF = 0;
ee12b079 245:da9d1bd999da 175 wait_us(1);
ee12b079 245:da9d1bd999da 176 PYLD_DFF_CLK = 1;
ee12b079 245:da9d1bd999da 177 wait_us(1);
ee12b079 245:da9d1bd999da 178 PYLD_DFF_CLK = 0;
ee12b079 245:da9d1bd999da 179 wait_us(1);
chaithanyarss 261:1e54415b34d3 180 PL_STATUS = DEVICE_DISABLED;
chaithanyarss 351:a89a46894ec0 181 WRITE_TO_EEPROM(3,DEVICE_DISABLED);
ee12b079 245:da9d1bd999da 182 }
ee12b079 245:da9d1bd999da 183
ee12b079 245:da9d1bd999da 184 void SW_ON_PL_EPS()
ee12b079 245:da9d1bd999da 185 {
chaithanyarss 261:1e54415b34d3 186 PYLD_EPS_DFF_PWR_CLK = 0;
chaithanyarss 261:1e54415b34d3 187 PYLD_EPS_DFF_PWR = 1;
chaithanyarss 261:1e54415b34d3 188 wait_us(1);
chaithanyarss 261:1e54415b34d3 189 PYLD_EPS_DFF_PWR_CLK = 1;
chaithanyarss 261:1e54415b34d3 190 wait_us(1);
chaithanyarss 261:1e54415b34d3 191 PYLD_EPS_DFF_PWR_CLK = 0;
chaithanyarss 261:1e54415b34d3 192 wait_us(1);
chaithanyarss 261:1e54415b34d3 193 PL_EPS_LATCH_SW_EN = 1;
chaithanyarss 351:a89a46894ec0 194 WRITE_TO_EEPROM(4,1);
ee12b079 245:da9d1bd999da 195 }
ee12b079 245:da9d1bd999da 196
ee12b079 209:63e9c8f8b5d2 197 void SW_OFF_PL_EPS()
ee12b079 209:63e9c8f8b5d2 198 {
chaithanyarss 261:1e54415b34d3 199 PYLD_EPS_DFF_PWR_CLK = 0;
chaithanyarss 261:1e54415b34d3 200 PYLD_EPS_DFF_PWR = 0;
chaithanyarss 261:1e54415b34d3 201 wait_us(1);
chaithanyarss 261:1e54415b34d3 202 PYLD_EPS_DFF_PWR_CLK = 1;
chaithanyarss 261:1e54415b34d3 203 wait_us(1);
chaithanyarss 261:1e54415b34d3 204 PYLD_EPS_DFF_PWR_CLK = 0;
chaithanyarss 261:1e54415b34d3 205 wait_us(1);
chaithanyarss 261:1e54415b34d3 206 PL_EPS_LATCH_SW_EN = 0;
chaithanyarss 351:a89a46894ec0 207 WRITE_TO_EEPROM(4,0);
ee12b079 209:63e9c8f8b5d2 208 }
ee12b079 209:63e9c8f8b5d2 209
ee12b079 209:63e9c8f8b5d2 210 void SW_ON_V_A_EN()
ee12b079 209:63e9c8f8b5d2 211 {
chaithanyarss 257:7d404e9dc9e2 212 V_A_EN = 1;
chaithanyarss 261:1e54415b34d3 213 EPS_V_A_EN_STATUS = 1;
chaithanyarss 351:a89a46894ec0 214 WRITE_TO_EEPROM(0,1);
ee12b079 209:63e9c8f8b5d2 215 }
ee12b079 209:63e9c8f8b5d2 216
ee12b079 209:63e9c8f8b5d2 217 void SW_OFF_V_A_EN()
ee12b079 209:63e9c8f8b5d2 218 {
chaithanyarss 257:7d404e9dc9e2 219 V_A_EN = 0;
chaithanyarss 261:1e54415b34d3 220 EPS_V_A_EN_STATUS = 0;
chaithanyarss 351:a89a46894ec0 221 WRITE_TO_EEPROM(0,0);
ee12b079 209:63e9c8f8b5d2 222 }
ee12b079 209:63e9c8f8b5d2 223
ee12b079 209:63e9c8f8b5d2 224 void RST_SD()
ee12b079 209:63e9c8f8b5d2 225 {
samp1234 352:022c513aee03 226 SD_CARD_fromuC_ENA3 = 0;
samp1234 352:022c513aee03 227 SD_CARD_fromISO_ENA4 = 0;
ee12b079 289:9bd62b69874c 228 SD_SW_EN_DS = 0;
ee12b079 209:63e9c8f8b5d2 229 wait_ms(10);
samp1234 352:022c513aee03 230 SD_CARD_fromuC_ENA3 = 1;
samp1234 352:022c513aee03 231 SD_CARD_fromISO_ENA4 = 1;
ee12b079 289:9bd62b69874c 232 SD_SW_EN_DS = 1;
ee12b079 289:9bd62b69874c 233 SD_STATUS = DEVICE_POWERED;
chaithanyarss 351:a89a46894ec0 234 WRITE_TO_EEPROM(2,DEVICE_POWERED);
chaithanyarss 261:1e54415b34d3 235 gPC.printf("rst sd\n");
ee12b079 245:da9d1bd999da 236 }
ee12b079 245:da9d1bd999da 237
ee12b079 245:da9d1bd999da 238 void SW_RST_BAE()
ee12b079 245:da9d1bd999da 239 {
samp1234 353:e1803e801e20 240 BAE_SW_EN_DS = 0;
samp1234 353:e1803e801e20 241 wait(5);
samp1234 353:e1803e801e20 242 BAE_SW_EN_DS = 1;
samp1234 353:e1803e801e20 243
ee12b079 289:9bd62b69874c 244 BAE_STATUS = DEVICE_POWERED;
chaithanyarss 351:a89a46894ec0 245 WRITE_TO_EEPROM(1,DEVICE_POWERED);
chaithanyarss 261:1e54415b34d3 246 gPC.printf("rst bae\n");
ee12b079 245:da9d1bd999da 247 }
ee12b079 245:da9d1bd999da 248
ee12b079 245:da9d1bd999da 249 void SW_RST_PL_BEE()
ee12b079 245:da9d1bd999da 250 {
ee12b079 289:9bd62b69874c 251 PYLD_DFF = 0;
ee12b079 245:da9d1bd999da 252 wait_ms(10);
ee12b079 289:9bd62b69874c 253 PYLD_DFF = 1;
ee12b079 289:9bd62b69874c 254 PL_STATUS = DEVICE_POWERED;
chaithanyarss 351:a89a46894ec0 255 WRITE_TO_EEPROM(3,DEVICE_POWERED);
ee12b079 209:63e9c8f8b5d2 256 }
ee12b079 209:63e9c8f8b5d2 257
ee12b079 209:63e9c8f8b5d2 258 void RST_BAE()
ee12b079 209:63e9c8f8b5d2 259 {
ee12b079 289:9bd62b69874c 260 RESET_TO_BAE = 0;
ee12b079 209:63e9c8f8b5d2 261 wait_ms(10);
ee12b079 289:9bd62b69874c 262 RESET_TO_BAE = 1;
ee12b079 209:63e9c8f8b5d2 263 }
ee12b079 209:63e9c8f8b5d2 264
ee12b079 209:63e9c8f8b5d2 265 void RST_PL_BEE()
ee12b079 209:63e9c8f8b5d2 266 {
ee12b079 289:9bd62b69874c 267 RESET_TO_PYLD = 0;
ee12b079 209:63e9c8f8b5d2 268 wait_ms(10);
ee12b079 289:9bd62b69874c 269 RESET_TO_PYLD = 1;
ee12b079 245:da9d1bd999da 270 }
ee12b079 245:da9d1bd999da 271
ee12b079 245:da9d1bd999da 272 void CDMS_INTERNAL_RESET()
ee12b079 245:da9d1bd999da 273 {
ee12b079 245:da9d1bd999da 274 NVIC_SystemReset();
ee12b079 245:da9d1bd999da 275 }
ee12b079 245:da9d1bd999da 276
ee12b079 245:da9d1bd999da 277 void SYS_PWR_RESET() // Have to be decided with EPS team.
ee12b079 245:da9d1bd999da 278 {
ee12b079 287:a387337491f7 279 //sys_pwr_rst = 1;
ee12b079 245:da9d1bd999da 280 }
ee12b079 245:da9d1bd999da 281
ee12b079 245:da9d1bd999da 282 void EPS_V_A_EN() // This is a reset function
ee12b079 245:da9d1bd999da 283 {
chaithanyarss 257:7d404e9dc9e2 284 V_A_EN = 0;
ee12b079 245:da9d1bd999da 285 wait_ms(10);
chaithanyarss 257:7d404e9dc9e2 286 V_A_EN = 1;
ee12b079 245:da9d1bd999da 287 }
ee12b079 245:da9d1bd999da 288
ee12b079 245:da9d1bd999da 289 void EPS_V_C_EN() // This is a reset function
ee12b079 245:da9d1bd999da 290 {
ee12b079 245:da9d1bd999da 291 COM_RX_CNTRL = 0;
ee12b079 245:da9d1bd999da 292 wait_ms(10);
ee12b079 245:da9d1bd999da 293 COM_RX_CNTRL = 1;
ee12b079 209:63e9c8f8b5d2 294 }
ee12b079 209:63e9c8f8b5d2 295
ee12b079 209:63e9c8f8b5d2 296 void RST_HK_COUNTER()
ee12b079 209:63e9c8f8b5d2 297 {
ee12b079 209:63e9c8f8b5d2 298 firstCount = true;
ee12b079 209:63e9c8f8b5d2 299 }
ee12b079 209:63e9c8f8b5d2 300
chaithanyarss 257:7d404e9dc9e2 301 int8_t CDMS_RD_SD_HK(uint8_t *sd_statusbits)
ee12b079 209:63e9c8f8b5d2 302 {
chaithanyarss 257:7d404e9dc9e2 303 int8_t p;
ee12b079 209:63e9c8f8b5d2 304 if(SD_SW_EN_DS != DEVICE_POWERED)
ee12b079 209:63e9c8f8b5d2 305 {
ee12b079 209:63e9c8f8b5d2 306 SD_RD_ERROR = 1;
chaithanyarss 257:7d404e9dc9e2 307 p = 1;
ee12b079 209:63e9c8f8b5d2 308 }
ee12b079 209:63e9c8f8b5d2 309 else
ee12b079 209:63e9c8f8b5d2 310 {
ee12b079 209:63e9c8f8b5d2 311 p = disk_read_statusbits(sd_statusbits);
ee12b079 209:63e9c8f8b5d2 312 }
chaithanyarss 257:7d404e9dc9e2 313 return p;
ee12b079 209:63e9c8f8b5d2 314 }
ee12b079 209:63e9c8f8b5d2 315
chaithanyarss 261:1e54415b34d3 316 void CDMS_CALIB_RTC(uint64_t time)
ee12b079 245:da9d1bd999da 317 {
chaithanyarss 257:7d404e9dc9e2 318 SPI_mutex.lock();
chaithanyarss 257:7d404e9dc9e2 319 gCS_RTC=1;
chaithanyarss 257:7d404e9dc9e2 320 spi.format(8,0);
chaithanyarss 257:7d404e9dc9e2 321 spi.frequency(1000000);
chaithanyarss 257:7d404e9dc9e2 322
chaithanyarss 257:7d404e9dc9e2 323 gCS_RTC=0;
chaithanyarss 257:7d404e9dc9e2 324 spi.write(0x82);
chaithanyarss 261:1e54415b34d3 325 spi.write((uint8_t)time);//set minutes
chaithanyarss 257:7d404e9dc9e2 326 gCS_RTC=1;
chaithanyarss 257:7d404e9dc9e2 327
chaithanyarss 257:7d404e9dc9e2 328 gCS_RTC=0;
chaithanyarss 257:7d404e9dc9e2 329 spi.write(0x83);
chaithanyarss 261:1e54415b34d3 330 spi.write((uint8_t)(time>>8) & 0x3F); //set hours
chaithanyarss 257:7d404e9dc9e2 331 gCS_RTC=1;
ee12b079 245:da9d1bd999da 332
chaithanyarss 257:7d404e9dc9e2 333 gCS_RTC=0;
chaithanyarss 257:7d404e9dc9e2 334 spi.write(0x85);
chaithanyarss 261:1e54415b34d3 335 spi.write((uint8_t)(time>>16) & 0x3F); //set date
chaithanyarss 257:7d404e9dc9e2 336 gCS_RTC=1;
chaithanyarss 257:7d404e9dc9e2 337
chaithanyarss 257:7d404e9dc9e2 338 gCS_RTC=0;
chaithanyarss 257:7d404e9dc9e2 339 spi.write(0x86);
chaithanyarss 261:1e54415b34d3 340 spi.write((uint8_t)(time>>24) & 0x1F); //set month
chaithanyarss 257:7d404e9dc9e2 341 gCS_RTC=1;
chaithanyarss 257:7d404e9dc9e2 342
chaithanyarss 257:7d404e9dc9e2 343 gCS_RTC=0;
chaithanyarss 257:7d404e9dc9e2 344 spi.write(0x87);
chaithanyarss 261:1e54415b34d3 345 spi.write((uint8_t)(time>>32)); //set year to 00(2000)
chaithanyarss 257:7d404e9dc9e2 346 gCS_RTC=1;
chaithanyarss 257:7d404e9dc9e2 347 gPC.puts("\n\r rtc initalised \n");
chaithanyarss 257:7d404e9dc9e2 348 SPI_mutex.unlock();
ee12b079 245:da9d1bd999da 349 }
ee12b079 245:da9d1bd999da 350
chaithanyarss 224:3ac1f91e0ebc 351 void CDMS_RESET()
chaithanyarss 224:3ac1f91e0ebc 352 {
chaithanyarss 224:3ac1f91e0ebc 353 NVIC_SystemReset();
chaithanyarss 224:3ac1f91e0ebc 354 }
chaithanyarss 224:3ac1f91e0ebc 355
ee12b079 245:da9d1bd999da 356 /*
ee12b079 245:da9d1bd999da 357 //void CDMS_INTERNAL_RESET()
ee12b079 209:63e9c8f8b5d2 358 {
ee12b079 209:63e9c8f8b5d2 359
ee12b079 245:da9d1bd999da 360 }
chaithanyarss 257:7d404e9dc9e2 361 */
chaithanyarss 257:7d404e9dc9e2 362
chaithanyarss 257:7d404e9dc9e2 363 //===============================MMS RAM functions==================================
chaithanyarss 257:7d404e9dc9e2 364
chaithanyarss 257:7d404e9dc9e2 365 void FCTN_CDMS_RD_L_RAM(Base_tm *);
chaithanyarss 257:7d404e9dc9e2 366
chaithanyarss 257:7d404e9dc9e2 367 void FCTN_CDMS_RD_L_RAM(Base_tm *tm_pointer)
chaithanyarss 257:7d404e9dc9e2 368 {
spacelab 330:6ac9661f2e10 369 uint32_t time = FCTN_CDMS_RD_RTC() >> 7; //Reading Time from RTC
spacelab 330:6ac9661f2e10 370 for(int i = 124; i<128; i++)
spacelab 330:6ac9661f2e10 371 CDMS_HEALTH_DATA[i] = time >> (127-i)*8;
ee12b079 301:701ac67649b7 372 for(int i=0;i<128;i++)
chaithanyarss 303:b49b486a7107 373 {
chaithanyarss 303:b49b486a7107 374 //tm_pointer->TM_string[i] = 0;
chaithanyarss 303:b49b486a7107 375 tm_pointer->TM_string[i+4] = CDMS_HEALTH_DATA[i];
chaithanyarss 303:b49b486a7107 376 }
spacelab 330:6ac9661f2e10 377
ee12b079 322:7d906d34aaff 378 }
ee12b079 322:7d906d34aaff 379
ee12b079 322:7d906d34aaff 380 void FCTN_CDMS_MAX_MIN(Base_tm *tm_pointer)
ee12b079 322:7d906d34aaff 381 {
chaithanyarss 333:cddef120cae3 382 tm_pointer->TM_string[4] = MAX_COM_ADF_TMP+40;
chaithanyarss 333:cddef120cae3 383 tm_pointer->TM_string[6] = (uint8_t)(MAX_RSSI_VOLTAGE*10);
ee12b079 322:7d906d34aaff 384
ee12b079 322:7d906d34aaff 385 for(int i=0;i<16;i++)
ee12b079 322:7d906d34aaff 386 {
ee12b079 322:7d906d34aaff 387 //tm_pointer->TM_string[i] = 0;
chaithanyarss 333:cddef120cae3 388 tm_pointer->TM_string[i+7] = (uint8_t)(min_max_data.temp_max[i]);
chaithanyarss 333:cddef120cae3 389 }
chaithanyarss 333:cddef120cae3 390
chaithanyarss 333:cddef120cae3 391 tm_pointer->TM_string[23] = MIN_COM_ADF_TMP+40;
chaithanyarss 333:cddef120cae3 392 tm_pointer->TM_string[25] = (uint8_t)(MIN_RSSI_VOLTAGE*10);
chaithanyarss 333:cddef120cae3 393
chaithanyarss 333:cddef120cae3 394 for(int i=0;i<16;i++)
chaithanyarss 333:cddef120cae3 395 {
chaithanyarss 333:cddef120cae3 396 //tm_pointer->TM_string[i] = 0;
chaithanyarss 333:cddef120cae3 397 tm_pointer->TM_string[i+26] = (uint8_t)(min_max_data.temp_min[i]);
ee12b079 322:7d906d34aaff 398 }
ee12b079 322:7d906d34aaff 399
chaithanyarss 328:2242ebc71be8 400 tm_pointer->TM_string[42] = GPIO_STATUS>>8;
chaithanyarss 328:2242ebc71be8 401 tm_pointer->TM_string[43] = (GPIO_STATUS<<3) & 0x00FF;
ee12b079 322:7d906d34aaff 402
ee12b079 322:7d906d34aaff 403 TIME_LATEST_RTC= FCTN_CDMS_RD_RTC() >> 7;
ee12b079 322:7d906d34aaff 404 for(int i = 0; i<4; i++)
chaithanyarss 328:2242ebc71be8 405 tm_pointer->TM_string[44+i] = TIME_LATEST_RTC >> (3-i)*8;
chaithanyarss 328:2242ebc71be8 406 }
chaithanyarss 328:2242ebc71be8 407
chaithanyarss 328:2242ebc71be8 408 #endif