初版
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
#include "includes.h"
|
||||
#include "bsp.h"
|
||||
#include "iic_api.h"
|
||||
|
||||
void bsp_init()
|
||||
{
|
||||
#if P11_HW_IIC_EN
|
||||
hw_iic_master_module_init();
|
||||
#endif//P11_HW_IIC_EN
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
#include "includes.h"
|
||||
#include "timer.h"
|
||||
|
||||
void clock_early_init()
|
||||
{
|
||||
if (M2P_LRC24M_MODE) {
|
||||
//P11_SYS_CLK_SEL(P11_SYS_CLK_BTOSC_24M);
|
||||
//P11_SYS_CLK_SEL(P11_SYS_CLK_LRC24M);
|
||||
P11_SYS_CLK_SEL(P11_SYS_CLK_RC16M);
|
||||
|
||||
#if 0
|
||||
//PB0 OUT
|
||||
P11_PORT->PB_DIR &= ~BIT(0);
|
||||
P11_PORT->PB_SEL |= BIT(0);
|
||||
//och0 sysclk
|
||||
SFR(P11_PORT->OCH_CON0, 0, 4, 7);
|
||||
//crossbar och0
|
||||
P11_OMAP->P11_PB0_OUT = P11_FO_GP_OCH0;
|
||||
|
||||
while (1);
|
||||
#endif
|
||||
}
|
||||
|
||||
//std12M 输出
|
||||
SFR(P11_CLOCK->CLK_CON1, 15, 2, 1); //MSYS_BT24M --> P11_BT24M
|
||||
SFR(P11_CLOCK->CLK_CON1, 17, 3, 1); //STD12M sel P11_BT24M input
|
||||
SFR(P11_CLOCK->CLK_CON1, 20, 2, 0); // div0
|
||||
SFR(P11_CLOCK->CLK_CON1, 22, 2, 1); // div1
|
||||
}
|
||||
|
||||
static void clock_switch_lrc24m()
|
||||
{
|
||||
printf("fun: %s\n", __FUNCTION__);
|
||||
|
||||
P11_SYS_CLK_SEL(P11_SYS_CLK_LRC24M);
|
||||
|
||||
uart_clk_sel(UART_CLK_SYS_CLK);
|
||||
}
|
||||
|
||||
static void clock_msg_handler(void *priv, u8 *msg, u32 len)
|
||||
{
|
||||
switch (msg[0]) {
|
||||
case MSG_CLOCK_LRC24M_OK:
|
||||
clock_switch_lrc24m();
|
||||
timer_set_clock_source(GPTIMER_CLK_SRC_LRC_24M);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
REGISTER_M2P_MSG_HANDLER(0, MSG_CLOCK, clock_msg_handler);
|
||||
@@ -0,0 +1,4 @@
|
||||
#include "includes.h"
|
||||
|
||||
const int LIB_CONFIG_LPCTMU_ENABLE = CONFIG_LPCTMU_ENABLE;
|
||||
const int LIB_CONFIG_EXCEPTION_RESET_ENABLE = !CONFIG_UART_DEBUG_ENABLE;
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef __LIB_CONFIG_H__
|
||||
#define __LIB_CONFIG_H__
|
||||
|
||||
extern const int LIB_CONFIG_LPCTMU_ENABLE;
|
||||
extern const int LIB_CONFIG_EXCEPTION_RESET_ENABLE;
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,35 @@
|
||||
#include "sdk_config.h"
|
||||
#include "includes.h"
|
||||
#ifdef CONFIG_UART_DEBUG_ENABLE
|
||||
const char libs_debug AT(.LOG_TAG_CONST) = TRUE; //打印总开关
|
||||
#else
|
||||
const char libs_debug AT(.LOG_TAG_CONST) = FALSE; //打印总开关
|
||||
#endif
|
||||
|
||||
#define CONFIG_DEBUG_LIBS(X) (X & libs_debug)
|
||||
|
||||
const char log_tag_const_i_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_MAIN AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_UBOOT AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_UBOOT AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_UBOOT AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_UPGRADE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_UPGRADE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_UPGRADE AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_FLASH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_FLASH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_FLASH AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_FS AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_FS AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_FS AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
const char log_tag_const_i_SFC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_d_SFC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
const char log_tag_const_e_SFC AT(.LOG_TAG_CONST) = CONFIG_DEBUG_LIBS(0);
|
||||
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
#ifndef __APP_CONFIG_H__
|
||||
#define __APP_CONFIG_H__
|
||||
|
||||
|
||||
|
||||
|
||||
//==========================================================//
|
||||
// 串口打印使能开关 //
|
||||
//==========================================================//
|
||||
#define CONFIG_UART_DEBUG_ENABLE 0
|
||||
#define CONFIG_DEBUG_UART_TX_PIN IO_PORTB_00
|
||||
#define CONFIG_DEBUG_UART_BAUD 115200L
|
||||
|
||||
|
||||
//==========================================================//
|
||||
// 低功耗触摸 //
|
||||
//==========================================================//
|
||||
|
||||
#define CONFIG_LPCTMU_ENABLE 0
|
||||
|
||||
|
||||
//==========================================================//
|
||||
// SENSOR驱动 //
|
||||
//==========================================================//
|
||||
|
||||
#define CONFIG_SENSOR_DRIVER_ENABLE 0
|
||||
#define CONFIG_SENSOR_SLEEP_ENABLE 0 //自动让SENSOR睡眠,需要SENSOR支持唤醒检测并IO中断唤醒MCU
|
||||
|
||||
#define TCFG_SC7A20_ENABLE 0
|
||||
|
||||
#define TCFG_MMC5603_ENABLE 0
|
||||
|
||||
#define TCFG_VCHR11S_ENABLE 0
|
||||
#define TCFG_HRS3602_ENABLE 0
|
||||
#define TCFG_HR_SENSOR_READ_BY_INT 0
|
||||
|
||||
//==========================================================//
|
||||
// soft iic //
|
||||
//==========================================================//
|
||||
#define TCFG_SW_I2C0_CLK_PORT IO_PORTB_02 //spft IIC CLK
|
||||
#define TCFG_SW_I2C0_DAT_PORT IO_PORTB_01 //spft IIC DAT
|
||||
#define TCFG_SW_I2C0_DELAY_CNT 1 //软件IIC延时参数,影响通讯时钟频率
|
||||
|
||||
|
||||
|
||||
//========================================================== //
|
||||
// hw iic //
|
||||
//==========================================================//
|
||||
#define P11_HW_IIC_EN 0
|
||||
#define P11_HW_IIC_SCL IO_PORTB_02
|
||||
#define P11_HW_IIC_SDA IO_PORTB_01
|
||||
#define P11_HW_IIC_FREQ (400*1000)
|
||||
#define P11_HW_IIC_PU_EN 1
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,407 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".iic.bss")
|
||||
#pragma data_seg(".iic.data")
|
||||
#pragma const_seg(".iic.const")
|
||||
#pragma code_seg(".iic.text")
|
||||
#pragma str_literal_override(".iic.text")
|
||||
#endif /* #ifdef SUPPORT_MS_EXTENSIONS */
|
||||
|
||||
#include "includes.h"
|
||||
#include "sdk_config.h"
|
||||
#include "gpio.h"
|
||||
#include "iic_api.h"
|
||||
|
||||
|
||||
/******************************soft iic*****************************/
|
||||
//如果无reg_addr:reg_addr=NULL,reg_len=0
|
||||
//return: <0:error, =read_len:ok
|
||||
int soft_i2c_master_read_nbytes_from_device_reg(soft_iic_dev iic,
|
||||
unsigned char dev_addr, //设备地址
|
||||
unsigned char *reg_addr, unsigned char reg_len,//设备寄存器地址,长度
|
||||
unsigned char *read_buf, int read_len)//缓存buf,读取长度
|
||||
{
|
||||
u8 ack;
|
||||
int ret = 0;
|
||||
if (soft_iic_check_busy(iic) != IIC_OK) { //busy
|
||||
ret = IIC_ERROR_BUSY; //busy
|
||||
goto _read_exit2;
|
||||
}
|
||||
soft_iic_start(iic);
|
||||
|
||||
if ((reg_addr != NULL) && (reg_len != 0)) {
|
||||
ack = soft_iic_tx_byte(iic, dev_addr & 0xfe);
|
||||
if (ack == 0) {
|
||||
printf("<err>:dev_addr no ack!\n");
|
||||
ret = IIC_ERROR_DEV_ADDR_ACK_ERROR; //无应答
|
||||
goto _read_exit1;
|
||||
}
|
||||
|
||||
for (u8 i = 0; i < reg_len; i++) {
|
||||
ack = soft_iic_tx_byte(iic, reg_addr[i]);
|
||||
if (ack == 0) {
|
||||
printf("<err>:reg_addr no ack!\n");
|
||||
ret = IIC_ERROR_REG_ADDR_ACK_ERROR; //无应答
|
||||
goto _read_exit1;
|
||||
}
|
||||
}
|
||||
|
||||
soft_iic_start(iic);
|
||||
}
|
||||
|
||||
ack = soft_iic_tx_byte(iic, dev_addr | BIT(0));
|
||||
if (ack == 0) {
|
||||
printf("<err>:dev_addr no ack!\n");
|
||||
ret = IIC_ERROR_DEV_ADDR_ACK_ERROR; //无应答
|
||||
goto _read_exit1;
|
||||
}
|
||||
|
||||
ret = soft_iic_read_buf(iic, read_buf, read_len);
|
||||
_read_exit1:
|
||||
soft_iic_stop(iic);
|
||||
_read_exit2:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//如果无reg_addr:reg_addr=NULL,reg_len=0
|
||||
//return: =write_len:ok, other:error
|
||||
int soft_i2c_master_write_nbytes_to_device_reg(soft_iic_dev iic,
|
||||
unsigned char dev_addr, //设备地址
|
||||
unsigned char *reg_addr, unsigned char reg_len,//设备寄存器地址,长度
|
||||
unsigned char *write_buf, int write_len)//数据buf, 写入长度
|
||||
{
|
||||
int res;
|
||||
u8 ack;
|
||||
if (soft_iic_check_busy(iic) != IIC_OK) { //busy
|
||||
res = IIC_ERROR_BUSY; //busy
|
||||
goto _write_exit2;
|
||||
}
|
||||
|
||||
soft_iic_start(iic);
|
||||
ack = soft_iic_tx_byte(iic, dev_addr);
|
||||
if (ack == 0) {
|
||||
printf("<err>:dev_addr no ack!\n");
|
||||
res = IIC_ERROR_DEV_ADDR_ACK_ERROR; //无应答
|
||||
goto _write_exit1;
|
||||
}
|
||||
|
||||
if ((reg_addr != NULL) && (reg_len != 0)) {
|
||||
for (u8 i = 0; i < reg_len; i++) {
|
||||
ack = soft_iic_tx_byte(iic, reg_addr[i]);
|
||||
if (ack == 0) {
|
||||
printf("<err>:reg_addr no ack!\n");
|
||||
res = IIC_ERROR_REG_ADDR_ACK_ERROR; //无应答
|
||||
goto _write_exit1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (res = 0; res < write_len; res++) {
|
||||
if (0 == soft_iic_tx_byte(iic, write_buf[res])) {
|
||||
printf("<err>:write data no ack!\n");
|
||||
goto _write_exit1;
|
||||
}
|
||||
}
|
||||
_write_exit1:
|
||||
soft_iic_stop(iic);
|
||||
_write_exit2:
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************hw iic master*****************************/
|
||||
|
||||
#define HW_IIC_MASTER_ISR_MODE_SEL 0 //1:中断模式,0:轮询
|
||||
|
||||
//如果无reg_addr:reg_addr=NULL,reg_len=0
|
||||
//return: other:error, =read_len:ok
|
||||
int hw_i2c_master_read_nbytes_from_device_reg(hw_iic_dev iic,
|
||||
unsigned char dev_addr, //设备地址
|
||||
unsigned char *reg_addr, unsigned char reg_len,//设备寄存器地址,长度
|
||||
unsigned char *read_buf, int read_len)//缓存buf,读取长度
|
||||
{
|
||||
#if HW_IIC_MASTER_ISR_MODE_SEL && HW_IIC_MASTER_ISR_EN
|
||||
#if defined(P11_HW_IIC_NUM)&&P11_HW_IIC_NUM
|
||||
if (iic != HW_P11_IIC_0)
|
||||
#endif
|
||||
{
|
||||
struct hw_iic_master_isr_transmit iic_isr_info = {
|
||||
.dev_addr = dev_addr & 0xfe,
|
||||
.restart_flag = 1,
|
||||
.reg_buf = reg_addr,
|
||||
.reg_len = reg_len,
|
||||
.data_buf = read_buf,
|
||||
.rx_len = read_len,
|
||||
.tx_len = 0,
|
||||
};
|
||||
if ((reg_addr == NULL) || (reg_len == 0)) {
|
||||
iic_isr_info .dev_addr = dev_addr | BIT(0);
|
||||
iic_isr_info .restart_flag = 0;
|
||||
}
|
||||
enum iic_state_enum iic_sta = hw_iic_master_isr_transmit_cfg(iic, &iic_isr_info, 20);//byte间隔超时20:20*30ms
|
||||
if (iic_sta != IIC_OK) {
|
||||
log_error("iic%d isr sta:%d\n", iic, iic_sta);
|
||||
if (iic_sta == IIC_ERROR_MASTER_ERROR) {
|
||||
hw_iic_reset(iic);
|
||||
}
|
||||
return iic_sta;
|
||||
}
|
||||
return iic_isr_info.xfer_postion;
|
||||
}
|
||||
#endif
|
||||
|
||||
u8 ack;
|
||||
int ret = 0;
|
||||
if (hw_iic_check_busy(iic) != IIC_OK) { //busy
|
||||
ret = IIC_ERROR_BUSY; //busy
|
||||
goto _read_exit2;
|
||||
}
|
||||
|
||||
ret = hw_iic_start(iic);
|
||||
if (ret < 0) {
|
||||
printf("<err>:iic lock busy!%d\n", ret);
|
||||
goto _read_exit2;
|
||||
}
|
||||
if ((reg_addr != NULL) && (reg_len != 0)) {
|
||||
ack = hw_iic_tx_byte(iic, dev_addr & 0xfe);
|
||||
if (ack == 0) {
|
||||
printf("<err>:dev_addr no ack!\n");
|
||||
ret = IIC_ERROR_DEV_ADDR_ACK_ERROR; //无应答
|
||||
goto _read_exit1;
|
||||
}
|
||||
|
||||
for (u8 i = 0; i < reg_len; i++) {
|
||||
ack = hw_iic_tx_byte(iic, reg_addr[i]);
|
||||
if (ack == 0) {
|
||||
printf("<err>:reg_addr no ack!\n");
|
||||
ret = IIC_ERROR_REG_ADDR_ACK_ERROR; //无应答
|
||||
goto _read_exit1;
|
||||
}
|
||||
}
|
||||
|
||||
hw_iic_start(iic);
|
||||
}
|
||||
|
||||
ack = hw_iic_tx_byte(iic, dev_addr | BIT(0));
|
||||
if (ack == 0) {
|
||||
printf("<err>:dev_addr no ack!\n");
|
||||
ret = IIC_ERROR_DEV_ADDR_ACK_ERROR; //无应答
|
||||
goto _read_exit1;
|
||||
}
|
||||
|
||||
ret = hw_iic_read_buf(iic, read_buf, read_len);
|
||||
_read_exit1:
|
||||
hw_iic_stop(iic);
|
||||
if (ret != read_len) {
|
||||
hw_iic_err_reset(iic);
|
||||
hw_iic_reset(iic);
|
||||
}
|
||||
_read_exit2:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//如果无reg_addr:reg_addr=NULL,reg_len=0
|
||||
//return: =write_len:ok, other:error
|
||||
int hw_i2c_master_write_nbytes_to_device_reg(hw_iic_dev iic,
|
||||
unsigned char dev_addr, //设备地址
|
||||
unsigned char *reg_addr, unsigned char reg_len,//设备寄存器地址,长度
|
||||
unsigned char *write_buf, int write_len)//数据buf, 写入长度
|
||||
{
|
||||
#if HW_IIC_MASTER_ISR_EN
|
||||
#if defined(P11_HW_IIC_NUM)&&P11_HW_IIC_NUM
|
||||
if (iic != HW_P11_IIC_0)
|
||||
#endif
|
||||
{
|
||||
struct hw_iic_master_isr_transmit iic_isr_info = {
|
||||
.dev_addr = dev_addr,
|
||||
.restart_flag = 0,
|
||||
.reg_buf = reg_addr,
|
||||
.reg_len = reg_len,
|
||||
.data_buf = write_buf,
|
||||
.rx_len = 0,
|
||||
.tx_len = write_len,
|
||||
};
|
||||
enum iic_state_enum iic_sta = hw_iic_master_isr_transmit_cfg(iic, &iic_isr_info, 20);//byte间隔超时20:20*30ms
|
||||
if (iic_sta != IIC_OK) {
|
||||
log_error("iic%d isr sta:%d\n", iic, iic_sta);
|
||||
if (iic_sta == IIC_ERROR_MASTER_ERROR) {
|
||||
hw_iic_reset(iic);
|
||||
}
|
||||
return iic_sta;
|
||||
}
|
||||
return iic_isr_info.xfer_postion;
|
||||
}
|
||||
#endif
|
||||
|
||||
int res;
|
||||
u8 ack;
|
||||
if (hw_iic_check_busy(iic) != IIC_OK) { //busy
|
||||
res = IIC_ERROR_BUSY; //busy
|
||||
goto _write_exit2;
|
||||
}
|
||||
|
||||
res = hw_iic_start(iic);
|
||||
if (res < 0) {
|
||||
printf("<err>:iic lock busy!%d\n", res);
|
||||
goto _write_exit2;
|
||||
}
|
||||
ack = hw_iic_tx_byte(iic, dev_addr);
|
||||
if (ack == 0) {
|
||||
printf("<err>:dev_addr no ack!\n");
|
||||
res = IIC_ERROR_DEV_ADDR_ACK_ERROR; //无应答
|
||||
goto _write_exit1;
|
||||
}
|
||||
|
||||
if ((reg_addr != NULL) && (reg_len != 0)) {
|
||||
for (u8 i = 0; i < reg_len; i++) {
|
||||
ack = hw_iic_tx_byte(iic, reg_addr[i]);
|
||||
if (ack == 0) {
|
||||
printf("<err>:reg_addr no ack!\n");
|
||||
res = IIC_ERROR_REG_ADDR_ACK_ERROR; //无应答
|
||||
goto _write_exit1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
for (res = 0; res < write_len; res++) {
|
||||
if (0 == hw_iic_tx_byte(iic, write_buf[res])) {
|
||||
printf("<err>:write data no ack!\n");
|
||||
goto _write_exit1;
|
||||
}
|
||||
}
|
||||
#else
|
||||
res = hw_iic_write_buf(iic, write_buf, write_len);
|
||||
#endif
|
||||
_write_exit1:
|
||||
hw_iic_stop(iic);
|
||||
if (res != write_len) {
|
||||
hw_iic_err_reset(iic);
|
||||
hw_iic_reset(iic);
|
||||
}
|
||||
_write_exit2:
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************hw iic slave*****************************/
|
||||
|
||||
//rx协议:start,addr write,data0,data1,,,,,,stop
|
||||
int hw_iic_slave_polling_rx(hw_iic_dev iic, u8 *rx_buf)
|
||||
{
|
||||
int rx_cnt = 0;
|
||||
int rx_state = 0;
|
||||
|
||||
printf("--iic slave polling rx --\n");
|
||||
local_irq_disable();//关闭所有中断
|
||||
rx_state = hw_iic_slave_rx_prepare(iic, 0, 600000);//1s
|
||||
if (rx_state == IIC_SLAVE_RX_PREPARE_OK) { //rx
|
||||
} else if (rx_state == IIC_SLAVE_RX_PREPARE_TIMEOUT) { //error
|
||||
printf("<err>:iic slave wait addr timeout!\n");
|
||||
local_irq_enable();
|
||||
return 0;
|
||||
} else if (rx_state == IIC_SLAVE_RX_PREPARE_END_OK) { //end
|
||||
printf("<err>:iic slave wait end!\n");
|
||||
local_irq_enable();
|
||||
return 0;
|
||||
}
|
||||
|
||||
rx_state = hw_iic_slave_rx_byte(iic, &rx_buf[0]);//addr
|
||||
if (rx_state >= IIC_SLAVE_RX_ADDR_RX) { //rx
|
||||
} else if (rx_state == IIC_SLAVE_RX_ADDR_NO_MATCH) { //error
|
||||
printf("<err>:iic slave rx addr error!\n");
|
||||
local_irq_enable();
|
||||
return 0;
|
||||
} else if (rx_state == IIC_SLAVE_RX_ADDR_TX) { //tx
|
||||
|
||||
}
|
||||
rx_state = hw_iic_slave_rx_prepare(iic, 1, 100000);//1s, 1:收到数据应答
|
||||
if (rx_state == IIC_SLAVE_RX_PREPARE_OK) { //rx
|
||||
} else if (rx_state == IIC_SLAVE_RX_PREPARE_TIMEOUT) { //error
|
||||
printf("<err>:iic slave wait reg timeout!\n");
|
||||
local_irq_enable();
|
||||
return 0;
|
||||
} else if (rx_state == IIC_SLAVE_RX_PREPARE_END_OK) { //end
|
||||
printf("iic slave wait end!\n");
|
||||
local_irq_enable();
|
||||
return 0;
|
||||
}
|
||||
|
||||
rx_cnt = hw_iic_slave_rx_nbyte(iic, &rx_buf[1]);
|
||||
local_irq_enable();
|
||||
/* printf("rx addr:%x, slave addr:%x\n", rx_buf[0], hw_iic_slave_get_addr(iic)); */
|
||||
rx_cnt++;
|
||||
/* log_info_hexdump(rx_buf, rx_cnt); */
|
||||
printf("~~~~~iic rx polling end~~~~~\n");
|
||||
memset(rx_buf, 0, rx_cnt);
|
||||
return rx_cnt;
|
||||
}
|
||||
|
||||
//tx协议:start,addr read,data0,data1,,,,,nack,stop
|
||||
int hw_iic_slave_polling_tx(hw_iic_dev iic, u8 *tx_buf)
|
||||
{
|
||||
u8 slave_rx_data[3] = {0, 0, 0};
|
||||
int rx_cnt = 0, tx_cnt = 0;
|
||||
int rx_state = 0;
|
||||
printf("--iic slave polling tx --\n");
|
||||
local_irq_disable();//关闭所有中断
|
||||
rx_state = hw_iic_slave_rx_prepare(iic, 0, 600000);//1s
|
||||
if (rx_state == IIC_SLAVE_RX_PREPARE_OK) { //rx
|
||||
} else if (rx_state == IIC_SLAVE_RX_PREPARE_TIMEOUT) { //error
|
||||
printf("<err>:iic slave wait addr timeout!\n");
|
||||
local_irq_enable();
|
||||
return 0;
|
||||
} else if (rx_state == IIC_SLAVE_RX_PREPARE_END_OK) { //end
|
||||
printf("<err>:iic slave wait end!\n");
|
||||
local_irq_enable();
|
||||
return 0;
|
||||
}
|
||||
|
||||
rx_state = hw_iic_slave_rx_byte(iic, &slave_rx_data[rx_cnt++]);//addr
|
||||
if (rx_state >= IIC_SLAVE_RX_ADDR_RX) { //rx
|
||||
} else if (rx_state == IIC_SLAVE_RX_ADDR_TX) { //tx
|
||||
hw_iic_slave_tx_byte(iic, tx_buf[tx_cnt++]);
|
||||
goto _tx_strat;
|
||||
} else { //error
|
||||
printf("<err>:iic slave rx addr error!\n");
|
||||
local_irq_enable();
|
||||
return 0;
|
||||
}
|
||||
|
||||
_tx_strat:
|
||||
tx_cnt = hw_iic_slave_tx_nbyte(iic, &tx_buf[tx_cnt]);
|
||||
|
||||
local_irq_enable();
|
||||
/* printf("rx0 addr:%x, slave addr:%x\n", slave_rx_data[0], hw_iic_slave_get_addr(iic)); */
|
||||
/* log_info_hexdump(slave_rx_data, rx_cnt); */
|
||||
printf("~~~~~iic tx polling end~~~~~\n");
|
||||
return tx_cnt + 1; //ok
|
||||
}
|
||||
|
||||
|
||||
void hw_iic_master_module_init()
|
||||
{
|
||||
struct iic_master_config hw_iic_config = {
|
||||
.role = IIC_MASTER,
|
||||
.scl_io = P11_HW_IIC_SCL,
|
||||
.sda_io = P11_HW_IIC_SDA,
|
||||
.io_mode = P11_HW_IIC_PU_EN ,//1:上拉或0:浮空
|
||||
.hdrive = PORT_DRIVE_STRENGT_2p4mA, //enum GPIO_HDRIVE 0:2.4MA, 1:8MA, 2:26.4MA, 3:40MA
|
||||
.master_frequency = P11_HW_IIC_FREQ , //软件iic频率不准(hz)
|
||||
.io_filter = 1, //软件无效
|
||||
.ie_en = 0,//1:注册中断
|
||||
.irq_priority = 3,//优先级
|
||||
};
|
||||
hw_iic_dev iic_dev = HW_IIC_0;
|
||||
hw_iic_init(HW_IIC_0, &hw_iic_config);
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".iic.bss")
|
||||
#pragma data_seg(".iic.data")
|
||||
#pragma const_seg(".iic.const")
|
||||
#pragma code_seg(".iic.text")
|
||||
#pragma str_literal_override(".iic.text")
|
||||
#endif /* #ifdef SUPPORT_MS_EXTENSIONS */
|
||||
|
||||
#include "includes.h"
|
||||
#include "gpio.h"
|
||||
#include "iic_soft.h"
|
||||
|
||||
|
||||
|
||||
static u8 soft_iic_state[MAX_SOFT_IIC_NUM];
|
||||
static struct iic_master_config soft_iic_cfg_cache[MAX_SOFT_IIC_NUM];
|
||||
|
||||
//input pull up
|
||||
#define IIC_SCL_H(scl) \
|
||||
gpio_set_direction(scl, 1)
|
||||
|
||||
#define IIC_SCL_L(scl) \
|
||||
gpio_set_direction(scl, 0); \
|
||||
gpio_set_output_value(scl, 0)
|
||||
|
||||
|
||||
#define IIC_SDA_DIR(sda, val) \
|
||||
gpio_set_direction(sda, val)
|
||||
|
||||
//input pull up
|
||||
#define IIC_SDA_H(sda) \
|
||||
gpio_set_direction(sda, 1)
|
||||
|
||||
#define IIC_SDA_L(sda) \
|
||||
gpio_set_direction(sda, 0); \
|
||||
gpio_set_output_value(sda, 0)
|
||||
|
||||
#define IIC_SDA_READ(sda) \
|
||||
gpio_read(sda)
|
||||
|
||||
#define soft_iic_delay(num) \
|
||||
delay_cnt= num; \
|
||||
while (delay_cnt--) { \
|
||||
asm("nop"); \
|
||||
}
|
||||
static inline u32 iic_get_delay(soft_iic_dev iic)
|
||||
{
|
||||
u32 hsb_clk = 16000000;//clk_get("sys");
|
||||
u32 delay_num = 0;
|
||||
return delay_num;
|
||||
}
|
||||
|
||||
extern const struct iic_master_config soft_iic_cfg_const[MAX_SOFT_IIC_NUM];
|
||||
struct iic_master_config *get_soft_iic_config(soft_iic_dev iic)
|
||||
{
|
||||
return (struct iic_master_config *)&soft_iic_cfg_const[iic];
|
||||
}
|
||||
enum iic_state_enum soft_iic_init(soft_iic_dev iic, struct iic_master_config *i2c_config)
|
||||
{
|
||||
ASSERT(iic < MAX_SOFT_IIC_NUM, "iic > MAX_SOFT_IIC_NUM");
|
||||
if (i2c_config == NULL) {
|
||||
printf("error: soft iic%d param error!\n", iic);
|
||||
return IIC_ERROR_PARAM_ERROR;
|
||||
}
|
||||
if (iic >= MAX_SOFT_IIC_NUM) {
|
||||
printf("error: soft iic index:%d error!\n", iic);
|
||||
return IIC_ERROR_INDEX_ERROR;
|
||||
}
|
||||
if ((soft_iic_state[iic]&BIT(7)) != 0) {
|
||||
printf("error: soft iic%d has been occupied!\n", iic);
|
||||
return IIC_ERROR_INIT_FAIL;
|
||||
}
|
||||
soft_iic_state[iic] = BIT(7);//init ok
|
||||
memcpy(&soft_iic_cfg_cache[iic], i2c_config, sizeof(struct iic_master_config));
|
||||
|
||||
//freq:
|
||||
|
||||
if (i2c_config->io_mode) {//pull up
|
||||
gpio_set_pull_up(i2c_config->scl_io, 1);
|
||||
gpio_set_pull_up(i2c_config->sda_io, 1);
|
||||
} else {
|
||||
gpio_set_pull_up(i2c_config->scl_io, 0);
|
||||
gpio_set_pull_up(i2c_config->sda_io, 0);
|
||||
}
|
||||
gpio_set_hd(i2c_config->scl_io, i2c_config->hdrive);
|
||||
gpio_set_hd(i2c_config->sda_io, i2c_config->hdrive);
|
||||
IIC_SDA_H(i2c_config->sda_io);
|
||||
IIC_SCL_H(i2c_config->scl_io);
|
||||
gpio_set_pull_down(i2c_config->scl_io, 0);
|
||||
gpio_set_pull_down(i2c_config->sda_io, 0);
|
||||
gpio_set_die(i2c_config->scl_io, 1);//en 1.1v
|
||||
gpio_set_die(i2c_config->sda_io, 1);//en 1.1v
|
||||
/* gpio_set_dieh(i2c_config->scl_io, 1);//en 3.3v */
|
||||
/* gpio_set_dieh(i2c_config->sda_io, 1);//en 3.3v */
|
||||
return IIC_OK;//ok
|
||||
}
|
||||
|
||||
enum iic_state_enum soft_iic_deinit(soft_iic_dev iic)
|
||||
{
|
||||
ASSERT(iic < MAX_SOFT_IIC_NUM, "iic > MAX_SOFT_IIC_NUM");
|
||||
if (soft_iic_state[iic] == 0) {
|
||||
printf("error: soft iic%d has been no init!\n", iic);
|
||||
return IIC_ERROR_NO_INIT;
|
||||
}
|
||||
soft_iic_state[iic] = 0;//no init
|
||||
|
||||
gpio_set_direction(soft_iic_cfg_cache[iic].scl_io, 1);
|
||||
gpio_set_direction(soft_iic_cfg_cache[iic].sda_io, 1);
|
||||
gpio_set_pull_up(soft_iic_cfg_cache[iic].scl_io, 0);
|
||||
gpio_set_pull_up(soft_iic_cfg_cache[iic].sda_io, 0);
|
||||
gpio_set_die(soft_iic_cfg_cache[iic].scl_io, 0);
|
||||
gpio_set_die(soft_iic_cfg_cache[iic].sda_io, 0);
|
||||
/* gpio_set_dieh(i2c_config->scl_io, 0);//en 3.3v */
|
||||
/* gpio_set_dieh(i2c_config->sda_io, 0);//en 3.3v */
|
||||
gpio_set_hd(soft_iic_cfg_cache[iic].scl_io, PORT_DRIVE_STRENGT_2p4mA);
|
||||
gpio_set_hd(soft_iic_cfg_cache[iic].sda_io, PORT_DRIVE_STRENGT_2p4mA);
|
||||
return IIC_OK;//ok
|
||||
}
|
||||
|
||||
enum iic_state_enum soft_iic_suspend(soft_iic_dev iic)
|
||||
{
|
||||
ASSERT(iic < MAX_SOFT_IIC_NUM, "iic > MAX_SOFT_IIC_NUM");
|
||||
if ((soft_iic_state[iic] & 0xc0) != 0x80) {
|
||||
printf("error: soft iic%d is no init or suspend!\n", iic);
|
||||
return IIC_ERROR_SUSPEND_FAIL;
|
||||
}
|
||||
if ((soft_iic_state[iic] & 0x3f) != 0) {
|
||||
printf("error: soft iic%d is busy!\n", iic);
|
||||
return IIC_ERROR_BUSY;
|
||||
}
|
||||
soft_iic_state[iic] |= BIT(6);//suspend ok
|
||||
|
||||
gpio_set_direction(soft_iic_cfg_cache[iic].scl_io, 1);
|
||||
gpio_set_direction(soft_iic_cfg_cache[iic].sda_io, 1);
|
||||
gpio_set_pull_up(soft_iic_cfg_cache[iic].scl_io, 0);
|
||||
gpio_set_pull_up(soft_iic_cfg_cache[iic].sda_io, 0);
|
||||
gpio_set_die(soft_iic_cfg_cache[iic].scl_io, 0);
|
||||
gpio_set_die(soft_iic_cfg_cache[iic].sda_io, 0);
|
||||
/* gpio_set_dieh(i2c_config->scl_io, 0);//en 3.3v */
|
||||
/* gpio_set_dieh(i2c_config->sda_io, 0);//en 3.3v */
|
||||
gpio_set_hd(soft_iic_cfg_cache[iic].scl_io, PORT_DRIVE_STRENGT_2p4mA);
|
||||
gpio_set_hd(soft_iic_cfg_cache[iic].sda_io, PORT_DRIVE_STRENGT_2p4mA);
|
||||
return IIC_OK;//ok
|
||||
}
|
||||
|
||||
enum iic_state_enum soft_iic_resume(soft_iic_dev iic)
|
||||
{
|
||||
ASSERT(iic < MAX_SOFT_IIC_NUM, "iic > MAX_SOFT_IIC_NUM");
|
||||
if ((soft_iic_state[iic] & 0xc0) != 0xc0) {
|
||||
printf("error: soft iic%d is no init or no suspend!\n", iic);
|
||||
return IIC_ERROR_RESUME_FAIL;
|
||||
}
|
||||
soft_iic_state[iic] &= ~ BIT(6); //resume ok
|
||||
|
||||
|
||||
if (soft_iic_cfg_cache[iic].io_mode) {//pull up
|
||||
gpio_set_pull_up(soft_iic_cfg_cache[iic].scl_io, 1);
|
||||
gpio_set_pull_up(soft_iic_cfg_cache[iic].sda_io, 1);
|
||||
} else {
|
||||
gpio_set_pull_up(soft_iic_cfg_cache[iic].scl_io, 0);
|
||||
gpio_set_pull_up(soft_iic_cfg_cache[iic].sda_io, 0);
|
||||
}
|
||||
gpio_set_hd(soft_iic_cfg_cache[iic].scl_io, soft_iic_cfg_cache[iic].hdrive);
|
||||
gpio_set_hd(soft_iic_cfg_cache[iic].sda_io, soft_iic_cfg_cache[iic].hdrive);
|
||||
IIC_SDA_H(soft_iic_cfg_cache[iic].sda_io);
|
||||
IIC_SCL_H(soft_iic_cfg_cache[iic].scl_io);
|
||||
gpio_set_pull_down(soft_iic_cfg_cache[iic].scl_io, 0);
|
||||
gpio_set_pull_down(soft_iic_cfg_cache[iic].sda_io, 0);
|
||||
gpio_set_die(soft_iic_cfg_cache[iic].scl_io, 1);
|
||||
gpio_set_die(soft_iic_cfg_cache[iic].sda_io, 1);
|
||||
/* gpio_set_dieh(i2c_config->scl_io, 1);//en 3.3v */
|
||||
/* gpio_set_dieh(i2c_config->sda_io, 1);//en 3.3v */
|
||||
return IIC_OK;//ok
|
||||
}
|
||||
|
||||
|
||||
|
||||
//return:0:error, 1:ok
|
||||
enum iic_state_enum soft_iic_check_busy(soft_iic_dev iic)
|
||||
{
|
||||
ASSERT(iic < MAX_SOFT_IIC_NUM, "iic > MAX_SOFT_IIC_NUM");
|
||||
if (soft_iic_state[iic] & 0x0f) {
|
||||
return IIC_ERROR_BUSY;//error
|
||||
}
|
||||
soft_iic_state[iic]++;//busy
|
||||
return IIC_OK;//ok
|
||||
}
|
||||
void soft_iic_idle(soft_iic_dev iic)
|
||||
{
|
||||
soft_iic_state[iic] &= 0xf0;//idle
|
||||
}
|
||||
|
||||
enum iic_state_enum soft_iic_start(soft_iic_dev iic)
|
||||
{
|
||||
ASSERT(iic < MAX_SOFT_IIC_NUM, "iic > MAX_SOFT_IIC_NUM");
|
||||
u32 delay_cnt;
|
||||
u32 dly_t = iic_get_delay(iic);
|
||||
/* printf("soft_iic_init hsb clock:%d, delay cnt:%d\n",clk_get("sys"),dly_t); */
|
||||
|
||||
IIC_SDA_H(soft_iic_cfg_cache[iic].sda_io);
|
||||
soft_iic_delay(dly_t);
|
||||
|
||||
IIC_SCL_H(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t * 2);
|
||||
|
||||
IIC_SDA_L(soft_iic_cfg_cache[iic].sda_io);
|
||||
soft_iic_delay(dly_t);
|
||||
|
||||
IIC_SCL_L(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t);
|
||||
return IIC_OK;//ok
|
||||
}
|
||||
|
||||
void soft_iic_stop(soft_iic_dev iic)
|
||||
{
|
||||
u32 delay_cnt;
|
||||
u32 dly_t = iic_get_delay(iic);
|
||||
IIC_SDA_L(soft_iic_cfg_cache[iic].sda_io);
|
||||
soft_iic_delay(dly_t);
|
||||
|
||||
IIC_SCL_H(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t * 2);
|
||||
|
||||
IIC_SDA_H(soft_iic_cfg_cache[iic].sda_io);
|
||||
soft_iic_delay(dly_t);
|
||||
soft_iic_idle(iic);
|
||||
}
|
||||
|
||||
void soft_iic_reset(soft_iic_dev iic)//同iic_v2
|
||||
{
|
||||
ASSERT(iic < MAX_SOFT_IIC_NUM, "iic > MAX_SOFT_IIC_NUM");
|
||||
soft_iic_start(iic);
|
||||
soft_iic_stop(iic);
|
||||
soft_iic_idle(iic);
|
||||
}
|
||||
|
||||
static u8 soft_iic_check_ack(soft_iic_dev iic)
|
||||
{
|
||||
u8 ack;
|
||||
u32 delay_cnt;
|
||||
u32 dly_t = iic_get_delay(iic);
|
||||
|
||||
IIC_SDA_DIR(soft_iic_cfg_cache[iic].sda_io, 1);
|
||||
IIC_SCL_L(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t);
|
||||
|
||||
IIC_SCL_H(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t);
|
||||
|
||||
if (IIC_SDA_READ(soft_iic_cfg_cache[iic].sda_io) == 0) {
|
||||
ack = 1;
|
||||
} else {
|
||||
ack = 0;
|
||||
}
|
||||
soft_iic_delay(dly_t);
|
||||
|
||||
IIC_SCL_L(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t);
|
||||
IIC_SDA_DIR(soft_iic_cfg_cache[iic].sda_io, 0);
|
||||
IIC_SDA_L(soft_iic_cfg_cache[iic].sda_io);
|
||||
|
||||
return ack;//1:有应答, 0:无
|
||||
}
|
||||
|
||||
static void soft_iic_rx_ack(soft_iic_dev iic)
|
||||
{
|
||||
u32 delay_cnt;
|
||||
u32 dly_t = iic_get_delay(iic);
|
||||
IIC_SDA_L(soft_iic_cfg_cache[iic].sda_io);
|
||||
soft_iic_delay(dly_t);
|
||||
|
||||
IIC_SCL_H(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t * 2);
|
||||
|
||||
IIC_SCL_L(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t);
|
||||
}
|
||||
|
||||
static void soft_iic_rx_nack(soft_iic_dev iic)
|
||||
{
|
||||
u32 delay_cnt;
|
||||
u32 dly_t = iic_get_delay(iic);
|
||||
IIC_SDA_H(soft_iic_cfg_cache[iic].sda_io);
|
||||
soft_iic_delay(dly_t);
|
||||
|
||||
IIC_SCL_H(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t * 2);
|
||||
|
||||
IIC_SCL_L(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t);
|
||||
}
|
||||
|
||||
u8 soft_iic_tx_byte(soft_iic_dev iic, u8 byte)
|
||||
{
|
||||
u32 delay_cnt;
|
||||
u32 dly_t = iic_get_delay(iic);
|
||||
|
||||
local_irq_disable();
|
||||
IIC_SCL_L(soft_iic_cfg_cache[iic].scl_io);
|
||||
for (u32 i = 0; i < 8; i++) { //MSB FIRST
|
||||
if ((byte << i) & 0x80) {
|
||||
IIC_SDA_H(soft_iic_cfg_cache[iic].sda_io);
|
||||
} else {
|
||||
IIC_SDA_L(soft_iic_cfg_cache[iic].sda_io);
|
||||
}
|
||||
soft_iic_delay(dly_t);
|
||||
|
||||
IIC_SCL_H(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t * 2);
|
||||
|
||||
IIC_SCL_L(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t);
|
||||
}
|
||||
u8 ack = soft_iic_check_ack(iic);//1:有应答, 0:无
|
||||
local_irq_enable();
|
||||
return ack;
|
||||
}
|
||||
|
||||
u8 soft_iic_rx_byte(soft_iic_dev iic, u8 ack, s8 *err)
|
||||
{
|
||||
u32 delay_cnt;
|
||||
u32 dly_t = iic_get_delay(iic);
|
||||
u8 byte = 0;
|
||||
|
||||
local_irq_disable();
|
||||
IIC_SDA_DIR(soft_iic_cfg_cache[iic].sda_io, 1);
|
||||
|
||||
for (u32 i = 0; i < 8; i++) {
|
||||
soft_iic_delay(dly_t);
|
||||
|
||||
IIC_SCL_H(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t);
|
||||
|
||||
byte = byte << 1;
|
||||
if (IIC_SDA_READ(soft_iic_cfg_cache[iic].sda_io)) {
|
||||
byte |= 1;
|
||||
}
|
||||
soft_iic_delay(dly_t);
|
||||
|
||||
IIC_SCL_L(soft_iic_cfg_cache[iic].scl_io);
|
||||
soft_iic_delay(dly_t);
|
||||
}
|
||||
|
||||
IIC_SDA_DIR(soft_iic_cfg_cache[iic].sda_io, 0);
|
||||
if (ack) {
|
||||
soft_iic_rx_ack(iic);
|
||||
} else {
|
||||
soft_iic_rx_nack(iic);
|
||||
}
|
||||
|
||||
local_irq_enable();
|
||||
if (err) {
|
||||
*err = IIC_OK;
|
||||
}
|
||||
return byte;
|
||||
}
|
||||
|
||||
//return: =len:ok
|
||||
int soft_iic_read_buf(soft_iic_dev iic, void *buf, int len)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
if (!buf || !len) {
|
||||
return IIC_ERROR_PARAM_ERROR;
|
||||
}
|
||||
for (i = 0; i < len - 1; i++) {
|
||||
((u8 *)buf)[i] = soft_iic_rx_byte(iic, 1, NULL);
|
||||
}
|
||||
((u8 *)buf)[len - 1] = soft_iic_rx_byte(iic, 0, NULL);
|
||||
return len;
|
||||
}
|
||||
|
||||
//return: =len:ok
|
||||
int soft_iic_write_buf(soft_iic_dev iic, const void *buf, int len)
|
||||
{
|
||||
int i;
|
||||
u8 ack;
|
||||
|
||||
if (!buf || !len) {
|
||||
return IIC_ERROR_PARAM_ERROR;
|
||||
}
|
||||
for (i = 0; i < len; i++) {
|
||||
ack = soft_iic_tx_byte(iic, ((u8 *)buf)[i]);
|
||||
if (ack == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "includes.h"
|
||||
#include "ipc_spin_lock.h"
|
||||
|
||||
void ipc_spin_lock_init()
|
||||
{
|
||||
for (u8 i = 0; i < 16; i++) {
|
||||
P11_RESLOCK->LOCK[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
volatile u16 ipc_debug_bit;
|
||||
|
||||
|
||||
AT(.ipc_spin_lock.text.cache.L1)
|
||||
__attribute__((noinline))
|
||||
void ipc_spin_lock(enum ipc_spin_lock_event event)//0~15
|
||||
{
|
||||
ASSERT(event <= 15);
|
||||
|
||||
if (cpu_in_irq()) {
|
||||
ipc_debug_bit |= BIT(event);
|
||||
} else {
|
||||
if (ipc_debug_bit & BIT(event)) {
|
||||
ASSERT(cpu_irq_disable(), "%x\n", event);
|
||||
}
|
||||
}
|
||||
|
||||
while (P11_RESLOCK->LOCK[event]);
|
||||
}
|
||||
AT(.ipc_spin_lock.text.cache.L1)
|
||||
__attribute__((noinline))
|
||||
void ipc_spin_unlock(enum ipc_spin_lock_event event)//0~15
|
||||
{
|
||||
ASSERT(event <= 15);
|
||||
P11_RESLOCK->LOCK[event] = 0;
|
||||
}
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,185 @@
|
||||
// *INDENT-OFF*
|
||||
#include "p11_rom_stubs.ld"
|
||||
|
||||
#include "power/p11/p11_mmap.h"
|
||||
|
||||
/*
|
||||
p11 memory地址图
|
||||
|
||||
0xf28000, end
|
||||
0xf27fe0, poff ram, 0x20
|
||||
0xf27f00, m2p_message, 0xe0
|
||||
0xf27ec0, p2m_message, 0x40
|
||||
0xf2xxxx, stack, 0x600
|
||||
0xf2xxxx, bss
|
||||
0xf20080, code/data
|
||||
0xf20000, isr_vertor, 0x80
|
||||
*/
|
||||
|
||||
MEMORY
|
||||
{
|
||||
p11_message_ram(rw) : ORIGIN = P2M_MESSAGE_RAM_BEGIN, LENGTH = (P2M_MESSAGE_SIZE+M2P_MESSAGE_SIZE)
|
||||
msys_poweroff_ram(rw) : ORIGIN = MSYS_POFF_RAM_BEGIN, LENGTH = MSYS_POFF_RAM_SIZE
|
||||
p11_ram0(rw) : ORIGIN = P11_RAM0_BEGIN, LENGTH = P11_RAM0_SIZE
|
||||
|
||||
|
||||
}
|
||||
|
||||
ENTRY(_start)
|
||||
|
||||
SECTIONS
|
||||
{
|
||||
. = ORIGIN(p11_ram0);
|
||||
.text ALIGN(32):
|
||||
{
|
||||
*startup.o(.text)
|
||||
*(.text*)
|
||||
*(.*.text)
|
||||
*(.*.const)
|
||||
|
||||
*(.*.text)
|
||||
*(.ipc_spin_lock.text.cache.L1)
|
||||
|
||||
. = ALIGN(4);
|
||||
sensor_dev_begin = .;
|
||||
KEEP(*(.sensor_dev))
|
||||
sensor_dev_end = .;
|
||||
|
||||
. = ALIGN(4);
|
||||
*(.rodata*)
|
||||
|
||||
#include "power/ld/power_text.ld"
|
||||
|
||||
. = ALIGN(4);
|
||||
*(.*.data)
|
||||
. = ALIGN(4);
|
||||
*(.data*)
|
||||
. = ALIGN(4);
|
||||
} > p11_ram0
|
||||
|
||||
.data ALIGN(32):
|
||||
{
|
||||
/* *(.data*) */
|
||||
} > p11_ram0
|
||||
|
||||
.bss ALIGN(4):
|
||||
{
|
||||
*(.bss)
|
||||
*(.*.bss)
|
||||
*(COMMON)
|
||||
} > p11_ram0
|
||||
|
||||
.stack_bss ALIGN(32):
|
||||
{
|
||||
*(.stack_magic0)
|
||||
PROVIDE(_stack_begin = .);
|
||||
PROVIDE(_sstack_begin = .);
|
||||
*(.sstack)
|
||||
PROVIDE(_sstack_end = .);
|
||||
|
||||
PROVIDE(_ustack_begin = .);
|
||||
*(.ustack)
|
||||
PROVIDE(_ustack_end = .);
|
||||
|
||||
PROVIDE(_stack_end = .);
|
||||
*(.stack_magic1)
|
||||
} > p11_ram0
|
||||
|
||||
#if 0
|
||||
PROVIDE(overlay_demo_begin = .);
|
||||
OVERLAY : AT(0x200000) SUBALIGN(4)
|
||||
{
|
||||
.overlay_bank_demo_init
|
||||
{
|
||||
LONG(0xffffffff);
|
||||
*(.demo.code.bank.0)
|
||||
. = ALIGN(4);
|
||||
}
|
||||
.overlay_bank_demo_normal0
|
||||
{
|
||||
LONG(0xffffffff);
|
||||
*(.demo.code.bank.1)
|
||||
}
|
||||
|
||||
.overlay_bank_demo_normal1
|
||||
{
|
||||
LONG(0xffffffff);
|
||||
*(.demo.code.bank.2)
|
||||
}
|
||||
} > p11_ram0
|
||||
PROVIDE(overlay_demo_end = .);
|
||||
|
||||
|
||||
PROVIDE(overlay_sensor_begin = .);
|
||||
OVERLAY : AT(0x210000) SUBALIGN(4)
|
||||
{
|
||||
/* TODO: */
|
||||
.overlay_bank_sensor_init
|
||||
{
|
||||
LONG(0xffffffff);
|
||||
*(.sensor.code.bank.0)
|
||||
. = ALIGN(4);
|
||||
}
|
||||
.overlay_bank_sensor_normal0
|
||||
{
|
||||
LONG(0xffffffff);
|
||||
*(.sensor.code.bank.1)
|
||||
}
|
||||
.overlay_bank_sensor_normal1
|
||||
{
|
||||
LONG(0xffffffff);
|
||||
*(.sensor.code.bank.2)
|
||||
}
|
||||
|
||||
} > p11_ram0
|
||||
PROVIDE(overlay_sensor_end = .);
|
||||
|
||||
PROVIDE(overlay_sys_begin = .);
|
||||
OVERLAY : AT(0x220000) SUBALIGN(4)
|
||||
{
|
||||
/* TODO: */
|
||||
.overlay_bank_sys_init
|
||||
{
|
||||
LONG(0xffffffff);
|
||||
*(.sys.code.bank.0)
|
||||
. = ALIGN(4);
|
||||
}
|
||||
.overlay_bank_sys_normal0
|
||||
{
|
||||
LONG(0xffffffff);
|
||||
*(.sys.code.bank.1)
|
||||
}
|
||||
} > p11_ram0
|
||||
PROVIDE(overlay_sys_end = .);
|
||||
#endif
|
||||
|
||||
PROVIDE(p11_heap_begin = .);
|
||||
p11_heap_end = P2M_MESSAGE_RAM_BEGIN;
|
||||
|
||||
. = ORIGIN(p11_message_ram);
|
||||
.p11_message ALIGN(32):
|
||||
{
|
||||
*(.p2m_data)
|
||||
*(.m2p_data)
|
||||
} > p11_message_ram
|
||||
|
||||
. = ORIGIN(msys_poweroff_ram);
|
||||
.p11_poweroff ALIGN(32):
|
||||
{
|
||||
*(.msys_poff_data)
|
||||
} > msys_poweroff_ram
|
||||
}
|
||||
|
||||
text_begin = ADDR(.text);
|
||||
text_size = SIZEOF(.text);
|
||||
text_end = text_begin + text_size;
|
||||
|
||||
bss_begin = ADDR(.bss);
|
||||
bss_size = SIZEOF(.bss);
|
||||
|
||||
p11_message_begin = ADDR(.p11_message);
|
||||
p11_message_size = SIZEOF(.p11_message);
|
||||
|
||||
data_addr = ADDR(.data);
|
||||
data_begin = text_begin + text_size;
|
||||
data_size = SIZEOF(.data);
|
||||
@@ -0,0 +1,6 @@
|
||||
idle = ABSOLUTE(0x8000);
|
||||
standby = ABSOLUTE(0x8008);
|
||||
standby_ext = ABSOLUTE(0x8012);
|
||||
sleep_ext = ABSOLUTE(0x8030);
|
||||
sleep = ABSOLUTE(0x804e);
|
||||
deep_sleep = ABSOLUTE(0x8058);
|
||||
Binary file not shown.
@@ -0,0 +1,103 @@
|
||||
rem @echo off
|
||||
|
||||
@echo *****************************************************************
|
||||
@echo SDK BR35 P11
|
||||
@echo *****************************************************************
|
||||
@echo %date%
|
||||
|
||||
cd %~dp0
|
||||
|
||||
set OBJDUMP=C:\JL\pi32\bin\llvm-objdump.exe
|
||||
set OBJSIZEDUMP=C:\JL\pi32\bin\llvm-objsizedump.exe
|
||||
set OBJCOPY=C:\JL\pi32\bin\llvm-objcopy.exe
|
||||
set BANKLINK=.\BankLink.exe
|
||||
set ELFFILE=p11.elf
|
||||
|
||||
REM %OBJDUMP% -D -address-mask=0x1ffffff -print-imm-hex -print-dbg %ELFFILE% > p11.lst
|
||||
|
||||
%OBJCOPY% -O binary -j .text %ELFFILE% text.bin
|
||||
%OBJCOPY% -O binary -j .overlay_bank_demo_init %ELFFILE% bank_demo_init.bin
|
||||
%OBJCOPY% -O binary -j .overlay_bank_demo_normal0 %ELFFILE% bank_demo_normal0.bin
|
||||
%OBJCOPY% -O binary -j .overlay_bank_demo_normal1 %ELFFILE% bank_demo_normal1.bin
|
||||
%OBJCOPY% -O binary -j .overlay_bank_demo_normal2 %ELFFILE% bank_demo_normal2.bin
|
||||
|
||||
%OBJCOPY% -O binary -j .overlay_bank_sensor_init %ELFFILE% bank_sensor_init.bin
|
||||
%OBJCOPY% -O binary -j .overlay_bank_sensor_normal0 %ELFFILE% bank_sensor_normal0.bin
|
||||
%OBJCOPY% -O binary -j .overlay_bank_sensor_normal1 %ELFFILE% bank_sensor_normal1.bin
|
||||
|
||||
|
||||
|
||||
%OBJDUMP% -section-headers -address-mask=0x1ffffff %ELFFILE%
|
||||
%OBJDUMP% -t %ELFFILE% > symbol_tbl.txt
|
||||
|
||||
%OBJSIZEDUMP% -dump-stack-size -enable-dbg-info %ELFFILE% > dump_stack_size.txt
|
||||
%OBJSIZEDUMP% -dump-function-call -enable-dbg-info %ELFFILE% > dump_func_call.txt
|
||||
|
||||
set LZ4_PACKET=.\lz4_packet.exe
|
||||
|
||||
set bank_files=0x80 text.bin
|
||||
|
||||
%LZ4_PACKET% -input text.bin 0 -o text.lz4
|
||||
set bank_lz4_files=0x80 text.lz4
|
||||
|
||||
for %%a in (bank_demo_init.bin) do if %%~za gtr 0 (
|
||||
set bank_files=%bank_files% 0xAA55AA55 bank_demo_init.bin
|
||||
%LZ4_PACKET% -input bank_demo_init.bin 0 -o bank_demo_init.lz4
|
||||
set bank_lz4_files=%bank_lz4_files% 0xAA55AA55 bank_demo_init.lz4
|
||||
)
|
||||
|
||||
for %%a in (bank_demo_normal0.bin) do if %%~za gtr 0 (
|
||||
set bank_files=%bank_files% 0xAA55AA55 bank_demo_normal0.bin
|
||||
%LZ4_PACKET% -input bank_demo_normal0.bin 0 -o bank_demo_normal0.lz4
|
||||
set bank_lz4_files=%bank_lz4_files% 0xAA55AA55 bank_demo_normal0.lz4
|
||||
)
|
||||
|
||||
for %%a in (bank_demo_normal1.bin) do if %%~za gtr 0 (
|
||||
set bank_files=%bank_files% 0xAA55AA55 bank_demo_normal1.bin
|
||||
%LZ4_PACKET% -input bank_demo_normal1.bin 0 -o bank_demo_normal1.lz4
|
||||
set bank_lz4_files=%bank_lz4_files% 0xAA55AA55 bank_demo_normal1.lz4
|
||||
)
|
||||
|
||||
for %%a in (bank_sensor_init.bin) do if %%~za gtr 0 (
|
||||
set bank_files=%bank_files% 0xAA55AA55 bank_sensor_init.bin
|
||||
%LZ4_PACKET% -input bank_sensor_init.bin 0 -o bank_sensor_init.lz4
|
||||
set bank_lz4_files=%bank_lz4_files% 0xAA55AA55 bank_sensor_init.lz4
|
||||
)
|
||||
|
||||
for %%a in (bank_sensor_normal0.bin) do if %%~za gtr 0 (
|
||||
set bank_files=%bank_files% 0xAA55AA55 bank_sensor_normal0.bin
|
||||
%LZ4_PACKET% -input bank_sensor_normal0.bin 0 -o bank_sensor_normal0.lz4
|
||||
set bank_lz4_files=%bank_lz4_files% 0xAA55AA55 bank_sensor_normal0.lz4
|
||||
)
|
||||
|
||||
for %%a in (bank_sensor_normal1.bin) do if %%~za gtr 0 (
|
||||
set bank_files=%bank_files% 0xAA55AA55 bank_sensor_normal1.bin
|
||||
%LZ4_PACKET% -input bank_sensor_normal1.bin 0 -o bank_sensor_normal1.lz4
|
||||
set bank_lz4_files=%bank_lz4_files% 0xAA55AA55 bank_sensor_normal1.lz4
|
||||
)
|
||||
|
||||
for %%a in (bank_sys_init.bin) do if %%~za gtr 0 (
|
||||
set bank_files=%bank_files% 0xAA55AA55 bank_sys_init.bin
|
||||
%LZ4_PACKET% -input bank_sys_init.bin 0 -o bank_sys_init.lz4
|
||||
set bank_lz4_files=%bank_lz4_files% 0xAA55AA55 bank_sys_init.lz4
|
||||
)
|
||||
|
||||
for %%a in (bank_sys_normal0.bin) do if %%~za gtr 0 (
|
||||
set bank_files=%bank_files% 0xAA55AA55 bank_sys_normal0.bin
|
||||
%LZ4_PACKET% -input bank_sys_normal0.bin 0 -o bank_sys_normal0.lz4
|
||||
set bank_lz4_files=%bank_lz4_files% 0xAA55AA55 bank_sys_normal0.lz4
|
||||
)
|
||||
|
||||
echo %bank_files%
|
||||
echo %bank_lz4_files%
|
||||
|
||||
%BANKLINK% %bank_files% p11_bank_code.bin
|
||||
%BANKLINK% %bank_lz4_files% p11_bank_code.lz4
|
||||
|
||||
if exist "..\..\..\..\..\..\sdk\cpu\br35\tools\" (
|
||||
copy .\p11_bank_code.bin ..\..\..\..\..\..\sdk\cpu\br35\tools\p11_code.bin
|
||||
copy .\p11_bank_code.lz4 ..\..\..\..\..\..\sdk\cpu\br35\tools\p11_code.lz4
|
||||
)
|
||||
|
||||
::pause
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
##!/bin/sh
|
||||
${OBJDUMP} -D -address-mask=0x1ffffff -print-imm-hex -print-dbg $1.elf > $1.lst
|
||||
|
||||
${OBJCOPY} -O binary -j .text $1.elf text.bin
|
||||
##${OBJCOPY} -O binary -j .p11_poweroff_code $1.elf p11_poweroff_code.bin
|
||||
${OBJCOPY} -O binary -j .overlay_bank_demo_init $1.elf bank_demo_init.bin
|
||||
${OBJCOPY} -O binary -j .overlay_bank_demo_normal0 $1.elf bank_demo_normal0.bin
|
||||
${OBJCOPY} -O binary -j .overlay_bank_demo_normal1 $1.elf bank_demo_normal1.bin
|
||||
${OBJCOPY} -O binary -j .overlay_bank_demo_normal2 $1.elf bank_demo_normal2.bin
|
||||
|
||||
${OBJCOPY} -O binary -j .overlay_bank_sensor_init $1.elf bank_sensor_init.bin
|
||||
${OBJCOPY} -O binary -j .overlay_bank_sensor_normal0 $1.elf bank_sensor_normal0.bin
|
||||
${OBJCOPY} -O binary -j .overlay_bank_sensor_normal1 $1.elf bank_sensor_normal1.bin
|
||||
|
||||
|
||||
|
||||
${OBJDUMP} -section-headers -address-mask=0x1ffffff $1.elf > segment_list.txt
|
||||
|
||||
${OBJSIZEDUMP} -lite -skip-zero -enable-dbg-info $1.elf | sort -k 1 > symbol_tbl.txt
|
||||
|
||||
${OBJSIZEDUMP} -dump-stack-size -enable-dbg-info $1.elf > dump_stack_size.txt
|
||||
${OBJSIZEDUMP} -dump-function-call -enable-dbg-info $1.elf > dump_func_call.txt
|
||||
/opt/utils/calc_min_stack_size.py --stack dump_stack_size.txt --call dump_func_call.txt > analyze.txt
|
||||
|
||||
compress_tool=lz4_packet
|
||||
|
||||
#bank_files="0x80 p11_poweroff_code.bin "
|
||||
bank_files=${bank_files}"0x80 text.bin "
|
||||
|
||||
$compress_tool -input text.bin 0 -o text.lz4
|
||||
bank_lz4_files=${bank_lz4_files}"0x80 text.lz4 "
|
||||
|
||||
if [ -s bank_demo_init.bin ]
|
||||
then
|
||||
bank_files=${bank_files}"0xAA55AA55 bank_demo_init.bin "
|
||||
$compress_tool -input bank_demo_init.bin 0 -o bank_demo_init.lz4
|
||||
bank_lz4_files=${bank_lz4_files}"0xAA55AA55 bank_demo_init.lz4 "
|
||||
fi
|
||||
|
||||
if [ -s bank_demo_normal0.bin ]
|
||||
then
|
||||
bank_files=${bank_files}"0xAA55AA55 bank_demo_normal0.bin "
|
||||
$compress_tool -input bank_demo_normal0.bin 0 -o bank_demo_normal0.lz4
|
||||
bank_lz4_files=${bank_lz4_files}"0xAA55AA55 bank_demo_normal0.lz4 "
|
||||
fi
|
||||
|
||||
if [ -s bank_demo_normal1.bin ]
|
||||
then
|
||||
bank_files=${bank_files}"0xAA55AA55 bank_demo_normal1.bin "
|
||||
$compress_tool -input bank_demo_normal1.bin 0 -o bank_demo_normal1.lz4
|
||||
bank_lz4_files=${bank_lz4_files}"0xAA55AA55 bank_demo_normal1.lz4 "
|
||||
fi
|
||||
|
||||
if [ -s bank_sensor_init.bin ]
|
||||
then
|
||||
bank_files=${bank_files}"0xAA55AA55 bank_sensor_init.bin "
|
||||
$compress_tool -input bank_sensor_init.bin 0 -o bank_sensor_init.lz4
|
||||
bank_lz4_files=${bank_lz4_files}"0xAA55AA55 bank_sensor_init.lz4 "
|
||||
fi
|
||||
|
||||
if [ -s bank_sensor_normal0.bin ]
|
||||
then
|
||||
bank_files=${bank_files}"0xAA55AA55 bank_sensor_normal0.bin "
|
||||
$compress_tool -input bank_sensor_normal0.bin 0 -o bank_sensor_normal0.lz4
|
||||
bank_lz4_files=${bank_lz4_files}"0xAA55AA55 bank_sensor_normal0.lz4 "
|
||||
fi
|
||||
|
||||
if [ -s bank_sensor_normal1.bin ]
|
||||
then
|
||||
bank_files=${bank_files}"0xAA55AA55 bank_sensor_normal1.bin "
|
||||
$compress_tool -input bank_sensor_normal1.bin 0 -o bank_sensor_normal1.lz4
|
||||
bank_lz4_files=${bank_lz4_files}"0xAA55AA55 bank_sensor_normal1.lz4 "
|
||||
fi
|
||||
|
||||
if [ -s bank_sys_init.bin ]
|
||||
then
|
||||
bank_files=${bank_files}"0xAA55AA55 bank_sys_init.bin "
|
||||
$compress_tool -input bank_sys_init.bin 0 -o bank_sys_init.lz4
|
||||
bank_lz4_files=${bank_lz4_files}"0xAA55AA55 bank_sys_init.lz4 "
|
||||
fi
|
||||
|
||||
if [ -s bank_sys_normal0.bin ]
|
||||
then
|
||||
bank_files=${bank_files}"0xAA55AA55 bank_sys_normal0.bin "
|
||||
$compress_tool -input bank_sys_normal0.bin 0 -o bank_sys_normal0.lz4
|
||||
bank_lz4_files=${bank_lz4_files}"0xAA55AA55 bank_sys_normal0.lz4 "
|
||||
fi
|
||||
|
||||
echo ${bank_files}
|
||||
echo ${bank_lz4_files}
|
||||
|
||||
BankLink ${bank_files} p11_bank_code.bin
|
||||
BankLink ${bank_lz4_files} p11_bank_code.lz4
|
||||
|
||||
cat p11_bank_code.bin > ${NICKNAME}_code.bin
|
||||
cat p11_bank_code.lz4 > ${NICKNAME}_code.lz4
|
||||
|
||||
# cp ${NICKNAME}_code.bin /home/chenrixin/work_space/code_refacter/wsdk/watch_sdk/cpu/br35/tools/p11_code.bin
|
||||
|
||||
cat segment_list.txt
|
||||
/opt/utils/report_segment_usage --sdk_path ${ROOT} \
|
||||
--tbl_file symbol_tbl.txt \
|
||||
--seg_file segment_list.txt \
|
||||
--map_file p11.map \
|
||||
--module_depth "{\"app\":1,\"lib\":2,\"[lib]\":2}"
|
||||
|
||||
host-client -project ${NICKNAME}$2 -f ${NICKNAME}_code.bin ${NICKNAME}_code.lz4
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,68 @@
|
||||
#include "power_interface.h"
|
||||
#include "io_imap.h"
|
||||
#include "main.h"
|
||||
/* ------------------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief io_map_to_gpio imap 转成标准io口
|
||||
*
|
||||
* @param imap
|
||||
*
|
||||
* @return -1 imap非法
|
||||
* other io口
|
||||
*/
|
||||
/* ------------------------------------------------------------------------------------*/
|
||||
static int io_map_to_gpio(u32 imap)
|
||||
{
|
||||
#define GROUP 16
|
||||
if (imap >= PA0_IN && imap < PB0_IN) {
|
||||
return imap + (0 * GROUP - PA0_IN);
|
||||
} else if (imap >= PB0_IN && imap < PC0_IN) {//IO_PORTB_XX
|
||||
return imap + (1 * GROUP - PB0_IN);
|
||||
} else if (imap >= PC0_IN && imap < USBDP_IN) {
|
||||
return imap + (2 * GROUP - PC0_IN);
|
||||
} else if (imap == USBDP_IN) {
|
||||
return 14 * GROUP;
|
||||
} else if (imap == USBDM_IN) {
|
||||
return 14 * GROUP + 1;
|
||||
} else if (imap == PP0_IN) {
|
||||
return 13 * GROUP;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------*/
|
||||
/**
|
||||
* @brief io_wkup_callback io唤醒回调(中断)
|
||||
*
|
||||
* @param imap
|
||||
* @param edge
|
||||
*
|
||||
* @return 0 唤醒主系统处理
|
||||
* 1 P11处理,不唤醒主系统
|
||||
*/
|
||||
/* ------------------------------------------------------------------------------------*/
|
||||
static u32 io_wkup_callback(u32 imap, P33_IO_WKUP_EDGE edge)
|
||||
{
|
||||
/* printf("imap: %d, %d\n", imap, edge); */
|
||||
#if CONFIG_SENSOR_SLEEP_ENABLE
|
||||
if (imap == PB3_IN) {
|
||||
task_post_msg(NULL, 1, MSG_P11_SENSOR_IRQ);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
void power_early_flowing()
|
||||
{
|
||||
power_early_init(0);
|
||||
|
||||
p33_io_wakeup_set_callback(io_wkup_callback);
|
||||
}
|
||||
|
||||
int power_later_flowing()
|
||||
{
|
||||
power_later_init(0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#include "power_interface.h"
|
||||
|
||||
void board_power_init()
|
||||
{
|
||||
message_init();
|
||||
|
||||
power_init(NULL);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
#include "includes.h"
|
||||
#include "gpio.h"
|
||||
#include "ipc_spin_lock.h"
|
||||
|
||||
void app_main();
|
||||
|
||||
int main(void)
|
||||
{
|
||||
local_irq_disable();
|
||||
ipc_spin_lock_init();
|
||||
|
||||
clock_early_init();
|
||||
|
||||
power_early_flowing(0);
|
||||
|
||||
#if CONFIG_UART_DEBUG_ENABLE
|
||||
debug_uart_init(CONFIG_DEBUG_UART_TX_PIN);
|
||||
#endif /* #if CONFIG_UART_DEBUG_ENABLE */
|
||||
|
||||
printf("\n============ Hello BR35 P11 ============\n");
|
||||
|
||||
//p11_q32s(0)->PMU_CON0 |= BIT(2); //P11 WKUP EN
|
||||
printf("p11_q32s(0)->PMU_CON0 = 0x%x\n", p11_q32s(0)->PMU_CON0);
|
||||
|
||||
debug_init(); //异常检测初始化
|
||||
|
||||
board_power_init();
|
||||
|
||||
local_irq_enable();
|
||||
|
||||
while (M2P_WAIT_RELEASE == 0) {
|
||||
asm("csync");
|
||||
}
|
||||
M2P_WAIT_RELEASE = 0;
|
||||
|
||||
app_main();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,213 @@
|
||||
#ifdef SUPPORT_MS_EXTENSIONS
|
||||
#pragma bss_seg(".uart.bss")
|
||||
#pragma data_seg(".uart.data")
|
||||
#pragma const_seg(".uart.const")
|
||||
#pragma code_seg(".uart.text")
|
||||
#pragma str_literal_override(".uart.text")
|
||||
#endif /* #ifdef SUPPORT_MS_EXTENSIONS */
|
||||
|
||||
#include "includes.h"
|
||||
#include "uart.h"
|
||||
#include "gpio.h"
|
||||
#include "ipc_spin_lock.h"
|
||||
|
||||
//uart时钟选择:
|
||||
//#define UART_CLK_SEL UART_CLK_SYS_CLK //由主系统gpcnt模块算出rc16m频率,rc16m频率跟pvdd有关,注意配置被覆盖。
|
||||
#define UART_CLK_SEL UART_CLK_STD_12M //低功耗不能使用该时钟源
|
||||
|
||||
//uart波特率选择:
|
||||
#define UART_TARGET_BAUD CONFIG_DEBUG_UART_BAUD
|
||||
//#define UART_TARGET_BAUD 1000000L
|
||||
|
||||
//调试串口选择: P11_UART0/P11_UART1
|
||||
#define DEBUG_UART_SELECT P11_UART0
|
||||
|
||||
//输入选择. 只有UART0有输入功能
|
||||
#define DEBUG_UART_RX_ENABLE 0
|
||||
#if DEBUG_UART_RX_ENABLE
|
||||
#define DEBUG_UART_RX_IO IO_PORTB_05
|
||||
#define DEBUG_UART_RX_OVERTIME 100 //ms
|
||||
#endif /* #if DEBUG_UART_RX_ENABLE */
|
||||
|
||||
static u8 init = 0;
|
||||
|
||||
#define P11_UART_CLK_SEL(x) SFR(P11_CLOCK->CLK_CON2, 2, 2, x)
|
||||
|
||||
|
||||
#define UART_ENTER_CRITICAL() irq_disable_core();//ipc_spin_lock(IPC_SPIN_LOCK_EVENT_UART)
|
||||
#define UART_EXIT_CRITICAL() irq_enable_core(); //ipc_spin_unlock(IPC_SPIN_LOCK_EVENT_UART)
|
||||
|
||||
|
||||
|
||||
|
||||
___interrupt
|
||||
static void uart0_isr(void)
|
||||
{
|
||||
u8 rx = 0;
|
||||
|
||||
if (UART_RX_PENDING_IS(P11_UART0)) {
|
||||
rx = UART_BUF_READ(P11_UART0);
|
||||
UART_RX_PENDING_CLEAR(P11_UART0);
|
||||
printf("RX pending, rx: 0x%x\n", rx);
|
||||
}
|
||||
|
||||
if (UART_OT_PENDING_IS(P11_UART0)) {
|
||||
rx = UART_BUF_READ(P11_UART0);
|
||||
UART_OT_PENDING_CLEAR(P11_UART0);
|
||||
printf("OT pending, rx: 0x%x\n", rx);
|
||||
}
|
||||
}
|
||||
|
||||
static u32 uart_src_clk_get(void)
|
||||
{
|
||||
u32 freq = 0;
|
||||
|
||||
if (UART_CLK_SEL == UART_CLK_STD_12M) {
|
||||
SFR(P11_CLOCK->CLK_CON1, 15, 2, 1); //MSYS_BT24M --> P11_BT24M
|
||||
SFR(P11_CLOCK->CLK_CON1, 17, 3, 1); //STD12M sel P11_BT24M input
|
||||
SFR(P11_CLOCK->CLK_CON1, 20, 2, 0); // div0
|
||||
SFR(P11_CLOCK->CLK_CON1, 22, 2, 1); // div1
|
||||
freq = 12000000;
|
||||
} else if (UART_CLK_SEL == UART_CLK_RC16M) {
|
||||
freq = 16000000;//(u32)((u32)m2p_message[M2P_RCH_FEQ_H] << 8 | m2p_message[M2P_RCH_FEQ_L]) * 1000;
|
||||
} else if (UART_CLK_SEL == UART_CLK_SYS_CLK) {
|
||||
freq = 24000000;
|
||||
}
|
||||
|
||||
return freq;
|
||||
}
|
||||
|
||||
void uart_clk_sel(enum UART_CLK_TABLE clk)
|
||||
{
|
||||
u32 freq = 0;
|
||||
|
||||
if (clk == UART_CLK_STD_12M) {
|
||||
freq = 12000000;
|
||||
} else if (clk == UART_CLK_RC16M) {
|
||||
freq = 16000000;
|
||||
} else if (clk == UART_CLK_SYS_CLK) {
|
||||
freq = 24000000;
|
||||
}
|
||||
|
||||
P11_UART_CLK_SEL(clk);
|
||||
|
||||
u16 baud_reg = (freq / UART_TARGET_BAUD) / 4 - 1;
|
||||
|
||||
UART_BAUD_SET(DEBUG_UART_SELECT, baud_reg);
|
||||
}
|
||||
|
||||
void debug_uart_init(u8 tx_port)
|
||||
{
|
||||
UART_CON0_CLEAR(DEBUG_UART_SELECT);
|
||||
UART_CON1_CLEAR(DEBUG_UART_SELECT);
|
||||
|
||||
uart_clk_sel(UART_CLK_SEL);
|
||||
|
||||
//tx io inita
|
||||
gpio_set_output_value(tx_port, 1);
|
||||
gpio_set_direction(tx_port, 0);
|
||||
|
||||
if (DEBUG_UART_SELECT == P11_UART1) {
|
||||
//gpio_set_fun_output_port(tx_port, P11_FO_UART1_TX, 1, 1);
|
||||
} else if (DEBUG_UART_SELECT == P11_UART0) {
|
||||
gpio_set_fun_output_port(tx_port, P11_FO_UART0_TX, 1, 1);
|
||||
}
|
||||
|
||||
#if DEBUG_UART_RX_ENABLE
|
||||
u32 ot_value = 0;
|
||||
if (DEBUG_UART_SELECT == P11_UART0) {
|
||||
//rx io init:
|
||||
gpio_set_direction(DEBUG_UART_RX_IO, 1);
|
||||
gpio_set_pull_up(DEBUG_UART_RX_IO, 1);
|
||||
gpio_set_pull_down(DEBUG_UART_RX_IO, 0);
|
||||
gpio_set_die(DEBUG_UART_RX_IO, 1);
|
||||
//iomc:
|
||||
gpio_set_fun_input_port(DEBUG_UART_RX_IO, PFI_UART0_RX);
|
||||
|
||||
//rx config:
|
||||
UART_OT_PENDING_CLEAR(P11_UART0);
|
||||
UART_RX_PENDING_CLEAR(P11_UART0);
|
||||
ot_value = (uart_src_clk_get() * DEBUG_UART_RX_OVERTIME) / 1000;
|
||||
UART_OTCNT_SET(P11_UART0, ot_value);
|
||||
UART_OT_INT_ENABLE(P11_UART0);
|
||||
UART_RX_INT_ENABLE(P11_UART0);
|
||||
UART_RX_ENABLE(P11_UART0);
|
||||
P11_CLOCK->WKUP_EN |= BIT(IRQ_UART0_IDX);
|
||||
request_irq(IRQ_UART0_IDX, uart0_isr, 0);
|
||||
}
|
||||
#endif /* #if DEBUG_UART_RX_ENABLE */
|
||||
|
||||
UART_TX_ENABLE(DEBUG_UART_SELECT);
|
||||
|
||||
init = 1;
|
||||
}
|
||||
void uart_putbyte(char a)
|
||||
{
|
||||
u32 ot = 400;
|
||||
while (!UART_TX_PENDING_IS(DEBUG_UART_SELECT)) {
|
||||
if (ot-- == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
UART_TX_PENDING_CLEAR(DEBUG_UART_SELECT);
|
||||
UART_BUF_WRITE(DEBUG_UART_SELECT, a);
|
||||
}
|
||||
__WEAK__
|
||||
void putchar(char a)
|
||||
{
|
||||
if (init == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (a == '\r') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (a == '\n') {
|
||||
uart_putbyte('\r');
|
||||
}
|
||||
uart_putbyte(a);
|
||||
}
|
||||
|
||||
__WEAK__
|
||||
void putbyte(char a)
|
||||
{
|
||||
putchar(a);
|
||||
}
|
||||
|
||||
#include "power_interface.h"
|
||||
|
||||
static P11_UART_TypeDef UART0_POWEROFF;
|
||||
|
||||
static u8 uart_enter_deepsleep(void)
|
||||
{
|
||||
UART0_POWEROFF.CON0 = DEBUG_UART_SELECT->CON0;
|
||||
UART0_POWEROFF.CON1 = DEBUG_UART_SELECT->CON1;
|
||||
UART0_POWEROFF.CON2 = DEBUG_UART_SELECT->CON2;
|
||||
UART0_POWEROFF.BAUD = DEBUG_UART_SELECT->BAUD;
|
||||
UART0_POWEROFF.OTCNT = DEBUG_UART_SELECT->OTCNT;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u8 uart_exit_deepsleep(void)
|
||||
{
|
||||
DEBUG_UART_SELECT->CON1 = UART0_POWEROFF.CON1;
|
||||
DEBUG_UART_SELECT->BAUD = UART0_POWEROFF.BAUD;
|
||||
DEBUG_UART_SELECT->OTCNT = UART0_POWEROFF.OTCNT;
|
||||
DEBUG_UART_SELECT->CON2 = UART0_POWEROFF.CON2;
|
||||
|
||||
DEBUG_UART_SELECT->CON0 = UART0_POWEROFF.CON0;
|
||||
DEBUG_UART_SELECT->CON0 |= (BIT(13) | BIT(12) | BIT(10));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if CONFIG_UART_DEBUG_ENABLE
|
||||
DEEPSLEEP_TARGET_REGISTER(uart) = {
|
||||
.name = "uart",
|
||||
.enter = uart_enter_deepsleep,
|
||||
.exit = uart_exit_deepsleep,
|
||||
};
|
||||
#endif
|
||||
/*-----------------------------------------------------------*/
|
||||
Reference in New Issue
Block a user