FM

Dependencies:   SimpleDMA eeprom mbed-rtos mbed FreescaleIAP

Fork of CDMS_CODE by shubham c

Committer:
samp1234
Date:
Sat Mar 11 04:46:31 2017 +0000
Revision:
354:0da912441c7b
Parent:
353:e1803e801e20
with obsrs 10mins implementation

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