CDMS_CODE_samp_23SEP_DMA_flag

Dependencies:   FreescaleIAP SimpleDMA mbed-rtos mbed

Fork of CDMS_CODE_samp_23SEP_DMA by iitm sat

Committer:
ee12b079
Date:
Fri Jul 08 12:18:41 2016 +0000
Revision:
242:4a78c173060b
Parent:
241:410c9cdd4f6e
Child:
244:cf5b95f5d499
adf integrated, to be tested

Who changed what in which revision?

UserRevisionLine numberNew 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 237:12061b714e47 10 unsigned char bbram_buffer[66]={0x19,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x33,0x00,0xF4,0xC2,0x10,0xC0,0x00,0x30,0x31,0x07,0x00,0x01,0x00,0x7F,0x00,0x0B,0x37,0x00,0x00,0x40,0x0C,0x00,0x05,0x00,0x00,0x18,0x12,0x34,0x56,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 241:410c9cdd4f6e 11 bool data_irq_err=0;
ee12b079 241:410c9cdd4f6e 12 bool data_err= false;
ee12b079 241:410c9cdd4f6e 13 unsigned char temp_byte=0x00;
ee12b079 241:410c9cdd4f6e 14 unsigned char data_err1[112];
ee12b079 241:410c9cdd4f6e 15 unsigned char data_err_cnt=0;
ee12b079 241:410c9cdd4f6e 16 unsigned int byte_count =0;
ee12b079 241:410c9cdd4f6e 17 #define DATA_ERR_THRS 20
ee12b079 241:410c9cdd4f6e 18 bool rolling_buffer_settings_error=true;
ee12b079 241:410c9cdd4f6e 19 bool bbram_write_success=true;
ee12b079 241:410c9cdd4f6e 20 int bbram_err_cnt=0;
ee12b079 241:410c9cdd4f6e 21 int rbp_err_cnt=0;
ee12b079 241:410c9cdd4f6e 22 bool reset_flag=false;
ee12b079 241:410c9cdd4f6e 23 #define RBP_THRS 4
ee12b079 241:410c9cdd4f6e 24 bool quit_configuration=false;
ee12b079 241:410c9cdd4f6e 25 bool power_reset_flag=false;
ee12b079 241:410c9cdd4f6e 26 unsigned int power_reset_count=0;
ee12b079 241:410c9cdd4f6e 27 bool Configuration_done=false;
ee12b079 241:410c9cdd4f6e 28 #define HW_THRS 2
ee12b079 9:e9eaada136c6 29
shreeshas95 2:2caf2a9a13aa 30 //int initialise_card();
shreeshas95 2:2caf2a9a13aa 31 //int disk_initialize();
shreeshas95 1:a0055b3280c8 32 //------------------------------------------------------------------------
shreeshas95 1:a0055b3280c8 33 // state checking functions
shreeshas95 1:a0055b3280c8 34 //bool assrt_phy_off( int, int, int);
shreeshas95 1:a0055b3280c8 35 //bool assrt_phy_on( int,int,int);
shreeshas95 1:a0055b3280c8 36 //bool assrt_phy_tx(int,int,int);
ee12b079 241:410c9cdd4f6e 37
ee12b079 241:410c9cdd4f6e 38 #define TRANSMIT_LEN_1 0xFF
ee12b079 241:410c9cdd4f6e 39 #define TRANSMIT_LEN_2 0xFF
ee12b079 241:410c9cdd4f6e 40 /***/
ee12b079 241:410c9cdd4f6e 41 Timer T;
ee12b079 9:e9eaada136c6 42
shreeshas95 1:a0055b3280c8 43 #define START_ADDRESS 0x020;
shreeshas95 1:a0055b3280c8 44 #define MISO_PIN PTE3
shreeshas95 1:a0055b3280c8 45 /**************Defining Counter Limits**************/
shreeshas95 1:a0055b3280c8 46 #define THRS 20
shreeshas95 1:a0055b3280c8 47 #define STATE_ERR_THRS 20
shreeshas95 1:a0055b3280c8 48 #define PHY_OFF_EXEC_TIME 300
shreeshas95 1:a0055b3280c8 49 #define PHY_ON_EXEC_TIME 300
shreeshas95 1:a0055b3280c8 50 #define PHY_TX_EXEC_TIME 600
shreeshas95 1:a0055b3280c8 51 /******DEFINING COMMANDS*********/
shreeshas95 1:a0055b3280c8 52 #define CMD_HW_RESET 0xC8
shreeshas95 1:a0055b3280c8 53 #define CMD_PHY_ON 0xB1
shreeshas95 1:a0055b3280c8 54 #define CMD_PHY_OFF 0xB0
shreeshas95 1:a0055b3280c8 55 #define CMD_PHY_TX 0xB5
shreeshas95 1:a0055b3280c8 56 #define CMD_CONFIG_DEV 0xBB
ee12b079 241:410c9cdd4f6e 57 /**STATES**/
ee12b079 241:410c9cdd4f6e 58 //=======================
ee12b079 241:410c9cdd4f6e 59 #define PHY_OFF 0xB1
ee12b079 241:410c9cdd4f6e 60 #define PHY_ON 0xB2
ee12b079 241:410c9cdd4f6e 61 #define PHY_TX 0xB4
ee12b079 241:410c9cdd4f6e 62 #define BUSY 0x00
ee12b079 241:410c9cdd4f6e 63 //===================================================
ee12b079 241:410c9cdd4f6e 64
ee12b079 241:410c9cdd4f6e 65 unsigned int Adf_data_counter=0;
ee12b079 241:410c9cdd4f6e 66 unsigned char status =0;
ee12b079 241:410c9cdd4f6e 67 unsigned int cmd_err_cnt=0;
ee12b079 241:410c9cdd4f6e 68 unsigned int data_length;
ee12b079 241:410c9cdd4f6e 69 unsigned int state_err_cnt=0;
ee12b079 241:410c9cdd4f6e 70 unsigned int miso_err_cnt=0;
ee12b079 241:410c9cdd4f6e 71 unsigned int hw_reset_err_cnt=0;
ee12b079 241:410c9cdd4f6e 72 unsigned int counter =0;
ee12b079 241:410c9cdd4f6e 73 bool temp_return = 0;
ee12b079 241:410c9cdd4f6e 74 bool bcn_flag=0;
ee12b079 241:410c9cdd4f6e 75 bool bbram_flag=0;
ee12b079 241:410c9cdd4f6e 76
ee12b079 241:410c9cdd4f6e 77 bool stop_transmission=false;
ee12b079 241:410c9cdd4f6e 78
ee12b079 241:410c9cdd4f6e 79 #define reset_flags {\
ee12b079 241:410c9cdd4f6e 80 finish_write_data = false;\
ee12b079 241:410c9cdd4f6e 81 buffer_state = true;\
ee12b079 241:410c9cdd4f6e 82 last_buffer = false;\
ee12b079 241:410c9cdd4f6e 83 loop_on = true;\
ee12b079 241:410c9cdd4f6e 84 ADF_off = false;\
ee12b079 241:410c9cdd4f6e 85 buffer_state = true;\
ee12b079 241:410c9cdd4f6e 86 loop_on = true;\
ee12b079 241:410c9cdd4f6e 87 ADF_off = false;\
ee12b079 241:410c9cdd4f6e 88 sent_tmfrom_SDcard = false;\
ee12b079 241:410c9cdd4f6e 89 Adf_data_counter=0;\
ee12b079 241:410c9cdd4f6e 90 status =0;\
ee12b079 241:410c9cdd4f6e 91 cmd_err_cnt=0;\
ee12b079 241:410c9cdd4f6e 92 data_length;\
ee12b079 241:410c9cdd4f6e 93 state_err_cnt=0;\
ee12b079 241:410c9cdd4f6e 94 miso_err_cnt=0;\
ee12b079 241:410c9cdd4f6e 95 hw_reset_err_cnt=0;\
ee12b079 241:410c9cdd4f6e 96 counter =0;\
ee12b079 241:410c9cdd4f6e 97 bcn_flag=0;\
ee12b079 241:410c9cdd4f6e 98 bbram_flag=0;\
ee12b079 241:410c9cdd4f6e 99 stop_transmission=false;\
ee12b079 241:410c9cdd4f6e 100 }
ee12b079 241:410c9cdd4f6e 101
ee12b079 241:410c9cdd4f6e 102
ee12b079 241:410c9cdd4f6e 103 int err_arr[64];
ee12b079 241:410c9cdd4f6e 104 bool bbram_err=false;
ee12b079 241:410c9cdd4f6e 105 int err_idx=-1;
ee12b079 241:410c9cdd4f6e 106 int err[64];
ee12b079 241:410c9cdd4f6e 107 #define bbram_check gCS_ADF=0;\
ee12b079 241:410c9cdd4f6e 108 for(int i=0;i<64;i++){\
ee12b079 241:410c9cdd4f6e 109 err_arr[i]=0;\
ee12b079 241:410c9cdd4f6e 110 }\
ee12b079 241:410c9cdd4f6e 111 for(int i=0;i<64;i++){\
ee12b079 241:410c9cdd4f6e 112 err[i]=0;\
ee12b079 241:410c9cdd4f6e 113 }\
ee12b079 241:410c9cdd4f6e 114 bbram_err=false;\
ee12b079 241:410c9cdd4f6e 115 gCS_ADF=0;\
ee12b079 241:410c9cdd4f6e 116 spi.write(0x39);\
ee12b079 241:410c9cdd4f6e 117 spi.write(0x00);\
ee12b079 241:410c9cdd4f6e 118 spi.write(0xFF);\
ee12b079 241:410c9cdd4f6e 119 for(int i=0;i<64;i++){\
ee12b079 241:410c9cdd4f6e 120 err_arr[i]=spi.write(0xFF);\
ee12b079 241:410c9cdd4f6e 121 if(err_arr[i]!=bbram_buffer[i+2]){\
ee12b079 241:410c9cdd4f6e 122 err[i]=1;\
ee12b079 241:410c9cdd4f6e 123 bbram_err=true;\
ee12b079 241:410c9cdd4f6e 124 }\
ee12b079 241:410c9cdd4f6e 125 }\
ee12b079 241:410c9cdd4f6e 126 gCS_ADF=1;\
ee12b079 241:410c9cdd4f6e 127 if(!bbram_err)\
ee12b079 241:410c9cdd4f6e 128 gPC.printf("BBRAM verified \r\n");\
ee12b079 241:410c9cdd4f6e 129 else\
ee12b079 241:410c9cdd4f6e 130 gPC.printf("BBRAM error \r\n");\
ee12b079 176:a5bfe3ca60b1 131
ee12b079 241:410c9cdd4f6e 132
ee12b079 241:410c9cdd4f6e 133 bool tx_loop=1;
ee12b079 241:410c9cdd4f6e 134
ee12b079 241:410c9cdd4f6e 135 #define PRNT_ONCE {\
ee12b079 241:410c9cdd4f6e 136 gPC.printf("%d %d lol_ what?\r\n",segment_len,EOS_len);\
ee12b079 241:410c9cdd4f6e 137 }
ee12b079 241:410c9cdd4f6e 138
ee12b079 241:410c9cdd4f6e 139 #define bbram_write {\
ee12b079 241:410c9cdd4f6e 140 gCS_ADF=0;\
ee12b079 241:410c9cdd4f6e 141 spi.write(0xB0);\
ee12b079 241:410c9cdd4f6e 142 wait_us(300);\
ee12b079 241:410c9cdd4f6e 143 gCS_ADF=1;\
ee12b079 241:410c9cdd4f6e 144 gCS_ADF=0;\
ee12b079 241:410c9cdd4f6e 145 for(int i=0;i<66;i++){\
ee12b079 241:410c9cdd4f6e 146 spi.write(bbram_buffer[i]);\
ee12b079 241:410c9cdd4f6e 147 }\
ee12b079 241:410c9cdd4f6e 148 gCS_ADF=1;\
ee12b079 241:410c9cdd4f6e 149 }
ee12b079 241:410c9cdd4f6e 150 //------------------------------------------------------------------------
ee12b079 241:410c9cdd4f6e 151 // state checking functions
ee12b079 241:410c9cdd4f6e 152 //bool assrt_phy_off( int, int, int);
ee12b079 241:410c9cdd4f6e 153 //bool assrt_phy_on( int,int,int);
ee12b079 241:410c9cdd4f6e 154 //bool assrt_phy_tx(int,int,int);
ee12b079 241:410c9cdd4f6e 155
shreeshas95 1:a0055b3280c8 156 #define check_status {\
shreeshas95 1:a0055b3280c8 157 unsigned char stat=0;\
shreeshas95 1:a0055b3280c8 158 gCS_ADF=0;\
ee12b079 176:a5bfe3ca60b1 159 spi.write(0xFF);\
ee12b079 176:a5bfe3ca60b1 160 stat = spi.write(0xFF);\
shreeshas95 1:a0055b3280c8 161 gCS_ADF=1;\
ee12b079 176:a5bfe3ca60b1 162 status = stat;\
shreeshas95 1:a0055b3280c8 163 }
ee12b079 241:410c9cdd4f6e 164
ee12b079 241:410c9cdd4f6e 165 /*CMD_VAR*/
ee12b079 241:410c9cdd4f6e 166 bool cmd_bit=true;
ee12b079 241:410c9cdd4f6e 167 bool cmd_err_flag=false;
ee12b079 241:410c9cdd4f6e 168 unsigned char command = 0x00;
ee12b079 241:410c9cdd4f6e 169 #define CMD(command) {\
ee12b079 241:410c9cdd4f6e 170 cmd_err_cnt=0;\
ee12b079 241:410c9cdd4f6e 171 cmd_err_flag=false;\
ee12b079 241:410c9cdd4f6e 172 while(cmd_err_cnt<3) {\
shreeshas95 1:a0055b3280c8 173 check_status;\
ee12b079 241:410c9cdd4f6e 174 cmd_bit=status&0x20;\
ee12b079 241:410c9cdd4f6e 175 if(cmd_bit) {\
ee12b079 241:410c9cdd4f6e 176 gCS_ADF=0;\
ee12b079 241:410c9cdd4f6e 177 spi.write(command);\
ee12b079 241:410c9cdd4f6e 178 gCS_ADF=1;\
shreeshas95 1:a0055b3280c8 179 break;\
ee12b079 241:410c9cdd4f6e 180 } else {\
ee12b079 241:410c9cdd4f6e 181 wait_us(5);\
ee12b079 241:410c9cdd4f6e 182 cmd_err_cnt++;\
shreeshas95 1:a0055b3280c8 183 }\
ee12b079 241:410c9cdd4f6e 184 }\
ee12b079 241:410c9cdd4f6e 185 if(cmd_err_cnt==3) {\
ee12b079 241:410c9cdd4f6e 186 cmd_err_flag=true;\
ee12b079 241:410c9cdd4f6e 187 }\
ee12b079 242:4a78c173060b 188 }
ee12b079 241:410c9cdd4f6e 189 // all three arguments are int\
ee12b079 241:410c9cdd4f6e 190 #define assrt_phy_off {\
ee12b079 241:410c9cdd4f6e 191 int state_err_cnt = 0;\
ee12b079 241:410c9cdd4f6e 192 CMD(CMD_PHY_OFF);\
ee12b079 241:410c9cdd4f6e 193 if(cmd_err_flag){\
ee12b079 241:410c9cdd4f6e 194 temp_return=1;\
shreeshas95 1:a0055b3280c8 195 }\
ee12b079 241:410c9cdd4f6e 196 else{\
ee12b079 241:410c9cdd4f6e 197 for(int i = 0 ; i < 40 ;i++){\
ee12b079 241:410c9cdd4f6e 198 CMD(CMD_PHY_OFF);\
ee12b079 241:410c9cdd4f6e 199 check_status;\
ee12b079 241:410c9cdd4f6e 200 if(status == PHY_OFF){\
ee12b079 241:410c9cdd4f6e 201 temp_return = 0;\
ee12b079 241:410c9cdd4f6e 202 break;\
ee12b079 241:410c9cdd4f6e 203 }\
ee12b079 241:410c9cdd4f6e 204 else if(state_err_cnt>THRS){\
ee12b079 241:410c9cdd4f6e 205 temp_return = 1;\
ee12b079 241:410c9cdd4f6e 206 break;\
ee12b079 241:410c9cdd4f6e 207 }\
ee12b079 241:410c9cdd4f6e 208 else {\
ee12b079 241:410c9cdd4f6e 209 wait_ms(1);\
ee12b079 241:410c9cdd4f6e 210 }\
shreeshas95 1:a0055b3280c8 211 }\
shreeshas95 1:a0055b3280c8 212 }\
shreeshas95 1:a0055b3280c8 213 }
ee12b079 241:410c9cdd4f6e 214
ee12b079 241:410c9cdd4f6e 215
ee12b079 241:410c9cdd4f6e 216 bool hardware_reset(int bcn_call)
ee12b079 241:410c9cdd4f6e 217 {
ee12b079 241:410c9cdd4f6e 218 for(int i= 0; i < 2 ; i++) {
shreeshas95 1:a0055b3280c8 219 gCS_ADF=0;
shreeshas95 1:a0055b3280c8 220 spi.write(CMD_HW_RESET);
shreeshas95 1:a0055b3280c8 221 gCS_ADF=1;
shreeshas95 1:a0055b3280c8 222 wait_ms(2);// Typically 1 ms
shreeshas95 1:a0055b3280c8 223 int count=0;
ee12b079 241:410c9cdd4f6e 224 temp_return = 0;
ee12b079 241:410c9cdd4f6e 225 while(count<10 && miso_err_cnt<10) {
ee12b079 241:410c9cdd4f6e 226 if(MISO_PIN) {
ee12b079 241:410c9cdd4f6e 227 // assrt_phy_off;
ee12b079 241:410c9cdd4f6e 228 /*asseert_phyoff Starts**/
ee12b079 241:410c9cdd4f6e 229 {\
ee12b079 241:410c9cdd4f6e 230 int state_err_cnt = 0;\
ee12b079 241:410c9cdd4f6e 231 CMD(CMD_PHY_OFF);\
ee12b079 241:410c9cdd4f6e 232 if(cmd_err_flag){\
ee12b079 241:410c9cdd4f6e 233 temp_return=1;\
ee12b079 241:410c9cdd4f6e 234 }\
ee12b079 241:410c9cdd4f6e 235 else{\
ee12b079 241:410c9cdd4f6e 236 for(int i = 0 ; i < 40 ;i++){\
ee12b079 241:410c9cdd4f6e 237 CMD(CMD_PHY_OFF);\
ee12b079 241:410c9cdd4f6e 238 check_status;\
ee12b079 241:410c9cdd4f6e 239 if(status == PHY_OFF){\
ee12b079 241:410c9cdd4f6e 240 temp_return = 0;\
ee12b079 241:410c9cdd4f6e 241 break;\
ee12b079 241:410c9cdd4f6e 242 }\
ee12b079 241:410c9cdd4f6e 243 else if(state_err_cnt>THRS){\
ee12b079 241:410c9cdd4f6e 244 temp_return = 1;\
ee12b079 241:410c9cdd4f6e 245 break;\
ee12b079 241:410c9cdd4f6e 246 }\
ee12b079 241:410c9cdd4f6e 247 else {\
ee12b079 241:410c9cdd4f6e 248 wait_ms(1);\
ee12b079 241:410c9cdd4f6e 249 }\
ee12b079 241:410c9cdd4f6e 250 }\
ee12b079 241:410c9cdd4f6e 251 }\
ee12b079 241:410c9cdd4f6e 252 }\
ee12b079 241:410c9cdd4f6e 253 /*Assert_phy_off_ends*/
ee12b079 241:410c9cdd4f6e 254
ee12b079 241:410c9cdd4f6e 255
ee12b079 241:410c9cdd4f6e 256
ee12b079 241:410c9cdd4f6e 257
ee12b079 241:410c9cdd4f6e 258
shreeshas95 1:a0055b3280c8 259 if(!temp_return){
shreeshas95 1:a0055b3280c8 260 return 0;
shreeshas95 1:a0055b3280c8 261 }
shreeshas95 1:a0055b3280c8 262 count++;
ee12b079 241:410c9cdd4f6e 263 } else {
shreeshas95 1:a0055b3280c8 264 wait_us(50);
shreeshas95 1:a0055b3280c8 265 miso_err_cnt++;
shreeshas95 1:a0055b3280c8 266 }
shreeshas95 1:a0055b3280c8 267 }
shreeshas95 1:a0055b3280c8 268 }
shreeshas95 1:a0055b3280c8 269 return 1;
shreeshas95 1:a0055b3280c8 270 }
ee12b079 241:410c9cdd4f6e 271 //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 272 //----------------------------------------------------------------------------
ee12b079 241:410c9cdd4f6e 273 unsigned char temp;
ee12b079 241:410c9cdd4f6e 274 bool reg_err;
ee12b079 241:410c9cdd4f6e 275 int reg_err_cnt;
ee12b079 241:410c9cdd4f6e 276 #define REG_ERR_THRS 5
ee12b079 241:410c9cdd4f6e 277 #define reg_check(addr1,addr2,reg_val){\
ee12b079 241:410c9cdd4f6e 278 gCS_ADF=0;\
ee12b079 241:410c9cdd4f6e 279 reg_err=false;\
ee12b079 241:410c9cdd4f6e 280 spi.write(addr1);\
ee12b079 241:410c9cdd4f6e 281 spi.write(addr2);\
ee12b079 241:410c9cdd4f6e 282 spi.write(0xFF);\
ee12b079 241:410c9cdd4f6e 283 temp = spi.write(0xFF);\
ee12b079 241:410c9cdd4f6e 284 if(temp==reg_val)\
ee12b079 241:410c9cdd4f6e 285 reg_err = false;\
ee12b079 241:410c9cdd4f6e 286 else\
ee12b079 241:410c9cdd4f6e 287 reg_err=true;\
ee12b079 241:410c9cdd4f6e 288 gCS_ADF=1;\
ee12b079 241:410c9cdd4f6e 289 }
ee12b079 241:410c9cdd4f6e 290
ee12b079 241:410c9cdd4f6e 291 #define initiate {\
shreeshas95 1:a0055b3280c8 292 gCS_ADF=0;\
shreeshas95 1:a0055b3280c8 293 spi.write(0xFF);\
shreeshas95 1:a0055b3280c8 294 spi.write(0xFF);\
shreeshas95 1:a0055b3280c8 295 gCS_ADF=1;\
ee12b079 241:410c9cdd4f6e 296 reg_err=true;\
ee12b079 241:410c9cdd4f6e 297 for(reg_err_cnt=0;reg_err_cnt<REG_ERR_THRS && reg_err;reg_err_cnt++){\
ee12b079 241:410c9cdd4f6e 298 gCS_ADF=0;\
ee12b079 241:410c9cdd4f6e 299 spi.write(0x08);\
ee12b079 241:410c9cdd4f6e 300 spi.write(0x14);\
ee12b079 241:410c9cdd4f6e 301 spi.write(TRANSMIT_LEN_1);\
ee12b079 241:410c9cdd4f6e 302 gCS_ADF=1;\
ee12b079 241:410c9cdd4f6e 303 reg_check(0x28,0x14,TRANSMIT_LEN_1);\
ee12b079 241:410c9cdd4f6e 304 }\
ee12b079 241:410c9cdd4f6e 305 if(reg_err)\
ee12b079 241:410c9cdd4f6e 306 gPC.printf("Reg_err_ignored %x \r\n",(int)temp);\
ee12b079 241:410c9cdd4f6e 307 else\
ee12b079 241:410c9cdd4f6e 308 gPC.printf("reg written successful %x \r\n",(int)temp);\
ee12b079 241:410c9cdd4f6e 309 reg_err=true;\
ee12b079 241:410c9cdd4f6e 310 for(reg_err_cnt=0;reg_err_cnt<REG_ERR_THRS && reg_err;reg_err_cnt++){\
ee12b079 241:410c9cdd4f6e 311 gCS_ADF=0;\
ee12b079 241:410c9cdd4f6e 312 spi.write(0x08);\
ee12b079 241:410c9cdd4f6e 313 spi.write(0x15);\
ee12b079 241:410c9cdd4f6e 314 spi.write(TRANSMIT_LEN_2);\
ee12b079 241:410c9cdd4f6e 315 gCS_ADF=1;\
ee12b079 241:410c9cdd4f6e 316 reg_check(0x28,0x15,TRANSMIT_LEN_2);\
ee12b079 241:410c9cdd4f6e 317 }\
ee12b079 241:410c9cdd4f6e 318 if(reg_err)\
ee12b079 241:410c9cdd4f6e 319 gPC.printf("Reg_err_ignored %x \r\n",(int)temp);\
ee12b079 241:410c9cdd4f6e 320 else\
ee12b079 241:410c9cdd4f6e 321 gPC.printf("reg written successful %x \r\n",(int)temp);\
ee12b079 242:4a78c173060b 322 }
ee12b079 242:4a78c173060b 323
ee12b079 241:410c9cdd4f6e 324 #define write_data {\
ee12b079 241:410c9cdd4f6e 325 counter++;\
shreeshas95 1:a0055b3280c8 326 gCS_ADF=0;\
ee12b079 241:410c9cdd4f6e 327 spi.write(0x0B);\
ee12b079 241:410c9cdd4f6e 328 spi.write(0x36);\
ee12b079 241:410c9cdd4f6e 329 spi.write(0xFF);\
shreeshas95 1:a0055b3280c8 330 gCS_ADF=1;\
ee12b079 241:410c9cdd4f6e 331 data_err_cnt=0;\
ee12b079 241:410c9cdd4f6e 332 data_err=true;\
ee12b079 241:410c9cdd4f6e 333 while(data_err && (data_err_cnt<DATA_ERR_THRS)){\
ee12b079 241:410c9cdd4f6e 334 gCS_ADF=0;\
ee12b079 241:410c9cdd4f6e 335 if(buffer_state){\
ee12b079 241:410c9cdd4f6e 336 spi.write(0x18);\
ee12b079 241:410c9cdd4f6e 337 spi.write(0x20);\
ee12b079 241:410c9cdd4f6e 338 for(unsigned char i=0; i<112;i++){\
ee12b079 241:410c9cdd4f6e 339 if(bypass_adf)\
ee12b079 241:410c9cdd4f6e 340 gPC.putc(buffer_112[i]);\
ee12b079 241:410c9cdd4f6e 341 else\
ee12b079 241:410c9cdd4f6e 342 spi.write(buffer_112[i]);\
ee12b079 241:410c9cdd4f6e 343 /*gPC.printf("0x%X,",spi.write(buffer_112[i]));*/\
ee12b079 241:410c9cdd4f6e 344 }\
ee12b079 241:410c9cdd4f6e 345 }\
ee12b079 241:410c9cdd4f6e 346 else{\
ee12b079 241:410c9cdd4f6e 347 spi.write(0x18);\
ee12b079 241:410c9cdd4f6e 348 spi.write(0x90);\
ee12b079 241:410c9cdd4f6e 349 for(unsigned char i=0; i<112;i++){\
ee12b079 241:410c9cdd4f6e 350 if(bypass_adf)\
ee12b079 241:410c9cdd4f6e 351 gPC.putc(buffer_112[i]);\
ee12b079 241:410c9cdd4f6e 352 else\
ee12b079 241:410c9cdd4f6e 353 spi.write(buffer_112[i]);\
ee12b079 241:410c9cdd4f6e 354 /*gPC.printf("0x%X,",spi.write(buffer_112[i]));*/\
ee12b079 241:410c9cdd4f6e 355 }\
ee12b079 241:410c9cdd4f6e 356 }\
ee12b079 241:410c9cdd4f6e 357 gCS_ADF=1;\
ee12b079 241:410c9cdd4f6e 358 wait_us(5);\
ee12b079 241:410c9cdd4f6e 359 data_err=false;\
ee12b079 241:410c9cdd4f6e 360 gCS_ADF=0;\
ee12b079 241:410c9cdd4f6e 361 spi.write(0x38);\
ee12b079 241:410c9cdd4f6e 362 if(buffer_state){\
ee12b079 241:410c9cdd4f6e 363 spi.write(0x20);\
ee12b079 241:410c9cdd4f6e 364 }\
ee12b079 241:410c9cdd4f6e 365 else{\
ee12b079 241:410c9cdd4f6e 366 spi.write(0x90);\
ee12b079 241:410c9cdd4f6e 367 }\
ee12b079 241:410c9cdd4f6e 368 spi.write(0xFF);\
ee12b079 241:410c9cdd4f6e 369 for(unsigned char i=0; i<112;i++){\
ee12b079 241:410c9cdd4f6e 370 temp_byte=spi.write(0xFF);\
ee12b079 241:410c9cdd4f6e 371 if(buffer_112[i]!=temp_byte){\
ee12b079 241:410c9cdd4f6e 372 data_err1[i]=1;\
ee12b079 241:410c9cdd4f6e 373 data_err=true;\
ee12b079 241:410c9cdd4f6e 374 }\
ee12b079 241:410c9cdd4f6e 375 }\
shreeshas95 1:a0055b3280c8 376 gCS_ADF=1;\
ee12b079 241:410c9cdd4f6e 377 /*SPI_mutex.unlock();*/\
ee12b079 241:410c9cdd4f6e 378 if(data_err==false){\
ee12b079 241:410c9cdd4f6e 379 buffer_state = !buffer_state;\
ee12b079 241:410c9cdd4f6e 380 }\
ee12b079 241:410c9cdd4f6e 381 data_err_cnt++;\
ee12b079 241:410c9cdd4f6e 382 if(last_buffer){\
ee12b079 241:410c9cdd4f6e 383 finish_write_data = true;\
ee12b079 241:410c9cdd4f6e 384 /*gPC.puts("adf_off\r\n");*/\
ee12b079 241:410c9cdd4f6e 385 }\
ee12b079 241:410c9cdd4f6e 386 }\
ee12b079 241:410c9cdd4f6e 387 }
ee12b079 241:410c9cdd4f6e 388
ee12b079 241:410c9cdd4f6e 389 #define check {\
ee12b079 242:4a78c173060b 390 check_status;\
ee12b079 242:4a78c173060b 391 gPC.printf("I 0x%X\r\n",(int)status);\
ee12b079 241:410c9cdd4f6e 392 if(IRQ || bypass_adf){\
ee12b079 241:410c9cdd4f6e 393 gPC.printf("det\r\n");\
ee12b079 241:410c9cdd4f6e 394 if(!ADF_off) {\
ee12b079 241:410c9cdd4f6e 395 if(finish_write_data) {\
ee12b079 241:410c9cdd4f6e 396 write_data;\
ee12b079 241:410c9cdd4f6e 397 ADF_off=true;\
ee12b079 241:410c9cdd4f6e 398 } else {\
ee12b079 241:410c9cdd4f6e 399 write_data;\
ee12b079 241:410c9cdd4f6e 400 if(sent_tmfrom_SDcard)\
ee12b079 241:410c9cdd4f6e 401 send_tm_from_SD_card_fun();\
ee12b079 241:410c9cdd4f6e 402 else snd_tm.transmit_data(buffer_112,&last_buffer);\
ee12b079 241:410c9cdd4f6e 403 }\
ee12b079 241:410c9cdd4f6e 404 } else {\
ee12b079 241:410c9cdd4f6e 405 wait_ms(20);\
ee12b079 241:410c9cdd4f6e 406 gCS_ADF=0;\
ee12b079 241:410c9cdd4f6e 407 spi.write(0xB1);\
ee12b079 241:410c9cdd4f6e 408 gCS_ADF=1;\
ee12b079 241:410c9cdd4f6e 409 gPC.puts("transmission done\r\n");\
ee12b079 241:410c9cdd4f6e 410 loop_on=false;\
ee12b079 241:410c9cdd4f6e 411 }\
ee12b079 241:410c9cdd4f6e 412 }\
ee12b079 241:410c9cdd4f6e 413 else{\
ee12b079 241:410c9cdd4f6e 414 if(T.read_us()>98000){\
ee12b079 241:410c9cdd4f6e 415 data_irq_err=true;\
ee12b079 241:410c9cdd4f6e 416 CMD(CMD_PHY_ON);\
ee12b079 241:410c9cdd4f6e 417 gPC.printf("Data_error_detected");\
ee12b079 241:410c9cdd4f6e 418 }\
ee12b079 241:410c9cdd4f6e 419 }\
ee12b079 241:410c9cdd4f6e 420 }
ee12b079 241:410c9cdd4f6e 421
ee12b079 241:410c9cdd4f6e 422 #define send_data {\
ee12b079 9:e9eaada136c6 423 gCS_ADF=0;\
ee12b079 9:e9eaada136c6 424 spi.write(0xBB);\
ee12b079 9:e9eaada136c6 425 gCS_ADF=1;\
ee12b079 9:e9eaada136c6 426 gCS_ADF=0;\
ee12b079 9:e9eaada136c6 427 spi.write(0xFF);\
ee12b079 9:e9eaada136c6 428 spi.write(0xFF);\
ee12b079 9:e9eaada136c6 429 gCS_ADF=1;\
ee12b079 241:410c9cdd4f6e 430 if(sent_tmfrom_SDcard){\
ee12b079 95:42d6747900cb 431 send_tm_from_SD_card_fun();\
shreeshas95 1:a0055b3280c8 432 }else{\
shreeshas95 1:a0055b3280c8 433 snd_tm.transmit_data(buffer_112,&last_buffer);\
shreeshas95 1:a0055b3280c8 434 }\
shreeshas95 1:a0055b3280c8 435 write_data;\
shreeshas95 1:a0055b3280c8 436 if(sent_tmfrom_SDcard){\
krishanprajapat 148:46763854fa83 437 send_tm_from_SD_card_fun();\
krishanprajapat 148:46763854fa83 438 }else{\
krishanprajapat 148:46763854fa83 439 snd_tm.transmit_data(buffer_112,&last_buffer);\
krishanprajapat 148:46763854fa83 440 }\
krishanprajapat 148:46763854fa83 441 write_data;\
krishanprajapat 148:46763854fa83 442 if(sent_tmfrom_SDcard){\
ee12b079 95:42d6747900cb 443 send_tm_from_SD_card_fun();\
shreeshas95 1:a0055b3280c8 444 }else{\
shreeshas95 1:a0055b3280c8 445 snd_tm.transmit_data(buffer_112,&last_buffer);\
shreeshas95 1:a0055b3280c8 446 }\
shreeshas95 1:a0055b3280c8 447 gCS_ADF=0;\
shreeshas95 1:a0055b3280c8 448 spi.write(0xB1);\
shreeshas95 1:a0055b3280c8 449 gCS_ADF=1;\
shreeshas95 1:a0055b3280c8 450 wait_us(300);\
shreeshas95 1:a0055b3280c8 451 gCS_ADF=0;\
shreeshas95 1:a0055b3280c8 452 spi.write(0xFF);\
shreeshas95 1:a0055b3280c8 453 spi.write(0xFF);\
shreeshas95 1:a0055b3280c8 454 gCS_ADF=1;\
shreeshas95 1:a0055b3280c8 455 gCS_ADF=0;\
shreeshas95 1:a0055b3280c8 456 spi.write(0xB5);\
shreeshas95 1:a0055b3280c8 457 gCS_ADF=1;\
shreeshas95 1:a0055b3280c8 458 wait_us(300);\
shreeshas95 1:a0055b3280c8 459 gCS_ADF=0;\
shreeshas95 1:a0055b3280c8 460 spi.write(0xFF);\
shreeshas95 1:a0055b3280c8 461 spi.write(0xFF);\
shreeshas95 1:a0055b3280c8 462 gCS_ADF=1;\
shreeshas95 1:a0055b3280c8 463 }
ee12b079 241:410c9cdd4f6e 464
ee12b079 241:410c9cdd4f6e 465 #define initial_adf_check {\
ee12b079 241:410c9cdd4f6e 466 bool Configuration_Done=false;\
ee12b079 241:410c9cdd4f6e 467 quit_configuration=false;\
ee12b079 241:410c9cdd4f6e 468 bool reset_flag1 = 0;\
ee12b079 241:410c9cdd4f6e 469 bool flag = false;\
ee12b079 241:410c9cdd4f6e 470 while((hw_reset_err_cnt<HW_THRS)&&(quit_configuration==false)){\
ee12b079 241:410c9cdd4f6e 471 while((bbram_err_cnt<2)&&(quit_configuration==false)){\
ee12b079 241:410c9cdd4f6e 472 /*assrt_phy_off;*/\
ee12b079 241:410c9cdd4f6e 473 /*Assrt_phy_off Begin*/\
ee12b079 241:410c9cdd4f6e 474 {\
ee12b079 241:410c9cdd4f6e 475 int state_err_cnt = 0;\
ee12b079 241:410c9cdd4f6e 476 CMD(CMD_PHY_OFF);\
ee12b079 241:410c9cdd4f6e 477 if(cmd_err_flag){\
ee12b079 241:410c9cdd4f6e 478 temp_return=1;\
ee12b079 241:410c9cdd4f6e 479 }\
ee12b079 241:410c9cdd4f6e 480 else{\
ee12b079 241:410c9cdd4f6e 481 for(int i = 0 ; i < 40 ;i++){\
ee12b079 241:410c9cdd4f6e 482 CMD(CMD_PHY_OFF);\
ee12b079 241:410c9cdd4f6e 483 check_status;\
ee12b079 241:410c9cdd4f6e 484 if(status == PHY_OFF){\
ee12b079 241:410c9cdd4f6e 485 temp_return = 0;\
ee12b079 241:410c9cdd4f6e 486 break;\
ee12b079 241:410c9cdd4f6e 487 }\
ee12b079 241:410c9cdd4f6e 488 else if(state_err_cnt>THRS){\
ee12b079 241:410c9cdd4f6e 489 temp_return = 1;\
ee12b079 241:410c9cdd4f6e 490 break;\
ee12b079 241:410c9cdd4f6e 491 }\
ee12b079 241:410c9cdd4f6e 492 else {\
ee12b079 241:410c9cdd4f6e 493 wait_ms(1);\
ee12b079 241:410c9cdd4f6e 494 }\
ee12b079 241:410c9cdd4f6e 495 }\
ee12b079 241:410c9cdd4f6e 496 }\
ee12b079 241:410c9cdd4f6e 497 }\
ee12b079 241:410c9cdd4f6e 498 /*Assrt_phy_off end*/\
ee12b079 241:410c9cdd4f6e 499 reset_flag1=temp_return;\
ee12b079 241:410c9cdd4f6e 500 if(!reset_flag1){\
ee12b079 241:410c9cdd4f6e 501 bbram_write;\
ee12b079 241:410c9cdd4f6e 502 while((rbp_err_cnt<RBP_THRS)&&(quit_configuration==false)){\
ee12b079 241:410c9cdd4f6e 503 bbram_check;\
ee12b079 241:410c9cdd4f6e 504 if(bbram_err==0){\
ee12b079 241:410c9cdd4f6e 505 bbram_write_success=true;\
ee12b079 241:410c9cdd4f6e 506 bbram_err_cnt=0;\
ee12b079 241:410c9cdd4f6e 507 initiate;\
ee12b079 241:410c9cdd4f6e 508 if(reg_err){\
ee12b079 241:410c9cdd4f6e 509 rbp_err_cnt++;\
ee12b079 241:410c9cdd4f6e 510 }\
ee12b079 241:410c9cdd4f6e 511 else{\
ee12b079 241:410c9cdd4f6e 512 rbp_err_cnt=0;\
ee12b079 241:410c9cdd4f6e 513 gPC.printf("NO Reg err\r\n");\
ee12b079 241:410c9cdd4f6e 514 CMD(CMD_CONFIG_DEV);\
ee12b079 241:410c9cdd4f6e 515 if(cmd_err_flag){\
ee12b079 241:410c9cdd4f6e 516 reset_flag=1;\
ee12b079 241:410c9cdd4f6e 517 gPC.printf("CMD ERR\r\n");\
ee12b079 241:410c9cdd4f6e 518 }\
ee12b079 241:410c9cdd4f6e 519 else{\
ee12b079 241:410c9cdd4f6e 520 reset_flag=0;\
ee12b079 241:410c9cdd4f6e 521 gPC.printf("NO CMD ERR CONFIG_DONE\r\n");\
ee12b079 241:410c9cdd4f6e 522 quit_configuration=true;\
ee12b079 241:410c9cdd4f6e 523 }\
ee12b079 241:410c9cdd4f6e 524 }\
ee12b079 241:410c9cdd4f6e 525 }\
ee12b079 241:410c9cdd4f6e 526 else{\
ee12b079 241:410c9cdd4f6e 527 bbram_write_success=false;\
ee12b079 241:410c9cdd4f6e 528 bbram_err_cnt++;\
ee12b079 241:410c9cdd4f6e 529 break;\
ee12b079 241:410c9cdd4f6e 530 }\
ee12b079 241:410c9cdd4f6e 531 }\
ee12b079 241:410c9cdd4f6e 532 }\
ee12b079 241:410c9cdd4f6e 533 else{\
ee12b079 241:410c9cdd4f6e 534 break;\
ee12b079 241:410c9cdd4f6e 535 }\
ee12b079 241:410c9cdd4f6e 536 }\
ee12b079 241:410c9cdd4f6e 537 if(reset_flag1){\
ee12b079 241:410c9cdd4f6e 538 hardware_reset(0);\
ee12b079 241:410c9cdd4f6e 539 hw_reset_err_cnt++;\
ee12b079 241:410c9cdd4f6e 540 gPC.puts("Resetting hardware\r\n");\
ee12b079 241:410c9cdd4f6e 541 }\
ee12b079 241:410c9cdd4f6e 542 }\
ee12b079 241:410c9cdd4f6e 543 if(hw_reset_err_cnt==HW_THRS){\
ee12b079 241:410c9cdd4f6e 544 power_reset_flag=1;\
ee12b079 241:410c9cdd4f6e 545 power_reset_count++;\
ee12b079 241:410c9cdd4f6e 546 }\
ee12b079 241:410c9cdd4f6e 547 else{\
ee12b079 241:410c9cdd4f6e 548 Configuration_Done=true;\
ee12b079 241:410c9cdd4f6e 549 gPC.printf("Configuration_Done\n");\
ee12b079 241:410c9cdd4f6e 550 }\
ee12b079 241:410c9cdd4f6e 551 }
ee12b079 241:410c9cdd4f6e 552
aniruddhv 52:0bd68655c651 553 #define configure_adf {\
ee12b079 241:410c9cdd4f6e 554 reset_flags;\
aniruddhv 52:0bd68655c651 555 initial_adf_check;\
ee12b079 241:410c9cdd4f6e 556 gPC.puts("Config_part done\r\n");\
ee12b079 9:e9eaada136c6 557 }
ee12b079 9:e9eaada136c6 558
ee12b079 95:42d6747900cb 559 #define transmit_adf {\
aniruddhv 52:0bd68655c651 560 configure_adf;\
aniruddhv 52:0bd68655c651 561 send_data;\
ee12b079 241:410c9cdd4f6e 562 CMD(CMD_PHY_TX);\
ee12b079 241:410c9cdd4f6e 563 wait_us(2000);\
aniruddhv 52:0bd68655c651 564 while(loop_on){\
ee12b079 241:410c9cdd4f6e 565 wait_us(20);\
ee12b079 241:410c9cdd4f6e 566 check;\
ee12b079 241:410c9cdd4f6e 567 if(data_irq_err){\
ee12b079 241:410c9cdd4f6e 568 break;\
aniruddhv 52:0bd68655c651 569 }\
aniruddhv 52:0bd68655c651 570 }\
aniruddhv 69:20f09a0c3fd2 571 /*gPC.puts("after while loop\r\n");*/\
ee12b079 88:b9beee1a7a3e 572 }
ee12b079 88:b9beee1a7a3e 573