working version

Dependencies:   mbed mbed-rtos SimpleDMA FreescaleIAP eeprom

Fork of CDMS_CODE_FM_28JAN2017 by samp Srinivasan

Committer:
samp1234
Date:
Sat Feb 10 09:06:26 2018 +0000
Revision:
356:197c93dc2012
Parent:
355:a5e72222ff26
Child:
357:f3d48d62e00e
Version used in QM

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