Procházet zdrojové kódy

Merge branch 'master' of https://gitee.com/openLuat/luatos-soc-air105

Wendal Chen před 2 roky
rodič
revize
da8e639bee

+ 5 - 1
application/include/luat_conf_bsp.h

@@ -49,6 +49,7 @@
 #define LUAT_USE_KEYBOARD 1
 #define LUAT_USE_DAC 1
 #define LUAT_USE_OTP 1
+#define LUAT_USE_SOFT_UART 1
 
 #define LUAT_USE_CRYPTO  1
 #define LUAT_USE_CJSON  1
@@ -92,7 +93,7 @@
 
 // #define LUAT_USE_IOTAUTH 1
 #define LUAT_USE_LORA 1
-// #define LUAT_USE_MAX30102 1
+// #define LUAT_USE_MAX30102
 // #define LUAT_USE_MLX90640 1
 #define LUAT_USE_MINIZ 1
 
@@ -118,6 +119,7 @@
 // 国密算法 SM2/SM3/SM4
 // #define LUAT_USE_GMSSL 1
 
+
 //---------------------
 // UI
 #define LUAT_USE_LCD 1
@@ -214,4 +216,6 @@ extern unsigned int gLVFlashTime;
 #define LUAT_RT_RET_TYPE int
 #define LUAT_RT_RET	0
 #define LUAT_RT_CB_PARAM void *pdata, void *param
+
+#define __LUAT_C_CODE_IN_RAM__ __attribute__((section (".RamFunc")))
 #endif

+ 2 - 2
application/src/luat_shell_air105.c

@@ -22,9 +22,9 @@
 
 #include "luat_base.h"
 #include "luat_shell.h"
-
-#include "luat_uart.h"
 #include "app_interface.h"
+#include "luat_uart.h"
+
 
 
 #define LUAT_LOG_TAG "luat.shell"

+ 76 - 1
application/src/luat_uart_air105.c

@@ -20,11 +20,12 @@
  */
 
 #include "luat_base.h"
+#include "app_interface.h"
 #include "luat_malloc.h"
 #include "luat_msgbus.h"
 #include "luat_uart.h"
 
-#include "app_interface.h"
+
 
 
 #define LUAT_LOG_TAG "luat.uart"
@@ -321,3 +322,77 @@ int luat_uart_wait_485_tx_done(int uartid)
     }
     return cnt;
 }
+
+#ifdef LUAT_USE_SOFT_UART
+#ifdef __AIR105_BSP__
+#include "air105.h"
+#include "air105_conf.h"
+#endif
+#ifndef __BSP_COMMON_H__
+#include "c_common.h"
+#endif
+
+static void __FUNC_IN_RAM__ prvHWTimer_IrqHandler(int32_t Line, void *pData)
+{
+	CommonFun_t callback = (CommonFun_t )pData;
+	uint8_t hwtimer_id = HWTimer_GetIDFromIrqline(Line);
+	volatile uint32_t clr;
+	clr = TIMM0->TIM[hwtimer_id].EOI;
+	callback();
+}
+
+int luat_uart_soft_setup_hwtimer_callback(int hwtimer_id, CommonFun_t callback)
+{
+	int irq_line = HWTimer_GetIrqLine(hwtimer_id);
+
+	TIMM0->TIM[hwtimer_id].ControlReg = 0;
+	ISR_OnOff(irq_line, 0);
+	ISR_Clear(irq_line);
+	if (callback)
+	{
+		ISR_SetHandler(irq_line, prvHWTimer_IrqHandler, callback);
+		ISR_SetPriority(irq_line, 3);
+		ISR_OnOff(irq_line, 1);
+	}
+	return 0;
+}
+void __FUNC_IN_RAM__ luat_uart_soft_gpio_fast_output(int pin, uint8_t value)
+{
+	GPIO_Output(pin, value);
+}
+uint8_t __FUNC_IN_RAM__ luat_uart_soft_gpio_fast_input(int pin)
+{
+	return GPIO_Input(pin);
+}
+void luat_uart_soft_gpio_fast_irq_set(int pin, uint8_t on_off)
+{
+	if (on_off)
+	{
+		GPIO_ExtiConfig(pin, 0, 0, 1);
+	}
+	else
+	{
+		GPIO_ExtiConfig(pin, 0, 0, 0);
+	}
+}
+uint32_t luat_uart_soft_cal_baudrate(uint32_t baudrate)
+{
+	return (48000000/baudrate);
+}
+void __FUNC_IN_RAM__ luat_uart_soft_hwtimer_onoff(int hwtimer_id, uint32_t period)
+{
+	TIMM0->TIM[hwtimer_id].ControlReg = 0;
+
+    // Enable TIMER IRQ
+    if (period)
+    {
+    	TIMM0->TIM[hwtimer_id].LoadCount = period - 1;
+    	TIMM0->TIM[hwtimer_id].ControlReg = TIMER_CONTROL_REG_TIMER_ENABLE|TIMER_CONTROL_REG_TIMER_MODE;
+    }
+}
+
+void __FUNC_IN_RAM__ luat_uart_soft_sleep_enable(uint8_t is_enable)
+{
+	PM_SetDriverRunFlag(PM_DRV_SOFT_UART, !is_enable);
+}
+#endif

+ 17 - 0
bsp/air105/hal/core_hwtimer.c

@@ -725,3 +725,20 @@ OPQueue_CmdStruct *HWTimer_GetOperationQueue(uint8_t HWTimerID)
 {
 	return 	prvHWTimer[HWTimerID].Cmd;
 }
+
+int __FUNC_IN_RAM__ HWTimer_GetIrqLine(uint8_t HWTimerID)
+{
+	return prvHWTimer[HWTimerID].IrqLine;
+}
+
+uint8_t __FUNC_IN_RAM__ HWTimer_GetIDFromIrqline(int Irqline)
+{
+	if (Irqline > TIM0_3_IRQn)
+	{
+		return (Irqline - TIM0_4_IRQn) + 4;
+	}
+	else
+	{
+		return (Irqline - TIM0_0_IRQn);
+	}
+}

+ 2 - 2
bsp/air105/hal/core_i2c.c

@@ -202,8 +202,8 @@ void I2C_MasterSetup(uint8_t I2CID, uint32_t Speed)
 	uint32_t Cnt = ((SystemCoreClock >> 3) / Speed);
 	I2C->IC_ENABLE = 0;
 	while(I2C->IC_ENABLE_STATUS & I2C_IC_ENABLE_STATUS_IC_EN){;}
-	I2C->IC_SDA_HOLD = 5;
-	I2C->IC_SDA_SETUP = Cnt/3;
+	I2C->IC_SDA_HOLD = Cnt >> 2;
+	I2C->IC_SDA_SETUP = Cnt >> 2;
 	switch(Speed)
 	{
 	case 100000:

+ 3 - 0
bsp/air105/include/core_hwtimer.h

@@ -120,4 +120,7 @@ uint32_t HWTimer_GetOperationQueueCaptureResult(uint8_t HWTimerID, CBFuncEx_t CB
 uint32_t HWTimer_GetOperationQueueLen(uint8_t HWTimerID);
 
 OPQueue_CmdStruct *HWTimer_GetOperationQueue(uint8_t HWTimerID);
+
+int HWTimer_GetIrqLine(uint8_t HWTimerID);
+uint8_t HWTimer_GetIDFromIrqline(int Irqline);
 #endif

+ 1 - 0
bsp/air105/include/core_pm.h

@@ -37,6 +37,7 @@ enum
 	PM_HW_MAX = 32,
 	PM_DRV_USB = 0,
 	PM_DRV_DBG,
+	PM_DRV_SOFT_UART,
 	PM_DRV_USER,
 	PM_DRV_MAX = 32,
 };