Dheeraj M Pai
/
October_22_1_28AM
Partially made code for adf7023
Diff: main.cpp
- Revision:
- 1:434b2062426b
- Parent:
- 0:e80c23aacae6
- Child:
- 2:599022fe2f99
diff -r e80c23aacae6 -r 434b2062426b main.cpp --- a/main.cpp Wed Oct 21 20:10:52 2015 +0000 +++ b/main.cpp Wed Oct 21 20:26:08 2015 +0000 @@ -11,6 +11,8 @@ #define THRS 20 #define STATE_ERR_THRS 20 #define PHY_OFF_EXEC_TIME 300 +#define PHY_ON_EXEC_TIME 300 +#define PHY_TX_EXEC_TIME 600 /******DEFINING OMMANDS*********/ #define CMD_HW_RESET 0xC8 @@ -386,7 +388,67 @@ return assrt_phy_off(cmd_err_cnt+1,spi_err_cnt,state_err_cnt); } } - +/*****************************/ +unsigned char assrt_phy_on(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ + status=check_status(); + if(status==0xB2){ + return 0; + } + else if(cmd_err_cnt>THRS||spi_err_cnt>THRS){ + return 1;//You need to Reset the hardware + } + else if(state_err_cnt>STATE_ERR_THRS){ + return 1;//Again reset the hardware + } + else if((status&0xA0)==0xA0){ //If Status' first three bit ore 0b1X1 =>SPI ready, Dont care interrupt and CMD Ready. + CS=0; + adf.write(0xB1); //CMD_PHY_OFF + CS=1; + wait_us(PHY_ON_EXEC_TIME);// Typical = 24us We are giving 300us + return assrt_phy_on(cmd_err_cnt,spi_err_cnt,state_err_cnt+1); + } + else if(status&0x80==0x00){ + wait_ms(5); + //Error: SPI=0 Not ready CMD= Dont care + return assrt_phy_on(cmd_err_cnt,spi_err_cnt+1,state_err_cnt); + } + else if(status&0xA0==0x80){ + wait_ms(1); + //Error: Command Not ready SPI Ready cmd_err_cnt is a global variable + return assrt_phy_on(cmd_err_cnt+1,spi_err_cnt,state_err_cnt); + } +} + /*****************************/ + unsigned char assrt_phy_tx(int cmd_err_cnt,int spi_err_cnt,int state_err_cnt){ + status=check_status(); + if((status & 0x1F) == 0xB4){ + return 0; + } + else if(cmd_err_cnt>THRS||spi_err_cnt>THRS){ + return 1;//You need to Reset the hardware + } + else if(state_err_cnt>STATE_ERR_THRS){ + return 1;//Again reset the hardware + } + else if((status&0xA0)==0xA0){ //If Status' first three bit ore 0b1X1 =>SPI ready, Dont care interrupt and CMD Ready. + CS=0; + adf.write(0xB1); //CMD_PHY_OFF + CS=1; + wait_us(PHY_TX_EXEC_TIME);// Typical = 24us We are giving 300us + return assrt_phy_tx(cmd_err_cnt,spi_err_cnt,state_err_cnt+1); + } + else if(status&0x80==0x00){ + wait_ms(1); + //Error: SPI=0 Not ready CMD= Dont care + return assrt_phy_tx(cmd_err_cnt,spi_err_cnt+1,state_err_cnt); + } + else if(status&0xA0==0x80){ + wait_us(50); + //Error: Command Not ready SPI Ready cmd_err_cnt is a global variable + return assrt_phy_tx(cmd_err_cnt+1,spi_err_cnt,state_err_cnt); + } +} + /***************************/ bool hardware_reset(int bcn_call){ if (bcn_call>20){