CDMS_CODE_samp_23SEP_DMA_flag
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE_samp_23SEP_DMA by
adf.h@28:cd3212fe5643, 2016-01-03 (annotated)
- Committer:
- ee12b079
- Date:
- Sun Jan 03 12:01:42 2016 +0000
- Revision:
- 28:cd3212fe5643
- Parent:
- 25:60964ad4f13b
data partially matching for stand alone code as well
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shreeshas95 | 1:a0055b3280c8 | 1 | //without reset feature , with state checks. |
shreeshas95 | 2:2caf2a9a13aa | 2 | InterruptIn IRQ(ADF_IRQ); |
ee12b079 | 9:e9eaada136c6 | 3 | |
shreeshas95 | 1:a0055b3280c8 | 4 | bool sent_tmfrom_SDcard; |
shreeshas95 | 1:a0055b3280c8 | 5 | bool loop_on; |
shreeshas95 | 1:a0055b3280c8 | 6 | bool ADF_off; |
shreeshas95 | 1:a0055b3280c8 | 7 | bool buffer_state; |
ee12b079 | 9:e9eaada136c6 | 8 | bool finish_write_data; |
shreeshas95 | 1:a0055b3280c8 | 9 | uint8_t signal = 0x00; |
shreeshas95 | 1:a0055b3280c8 | 10 | 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}; |
ee12b079 | 9:e9eaada136c6 | 11 | |
shreeshas95 | 2:2caf2a9a13aa | 12 | //int initialise_card(); |
shreeshas95 | 2:2caf2a9a13aa | 13 | //int disk_initialize(); |
ee12b079 | 9:e9eaada136c6 | 14 | |
shreeshas95 | 1:a0055b3280c8 | 15 | #define bbram_write {\ |
shreeshas95 | 1:a0055b3280c8 | 16 | SPI_mutex.lock();\ |
shreeshas95 | 1:a0055b3280c8 | 17 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 18 | spi.write(0xB0);\ |
shreeshas95 | 1:a0055b3280c8 | 19 | wait_us(300);\ |
shreeshas95 | 1:a0055b3280c8 | 20 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 21 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 22 | for(int i=0;i<66;i++){\ |
shreeshas95 | 1:a0055b3280c8 | 23 | spi.write(bbram_buffer[i]);\ |
shreeshas95 | 1:a0055b3280c8 | 24 | }\ |
shreeshas95 | 1:a0055b3280c8 | 25 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 26 | SPI_mutex.unlock();\ |
shreeshas95 | 1:a0055b3280c8 | 27 | } |
shreeshas95 | 1:a0055b3280c8 | 28 | //------------------------------------------------------------------------ |
shreeshas95 | 1:a0055b3280c8 | 29 | // state checking functions |
shreeshas95 | 1:a0055b3280c8 | 30 | //bool assrt_phy_off( int, int, int); |
shreeshas95 | 1:a0055b3280c8 | 31 | //bool assrt_phy_on( int,int,int); |
shreeshas95 | 1:a0055b3280c8 | 32 | //bool assrt_phy_tx(int,int,int); |
ee12b079 | 9:e9eaada136c6 | 33 | |
shreeshas95 | 1:a0055b3280c8 | 34 | #define START_ADDRESS 0x020; |
shreeshas95 | 1:a0055b3280c8 | 35 | #define MISO_PIN PTE3 |
shreeshas95 | 1:a0055b3280c8 | 36 | /**************Defining Counter Limits**************/ |
shreeshas95 | 1:a0055b3280c8 | 37 | #define THRS 20 |
shreeshas95 | 1:a0055b3280c8 | 38 | #define STATE_ERR_THRS 20 |
shreeshas95 | 1:a0055b3280c8 | 39 | #define PHY_OFF_EXEC_TIME 300 |
shreeshas95 | 1:a0055b3280c8 | 40 | #define PHY_ON_EXEC_TIME 300 |
shreeshas95 | 1:a0055b3280c8 | 41 | #define PHY_TX_EXEC_TIME 600 |
shreeshas95 | 1:a0055b3280c8 | 42 | /******DEFINING COMMANDS*********/ |
shreeshas95 | 1:a0055b3280c8 | 43 | #define CMD_HW_RESET 0xC8 |
shreeshas95 | 1:a0055b3280c8 | 44 | #define CMD_PHY_ON 0xB1 |
shreeshas95 | 1:a0055b3280c8 | 45 | #define CMD_PHY_OFF 0xB0 |
shreeshas95 | 1:a0055b3280c8 | 46 | #define CMD_PHY_TX 0xB5 |
shreeshas95 | 1:a0055b3280c8 | 47 | #define CMD_CONFIG_DEV 0xBB |
ee12b079 | 9:e9eaada136c6 | 48 | |
shreeshas95 | 1:a0055b3280c8 | 49 | #define check_status {\ |
shreeshas95 | 1:a0055b3280c8 | 50 | unsigned char stat=0;\ |
shreeshas95 | 1:a0055b3280c8 | 51 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 52 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 53 | stat = spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 54 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 55 | status = stat;\ |
shreeshas95 | 1:a0055b3280c8 | 56 | } |
ee12b079 | 9:e9eaada136c6 | 57 | |
shreeshas95 | 1:a0055b3280c8 | 58 | // all three arguments are int |
shreeshas95 | 1:a0055b3280c8 | 59 | #define assrt_phy_off(return_this) {\ |
shreeshas95 | 1:a0055b3280c8 | 60 | int cmd_err_cnt = 0;\ |
shreeshas95 | 1:a0055b3280c8 | 61 | int spi_err_cnt = 0;\ |
shreeshas95 | 1:a0055b3280c8 | 62 | int state_err_cnt = 0;\ |
shreeshas95 | 1:a0055b3280c8 | 63 | for(int i = 0 ; i < 40 ;i++){\ |
shreeshas95 | 1:a0055b3280c8 | 64 | check_status;\ |
shreeshas95 | 1:a0055b3280c8 | 65 | if(status == 0xB1){\ |
shreeshas95 | 1:a0055b3280c8 | 66 | return_this = 0;\ |
shreeshas95 | 1:a0055b3280c8 | 67 | break;\ |
shreeshas95 | 1:a0055b3280c8 | 68 | }\ |
shreeshas95 | 1:a0055b3280c8 | 69 | else if(cmd_err_cnt>THRS||spi_err_cnt>THRS){\ |
shreeshas95 | 1:a0055b3280c8 | 70 | return_this = 1;\ |
shreeshas95 | 1:a0055b3280c8 | 71 | break;\ |
shreeshas95 | 1:a0055b3280c8 | 72 | }\ |
shreeshas95 | 1:a0055b3280c8 | 73 | else if(state_err_cnt>STATE_ERR_THRS){\ |
shreeshas95 | 1:a0055b3280c8 | 74 | return_this = 1;\ |
shreeshas95 | 1:a0055b3280c8 | 75 | break;\ |
shreeshas95 | 1:a0055b3280c8 | 76 | }\ |
shreeshas95 | 1:a0055b3280c8 | 77 | else if( (status & 0xA0) == 0xA0 ){\ |
shreeshas95 | 1:a0055b3280c8 | 78 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 79 | spi.write(CMD_PHY_OFF);\ |
shreeshas95 | 1:a0055b3280c8 | 80 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 81 | wait_us(PHY_OFF_EXEC_TIME);\ |
shreeshas95 | 1:a0055b3280c8 | 82 | state_err_cnt++;\ |
shreeshas95 | 1:a0055b3280c8 | 83 | }\ |
shreeshas95 | 1:a0055b3280c8 | 84 | else if(status&0x80==0x00){\ |
shreeshas95 | 1:a0055b3280c8 | 85 | wait_ms(5);\ |
shreeshas95 | 1:a0055b3280c8 | 86 | spi_err_cnt++;\ |
shreeshas95 | 1:a0055b3280c8 | 87 | }\ |
shreeshas95 | 1:a0055b3280c8 | 88 | else {\ |
shreeshas95 | 1:a0055b3280c8 | 89 | wait_ms(1);\ |
shreeshas95 | 1:a0055b3280c8 | 90 | cmd_err_cnt++;\ |
shreeshas95 | 1:a0055b3280c8 | 91 | }\ |
shreeshas95 | 1:a0055b3280c8 | 92 | }\ |
shreeshas95 | 1:a0055b3280c8 | 93 | } |
ee12b079 | 9:e9eaada136c6 | 94 | |
ee12b079 | 9:e9eaada136c6 | 95 | |
shreeshas95 | 1:a0055b3280c8 | 96 | //#define assrt_phy_on(cmd_err_cnt, spi_err_cnt, state_err_cnt, return_this){\ |
shreeshas95 | 1:a0055b3280c8 | 97 | // status=check_status();\ |
shreeshas95 | 1:a0055b3280c8 | 98 | // if((status&0x1F)==0x12){\ |
shreeshas95 | 1:a0055b3280c8 | 99 | // return 0;\ |
shreeshas95 | 1:a0055b3280c8 | 100 | // }\ |
shreeshas95 | 1:a0055b3280c8 | 101 | // else if(cmd_err_cnt>THRS||spi_err_cnt>THRS){\ |
shreeshas95 | 1:a0055b3280c8 | 102 | // return 1;\ |
shreeshas95 | 1:a0055b3280c8 | 103 | // }\ |
shreeshas95 | 1:a0055b3280c8 | 104 | // else if(state_err_cnt>STATE_ERR_THRS){\ |
shreeshas95 | 1:a0055b3280c8 | 105 | // return 1;\ |
shreeshas95 | 1:a0055b3280c8 | 106 | // }\ |
shreeshas95 | 1:a0055b3280c8 | 107 | // else if((status&0xA0)==0xA0){\ |
shreeshas95 | 1:a0055b3280c8 | 108 | // cs_adf=0;\ |
shreeshas95 | 1:a0055b3280c8 | 109 | // spi.write(0xB1);\ |
shreeshas95 | 1:a0055b3280c8 | 110 | // cs_adf=1;\ |
shreeshas95 | 1:a0055b3280c8 | 111 | // wait_us(PHY_ON_EXEC_TIME);\ |
shreeshas95 | 1:a0055b3280c8 | 112 | // return assrt_phy_on(cmd_err_cnt,spi_err_cnt,state_err_cnt+1);\ |
shreeshas95 | 1:a0055b3280c8 | 113 | // }\ |
shreeshas95 | 1:a0055b3280c8 | 114 | // else if(status&0x80==0x00){\ |
shreeshas95 | 1:a0055b3280c8 | 115 | // wait_ms(5);\ |
shreeshas95 | 1:a0055b3280c8 | 116 | // //Error: SPI=0 Not ready CMD= Dont care |
shreeshas95 | 1:a0055b3280c8 | 117 | // return assrt_phy_on(cmd_err_cnt,spi_err_cnt+1,state_err_cnt);\ |
shreeshas95 | 1:a0055b3280c8 | 118 | // }\ |
shreeshas95 | 1:a0055b3280c8 | 119 | // else{\ |
shreeshas95 | 1:a0055b3280c8 | 120 | // if(status&0xA0==0x80){\ |
shreeshas95 | 1:a0055b3280c8 | 121 | // wait_ms(1);\ |
shreeshas95 | 1:a0055b3280c8 | 122 | // //Error: Command Not ready SPI Ready cmd_err_cnt is a global variable |
shreeshas95 | 1:a0055b3280c8 | 123 | // return assrt_phy_on(cmd_err_cnt+1,spi_err_cnt,state_err_cnt);\ |
shreeshas95 | 1:a0055b3280c8 | 124 | // }\ |
shreeshas95 | 1:a0055b3280c8 | 125 | // }\ |
shreeshas95 | 1:a0055b3280c8 | 126 | //} |
ee12b079 | 9:e9eaada136c6 | 127 | |
ee12b079 | 9:e9eaada136c6 | 128 | |
ee12b079 | 9:e9eaada136c6 | 129 | |
ee12b079 | 9:e9eaada136c6 | 130 | |
shreeshas95 | 1:a0055b3280c8 | 131 | #define initial_adf_check {\ |
shreeshas95 | 1:a0055b3280c8 | 132 | spi.write(CMD_PHY_OFF);\ |
shreeshas95 | 1:a0055b3280c8 | 133 | int tempReturn = 0;\ |
shreeshas95 | 2:2caf2a9a13aa | 134 | bool flag = false;\ |
shreeshas95 | 1:a0055b3280c8 | 135 | while( hw_reset_err_cnt < 2 ){\ |
shreeshas95 | 1:a0055b3280c8 | 136 | assrt_phy_off( tempReturn);\ |
shreeshas95 | 1:a0055b3280c8 | 137 | if( !tempReturn ){\ |
shreeshas95 | 1:a0055b3280c8 | 138 | bbram_write;\ |
shreeshas95 | 1:a0055b3280c8 | 139 | bbram_flag=1;\ |
shreeshas95 | 2:2caf2a9a13aa | 140 | flag = true;\ |
shreeshas95 | 1:a0055b3280c8 | 141 | break;\ |
shreeshas95 | 1:a0055b3280c8 | 142 | }\ |
shreeshas95 | 1:a0055b3280c8 | 143 | else{\ |
shreeshas95 | 1:a0055b3280c8 | 144 | hardware_reset(0);\ |
shreeshas95 | 1:a0055b3280c8 | 145 | hw_reset_err_cnt++;\ |
shreeshas95 | 2:2caf2a9a13aa | 146 | gPC.puts("Resetting hardware\r\n");\ |
shreeshas95 | 1:a0055b3280c8 | 147 | }\ |
shreeshas95 | 1:a0055b3280c8 | 148 | }\ |
shreeshas95 | 2:2caf2a9a13aa | 149 | if( flag == false ){\ |
shreeshas95 | 2:2caf2a9a13aa | 150 | gPC.puts("Seems to be SPI problem\r\n");\ |
shreeshas95 | 2:2caf2a9a13aa | 151 | }\ |
shreeshas95 | 1:a0055b3280c8 | 152 | assrt_phy_off(tempReturn);\ |
shreeshas95 | 1:a0055b3280c8 | 153 | if(!bbram_flag){\ |
shreeshas95 | 1:a0055b3280c8 | 154 | bcn_flag=1;\ |
shreeshas95 | 1:a0055b3280c8 | 155 | }\ |
shreeshas95 | 1:a0055b3280c8 | 156 | } |
ee12b079 | 9:e9eaada136c6 | 157 | |
shreeshas95 | 1:a0055b3280c8 | 158 | unsigned char status =0; |
shreeshas95 | 1:a0055b3280c8 | 159 | unsigned int cmd_err_cnt=0; |
shreeshas95 | 1:a0055b3280c8 | 160 | unsigned int state_err_cnt=0; |
shreeshas95 | 1:a0055b3280c8 | 161 | unsigned int miso_err_cnt=0; |
shreeshas95 | 1:a0055b3280c8 | 162 | unsigned int hw_reset_err_cnt=0; |
shreeshas95 | 1:a0055b3280c8 | 163 | bool bcn_flag=0; |
shreeshas95 | 1:a0055b3280c8 | 164 | bool bbram_flag=0; |
ee12b079 | 9:e9eaada136c6 | 165 | |
shreeshas95 | 1:a0055b3280c8 | 166 | //bool assrt_phy_off(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ |
shreeshas95 | 1:a0055b3280c8 | 167 | // status=check_status(); |
shreeshas95 | 1:a0055b3280c8 | 168 | // if(status==0xB1){ |
shreeshas95 | 1:a0055b3280c8 | 169 | // return 0; |
shreeshas95 | 1:a0055b3280c8 | 170 | // } |
shreeshas95 | 1:a0055b3280c8 | 171 | // else if(cmd_err_cnt>THRS||spi_err_cnt>THRS){ |
shreeshas95 | 1:a0055b3280c8 | 172 | // return 1;//You need to Reset the hardware |
shreeshas95 | 1:a0055b3280c8 | 173 | // } |
shreeshas95 | 1:a0055b3280c8 | 174 | // else if(state_err_cnt>STATE_ERR_THRS){ |
shreeshas95 | 1:a0055b3280c8 | 175 | // return 1;//Again reset the hardware |
shreeshas95 | 1:a0055b3280c8 | 176 | // } |
shreeshas95 | 1:a0055b3280c8 | 177 | // else if((status&0xA0)==0xA0){ //If Status' first three bit ore 0b1X1 =>SPI ready, Dont care interrupt and CMD Ready. |
shreeshas95 | 1:a0055b3280c8 | 178 | // cs_adf=0; |
shreeshas95 | 1:a0055b3280c8 | 179 | // spi.write(CMD_PHY_OFF); //CMD_PHY_OFF=0xB0 |
shreeshas95 | 1:a0055b3280c8 | 180 | // cs_adf=1; |
shreeshas95 | 1:a0055b3280c8 | 181 | // wait_us(PHY_OFF_EXEC_TIME);// Typical = 24us We are giving 300us |
shreeshas95 | 1:a0055b3280c8 | 182 | // return assrt_phy_off(cmd_err_cnt,spi_err_cnt,state_err_cnt+1); |
shreeshas95 | 1:a0055b3280c8 | 183 | // } |
shreeshas95 | 1:a0055b3280c8 | 184 | // else if(status&0x80==0x00){ |
shreeshas95 | 1:a0055b3280c8 | 185 | // wait_ms(5); |
shreeshas95 | 1:a0055b3280c8 | 186 | // //Error: SPI=0 Not ready CMD= Dont care |
shreeshas95 | 1:a0055b3280c8 | 187 | // return assrt_phy_off(cmd_err_cnt,spi_err_cnt+1,state_err_cnt); |
shreeshas95 | 1:a0055b3280c8 | 188 | // } |
shreeshas95 | 1:a0055b3280c8 | 189 | // else {//if(status&0xA0==0x80){ |
shreeshas95 | 1:a0055b3280c8 | 190 | // wait_ms(1); |
shreeshas95 | 1:a0055b3280c8 | 191 | // //Error: Command Not ready SPI Ready cmd_err_cnt is a global variable |
shreeshas95 | 1:a0055b3280c8 | 192 | // return assrt_phy_off(cmd_err_cnt+1,spi_err_cnt,state_err_cnt); |
shreeshas95 | 1:a0055b3280c8 | 193 | // } |
shreeshas95 | 1:a0055b3280c8 | 194 | //} |
ee12b079 | 9:e9eaada136c6 | 195 | |
shreeshas95 | 1:a0055b3280c8 | 196 | //bool assrt_phy_on(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ |
shreeshas95 | 1:a0055b3280c8 | 197 | // status=check_status(); |
shreeshas95 | 1:a0055b3280c8 | 198 | // if((status&0x1F)==0x12){ |
shreeshas95 | 1:a0055b3280c8 | 199 | // return 0; |
shreeshas95 | 1:a0055b3280c8 | 200 | // } |
shreeshas95 | 1:a0055b3280c8 | 201 | // else if(cmd_err_cnt>THRS||spi_err_cnt>THRS){ |
shreeshas95 | 1:a0055b3280c8 | 202 | // return 1;//You need to Reset the hardware |
shreeshas95 | 1:a0055b3280c8 | 203 | // } |
shreeshas95 | 1:a0055b3280c8 | 204 | // else if(state_err_cnt>STATE_ERR_THRS){ |
shreeshas95 | 1:a0055b3280c8 | 205 | // return 1;//Again reset the hardware |
shreeshas95 | 1:a0055b3280c8 | 206 | // } |
shreeshas95 | 1:a0055b3280c8 | 207 | // else if((status&0xA0)==0xA0){ //If Status' first three bit ore 0b1X1 =>SPI ready, Dont care interrupt and CMD Ready. |
shreeshas95 | 1:a0055b3280c8 | 208 | // cs_adf=0; |
shreeshas95 | 1:a0055b3280c8 | 209 | // spi.write(0xB1); //CMD_PHY_OFF |
shreeshas95 | 1:a0055b3280c8 | 210 | // cs_adf=1; |
shreeshas95 | 1:a0055b3280c8 | 211 | // wait_us(PHY_ON_EXEC_TIME);// Typical = 24us We are giving 300us |
shreeshas95 | 1:a0055b3280c8 | 212 | // return assrt_phy_on(cmd_err_cnt,spi_err_cnt,state_err_cnt+1); |
shreeshas95 | 1:a0055b3280c8 | 213 | // } |
shreeshas95 | 1:a0055b3280c8 | 214 | // else if(status&0x80==0x00){ |
shreeshas95 | 1:a0055b3280c8 | 215 | // wait_ms(5); |
shreeshas95 | 1:a0055b3280c8 | 216 | // //Error: SPI=0 Not ready CMD= Dont care |
shreeshas95 | 1:a0055b3280c8 | 217 | // return assrt_phy_on(cmd_err_cnt,spi_err_cnt+1,state_err_cnt); |
shreeshas95 | 1:a0055b3280c8 | 218 | // } |
shreeshas95 | 1:a0055b3280c8 | 219 | // else{ |
shreeshas95 | 1:a0055b3280c8 | 220 | // if(status&0xA0==0x80){ |
shreeshas95 | 1:a0055b3280c8 | 221 | // wait_ms(1); |
shreeshas95 | 1:a0055b3280c8 | 222 | // //Error: Command Not ready SPI Ready cmd_err_cnt is a global variable |
shreeshas95 | 1:a0055b3280c8 | 223 | // return assrt_phy_on(cmd_err_cnt+1,spi_err_cnt,state_err_cnt); |
shreeshas95 | 1:a0055b3280c8 | 224 | // } |
shreeshas95 | 1:a0055b3280c8 | 225 | // } |
shreeshas95 | 1:a0055b3280c8 | 226 | //} |
ee12b079 | 9:e9eaada136c6 | 227 | |
ee12b079 | 9:e9eaada136c6 | 228 | |
shreeshas95 | 1:a0055b3280c8 | 229 | // bool assrt_phy_tx(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ |
shreeshas95 | 1:a0055b3280c8 | 230 | // status=check_status(); |
shreeshas95 | 1:a0055b3280c8 | 231 | // if((status & 0x1F) == 0x14){ |
shreeshas95 | 1:a0055b3280c8 | 232 | // return 0; |
shreeshas95 | 1:a0055b3280c8 | 233 | // } |
shreeshas95 | 1:a0055b3280c8 | 234 | // else if(cmd_err_cnt>THRS||spi_err_cnt>THRS){ |
shreeshas95 | 1:a0055b3280c8 | 235 | // return 1;//You need to Reset the hardware |
shreeshas95 | 1:a0055b3280c8 | 236 | // } |
shreeshas95 | 1:a0055b3280c8 | 237 | // else if(state_err_cnt>STATE_ERR_THRS){ |
shreeshas95 | 1:a0055b3280c8 | 238 | // return 1;//Again reset the hardware |
shreeshas95 | 1:a0055b3280c8 | 239 | // } |
shreeshas95 | 1:a0055b3280c8 | 240 | // else if((status&0xA0)==0xA0){ //If Status' first three bit ore 0b1X1 =>SPI ready, Dont care interrupt and CMD Ready. |
shreeshas95 | 1:a0055b3280c8 | 241 | // cs_adf=0; |
shreeshas95 | 1:a0055b3280c8 | 242 | // spi.write(0xB1); //CMD_PHY_OFF |
shreeshas95 | 1:a0055b3280c8 | 243 | // cs_adf=1; |
shreeshas95 | 1:a0055b3280c8 | 244 | // wait_us(PHY_TX_EXEC_TIME);// Typical = 24us We are giving 300us |
shreeshas95 | 1:a0055b3280c8 | 245 | // return assrt_phy_tx(cmd_err_cnt,spi_err_cnt,state_err_cnt+1); |
shreeshas95 | 1:a0055b3280c8 | 246 | // } |
shreeshas95 | 1:a0055b3280c8 | 247 | // else if(status&0x80==0x00){ |
shreeshas95 | 1:a0055b3280c8 | 248 | // wait_ms(1); |
shreeshas95 | 1:a0055b3280c8 | 249 | // //Error: SPI=0 Not ready CMD= Dont care |
shreeshas95 | 1:a0055b3280c8 | 250 | // return assrt_phy_tx(cmd_err_cnt,spi_err_cnt+1,state_err_cnt); |
shreeshas95 | 1:a0055b3280c8 | 251 | // } |
shreeshas95 | 1:a0055b3280c8 | 252 | // else { |
shreeshas95 | 1:a0055b3280c8 | 253 | // if(status&0xA0==0x80){ |
shreeshas95 | 1:a0055b3280c8 | 254 | // wait_us(50); |
shreeshas95 | 1:a0055b3280c8 | 255 | // //Error: Command Not ready SPI Ready cmd_err_cnt is a global variable |
shreeshas95 | 1:a0055b3280c8 | 256 | // return assrt_phy_tx(cmd_err_cnt+1,spi_err_cnt,state_err_cnt); |
shreeshas95 | 1:a0055b3280c8 | 257 | // } |
shreeshas95 | 1:a0055b3280c8 | 258 | // } |
shreeshas95 | 1:a0055b3280c8 | 259 | //} |
ee12b079 | 9:e9eaada136c6 | 260 | |
shreeshas95 | 1:a0055b3280c8 | 261 | bool hardware_reset(int bcn_call){ |
shreeshas95 | 1:a0055b3280c8 | 262 | for(int i= 0; i < 20 ; i++){ |
shreeshas95 | 1:a0055b3280c8 | 263 | gCS_ADF=0; |
shreeshas95 | 1:a0055b3280c8 | 264 | spi.write(CMD_HW_RESET); |
shreeshas95 | 1:a0055b3280c8 | 265 | gCS_ADF=1; |
shreeshas95 | 1:a0055b3280c8 | 266 | wait_ms(2);// Typically 1 ms |
shreeshas95 | 1:a0055b3280c8 | 267 | int count=0; |
shreeshas95 | 1:a0055b3280c8 | 268 | int temp_return = 0; |
shreeshas95 | 1:a0055b3280c8 | 269 | while(count<10 && miso_err_cnt<10){ |
shreeshas95 | 1:a0055b3280c8 | 270 | if(MISO_PIN){ |
shreeshas95 | 1:a0055b3280c8 | 271 | assrt_phy_off(temp_return); |
shreeshas95 | 1:a0055b3280c8 | 272 | if(!temp_return){ |
shreeshas95 | 1:a0055b3280c8 | 273 | return 0; |
shreeshas95 | 1:a0055b3280c8 | 274 | } |
shreeshas95 | 1:a0055b3280c8 | 275 | count++; |
shreeshas95 | 1:a0055b3280c8 | 276 | } |
shreeshas95 | 1:a0055b3280c8 | 277 | else{ |
shreeshas95 | 1:a0055b3280c8 | 278 | wait_us(50); |
shreeshas95 | 1:a0055b3280c8 | 279 | miso_err_cnt++; |
shreeshas95 | 1:a0055b3280c8 | 280 | } |
shreeshas95 | 1:a0055b3280c8 | 281 | } |
shreeshas95 | 1:a0055b3280c8 | 282 | } |
shreeshas95 | 1:a0055b3280c8 | 283 | return 1; |
shreeshas95 | 1:a0055b3280c8 | 284 | } |
ee12b079 | 9:e9eaada136c6 | 285 | |
shreeshas95 | 1:a0055b3280c8 | 286 | //bool hardware_reset(int bcn_call){ |
shreeshas95 | 1:a0055b3280c8 | 287 | // if (bcn_call>20){//Worst Case 20seconds will be lost ! |
shreeshas95 | 1:a0055b3280c8 | 288 | // return 1; |
shreeshas95 | 1:a0055b3280c8 | 289 | // } |
shreeshas95 | 1:a0055b3280c8 | 290 | // int count=0; |
shreeshas95 | 1:a0055b3280c8 | 291 | // cs_adf=0; |
shreeshas95 | 1:a0055b3280c8 | 292 | // spi.write(CMD_HW_RESET); |
shreeshas95 | 1:a0055b3280c8 | 293 | // cs_adf=1; |
shreeshas95 | 1:a0055b3280c8 | 294 | // wait_ms(2);// Typically 1 ms |
shreeshas95 | 1:a0055b3280c8 | 295 | // while(count<10 && miso_err_cnt<10){ |
shreeshas95 | 1:a0055b3280c8 | 296 | // if(MISO_PIN){ |
shreeshas95 | 1:a0055b3280c8 | 297 | // int temp_return; |
shreeshas95 | 1:a0055b3280c8 | 298 | // assrt_phy_off(0,0,0,temp_return); |
shreeshas95 | 1:a0055b3280c8 | 299 | // if(!temp_return){ |
shreeshas95 | 1:a0055b3280c8 | 300 | // break; |
shreeshas95 | 1:a0055b3280c8 | 301 | // } |
shreeshas95 | 1:a0055b3280c8 | 302 | // count++; |
shreeshas95 | 1:a0055b3280c8 | 303 | // } |
shreeshas95 | 1:a0055b3280c8 | 304 | // else{ |
shreeshas95 | 1:a0055b3280c8 | 305 | // wait_us(50); |
shreeshas95 | 1:a0055b3280c8 | 306 | // miso_err_cnt++; |
shreeshas95 | 1:a0055b3280c8 | 307 | // } |
shreeshas95 | 1:a0055b3280c8 | 308 | // } |
shreeshas95 | 1:a0055b3280c8 | 309 | // if(count==10 ||miso_err_cnt==10){ |
shreeshas95 | 1:a0055b3280c8 | 310 | // return hardware_reset(bcn_call+1); |
shreeshas95 | 1:a0055b3280c8 | 311 | // } |
shreeshas95 | 1:a0055b3280c8 | 312 | // else |
shreeshas95 | 1:a0055b3280c8 | 313 | // return 0; |
shreeshas95 | 1:a0055b3280c8 | 314 | // |
shreeshas95 | 1:a0055b3280c8 | 315 | //} |
ee12b079 | 9:e9eaada136c6 | 316 | |
ee12b079 | 9:e9eaada136c6 | 317 | |
ee12b079 | 9:e9eaada136c6 | 318 | |
ee12b079 | 9:e9eaada136c6 | 319 | |
shreeshas95 | 1:a0055b3280c8 | 320 | //void initial_adf_check(){ |
shreeshas95 | 1:a0055b3280c8 | 321 | // spi.write(CMD_PHY_OFF); //0xB0 |
shreeshas95 | 1:a0055b3280c8 | 322 | // while(hw_reset_err_cnt<2){ |
shreeshas95 | 1:a0055b3280c8 | 323 | // |
shreeshas95 | 1:a0055b3280c8 | 324 | // if(!assrt_phy_off(0,0,0)){ //assrt_phy_off () returns 0 if state is PHY_OFF , returns 1 if couldn't go to PHY_OFF |
shreeshas95 | 1:a0055b3280c8 | 325 | // bbram_write(); |
shreeshas95 | 1:a0055b3280c8 | 326 | // bbram_flag=1; |
shreeshas95 | 1:a0055b3280c8 | 327 | // break; |
shreeshas95 | 1:a0055b3280c8 | 328 | // } |
shreeshas95 | 1:a0055b3280c8 | 329 | // else{ |
shreeshas95 | 1:a0055b3280c8 | 330 | // hardware_reset(0); // Asserts Hardware for 20sec(20times). PHY_OFF for 20,000 times |
shreeshas95 | 1:a0055b3280c8 | 331 | // hw_reset_err_cnt++; |
shreeshas95 | 1:a0055b3280c8 | 332 | // } |
shreeshas95 | 1:a0055b3280c8 | 333 | // } |
shreeshas95 | 1:a0055b3280c8 | 334 | // assrt_phy_off(0,0,0);// We actually do not need this but make sure "we do not need this" |
shreeshas95 | 1:a0055b3280c8 | 335 | // if(!bbram_flag){ |
shreeshas95 | 1:a0055b3280c8 | 336 | // //Switch to beacon |
shreeshas95 | 1:a0055b3280c8 | 337 | // bcn_flag=1; |
shreeshas95 | 1:a0055b3280c8 | 338 | // } |
shreeshas95 | 1:a0055b3280c8 | 339 | //} |
ee12b079 | 9:e9eaada136c6 | 340 | |
shreeshas95 | 1:a0055b3280c8 | 341 | //for reseting the transmission call assert function after b5 and b1. after b1 assert_phi_on and after b5 assert_phi_tx. |
shreeshas95 | 1:a0055b3280c8 | 342 | //---------------------------------------------------------------------------- |
ee12b079 | 9:e9eaada136c6 | 343 | |
shreeshas95 | 1:a0055b3280c8 | 344 | # define initiate {\ |
shreeshas95 | 1:a0055b3280c8 | 345 | SPI_mutex.lock();\ |
shreeshas95 | 1:a0055b3280c8 | 346 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 347 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 348 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 349 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 350 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 351 | spi.write(0x08);\ |
shreeshas95 | 1:a0055b3280c8 | 352 | spi.write(0x14);\ |
shreeshas95 | 1:a0055b3280c8 | 353 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 354 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 355 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 356 | spi.write(0x08);\ |
shreeshas95 | 1:a0055b3280c8 | 357 | spi.write(0x15);\ |
shreeshas95 | 1:a0055b3280c8 | 358 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 359 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 360 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 361 | spi.write(0x09);\ |
shreeshas95 | 1:a0055b3280c8 | 362 | spi.write(0x24);\ |
shreeshas95 | 1:a0055b3280c8 | 363 | spi.write(0x20);\ |
shreeshas95 | 1:a0055b3280c8 | 364 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 365 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 366 | spi.write(0x09);\ |
shreeshas95 | 1:a0055b3280c8 | 367 | spi.write(0x37);\ |
shreeshas95 | 1:a0055b3280c8 | 368 | spi.write(0xE0);\ |
shreeshas95 | 1:a0055b3280c8 | 369 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 370 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 371 | spi.write(0x09);\ |
shreeshas95 | 1:a0055b3280c8 | 372 | spi.write(0x36);\ |
shreeshas95 | 1:a0055b3280c8 | 373 | spi.write(0x70);\ |
shreeshas95 | 1:a0055b3280c8 | 374 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 375 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 376 | spi.write(0x09);\ |
shreeshas95 | 1:a0055b3280c8 | 377 | spi.write(0x39);\ |
shreeshas95 | 1:a0055b3280c8 | 378 | spi.write(0x10);\ |
shreeshas95 | 1:a0055b3280c8 | 379 | gCS_ADF=1;\ |
ee12b079 | 9:e9eaada136c6 | 380 | gCS_ADF=0;\ |
ee12b079 | 9:e9eaada136c6 | 381 | spi.write(0xBB);\ |
ee12b079 | 9:e9eaada136c6 | 382 | gCS_ADF=1;\ |
ee12b079 | 9:e9eaada136c6 | 383 | gCS_ADF=0;\ |
ee12b079 | 9:e9eaada136c6 | 384 | spi.write(0xFF);\ |
ee12b079 | 9:e9eaada136c6 | 385 | spi.write(0xFF);\ |
ee12b079 | 9:e9eaada136c6 | 386 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 387 | SPI_mutex.unlock();\ |
shreeshas95 | 1:a0055b3280c8 | 388 | } |
ee12b079 | 9:e9eaada136c6 | 389 | |
ee12b079 | 9:e9eaada136c6 | 390 | |
shreeshas95 | 1:a0055b3280c8 | 391 | #define write_data {\ |
shreeshas95 | 1:a0055b3280c8 | 392 | SPI_mutex.lock();\ |
shreeshas95 | 1:a0055b3280c8 | 393 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 394 | spi.write(0x0B);\ |
shreeshas95 | 1:a0055b3280c8 | 395 | spi.write(0x36);\ |
shreeshas95 | 1:a0055b3280c8 | 396 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 397 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 398 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 399 | if(buffer_state){\ |
shreeshas95 | 1:a0055b3280c8 | 400 | spi.write(0x18);\ |
shreeshas95 | 1:a0055b3280c8 | 401 | spi.write(0x20);\ |
shreeshas95 | 1:a0055b3280c8 | 402 | for(unsigned char i=0; i<112;i++){\ |
shreeshas95 | 1:a0055b3280c8 | 403 | spi.write(buffer_112[i]);\ |
ee12b079 | 28:cd3212fe5643 | 404 | /*gPC.printf("0x%X,",spi.write(buffer_112[i]));*/\ |
shreeshas95 | 1:a0055b3280c8 | 405 | }\ |
shreeshas95 | 1:a0055b3280c8 | 406 | }\ |
shreeshas95 | 1:a0055b3280c8 | 407 | else{\ |
shreeshas95 | 1:a0055b3280c8 | 408 | spi.write(0x18);\ |
shreeshas95 | 1:a0055b3280c8 | 409 | spi.write(0x90);\ |
shreeshas95 | 1:a0055b3280c8 | 410 | for(unsigned char i=0; i<112;i++){\ |
shreeshas95 | 1:a0055b3280c8 | 411 | spi.write(buffer_112[i]);\ |
ee12b079 | 28:cd3212fe5643 | 412 | /*gPC.printf("0x%X,",spi.write(buffer_112[i]));*/\ |
shreeshas95 | 1:a0055b3280c8 | 413 | }\ |
shreeshas95 | 1:a0055b3280c8 | 414 | }\ |
shreeshas95 | 1:a0055b3280c8 | 415 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 416 | SPI_mutex.unlock();\ |
shreeshas95 | 1:a0055b3280c8 | 417 | buffer_state = !buffer_state;\ |
shreeshas95 | 1:a0055b3280c8 | 418 | if(last_buffer){\ |
ee12b079 | 9:e9eaada136c6 | 419 | finish_write_data = true;\ |
shreeshas95 | 1:a0055b3280c8 | 420 | gPC.puts("adf_off\r\n");\ |
shreeshas95 | 1:a0055b3280c8 | 421 | }\ |
shreeshas95 | 1:a0055b3280c8 | 422 | } |
shreeshas95 | 1:a0055b3280c8 | 423 | |
shreeshas95 | 1:a0055b3280c8 | 424 | #define send_data {\ |
shreeshas95 | 1:a0055b3280c8 | 425 | if(sent_tmfrom_SDcard){\ |
shreeshas95 | 1:a0055b3280c8 | 426 | send_tm_from_SD_card();\ |
shreeshas95 | 1:a0055b3280c8 | 427 | }else{\ |
shreeshas95 | 1:a0055b3280c8 | 428 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
shreeshas95 | 1:a0055b3280c8 | 429 | }\ |
shreeshas95 | 1:a0055b3280c8 | 430 | write_data;\ |
shreeshas95 | 1:a0055b3280c8 | 431 | if(sent_tmfrom_SDcard){\ |
shreeshas95 | 1:a0055b3280c8 | 432 | send_tm_from_SD_card();\ |
shreeshas95 | 1:a0055b3280c8 | 433 | }else{\ |
shreeshas95 | 1:a0055b3280c8 | 434 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
shreeshas95 | 1:a0055b3280c8 | 435 | }\ |
shreeshas95 | 1:a0055b3280c8 | 436 | write_data;\ |
shreeshas95 | 1:a0055b3280c8 | 437 | if(sent_tmfrom_SDcard){\ |
shreeshas95 | 1:a0055b3280c8 | 438 | send_tm_from_SD_card();\ |
shreeshas95 | 1:a0055b3280c8 | 439 | }else{\ |
shreeshas95 | 1:a0055b3280c8 | 440 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
shreeshas95 | 1:a0055b3280c8 | 441 | }\ |
shreeshas95 | 1:a0055b3280c8 | 442 | SPI_mutex.lock();\ |
shreeshas95 | 1:a0055b3280c8 | 443 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 444 | spi.write(0xB1);\ |
shreeshas95 | 1:a0055b3280c8 | 445 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 446 | wait_us(300);\ |
shreeshas95 | 1:a0055b3280c8 | 447 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 448 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 449 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 450 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 451 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 452 | spi.write(0xB5);\ |
shreeshas95 | 1:a0055b3280c8 | 453 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 454 | wait_us(300);\ |
shreeshas95 | 1:a0055b3280c8 | 455 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 456 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 457 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 458 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 459 | SPI_mutex.unlock();\ |
shreeshas95 | 1:a0055b3280c8 | 460 | } |
shreeshas95 | 1:a0055b3280c8 | 461 | |
shreeshas95 | 1:a0055b3280c8 | 462 | |
shreeshas95 | 1:a0055b3280c8 | 463 | |
shreeshas95 | 1:a0055b3280c8 | 464 | #define adf_SND_SDCard {\ |
shreeshas95 | 1:a0055b3280c8 | 465 | buffer_state = true;\ |
shreeshas95 | 1:a0055b3280c8 | 466 | last_buffer = false;\ |
shreeshas95 | 1:a0055b3280c8 | 467 | loop_on = true;\ |
shreeshas95 | 1:a0055b3280c8 | 468 | ADF_off = false;\ |
shreeshas95 | 1:a0055b3280c8 | 469 | sent_tmfrom_SDcard = true;\ |
shreeshas95 | 1:a0055b3280c8 | 470 | signal = COM_MNG_TMTC_SIGNAL_ADF_SD;\ |
shreeshas95 | 1:a0055b3280c8 | 471 | start_block_num = starting_add;\ |
shreeshas95 | 1:a0055b3280c8 | 472 | end_block_num = ending_add;\ |
shreeshas95 | 1:a0055b3280c8 | 473 | initial_adf_check;\ |
shreeshas95 | 1:a0055b3280c8 | 474 | initiate;\ |
shreeshas95 | 1:a0055b3280c8 | 475 | send_data;\ |
shreeshas95 | 1:a0055b3280c8 | 476 | while(loop_on){\ |
shreeshas95 | 2:2caf2a9a13aa | 477 | /*led2=!led2;*/\ |
shreeshas95 | 3:6c81fc8834e2 | 478 | gCOM_MNG_TMTC_THREAD->signal_wait(COM_MNG_TMTC_SIGNAL_ADF_SD);\ |
shreeshas95 | 1:a0055b3280c8 | 479 | if(ADF_off){\ |
shreeshas95 | 1:a0055b3280c8 | 480 | SPI_mutex.lock();\ |
shreeshas95 | 1:a0055b3280c8 | 481 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 482 | spi.write(0xB1);\ |
shreeshas95 | 1:a0055b3280c8 | 483 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 484 | SPI_mutex.unlock();\ |
shreeshas95 | 1:a0055b3280c8 | 485 | gPC.puts("transmission done\r\n");\ |
shreeshas95 | 1:a0055b3280c8 | 486 | loop_on = false;\ |
shreeshas95 | 1:a0055b3280c8 | 487 | }else{\ |
shreeshas95 | 1:a0055b3280c8 | 488 | write_data;\ |
shreeshas95 | 1:a0055b3280c8 | 489 | if(!last_buffer)\ |
shreeshas95 | 1:a0055b3280c8 | 490 | send_tm_from_SD_card();\ |
shreeshas95 | 1:a0055b3280c8 | 491 | }\ |
shreeshas95 | 1:a0055b3280c8 | 492 | }\ |
shreeshas95 | 1:a0055b3280c8 | 493 | } |
shreeshas95 | 1:a0055b3280c8 | 494 | |
shreeshas95 | 1:a0055b3280c8 | 495 | void read_TC(Base_tc* TC_ptr){ |
shreeshas95 | 1:a0055b3280c8 | 496 | gPC.puts("Inside sd card sending\r\n"); |
shreeshas95 | 1:a0055b3280c8 | 497 | unsigned char service_subtype = 0; |
shreeshas95 | 1:a0055b3280c8 | 498 | uint64_t starting_add = 0, ending_add = 0; |
shreeshas95 | 1:a0055b3280c8 | 499 | service_subtype = (TC_ptr->TC_string[2])&0x0f; |
shreeshas95 | 1:a0055b3280c8 | 500 | starting_add = (TC_ptr->TC_string[5]) + ( (TC_ptr->TC_string[4])<<8 ) + ( (TC_ptr->TC_string[3]) <<16); |
shreeshas95 | 1:a0055b3280c8 | 501 | ending_add = (TC_ptr->TC_string[8]) + ( (TC_ptr->TC_string[7])<<8 ) + ( (TC_ptr->TC_string[6]) <<16); |
shreeshas95 | 1:a0055b3280c8 | 502 | starting_add = 10; // for now |
shreeshas95 | 1:a0055b3280c8 | 503 | ending_add = 20; |
shreeshas95 | 1:a0055b3280c8 | 504 | // adf_SND_SDCard(starting_add , ending_add); |
shreeshas95 | 1:a0055b3280c8 | 505 | gPC.puts("sending from sd card\r\n"); |
shreeshas95 | 1:a0055b3280c8 | 506 | adf_SND_SDCard; |
shreeshas95 | 1:a0055b3280c8 | 507 | } |
ee12b079 | 9:e9eaada136c6 | 508 | |
shreeshas95 | 2:2caf2a9a13aa | 509 | //Timeout ADF_non_responsive_timeout; |
shreeshas95 | 2:2caf2a9a13aa | 510 | //bool ADF_non_responsive_flag = false; |
shreeshas95 | 2:2caf2a9a13aa | 511 | // |
shreeshas95 | 2:2caf2a9a13aa | 512 | //void ADF_non_responsive_fun(){ |
shreeshas95 | 2:2caf2a9a13aa | 513 | // ADF_non_responsive_flag = true; |
shreeshas95 | 2:2caf2a9a13aa | 514 | // gCOM_MNG_TMTC_THREAD->signal_set(signal); |
shreeshas95 | 2:2caf2a9a13aa | 515 | //} |
ee12b079 | 9:e9eaada136c6 | 516 | |
krishanprajapat | 19:27e5f2edaf26 | 517 | #define configure_adf {\ |
krishanprajapat | 19:27e5f2edaf26 | 518 | finish_write_data = false;\ |
krishanprajapat | 19:27e5f2edaf26 | 519 | buffer_state = true;\ |
krishanprajapat | 19:27e5f2edaf26 | 520 | last_buffer = false;\ |
krishanprajapat | 19:27e5f2edaf26 | 521 | loop_on = true;\ |
krishanprajapat | 19:27e5f2edaf26 | 522 | ADF_off = false;\ |
krishanprajapat | 19:27e5f2edaf26 | 523 | initial_adf_check;\ |
krishanprajapat | 19:27e5f2edaf26 | 524 | gPC.puts("initial adf check\r\n");\ |
krishanprajapat | 19:27e5f2edaf26 | 525 | initiate;\ |
krishanprajapat | 19:27e5f2edaf26 | 526 | gPC.puts("adf configured\r\n");\ |
ee12b079 | 25:60964ad4f13b | 527 | gLEDR = !gLEDR;\ |
ee12b079 | 9:e9eaada136c6 | 528 | } |
ee12b079 | 9:e9eaada136c6 | 529 | |
krishanprajapat | 19:27e5f2edaf26 | 530 | #define adf_not_SDcard {\ |
krishanprajapat | 19:27e5f2edaf26 | 531 | sent_tmfrom_SDcard = false;\ |
krishanprajapat | 19:27e5f2edaf26 | 532 | configure_adf;\ |
krishanprajapat | 19:27e5f2edaf26 | 533 | signal = COM_MNG_TMTC_SIGNAL_ADF_NSD;\ |
krishanprajapat | 19:27e5f2edaf26 | 534 | send_data;\ |
krishanprajapat | 19:27e5f2edaf26 | 535 | while(loop_on){\ |
krishanprajapat | 19:27e5f2edaf26 | 536 | wait_ms(COM_TX_TICKER_LIMIT);\ |
krishanprajapat | 19:27e5f2edaf26 | 537 | if(IRQ){\ |
ee12b079 | 20:0e856afd1cf1 | 538 | if(finish_write_data){\ |
ee12b079 | 20:0e856afd1cf1 | 539 | if(ADF_off){\ |
ee12b079 | 20:0e856afd1cf1 | 540 | SPI_mutex.lock();\ |
ee12b079 | 20:0e856afd1cf1 | 541 | gCS_ADF=0;\ |
ee12b079 | 20:0e856afd1cf1 | 542 | spi.write(0xB1);\ |
ee12b079 | 20:0e856afd1cf1 | 543 | gCS_ADF=1;\ |
ee12b079 | 20:0e856afd1cf1 | 544 | SPI_mutex.unlock();\ |
ee12b079 | 20:0e856afd1cf1 | 545 | loop_on = false;\ |
ee12b079 | 20:0e856afd1cf1 | 546 | gPC.puts("Transmission done\r\n");\ |
ee12b079 | 20:0e856afd1cf1 | 547 | }\ |
ee12b079 | 20:0e856afd1cf1 | 548 | else{\ |
ee12b079 | 20:0e856afd1cf1 | 549 | ADF_off = true;\ |
ee12b079 | 20:0e856afd1cf1 | 550 | }\ |
ee12b079 | 20:0e856afd1cf1 | 551 | }else{\ |
ee12b079 | 20:0e856afd1cf1 | 552 | write_data;\ |
ee12b079 | 20:0e856afd1cf1 | 553 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
ee12b079 | 20:0e856afd1cf1 | 554 | }\ |
krishanprajapat | 19:27e5f2edaf26 | 555 | }\ |
krishanprajapat | 19:27e5f2edaf26 | 556 | }\ |
krishanprajapat | 19:27e5f2edaf26 | 557 | gPC.puts("after while loop\r\n");\ |
krishanprajapat | 19:27e5f2edaf26 | 558 | } |
krishanprajapat | 19:27e5f2edaf26 | 559 | |
krishanprajapat | 19:27e5f2edaf26 | 560 | |
krishanprajapat | 19:27e5f2edaf26 | 561 | |
krishanprajapat | 19:27e5f2edaf26 | 562 | |
krishanprajapat | 19:27e5f2edaf26 | 563 | |
krishanprajapat | 19:27e5f2edaf26 | 564 | |
krishanprajapat | 19:27e5f2edaf26 | 565 | |
krishanprajapat | 19:27e5f2edaf26 | 566 | |
krishanprajapat | 19:27e5f2edaf26 | 567 | |
krishanprajapat | 19:27e5f2edaf26 | 568 | |
krishanprajapat | 19:27e5f2edaf26 | 569 | |
krishanprajapat | 19:27e5f2edaf26 | 570 | |
krishanprajapat | 19:27e5f2edaf26 | 571 | |
krishanprajapat | 19:27e5f2edaf26 | 572 | |
shreeshas95 | 2:2caf2a9a13aa | 573 | // if( ADF_non_responsive_flag == false ){ |
krishanprajapat | 19:27e5f2edaf26 | 574 | // if(finish_write_data){ |
krishanprajapat | 19:27e5f2edaf26 | 575 | // if(ADF_off){ |
krishanprajapat | 19:27e5f2edaf26 | 576 | // break; |
krishanprajapat | 19:27e5f2edaf26 | 577 | // } |
krishanprajapat | 19:27e5f2edaf26 | 578 | // } |
krishanprajapat | 19:27e5f2edaf26 | 579 | // SPI_mutex.lock(); |
krishanprajapat | 19:27e5f2edaf26 | 580 | // ticker.detach(); |
krishanprajapat | 19:27e5f2edaf26 | 581 | // // wait_ms(35); |
krishanprajapat | 19:27e5f2edaf26 | 582 | // gCS_ADF=0; |
krishanprajapat | 19:27e5f2edaf26 | 583 | // spi.write(0xB1); |
krishanprajapat | 19:27e5f2edaf26 | 584 | // gCS_ADF=1; |
krishanprajapat | 19:27e5f2edaf26 | 585 | // SPI_mutex.unlock(); |
krishanprajapat | 19:27e5f2edaf26 | 586 | // loop_on = false; |
krishanprajapat | 19:27e5f2edaf26 | 587 | // gPC.puts("Transmission done\r\n"); |
krishanprajapat | 19:27e5f2edaf26 | 588 | // } |
krishanprajapat | 19:27e5f2edaf26 | 589 | // else{ |
krishanprajapat | 19:27e5f2edaf26 | 590 | // ADF_off = true; |
krishanprajapat | 19:27e5f2edaf26 | 591 | // } |
krishanprajapat | 19:27e5f2edaf26 | 592 | // }else{ |
krishanprajapat | 19:27e5f2edaf26 | 593 | // write_data; |
krishanprajapat | 19:27e5f2edaf26 | 594 | // snd_tm.transmit_data(buffer_112,&last_buffer); |
krishanprajapat | 19:27e5f2edaf26 | 595 | // } |
shreeshas95 | 2:2caf2a9a13aa | 596 | // } |
shreeshas95 | 2:2caf2a9a13aa | 597 | // else{ |
shreeshas95 | 2:2caf2a9a13aa | 598 | // gPC.puts("ADF non responsive\r\n"); |
shreeshas95 | 2:2caf2a9a13aa | 599 | // break; |
ee12b079 | 20:0e856afd1cf1 | 600 | // } |