11th feb i2c checking chaitu's code

Dependencies:   SimpleDMA eeprom mbed-rtos mbed

Fork of CDMS_CODE_FM_28JAN2017 by samp Srinivasan

Committer:
chaithanyarss
Date:
Fri Feb 10 20:37:45 2017 +0000
Revision:
353:890c6b98392a
Parent:
352:022c513aee03
11th feb ; checking i2c..; chaitu's code

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