for frequency correction testing
Dependencies: FreescaleIAP SimpleDMA mbed-rtos mbed
Fork of CDMS_CODE by
adf.h@318:978d72f191f9, 2016-12-08 (annotated)
- Committer:
- ee12b079
- Date:
- Thu Dec 08 13:12:34 2016 +0000
- Revision:
- 318:978d72f191f9
- Parent:
- 317:31bb2e9eda85
- Child:
- 321:42bdefc37270
adf_temp, tc_curr, pa_hot
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shreeshas95 | 1:a0055b3280c8 | 1 | //without reset feature , with state checks. |
ee12b079 | 172:c508bbf7e89a | 2 | InterruptIn IRQ(ADF_IRQ); |
aniruddhv | 52:0bd68655c651 | 3 | //Ticker ticker; |
ee12b079 | 176:a5bfe3ca60b1 | 4 | |
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; |
ee12b079 | 288:aa93d6652381 | 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,/*PA Level Byte*/0x57/*PA Parameters*/,0x00,0x0B,0x37,0x00,0x00,0x40,0x0C,0x00,0x05,0x00,0x00,0x18,0x12,0x34,0x56,0x20,0x10,0xC4,0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0xE0,0x00,0x10,0x04,0x00,0x00,0x00,0x00,0x00}; |
ee12b079 | 268:ded5306a1fd1 | 11 | bool data_irq_err=0; |
ee12b079 | 268:ded5306a1fd1 | 12 | bool data_err= false; |
ee12b079 | 268:ded5306a1fd1 | 13 | unsigned char temp_byte=0x00; |
ee12b079 | 268:ded5306a1fd1 | 14 | unsigned char data_err1[112]; |
ee12b079 | 268:ded5306a1fd1 | 15 | unsigned char data_err_cnt=0; |
ee12b079 | 268:ded5306a1fd1 | 16 | unsigned int byte_count =0; |
ee12b079 | 268:ded5306a1fd1 | 17 | #define DATA_ERR_THRS 20 |
ee12b079 | 268:ded5306a1fd1 | 18 | bool rolling_buffer_settings_error=true; |
ee12b079 | 268:ded5306a1fd1 | 19 | bool bbram_write_success=true; |
ee12b079 | 268:ded5306a1fd1 | 20 | int bbram_err_cnt=0; |
ee12b079 | 268:ded5306a1fd1 | 21 | int rbp_err_cnt=0; |
ee12b079 | 268:ded5306a1fd1 | 22 | bool reset_flag=false; |
ee12b079 | 268:ded5306a1fd1 | 23 | #define RBP_THRS 4 |
ee12b079 | 268:ded5306a1fd1 | 24 | bool quit_configuration=false; |
ee12b079 | 268:ded5306a1fd1 | 25 | bool power_reset_flag=false; |
ee12b079 | 268:ded5306a1fd1 | 26 | unsigned int power_reset_count=0; |
ee12b079 | 268:ded5306a1fd1 | 27 | bool Configuration_done=false; |
ee12b079 | 268:ded5306a1fd1 | 28 | #define HW_THRS 2 |
ee12b079 | 317:31bb2e9eda85 | 29 | bool hw_reset_flag = false; |
ee12b079 | 317:31bb2e9eda85 | 30 | uint8_t firstbyte; |
ee12b079 | 317:31bb2e9eda85 | 31 | uint8_t secondbyte; |
ee12b079 | 268:ded5306a1fd1 | 32 | |
ee12b079 | 317:31bb2e9eda85 | 33 | //ADF temperature reading |
ee12b079 | 317:31bb2e9eda85 | 34 | #define temp_correction_value 0 |
ee12b079 | 317:31bb2e9eda85 | 35 | |
ee12b079 | 268:ded5306a1fd1 | 36 | #define TRANSMIT_LEN_1 0xFF |
ee12b079 | 268:ded5306a1fd1 | 37 | #define TRANSMIT_LEN_2 0xFF |
ee12b079 | 268:ded5306a1fd1 | 38 | /***/ |
ee12b079 | 268:ded5306a1fd1 | 39 | Timer T; |
ee12b079 | 9:e9eaada136c6 | 40 | |
shreeshas95 | 1:a0055b3280c8 | 41 | #define START_ADDRESS 0x020; |
shreeshas95 | 1:a0055b3280c8 | 42 | #define MISO_PIN PTE3 |
shreeshas95 | 1:a0055b3280c8 | 43 | /**************Defining Counter Limits**************/ |
shreeshas95 | 1:a0055b3280c8 | 44 | #define THRS 20 |
shreeshas95 | 1:a0055b3280c8 | 45 | #define STATE_ERR_THRS 20 |
shreeshas95 | 1:a0055b3280c8 | 46 | #define PHY_OFF_EXEC_TIME 300 |
shreeshas95 | 1:a0055b3280c8 | 47 | #define PHY_ON_EXEC_TIME 300 |
shreeshas95 | 1:a0055b3280c8 | 48 | #define PHY_TX_EXEC_TIME 600 |
shreeshas95 | 1:a0055b3280c8 | 49 | /******DEFINING COMMANDS*********/ |
shreeshas95 | 1:a0055b3280c8 | 50 | #define CMD_HW_RESET 0xC8 |
shreeshas95 | 1:a0055b3280c8 | 51 | #define CMD_PHY_ON 0xB1 |
shreeshas95 | 1:a0055b3280c8 | 52 | #define CMD_PHY_OFF 0xB0 |
shreeshas95 | 1:a0055b3280c8 | 53 | #define CMD_PHY_TX 0xB5 |
shreeshas95 | 1:a0055b3280c8 | 54 | #define CMD_CONFIG_DEV 0xBB |
ee12b079 | 268:ded5306a1fd1 | 55 | /**STATES**/ |
ee12b079 | 268:ded5306a1fd1 | 56 | //======================= |
ee12b079 | 268:ded5306a1fd1 | 57 | #define PHY_OFF 0xB1 |
ee12b079 | 268:ded5306a1fd1 | 58 | #define PHY_ON 0xB2 |
ee12b079 | 268:ded5306a1fd1 | 59 | #define PHY_TX 0xB4 |
ee12b079 | 268:ded5306a1fd1 | 60 | #define BUSY 0x00 |
ee12b079 | 268:ded5306a1fd1 | 61 | //=================================================== |
ee12b079 | 268:ded5306a1fd1 | 62 | |
ee12b079 | 317:31bb2e9eda85 | 63 | #define POWER_RESET_THRS 2 |
ee12b079 | 317:31bb2e9eda85 | 64 | #define HW_RESET_THRS 2 |
ee12b079 | 317:31bb2e9eda85 | 65 | |
ee12b079 | 268:ded5306a1fd1 | 66 | unsigned int Adf_data_counter=0; |
ee12b079 | 268:ded5306a1fd1 | 67 | unsigned char status =0; |
ee12b079 | 268:ded5306a1fd1 | 68 | unsigned int cmd_err_cnt=0; |
ee12b079 | 268:ded5306a1fd1 | 69 | unsigned int data_length; |
ee12b079 | 268:ded5306a1fd1 | 70 | unsigned int state_err_cnt=0; |
ee12b079 | 268:ded5306a1fd1 | 71 | unsigned int miso_err_cnt=0; |
ee12b079 | 268:ded5306a1fd1 | 72 | unsigned int hw_reset_err_cnt=0; |
ee12b079 | 268:ded5306a1fd1 | 73 | unsigned int counter =0; |
ee12b079 | 268:ded5306a1fd1 | 74 | bool temp_return = 0; |
ee12b079 | 268:ded5306a1fd1 | 75 | bool bcn_flag=0; |
ee12b079 | 268:ded5306a1fd1 | 76 | bool bbram_flag=0; |
ee12b079 | 268:ded5306a1fd1 | 77 | |
ee12b079 | 268:ded5306a1fd1 | 78 | bool stop_transmission=false; |
ee12b079 | 268:ded5306a1fd1 | 79 | |
ee12b079 | 268:ded5306a1fd1 | 80 | #define reset_flags {\ |
ee12b079 | 268:ded5306a1fd1 | 81 | finish_write_data = false;\ |
ee12b079 | 268:ded5306a1fd1 | 82 | buffer_state = true;\ |
ee12b079 | 268:ded5306a1fd1 | 83 | last_buffer = false;\ |
ee12b079 | 268:ded5306a1fd1 | 84 | loop_on = true;\ |
ee12b079 | 268:ded5306a1fd1 | 85 | ADF_off = false;\ |
ee12b079 | 268:ded5306a1fd1 | 86 | buffer_state = true;\ |
ee12b079 | 268:ded5306a1fd1 | 87 | loop_on = true;\ |
ee12b079 | 268:ded5306a1fd1 | 88 | ADF_off = false;\ |
ee12b079 | 271:72529b247333 | 89 | /*sent_tmfrom_SDcard = false;*/\ |
ee12b079 | 268:ded5306a1fd1 | 90 | Adf_data_counter=0;\ |
ee12b079 | 268:ded5306a1fd1 | 91 | status =0;\ |
ee12b079 | 268:ded5306a1fd1 | 92 | cmd_err_cnt=0;\ |
ee12b079 | 268:ded5306a1fd1 | 93 | data_length;\ |
ee12b079 | 268:ded5306a1fd1 | 94 | state_err_cnt=0;\ |
ee12b079 | 268:ded5306a1fd1 | 95 | miso_err_cnt=0;\ |
ee12b079 | 268:ded5306a1fd1 | 96 | hw_reset_err_cnt=0;\ |
ee12b079 | 268:ded5306a1fd1 | 97 | counter =0;\ |
ee12b079 | 268:ded5306a1fd1 | 98 | bcn_flag=0;\ |
ee12b079 | 268:ded5306a1fd1 | 99 | bbram_flag=0;\ |
ee12b079 | 268:ded5306a1fd1 | 100 | stop_transmission=false;\ |
ee12b079 | 268:ded5306a1fd1 | 101 | } |
ee12b079 | 268:ded5306a1fd1 | 102 | |
ee12b079 | 268:ded5306a1fd1 | 103 | |
ee12b079 | 268:ded5306a1fd1 | 104 | int err_arr[64]; |
ee12b079 | 268:ded5306a1fd1 | 105 | bool bbram_err=false; |
ee12b079 | 268:ded5306a1fd1 | 106 | int err_idx=-1; |
ee12b079 | 268:ded5306a1fd1 | 107 | int err[64]; |
ee12b079 | 268:ded5306a1fd1 | 108 | #define bbram_check gCS_ADF=0;\ |
ee12b079 | 268:ded5306a1fd1 | 109 | for(int i=0;i<64;i++){\ |
ee12b079 | 268:ded5306a1fd1 | 110 | err_arr[i]=0;\ |
ee12b079 | 268:ded5306a1fd1 | 111 | }\ |
ee12b079 | 268:ded5306a1fd1 | 112 | for(int i=0;i<64;i++){\ |
ee12b079 | 268:ded5306a1fd1 | 113 | err[i]=0;\ |
ee12b079 | 268:ded5306a1fd1 | 114 | }\ |
ee12b079 | 268:ded5306a1fd1 | 115 | bbram_err=false;\ |
ee12b079 | 268:ded5306a1fd1 | 116 | gCS_ADF=0;\ |
ee12b079 | 268:ded5306a1fd1 | 117 | spi.write(0x39);\ |
ee12b079 | 268:ded5306a1fd1 | 118 | spi.write(0x00);\ |
ee12b079 | 268:ded5306a1fd1 | 119 | spi.write(0xFF);\ |
ee12b079 | 268:ded5306a1fd1 | 120 | for(int i=0;i<64;i++){\ |
ee12b079 | 268:ded5306a1fd1 | 121 | err_arr[i]=spi.write(0xFF);\ |
ee12b079 | 268:ded5306a1fd1 | 122 | if(err_arr[i]!=bbram_buffer[i+2]){\ |
ee12b079 | 268:ded5306a1fd1 | 123 | err[i]=1;\ |
ee12b079 | 268:ded5306a1fd1 | 124 | bbram_err=true;\ |
ee12b079 | 268:ded5306a1fd1 | 125 | }\ |
ee12b079 | 268:ded5306a1fd1 | 126 | }\ |
ee12b079 | 268:ded5306a1fd1 | 127 | gCS_ADF=1;\ |
ee12b079 | 268:ded5306a1fd1 | 128 | if(!bbram_err)\ |
ee12b079 | 268:ded5306a1fd1 | 129 | gPC.printf("BBRAM verified \r\n");\ |
ee12b079 | 268:ded5306a1fd1 | 130 | else\ |
ee12b079 | 268:ded5306a1fd1 | 131 | gPC.printf("BBRAM error \r\n");\ |
ee12b079 | 176:a5bfe3ca60b1 | 132 | |
ee12b079 | 268:ded5306a1fd1 | 133 | |
ee12b079 | 268:ded5306a1fd1 | 134 | bool tx_loop=1; |
ee12b079 | 268:ded5306a1fd1 | 135 | |
ee12b079 | 268:ded5306a1fd1 | 136 | #define PRNT_ONCE {\ |
ee12b079 | 268:ded5306a1fd1 | 137 | gPC.printf("%d %d lol_ what?\r\n",segment_len,EOS_len);\ |
ee12b079 | 268:ded5306a1fd1 | 138 | } |
ee12b079 | 268:ded5306a1fd1 | 139 | |
ee12b079 | 268:ded5306a1fd1 | 140 | #define bbram_write {\ |
ee12b079 | 268:ded5306a1fd1 | 141 | gCS_ADF=0;\ |
ee12b079 | 268:ded5306a1fd1 | 142 | spi.write(0xB0);\ |
ee12b079 | 268:ded5306a1fd1 | 143 | wait_us(300);\ |
ee12b079 | 268:ded5306a1fd1 | 144 | gCS_ADF=1;\ |
ee12b079 | 268:ded5306a1fd1 | 145 | gCS_ADF=0;\ |
ee12b079 | 268:ded5306a1fd1 | 146 | for(int i=0;i<66;i++){\ |
ee12b079 | 268:ded5306a1fd1 | 147 | spi.write(bbram_buffer[i]);\ |
ee12b079 | 268:ded5306a1fd1 | 148 | }\ |
ee12b079 | 268:ded5306a1fd1 | 149 | gCS_ADF=1;\ |
ee12b079 | 268:ded5306a1fd1 | 150 | } |
ee12b079 | 268:ded5306a1fd1 | 151 | //------------------------------------------------------------------------ |
ee12b079 | 268:ded5306a1fd1 | 152 | // state checking functions |
ee12b079 | 268:ded5306a1fd1 | 153 | //bool assrt_phy_off( int, int, int); |
ee12b079 | 268:ded5306a1fd1 | 154 | //bool assrt_phy_on( int,int,int); |
ee12b079 | 268:ded5306a1fd1 | 155 | //bool assrt_phy_tx(int,int,int); |
ee12b079 | 268:ded5306a1fd1 | 156 | |
shreeshas95 | 1:a0055b3280c8 | 157 | #define check_status {\ |
shreeshas95 | 1:a0055b3280c8 | 158 | unsigned char stat=0;\ |
shreeshas95 | 1:a0055b3280c8 | 159 | gCS_ADF=0;\ |
ee12b079 | 176:a5bfe3ca60b1 | 160 | spi.write(0xFF);\ |
ee12b079 | 176:a5bfe3ca60b1 | 161 | stat = spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 162 | gCS_ADF=1;\ |
ee12b079 | 176:a5bfe3ca60b1 | 163 | status = stat;\ |
shreeshas95 | 1:a0055b3280c8 | 164 | } |
ee12b079 | 271:72529b247333 | 165 | /***********************/ |
ee12b079 | 271:72529b247333 | 166 | /**********Restart ADF**************/ |
ee12b079 | 271:72529b247333 | 167 | |
ee12b079 | 271:72529b247333 | 168 | /**************************/ |
ee12b079 | 268:ded5306a1fd1 | 169 | |
ee12b079 | 268:ded5306a1fd1 | 170 | /*CMD_VAR*/ |
ee12b079 | 268:ded5306a1fd1 | 171 | bool cmd_bit=true; |
ee12b079 | 268:ded5306a1fd1 | 172 | bool cmd_err_flag=false; |
ee12b079 | 268:ded5306a1fd1 | 173 | unsigned char command = 0x00; |
ee12b079 | 271:72529b247333 | 174 | void CMD(uint8_t command) { |
ee12b079 | 271:72529b247333 | 175 | cmd_err_cnt=0; |
ee12b079 | 271:72529b247333 | 176 | cmd_err_flag=false; |
ee12b079 | 271:72529b247333 | 177 | while(cmd_err_cnt<3) { |
ee12b079 | 271:72529b247333 | 178 | check_status; |
ee12b079 | 271:72529b247333 | 179 | cmd_bit=status&0x20; |
ee12b079 | 271:72529b247333 | 180 | if(cmd_bit) { |
ee12b079 | 271:72529b247333 | 181 | gCS_ADF=0; |
ee12b079 | 271:72529b247333 | 182 | spi.write(command); |
ee12b079 | 271:72529b247333 | 183 | gCS_ADF=1; |
ee12b079 | 271:72529b247333 | 184 | break; |
ee12b079 | 271:72529b247333 | 185 | } else { |
ee12b079 | 271:72529b247333 | 186 | wait_us(5); |
ee12b079 | 271:72529b247333 | 187 | cmd_err_cnt++; |
ee12b079 | 271:72529b247333 | 188 | } |
ee12b079 | 271:72529b247333 | 189 | } |
ee12b079 | 271:72529b247333 | 190 | if(cmd_err_cnt==3) { |
ee12b079 | 271:72529b247333 | 191 | cmd_err_flag=true; |
ee12b079 | 271:72529b247333 | 192 | } |
ee12b079 | 268:ded5306a1fd1 | 193 | } |
ee12b079 | 271:72529b247333 | 194 | |
ee12b079 | 271:72529b247333 | 195 | // all three arguments are int |
ee12b079 | 268:ded5306a1fd1 | 196 | #define assrt_phy_off {\ |
ee12b079 | 268:ded5306a1fd1 | 197 | int state_err_cnt = 0;\ |
ee12b079 | 268:ded5306a1fd1 | 198 | CMD(CMD_PHY_OFF);\ |
ee12b079 | 268:ded5306a1fd1 | 199 | if(cmd_err_flag){\ |
ee12b079 | 268:ded5306a1fd1 | 200 | temp_return=1;\ |
chaithanyarss | 261:1e54415b34d3 | 201 | }\ |
ee12b079 | 268:ded5306a1fd1 | 202 | else{\ |
ee12b079 | 268:ded5306a1fd1 | 203 | for(int i = 0 ; i < 40 ;i++){\ |
ee12b079 | 268:ded5306a1fd1 | 204 | CMD(CMD_PHY_OFF);\ |
ee12b079 | 268:ded5306a1fd1 | 205 | check_status;\ |
ee12b079 | 268:ded5306a1fd1 | 206 | if(status == PHY_OFF){\ |
ee12b079 | 268:ded5306a1fd1 | 207 | temp_return = 0;\ |
ee12b079 | 268:ded5306a1fd1 | 208 | break;\ |
ee12b079 | 268:ded5306a1fd1 | 209 | }\ |
ee12b079 | 268:ded5306a1fd1 | 210 | else if(state_err_cnt>THRS){\ |
ee12b079 | 268:ded5306a1fd1 | 211 | temp_return = 1;\ |
ee12b079 | 268:ded5306a1fd1 | 212 | break;\ |
ee12b079 | 268:ded5306a1fd1 | 213 | }\ |
ee12b079 | 268:ded5306a1fd1 | 214 | else {\ |
ee12b079 | 268:ded5306a1fd1 | 215 | wait_ms(1);\ |
ee12b079 | 268:ded5306a1fd1 | 216 | }\ |
shreeshas95 | 1:a0055b3280c8 | 217 | }\ |
ee12b079 | 248:da9d1bd999da | 218 | }\ |
ee12b079 | 248:da9d1bd999da | 219 | } |
ee12b079 | 268:ded5306a1fd1 | 220 | |
ee12b079 | 317:31bb2e9eda85 | 221 | bool dummy_digitalOut_1=0; |
ee12b079 | 317:31bb2e9eda85 | 222 | #define power_reset{\ |
ee12b079 | 317:31bb2e9eda85 | 223 | dummy_digitalOut_1=0;\ |
ee12b079 | 317:31bb2e9eda85 | 224 | wait_ms(10);\ |
ee12b079 | 317:31bb2e9eda85 | 225 | dummy_digitalOut_1=1;\ |
ee12b079 | 317:31bb2e9eda85 | 226 | power_reset_flag=false;\ |
ee12b079 | 317:31bb2e9eda85 | 227 | power_reset_count++;\ |
ee12b079 | 317:31bb2e9eda85 | 228 | wait_ms(10);\ |
ee12b079 | 317:31bb2e9eda85 | 229 | }\ |
ee12b079 | 317:31bb2e9eda85 | 230 | |
ee12b079 | 318:978d72f191f9 | 231 | void get_temp_and_txcurr(){ |
ee12b079 | 317:31bb2e9eda85 | 232 | /*ADF Temperature reading*/; |
ee12b079 | 317:31bb2e9eda85 | 233 | gCS_ADF=0; |
ee12b079 | 317:31bb2e9eda85 | 234 | spi.write(0x1B); |
ee12b079 | 317:31bb2e9eda85 | 235 | spi.write(0x24); |
ee12b079 | 317:31bb2e9eda85 | 236 | spi.write(0x10); |
ee12b079 | 317:31bb2e9eda85 | 237 | gCS_ADF=1; |
ee12b079 | 317:31bb2e9eda85 | 238 | gCS_ADF=0; |
ee12b079 | 317:31bb2e9eda85 | 239 | spi.write(0x1B); |
ee12b079 | 317:31bb2e9eda85 | 240 | spi.write(0x25); |
ee12b079 | 317:31bb2e9eda85 | 241 | spi.write(0x02); |
ee12b079 | 317:31bb2e9eda85 | 242 | gCS_ADF=1; |
ee12b079 | 317:31bb2e9eda85 | 243 | gCS_ADF=0; |
ee12b079 | 317:31bb2e9eda85 | 244 | spi.write(0x1B); |
ee12b079 | 317:31bb2e9eda85 | 245 | spi.write(0x59); |
ee12b079 | 317:31bb2e9eda85 | 246 | spi.write(0x08); |
ee12b079 | 317:31bb2e9eda85 | 247 | gCS_ADF=1; |
ee12b079 | 317:31bb2e9eda85 | 248 | uint16_t sum_temp = 0; |
ee12b079 | 317:31bb2e9eda85 | 249 | for(int i =0; i< 10;i++) |
ee12b079 | 317:31bb2e9eda85 | 250 | { |
ee12b079 | 317:31bb2e9eda85 | 251 | gCS_ADF=0; |
ee12b079 | 317:31bb2e9eda85 | 252 | spi.write(0x3B); |
ee12b079 | 317:31bb2e9eda85 | 253 | spi.write(0x27); |
ee12b079 | 317:31bb2e9eda85 | 254 | spi.write(0xFF); |
ee12b079 | 317:31bb2e9eda85 | 255 | secondbyte = spi.write(0xFF); |
ee12b079 | 317:31bb2e9eda85 | 256 | gCS_ADF=1; |
ee12b079 | 317:31bb2e9eda85 | 257 | gCS_ADF=0; |
ee12b079 | 317:31bb2e9eda85 | 258 | spi.write(0x3B); |
ee12b079 | 317:31bb2e9eda85 | 259 | spi.write(0x28); |
ee12b079 | 317:31bb2e9eda85 | 260 | spi.write(0xFF); |
ee12b079 | 317:31bb2e9eda85 | 261 | firstbyte = spi.write(0xFF); |
ee12b079 | 317:31bb2e9eda85 | 262 | gCS_ADF=1; |
ee12b079 | 317:31bb2e9eda85 | 263 | gCS_ADF=0; |
ee12b079 | 317:31bb2e9eda85 | 264 | spi.write(0x3B); |
ee12b079 | 317:31bb2e9eda85 | 265 | spi.write(0x27); |
ee12b079 | 317:31bb2e9eda85 | 266 | spi.write(0xFF); |
ee12b079 | 317:31bb2e9eda85 | 267 | secondbyte = spi.write(0xFF); |
ee12b079 | 317:31bb2e9eda85 | 268 | gCS_ADF=1; |
ee12b079 | 318:978d72f191f9 | 269 | COM_ADF_TMP = firstbyte<<6; |
ee12b079 | 318:978d72f191f9 | 270 | COM_ADF_TMP += secondbyte; |
ee12b079 | 318:978d72f191f9 | 271 | COM_ADF_TMP = (COM_ADF_TMP/1.83) - 118.43 + temp_correction_value; |
ee12b079 | 318:978d72f191f9 | 272 | sum_temp+=COM_ADF_TMP; |
ee12b079 | 317:31bb2e9eda85 | 273 | } |
ee12b079 | 318:978d72f191f9 | 274 | COM_ADF_TMP = sum_temp/10; |
ee12b079 | 318:978d72f191f9 | 275 | uint8_t txcurr = (3.3*COM_TX_OC_FAULT)/(0.05)*100; |
ee12b079 | 317:31bb2e9eda85 | 276 | } |
ee12b079 | 268:ded5306a1fd1 | 277 | |
ee12b079 | 268:ded5306a1fd1 | 278 | bool hardware_reset(int bcn_call) |
ee12b079 | 268:ded5306a1fd1 | 279 | { |
ee12b079 | 317:31bb2e9eda85 | 280 | if(hw_reset_err_cnt>HW_RESET_THRS){ |
ee12b079 | 317:31bb2e9eda85 | 281 | power_reset_flag=true; |
ee12b079 | 317:31bb2e9eda85 | 282 | power_reset; |
ee12b079 | 317:31bb2e9eda85 | 283 | return 0; |
ee12b079 | 317:31bb2e9eda85 | 284 | } |
ee12b079 | 317:31bb2e9eda85 | 285 | |
ee12b079 | 268:ded5306a1fd1 | 286 | for(int i= 0; i < 2 ; i++) { |
shreeshas95 | 1:a0055b3280c8 | 287 | gCS_ADF=0; |
shreeshas95 | 1:a0055b3280c8 | 288 | spi.write(CMD_HW_RESET); |
shreeshas95 | 1:a0055b3280c8 | 289 | gCS_ADF=1; |
shreeshas95 | 1:a0055b3280c8 | 290 | wait_ms(2);// Typically 1 ms |
shreeshas95 | 1:a0055b3280c8 | 291 | int count=0; |
ee12b079 | 268:ded5306a1fd1 | 292 | temp_return = 0; |
ee12b079 | 268:ded5306a1fd1 | 293 | while(count<10 && miso_err_cnt<10) { |
ee12b079 | 268:ded5306a1fd1 | 294 | if(MISO_PIN) { |
ee12b079 | 268:ded5306a1fd1 | 295 | // assrt_phy_off; |
ee12b079 | 268:ded5306a1fd1 | 296 | /*asseert_phyoff Starts**/ |
ee12b079 | 268:ded5306a1fd1 | 297 | {\ |
ee12b079 | 268:ded5306a1fd1 | 298 | int state_err_cnt = 0;\ |
ee12b079 | 268:ded5306a1fd1 | 299 | CMD(CMD_PHY_OFF);\ |
ee12b079 | 268:ded5306a1fd1 | 300 | if(cmd_err_flag){\ |
ee12b079 | 268:ded5306a1fd1 | 301 | temp_return=1;\ |
ee12b079 | 268:ded5306a1fd1 | 302 | }\ |
ee12b079 | 268:ded5306a1fd1 | 303 | else{\ |
ee12b079 | 268:ded5306a1fd1 | 304 | for(int i = 0 ; i < 40 ;i++){\ |
ee12b079 | 268:ded5306a1fd1 | 305 | CMD(CMD_PHY_OFF);\ |
ee12b079 | 268:ded5306a1fd1 | 306 | check_status;\ |
ee12b079 | 268:ded5306a1fd1 | 307 | if(status == PHY_OFF){\ |
ee12b079 | 268:ded5306a1fd1 | 308 | temp_return = 0;\ |
ee12b079 | 268:ded5306a1fd1 | 309 | break;\ |
ee12b079 | 268:ded5306a1fd1 | 310 | }\ |
ee12b079 | 268:ded5306a1fd1 | 311 | else if(state_err_cnt>THRS){\ |
ee12b079 | 268:ded5306a1fd1 | 312 | temp_return = 1;\ |
ee12b079 | 268:ded5306a1fd1 | 313 | break;\ |
ee12b079 | 268:ded5306a1fd1 | 314 | }\ |
ee12b079 | 268:ded5306a1fd1 | 315 | else {\ |
ee12b079 | 268:ded5306a1fd1 | 316 | wait_ms(1);\ |
ee12b079 | 268:ded5306a1fd1 | 317 | }\ |
ee12b079 | 268:ded5306a1fd1 | 318 | }\ |
ee12b079 | 268:ded5306a1fd1 | 319 | }\ |
ee12b079 | 268:ded5306a1fd1 | 320 | }\ |
ee12b079 | 268:ded5306a1fd1 | 321 | /*Assert_phy_off_ends*/ |
ee12b079 | 268:ded5306a1fd1 | 322 | |
ee12b079 | 268:ded5306a1fd1 | 323 | |
ee12b079 | 268:ded5306a1fd1 | 324 | |
ee12b079 | 268:ded5306a1fd1 | 325 | |
ee12b079 | 268:ded5306a1fd1 | 326 | |
shreeshas95 | 1:a0055b3280c8 | 327 | if(!temp_return){ |
shreeshas95 | 1:a0055b3280c8 | 328 | return 0; |
shreeshas95 | 1:a0055b3280c8 | 329 | } |
shreeshas95 | 1:a0055b3280c8 | 330 | count++; |
ee12b079 | 268:ded5306a1fd1 | 331 | } else { |
shreeshas95 | 1:a0055b3280c8 | 332 | wait_us(50); |
shreeshas95 | 1:a0055b3280c8 | 333 | miso_err_cnt++; |
shreeshas95 | 1:a0055b3280c8 | 334 | } |
shreeshas95 | 1:a0055b3280c8 | 335 | } |
shreeshas95 | 1:a0055b3280c8 | 336 | } |
shreeshas95 | 1:a0055b3280c8 | 337 | return 1; |
shreeshas95 | 1:a0055b3280c8 | 338 | } |
ee12b079 | 268:ded5306a1fd1 | 339 | //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 | 340 | //---------------------------------------------------------------------------- |
ee12b079 | 268:ded5306a1fd1 | 341 | unsigned char temp; |
ee12b079 | 268:ded5306a1fd1 | 342 | bool reg_err; |
ee12b079 | 268:ded5306a1fd1 | 343 | int reg_err_cnt; |
ee12b079 | 268:ded5306a1fd1 | 344 | #define REG_ERR_THRS 5 |
ee12b079 | 268:ded5306a1fd1 | 345 | #define reg_check(addr1,addr2,reg_val){\ |
ee12b079 | 268:ded5306a1fd1 | 346 | gCS_ADF=0;\ |
ee12b079 | 268:ded5306a1fd1 | 347 | reg_err=false;\ |
ee12b079 | 268:ded5306a1fd1 | 348 | spi.write(addr1);\ |
ee12b079 | 268:ded5306a1fd1 | 349 | spi.write(addr2);\ |
ee12b079 | 268:ded5306a1fd1 | 350 | spi.write(0xFF);\ |
ee12b079 | 268:ded5306a1fd1 | 351 | temp = spi.write(0xFF);\ |
ee12b079 | 268:ded5306a1fd1 | 352 | if(temp==reg_val)\ |
ee12b079 | 268:ded5306a1fd1 | 353 | reg_err = false;\ |
ee12b079 | 268:ded5306a1fd1 | 354 | else\ |
ee12b079 | 268:ded5306a1fd1 | 355 | reg_err=true;\ |
ee12b079 | 268:ded5306a1fd1 | 356 | gCS_ADF=1;\ |
ee12b079 | 268:ded5306a1fd1 | 357 | } |
ee12b079 | 268:ded5306a1fd1 | 358 | |
ee12b079 | 268:ded5306a1fd1 | 359 | #define initiate {\ |
shreeshas95 | 1:a0055b3280c8 | 360 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 361 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 362 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 363 | gCS_ADF=1;\ |
ee12b079 | 268:ded5306a1fd1 | 364 | reg_err=true;\ |
ee12b079 | 268:ded5306a1fd1 | 365 | for(reg_err_cnt=0;reg_err_cnt<REG_ERR_THRS && reg_err;reg_err_cnt++){\ |
ee12b079 | 268:ded5306a1fd1 | 366 | gCS_ADF=0;\ |
ee12b079 | 268:ded5306a1fd1 | 367 | spi.write(0x08);\ |
ee12b079 | 268:ded5306a1fd1 | 368 | spi.write(0x14);\ |
ee12b079 | 268:ded5306a1fd1 | 369 | spi.write(TRANSMIT_LEN_1);\ |
ee12b079 | 268:ded5306a1fd1 | 370 | gCS_ADF=1;\ |
ee12b079 | 268:ded5306a1fd1 | 371 | reg_check(0x28,0x14,TRANSMIT_LEN_1);\ |
ee12b079 | 268:ded5306a1fd1 | 372 | }\ |
ee12b079 | 268:ded5306a1fd1 | 373 | if(reg_err)\ |
ee12b079 | 268:ded5306a1fd1 | 374 | gPC.printf("Reg_err_ignored %x \r\n",(int)temp);\ |
ee12b079 | 268:ded5306a1fd1 | 375 | else\ |
ee12b079 | 268:ded5306a1fd1 | 376 | gPC.printf("reg written successful %x \r\n",(int)temp);\ |
ee12b079 | 268:ded5306a1fd1 | 377 | reg_err=true;\ |
ee12b079 | 268:ded5306a1fd1 | 378 | for(reg_err_cnt=0;reg_err_cnt<REG_ERR_THRS && reg_err;reg_err_cnt++){\ |
ee12b079 | 268:ded5306a1fd1 | 379 | gCS_ADF=0;\ |
ee12b079 | 268:ded5306a1fd1 | 380 | spi.write(0x08);\ |
ee12b079 | 268:ded5306a1fd1 | 381 | spi.write(0x15);\ |
ee12b079 | 268:ded5306a1fd1 | 382 | spi.write(TRANSMIT_LEN_2);\ |
ee12b079 | 268:ded5306a1fd1 | 383 | gCS_ADF=1;\ |
ee12b079 | 268:ded5306a1fd1 | 384 | reg_check(0x28,0x15,TRANSMIT_LEN_2);\ |
ee12b079 | 268:ded5306a1fd1 | 385 | }\ |
ee12b079 | 268:ded5306a1fd1 | 386 | if(reg_err)\ |
ee12b079 | 268:ded5306a1fd1 | 387 | gPC.printf("Reg_err_ignored %x \r\n",(int)temp);\ |
ee12b079 | 268:ded5306a1fd1 | 388 | else\ |
ee12b079 | 268:ded5306a1fd1 | 389 | gPC.printf("reg written successful %x \r\n",(int)temp);\ |
ee12b079 | 268:ded5306a1fd1 | 390 | } |
ee12b079 | 268:ded5306a1fd1 | 391 | |
ee12b079 | 268:ded5306a1fd1 | 392 | #define write_data {\ |
ee12b079 | 268:ded5306a1fd1 | 393 | counter++;\ |
ee12b079 | 271:72529b247333 | 394 | if(counter==584){\ |
ee12b079 | 271:72529b247333 | 395 | finish_write_data=true;\ |
ee12b079 | 271:72529b247333 | 396 | restart_adf_flag=true;\ |
ee12b079 | 271:72529b247333 | 397 | counter=0;\ |
ee12b079 | 271:72529b247333 | 398 | }\ |
shreeshas95 | 1:a0055b3280c8 | 399 | gCS_ADF=0;\ |
ee12b079 | 268:ded5306a1fd1 | 400 | spi.write(0x0B);\ |
ee12b079 | 268:ded5306a1fd1 | 401 | spi.write(0x36);\ |
ee12b079 | 268:ded5306a1fd1 | 402 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 403 | gCS_ADF=1;\ |
ee12b079 | 268:ded5306a1fd1 | 404 | data_err_cnt=0;\ |
ee12b079 | 268:ded5306a1fd1 | 405 | data_err=true;\ |
ee12b079 | 268:ded5306a1fd1 | 406 | while(data_err && (data_err_cnt<DATA_ERR_THRS)){\ |
ee12b079 | 268:ded5306a1fd1 | 407 | gCS_ADF=0;\ |
ee12b079 | 268:ded5306a1fd1 | 408 | if(buffer_state){\ |
ee12b079 | 268:ded5306a1fd1 | 409 | spi.write(0x18);\ |
ee12b079 | 268:ded5306a1fd1 | 410 | spi.write(0x20);\ |
ee12b079 | 268:ded5306a1fd1 | 411 | for(unsigned char i=0; i<112;i++){\ |
ee12b079 | 268:ded5306a1fd1 | 412 | spi.write(buffer_112[i]);\ |
ee12b079 | 268:ded5306a1fd1 | 413 | /*gPC.printf("0x%X,",spi.write(buffer_112[i]));*/\ |
ee12b079 | 268:ded5306a1fd1 | 414 | }\ |
ee12b079 | 268:ded5306a1fd1 | 415 | }\ |
ee12b079 | 268:ded5306a1fd1 | 416 | else{\ |
ee12b079 | 268:ded5306a1fd1 | 417 | spi.write(0x18);\ |
ee12b079 | 268:ded5306a1fd1 | 418 | spi.write(0x90);\ |
ee12b079 | 268:ded5306a1fd1 | 419 | for(unsigned char i=0; i<112;i++){\ |
ee12b079 | 268:ded5306a1fd1 | 420 | spi.write(buffer_112[i]);\ |
ee12b079 | 268:ded5306a1fd1 | 421 | /*gPC.printf("0x%X,",spi.write(buffer_112[i]));*/\ |
ee12b079 | 268:ded5306a1fd1 | 422 | }\ |
ee12b079 | 268:ded5306a1fd1 | 423 | }\ |
ee12b079 | 268:ded5306a1fd1 | 424 | gCS_ADF=1;\ |
ee12b079 | 268:ded5306a1fd1 | 425 | wait_us(5);\ |
ee12b079 | 268:ded5306a1fd1 | 426 | data_err=false;\ |
ee12b079 | 268:ded5306a1fd1 | 427 | gCS_ADF=0;\ |
ee12b079 | 268:ded5306a1fd1 | 428 | spi.write(0x38);\ |
ee12b079 | 268:ded5306a1fd1 | 429 | if(buffer_state){\ |
ee12b079 | 268:ded5306a1fd1 | 430 | spi.write(0x20);\ |
ee12b079 | 268:ded5306a1fd1 | 431 | }\ |
ee12b079 | 268:ded5306a1fd1 | 432 | else{\ |
ee12b079 | 268:ded5306a1fd1 | 433 | spi.write(0x90);\ |
ee12b079 | 268:ded5306a1fd1 | 434 | }\ |
ee12b079 | 268:ded5306a1fd1 | 435 | spi.write(0xFF);\ |
ee12b079 | 268:ded5306a1fd1 | 436 | for(unsigned char i=0; i<112;i++){\ |
ee12b079 | 268:ded5306a1fd1 | 437 | temp_byte=spi.write(0xFF);\ |
ee12b079 | 268:ded5306a1fd1 | 438 | if(buffer_112[i]!=temp_byte){\ |
ee12b079 | 268:ded5306a1fd1 | 439 | data_err1[i]=1;\ |
ee12b079 | 268:ded5306a1fd1 | 440 | data_err=true;\ |
ee12b079 | 268:ded5306a1fd1 | 441 | }\ |
ee12b079 | 268:ded5306a1fd1 | 442 | }\ |
shreeshas95 | 1:a0055b3280c8 | 443 | gCS_ADF=1;\ |
ee12b079 | 268:ded5306a1fd1 | 444 | /*SPI_mutex.unlock();*/\ |
ee12b079 | 268:ded5306a1fd1 | 445 | if(data_err==false){\ |
ee12b079 | 268:ded5306a1fd1 | 446 | buffer_state = !buffer_state;\ |
ee12b079 | 268:ded5306a1fd1 | 447 | }\ |
ee12b079 | 268:ded5306a1fd1 | 448 | data_err_cnt++;\ |
ee12b079 | 268:ded5306a1fd1 | 449 | if(last_buffer){\ |
ee12b079 | 268:ded5306a1fd1 | 450 | finish_write_data = true;\ |
ee12b079 | 268:ded5306a1fd1 | 451 | /*gPC.puts("adf_off\r\n");*/\ |
ee12b079 | 268:ded5306a1fd1 | 452 | }\ |
ee12b079 | 268:ded5306a1fd1 | 453 | }\ |
ee12b079 | 268:ded5306a1fd1 | 454 | } |
ee12b079 | 268:ded5306a1fd1 | 455 | |
ee12b079 | 268:ded5306a1fd1 | 456 | #define check {\ |
ee12b079 | 268:ded5306a1fd1 | 457 | check_status;\ |
ee12b079 | 268:ded5306a1fd1 | 458 | /*gPC.printf("I 0x%X\r\n",(int)status);*/\ |
ee12b079 | 271:72529b247333 | 459 | if(IRQ){\ |
ee12b079 | 268:ded5306a1fd1 | 460 | /*gPC.printf("det\r\n");*/\ |
ee12b079 | 268:ded5306a1fd1 | 461 | if(!ADF_off) {\ |
ee12b079 | 271:72529b247333 | 462 | if(finish_write_data || restart_adf_flag) {\ |
ee12b079 | 268:ded5306a1fd1 | 463 | write_data;\ |
ee12b079 | 268:ded5306a1fd1 | 464 | ADF_off=true;\ |
ee12b079 | 317:31bb2e9eda85 | 465 | T.stop();\ |
ee12b079 | 317:31bb2e9eda85 | 466 | T.reset();\ |
ee12b079 | 317:31bb2e9eda85 | 467 | T.start();\ |
ee12b079 | 317:31bb2e9eda85 | 468 | /*ADF Temperature reading*/;\ |
ee12b079 | 318:978d72f191f9 | 469 | get_temp_and_txcurr();\ |
ee12b079 | 268:ded5306a1fd1 | 470 | } else {\ |
ee12b079 | 317:31bb2e9eda85 | 471 | T.stop();\ |
ee12b079 | 317:31bb2e9eda85 | 472 | T.reset();\ |
ee12b079 | 317:31bb2e9eda85 | 473 | T.start();\ |
ee12b079 | 268:ded5306a1fd1 | 474 | write_data;\ |
ee12b079 | 268:ded5306a1fd1 | 475 | if(sent_tmfrom_SDcard)\ |
ee12b079 | 268:ded5306a1fd1 | 476 | send_tm_from_SD_card_fun();\ |
ee12b079 | 268:ded5306a1fd1 | 477 | else snd_tm.transmit_data(buffer_112,&last_buffer);\ |
ee12b079 | 268:ded5306a1fd1 | 478 | }\ |
ee12b079 | 268:ded5306a1fd1 | 479 | } else {\ |
ee12b079 | 268:ded5306a1fd1 | 480 | wait_ms(20);\ |
ee12b079 | 268:ded5306a1fd1 | 481 | gCS_ADF=0;\ |
ee12b079 | 268:ded5306a1fd1 | 482 | spi.write(0xB1);\ |
ee12b079 | 268:ded5306a1fd1 | 483 | gCS_ADF=1;\ |
ee12b079 | 268:ded5306a1fd1 | 484 | gPC.puts("transmission done\r\n");\ |
ee12b079 | 317:31bb2e9eda85 | 485 | gPC.printf("Time taken by last write_data %f msecs\n", T.read_ms());\ |
ee12b079 | 317:31bb2e9eda85 | 486 | T.stop();\ |
ee12b079 | 317:31bb2e9eda85 | 487 | T.reset();\ |
ee12b079 | 268:ded5306a1fd1 | 488 | loop_on=false;\ |
ee12b079 | 271:72529b247333 | 489 | if(restart_adf_flag)\ |
ee12b079 | 271:72529b247333 | 490 | {\ |
ee12b079 | 271:72529b247333 | 491 | restart_adf_flag=false;\ |
ee12b079 | 271:72529b247333 | 492 | ADF_off=false;\ |
ee12b079 | 271:72529b247333 | 493 | send_data;\ |
ee12b079 | 271:72529b247333 | 494 | loop_on=true;\ |
ee12b079 | 271:72529b247333 | 495 | CMD(CMD_PHY_TX);\ |
ee12b079 | 271:72529b247333 | 496 | wait_us(2000);\ |
ee12b079 | 271:72529b247333 | 497 | }\ |
ee12b079 | 268:ded5306a1fd1 | 498 | }\ |
ee12b079 | 268:ded5306a1fd1 | 499 | }\ |
ee12b079 | 317:31bb2e9eda85 | 500 | else{\ |
ee12b079 | 317:31bb2e9eda85 | 501 | if(T.read_us()>98000){\ |
ee12b079 | 317:31bb2e9eda85 | 502 | data_irq_err=true;\ |
ee12b079 | 317:31bb2e9eda85 | 503 | CMD(CMD_PHY_ON);\ |
ee12b079 | 317:31bb2e9eda85 | 504 | gPC.printf("Data_error_detected");\ |
ee12b079 | 317:31bb2e9eda85 | 505 | T.stop();\ |
ee12b079 | 317:31bb2e9eda85 | 506 | T.reset();\ |
ee12b079 | 317:31bb2e9eda85 | 507 | }\ |
ee12b079 | 317:31bb2e9eda85 | 508 | }\ |
ee12b079 | 268:ded5306a1fd1 | 509 | } |
ee12b079 | 268:ded5306a1fd1 | 510 | |
ee12b079 | 268:ded5306a1fd1 | 511 | #define send_data {\ |
ee12b079 | 9:e9eaada136c6 | 512 | gCS_ADF=0;\ |
ee12b079 | 9:e9eaada136c6 | 513 | spi.write(0xBB);\ |
ee12b079 | 9:e9eaada136c6 | 514 | gCS_ADF=1;\ |
ee12b079 | 9:e9eaada136c6 | 515 | gCS_ADF=0;\ |
ee12b079 | 9:e9eaada136c6 | 516 | spi.write(0xFF);\ |
ee12b079 | 9:e9eaada136c6 | 517 | spi.write(0xFF);\ |
ee12b079 | 9:e9eaada136c6 | 518 | gCS_ADF=1;\ |
ee12b079 | 268:ded5306a1fd1 | 519 | if(sent_tmfrom_SDcard){\ |
ee12b079 | 95:42d6747900cb | 520 | send_tm_from_SD_card_fun();\ |
shreeshas95 | 1:a0055b3280c8 | 521 | }else{\ |
shreeshas95 | 1:a0055b3280c8 | 522 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
shreeshas95 | 1:a0055b3280c8 | 523 | }\ |
shreeshas95 | 1:a0055b3280c8 | 524 | write_data;\ |
shreeshas95 | 1:a0055b3280c8 | 525 | if(sent_tmfrom_SDcard){\ |
krishanprajapat | 148:46763854fa83 | 526 | send_tm_from_SD_card_fun();\ |
krishanprajapat | 148:46763854fa83 | 527 | }else{\ |
krishanprajapat | 148:46763854fa83 | 528 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
krishanprajapat | 148:46763854fa83 | 529 | }\ |
krishanprajapat | 148:46763854fa83 | 530 | write_data;\ |
krishanprajapat | 148:46763854fa83 | 531 | if(sent_tmfrom_SDcard){\ |
ee12b079 | 95:42d6747900cb | 532 | send_tm_from_SD_card_fun();\ |
shreeshas95 | 1:a0055b3280c8 | 533 | }else{\ |
shreeshas95 | 1:a0055b3280c8 | 534 | snd_tm.transmit_data(buffer_112,&last_buffer);\ |
shreeshas95 | 1:a0055b3280c8 | 535 | }\ |
shreeshas95 | 1:a0055b3280c8 | 536 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 537 | spi.write(0xB1);\ |
shreeshas95 | 1:a0055b3280c8 | 538 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 539 | wait_us(300);\ |
shreeshas95 | 1:a0055b3280c8 | 540 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 541 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 542 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 543 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 544 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 545 | spi.write(0xB5);\ |
shreeshas95 | 1:a0055b3280c8 | 546 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 547 | wait_us(300);\ |
shreeshas95 | 1:a0055b3280c8 | 548 | gCS_ADF=0;\ |
shreeshas95 | 1:a0055b3280c8 | 549 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 550 | spi.write(0xFF);\ |
shreeshas95 | 1:a0055b3280c8 | 551 | gCS_ADF=1;\ |
shreeshas95 | 1:a0055b3280c8 | 552 | } |
ee12b079 | 268:ded5306a1fd1 | 553 | |
ee12b079 | 268:ded5306a1fd1 | 554 | #define initial_adf_check {\ |
ee12b079 | 268:ded5306a1fd1 | 555 | bool Configuration_Done=false;\ |
ee12b079 | 268:ded5306a1fd1 | 556 | quit_configuration=false;\ |
ee12b079 | 268:ded5306a1fd1 | 557 | bool reset_flag1 = 0;\ |
ee12b079 | 268:ded5306a1fd1 | 558 | bool flag = false;\ |
ee12b079 | 268:ded5306a1fd1 | 559 | while((hw_reset_err_cnt<HW_THRS)&&(quit_configuration==false)){\ |
ee12b079 | 268:ded5306a1fd1 | 560 | while((bbram_err_cnt<2)&&(quit_configuration==false)){\ |
ee12b079 | 268:ded5306a1fd1 | 561 | /*assrt_phy_off;*/\ |
ee12b079 | 268:ded5306a1fd1 | 562 | /*Assrt_phy_off Begin*/\ |
ee12b079 | 268:ded5306a1fd1 | 563 | {\ |
ee12b079 | 268:ded5306a1fd1 | 564 | int state_err_cnt = 0;\ |
ee12b079 | 268:ded5306a1fd1 | 565 | CMD(CMD_PHY_OFF);\ |
ee12b079 | 268:ded5306a1fd1 | 566 | if(cmd_err_flag){\ |
ee12b079 | 268:ded5306a1fd1 | 567 | temp_return=1;\ |
ee12b079 | 268:ded5306a1fd1 | 568 | }\ |
ee12b079 | 268:ded5306a1fd1 | 569 | else{\ |
ee12b079 | 268:ded5306a1fd1 | 570 | for(int i = 0 ; i < 40 ;i++){\ |
ee12b079 | 268:ded5306a1fd1 | 571 | CMD(CMD_PHY_OFF);\ |
ee12b079 | 268:ded5306a1fd1 | 572 | check_status;\ |
ee12b079 | 268:ded5306a1fd1 | 573 | if(status == PHY_OFF){\ |
ee12b079 | 268:ded5306a1fd1 | 574 | temp_return = 0;\ |
ee12b079 | 268:ded5306a1fd1 | 575 | break;\ |
ee12b079 | 268:ded5306a1fd1 | 576 | }\ |
ee12b079 | 268:ded5306a1fd1 | 577 | else if(state_err_cnt>THRS){\ |
ee12b079 | 268:ded5306a1fd1 | 578 | temp_return = 1;\ |
ee12b079 | 268:ded5306a1fd1 | 579 | break;\ |
ee12b079 | 268:ded5306a1fd1 | 580 | }\ |
ee12b079 | 268:ded5306a1fd1 | 581 | else {\ |
ee12b079 | 268:ded5306a1fd1 | 582 | wait_ms(1);\ |
ee12b079 | 268:ded5306a1fd1 | 583 | }\ |
ee12b079 | 268:ded5306a1fd1 | 584 | }\ |
ee12b079 | 268:ded5306a1fd1 | 585 | }\ |
ee12b079 | 268:ded5306a1fd1 | 586 | }\ |
ee12b079 | 268:ded5306a1fd1 | 587 | /*Assrt_phy_off end*/\ |
ee12b079 | 268:ded5306a1fd1 | 588 | reset_flag1=temp_return;\ |
ee12b079 | 268:ded5306a1fd1 | 589 | if(!reset_flag1){\ |
ee12b079 | 268:ded5306a1fd1 | 590 | bbram_write;\ |
ee12b079 | 268:ded5306a1fd1 | 591 | while((rbp_err_cnt<RBP_THRS)&&(quit_configuration==false)){\ |
ee12b079 | 268:ded5306a1fd1 | 592 | bbram_check;\ |
ee12b079 | 268:ded5306a1fd1 | 593 | if(bbram_err==0){\ |
ee12b079 | 268:ded5306a1fd1 | 594 | bbram_write_success=true;\ |
ee12b079 | 268:ded5306a1fd1 | 595 | bbram_err_cnt=0;\ |
ee12b079 | 268:ded5306a1fd1 | 596 | initiate;\ |
ee12b079 | 268:ded5306a1fd1 | 597 | if(reg_err){\ |
ee12b079 | 268:ded5306a1fd1 | 598 | rbp_err_cnt++;\ |
ee12b079 | 268:ded5306a1fd1 | 599 | }\ |
ee12b079 | 268:ded5306a1fd1 | 600 | else{\ |
ee12b079 | 268:ded5306a1fd1 | 601 | rbp_err_cnt=0;\ |
ee12b079 | 268:ded5306a1fd1 | 602 | gPC.printf("NO Reg err\r\n");\ |
ee12b079 | 268:ded5306a1fd1 | 603 | CMD(CMD_CONFIG_DEV);\ |
ee12b079 | 268:ded5306a1fd1 | 604 | if(cmd_err_flag){\ |
ee12b079 | 268:ded5306a1fd1 | 605 | reset_flag=1;\ |
ee12b079 | 268:ded5306a1fd1 | 606 | gPC.printf("CMD ERR\r\n");\ |
ee12b079 | 268:ded5306a1fd1 | 607 | }\ |
ee12b079 | 268:ded5306a1fd1 | 608 | else{\ |
ee12b079 | 268:ded5306a1fd1 | 609 | reset_flag=0;\ |
ee12b079 | 268:ded5306a1fd1 | 610 | gPC.printf("NO CMD ERR CONFIG_DONE\r\n");\ |
ee12b079 | 268:ded5306a1fd1 | 611 | quit_configuration=true;\ |
ee12b079 | 268:ded5306a1fd1 | 612 | }\ |
ee12b079 | 268:ded5306a1fd1 | 613 | }\ |
ee12b079 | 268:ded5306a1fd1 | 614 | }\ |
ee12b079 | 268:ded5306a1fd1 | 615 | else{\ |
ee12b079 | 268:ded5306a1fd1 | 616 | bbram_write_success=false;\ |
ee12b079 | 268:ded5306a1fd1 | 617 | bbram_err_cnt++;\ |
ee12b079 | 268:ded5306a1fd1 | 618 | break;\ |
ee12b079 | 268:ded5306a1fd1 | 619 | }\ |
ee12b079 | 268:ded5306a1fd1 | 620 | }\ |
ee12b079 | 268:ded5306a1fd1 | 621 | }\ |
ee12b079 | 268:ded5306a1fd1 | 622 | else{\ |
ee12b079 | 268:ded5306a1fd1 | 623 | break;\ |
ee12b079 | 268:ded5306a1fd1 | 624 | }\ |
ee12b079 | 268:ded5306a1fd1 | 625 | }\ |
ee12b079 | 268:ded5306a1fd1 | 626 | if(reset_flag1){\ |
ee12b079 | 268:ded5306a1fd1 | 627 | hardware_reset(0);\ |
ee12b079 | 268:ded5306a1fd1 | 628 | hw_reset_err_cnt++;\ |
ee12b079 | 268:ded5306a1fd1 | 629 | gPC.puts("Resetting hardware\r\n");\ |
ee12b079 | 268:ded5306a1fd1 | 630 | }\ |
ee12b079 | 268:ded5306a1fd1 | 631 | }\ |
ee12b079 | 268:ded5306a1fd1 | 632 | if(hw_reset_err_cnt==HW_THRS){\ |
ee12b079 | 268:ded5306a1fd1 | 633 | power_reset_flag=1;\ |
ee12b079 | 268:ded5306a1fd1 | 634 | power_reset_count++;\ |
ee12b079 | 268:ded5306a1fd1 | 635 | }\ |
ee12b079 | 268:ded5306a1fd1 | 636 | else{\ |
ee12b079 | 268:ded5306a1fd1 | 637 | Configuration_Done=true;\ |
ee12b079 | 268:ded5306a1fd1 | 638 | gPC.printf("Configuration_Done\n");\ |
ee12b079 | 268:ded5306a1fd1 | 639 | }\ |
ee12b079 | 268:ded5306a1fd1 | 640 | } |
ee12b079 | 268:ded5306a1fd1 | 641 | |
aniruddhv | 52:0bd68655c651 | 642 | #define configure_adf {\ |
ee12b079 | 268:ded5306a1fd1 | 643 | reset_flags;\ |
aniruddhv | 52:0bd68655c651 | 644 | initial_adf_check;\ |
ee12b079 | 268:ded5306a1fd1 | 645 | gPC.puts("Config_part done\r\n");\ |
ee12b079 | 9:e9eaada136c6 | 646 | } |
ee12b079 | 9:e9eaada136c6 | 647 | |
ee12b079 | 95:42d6747900cb | 648 | #define transmit_adf {\ |
ee12b079 | 317:31bb2e9eda85 | 649 | while(power_reset_count<POWER_RESET_THRS){\ |
ee12b079 | 271:72529b247333 | 650 | restart_adf_flag=false;\ |
ee12b079 | 271:72529b247333 | 651 | bool tx_err=false;\ |
aniruddhv | 52:0bd68655c651 | 652 | configure_adf;\ |
aniruddhv | 52:0bd68655c651 | 653 | send_data;\ |
ee12b079 | 286:0f3a2a7ac295 | 654 | /*PA MCR level*/;\ |
ee12b079 | 286:0f3a2a7ac295 | 655 | gCS_ADF=0;\ |
ee12b079 | 286:0f3a2a7ac295 | 656 | spi.write(0x1B);\ |
ee12b079 | 286:0f3a2a7ac295 | 657 | spi.write(0x07);\ |
ee12b079 | 286:0f3a2a7ac295 | 658 | spi.write(0x35);\ |
ee12b079 | 286:0f3a2a7ac295 | 659 | gCS_ADF=1;\ |
ee12b079 | 317:31bb2e9eda85 | 660 | CMD(CMD_PHY_TX);\ |
ee12b079 | 268:ded5306a1fd1 | 661 | wait_us(2000);\ |
ee12b079 | 317:31bb2e9eda85 | 662 | T.start();\ |
aniruddhv | 52:0bd68655c651 | 663 | while(loop_on){\ |
ee12b079 | 268:ded5306a1fd1 | 664 | wait_us(20);\ |
ee12b079 | 268:ded5306a1fd1 | 665 | check;\ |
ee12b079 | 271:72529b247333 | 666 | if(data_irq_err||tx_err){\ |
ee12b079 | 317:31bb2e9eda85 | 667 | hw_reset_err_cnt++;\ |
ee12b079 | 317:31bb2e9eda85 | 668 | hw_reset_flag=true;\ |
ee12b079 | 268:ded5306a1fd1 | 669 | break;\ |
aniruddhv | 52:0bd68655c651 | 670 | }\ |
aniruddhv | 52:0bd68655c651 | 671 | }\ |
ee12b079 | 317:31bb2e9eda85 | 672 | if(hw_reset_flag==true){\ |
ee12b079 | 317:31bb2e9eda85 | 673 | hardware_reset(0);\ |
ee12b079 | 317:31bb2e9eda85 | 674 | }\ |
ee12b079 | 317:31bb2e9eda85 | 675 | else{\ |
ee12b079 | 317:31bb2e9eda85 | 676 | break;\ |
ee12b079 | 317:31bb2e9eda85 | 677 | }\ |
ee12b079 | 317:31bb2e9eda85 | 678 | gPC.puts("after while loop\r\n");\ |
ee12b079 | 317:31bb2e9eda85 | 679 | }\ |
ee12b079 | 317:31bb2e9eda85 | 680 | } |