
Repository for CDMS code
Dependencies: SimpleDMA mbed-rtos mbed eeprom
Fork of COM_MNG_TMTC_SIMPLE by
Revision 317:31bb2e9eda85, committed 2016-12-08
- Comitter:
- ee12b079
- Date:
- Thu Dec 08 07:12:16 2016 +0000
- Parent:
- 313:5d06a08baf0e
- Child:
- 318:978d72f191f9
- Commit message:
- ADF temperature added,needs to be calibrated; reset functionality added, to be tested
Changed in this revision
adf.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/adf.h Tue Dec 06 09:35:26 2016 +0000 +++ b/adf.h Thu Dec 08 07:12:16 2016 +0000 @@ -26,7 +26,9 @@ unsigned int power_reset_count=0; bool Configuration_done=false; #define HW_THRS 2 - +bool hw_reset_flag = false; +uint8_t firstbyte; +uint8_t secondbyte; //int initialise_card(); //int disk_initialize(); //------------------------------------------------------------------------ @@ -35,6 +37,10 @@ //bool assrt_phy_on( int,int,int); //bool assrt_phy_tx(int,int,int); +uint8_t adf_temp = 0x00; +//ADF temperature reading +#define temp_correction_value 0 + #define TRANSMIT_LEN_1 0xFF #define TRANSMIT_LEN_2 0xFF /***/ @@ -62,6 +68,9 @@ #define BUSY 0x00 //=================================================== +#define POWER_RESET_THRS 2 +#define HW_RESET_THRS 2 + unsigned int Adf_data_counter=0; unsigned char status =0; unsigned int cmd_err_cnt=0; @@ -217,9 +226,70 @@ }\ } +bool dummy_digitalOut_1=0; +#define power_reset{\ + dummy_digitalOut_1=0;\ + wait_ms(10);\ + dummy_digitalOut_1=1;\ + power_reset_flag=false;\ + power_reset_count++;\ + wait_ms(10);\ + }\ + +void get_temp(){ +/*ADF Temperature reading*/; + gCS_ADF=0; + spi.write(0x1B); + spi.write(0x24); + spi.write(0x10); + gCS_ADF=1; + gCS_ADF=0; + spi.write(0x1B); + spi.write(0x25); + spi.write(0x02); + gCS_ADF=1; + gCS_ADF=0; + spi.write(0x1B); + spi.write(0x59); + spi.write(0x08); + gCS_ADF=1; + uint16_t sum_temp = 0; + for(int i =0; i< 10;i++) + { + gCS_ADF=0; + spi.write(0x3B); + spi.write(0x27); + spi.write(0xFF); + secondbyte = spi.write(0xFF); + gCS_ADF=1; + gCS_ADF=0; + spi.write(0x3B); + spi.write(0x28); + spi.write(0xFF); + firstbyte = spi.write(0xFF); + gCS_ADF=1; + gCS_ADF=0; + spi.write(0x3B); + spi.write(0x27); + spi.write(0xFF); + secondbyte = spi.write(0xFF); + gCS_ADF=1; + adf_temp = firstbyte<<6; + adf_temp += secondbyte; + adf_temp = (adf_temp/1.83) - 118.43 + temp_correction_value; + sum_temp+=adf_temp; + } + adf_temp = sum_temp/10; + } bool hardware_reset(int bcn_call) { + if(hw_reset_err_cnt>HW_RESET_THRS){ + power_reset_flag=true; + power_reset; + return 0; + } + for(int i= 0; i < 2 ; i++) { gCS_ADF=0; spi.write(CMD_HW_RESET); @@ -399,7 +469,15 @@ if(finish_write_data || restart_adf_flag) {\ write_data;\ ADF_off=true;\ + T.stop();\ + T.reset();\ + T.start();\ + /*ADF Temperature reading*/;\ + get_temp();\ } else {\ + T.stop();\ + T.reset();\ + T.start();\ write_data;\ if(sent_tmfrom_SDcard)\ send_tm_from_SD_card_fun();\ @@ -411,6 +489,9 @@ spi.write(0xB1);\ gCS_ADF=1;\ gPC.puts("transmission done\r\n");\ + gPC.printf("Time taken by last write_data %f msecs\n", T.read_ms());\ + T.stop();\ + T.reset();\ loop_on=false;\ if(restart_adf_flag)\ {\ @@ -421,16 +502,17 @@ CMD(CMD_PHY_TX);\ wait_us(2000);\ }\ - /*Stop_the_Timer*/\ }\ }\ - /*else{*/\ - /*if(T.read_us()>98000){*/\ - /*data_irq_err=true;*/\ - /*CMD(CMD_PHY_ON);*/\ - /*gPC.printf("Data_error_detected");*/\ - /*}*/\ - /*}*/\ + else{\ + if(T.read_us()>98000){\ + data_irq_err=true;\ + CMD(CMD_PHY_ON);\ + gPC.printf("Data_error_detected");\ + T.stop();\ + T.reset();\ + }\ + }\ } #define send_data {\ @@ -571,24 +653,35 @@ } #define transmit_adf {\ +while(power_reset_count<POWER_RESET_THRS){\ restart_adf_flag=false;\ bool tx_err=false;\ configure_adf;\ send_data;\ - CMD(CMD_PHY_TX);\ /*PA MCR level*/;\ gCS_ADF=0;\ spi.write(0x1B);\ spi.write(0x07);\ spi.write(0x35);\ gCS_ADF=1;\ + CMD(CMD_PHY_TX);\ wait_us(2000);\ + T.start();\ while(loop_on){\ wait_us(20);\ check;\ if(data_irq_err||tx_err){\ + hw_reset_err_cnt++;\ + hw_reset_flag=true;\ break;\ }\ }\ - /*gPC.puts("after while loop\r\n");*/\ -} + if(hw_reset_flag==true){\ + hardware_reset(0);\ + }\ + else{\ + break;\ + }\ + gPC.puts("after while loop\r\n");\ +}\ +} \ No newline at end of file