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.
191 lines
5.8 KiB
191 lines
5.8 KiB
////////////////////////////////////////////////////////////////////////////
|
|
///@copyright Copyright (c) 2017, 传控科技 All rights reserved.
|
|
///-------------------------------------------------------------------------
|
|
/// @file cw63xx.c
|
|
/// @brief cw630x driver app
|
|
///-------------------------------------------------------------------------
|
|
/// @version 1.0
|
|
/// @author CC
|
|
/// @date 20170122
|
|
/// @note cc_AS_stc01
|
|
|
|
/// @version 1.1
|
|
/// @author CC
|
|
/// @date 20170619
|
|
/// @note for
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
#include "cw63xx.h"
|
|
//#include "../debug/debug_drv.h"
|
|
#include "../msp/iic_sim.h"
|
|
#include "../msp/uart0.h"
|
|
//#include "msa300.h"
|
|
|
|
///-------------------------------------------------------------------------
|
|
/// @breif L1_cw63xx_init
|
|
/// @param a s_task_PWON
|
|
/// @param s "L1_cw63xx_init"
|
|
/// @return none
|
|
/// @see Test() (本函数参考其它的相关的函数,这里作一个链接)
|
|
/// @note (note描述需要注意的问题)
|
|
///-------------------------------------------------------------------------
|
|
#define D_lowPower_warnning 0x02
|
|
#define D_lowPower_BAT_FULL 0x08
|
|
|
|
|
|
|
|
|
|
/*****************************
|
|
|
|
if(BITN_G(I2CTXD,BITN1))
|
|
|
|
CHG_IN:如果 DCIN 有 5V 电源接入,则检测到充电并触发中断,寄存器 0x03[5]由 0 变成 1。
|
|
BAT_FULL:如果电池充满电,电流变为 0,则触发中断,寄存器 0x03[4]由 0 变成 1。
|
|
BAT_OT:如果电池温度过高(默认值 60℃左右),则触发中断并停止充电,寄存器 0x03[3]由 0 变成1。
|
|
BAT_UT:如果电池温度过低(默认值 0℃左右),则触发中断并停止充电,寄存器 0x03[2]由 0 变成1。
|
|
LOW_BAT:如果电池电压低于告警值时(默认为 3.4V),则触发中断,寄存器 0x03[1]由 0 变成 1。
|
|
BUTTON:按键按下,会触发一个中断,寄存器 0x03[0]由 0 变成 1
|
|
|
|
实际中,去掉电池后产生的是 BAT_FULL中断。
|
|
|
|
***************************/
|
|
void L1_cw63xx_sta(void)
|
|
{
|
|
U8 d;
|
|
L2_I2C_ReadReg(D_i2c_addr_cw63xx,D_CW63X_REG_Interrupt,&d,1);
|
|
if(BITN_G(d, BITN1))///收到低电压警告
|
|
{
|
|
I2CTXD = 1;
|
|
}
|
|
|
|
if(BITN_G(d, BITN4))///只有充满电后才低压标志被清零
|
|
{
|
|
I2CTXD = 0;
|
|
}
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_CW63X_REG_Interrupt,0);
|
|
}
|
|
#if 0
|
|
void L1_cw63xx_init(void)
|
|
{
|
|
U8 val = 0;
|
|
// LDO1 LDO2 LDO3 LDO4
|
|
#if 0
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_CW63X_REG_LDO1,D_CW63XX_ON|D_CW63XX_3V2); // 进入normal 模式
|
|
Lc_delay_ms(100);// 2000--7s
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_CW63X_REG_LDO2,D_CW63XX_ON|D_CW63XX_3V2); // 打开 LDO1 并设置为1.8v
|
|
Lc_delay_ms(100);
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_CW63X_REG_LDO3,D_CW63XX_ON|D_CW63XX_3V2); // 进入normal 模式
|
|
Lc_delay_ms(100);// 2000--7s
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_CW63X_REG_LDO4,D_CW63XX_ON|D_CW63XX_3V2); // 打开 LDO1 并设置为1.8v
|
|
//#else
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_power_VCC,D_CW63XX_ON|D_CW63XX_2V5); // mcu gsensor
|
|
Lc_delay_ms(10);// 2000--7s
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_power_VCC1,D_CW63XX_ON|D_CW63XX_3V); // uart4 sed ch430 mcu_program
|
|
Lc_delay_ms(10);
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_power_VCC2,D_CW63XX_ON|D_CW63XX_2V5); //uart 4 receive
|
|
Lc_delay_ms(10);// 2000--7s
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_power_VCC3,D_CW63XX_ON|D_CW63XX_2V5); // 设置 AS cpu 供电2.5v
|
|
|
|
//L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_power_VCC2,D_CW63XX_ON|D_CW63XX_1V8); // 设置 AS cpu 供电2.5v
|
|
//Lc_delay_ms(600);
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_power_VCC3,D_CW63XX_ON|D_CW63XX_2V8); // 设置 AS cpu 供电2.5v
|
|
Lc_delay_ms(10);
|
|
|
|
#endif
|
|
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_CW63X_REG_Charge,0x3F);///150mA CHARGE
|
|
///L2_I2C_ReadReg(D_i2c_addr_cw63xx,D_CW63X_REG_Charge,&val,1);
|
|
// L0_uart0_uchex(val);
|
|
// Lc_delay_ms(10);
|
|
//// Lc_delay_ms(10);
|
|
//// L2_I2C_ReadReg(D_i2c_addr_cw63xx,D_CW63X_REG_Charge,&val,1);
|
|
//// L0_uart0_uc(val);
|
|
//// Lc_delay_ms(10);
|
|
/******************
|
|
while(9)
|
|
{
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_power_VCC2,D_CW63XX_ON|D_CW63XX_2V8); L0_uart0_uc('e');
|
|
Lc_delay_ms(30);
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,D_power_VCC2,D_CW63XX_OFF|D_CW63XX_2V8);
|
|
Lc_delay_ms(30);
|
|
|
|
}
|
|
*****************/
|
|
|
|
///--------------------------------------------------------------------
|
|
// L2_I2C_ReadReg(D_i2c_addr_cw63xx,D_CW63X_REG_LDO1,s_as1.d,4);// press
|
|
// L0_uart0_uchex(s_as1.d[0]); L0_uart0_uchex(s_as1.d[1]); L0_uart0_uchex(s_as1.d[2]); L0_uart0_uchex(s_as1.d[3]);
|
|
|
|
}
|
|
|
|
void L3_cw63xx_fun(U8 *pPara)
|
|
{
|
|
*pPara=0;
|
|
}
|
|
|
|
///#else
|
|
|
|
//// FX CMD R2 R3 4
|
|
void L3_cw63xx_fun(U8 *pPara)
|
|
{
|
|
U8 val = 0;
|
|
TS_P_debug *p = pPara;
|
|
switch(p->cmd)
|
|
{
|
|
/**********
|
|
case 0:
|
|
L1_cw63xx_init();
|
|
L0_uart0_uc('C');
|
|
L0_uart0_uc(p->R1);
|
|
L0_uart0_uc(p->R2);
|
|
L0_uart0_uc(p->R3);
|
|
break;
|
|
***********/
|
|
case 1: ////
|
|
//// AX CMDR2 R3 R4
|
|
/// AD 01 01 03 04 读取reg 01的数值
|
|
//void L2_I2C_ReadReg(unsigned char sla,unsigned char reg,
|
|
// unsigned char *r,unsigned char n)
|
|
L2_I2C_ReadReg(D_i2c_addr_cw63xx,p->R2,&val,1);
|
|
L0_uart0_uc(val);
|
|
break;
|
|
|
|
|
|
case 2: //FD 02 03 04 00
|
|
///aD 02 0A 38 00 //vcc1 off
|
|
///aD 02 0A B8 00 //vcc1 ON
|
|
///FD 02 0B 04 00 B0011_1000
|
|
///FD 02 0C 04 00
|
|
///FD 02 01 3a 00 100mA充电
|
|
|
|
L0_uart0_uc('W');
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,p->R2,p->R3);
|
|
//L0_uart0_uc(pPara[2]);
|
|
|
|
L0_uart0_uc(p->R2);
|
|
L0_uart0_uc(p->R3);
|
|
break;
|
|
|
|
|
|
default:
|
|
break;
|
|
};
|
|
}
|
|
|
|
L2_I2C_ReadReg(D_i2c_addr_cw63xx,0,s_as.d,4);
|
|
L0_uart0_sendArray(s_as.d,4);
|
|
L2_I2C_WriteCmd(D_i2c_addr_cw63xx,0x03,0);////读完中断后需要写零才能清空中断
|
|
CHG_IN:如果 DCIN 有 5V 电源接入,则检测到充电并触发中断,寄存器 0x03[5]由 0 变成 1。
|
|
BAT_FULL:如果电池充满电,电流变为 0,则触发中断,寄存器 0x03[4]由 0 变成 1。
|
|
BAT_OT:如果电池温度过高(默认值 60℃左右),则触发中断并停止充电,寄存器 0x03[3]由 0 变成1。
|
|
BAT_UT:如果电池温度过低(默认值 0℃左右),则触发中断并停止充电,寄存器 0x03[2]由 0 变成1。
|
|
LOW_BAT:如果电池电压低于告警值时(默认为 3.4V),则触发中断,寄存器 0x03[1]由 0 变成 1。
|
|
BUTTON:按键按下,会触发一个中断,寄存器 0x03[0]由 0 变成 1
|
|
|
|
实际中,去掉电池后产生的是 BAT_FULL中断。
|
|
|
|
#endif
|
|
|
|
|
|
|