working version

Dependencies:   mbed mbed-rtos SimpleDMA FreescaleIAP eeprom

Fork of CDMS_CODE_FM_28JAN2017 by samp Srinivasan

Committer:
samp1234
Date:
Tue Mar 28 08:50:07 2017 +0000
Revision:
355:a5e72222ff26
Parent:
354:eb6c863756a8
Child:
356:197c93dc2012
Final with 1min obsrs

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