You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
193 lines
5.0 KiB
193 lines
5.0 KiB
|
|
/*******************************************************************************
|
|
Function :
|
|
Brief : reg common driver
|
|
Input :
|
|
Return :
|
|
*******************************************************************************/
|
|
int reg_errcnt=0;
|
|
|
|
#define HW32_REG(ADDRESS) (*((volatile unsigned long *)(ADDRESS)))
|
|
|
|
// I2C Status In Master Transmitter Mode
|
|
#define I2C_STA_MST_STA 0X08
|
|
#define I2C_STA_MST_RESTA 0X10
|
|
|
|
#define I2C_STA_MST_TX_ADDR_W_ACK 0x18
|
|
#define I2C_STA_MST_TX_ADDR_W_NACK 0x20
|
|
|
|
#define I2C_STA_MST_TX_DATA_ACK 0x28
|
|
#define I2C_STA_MST_TX_DATA_NACK 0x30
|
|
|
|
// I2C Status In Master Receiver Mode
|
|
#define I2C_STA_MST_RX_ADDR_R_ACK 0x40
|
|
#define I2C_STA_MST_RX_ADDR_R_NACK 0x48
|
|
|
|
#define I2C_STA_MST_RX_DATA_ACK 0x50
|
|
#define I2C_STA_MST_RX_DATA_NACK 0x58
|
|
|
|
// I2C Status In Slave Receiver Mode
|
|
#define I2C_STA_SLV_RX_ADDR_W_ACK 0x60
|
|
#define I2C_STA_SLV_RX_ARB_LOST_ADDR_ACK 0x68
|
|
#define I2C_STA_SLV_RX_REG_ADDR_ACK 0x70
|
|
#define I2C_STA_SLV_RX_ARB_LOST_REG_ADDR_ACK 0x78
|
|
#define I2C_STA_SLV_RX_DATA_ACK 0x80
|
|
#define I2C_STA_SLV_RX_DATA_NACK 0x88
|
|
#define I2C_STA_SLV_RX_PADDR_DATA_ACK 0x90
|
|
#define I2C_STA_SLV_RX_PADDR_DATA_NACK 0x98
|
|
#define I2C_STA_SLV_RX_STO_RSTA 0xA0
|
|
|
|
// I2C Status In Slave Transmitter Mode
|
|
#define I2C_STA_SLV_TX_ADDR_R_ACK 0xA8
|
|
#define I2C_STA_SLV_TX_ARB_LOST_ADD_R_ACK 0XB0
|
|
#define I2C_STA_SLV_TX_DATA_ACK 0xB8
|
|
#define I2C_STA_SLV_TX_DATA_NACK 0xC0
|
|
#define I2C_STA_SLV_TX_LAST_DATA_ACK 0xC8
|
|
#define I2C_STA_SLV_TX_ARB_LOST 0X38
|
|
#define I2C_STA_SLV_TX_NO_STA 0XF8
|
|
#define I2C_STA_MISC_BUS_ERR 0x00
|
|
|
|
#define I2C_STA_SLV_TX_ARB_LOST 0X38
|
|
//#define I2C_STA_SLV_TX_NO_STA 0XF8
|
|
#define I2C_STA_MISC_BUS_ERR 0x00
|
|
|
|
|
|
static void delay_for_character(void)
|
|
{
|
|
int i;
|
|
for (i=0; i<2;i++){
|
|
__ISB();
|
|
}
|
|
return;
|
|
}
|
|
|
|
static void delay2(void)
|
|
{
|
|
int i;
|
|
for (i=0; i<50;i++){
|
|
__ISB();
|
|
}
|
|
return;
|
|
}
|
|
|
|
static void fw_read_check_with_warn(uint32_t address, uint32_t expect_data, uint32_t read_bits)
|
|
{
|
|
if( (HW32_REG(address)&read_bits)!=(expect_data&read_bits)){
|
|
reg_errcnt++;
|
|
printf("ERROR:RW bit, the expected %x, actual %x for address %x\n",expect_data&read_bits,HW32_REG(address),address);
|
|
}
|
|
//if( (HW32_REG(address)&read_bits)!=(expect_data&read_bits))
|
|
// printf("WARN:RO bit, the expected %x, actual %x for address %x\n",expect_data,HW32_REG(address),address);
|
|
}
|
|
|
|
static void fw_write_check_protect(uint32_t address, uint32_t expect_data)
|
|
{
|
|
HW32_REG(address) = expect_data;
|
|
if(HW32_REG(address)!=0x00000000){
|
|
reg_errcnt++;
|
|
printf("ERROR:PROTECT bit, the expected %x, actual %x for address %x\n",0x00000000,HW32_REG(address),address);
|
|
}
|
|
}
|
|
|
|
static void fw_write_check_with_warn(uint32_t address, uint32_t expect_data, uint32_t read_bits)
|
|
{
|
|
HW32_REG(address) = expect_data;
|
|
delay_for_character();
|
|
if( (HW32_REG(address)&read_bits)!=(expect_data&read_bits)){
|
|
reg_errcnt++;
|
|
printf("ERROR:RW bit, the expected %x, actual %x for address %x\n",expect_data&read_bits,HW32_REG(address),address);
|
|
}
|
|
//if( (HW32_REG(address)&read_bits)!=(expect_data&read_bits))
|
|
// printf("WARN:RO bit, the expected %x, actual %x for address %x\n",expect_data,HW32_REG(address),address);
|
|
}
|
|
|
|
|
|
//------------------------------------------//
|
|
// Name: Qingqing He
|
|
// Function: check wc_reg
|
|
// Arguments:the value read from wc reg is always 0
|
|
// exp_val:
|
|
//------------------------------------------//
|
|
static void fw_write_check_wc_reg(uint32_t address,uint32_t write_data, uint32_t expect_data, uint32_t read_bits)
|
|
{
|
|
HW32_REG(address) = write_data;
|
|
delay_for_character();
|
|
if( (HW32_REG(address)&read_bits)!=(expect_data&read_bits)){
|
|
reg_errcnt++;
|
|
printf("ERROR:RW bit, the expected %x, actual %x for address %x\n",expect_data&read_bits,HW32_REG(address),address);
|
|
}
|
|
}
|
|
|
|
//------------------------------------------//
|
|
// Function: config func i2c
|
|
//------------------------------------------//
|
|
static void config_func_i2c(void)
|
|
{
|
|
int i = 0 ;
|
|
int smb_sel_tmout = 0;
|
|
int con_reg;
|
|
|
|
printf("Enable func i2c master\n");
|
|
|
|
REG_I2C_MASTER_I2CCON->bf.ens1 = 1;
|
|
delay2();
|
|
|
|
REG_I2C_MASTER_I2CADR->bf.adr = 0x48;
|
|
delay2();
|
|
|
|
REG_I2C_MASTER_I2CCON->bf.aa = 1;
|
|
delay2();
|
|
|
|
con_reg = REG_I2C_MASTER_I2CCON -> word;
|
|
|
|
//REG_CLKCTRL_PIN_MUL_SET->bf.gp67_i2c_role = 1; //8849
|
|
|
|
printf("set slave address to 0x48\n");
|
|
REG_I2C_MASTER_I2CADR->bf.adr = 0x48;
|
|
|
|
}
|
|
|
|
|
|
static void config_func_i2c1(void)
|
|
{
|
|
int i = 0 ;
|
|
int smb_sel_tmout = 0;
|
|
int con_reg;
|
|
|
|
printf("Enable func i2c master\n");
|
|
|
|
REG_I2C1_MASTER_I2CCON->bf.ens1 = 1;
|
|
delay2();
|
|
|
|
REG_I2C1_MASTER_I2CADR->bf.adr = 0x48;
|
|
delay2();
|
|
|
|
REG_I2C1_MASTER_I2CCON->bf.aa = 1;
|
|
delay2();
|
|
|
|
con_reg = REG_I2C1_MASTER_I2CCON -> word;
|
|
|
|
//REG_CLKCTRL_PIN_MUL_SET->bf.gp67_i2c_role = 1; //8849
|
|
|
|
printf("set slave address to 0x48\n");
|
|
REG_I2C1_MASTER_I2CADR->bf.adr = 0x48;
|
|
|
|
}
|
|
|
|
|
|
static void fw_set_protect(void)
|
|
{
|
|
HW32_REG(0x4001401C) = 0x00000000;
|
|
}
|
|
|
|
static void fw_unset_protect(void)
|
|
{
|
|
HW32_REG(0x4001401C) = 0x00009A6E;
|
|
}
|
|
|
|
static void fw_unset_protect1(void)
|
|
{
|
|
HW32_REG(0x4001204C) = 0x00008E9F;
|
|
}
|
|
|
|
|
|
|