working version
Dependencies: mbed mbed-rtos SimpleDMA FreescaleIAP eeprom
Fork of CDMS_CODE_FM_28JAN2017 by
Diff: FMS_all.h
- Revision:
- 356:197c93dc2012
- Parent:
- 355:a5e72222ff26
- Child:
- 357:f3d48d62e00e
diff -r a5e72222ff26 -r 197c93dc2012 FMS_all.h --- a/FMS_all.h Tue Mar 28 08:50:07 2017 +0000 +++ b/FMS_all.h Sat Feb 10 09:06:26 2018 +0000 @@ -81,8 +81,8 @@ void CDMS_SD_SW_ON() { - SD_CARD_fromuC_ENA3 = 1; - SD_CARD_fromISO_ENA4 = 1; + // SD_CARD_fromuC_ENA3 = 1; + // SD_CARD_fromISO_ENA4 = 1; SD_SW_EN_DS = 1; SD_STATUS = DEVICE_POWERED; FCTN_CDMS_WR_FLASH(2,DEVICE_POWERED); @@ -91,11 +91,11 @@ void CDMS_SD_SW_OFF() { - SD_CARD_fromuC_ENA3 = 0; - SD_CARD_fromISO_ENA4 = 0; + // SD_CARD_fromuC_ENA3 = 0; + // SD_CARD_fromISO_ENA4 = 0; SD_SW_EN_DS = 0; - // SD_STATUS = DEVICE_DISABLED; - SD_STATUS = 0; + SD_STATUS = DEVICE_DISABLED; + // SD_STATUS = 0; FCTN_CDMS_WR_FLASH(2,DEVICE_DISABLED); gPC.printf("sw off sd\n"); } @@ -106,14 +106,20 @@ SPI_mutex.lock(); gCS_RTC=1; gCS_RTC=0; - spi.write(0x81); //register address with write flag - spi.write(0x00);//disabling stop bit in the seconds register - gCS_RTC=1; - gCS_RTC=0; + spi.write(0x01); //reading seconds register + uint8_t response =spi.write(0x01); + response = response & 0x7F; + gCS_RTC=1; + gCS_RTC=0; spi.write(0x8C); //register address with write flag spi.write(0x00);//enabling halt bit in the seconds register gCS_RTC=1; - EN_RTC = 0x01; + gCS_RTC=0; + spi.write(0x81); //register address with write flag + spi.write(response);//disabling stop bit in the seconds register + gCS_RTC=1; + + //EN_RTC = 0x01; CDMS_RTC_DISABLE =1; FCTN_CDMS_WR_FLASH(6,DEVICE_POWERED); // gPC.printf("0x%08X \n", READ_FROM_EERPOM(6)); @@ -126,15 +132,20 @@ SPI_mutex.lock(); gCS_RTC=1; gCS_RTC=0; + spi.write(0x01); //reading seconds register + uint8_t response =spi.write(0x01); + response = response + 0x80; + gCS_RTC=1; + gCS_RTC=0; spi.write(0x81); //register address with write flag - spi.write(0x80);//enabling stop bit in the seconds register + spi.write(response);//enabling stop bit in the seconds register + also preserving the second bits in the register gCS_RTC=1; gCS_RTC=0; spi.write(0x8C); //register address with write flag spi.write(0x40);//enabling halt bit in the seconds register gCS_RTC=1; - EN_RTC = 0x00; + //EN_RTC = 0x00; CDMS_RTC_DISABLE = 0; FCTN_CDMS_WR_FLASH(6,0x00); SPI_mutex.unlock(); @@ -152,8 +163,8 @@ void SW_OFF_BAE() { BAE_SW_EN_DS = 0; - // BAE_STATUS = DEVICE_DISABLED; - BAE_STATUS = 0; + BAE_STATUS = DEVICE_DISABLED; + // BAE_STATUS = 0; FCTN_CDMS_WR_FLASH(1,DEVICE_DISABLED); gPC.printf("sw off bae\n"); } @@ -167,8 +178,8 @@ wait_us(1); PYLD_DFF_CLK = 0; wait_us(1); - PL_STATUS = DEVICE_POWERED; - FCTN_CDMS_WR_FLASH(3,DEVICE_POWERED); + PL_BEE_SW_STATUS = DEVICE_POWERED; + FCTN_CDMS_WR_FLASH(4,DEVICE_POWERED); } void SW_OFF_PL_BEE() @@ -180,9 +191,8 @@ wait_us(1); PYLD_DFF_CLK = 0; wait_us(1); - // PL_STATUS = DEVICE_DISABLED; - PL_STATUS = 0; - FCTN_CDMS_WR_FLASH(3,DEVICE_DISABLED); + PL_BEE_SW_STATUS = DEVICE_DISABLED; + FCTN_CDMS_WR_FLASH(4,DEVICE_DISABLED); } void SW_ON_PL_EPS() @@ -196,7 +206,7 @@ wait_us(1); PL_EPS_LATCH_SW_EN = 1; - FCTN_CDMS_WR_FLASH(4,1); + //FCTN_CDMS_WR_FLASH(4,1); } void SW_OFF_PL_EPS() @@ -210,7 +220,7 @@ wait_us(1); PL_EPS_LATCH_SW_EN = 0; - FCTN_CDMS_WR_FLASH(4,0); + //FCTN_CDMS_WR_FLASH(4,0); } void SW_ON_V_A_EN() @@ -254,11 +264,11 @@ void SW_RST_PL_BEE() { - PYLD_DFF = 0; + SW_OFF_PL_BEE(); wait_ms(10); - PYLD_DFF = 1; - PL_STATUS = DEVICE_POWERED; - FCTN_CDMS_WR_FLASH(3,DEVICE_POWERED); + SW_ON_PL_BEE(); + //PL_STATUS = DEVICE_POWERED; + //FCTN_CDMS_WR_FLASH(16,DEVICE_POWERED); } void RST_BAE() @@ -302,6 +312,10 @@ void RST_HK_COUNTER() { firstCount = true; + CDMS_HK_MAIN_COUNTER = 0; + PL_MAIN_COUNTER = 0; + PL_RCV_SC_DATA_COUNTER = 0; + COMRX_RESET_COUNTER = 0; } int8_t CDMS_RD_SD_HK(uint8_t *sd_statusbits) @@ -319,36 +333,50 @@ return p; } -void CDMS_CALIB_RTC(uint64_t time) +void CDMS_CALIB_RTC(uint32_t time) { + gPC.printf("\n\r Hello : %u",time); SPI_mutex.lock(); gCS_RTC=1; spi.format(8,0); spi.frequency(1000000); + gPC.printf("\n\rseconds: %u",((((((uint8_t)(time) & 0x3F)/10)<<4)+(((uint8_t)(time) & 0x3F)%10)) & 0x7F)); + gCS_RTC=0; + spi.write(0x81); + spi.write((((((uint8_t)(time) & 0x3F)/10)<<4)+(((uint8_t)(time) & 0x3F)%10)) & 0x7F);//set seconds plus stop bit = 0 + gCS_RTC=1; + + gPC.printf("\n\rminutes: %u",(((((uint8_t)(time>>6) & 0x3F)/10)<<4)+(((uint8_t)(time>>6) & 0x3F)%10))); gCS_RTC=0; spi.write(0x82); - spi.write((uint8_t)time);//set minutes + spi.write(((((uint8_t)(time>>6) & 0x3F)/10)<<4)+(((uint8_t)(time>>6) & 0x3F)%10));//set minutes gCS_RTC=1; + gPC.printf("\n\rhours: %u",(((((uint8_t)(time>>12) & 0x1F)/10)<<4)+(((uint8_t)(time>>12) & 0x1F)%10))); gCS_RTC=0; spi.write(0x83); - spi.write((uint8_t)(time>>8) & 0x3F); //set hours + spi.write(((((uint8_t)(time>>12) & 0x1F)/10)<<4)+(((uint8_t)(time>>12) & 0x1F)%10)); //set hours gCS_RTC=1; + gPC.printf("\n\rdate : %u",(((((uint8_t)(time>>17) & 0x1F)/10)<<4)+(((uint8_t)(time>>17) & 0x1F)%10))); gCS_RTC=0; spi.write(0x85); - spi.write((uint8_t)(time>>16) & 0x3F); //set date + spi.write(((((uint8_t)(time>>17) & 0x1F)/10)<<4)+(((uint8_t)(time>>17) & 0x1F)%10)); //set date gCS_RTC=1; + gPC.printf("\n\rmonth : %u",(((((uint8_t)(time>>22) & 0x0F)/10)<<4)+(((uint8_t)(time>>22) & 0x0F)%10))); gCS_RTC=0; spi.write(0x86); - spi.write((uint8_t)(time>>24) & 0x1F); //set month + spi.write(((((uint8_t)(time>>22) & 0x0F)/10)<<4)+(((uint8_t)(time>>22) & 0x0F)%10)); //set month gCS_RTC=1; + uint8_t temp = ((((uint8_t)(time>>26) & 0xFF)/10)<<4)+(((uint8_t)(time>>26) & 0xFF)%10); + gPC.printf("\n\rtemp : %u",((((uint8_t)(time>>26) & 0xFF)/10)<<4)+(((uint8_t)(time>>26) & 0xFF)%10)); + uint8_t year = (temp == 0x00)?0x16:(temp == 0x01)?0x17:(temp == 0x02)?0x18:(temp == 0x03)?0x019:0x16; gCS_RTC=0; spi.write(0x87); - spi.write((uint8_t)(time>>32)); //set year to 00(2000) + spi.write(year); //set year gCS_RTC=1; gPC.puts("\n\r rtc initalised \n"); SPI_mutex.unlock(); @@ -375,6 +403,8 @@ uint32_t time = FCTN_CDMS_RD_RTC() >> 7; //Reading Time from RTC for(int i = 124; i<128; i++) CDMS_HEALTH_DATA[i] = time >> (127-i)*8; + CDMS_HEALTH_DATA[87] = (uint8_t)(RSSI_MAX*10); + CDMS_HEALTH_DATA[103] = (uint8_t)(COM_PA_TMP_IN_TX); for(int i=0;i<128;i++) { //tm_pointer->TM_string[i] = 0; @@ -386,6 +416,7 @@ void FCTN_CDMS_MAX_MIN(Base_tm *tm_pointer) { tm_pointer->TM_string[4] = MAX_COM_ADF_TMP+40; + tm_pointer->TM_string[5] = (uint8_t)min_max_data.CDMS_temp_max; tm_pointer->TM_string[6] = (uint8_t)(MAX_RSSI_VOLTAGE*10); for(int i=0;i<16;i++) @@ -395,6 +426,7 @@ } tm_pointer->TM_string[23] = MIN_COM_ADF_TMP+40; + tm_pointer->TM_string[24] = (uint8_t)min_max_data.CDMS_temp_min; tm_pointer->TM_string[25] = (uint8_t)(MIN_RSSI_VOLTAGE*10); for(int i=0;i<16;i++) @@ -403,8 +435,8 @@ tm_pointer->TM_string[i+26] = (uint8_t)(min_max_data.temp_min[i]); } - tm_pointer->TM_string[42] = GPIO_STATUS>>8; - tm_pointer->TM_string[43] = (GPIO_STATUS<<3) & 0x00FF; + tm_pointer->TM_string[42] = GPIO_FAULTS>>8; + tm_pointer->TM_string[43] = (GPIO_FAULTS<<3) & 0x00FF; TIME_LATEST_RTC= FCTN_CDMS_RD_RTC() >> 7; for(int i = 0; i<4; i++)