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