CDMS code for testing sbc
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
Diff: adf.h
- Revision:
- 9:e9eaada136c6
- Parent:
- 3:6c81fc8834e2
- Child:
- 17:6eb9387f1fb8
- Child:
- 18:f87a5b919d60
- Child:
- 19:27e5f2edaf26
- Child:
- 24:55cd06f4a534
- Child:
- 52:0bd68655c651
- Child:
- 70:c4a9b78d1c89
--- a/adf.h Thu Dec 31 10:06:45 2015 +0000 +++ b/adf.h Thu Dec 31 10:19:12 2015 +0000 @@ -1,17 +1,18 @@ //without reset feature , with state checks. InterruptIn IRQ(ADF_IRQ); Ticker ticker; - + bool sent_tmfrom_SDcard; bool loop_on; bool ADF_off; bool buffer_state; +bool finish_write_data; uint8_t signal = 0x00; unsigned char bbram_buffer[66]={0x19,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0xF4,0xC2,0x10,0xC0,0x00,0x30,0x31,0x07,0x00,0x01,0x00,0x7F,0x00,0x0B,0x37,0x00,0x00,0x40,0x0C,0x00,0x05,0x00,0x00,0x18,0x12,0x34,0x56,0x10,0x10,0xC4,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,0x00}; - + //int initialise_card(); //int disk_initialize(); - + #define bbram_write {\ SPI_mutex.lock();\ gCS_ADF=0;\ @@ -30,7 +31,7 @@ //bool assrt_phy_off( int, int, int); //bool assrt_phy_on( int,int,int); //bool assrt_phy_tx(int,int,int); - + #define START_ADDRESS 0x020; #define MISO_PIN PTE3 /**************Defining Counter Limits**************/ @@ -45,7 +46,7 @@ #define CMD_PHY_OFF 0xB0 #define CMD_PHY_TX 0xB5 #define CMD_CONFIG_DEV 0xBB - + #define check_status {\ unsigned char stat=0;\ gCS_ADF=0;\ @@ -54,7 +55,7 @@ gCS_ADF=1;\ status = stat;\ } - + // all three arguments are int #define assrt_phy_off(return_this) {\ int cmd_err_cnt = 0;\ @@ -91,8 +92,8 @@ }\ }\ } - - + + //#define assrt_phy_on(cmd_err_cnt, spi_err_cnt, state_err_cnt, return_this){\ // status=check_status();\ // if((status&0x1F)==0x12){\ @@ -124,10 +125,10 @@ // }\ // }\ //} - - - - + + + + #define initial_adf_check {\ spi.write(CMD_PHY_OFF);\ int tempReturn = 0;\ @@ -154,7 +155,7 @@ bcn_flag=1;\ }\ } - + unsigned char status =0; unsigned int cmd_err_cnt=0; unsigned int state_err_cnt=0; @@ -162,7 +163,7 @@ unsigned int hw_reset_err_cnt=0; bool bcn_flag=0; bool bbram_flag=0; - + //bool assrt_phy_off(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ // status=check_status(); // if(status==0xB1){ @@ -192,7 +193,7 @@ // return assrt_phy_off(cmd_err_cnt+1,spi_err_cnt,state_err_cnt); // } //} - + //bool assrt_phy_on(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ // status=check_status(); // if((status&0x1F)==0x12){ @@ -224,8 +225,8 @@ // } // } //} - - + + // bool assrt_phy_tx(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ // status=check_status(); // if((status & 0x1F) == 0x14){ @@ -257,7 +258,7 @@ // } // } //} - + bool hardware_reset(int bcn_call){ for(int i= 0; i < 20 ; i++){ gCS_ADF=0; @@ -282,7 +283,7 @@ } return 1; } - + //bool hardware_reset(int bcn_call){ // if (bcn_call>20){//Worst Case 20seconds will be lost ! // return 1; @@ -313,10 +314,10 @@ // return 0; // //} - - - - + + + + //void initial_adf_check(){ // spi.write(CMD_PHY_OFF); //0xB0 // while(hw_reset_err_cnt<2){ @@ -337,10 +338,10 @@ // bcn_flag=1; // } //} - + //for reseting the transmission call assert function after b5 and b1. after b1 assert_phi_on and after b5 assert_phi_tx. //---------------------------------------------------------------------------- - + # define initiate {\ SPI_mutex.lock();\ gCS_ADF=0;\ @@ -377,10 +378,17 @@ spi.write(0x39);\ spi.write(0x10);\ gCS_ADF=1;\ + gCS_ADF=0;\ + spi.write(0xBB);\ + gCS_ADF=1;\ + gCS_ADF=0;\ + spi.write(0xFF);\ + spi.write(0xFF);\ + gCS_ADF=1;\ SPI_mutex.unlock();\ } - - + + #define write_data {\ SPI_mutex.lock();\ gCS_ADF=0;\ @@ -407,29 +415,20 @@ SPI_mutex.unlock();\ buffer_state = !buffer_state;\ if(last_buffer){\ - ADF_off = true;\ + finish_write_data = true;\ gPC.puts("adf_off\r\n");\ }\ } - + void check(){ if(IRQ){ gCOM_MNG_TMTC_THREAD->signal_set(signal); } } - + #define send_data {\ - SPI_mutex.lock();\ - gCS_ADF=0;\ - spi.write(0xBB);\ - gCS_ADF=1;\ - gCS_ADF=0;\ - spi.write(0xFF);\ - spi.write(0xFF);\ - gCS_ADF=1;\ - SPI_mutex.unlock();\ if(sent_tmfrom_SDcard){\ send_tm_from_SD_card();\ }else{\ @@ -515,7 +514,7 @@ gPC.puts("sending from sd card\r\n"); adf_SND_SDCard; } - + //Timeout ADF_non_responsive_timeout; //bool ADF_non_responsive_flag = false; // @@ -523,34 +522,48 @@ // ADF_non_responsive_flag = true; // gCOM_MNG_TMTC_THREAD->signal_set(signal); //} - -void adf_not_SDcard(){ + +void configure_adf(){ + finish_write_data = false; buffer_state = true; last_buffer = false; loop_on = true; ADF_off = false; + /*initial adf check*/ + initial_adf_check; + gPC.puts("initial adf check\r\n"); + initiate; +// gPC.puts("initiate done\r\n"); + gPC.puts("adf configured\r\n"); +} + +void adf_not_SDcard(){ sent_tmfrom_SDcard = false; - + configure_adf(); signal = COM_MNG_TMTC_SIGNAL_ADF_NSD; - initial_adf_check; - initiate; send_data; // gPC.puts("Inside adf transmission\r\n"); // ADF_non_responsive_timeout.attach(&ADF_non_responsive_fun, 10); - + while(loop_on){ gCOM_MNG_TMTC_THREAD->signal_wait(COM_MNG_TMTC_SIGNAL_ADF_NSD); // if( ADF_non_responsive_flag == false ){ - if(ADF_off){ - SPI_mutex.lock(); - ticker.detach(); - // wait_ms(35); - gCS_ADF=0; - spi.write(0xB1); - gCS_ADF=1; - SPI_mutex.unlock(); - loop_on = false; + if(finish_write_data){ + if(ADF_off){ + SPI_mutex.lock(); + ticker.detach(); + // wait_ms(35); + gCS_ADF=0; + spi.write(0xB1); + gCS_ADF=1; + SPI_mutex.unlock(); + loop_on = false; + gPC.puts("Transmission done\r\n"); + } + else{ + ADF_off = true; + } }else{ write_data; snd_tm.transmit_data(buffer_112,&last_buffer); @@ -561,5 +574,4 @@ // break; // } } -} - \ No newline at end of file +} \ No newline at end of file