Repository for testing ADF code of COM_TMTC_SIMPLE
Fork of COM_MNG_TMTC_SIMPLE by
adf2.h@4:e37674541504, 2015-12-24 (annotated)
- Committer:
- shekhar
- Date:
- Thu Dec 24 18:38:12 2015 +0000
- Revision:
- 4:e37674541504
ADF code to be tested
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shekhar | 4:e37674541504 | 1 | //without reset feature , with state checks. |
shekhar | 4:e37674541504 | 2 | #include<iostream> |
shekhar | 4:e37674541504 | 3 | #include"mbed.h" |
shekhar | 4:e37674541504 | 4 | #define ADF_IRQ PTA14 |
shekhar | 4:e37674541504 | 5 | #define SPI_MOSI PTE1 |
shekhar | 4:e37674541504 | 6 | #define SPI_MISO PTE3 |
shekhar | 4:e37674541504 | 7 | #define SPI_CLK PTE2 |
shekhar | 4:e37674541504 | 8 | #define SPI_CS_ADF PTA15 |
shekhar | 4:e37674541504 | 9 | //Serial gPC( USBTX, USBRX ); |
shekhar | 4:e37674541504 | 10 | //gPC.baud(1200); |
shekhar | 4:e37674541504 | 11 | InterruptIn IRQ(ADF_IRQ); |
shekhar | 4:e37674541504 | 12 | Ticker ticker; |
shekhar | 4:e37674541504 | 13 | //SPI spi(PTE1, PTE3, PTE2); |
shekhar | 4:e37674541504 | 14 | //DigitalOut gCS_ADF(SPI_CS_ADF); |
shekhar | 4:e37674541504 | 15 | unsigned int Adf_data_counter=0; |
shekhar | 4:e37674541504 | 16 | unsigned char status =0; |
shekhar | 4:e37674541504 | 17 | unsigned int cmd_err_cnt=0; |
shekhar | 4:e37674541504 | 18 | unsigned int state_err_cnt=0; |
shekhar | 4:e37674541504 | 19 | unsigned int miso_err_cnt=0; |
shekhar | 4:e37674541504 | 20 | unsigned int hw_reset_err_cnt=0; |
shekhar | 4:e37674541504 | 21 | bool bcn_flag=0; |
shekhar | 4:e37674541504 | 22 | bool bbram_flag=0; |
shekhar | 4:e37674541504 | 23 | |
shekhar | 4:e37674541504 | 24 | bool stop_transmission=false; |
shekhar | 4:e37674541504 | 25 | bool sent_tmfrom_SDcard; |
shekhar | 4:e37674541504 | 26 | bool loop_on; |
shekhar | 4:e37674541504 | 27 | bool ADF_off; |
shekhar | 4:e37674541504 | 28 | bool buffer_state; |
shekhar | 4:e37674541504 | 29 | uint8_t signal = 0x00; |
shekhar | 4:e37674541504 | 30 | uint8_t 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}; |
shekhar | 4:e37674541504 | 31 | uint8_t Adf_data[100]={}; //Data to be transmitted |
shekhar | 4:e37674541504 | 32 | //uint8_t buffer_112[112]; |
shekhar | 4:e37674541504 | 33 | //int initialise_card(); |
shekhar | 4:e37674541504 | 34 | //int disk_initialize(); |
shekhar | 4:e37674541504 | 35 | |
shekhar | 4:e37674541504 | 36 | |
shekhar | 4:e37674541504 | 37 | //void transmitdata(){ // copy the data to be transmitted to bufer_112 |
shekhar | 4:e37674541504 | 38 | // for(int i=0;i<112;i++){ |
shekhar | 4:e37674541504 | 39 | // buffer_112[i]=Adf_data[Adf_data_counter]; |
shekhar | 4:e37674541504 | 40 | // if(100==Adf_data_counter){ |
shekhar | 4:e37674541504 | 41 | // Adf_data_counter++; |
shekhar | 4:e37674541504 | 42 | // stop_transmission= true; |
shekhar | 4:e37674541504 | 43 | // break; |
shekhar | 4:e37674541504 | 44 | // } |
shekhar | 4:e37674541504 | 45 | // } |
shekhar | 4:e37674541504 | 46 | //} |
shekhar | 4:e37674541504 | 47 | |
shekhar | 4:e37674541504 | 48 | #define bbram_write {\ |
shekhar | 4:e37674541504 | 49 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 50 | spi.write(0xB0);\ |
shekhar | 4:e37674541504 | 51 | wait_us(300);\ |
shekhar | 4:e37674541504 | 52 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 53 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 54 | for(int i=0;i<66;i++){\ |
shekhar | 4:e37674541504 | 55 | spi.write(bbram_buffer[i]);\ |
shekhar | 4:e37674541504 | 56 | }\ |
shekhar | 4:e37674541504 | 57 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 58 | } |
shekhar | 4:e37674541504 | 59 | //------------------------------------------------------------------------ |
shekhar | 4:e37674541504 | 60 | // state checking functions |
shekhar | 4:e37674541504 | 61 | //bool assrt_phy_off( int, int, int); |
shekhar | 4:e37674541504 | 62 | //bool assrt_phy_on( int,int,int); |
shekhar | 4:e37674541504 | 63 | //bool assrt_phy_tx(int,int,int); |
shekhar | 4:e37674541504 | 64 | |
shekhar | 4:e37674541504 | 65 | #define START_ADDRESS 0x020; |
shekhar | 4:e37674541504 | 66 | #define MISO_PIN PTE3 |
shekhar | 4:e37674541504 | 67 | /**************Defining Counter Limits**************/ |
shekhar | 4:e37674541504 | 68 | #define THRS 20 |
shekhar | 4:e37674541504 | 69 | #define STATE_ERR_THRS 20 |
shekhar | 4:e37674541504 | 70 | #define PHY_OFF_EXEC_TIME 300 |
shekhar | 4:e37674541504 | 71 | #define PHY_ON_EXEC_TIME 300 |
shekhar | 4:e37674541504 | 72 | #define PHY_TX_EXEC_TIME 600 |
shekhar | 4:e37674541504 | 73 | /******DEFINING COMMANDS*********/ |
shekhar | 4:e37674541504 | 74 | #define CMD_HW_RESET 0xC8 |
shekhar | 4:e37674541504 | 75 | #define CMD_PHY_ON 0xB1 |
shekhar | 4:e37674541504 | 76 | #define CMD_PHY_OFF 0xB0 |
shekhar | 4:e37674541504 | 77 | #define CMD_PHY_TX 0xB5 |
shekhar | 4:e37674541504 | 78 | #define CMD_CONFIG_DEV 0xBB |
shekhar | 4:e37674541504 | 79 | |
shekhar | 4:e37674541504 | 80 | #define check_status {\ |
shekhar | 4:e37674541504 | 81 | unsigned char stat=0;\ |
shekhar | 4:e37674541504 | 82 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 83 | spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 84 | stat = spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 85 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 86 | status = stat;\ |
shekhar | 4:e37674541504 | 87 | } |
shekhar | 4:e37674541504 | 88 | |
shekhar | 4:e37674541504 | 89 | // all three arguments are int |
shekhar | 4:e37674541504 | 90 | #define assrt_phy_off(return_this) {\ |
shekhar | 4:e37674541504 | 91 | int cmd_err_cnt = 0;\ |
shekhar | 4:e37674541504 | 92 | int spi_err_cnt = 0;\ |
shekhar | 4:e37674541504 | 93 | int state_err_cnt = 0;\ |
shekhar | 4:e37674541504 | 94 | for(int i = 0 ; i < 40 ;i++){\ |
shekhar | 4:e37674541504 | 95 | check_status;\ |
shekhar | 4:e37674541504 | 96 | if(status == 0xB1){\ |
shekhar | 4:e37674541504 | 97 | return_this = 0;\ |
shekhar | 4:e37674541504 | 98 | break;\ |
shekhar | 4:e37674541504 | 99 | }\ |
shekhar | 4:e37674541504 | 100 | else if(cmd_err_cnt>THRS||spi_err_cnt>THRS){\ |
shekhar | 4:e37674541504 | 101 | return_this = 1;\ |
shekhar | 4:e37674541504 | 102 | break;\ |
shekhar | 4:e37674541504 | 103 | }\ |
shekhar | 4:e37674541504 | 104 | else if(state_err_cnt>STATE_ERR_THRS){\ |
shekhar | 4:e37674541504 | 105 | return_this = 1;\ |
shekhar | 4:e37674541504 | 106 | break;\ |
shekhar | 4:e37674541504 | 107 | }\ |
shekhar | 4:e37674541504 | 108 | else if( (status & 0xA0) == 0xA0 ){\ |
shekhar | 4:e37674541504 | 109 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 110 | spi.write(CMD_PHY_OFF);\ |
shekhar | 4:e37674541504 | 111 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 112 | wait_us(PHY_OFF_EXEC_TIME);\ |
shekhar | 4:e37674541504 | 113 | state_err_cnt++;\ |
shekhar | 4:e37674541504 | 114 | }\ |
shekhar | 4:e37674541504 | 115 | else if(status&0x80==0x00){\ |
shekhar | 4:e37674541504 | 116 | wait_ms(5);\ |
shekhar | 4:e37674541504 | 117 | spi_err_cnt++;\ |
shekhar | 4:e37674541504 | 118 | }\ |
shekhar | 4:e37674541504 | 119 | else {\ |
shekhar | 4:e37674541504 | 120 | wait_ms(1);\ |
shekhar | 4:e37674541504 | 121 | cmd_err_cnt++;\ |
shekhar | 4:e37674541504 | 122 | }\ |
shekhar | 4:e37674541504 | 123 | }\ |
shekhar | 4:e37674541504 | 124 | } |
shekhar | 4:e37674541504 | 125 | |
shekhar | 4:e37674541504 | 126 | |
shekhar | 4:e37674541504 | 127 | |
shekhar | 4:e37674541504 | 128 | |
shekhar | 4:e37674541504 | 129 | #define initial_adf_check {\ |
shekhar | 4:e37674541504 | 130 | spi.write(CMD_PHY_OFF);\ |
shekhar | 4:e37674541504 | 131 | int tempReturn = 0;\ |
shekhar | 4:e37674541504 | 132 | bool flag = false;\ |
shekhar | 4:e37674541504 | 133 | while( hw_reset_err_cnt < 2 ){\ |
shekhar | 4:e37674541504 | 134 | assrt_phy_off( tempReturn);\ |
shekhar | 4:e37674541504 | 135 | if( !tempReturn ){\ |
shekhar | 4:e37674541504 | 136 | bbram_write;\ |
shekhar | 4:e37674541504 | 137 | bbram_flag=1;\ |
shekhar | 4:e37674541504 | 138 | flag = true;\ |
shekhar | 4:e37674541504 | 139 | break;\ |
shekhar | 4:e37674541504 | 140 | }\ |
shekhar | 4:e37674541504 | 141 | else{\ |
shekhar | 4:e37674541504 | 142 | hardware_reset(0);\ |
shekhar | 4:e37674541504 | 143 | hw_reset_err_cnt++;\ |
shekhar | 4:e37674541504 | 144 | gPC.puts("Resetting hardware\r\n");\ |
shekhar | 4:e37674541504 | 145 | }\ |
shekhar | 4:e37674541504 | 146 | }\ |
shekhar | 4:e37674541504 | 147 | if( flag == false ){\ |
shekhar | 4:e37674541504 | 148 | gPC.puts("Seems to be SPI problem\r\n");\ |
shekhar | 4:e37674541504 | 149 | }\ |
shekhar | 4:e37674541504 | 150 | assrt_phy_off(tempReturn);\ |
shekhar | 4:e37674541504 | 151 | if(!bbram_flag){\ |
shekhar | 4:e37674541504 | 152 | bcn_flag=1;\ |
shekhar | 4:e37674541504 | 153 | }\ |
shekhar | 4:e37674541504 | 154 | } |
shekhar | 4:e37674541504 | 155 | |
shekhar | 4:e37674541504 | 156 | bool hardware_reset(int bcn_call){ |
shekhar | 4:e37674541504 | 157 | for(int i= 0; i < 20 ; i++){ |
shekhar | 4:e37674541504 | 158 | gCS_ADF=0; |
shekhar | 4:e37674541504 | 159 | spi.write(CMD_HW_RESET); |
shekhar | 4:e37674541504 | 160 | gCS_ADF=1; |
shekhar | 4:e37674541504 | 161 | wait_ms(2);// Typically 1 ms |
shekhar | 4:e37674541504 | 162 | int count=0; |
shekhar | 4:e37674541504 | 163 | int temp_return = 0; |
shekhar | 4:e37674541504 | 164 | while(count<10 && miso_err_cnt<10){ |
shekhar | 4:e37674541504 | 165 | if(MISO_PIN){ |
shekhar | 4:e37674541504 | 166 | assrt_phy_off(temp_return); |
shekhar | 4:e37674541504 | 167 | if(!temp_return){ |
shekhar | 4:e37674541504 | 168 | return 0; |
shekhar | 4:e37674541504 | 169 | } |
shekhar | 4:e37674541504 | 170 | count++; |
shekhar | 4:e37674541504 | 171 | } |
shekhar | 4:e37674541504 | 172 | else{ |
shekhar | 4:e37674541504 | 173 | wait_us(50); |
shekhar | 4:e37674541504 | 174 | miso_err_cnt++; |
shekhar | 4:e37674541504 | 175 | } |
shekhar | 4:e37674541504 | 176 | } |
shekhar | 4:e37674541504 | 177 | } |
shekhar | 4:e37674541504 | 178 | return 1; |
shekhar | 4:e37674541504 | 179 | } |
shekhar | 4:e37674541504 | 180 | //for reseting the transmission call assert function after b5 and b1. after b1 assert_phi_on and after b5 assert_phi_tx. |
shekhar | 4:e37674541504 | 181 | //---------------------------------------------------------------------------- |
shekhar | 4:e37674541504 | 182 | |
shekhar | 4:e37674541504 | 183 | # define initiate {\ |
shekhar | 4:e37674541504 | 184 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 185 | spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 186 | spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 187 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 188 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 189 | spi.write(0x08);\ |
shekhar | 4:e37674541504 | 190 | spi.write(0x14);\ |
shekhar | 4:e37674541504 | 191 | spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 192 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 193 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 194 | spi.write(0x08);\ |
shekhar | 4:e37674541504 | 195 | spi.write(0x15);\ |
shekhar | 4:e37674541504 | 196 | spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 197 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 198 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 199 | spi.write(0x09);\ |
shekhar | 4:e37674541504 | 200 | spi.write(0x24);\ |
shekhar | 4:e37674541504 | 201 | spi.write(0x20);\ |
shekhar | 4:e37674541504 | 202 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 203 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 204 | spi.write(0x09);\ |
shekhar | 4:e37674541504 | 205 | spi.write(0x37);\ |
shekhar | 4:e37674541504 | 206 | spi.write(0xE0);\ |
shekhar | 4:e37674541504 | 207 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 208 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 209 | spi.write(0x09);\ |
shekhar | 4:e37674541504 | 210 | spi.write(0x36);\ |
shekhar | 4:e37674541504 | 211 | spi.write(0x70);\ |
shekhar | 4:e37674541504 | 212 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 213 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 214 | spi.write(0x09);\ |
shekhar | 4:e37674541504 | 215 | spi.write(0x39);\ |
shekhar | 4:e37674541504 | 216 | spi.write(0x10);\ |
shekhar | 4:e37674541504 | 217 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 218 | } |
shekhar | 4:e37674541504 | 219 | |
shekhar | 4:e37674541504 | 220 | |
shekhar | 4:e37674541504 | 221 | #define write_data {\ |
shekhar | 4:e37674541504 | 222 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 223 | spi.write(0x0B);\ |
shekhar | 4:e37674541504 | 224 | spi.write(0x36);\ |
shekhar | 4:e37674541504 | 225 | spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 226 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 227 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 228 | if(buffer_state && last_buffer==false){\ |
shekhar | 4:e37674541504 | 229 | spi.write(0x18);\ |
shekhar | 4:e37674541504 | 230 | spi.write(0x20);\ |
shekhar | 4:e37674541504 | 231 | for(unsigned char i=0; i<112;i++){\ |
shekhar | 4:e37674541504 | 232 | spi.write(buffer_112[i]);\ |
shekhar | 4:e37674541504 | 233 | }\ |
shekhar | 4:e37674541504 | 234 | }\ |
shekhar | 4:e37674541504 | 235 | else if(last_buffer==false)\ |
shekhar | 4:e37674541504 | 236 | {\ |
shekhar | 4:e37674541504 | 237 | spi.write(0x18);\ |
shekhar | 4:e37674541504 | 238 | spi.write(0x90);\ |
shekhar | 4:e37674541504 | 239 | for(unsigned char i=0; i<112;i++){\ |
shekhar | 4:e37674541504 | 240 | spi.write(buffer_112[i]);\ |
shekhar | 4:e37674541504 | 241 | }\ |
shekhar | 4:e37674541504 | 242 | }\ |
shekhar | 4:e37674541504 | 243 | if(last_buffer)\ |
shekhar | 4:e37674541504 | 244 | {\ |
shekhar | 4:e37674541504 | 245 | for(unsigned char i=0; i<112;i++){\ |
shekhar | 4:e37674541504 | 246 | spi.write(buffer_112[i]);\ |
shekhar | 4:e37674541504 | 247 | }\ |
shekhar | 4:e37674541504 | 248 | ADF_off = true;\ |
shekhar | 4:e37674541504 | 249 | gPC.puts("adf_off\r\n");\ |
shekhar | 4:e37674541504 | 250 | }\ |
shekhar | 4:e37674541504 | 251 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 252 | buffer_state = !buffer_state;\ |
shekhar | 4:e37674541504 | 253 | } |
shekhar | 4:e37674541504 | 254 | //void send_tm_from_SD_card(){ |
shekhar | 4:e37674541504 | 255 | // } |
shekhar | 4:e37674541504 | 256 | // |
shekhar | 4:e37674541504 | 257 | void check(){ |
shekhar | 4:e37674541504 | 258 | if(IRQ){ |
shekhar | 4:e37674541504 | 259 | if(!ADF_off){ |
shekhar | 4:e37674541504 | 260 | write_data; |
shekhar | 4:e37674541504 | 261 | ADF_off=true; |
shekhar | 4:e37674541504 | 262 | } |
shekhar | 4:e37674541504 | 263 | else{ |
shekhar | 4:e37674541504 | 264 | write_data; |
shekhar | 4:e37674541504 | 265 | snd_tm.transmit_data(buffer_112,&last_buffer); |
shekhar | 4:e37674541504 | 266 | } |
shekhar | 4:e37674541504 | 267 | } |
shekhar | 4:e37674541504 | 268 | else{ |
shekhar | 4:e37674541504 | 269 | ticker.detach(); |
shekhar | 4:e37674541504 | 270 | gCS_ADF=0; |
shekhar | 4:e37674541504 | 271 | spi.write(0xB1); |
shekhar | 4:e37674541504 | 272 | gCS_ADF=1; |
shekhar | 4:e37674541504 | 273 | gPC.puts("transmission done\r\n"); |
shekhar | 4:e37674541504 | 274 | loop_on=false; |
shekhar | 4:e37674541504 | 275 | } |
shekhar | 4:e37674541504 | 276 | } |
shekhar | 4:e37674541504 | 277 | |
shekhar | 4:e37674541504 | 278 | // |
shekhar | 4:e37674541504 | 279 | //#define send_data {\ |
shekhar | 4:e37674541504 | 280 | // gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 281 | // spi.write(0xBB);\ |
shekhar | 4:e37674541504 | 282 | // gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 283 | // gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 284 | // spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 285 | // spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 286 | // gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 287 | // if(sent_tmfrom_SDcard){\ |
shekhar | 4:e37674541504 | 288 | // send_tm_from_SD_card();\ |
shekhar | 4:e37674541504 | 289 | // }else{\ |
shekhar | 4:e37674541504 | 290 | // transmitdata();\ |
shekhar | 4:e37674541504 | 291 | // }\ |
shekhar | 4:e37674541504 | 292 | // write_data;\ |
shekhar | 4:e37674541504 | 293 | // if(sent_tmfrom_SDcard){\ |
shekhar | 4:e37674541504 | 294 | // send_tm_from_SD_card();\ |
shekhar | 4:e37674541504 | 295 | // }else{\ |
shekhar | 4:e37674541504 | 296 | // transmitdata();\ |
shekhar | 4:e37674541504 | 297 | // }\ |
shekhar | 4:e37674541504 | 298 | // write_data;\ |
shekhar | 4:e37674541504 | 299 | // if(sent_tmfrom_SDcard){\ |
shekhar | 4:e37674541504 | 300 | // send_tm_from_SD_card();\ |
shekhar | 4:e37674541504 | 301 | // }else{\ |
shekhar | 4:e37674541504 | 302 | // transmitdata();\ |
shekhar | 4:e37674541504 | 303 | // }\ |
shekhar | 4:e37674541504 | 304 | // gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 305 | // spi.write(0xB1);\ |
shekhar | 4:e37674541504 | 306 | // gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 307 | // wait_us(300);\ |
shekhar | 4:e37674541504 | 308 | // gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 309 | // spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 310 | // spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 311 | // gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 312 | // gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 313 | // spi.write(0xB5);\ |
shekhar | 4:e37674541504 | 314 | // gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 315 | // wait_us(300);\ |
shekhar | 4:e37674541504 | 316 | // gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 317 | // spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 318 | // spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 319 | // gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 320 | // ticker.attach_us(&check,32000);\ |
shekhar | 4:e37674541504 | 321 | //} |
shekhar | 4:e37674541504 | 322 | |
shekhar | 4:e37674541504 | 323 | #define send_data {\ |
shekhar | 4:e37674541504 | 324 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 325 | spi.write(0xBB);\ |
shekhar | 4:e37674541504 | 326 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 327 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 328 | spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 329 | spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 330 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 331 | if(sent_tmfrom_SDcard){\ |
shekhar | 4:e37674541504 | 332 | }\ |
shekhar | 4:e37674541504 | 333 | else{\ |
shekhar | 4:e37674541504 | 334 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
shekhar | 4:e37674541504 | 335 | }\ |
shekhar | 4:e37674541504 | 336 | write_data;\ |
shekhar | 4:e37674541504 | 337 | if(sent_tmfrom_SDcard){\ |
shekhar | 4:e37674541504 | 338 | }else{\ |
shekhar | 4:e37674541504 | 339 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
shekhar | 4:e37674541504 | 340 | }\ |
shekhar | 4:e37674541504 | 341 | write_data;\ |
shekhar | 4:e37674541504 | 342 | if(sent_tmfrom_SDcard){\ |
shekhar | 4:e37674541504 | 343 | }else{\ |
shekhar | 4:e37674541504 | 344 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
shekhar | 4:e37674541504 | 345 | }\ |
shekhar | 4:e37674541504 | 346 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 347 | spi.write(0xB1);\ |
shekhar | 4:e37674541504 | 348 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 349 | wait_us(300);\ |
shekhar | 4:e37674541504 | 350 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 351 | spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 352 | spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 353 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 354 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 355 | spi.write(0xB5);\ |
shekhar | 4:e37674541504 | 356 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 357 | wait_us(300);\ |
shekhar | 4:e37674541504 | 358 | gCS_ADF=0;\ |
shekhar | 4:e37674541504 | 359 | spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 360 | spi.write(0xFF);\ |
shekhar | 4:e37674541504 | 361 | gCS_ADF=1;\ |
shekhar | 4:e37674541504 | 362 | ticker.attach_us(&check,32000);\ |
shekhar | 4:e37674541504 | 363 | } |
shekhar | 4:e37674541504 | 364 | |
shekhar | 4:e37674541504 | 365 | void adf_not_SDcard(){ |
shekhar | 4:e37674541504 | 366 | buffer_state = true; |
shekhar | 4:e37674541504 | 367 | last_buffer = false; |
shekhar | 4:e37674541504 | 368 | loop_on = true; |
shekhar | 4:e37674541504 | 369 | ADF_off = false; |
shekhar | 4:e37674541504 | 370 | sent_tmfrom_SDcard = false; |
shekhar | 4:e37674541504 | 371 | |
shekhar | 4:e37674541504 | 372 | // signal = COM_MNG_TMTC_SIGNAL_ADF_NSD; |
shekhar | 4:e37674541504 | 373 | initial_adf_check; |
shekhar | 4:e37674541504 | 374 | initiate; |
shekhar | 4:e37674541504 | 375 | send_data; |
shekhar | 4:e37674541504 | 376 | |
shekhar | 4:e37674541504 | 377 | // gPC.puts("Inside adf transmission\r\n"); |
shekhar | 4:e37674541504 | 378 | // ADF_non_responsive_timeout.attach(&ADF_non_responsive_fun, 10); |
shekhar | 4:e37674541504 | 379 | |
shekhar | 4:e37674541504 | 380 | } |