mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-21 02:15:55 +08:00
更新硬件SDK
This commit is contained in:
13
sdk/合宙/air780e/csdk/luatos-soc-2022/project/luatos/README.md
Normal file
13
sdk/合宙/air780e/csdk/luatos-soc-2022/project/luatos/README.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# LuatOS @ Air780E
|
||||
|
||||
这是bsp代码, 不是完整的LuatOS代码, 需要配合[主库](https://gitee.com/openLuat/LuatOS) 一起才能编译固件
|
||||
|
||||
## 编译说明
|
||||
|
||||
请查阅wiki: https://wiki.luatos.com/develop/compile/Air780E.html
|
||||
|
||||
## 有任何建议或反馈
|
||||
|
||||
1. 如果是LuatOS的需求或缺陷, 请到 [主库](https://gitee.com/openLuat/LuatOS) 报issue
|
||||
2. 如果是Air780E的csdk的需求或缺陷, 请到 [主库](https://gitee.com/openLuat/luatos-soc-2022) 报issue
|
||||
|
||||
@@ -0,0 +1,376 @@
|
||||
#ifndef __RTE_DEVICE_H
|
||||
#define __RTE_DEVICE_H
|
||||
|
||||
#include "ec618.h"
|
||||
|
||||
/* Peripheral IO Mode Select, Must Configure First !!!
|
||||
Note, when receiver works in DMA_MODE, interrupt is also enabled to transfer tailing bytes.
|
||||
*/
|
||||
|
||||
#define POLLING_MODE 0x1
|
||||
#define DMA_MODE 0x2
|
||||
#define IRQ_MODE 0x3
|
||||
#define UNILOG_MODE 0x4
|
||||
|
||||
#define RTE_UART0_TX_IO_MODE UNILOG_MODE
|
||||
#define RTE_UART0_RX_IO_MODE IRQ_MODE
|
||||
#define USART0_RX_TRIG_LVL (30)
|
||||
|
||||
#define RTE_UART1_TX_IO_MODE DMA_MODE
|
||||
#define RTE_UART1_RX_IO_MODE DMA_MODE
|
||||
|
||||
#define RTE_UART2_TX_IO_MODE DMA_MODE
|
||||
#define RTE_UART2_RX_IO_MODE DMA_MODE
|
||||
|
||||
#define RTE_SPI0_IO_MODE POLLING_MODE
|
||||
|
||||
#define RTE_SPI1_IO_MODE POLLING_MODE
|
||||
|
||||
#define RTE_I2C0_IO_MODE POLLING_MODE
|
||||
#define RTE_I2C1_IO_MODE POLLING_MODE
|
||||
|
||||
|
||||
// I2C0 (Inter-integrated Circuit Interface) [Driver_I2C0]
|
||||
// Configuration settings for Driver_I2C0 in component ::Drivers:I2C
|
||||
#define RTE_I2C0 1
|
||||
|
||||
// { PAD_PIN13}, // 4 : gpio14 / 2 : I2C0 SCL
|
||||
// { PAD_PIN14}, // 4 : gpio15 / 2 : I2C0 SDA
|
||||
#define RTE_I2C0_SCL_BIT 13 // AUDIO use 13
|
||||
#define RTE_I2C0_SCL_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_I2C0_SDA_BIT 14 // AUDIO use 14
|
||||
#define RTE_I2C0_SDA_FUNC PAD_MUX_ALT2
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_I2C0_DMA_TX_EN 0
|
||||
#define RTE_I2C0_DMA_TX_REQID DMA_REQUEST_I2C0_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_I2C0_DMA_RX_EN 0
|
||||
#define RTE_I2C0_DMA_RX_REQID DMA_REQUEST_I2C0_RX
|
||||
|
||||
// I2C1 (Inter-integrated Circuit Interface) [Driver_I2C1]
|
||||
// Configuration settings for Driver_I2C1 in component ::Drivers:I2C
|
||||
#define RTE_I2C1 1
|
||||
|
||||
// { PAD_PIN20}, // 0 : gpio5 / 2 : I2C1 SCL
|
||||
// { PAD_PIN19}, // 0 : gpio4 / 2 : I2C1 SDA
|
||||
#define RTE_I2C1_SCL_BIT 20
|
||||
#define RTE_I2C1_SCL_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_I2C1_SDA_BIT 19
|
||||
#define RTE_I2C1_SDA_FUNC PAD_MUX_ALT2
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_I2C1_DMA_TX_EN 1
|
||||
#define RTE_I2C1_DMA_TX_REQID DMA_REQUEST_I2C1_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_I2C1_DMA_RX_EN 1
|
||||
#define RTE_I2C1_DMA_RX_REQID DMA_REQUEST_I2C1_RX
|
||||
|
||||
|
||||
// UART0 (Universal asynchronous receiver transmitter) [Driver_USART0]
|
||||
// Configuration settings for Driver_USART0 in component ::Drivers:USART
|
||||
#define RTE_UART0_CTS_PIN_EN 0
|
||||
#define RTE_UART0_RTS_PIN_EN 0
|
||||
|
||||
// { PAD_PIN27}, // 0 : gpio12 / 3 : UART0 RTSn
|
||||
// { PAD_PIN28}, // 0 : gpio13 / 3 : UART0 CTSn
|
||||
// { PAD_PIN29}, // 0 : gpio14 / 3 : UART0 RXD
|
||||
// { PAD_PIN30}, // 0 : gpio15 / 3 : UART0 TXD
|
||||
#define RTE_UART0_RTS_BIT 27
|
||||
#define RTE_UART0_RTS_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_UART0_CTS_BIT 28
|
||||
#define RTE_UART0_CTS_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_UART0_RX_BIT 29
|
||||
#define RTE_UART0_RX_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_UART0_TX_BIT 30
|
||||
#define RTE_UART0_TX_FUNC PAD_MUX_ALT3
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART0_DMA_TX_REQID DMA_REQUEST_USART0_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART0_DMA_RX_REQID DMA_REQUEST_USART0_RX
|
||||
|
||||
// UART1 (Universal asynchronous receiver transmitter) [Driver_USART1]
|
||||
// Configuration settings for Driver_USART1 in component ::Drivers:USART
|
||||
#define RTE_UART1_CTS_PIN_EN 0
|
||||
#define RTE_UART1_RTS_PIN_EN 0
|
||||
|
||||
// { PAD_PIN31}, // 0 : gpio16 / 1 : UART1 RTS
|
||||
// { PAD_PIN32}, // 0 : gpio17 / 1 : UART1 CTS
|
||||
// { PAD_PIN33}, // 0 : gpio18 / 1 : UART1 RXD
|
||||
// { PAD_PIN34}, // 0 : gpio19 / 1 : UART1 TXD
|
||||
#define RTE_UART1_RTS_BIT 31
|
||||
#define RTE_UART1_RTS_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_UART1_CTS_BIT 32
|
||||
#define RTE_UART1_CTS_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_UART1_RX_BIT 33
|
||||
#define RTE_UART1_RX_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_UART1_TX_BIT 34
|
||||
#define RTE_UART1_TX_FUNC PAD_MUX_ALT1
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART1_DMA_TX_REQID DMA_REQUEST_USART1_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART1_DMA_RX_REQID DMA_REQUEST_USART1_RX
|
||||
|
||||
// UART2 (Universal asynchronous receiver transmitter) [Driver_USART2]
|
||||
// Configuration settings for Driver_USART2 in component ::Drivers:USART
|
||||
#define RTE_UART2_CTS_PIN_EN 0
|
||||
#define RTE_UART2_RTS_PIN_EN 0
|
||||
|
||||
// { PAD_PIN25}, // 0 : gpio10 / 3 : UART2 RXD
|
||||
// { PAD_PIN26}, // 0 : gpio11 / 3 : UART2 TXD
|
||||
#define RTE_UART2_RX_BIT 25
|
||||
#define RTE_UART2_RX_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_UART2_TX_BIT 26
|
||||
#define RTE_UART2_TX_FUNC PAD_MUX_ALT3
|
||||
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART2_DMA_TX_REQID DMA_REQUEST_USART2_TX
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_UART2_DMA_RX_REQID DMA_REQUEST_USART2_RX
|
||||
|
||||
// SPI0 (Serial Peripheral Interface) [Driver_SPI0]
|
||||
// Configuration settings for Driver_SPI0 in component ::Drivers:SPI
|
||||
#define RTE_SPI0 1
|
||||
|
||||
// { PAD_PIN23}, // 0 : gpio8 / 1 : SPI0 SSn
|
||||
// { PAD_PIN24}, // 0 : gpio9 / 1 : SPI0 MOSI
|
||||
// { PAD_PIN25}, // 0 : gpio10 / 1 : SPI0 MISO
|
||||
// { PAD_PIN26}, // 0 : gpio11 / 1 : SPI0 SCLK
|
||||
#define RTE_SPI0_SSN_BIT 0xFF
|
||||
#define RTE_SPI0_SSN_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI0_MOSI_BIT 24
|
||||
#define RTE_SPI0_MOSI_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI0_MISO_BIT 25
|
||||
#define RTE_SPI0_MISO_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI0_SCLK_BIT 26
|
||||
#define RTE_SPI0_SCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI0_SSN_GPIO_INSTANCE 0
|
||||
#define RTE_SPI0_SSN_GPIO_INDEX 8
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_SPI0_DMA_TX_REQID DMA_REQUEST_SPI0_TX
|
||||
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_SPI0_DMA_RX_REQID DMA_REQUEST_SPI0_RX
|
||||
|
||||
// SPI1 (Serial Peripheral Interface) [Driver_SPI1]
|
||||
// Configuration settings for Driver_SPI1 in component ::Drivers:SPI
|
||||
#define RTE_SPI1 0
|
||||
|
||||
// { PAD_PIN27}, // 0 : gpio12 / 1 : SPI1 SSn
|
||||
// { PAD_PIN28}, // 0 : gpio13 / 1 : SPI1 MOSI
|
||||
// { PAD_PIN29}, // 0 : gpio14 / 1 : SPI1 MISO
|
||||
// { PAD_PIN30}, // 0 : gpio15 / 1 : SPI1 SCLK
|
||||
// { PAD_PIN31}, // 0 : gpio16 / 4 : SPI1 SSn1
|
||||
#define RTE_SPI1_SSN_BIT 27
|
||||
#define RTE_SPI1_SSN_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI1_MOSI_BIT 28
|
||||
#define RTE_SPI1_MOSI_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI1_MISO_BIT 29
|
||||
#define RTE_SPI1_MISO_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI1_SCLK_BIT 30
|
||||
#define RTE_SPI1_SCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_SPI1_SSN_GPIO_INSTANCE 0
|
||||
#define RTE_SPI1_SSN_GPIO_INDEX 12
|
||||
|
||||
#define RTE_SPI1_SSN1_BIT 31
|
||||
#define RTE_SPI1_SSN1_FUNC PAD_MUX_ALT4
|
||||
|
||||
// DMA
|
||||
// Tx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_SPI1_DMA_TX_REQID DMA_REQUEST_SPI1_TX
|
||||
|
||||
// Rx
|
||||
// Channel <0=>0 <1=>1 <2=>2 <3=>3 <4=>4 <5=>5 <6=>6 <7=>7
|
||||
#define RTE_SPI1_DMA_RX_REQID DMA_REQUEST_SPI1_RX
|
||||
|
||||
|
||||
// PWM0 Controller [Driver_PWM0]
|
||||
// Configuration settings for Driver_PWM0 in component ::Drivers:PWM
|
||||
#define RTE_PWM 1
|
||||
|
||||
/*+ PWM 配置 */
|
||||
// 对应的pad 需要查文档:
|
||||
// https://cdn.openluat-luatcommunity.openluat.com/attachment/20221111180133218_Air780E&Air600E_GPIO_table_1110.pdf
|
||||
// TODO 改成用 GPIO_ToPadEC618 ?
|
||||
|
||||
// GPIO 23
|
||||
#define RTE_PWM0 43
|
||||
// GPIO 24
|
||||
#define RTE_PWM1 44
|
||||
// GPIO 25
|
||||
#define RTE_PWM2 45
|
||||
// GPIO 26
|
||||
// #define RTE_PWM3 46
|
||||
// GPIO 27
|
||||
#define RTE_PWM4 47
|
||||
// GPIO 28
|
||||
// #define RTE_PWM5 48
|
||||
|
||||
#define RTE_PWM_FUNC PAD_MUX_ALT5
|
||||
|
||||
/*- PWM 配置 */
|
||||
|
||||
#define EFUSE_INIT_MODE POLLING_MODE
|
||||
#define L2CTLS_INIT_MODE POLLING_MODE
|
||||
|
||||
#define FLASH_BARE_RW_MODE 1
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define RTE_UART0 1
|
||||
#define RTE_UART1 1
|
||||
#define RTE_UART2 1
|
||||
/* to enable external thermal */
|
||||
#define EXTERNAL_NTC_EXIST 0
|
||||
|
||||
|
||||
#if (RTE_UART1 == 1)
|
||||
#define UART1_DTR_PAD_INDEX 26 // GPIO11
|
||||
#define UART1_DTR_GPIO_INSTANCE 0
|
||||
#define UART1_DTR_GPIO_PIN 11
|
||||
|
||||
#define UART1_RI_PAD_INDEX 44 // AONIO 4 = GPIO24
|
||||
#define UART1_RI_GPIO_INSTANCE 1
|
||||
#define UART1_RI_GPIO_PIN 8
|
||||
#define UART1_RI_PWM_INSTANCE 1
|
||||
#define UART1_RI_PWM_CLK_ID FCLK_TIMER1
|
||||
#define UART1_RI_PWM_CLK_SEL FCLK_TIMER1_SEL_26M
|
||||
|
||||
#define UART1_DCD_PAD_INDEX 45 // AONIO 5 = GPIO25
|
||||
#define UART1_DCD_GPIO_INSTANCE 1
|
||||
#define UART1_DCD_GPIO_PIN 9
|
||||
#endif
|
||||
|
||||
#if (RTE_UART2 == 1)
|
||||
#define UART2_DTR_PAD_INDEX 25 // GPIO10
|
||||
#define UART2_DTR_GPIO_INSTANCE 0
|
||||
#define UART2_DTR_GPIO_PIN 10
|
||||
|
||||
#define UART2_RI_PAD_INDEX 43 // AONIO 3 = GPIO23
|
||||
#define UART2_RI_GPIO_INSTANCE 1
|
||||
#define UART2_RI_GPIO_PIN 7
|
||||
#define UART2_RI_PWM_INSTANCE 0
|
||||
#define UART2_RI_PWM_CLK_ID FCLK_TIMER0
|
||||
#define UART2_RI_PWM_CLK_SEL FCLK_TIMER0_SEL_26M
|
||||
|
||||
#define UART2_DCD_PAD_INDEX 47 // AONIO 7 = GPIO27
|
||||
#define UART2_DCD_GPIO_INSTANCE 1
|
||||
#define UART2_DCD_GPIO_PIN 11
|
||||
#endif
|
||||
|
||||
|
||||
#define NETLIGHT_PAD_INDEX 46 // AONIO 6 = GPIO26
|
||||
#define NETLIGHT_PAD_ALT_FUNC PAD_MUX_ALT5
|
||||
#define NETLIGHT_PWM_INSTANCE 3
|
||||
|
||||
//USIM1 OPTION1
|
||||
#define USIM1_URST_OP1_PAD_INDEX 19 // GPIO4
|
||||
#define USIM1_URST_OP1_GPIO_INSTANCE 0
|
||||
#define USIM1_URST_OP1_GPIO_PIN 4
|
||||
#define USIM1_UCLK_OP1_PAD_INDEX 20 // GPIO5
|
||||
#define USIM1_UCLK_OP1_GPIO_INSTANCE 0
|
||||
#define USIM1_UCLK_OP1_GPIO_PIN 5
|
||||
#define USIM1_UIO_OP1_PAD_INDEX 21 // GPIO6
|
||||
#define USIM1_UIO_OP1_GPIO_INSTANCE 0
|
||||
#define USIM1_UIO_OP1_GPIO_PIN 6
|
||||
|
||||
//USIM1 OPTION2
|
||||
#define USIM1_UIO_OP2_PAD_INDEX 27 // GPIO12
|
||||
#define USIM1_UIO_OP2_GPIO_INSTANCE 0
|
||||
#define USIM1_UIO_OP2_GPIO_PIN 12
|
||||
#define USIM1_URST_OP2_PAD_INDEX 28 // GPIO13
|
||||
#define USIM1_URST_OP2_GPIO_INSTANCE 0
|
||||
#define USIM1_URST_OP2_GPIO_PIN 13
|
||||
#define USIM1_UCLK_OP2_PAD_INDEX 29 // GPIO14
|
||||
#define USIM1_UCLK_OP2_GPIO_INSTANCE 0
|
||||
#define USIM1_UCLK_OP2_GPIO_PIN 14
|
||||
|
||||
//USIM1 clock latched by AONIO, for example, use AONIO-6 test on EVB
|
||||
#define AONIO_6_PAD_INDEX 46 // AONIO 6 = GPIO26
|
||||
#define AONIO_6_GPIO_INSTANCE 1
|
||||
#define AONIO_6_GPIO_PIN 10
|
||||
|
||||
#define RTE_CSPI0 0
|
||||
|
||||
#define RTE_CSPI0_MCLK_PAD_ADDR 39
|
||||
#define RTE_CSPI0_MCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI0_PCLK_PAD_ADDR 35
|
||||
#define RTE_CSPI0_PCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI0_CS_PAD_ADDR 36
|
||||
#define RTE_CSPI0_CS_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI0_SDO0_PAD_ADDR 37
|
||||
#define RTE_CSPI0_SDO0_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI0_SDO1_PAD_ADDR 38
|
||||
#define RTE_CSPI0_SDO1_FUNC PAD_MUX_ALT1
|
||||
|
||||
// DMA CSPI0 Request ID
|
||||
#define RTE_CSPI0_DMA_RX_REQID DMA_REQUEST_I2S0_RX
|
||||
|
||||
// CSPI1 Configuration
|
||||
#define RTE_CSPI1 1
|
||||
|
||||
#define RTE_CSPI1_MCLK_PAD_ADDR 18
|
||||
#define RTE_CSPI1_MCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI1_PCLK_PAD_ADDR 19
|
||||
#define RTE_CSPI1_PCLK_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI1_CS_PAD_ADDR 20
|
||||
#define RTE_CSPI1_CS_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI1_SDO0_PAD_ADDR 21
|
||||
#define RTE_CSPI1_SDO0_FUNC PAD_MUX_ALT1
|
||||
|
||||
#define RTE_CSPI1_SDO1_PAD_ADDR 22
|
||||
#define RTE_CSPI1_SDO1_FUNC PAD_MUX_ALT1
|
||||
|
||||
// DMA CSPI1 Request ID
|
||||
#define RTE_CSPI1_DMA_RX_REQID DMA_REQUEST_I2S1_RX
|
||||
|
||||
#endif /* __RTE_DEVICE_H */
|
||||
@@ -0,0 +1,242 @@
|
||||
|
||||
#ifndef LUAT_CONF_BSP
|
||||
#define LUAT_CONF_BSP
|
||||
|
||||
#define LUAT_BSP_VERSION "V1003"
|
||||
|
||||
// 启用64位虚拟机
|
||||
// #define LUAT_CONF_VM_64bit
|
||||
|
||||
//-----------------------------
|
||||
// 内存配置, 默认200k, 128 ~ 300k 可调
|
||||
// 一般无需修改. 若不需要使用SSL/TLS/TTS,可适当增加,但不应该超过300k
|
||||
//#define LUAT_HEAP_SIZE (200*1024)
|
||||
//-----------------------------
|
||||
|
||||
//------------------------------------------------------
|
||||
// 以下custom --> 到 <-- custom 之间的内容,是供用户配置的
|
||||
// 同时也是云编译可配置的部分. 提交代码时切勿删除会修改标识
|
||||
//custom -->
|
||||
//------------------------------------------------------
|
||||
|
||||
// 外设,按需启用, 最起码启用uart和wdt库
|
||||
#define LUAT_USE_UART 1
|
||||
#define LUAT_USE_GPIO 1
|
||||
#define LUAT_USE_I2C 1
|
||||
#define LUAT_USE_SPI 1
|
||||
#define LUAT_USE_ADC 1
|
||||
#define LUAT_USE_PWM 1
|
||||
#define LUAT_USE_WDT 1
|
||||
#define LUAT_USE_PM 1
|
||||
#define LUAT_USE_MCU 1
|
||||
#define LUAT_USE_RTC 1
|
||||
#define LUAT_USE_OTP 1
|
||||
|
||||
#define LUAT_USE_HMETA 1
|
||||
|
||||
#define LUAT_USE_IOTAUTH 1
|
||||
#define LUAT_USE_WEBSOCKET 1
|
||||
|
||||
//----------------------------
|
||||
// 常用工具库, 按需启用, cjson和pack是强烈推荐启用的
|
||||
#define LUAT_USE_CRYPTO 1
|
||||
#define LUAT_USE_CJSON 1
|
||||
#define LUAT_USE_ZBUFF 1
|
||||
#define LUAT_USE_PACK 1
|
||||
#define LUAT_USE_LIBGNSS 1
|
||||
#define LUAT_USE_FS 1
|
||||
#define LUAT_USE_SENSOR 1
|
||||
#define LUAT_USE_SFUD 1
|
||||
// #define LUAT_USE_SFD 1
|
||||
// #define LUAT_USE_STATEM 1
|
||||
// 性能测试
|
||||
//#define LUAT_USE_COREMARK 1
|
||||
#define LUAT_USE_IR 1
|
||||
// FDB 提供kv数据库, 与nvm库类似
|
||||
#define LUAT_USE_FDB 1
|
||||
// fskv提供与fdb兼容的API,旨在替代fdb库
|
||||
#define LUAT_USE_FSKV 1
|
||||
#define LUAT_USE_I2CTOOLS 1
|
||||
#define LUAT_USE_LORA 1
|
||||
// #define LUAT_USE_MLX90640 1
|
||||
// zlib压缩,更快更小的实现
|
||||
#define LUAT_USE_MINIZ 1
|
||||
#define LUAT_USE_SNTP 1
|
||||
#define LUAT_USE_FTP 1
|
||||
|
||||
#define LUAT_USE_WLAN 1
|
||||
#define LUAT_USE_WLAN_SCANONLY 1
|
||||
|
||||
//---------------SDIO-FATFS特别配置
|
||||
// sdio库对接的是fatfs
|
||||
// fatfs的长文件名和非英文文件名支持需要180k的ROM, 非常奢侈
|
||||
// #define LUAT_USE_FATFS
|
||||
// #define FF_USE_LFN 3
|
||||
// #define FF_LFN_UNICODE 3
|
||||
|
||||
#define LUAT_USE_PROFILER 1
|
||||
|
||||
//----------------------------
|
||||
// 高通字体, 需配合芯片使用
|
||||
#define LUAT_USE_GTFONT 1
|
||||
// #define LUAT_USE_GTFONT_UTF8
|
||||
|
||||
//----------------------------
|
||||
// 高级功能, 其中shell是推荐启用, 除非你打算uart0也读数据
|
||||
// #define LUAT_USE_SHELL 1
|
||||
// #define LUAT_USE_DBG
|
||||
// 多虚拟机支持,实验性,一般不启用
|
||||
// #define LUAT_USE_VMX 1
|
||||
#define LUAT_USE_PROTOBUF 1
|
||||
|
||||
#define LUAT_USE_RSA 1
|
||||
#define LUAT_USE_MEDIA 1
|
||||
// #define LUAT_USE_TTS 1
|
||||
//---------------------
|
||||
// UI
|
||||
// LCD 是彩屏, 若使用LVGL就必须启用LCD
|
||||
#define LUAT_USE_LCD
|
||||
#define LUAT_USE_TJPGD
|
||||
// EINK 是墨水屏
|
||||
#define LUAT_USE_EINK
|
||||
|
||||
//---------------------
|
||||
// U8G2
|
||||
// 单色屏, 支持i2c/spi
|
||||
// #define LUAT_USE_DISP
|
||||
#define LUAT_USE_U8G2
|
||||
|
||||
/**************FONT*****************/
|
||||
#define LUAT_USE_FONTS
|
||||
/**********U8G2&LCD&EINK FONT*************/
|
||||
#define USE_U8G2_OPPOSANSM_ENGLISH 1
|
||||
// #define USE_U8G2_OPPOSANSM8_CHINESE
|
||||
// #define USE_U8G2_OPPOSANSM10_CHINESE
|
||||
// #define USE_U8G2_OPPOSANSM12_CHINESE
|
||||
// #define USE_U8G2_OPPOSANSM16_CHINESE
|
||||
// #define USE_U8G2_OPPOSANSM24_CHINESE
|
||||
// #define USE_U8G2_OPPOSANSM32_CHINESE
|
||||
/**********LVGL FONT*************/
|
||||
// #define LV_FONT_OPPOSANS_M_8
|
||||
// #define LV_FONT_OPPOSANS_M_10
|
||||
// #define LV_FONT_OPPOSANS_M_12
|
||||
// #define LV_FONT_OPPOSANS_M_16
|
||||
|
||||
//---------------------
|
||||
// LVGL
|
||||
// 主推的UI库, 功能强大但API繁琐
|
||||
//#define LUAT_USE_LVGL
|
||||
|
||||
#define LUAT_USE_LVGL_ARC //圆弧 无依赖
|
||||
#define LUAT_USE_LVGL_BAR //进度条 无依赖
|
||||
#define LUAT_USE_LVGL_BTN //按钮 依赖容器CONT
|
||||
#define LUAT_USE_LVGL_BTNMATRIX //按钮矩阵 无依赖
|
||||
#define LUAT_USE_LVGL_CALENDAR //日历 无依赖
|
||||
#define LUAT_USE_LVGL_CANVAS //画布 依赖图片IMG
|
||||
#define LUAT_USE_LVGL_CHECKBOX //复选框 依赖按钮BTN 标签LABEL
|
||||
#define LUAT_USE_LVGL_CHART //图表 无依赖
|
||||
#define LUAT_USE_LVGL_CONT //容器 无依赖
|
||||
#define LUAT_USE_LVGL_CPICKER //颜色选择器 无依赖
|
||||
#define LUAT_USE_LVGL_DROPDOWN //下拉列表 依赖页面PAGE 标签LABEL
|
||||
#define LUAT_USE_LVGL_GAUGE //仪表 依赖进度条BAR 仪表(弧形刻度)LINEMETER
|
||||
#define LUAT_USE_LVGL_IMG //图片 依赖标签LABEL
|
||||
#define LUAT_USE_LVGL_IMGBTN //图片按钮 依赖按钮BTN
|
||||
#define LUAT_USE_LVGL_KEYBOARD //键盘 依赖图片按钮IMGBTN
|
||||
#define LUAT_USE_LVGL_LABEL //标签 无依赖
|
||||
#define LUAT_USE_LVGL_LED //LED 无依赖
|
||||
#define LUAT_USE_LVGL_LINE //线 无依赖
|
||||
#define LUAT_USE_LVGL_LIST //列表 依赖页面PAGE 按钮BTN 标签LABEL
|
||||
#define LUAT_USE_LVGL_LINEMETER //仪表(弧形刻度) 无依赖
|
||||
#define LUAT_USE_LVGL_OBJMASK //对象蒙版 无依赖
|
||||
#define LUAT_USE_LVGL_MSGBOX //消息框 依赖图片按钮IMGBTN 标签LABEL
|
||||
#define LUAT_USE_LVGL_PAGE //页面 依赖容器CONT
|
||||
#define LUAT_USE_LVGL_SPINNER //旋转器 依赖圆弧ARC 动画ANIM
|
||||
#define LUAT_USE_LVGL_ROLLER //滚筒 无依赖
|
||||
#define LUAT_USE_LVGL_SLIDER //滑杆 依赖进度条BAR
|
||||
#define LUAT_USE_LVGL_SPINBOX //数字调整框 无依赖
|
||||
#define LUAT_USE_LVGL_SWITCH //开关 依赖滑杆SLIDER
|
||||
#define LUAT_USE_LVGL_TEXTAREA //文本框 依赖标签LABEL 页面PAGE
|
||||
#define LUAT_USE_LVGL_TABLE //表格 依赖标签LABEL
|
||||
#define LUAT_USE_LVGL_TABVIEW //页签 依赖页面PAGE 图片按钮IMGBTN
|
||||
#define LUAT_USE_LVGL_TILEVIEW //平铺视图 依赖页面PAGE
|
||||
#define LUAT_USE_LVGL_WIN //窗口 依赖容器CONT 按钮BTN 标签LABEL 图片IMG 页面PAGE
|
||||
|
||||
//-------------------------------------------------------------------------------
|
||||
//<-- custom
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// 以下选项仅开发人员可修改, 一般用户切勿自行修改
|
||||
|
||||
#define LUAT_COMPILER_NOWEAK
|
||||
#define LUAT_GPIO_PIN_MAX 36
|
||||
|
||||
// 内存优化: 减少内存消耗, 会稍微减低性能
|
||||
#define LUAT_USE_MEMORY_OPTIMIZATION_CODE_MMAP 1
|
||||
|
||||
//----------------------------------
|
||||
// 使用VFS(虚拟文件系统)和内置库文件, 必须启用
|
||||
#define LUAT_USE_FS_VFS 1
|
||||
#define LUAT_USE_VFS_INLINE_LIB 1
|
||||
#define LUA_USE_VFS_FILENAME_OFFSET 1
|
||||
//----------------------------------
|
||||
|
||||
#define LV_DISP_DEF_REFR_PERIOD 30
|
||||
#define LUAT_LV_DEBUG 0
|
||||
|
||||
#define LV_MEM_CUSTOM 1
|
||||
|
||||
#define LUAT_USE_LVGL_INDEV 1 // 输入设备
|
||||
|
||||
#define LV_HOR_RES_MAX (160)
|
||||
#define LV_VER_RES_MAX (80)
|
||||
#define LV_COLOR_DEPTH 16
|
||||
|
||||
#define LV_COLOR_16_SWAP 1
|
||||
#define __LVGL_SLEEP_ENABLE__
|
||||
|
||||
#undef LV_DISP_DEF_REFR_PERIOD
|
||||
#define LV_DISP_DEF_REFR_PERIOD g_lvgl_flash_time
|
||||
extern unsigned int g_lvgl_flash_time;
|
||||
|
||||
#define LV_TICK_CUSTOM 1
|
||||
#define LV_TICK_CUSTOM_INCLUDE "common_api.h" /*Header for the system time function*/
|
||||
#define LV_TICK_CUSTOM_SYS_TIME_EXPR ((uint32_t)GetSysTickMS()) /*Expression evaluating to current system time in ms*/
|
||||
|
||||
#define LUAT_LOG_NO_NEWLINE
|
||||
#define __LUATOS_TICK_64BIT__
|
||||
|
||||
#define LUAT_RET int
|
||||
#define LUAT_RT_RET_TYPE void
|
||||
#define LUAT_RT_CB_PARAM void *param
|
||||
|
||||
#define time(X) luat_time(X)
|
||||
|
||||
#define LUAT_USE_NETWORK 1
|
||||
#define LUAT_USE_TLS 1
|
||||
#define LUAT_USE_LWIP 1
|
||||
#define LUAT_USE_DNS 1
|
||||
#define LUAT_USE_ERR_DUMP 1
|
||||
#define LUAT_USE_DHCP 1
|
||||
#define LUAT_USE_ERRDUMP 1
|
||||
#define LUAT_USE_FOTA 1
|
||||
|
||||
//目前没用到的宏,但是得写在这里
|
||||
//#define LUAT_USE_MOBILE
|
||||
|
||||
#define LUA_SCRIPT_ADDR (FLASH_FOTA_REGION_START - 732 * 1024)
|
||||
#define LUA_SCRIPT_OTA_ADDR (FLASH_FOTA_REGION_START - 284 * 1024)
|
||||
|
||||
#ifdef LUAT_USE_TTS
|
||||
#undef LUAT_USE_SFUD
|
||||
#define LUAT_USE_SFUD 1
|
||||
#undef LUAT_USE_LCD
|
||||
#undef LUAT_USE_TJPGD
|
||||
#undef LUAT_USE_LORA
|
||||
#undef LUAT_USE_IR
|
||||
#undef USE_U8G2_OPPOSANSM_ENGLISH
|
||||
#undef LUAT_USE_EINK
|
||||
#define LUAT_USE_TTS_16K 1
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright (c) 2022 OpenLuat & AirM2M
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef __LUAT_I2S_EC618_H__
|
||||
#define __LUAT_I2S_EC618_H__
|
||||
#include "common_api.h"
|
||||
void luat_i2s_init(void);
|
||||
int luat_i2s_start(uint8_t bus_id, uint8_t is_play, uint32_t sample, uint8_t channel_num);
|
||||
void luat_i2s_base_setup(uint8_t bus_id, uint8_t mode, uint8_t frame_size);
|
||||
void luat_i2s_no_block_tx(uint8_t bus_id, uint8_t* address, uint32_t byte_len, CBFuncEx_t cb, void *param);
|
||||
void luat_i2s_no_block_rx(uint8_t bus_id, uint32_t byte_len, CBFuncEx_t cb, void *param);
|
||||
void luat_i2s_tx_stop(uint8_t bus_id);
|
||||
void luat_i2s_rx_stop(uint8_t bus_id);
|
||||
void luat_i2s_deinit(uint8_t bus_id);
|
||||
void luat_i2s_pause(uint8_t bus_id);
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,69 @@
|
||||
[config]
|
||||
line_0_com = COM46
|
||||
agbaud=921600
|
||||
|
||||
;filter com config
|
||||
filter_embedusb=0
|
||||
filter_externcom=0
|
||||
|
||||
[package_info]
|
||||
pkgflag = 1
|
||||
pkg_extract_exe = .\fcelf.exe
|
||||
arg_pkg_path_val =.\luatos.binpkg
|
||||
|
||||
|
||||
;agentboot.bin file infomation
|
||||
[agentboot]
|
||||
tool_basedir = 1
|
||||
agpath =.\agentboot_usb.bin
|
||||
|
||||
[storage_cfg]
|
||||
opt_storage_list="cp_flash"
|
||||
format_path=format_ec618.json
|
||||
|
||||
;bootloader.bin file infomation
|
||||
[bootloader]
|
||||
blpath = .\image_ec618\ap_bootloader.bin
|
||||
blloadskip = 0
|
||||
|
||||
;system.bin file infomation
|
||||
[system]
|
||||
syspath =.\image_ec618\ap_demo-flash.bin
|
||||
sysloadskip = 0
|
||||
burnaddr = 0x24000
|
||||
|
||||
[cp_system]
|
||||
cp_syspath = .\image_ec618\cp-demo-flash.bin
|
||||
cp_sysloadskip = 0
|
||||
|
||||
;control such as reset before download
|
||||
[control]
|
||||
;detect = 1
|
||||
;reset = 2
|
||||
;atreset=at+ecrst=delay,500
|
||||
;atbaud=115200
|
||||
|
||||
prempt_detect_time = 6
|
||||
msg_waittime = 2
|
||||
max_preamble_cnt = 8
|
||||
lpc_recover_en = 0
|
||||
;cfg reset to 2, skip reset pin
|
||||
pullup_qspi =1
|
||||
rom_version= 0000000102000000
|
||||
|
||||
[flexfile0]
|
||||
filepath = .\MergeRfTable_ec618.bin
|
||||
burnaddr = 0xe7000
|
||||
storage_type=cp_flash
|
||||
|
||||
|
||||
[flexfile1]
|
||||
filepath = .\MergeRfTable_ec618.bin
|
||||
burnaddr = 0xce000
|
||||
storage_type=cp_flash
|
||||
|
||||
|
||||
[flexfile2]
|
||||
filepath = .\script.bin
|
||||
burnaddr = 0x24D000
|
||||
storage_type=ap_flash
|
||||
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"fs": {
|
||||
"begin":"0xb84000",
|
||||
"length":"294912"
|
||||
},
|
||||
"fraw": {
|
||||
"begin":"0xbfc000",
|
||||
"length":"4096"
|
||||
},
|
||||
"rr": {
|
||||
"begin":"0x88e7000",
|
||||
"length":"102400"
|
||||
},
|
||||
"drr": {
|
||||
"begin":"0x88ce000",
|
||||
"length":"102400"
|
||||
},
|
||||
"hfd": {
|
||||
"begin":"0x8864000",
|
||||
"length":"430080"
|
||||
},
|
||||
"opt": {
|
||||
"begin":"0x2E4000",
|
||||
"length":"0x00020000"
|
||||
},
|
||||
"cal":[
|
||||
{
|
||||
"stor_type": "cp_flash",
|
||||
"offst_flag": "1",
|
||||
"begin":"0xe7000",
|
||||
"length":"0x19000"
|
||||
}
|
||||
],
|
||||
"erallum":[
|
||||
{
|
||||
"stor_type": "ap_flash",
|
||||
"offst_flag": "1",
|
||||
"begin":"0x0",
|
||||
"length":"0x3cc000"
|
||||
},
|
||||
{
|
||||
"stor_type": "ap_flash",
|
||||
"offst_flag": "1",
|
||||
"begin":"0x3e4000",
|
||||
"length":"0x1c000"
|
||||
},
|
||||
{
|
||||
"stor_type": "cp_flash",
|
||||
"offst_flag": "1",
|
||||
"begin":"0x0",
|
||||
"length":"0xcd000"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
{
|
||||
"version" : 1,
|
||||
"chip" : {
|
||||
"type" : "ec618",
|
||||
"ram" : {
|
||||
"total" : 384,
|
||||
"sys" : 256,
|
||||
"lua" : 128
|
||||
}
|
||||
},
|
||||
"rom": {
|
||||
"file" : "luatos.binpkg",
|
||||
"fs" : {
|
||||
"script" : {
|
||||
"offset" : "0",
|
||||
"size" : 448,
|
||||
"type": "luadb"
|
||||
}
|
||||
},
|
||||
"version-core": "v0001",
|
||||
"version-bsp" : "v0001",
|
||||
"mark" : "default",
|
||||
"build" : {
|
||||
"build_at" : "",
|
||||
"build_by" : "",
|
||||
"build_host" : "",
|
||||
"build_system" : ""
|
||||
}
|
||||
},
|
||||
"script" : {
|
||||
"file" : "script.bin",
|
||||
"lua" : "5.3",
|
||||
"bitw" : 32,
|
||||
"use-luac" : true,
|
||||
"use-debug" : true
|
||||
},
|
||||
"fs" : {
|
||||
"total_len" : 288,
|
||||
"format_len" : "1000"
|
||||
},
|
||||
"user" : {
|
||||
"project" : "",
|
||||
"version" : "",
|
||||
"log_br" : "921600"
|
||||
},
|
||||
"download" : {
|
||||
"bl_addr" : "00004000",
|
||||
"partition_addr" : "00008000",
|
||||
"core_addr" : "00024000",
|
||||
"app_addr" : "00000000",
|
||||
"script_addr" : "0024D000",
|
||||
"nvm_addr" : "00000000",
|
||||
"fs_addr" : "003B0000",
|
||||
"force_br" : "1152000",
|
||||
"extra_param" : "002f0200"
|
||||
},
|
||||
"fota" : {
|
||||
"magic_num" : "eaf18c16",
|
||||
"block_len" : "40000",
|
||||
"core_type" : "diff",
|
||||
"ap_type" : "diff",
|
||||
"cp_type" : "diff",
|
||||
"full_addr" : "002BD000"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
[loggers]
|
||||
keys=root
|
||||
|
||||
[handlers]
|
||||
keys=stream_handler,file_handler
|
||||
|
||||
[formatters]
|
||||
keys=formatter
|
||||
|
||||
[logger_root]
|
||||
level=DEBUG
|
||||
handlers=stream_handler,file_handler
|
||||
;handlers=file_handler
|
||||
|
||||
[handler_stream_handler]
|
||||
class=StreamHandler
|
||||
level=DEBUG
|
||||
formatter=formatter
|
||||
args=(sys.stderr,)
|
||||
|
||||
[handler_file_handler]
|
||||
class=FileHandler
|
||||
level=DEBUG
|
||||
formatter=formatter
|
||||
args=('logging_output.log', 'a', None, True)
|
||||
|
||||
[formatter_formatter]
|
||||
format=%(asctime)s %(levelname)-8s %(message)s
|
||||
;format=%(asctime)s %(levelname)-8s %(funcName)s %(lineno)s %(message)s
|
||||
|
||||
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
* Copyright (c) 2022 OpenLuat & AirM2M
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
#include "bsp_common.h"
|
||||
#include "luat_audio.h"
|
||||
#include "luat_i2s.h"
|
||||
#include "common_api.h"
|
||||
#include "audio_play.h"
|
||||
#include "driver_gpio.h"
|
||||
#include "luat_msgbus.h"
|
||||
#include "driver_gpio.h"
|
||||
#include "soc_spi.h"
|
||||
#include "ivTTSSDKID_all.h"
|
||||
#include "ivTTS.h"
|
||||
#include "luat_spi.h"
|
||||
#include "sfud.h"
|
||||
#include "luat_rtos.h"
|
||||
#include "luat_gpio.h"
|
||||
//#include "luat_multimedia.h"
|
||||
typedef struct
|
||||
{
|
||||
uint32_t dac_delay_len;
|
||||
uint32_t pa_delay_time;
|
||||
HANDLE pa_delay_timer;
|
||||
int pa_pin;
|
||||
int dac_pin;
|
||||
uint16_t vol;
|
||||
uint8_t pa_on_level;
|
||||
uint8_t dac_on_level;
|
||||
uint8_t raw_mode;
|
||||
}luat_audio_hardware_t;
|
||||
|
||||
static luat_audio_hardware_t g_s_audio_hardware;
|
||||
|
||||
extern int l_multimedia_raw_handler(lua_State *L, void* ptr);
|
||||
//extern void audio_play_file_default_fun(void *param);
|
||||
//extern void audio_play_TTS_default_fun(void *param);
|
||||
//extern void audio_play_tts_set_resource_ex(void *address, void *sdk_id, void *read_resource_fun);
|
||||
//extern void audio_play_global_init_ex(audio_play_event_cb_fun_t event_cb, audio_play_data_cb_fun_t data_cb, audio_play_default_fun_t play_file_fun, audio_play_default_fun_t play_tts_fun, void *user_param);
|
||||
//extern int audio_play_write_blank_raw_ex(uint8_t multimedia_id, uint8_t cnt, uint8_t add_font);
|
||||
|
||||
static void app_pa_on(uint32_t arg)
|
||||
{
|
||||
luat_gpio_set(g_s_audio_hardware.pa_pin, g_s_audio_hardware.pa_on_level);
|
||||
}
|
||||
|
||||
static void audio_event_cb(uint32_t event, void *param)
|
||||
{
|
||||
//DBG("%d", event);
|
||||
rtos_msg_t msg = {0};
|
||||
switch(event)
|
||||
{
|
||||
case MULTIMEDIA_CB_AUDIO_DECODE_START:
|
||||
luat_gpio_set(g_s_audio_hardware.dac_pin, g_s_audio_hardware.dac_on_level);
|
||||
audio_play_write_blank_raw_ex(0, g_s_audio_hardware.dac_delay_len, 1);
|
||||
break;
|
||||
case MULTIMEDIA_CB_AUDIO_OUTPUT_START:
|
||||
luat_rtos_timer_start(g_s_audio_hardware.pa_delay_timer, g_s_audio_hardware.pa_delay_time, 0, app_pa_on, NULL);
|
||||
break;
|
||||
case MULTIMEDIA_CB_AUDIO_NEED_DATA:
|
||||
if (g_s_audio_hardware.raw_mode)
|
||||
{
|
||||
msg.handler = l_multimedia_raw_handler;
|
||||
msg.arg1 = MULTIMEDIA_CB_AUDIO_NEED_DATA;
|
||||
msg.arg2 = (int)param;
|
||||
luat_msgbus_put(&msg, 1);
|
||||
}
|
||||
break;
|
||||
case MULTIMEDIA_CB_TTS_INIT:
|
||||
break;
|
||||
case MULTIMEDIA_CB_TTS_DONE:
|
||||
if (!audio_play_get_last_error(0))
|
||||
{
|
||||
audio_play_write_blank_raw_ex(0, 1, 0);
|
||||
}
|
||||
break;
|
||||
case MULTIMEDIA_CB_AUDIO_DONE:
|
||||
luat_rtos_timer_stop(g_s_audio_hardware.pa_delay_timer);
|
||||
// luat_audio_play_get_last_error(0);
|
||||
luat_gpio_set(g_s_audio_hardware.pa_pin, !g_s_audio_hardware.pa_on_level);
|
||||
luat_gpio_set(g_s_audio_hardware.dac_pin, !g_s_audio_hardware.dac_on_level);
|
||||
msg.handler = l_multimedia_raw_handler;
|
||||
msg.arg1 = MULTIMEDIA_CB_AUDIO_DONE;
|
||||
msg.arg2 = (int)param;
|
||||
luat_msgbus_put(&msg, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void audio_data_cb(uint8_t *data, uint32_t len, uint8_t bits, uint8_t channels)
|
||||
{
|
||||
//这里可以对音频数据进行软件音量缩放,或者直接清空来静音
|
||||
if (g_s_audio_hardware.vol != 100)
|
||||
{
|
||||
int16_t *i16 = (int16_t *)data;
|
||||
uint32_t i = 0;
|
||||
uint32_t pos = 0;
|
||||
int32_t temp;
|
||||
while(pos < len)
|
||||
{
|
||||
temp = i16[i];
|
||||
temp = temp * g_s_audio_hardware.vol / 100;
|
||||
if (temp > 32767)
|
||||
{
|
||||
temp = 32767;
|
||||
}
|
||||
else if (temp < -32768)
|
||||
{
|
||||
temp = -32768;
|
||||
}
|
||||
i16[i] = temp;
|
||||
i++;
|
||||
pos += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef LUAT_USE_TTS
|
||||
#define FLASH_TTS_ADDR (64 * 1024)
|
||||
extern luat_sfud_flash_t luat_sfud;
|
||||
static PV_Union g_s_spi_config;
|
||||
static ivBool tts_read_data(
|
||||
ivPointer pParameter, /* [in] user callback parameter */
|
||||
ivPointer pBuffer, /* [out] read resource buffer */
|
||||
ivResAddress iPos, /* [in] read start position */
|
||||
ivResSize nSize ) /* [in] read size */
|
||||
{
|
||||
iPos += FLASH_TTS_ADDR;
|
||||
GPIO_FastOutput(g_s_spi_config.u8[1], 0);
|
||||
char cmd[4] = {0x03, iPos >> 16, (iPos >> 8) & 0xFF, iPos & 0xFF};
|
||||
SPI_FastTransfer(g_s_spi_config.u8[0], cmd, cmd, 4);
|
||||
if (nSize >= 4096) {
|
||||
SPI_BlockTransfer(g_s_spi_config.u8[0], pBuffer, pBuffer, nSize);
|
||||
}
|
||||
else {
|
||||
SPI_FastTransfer(g_s_spi_config.u8[0], pBuffer, pBuffer, nSize);
|
||||
}
|
||||
|
||||
GPIO_FastOutput(g_s_spi_config.u8[1], 1);
|
||||
// if (memcmp(buff, ivtts_16k + offset, len)) {
|
||||
// LUAT_DEBUG_PRINT("tts data NOT match %04X %04X", offset, len);
|
||||
// }
|
||||
return ivTrue;
|
||||
}
|
||||
#endif
|
||||
HANDLE soc_audio_fopen(const char *fname, const char *mode)
|
||||
{
|
||||
return luat_fs_fopen(fname, mode);
|
||||
}
|
||||
|
||||
int soc_audio_fread(void *buffer, uint32_t size, uint32_t num, void *fp)
|
||||
{
|
||||
return luat_fs_fread(buffer, size, num, fp);
|
||||
}
|
||||
|
||||
int soc_audio_fseek(void *fp, long offset, int origin)
|
||||
{
|
||||
return luat_fs_fseek(fp, offset, origin);
|
||||
}
|
||||
|
||||
int soc_audio_fclose(void *fp)
|
||||
{
|
||||
return luat_fs_fclose(fp);
|
||||
}
|
||||
|
||||
void luat_audio_global_init(void)
|
||||
{
|
||||
|
||||
#ifdef LUAT_USE_TTS
|
||||
audio_play_global_init_ex(audio_event_cb, audio_data_cb, audio_play_file_default_fun, audio_play_TTS_default_fun, NULL);
|
||||
#ifdef LUAT_USE_TTS_16K
|
||||
ivCStrA sdk_id = AISOUND_SDK_USERID_16K;
|
||||
#else
|
||||
ivCStrA sdk_id = AISOUND_SDK_USERID_8K;
|
||||
#endif
|
||||
audio_play_tts_set_resource_ex(NULL, sdk_id, tts_read_data);
|
||||
#else
|
||||
audio_play_global_init_ex(audio_event_cb, audio_data_cb, audio_play_file_default_fun, NULL, NULL);
|
||||
#endif
|
||||
g_s_audio_hardware.dac_delay_len = 6;
|
||||
g_s_audio_hardware.pa_delay_time = 200;
|
||||
g_s_audio_hardware.pa_delay_timer = luat_create_rtos_timer(app_pa_on, NULL, NULL);
|
||||
g_s_audio_hardware.vol = 100;
|
||||
g_s_audio_hardware.dac_pin = -1;
|
||||
g_s_audio_hardware.pa_pin = -1;
|
||||
}
|
||||
|
||||
int luat_audio_play_multi_files(uint8_t multimedia_id, uData_t *info, uint32_t files_num, uint8_t error_stop)
|
||||
{
|
||||
g_s_audio_hardware.raw_mode = 0;
|
||||
uint32_t i;
|
||||
audio_play_info_t play_info[files_num];
|
||||
for(i = 0; i < files_num; i++)
|
||||
{
|
||||
play_info[i].path = info[i].value.asBuffer.buffer;
|
||||
play_info[i].address = 0;
|
||||
}
|
||||
return audio_play_multi_files(multimedia_id, play_info, files_num);
|
||||
}
|
||||
|
||||
int luat_audio_play_file(uint8_t multimedia_id, const char *path)
|
||||
{
|
||||
g_s_audio_hardware.raw_mode = 0;
|
||||
audio_play_info_t play_info[1];
|
||||
play_info[0].path = path;
|
||||
play_info[0].fail_continue = 0;
|
||||
play_info[0].address = NULL;
|
||||
return audio_play_multi_files(multimedia_id, play_info, 1);
|
||||
}
|
||||
|
||||
uint8_t luat_audio_is_finish(uint8_t multimedia_id)
|
||||
{
|
||||
return audio_play_is_finish(multimedia_id);
|
||||
}
|
||||
|
||||
int luat_audio_play_stop(uint8_t multimedia_id)
|
||||
{
|
||||
return audio_play_stop(multimedia_id);
|
||||
}
|
||||
|
||||
int luat_audio_pause_raw(uint8_t multimedia_id, uint8_t is_pause)
|
||||
{
|
||||
return audio_play_pause_raw(multimedia_id, is_pause);
|
||||
}
|
||||
|
||||
int luat_audio_play_get_last_error(uint8_t multimedia_id)
|
||||
{
|
||||
return audio_play_get_last_error(multimedia_id);
|
||||
}
|
||||
|
||||
int luat_audio_start_raw(uint8_t multimedia_id, uint8_t audio_format, uint8_t num_channels, uint32_t sample_rate, uint8_t bits_per_sample, uint8_t is_signed)
|
||||
{
|
||||
return audio_play_start_raw(multimedia_id, audio_format, num_channels, sample_rate, bits_per_sample, is_signed);
|
||||
}
|
||||
|
||||
int luat_audio_write_raw(uint8_t multimedia_id, uint8_t *data, uint32_t len)
|
||||
{
|
||||
int result = audio_play_write_raw(multimedia_id, data, len);
|
||||
if (!result)
|
||||
{
|
||||
g_s_audio_hardware.raw_mode = 1;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int luat_audio_stop_raw(uint8_t multimedia_id)
|
||||
{
|
||||
return audio_play_stop_raw(multimedia_id);
|
||||
}
|
||||
|
||||
void luat_audio_config_pa(uint8_t multimedia_id, uint32_t pin, int level, uint32_t dummy_time_len, uint32_t pa_delay_time)
|
||||
{
|
||||
if (pin < HAL_GPIO_MAX)
|
||||
{
|
||||
g_s_audio_hardware.pa_pin = pin;
|
||||
g_s_audio_hardware.pa_on_level = level;
|
||||
GPIO_Config(pin, 0, !level);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(pin, 0), 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_s_audio_hardware.pa_pin = -1;
|
||||
}
|
||||
g_s_audio_hardware.dac_delay_len = dummy_time_len;
|
||||
g_s_audio_hardware.pa_delay_time = pa_delay_time;
|
||||
}
|
||||
|
||||
void luat_audio_config_dac(uint8_t multimedia_id, int pin, int level)
|
||||
{
|
||||
if (pin < 0)
|
||||
{ g_s_audio_hardware.dac_pin = HAL_GPIO_12;
|
||||
g_s_audio_hardware.dac_on_level = 1;
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(g_s_audio_hardware.dac_pin, 4), 4, 0, 0);
|
||||
GPIO_Config(g_s_audio_hardware.dac_pin, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (pin < HAL_GPIO_MAX)
|
||||
{
|
||||
g_s_audio_hardware.dac_pin = pin;
|
||||
g_s_audio_hardware.dac_on_level = level;
|
||||
GPIO_Config(pin, 0, !level);
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(g_s_audio_hardware.dac_pin, 0), 0, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
g_s_audio_hardware.dac_pin = -1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
uint16_t luat_audio_vol(uint8_t multimedia_id, uint16_t vol)
|
||||
{
|
||||
g_s_audio_hardware.vol = vol;
|
||||
return g_s_audio_hardware.vol;
|
||||
}
|
||||
|
||||
int luat_i2s_setup(luat_i2s_conf_t *conf)
|
||||
{
|
||||
luat_i2s_base_setup(0, conf->communication_format, I2S_FRAME_SIZE_16_16);
|
||||
return 0;
|
||||
}
|
||||
int luat_i2s_send(uint8_t id, char* buff, size_t len)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int luat_i2s_recv(uint8_t id, char* buff, size_t len)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int luat_i2s_close(uint8_t id)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
int l_i2s_play(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_i2s_pause(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int l_i2s_stop(lua_State *L) {
|
||||
return 0;
|
||||
}
|
||||
#ifdef LUAT_USE_TTS
|
||||
int luat_audio_play_tts_text(uint32_t multimedia_id, void *text, uint32_t text_bytes)
|
||||
{
|
||||
if (!g_s_spi_config.u32)
|
||||
{
|
||||
if (LUAT_TYPE_SPI == luat_sfud.luat_spi)
|
||||
{
|
||||
luat_spi_t *spi = (luat_spi_t *)luat_sfud.user_data;
|
||||
g_s_spi_config.u8[0] = spi->id;
|
||||
g_s_spi_config.u8[1] = spi->cs;
|
||||
}
|
||||
else if (LUAT_TYPE_SPI_DEVICE == luat_sfud.luat_spi)
|
||||
{
|
||||
luat_spi_device_t* spi_device = (luat_spi_t *)luat_sfud.user_data;
|
||||
g_s_spi_config.u8[0] = spi_device->bus_id;
|
||||
g_s_spi_config.u8[1] = spi_device->spi_config.cs;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return audio_play_tts_text(multimedia_id, text, text_bytes);
|
||||
}
|
||||
|
||||
int luat_audio_play_tts_set_param(uint32_t multimedia_id, uint32_t param_id, uint32_t param_value)
|
||||
{
|
||||
return audio_play_tts_set_param(multimedia_id, param_id, param_value);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,364 @@
|
||||
#include "common_api.h"
|
||||
#include "luat_base.h"
|
||||
#include "luat_msgbus.h"
|
||||
#include "luat_malloc.h"
|
||||
#include "luat_fs.h"
|
||||
#include "luat_timer.h"
|
||||
#include <stdlib.h>
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "mbedtls/cipher.h"
|
||||
#include "mbedtls/sha1.h"
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "mbedtls/sha512.h"
|
||||
#include "mbedtls/md5.h"
|
||||
|
||||
#define LUAT_LOG_TAG "base"
|
||||
#include "luat_log.h"
|
||||
|
||||
#ifdef LUAT_USE_LVGL
|
||||
#include "lvgl.h"
|
||||
void luat_lv_fs_init(void);
|
||||
void lv_bmp_init(void);
|
||||
void lv_png_init(void);
|
||||
void lv_split_jpeg_init(void);
|
||||
#endif
|
||||
|
||||
static const luaL_Reg loadedlibs[] = {
|
||||
{"_G", luaopen_base}, // _G
|
||||
{LUA_LOADLIBNAME, luaopen_package}, // require
|
||||
{LUA_COLIBNAME, luaopen_coroutine}, // coroutine协程库
|
||||
{LUA_TABLIBNAME, luaopen_table}, // table库,操作table类型的数据结构
|
||||
{LUA_IOLIBNAME, luaopen_io}, // io库,操作文件
|
||||
{LUA_OSLIBNAME, luaopen_os}, // os库,已精简
|
||||
{LUA_STRLIBNAME, luaopen_string}, // string库,字符串操作
|
||||
{LUA_MATHLIBNAME, luaopen_math}, // math 数值计算
|
||||
{LUA_UTF8LIBNAME, luaopen_utf8},
|
||||
{LUA_DBLIBNAME, luaopen_debug}, // debug库,已精简
|
||||
#ifdef LUAT_USE_DBG
|
||||
#ifndef LUAT_USE_SHELL
|
||||
#define LUAT_USE_SHELL
|
||||
#endif
|
||||
{"dbg", luaopen_dbg}, // 调试库
|
||||
#endif
|
||||
#if defined(LUA_COMPAT_BITLIB)
|
||||
{LUA_BITLIBNAME, luaopen_bit32}, // 不太可能启用
|
||||
#endif
|
||||
// 往下是LuatOS定制的库, 如需精简请仔细测试
|
||||
//----------------------------------------------------------------------
|
||||
// 核心支撑库, 不可禁用!!
|
||||
{"rtos", luaopen_rtos}, // rtos底层库, 核心功能是队列和定时器
|
||||
{"log", luaopen_log}, // 日志库
|
||||
{"timer", luaopen_timer}, // 延时库
|
||||
//-----------------------------------------------------------------------
|
||||
{"mobile", luaopen_mobile},
|
||||
{"sms", luaopen_sms},
|
||||
{"errDump",luaopen_errdump},
|
||||
#ifdef LUAT_USE_NETWORK
|
||||
{"socket", luaopen_socket_adapter},
|
||||
{"mqtt", luaopen_mqtt},
|
||||
{"websocket", luaopen_websocket},
|
||||
{"http", luaopen_http},
|
||||
#ifdef LUAT_USE_FTP
|
||||
{"ftp", luaopen_ftp},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef LUAT_USE_WLAN
|
||||
{"wlan", luaopen_wlan},
|
||||
#endif
|
||||
// 设备驱动类, 可按实际情况删减. 即使最精简的固件, 也强烈建议保留uart库
|
||||
#ifdef LUAT_USE_UART
|
||||
{"uart", luaopen_uart}, // 串口操作
|
||||
#endif
|
||||
#ifdef LUAT_USE_GPIO
|
||||
{"gpio", luaopen_gpio}, // GPIO脚的操作
|
||||
#endif
|
||||
#ifdef LUAT_USE_I2C
|
||||
{"i2c", luaopen_i2c}, // I2C操作
|
||||
#endif
|
||||
#ifdef LUAT_USE_SPI
|
||||
{"spi", luaopen_spi}, // SPI操作
|
||||
#endif
|
||||
#ifdef LUAT_USE_ADC
|
||||
{"adc", luaopen_adc}, // ADC模块
|
||||
#endif
|
||||
#ifdef LUAT_USE_PWM
|
||||
{"pwm", luaopen_pwm}, // PWM模块
|
||||
#endif
|
||||
#ifdef LUAT_USE_WDT
|
||||
{"wdt", luaopen_wdt}, // watchdog模块
|
||||
#endif
|
||||
#ifdef LUAT_USE_PM
|
||||
{"pm", luaopen_pm}, // 电源管理模块
|
||||
#endif
|
||||
#ifdef LUAT_USE_MCU
|
||||
{"mcu", luaopen_mcu}, // MCU特有的一些操作
|
||||
#endif
|
||||
#ifdef LUAT_USE_RTC
|
||||
{"rtc", luaopen_rtc}, // 实时时钟
|
||||
#endif
|
||||
#ifdef LUAT_USE_OTP
|
||||
{"otp", luaopen_otp}, // OTP
|
||||
#endif
|
||||
//-----------------------------------------------------------------------
|
||||
// 工具库, 按需选用
|
||||
#ifdef LUAT_USE_CRYPTO
|
||||
{"crypto",luaopen_crypto}, // 加密和hash模块
|
||||
#endif
|
||||
#ifdef LUAT_USE_CJSON
|
||||
{"json", luaopen_cjson}, // json的序列化和反序列化
|
||||
#endif
|
||||
#ifdef LUAT_USE_ZBUFF
|
||||
{"zbuff", luaopen_zbuff}, // 像C语言语言操作内存块
|
||||
#endif
|
||||
#ifdef LUAT_USE_PACK
|
||||
{"pack", luaopen_pack}, // pack.pack/pack.unpack
|
||||
#endif
|
||||
// {"mqttcore",luaopen_mqttcore}, // MQTT 协议封装
|
||||
// {"libcoap", luaopen_libcoap}, // 处理COAP消息
|
||||
|
||||
#ifdef LUAT_USE_LIBGNSS
|
||||
{"libgnss", luaopen_libgnss}, // 处理GNSS定位数据
|
||||
#endif
|
||||
#ifdef LUAT_USE_FS
|
||||
{"fs", luaopen_fs}, // 文件系统库,在io库之外再提供一些方法
|
||||
#endif
|
||||
#ifdef LUAT_USE_SENSOR
|
||||
{"sensor", luaopen_sensor}, // 传感器库,支持DS18B20
|
||||
#endif
|
||||
#ifdef LUAT_USE_SFUD
|
||||
{"sfud", luaopen_sfud}, // sfud
|
||||
#endif
|
||||
#ifdef LUAT_USE_SFD
|
||||
{"sfd", luaopen_sfd}, // sfud
|
||||
#endif
|
||||
#ifdef LUAT_USE_DISP
|
||||
{"disp", luaopen_disp}, // OLED显示模块
|
||||
#endif
|
||||
#ifdef LUAT_USE_U8G2
|
||||
{"u8g2", luaopen_u8g2}, // u8g2
|
||||
#endif
|
||||
|
||||
#ifdef LUAT_USE_EINK
|
||||
{"eink", luaopen_eink}, // 电子墨水屏
|
||||
#endif
|
||||
#ifdef LUAT_USE_FATFS
|
||||
{"fatfs", luaopen_fatfs}, // SD卡/tf卡
|
||||
#endif
|
||||
|
||||
#ifdef LUAT_USE_LVGL
|
||||
// #ifndef LUAT_USE_LCD
|
||||
// #define LUAT_USE_LCD
|
||||
// #endif
|
||||
{"lvgl", luaopen_lvgl},
|
||||
#endif
|
||||
|
||||
#ifdef LUAT_USE_LCD
|
||||
{"lcd", luaopen_lcd},
|
||||
#endif
|
||||
#ifdef LUAT_USE_STATEM
|
||||
{"statem", luaopen_statem},
|
||||
#endif
|
||||
#ifdef LUAT_USE_GTFONT
|
||||
{"gtfont", luaopen_gtfont},
|
||||
#endif
|
||||
#ifdef LUAT_USE_FSKV
|
||||
{"fskv", luaopen_fskv},
|
||||
// 启用FSKV的时候,自动禁用FDB
|
||||
#ifdef LUAT_USE_FDB
|
||||
#undef LUAT_USE_FDB
|
||||
#endif
|
||||
#endif
|
||||
#ifdef LUAT_USE_FDB
|
||||
{"fdb", luaopen_fdb},
|
||||
#endif
|
||||
#ifdef LUAT_USE_VMX
|
||||
{"vmx", luaopen_vmx},
|
||||
#endif
|
||||
#ifdef LUAT_USE_COREMARK
|
||||
{"coremark", luaopen_coremark},
|
||||
#endif
|
||||
#ifdef LUAT_USE_FONTS
|
||||
{"fonts", luaopen_fonts},
|
||||
#endif
|
||||
#ifdef LUAT_USE_ZLIB
|
||||
{"zlib", luaopen_zlib},
|
||||
#endif
|
||||
#ifdef LUAT_USE_MLX90640
|
||||
{"mlx90640", luaopen_mlx90640},
|
||||
#endif
|
||||
#ifdef LUAT_USE_IR
|
||||
{"ir", luaopen_ir},
|
||||
#endif
|
||||
#ifdef LUAT_USE_YMODEM
|
||||
{"ymodem", luaopen_ymodem},
|
||||
#endif
|
||||
#ifdef LUAT_USE_LORA
|
||||
{"lora", luaopen_lora},
|
||||
#endif
|
||||
#ifdef LUAT_USE_MINIZ
|
||||
{"miniz", luaopen_miniz},
|
||||
#endif
|
||||
#ifdef LUAT_USE_PROTOBUF
|
||||
{"protobuf", luaopen_protobuf},
|
||||
#endif
|
||||
#ifdef LUAT_USE_IOTAUTH
|
||||
{"iotauth", luaopen_iotauth},
|
||||
#endif
|
||||
#ifdef LUAT_USE_HTTPSRV
|
||||
{"httpsrv", luaopen_httpsrv},
|
||||
#endif
|
||||
#ifdef LUAT_USE_RSA
|
||||
{"rsa", luaopen_rsa},
|
||||
#endif
|
||||
#ifdef LUAT_USE_MEDIA
|
||||
{"i2s", luaopen_i2s},
|
||||
{"audio", luaopen_multimedia_audio},
|
||||
#ifndef LUAT_USE_TTS
|
||||
{"codec", luaopen_multimedia_codec},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef LUAT_USE_HMETA
|
||||
{"hmeta", luaopen_hmeta},
|
||||
#endif
|
||||
#ifdef LUAT_USE_FOTA
|
||||
{"fota", luaopen_fota},
|
||||
#endif
|
||||
#ifdef LUAT_USE_PROFILER
|
||||
{"profiler", luaopen_profiler},
|
||||
#endif
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
#if MBEDTLS_VERSION_NUMBER >= 0x03000000
|
||||
#else
|
||||
void mbedtls_md5( const unsigned char *input,
|
||||
size_t ilen,
|
||||
unsigned char output[16] )
|
||||
{
|
||||
mbedtls_md5_ret( input, ilen, output );
|
||||
}
|
||||
#endif
|
||||
|
||||
// 按不同的rtconfig加载不同的库函数
|
||||
void luat_openlibs(lua_State *L) {
|
||||
// 初始化队列服务
|
||||
luat_msgbus_init();
|
||||
//print_list_mem("done>luat_msgbus_init");
|
||||
// 加载系统库
|
||||
const luaL_Reg *lib;
|
||||
/* "require" functions from 'loadedlibs' and set results to global table */
|
||||
for (lib = loadedlibs; lib->func; lib++) {
|
||||
luaL_requiref(L, lib->name, lib->func, 1);
|
||||
lua_pop(L, 1); /* remove lib */
|
||||
//extern void print_list_mem(const char* name);
|
||||
//print_list_mem(lib->name);
|
||||
}
|
||||
}
|
||||
|
||||
void ResetECSystemReset(void);
|
||||
|
||||
void luat_os_reboot(int code){
|
||||
(void)code;
|
||||
ResetECSystemReset();
|
||||
}
|
||||
|
||||
const char* luat_os_bsp(void) {
|
||||
return "EC618";
|
||||
}
|
||||
|
||||
/** 设备进入待机模式 */
|
||||
void luat_os_standy(int timeout) {
|
||||
(void)timeout;
|
||||
return; // nop
|
||||
}
|
||||
|
||||
// from reset.h
|
||||
|
||||
//void luat_ota_reboot(int timeout_ms) {
|
||||
// if (timeout_ms > 0)
|
||||
// luat_timer_mdelay(timeout_ms);
|
||||
// // nop
|
||||
//}
|
||||
|
||||
uint32_t luat_get_utc(uint32_t *tamp)
|
||||
{
|
||||
uint32_t sec = soc_get_utc();
|
||||
if (tamp)
|
||||
{
|
||||
*tamp = sec;
|
||||
}
|
||||
return sec;
|
||||
}
|
||||
|
||||
void luat_os_entry_cri(void) {
|
||||
portENTER_CRITICAL();
|
||||
}
|
||||
|
||||
void luat_os_exit_cri(void) {
|
||||
portEXIT_CRITICAL();
|
||||
}
|
||||
|
||||
// delay_us 是系统函数
|
||||
extern void delay_us(uint32_t us);
|
||||
void luat_timer_us_delay(size_t us) {
|
||||
if (us > 0)
|
||||
delay_us(us);
|
||||
}
|
||||
|
||||
extern void soc_vsprintf(uint8_t no_print, const char *fmt, va_list ap);
|
||||
void DBG_Printf(const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
soc_vsprintf(0, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
extern const uint8_t ByteToAsciiTable[16];
|
||||
void DBG_HexPrintf(void *Data, unsigned int len)
|
||||
{
|
||||
uint8_t *data = (uint8_t *)Data;
|
||||
uint8_t *uart_buf;
|
||||
uint32_t i,j;
|
||||
j = 0;
|
||||
if (!len) return;
|
||||
uart_buf = luat_heap_malloc(len * 3 + 2);
|
||||
if (!uart_buf) return;
|
||||
memset(uart_buf, 0, len * 3 + 2);
|
||||
for (i = 0; i < len; i++){
|
||||
uart_buf[j++] = ByteToAsciiTable[(data[i] & 0xf0) >> 4];
|
||||
uart_buf[j++] = ByteToAsciiTable[data[i] & 0x0f];
|
||||
uart_buf[j++] = ' ';
|
||||
}
|
||||
uart_buf[j++] = '\r';
|
||||
uart_buf[j++] = '\n';
|
||||
luat_log_write((char*)uart_buf, len * 3 + 2);
|
||||
luat_heap_free(uart_buf);
|
||||
}
|
||||
|
||||
struct tm *mbedtls_platform_gmtime_r( const mbedtls_time_t *tt,
|
||||
struct tm *tm_buf )
|
||||
{
|
||||
Date_UserDataStruct Date;
|
||||
Time_UserDataStruct Time;
|
||||
Tamp2UTC(*tt, &Date, &Time, 0);
|
||||
tm_buf->tm_year = Date.Year - 1900;
|
||||
tm_buf->tm_mon = Date.Mon - 1;
|
||||
tm_buf->tm_mday = Date.Day;
|
||||
tm_buf->tm_hour = Time.Hour;
|
||||
tm_buf->tm_min = Time.Min;
|
||||
tm_buf->tm_sec = Time.Sec;
|
||||
return tm_buf;
|
||||
|
||||
}
|
||||
|
||||
#include "osasys.h"
|
||||
|
||||
time_t luat_time(time_t *_Time) {
|
||||
utc_timer_value_t *timeUtc = OsaSystemTimeReadUtc();
|
||||
if (_Time != NULL) {
|
||||
*_Time = timeUtc->UTCsecs;
|
||||
}
|
||||
return timeUtc->UTCsecs;
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
/*
|
||||
* Copyright (c) 2022 OpenLuat & AirM2M
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "luat_base.h"
|
||||
#include "luat_mcu.h"
|
||||
#include "luat_malloc.h"
|
||||
#include "luat_spi.h"
|
||||
#include "luat_fota.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "bsp_common.h"
|
||||
#include "platform_define.h"
|
||||
#define LUAT_LOG_TAG "fota"
|
||||
#include "luat_log.h"
|
||||
#include "mbedtls/md5.h"
|
||||
#include "fota_nvm.h"
|
||||
extern void fotaNvmNfsPeInit(uint8_t isSmall);
|
||||
#define __SOC_OTA_COMMON_DATA_LOAD_ADDRESS__ (LUA_SCRIPT_OTA_ADDR + AP_FLASH_XIP_ADDR)
|
||||
#define __SOC_OTA_COMMON_DATA_SAVE_ADDRESS__ (LUA_SCRIPT_OTA_ADDR)
|
||||
#define __SOC_OTA_SDK_DATA_LOAD_ADDRESS__ (FLASH_FOTA_REGION_START + AP_FLASH_XIP_ADDR)
|
||||
#define __SOC_OTA_SDK_DATA_SAVE_ADDRESS__ (FLASH_FOTA_REGION_START)
|
||||
typedef struct
|
||||
{
|
||||
Buffer_Struct data_buffer;
|
||||
mbedtls_md5_context *md5_ctx;
|
||||
CoreUpgrade_FileHeadCalMD5Struct *p_fota_file_head;
|
||||
uint32_t *crc32_table;
|
||||
uint32_t ota_done_len;
|
||||
uint8_t ota_state;
|
||||
}luat_fota_ctrl_t;
|
||||
|
||||
enum
|
||||
{
|
||||
OTA_STATE_IDLE,
|
||||
OTA_STATE_WRITE_COMMON_DATA,
|
||||
OTA_STATE_WRITE_SDK_DATA,
|
||||
OTA_STATE_OK,
|
||||
};
|
||||
|
||||
static luat_fota_ctrl_t g_s_fota;
|
||||
|
||||
static void luat_fota_finish(void)
|
||||
{
|
||||
CoreUpgrade_HeadCalMD5Struct Head = {0};
|
||||
PV_Union uPV;
|
||||
Head.MaigcNum = __APP_START_MAGIC__;
|
||||
Head.DataStartAddress = __SOC_OTA_COMMON_DATA_LOAD_ADDRESS__;
|
||||
uPV.u8[0] = CORE_OTA_MODE_FULL;
|
||||
uPV.u8[1] = CORE_OTA_IN_FLASH;
|
||||
Head.Param1 = uPV.u32;
|
||||
Head.DataLen = g_s_fota.p_fota_file_head->CommonDataLen;
|
||||
memcpy(Head.CommonMD5, g_s_fota.p_fota_file_head->CommonMD5, 16);
|
||||
Head.CRC32 = CRC32_Cal(g_s_fota.crc32_table, (uint8_t *)&Head.Param1, sizeof(Head) - 8, 0xffffffff);
|
||||
BSP_QSPI_Erase_Safe(__SOC_OTA_INFO_DATA_SAVE_ADDRESS__, __FLASH_SECTOR_SIZE__);
|
||||
BSP_QSPI_Write_Safe((uint8_t *)&Head, __SOC_OTA_INFO_DATA_SAVE_ADDRESS__, sizeof(Head));
|
||||
g_s_fota.ota_state = OTA_STATE_OK;
|
||||
luat_heap_free(g_s_fota.crc32_table);
|
||||
g_s_fota.crc32_table = NULL;
|
||||
luat_heap_free(g_s_fota.md5_ctx);
|
||||
g_s_fota.md5_ctx = NULL;
|
||||
luat_heap_free(g_s_fota.p_fota_file_head);
|
||||
g_s_fota.p_fota_file_head = NULL;
|
||||
OS_DeInitBuffer(&g_s_fota.data_buffer);
|
||||
LLOGI("fota ok!, wait reboot");
|
||||
}
|
||||
|
||||
int luat_fota_init(uint32_t start_address, uint32_t len, luat_spi_device_t* spi_device, const char *path, uint32_t pathlen)
|
||||
{
|
||||
if (!g_s_fota.crc32_table)
|
||||
{
|
||||
g_s_fota.p_fota_file_head = luat_heap_malloc(sizeof(CoreUpgrade_FileHeadCalMD5Struct));
|
||||
g_s_fota.crc32_table = luat_heap_malloc(256 * sizeof(uint32_t));
|
||||
memset(g_s_fota.crc32_table, 0, 1024);
|
||||
g_s_fota.md5_ctx = luat_heap_malloc(sizeof(mbedtls_md5_context));
|
||||
CRC32_CreateTable(g_s_fota.crc32_table, CRC32_GEN);
|
||||
}
|
||||
memset(g_s_fota.p_fota_file_head, 0, sizeof(CoreUpgrade_FileHeadCalMD5Struct));
|
||||
g_s_fota.ota_state = OTA_STATE_IDLE;
|
||||
BSP_QSPI_Erase_Safe(__SOC_OTA_INFO_DATA_SAVE_ADDRESS__, __FLASH_SECTOR_SIZE__);
|
||||
OS_ReInitBuffer(&g_s_fota.data_buffer, __FLASH_SECTOR_SIZE__ * 4);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_fota_write(uint8_t *data, uint32_t len)
|
||||
{
|
||||
uint32_t save_len;
|
||||
OS_BufferWrite(&g_s_fota.data_buffer, data, len);
|
||||
REPEAT:
|
||||
switch(g_s_fota.ota_state)
|
||||
{
|
||||
case OTA_STATE_IDLE:
|
||||
if (g_s_fota.data_buffer.Pos > sizeof(CoreUpgrade_FileHeadCalMD5Struct))
|
||||
{
|
||||
memcpy(g_s_fota.p_fota_file_head, g_s_fota.data_buffer.Data, sizeof(CoreUpgrade_FileHeadCalMD5Struct));
|
||||
OS_BufferRemove(&g_s_fota.data_buffer, sizeof(CoreUpgrade_FileHeadCalMD5Struct));
|
||||
if (g_s_fota.p_fota_file_head->MaigcNum != __APP_START_MAGIC__)
|
||||
{
|
||||
LLOGI("magic num error %x", g_s_fota.p_fota_file_head->MaigcNum);
|
||||
g_s_fota.data_buffer.Pos = 0;
|
||||
return -1;
|
||||
}
|
||||
uint32_t crc32 = CRC32_Cal(g_s_fota.crc32_table, g_s_fota.p_fota_file_head->MainVersion, sizeof(CoreUpgrade_FileHeadCalMD5Struct) - 8, 0xffffffff);
|
||||
if (crc32 != g_s_fota.p_fota_file_head->CRC32)
|
||||
{
|
||||
LLOGI("file head crc32 error %x,%x", crc32, g_s_fota.p_fota_file_head->CRC32);
|
||||
g_s_fota.data_buffer.Pos = 0;
|
||||
return -1;
|
||||
}
|
||||
g_s_fota.ota_done_len = 0;
|
||||
mbedtls_md5_init(g_s_fota.md5_ctx);
|
||||
mbedtls_md5_starts_ret(g_s_fota.md5_ctx);
|
||||
if (g_s_fota.p_fota_file_head->CommonDataLen)
|
||||
{
|
||||
g_s_fota.ota_state = OTA_STATE_WRITE_COMMON_DATA;
|
||||
fotaNvmNfsPeInit(1);
|
||||
LLOGI("write stript data");
|
||||
goto REPEAT;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_s_fota.ota_state = OTA_STATE_WRITE_SDK_DATA;
|
||||
LLOGI("write core data");
|
||||
goto REPEAT;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case OTA_STATE_WRITE_COMMON_DATA:
|
||||
save_len = ((g_s_fota.ota_done_len + __FLASH_SECTOR_SIZE__) < g_s_fota.p_fota_file_head->CommonDataLen)?__FLASH_SECTOR_SIZE__:(g_s_fota.p_fota_file_head->CommonDataLen - g_s_fota.ota_done_len);
|
||||
if (g_s_fota.data_buffer.Pos >= save_len)
|
||||
{
|
||||
BSP_QSPI_Erase_Safe(__SOC_OTA_COMMON_DATA_SAVE_ADDRESS__ + g_s_fota.ota_done_len, __FLASH_SECTOR_SIZE__);
|
||||
BSP_QSPI_Write_Safe(g_s_fota.data_buffer.Data, __SOC_OTA_COMMON_DATA_SAVE_ADDRESS__ + g_s_fota.ota_done_len, save_len);
|
||||
mbedtls_md5_update_ret(g_s_fota.md5_ctx, (uint8_t *)(__SOC_OTA_COMMON_DATA_LOAD_ADDRESS__ + g_s_fota.ota_done_len), save_len );
|
||||
OS_BufferRemove(&g_s_fota.data_buffer, save_len);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
g_s_fota.ota_done_len += save_len;
|
||||
if (g_s_fota.ota_done_len >= g_s_fota.p_fota_file_head->CommonDataLen)
|
||||
{
|
||||
LLOGI("stript data done, now checking");
|
||||
fotaNvmNfsPeInit(0);
|
||||
uint8_t md5[16];
|
||||
mbedtls_md5_finish_ret(g_s_fota.md5_ctx, md5);
|
||||
if (memcmp(md5, g_s_fota.p_fota_file_head->CommonMD5, 16))
|
||||
{
|
||||
LLOGI("stript data md5 check failed");
|
||||
g_s_fota.ota_state = OTA_STATE_IDLE;
|
||||
g_s_fota.data_buffer.Pos = 0;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
LLOGI("stript data md5 ok");
|
||||
if (g_s_fota.p_fota_file_head->SDKDataLen)
|
||||
{
|
||||
g_s_fota.ota_state = OTA_STATE_WRITE_SDK_DATA;
|
||||
g_s_fota.ota_done_len = 0;
|
||||
LLOGI("write core data");
|
||||
goto REPEAT;
|
||||
}
|
||||
else
|
||||
{
|
||||
LLOGI("stript data md5 ok");
|
||||
luat_fota_finish();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
goto REPEAT;
|
||||
}
|
||||
break;
|
||||
case OTA_STATE_WRITE_SDK_DATA:
|
||||
save_len = ((g_s_fota.ota_done_len + __FLASH_SECTOR_SIZE__) < (g_s_fota.p_fota_file_head->SDKDataLen))?__FLASH_SECTOR_SIZE__:(g_s_fota.p_fota_file_head->SDKDataLen - g_s_fota.ota_done_len);
|
||||
if (g_s_fota.data_buffer.Pos >= save_len)
|
||||
{
|
||||
BSP_QSPI_Erase_Safe(__SOC_OTA_SDK_DATA_SAVE_ADDRESS__ + g_s_fota.ota_done_len, __FLASH_SECTOR_SIZE__);
|
||||
BSP_QSPI_Write_Safe(g_s_fota.data_buffer.Data, __SOC_OTA_SDK_DATA_SAVE_ADDRESS__ + g_s_fota.ota_done_len, save_len);
|
||||
OS_BufferRemove(&g_s_fota.data_buffer, save_len);
|
||||
// mbedtls_md5_update_ret(g_s_fota.md5_ctx, (uint8_t *)(__SOC_OTA_COMMON_DATA_SAVE_ADDRESS__ + g_s_fota.ota_done_len), save_len );
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
g_s_fota.ota_done_len += save_len;
|
||||
if (g_s_fota.ota_done_len >= g_s_fota.p_fota_file_head->SDKDataLen)
|
||||
{
|
||||
fotaNvmInit();
|
||||
FotaDefChkDeltaState_t chkDelta = {0};
|
||||
FotaDefChkBaseImage_t chkBase = {0};
|
||||
|
||||
fotaNvmDoExtension(FOTA_DEF_CHK_DELTA_STATE, (void*)&chkDelta);
|
||||
if(!chkDelta.isValid)
|
||||
{
|
||||
LLOGI("validate delta err! errno(%d)", chkDelta.state);
|
||||
g_s_fota.ota_state = OTA_STATE_IDLE;
|
||||
g_s_fota.data_buffer.Pos = 0;
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
LLOGI("validate delta ok!");
|
||||
fotaNvmDoExtension(FOTA_DEF_CHK_BASE_IMAGE, (void*)&chkBase);
|
||||
if(!chkBase.isMatched)
|
||||
{
|
||||
LLOGI("however, base fw is unmatched!");
|
||||
fotaNvmClearDelta(0, 4096);
|
||||
g_s_fota.ota_state = OTA_STATE_IDLE;
|
||||
g_s_fota.data_buffer.Pos = 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
LLOGI("sdk data ok!");
|
||||
luat_fota_finish();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
goto REPEAT;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int luat_fota_done(void)
|
||||
{
|
||||
switch(g_s_fota.ota_state)
|
||||
{
|
||||
case OTA_STATE_IDLE:
|
||||
return -1;
|
||||
case OTA_STATE_OK:
|
||||
return 0;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int luat_fota_end(uint8_t is_ok)
|
||||
{
|
||||
if (g_s_fota.ota_state != OTA_STATE_OK)
|
||||
{
|
||||
luat_heap_free(g_s_fota.crc32_table);
|
||||
g_s_fota.crc32_table = NULL;
|
||||
luat_heap_free(g_s_fota.md5_ctx);
|
||||
g_s_fota.md5_ctx = NULL;
|
||||
luat_heap_free(g_s_fota.p_fota_file_head);
|
||||
g_s_fota.p_fota_file_head = NULL;
|
||||
OS_DeInitBuffer(&g_s_fota.data_buffer);
|
||||
OS_DeInitBuffer(&g_s_fota.data_buffer);
|
||||
BSP_QSPI_Erase_Safe(__SOC_OTA_INFO_DATA_SAVE_ADDRESS__, __FLASH_SECTOR_SIZE__);
|
||||
LLOGI("fota failed");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t luat_fota_wait_ready(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "luat_base.h"
|
||||
#include "luat_hmeta.h"
|
||||
|
||||
extern int soc_get_model_name(char *model);
|
||||
|
||||
int luat_hmeta_model_name(char* buff) {
|
||||
soc_get_model_name(buff);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,105 @@
|
||||
|
||||
#include "common_api.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include "luat_base.h"
|
||||
#include "luat_log.h"
|
||||
#include "luat_uart.h"
|
||||
#include "printf.h"
|
||||
#include "luat_cmux.h"
|
||||
#include "luat_conf_bsp.h"
|
||||
|
||||
#include "cms_def.h"
|
||||
|
||||
extern luat_cmux_t cmux_ctx;
|
||||
extern void soc_debug_out(char *string, uint32_t size);
|
||||
static uint32_t luat_log_uart_port = 0;
|
||||
static uint32_t luat_log_level_cur = LUAT_LOG_DEBUG;
|
||||
|
||||
#define LOGLOG_SIZE 1024
|
||||
static char log_printf_buff[LOGLOG_SIZE] __attribute__((aligned (16)));
|
||||
|
||||
void luat_log_set_uart_port(int port) {
|
||||
luat_log_uart_port = port;
|
||||
}
|
||||
|
||||
uint8_t luat_log_get_uart_port(void) {
|
||||
return luat_log_uart_port;
|
||||
}
|
||||
|
||||
void luat_nprint(char *s, size_t l) {
|
||||
#ifdef LUAT_USE_SHELL
|
||||
if (cmux_ctx.state == 1 && cmux_ctx.log_state ==1){
|
||||
luat_cmux_write(LUAT_CMUX_CH_LOG, CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,s, l);
|
||||
}else
|
||||
#endif
|
||||
soc_debug_out(s, l);
|
||||
}
|
||||
|
||||
void luat_log_write(char *s, size_t l) {
|
||||
#ifdef LUAT_USE_SHELL
|
||||
if (cmux_ctx.state == 1 && cmux_ctx.log_state ==1){
|
||||
luat_cmux_write(LUAT_CMUX_CH_LOG, CMUX_FRAME_UIH & ~ CMUX_CONTROL_PF,s, l);
|
||||
}else
|
||||
#endif
|
||||
soc_debug_out(s, l);
|
||||
}
|
||||
|
||||
void luat_log_set_level(int level) {
|
||||
luat_log_level_cur = level;
|
||||
}
|
||||
|
||||
int luat_log_get_level() {
|
||||
return luat_log_level_cur;
|
||||
}
|
||||
|
||||
void luat_log_log(int level, const char* tag, const char* _fmt, ...) {
|
||||
if (luat_log_level_cur > level) return;
|
||||
char *tmp = (char *)log_printf_buff;
|
||||
switch (level)
|
||||
{
|
||||
case LUAT_LOG_DEBUG:
|
||||
log_printf_buff[0] = 'D';
|
||||
break;
|
||||
case LUAT_LOG_INFO:
|
||||
log_printf_buff[0] = 'I';
|
||||
break;
|
||||
case LUAT_LOG_WARN:
|
||||
log_printf_buff[0] = 'W';
|
||||
break;
|
||||
case LUAT_LOG_ERROR:
|
||||
log_printf_buff[0] = 'E';
|
||||
break;
|
||||
default:
|
||||
log_printf_buff[0] = '?';
|
||||
break;
|
||||
}
|
||||
log_printf_buff[1] = '/';
|
||||
tmp += 2;
|
||||
memcpy(tmp, tag, strlen(tag));
|
||||
log_printf_buff[2+strlen(tag)] = ' ';
|
||||
tmp += strlen(tag) + 1;
|
||||
|
||||
va_list args;
|
||||
va_start(args, _fmt);
|
||||
size_t len = vsnprintf_(tmp, LOGLOG_SIZE - (2 + strlen(tag) + 1 + 1 + 1), _fmt, args);
|
||||
va_end(args);
|
||||
if (len > 0) {
|
||||
len += 2 + strlen(tag) + 1;
|
||||
log_printf_buff[len] = 0;
|
||||
luat_log_write(log_printf_buff, len+1);
|
||||
}
|
||||
}
|
||||
|
||||
void luat_log_printf(int level, const char* _fmt, ...) {
|
||||
size_t len;
|
||||
va_list args;
|
||||
if (luat_log_level_cur > level) return;
|
||||
va_start(args, _fmt);
|
||||
len = vsnprintf_(log_printf_buff, LOGLOG_SIZE, _fmt, args);
|
||||
va_end(args);
|
||||
if (len > 0) {
|
||||
luat_log_write(log_printf_buff, len);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,235 @@
|
||||
/*
|
||||
* Copyright (c) 2022 OpenLuat & AirM2M
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
* this software and associated documentation files (the "Software"), to deal in
|
||||
* the Software without restriction, including without limitation the rights to
|
||||
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
* subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in all
|
||||
* copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include "common_api.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "wdt.h"
|
||||
#include "luat_pm.h"
|
||||
#include "luat_rtos.h"
|
||||
#include "luat_mobile.h"
|
||||
#include "luat_sms.h"
|
||||
#include "luat_network_adapter.h"
|
||||
#include "ps_event_callback.h"
|
||||
#include "networkmgr.h"
|
||||
#include "plat_config.h"
|
||||
#include "driver_gpio.h"
|
||||
#ifdef LUAT_USE_LVGL
|
||||
#include "lvgl.h"
|
||||
#include "luat_lvgl.h"
|
||||
#endif
|
||||
#include "luat_errdump.h"
|
||||
|
||||
extern int luat_main(void);
|
||||
extern void luat_heap_init(void);
|
||||
const char *soc_get_sdk_type(void)
|
||||
{
|
||||
return "LuatOS-SoC";
|
||||
}
|
||||
const char *soc_get_sdk_version(void)
|
||||
{
|
||||
return LUAT_BSP_VERSION;
|
||||
}
|
||||
luat_rtos_timer_t lvgl_timer_handle;
|
||||
#ifdef LUAT_USE_LVGL
|
||||
#define LVGL_TICK_PERIOD 10
|
||||
unsigned int g_lvgl_flash_time;
|
||||
static uint32_t lvgl_tick_cnt;
|
||||
|
||||
static int luat_lvg_handler(lua_State* L, void* ptr) {
|
||||
// DBG("%u", lv_tick_get());
|
||||
if (lvgl_tick_cnt) lvgl_tick_cnt--;
|
||||
lv_task_handler();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void luat_lvgl_callback(void *param){
|
||||
if (lvgl_tick_cnt < 5)
|
||||
{
|
||||
lvgl_tick_cnt++;
|
||||
rtos_msg_t msg = {0};
|
||||
msg.handler = luat_lvg_handler;
|
||||
luat_msgbus_put(&msg, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void luat_lvgl_tick_sleep(uint8_t OnOff)
|
||||
{
|
||||
if (!OnOff)
|
||||
{
|
||||
luat_rtos_timer_start(lvgl_timer_handle, LVGL_TICK_PERIOD, true, luat_lvgl_callback, NULL);
|
||||
}
|
||||
else
|
||||
{
|
||||
luat_rtos_timer_stop(lvgl_timer_handle);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
void luat_lvgl_tick_sleep(uint8_t OnOff)
|
||||
{
|
||||
|
||||
}
|
||||
#endif
|
||||
extern int soc_mobile_get_default_pdp_part_info(uint8_t *ip_type, uint8_t *apn,uint8_t *apn_len, uint8_t *dns_num, ip_addr_t *dns_ip);
|
||||
|
||||
|
||||
//static INT32 ps_callback(PsEventID eventID, void *param, UINT32 paramLen)
|
||||
//{
|
||||
// NmAtiNetInfoInd *net_info = (NmAtiNetInfoInd *)param;
|
||||
// ip_addr_t dns_ip;
|
||||
// if(PS_URC_ID_PS_NETINFO == eventID)
|
||||
// {
|
||||
// if (NM_NETIF_ACTIVATED == net_info->netifInfo.netStatus)
|
||||
// {
|
||||
// if (net_info->netifInfo.ipv4Cid != 0xFF)
|
||||
// {
|
||||
// dns_ip.type = IPADDR_TYPE_V4;
|
||||
// dns_ip.u_addr.ip4 = net_info->netifInfo.ipv4Info.dns[0];
|
||||
// network_set_dns_server(NW_ADAPTER_INDEX_LWIP_GPRS, 2, &dns_ip);
|
||||
// dns_ip.u_addr.ip4 = net_info->netifInfo.ipv4Info.dns[1];
|
||||
// network_set_dns_server(NW_ADAPTER_INDEX_LWIP_GPRS, 3, &dns_ip);
|
||||
//
|
||||
// }
|
||||
// else if (net_info->netifInfo.ipv6Cid != 0xFF)
|
||||
// {
|
||||
// // dns_ip.type = IPADDR_TYPE_V6;
|
||||
// // dns_ip.u_addr.ip6 = net_info->netifInfo.ipv6Info.dns[0];
|
||||
// // network_set_dns_server(NW_ADAPTER_INDEX_LWIP_GPRS, 3, &dns_ip);
|
||||
// //dns_ip.u_addr.ip6 = net_info->netifInfo.ipv6Info.dns[1];
|
||||
// //network_set_dns_server(NW_ADAPTER_INDEX_LWIP_GPRS, 3, &dns_ip);
|
||||
// }
|
||||
// net_lwip_set_link_state(NW_ADAPTER_INDEX_LWIP_GPRS, 1);
|
||||
// }
|
||||
// }
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
//static void dft_usb_recv_cb(uint8_t channel, uint8_t *input, uint32_t len){
|
||||
// if (input == NULL) {
|
||||
// switch(len){
|
||||
// case 0:
|
||||
// LLOGD("usb serial connected");
|
||||
// break;
|
||||
// default:
|
||||
// LLOGD("usb serial disconnected");
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
//#ifdef LUAT_USE_SHELL
|
||||
// else {
|
||||
// luat_shell_push(input, len);
|
||||
// }
|
||||
//#endif
|
||||
//}
|
||||
extern int soc_get_model_name(char *model);
|
||||
|
||||
static void luat_main_print_model(void)
|
||||
{
|
||||
char temp[40] = {0};
|
||||
soc_get_model_name(temp);
|
||||
DBG("model %s", temp);
|
||||
}
|
||||
|
||||
static void luatos_task(void *param)
|
||||
{
|
||||
BSP_SetPlatConfigItemValue(PLAT_CONFIG_ITEM_FAULT_ACTION, EXCEP_OPTION_DUMP_FLASH_EPAT_RESET);
|
||||
if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_FAULT_ACTION) == EXCEP_OPTION_SILENT_RESET)
|
||||
ResetLockupCfg(true, true);
|
||||
else
|
||||
ResetLockupCfg(false, false);
|
||||
|
||||
luat_heap_init();
|
||||
luat_main_print_model();
|
||||
#ifdef LUAT_USE_MEDIA
|
||||
luat_audio_global_init();
|
||||
#endif
|
||||
// set_usb_serial_input_callback(dft_usb_recv_cb);
|
||||
//DBG("LuatOS starting ...");
|
||||
|
||||
#ifdef LUAT_USE_LVGL
|
||||
g_lvgl_flash_time = 33;
|
||||
lv_init();
|
||||
luat_rtos_timer_create(&lvgl_timer_handle);
|
||||
|
||||
#ifdef __LVGL_SLEEP_ENABLE__
|
||||
luat_lvgl_tick_sleep(1);
|
||||
#else
|
||||
luat_rtos_timer_start(lvgl_timer_handle, LVGL_TICK_PERIOD, true, luat_lvgl_callback, NULL);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
luat_pm_init();
|
||||
luat_main();
|
||||
while (1) {
|
||||
DBG("LuatOS exit"); // TODO 咋就没重启呢
|
||||
luat_rtos_task_sleep(15000);
|
||||
luat_os_reboot(0);
|
||||
}
|
||||
}
|
||||
|
||||
void luat_mobile_event_cb(LUAT_MOBILE_EVENT_E event, uint8_t index, uint8_t status);
|
||||
void luat_sms_recv_cb(uint32_t event, void *param);
|
||||
|
||||
static void luatos_mobile_event_callback(LUAT_MOBILE_EVENT_E event, uint8_t index, uint8_t status)
|
||||
{
|
||||
if (LUAT_MOBILE_EVENT_NETIF == event)
|
||||
{
|
||||
if (LUAT_MOBILE_NETIF_LINK_ON == status)
|
||||
{
|
||||
ip_addr_t dns_ip[2];
|
||||
uint8_t type, dns_num;
|
||||
dns_num = 2;
|
||||
soc_mobile_get_default_pdp_part_info(&type, NULL, NULL, &dns_num, dns_ip);
|
||||
if (dns_num > 0)
|
||||
{
|
||||
network_set_dns_server(NW_ADAPTER_INDEX_LWIP_GPRS, 2, &dns_ip[0]);
|
||||
if (dns_num > 1)
|
||||
{
|
||||
network_set_dns_server(NW_ADAPTER_INDEX_LWIP_GPRS, 3, &dns_ip[1]);
|
||||
}
|
||||
}
|
||||
net_lwip_set_link_state(NW_ADAPTER_INDEX_LWIP_GPRS, 1);
|
||||
}
|
||||
}
|
||||
luat_mobile_event_cb(event, index, status);
|
||||
}
|
||||
|
||||
static void luatos_task_init(void)
|
||||
{
|
||||
GPIO_GlobalInit(NULL);
|
||||
luat_mobile_event_register_handler(luatos_mobile_event_callback);
|
||||
luat_sms_init();
|
||||
luat_sms_recv_msg_register_handler(luat_sms_recv_cb);
|
||||
net_lwip_init();
|
||||
net_lwip_register_adapter(NW_ADAPTER_INDEX_LWIP_GPRS);
|
||||
network_register_set_default(NW_ADAPTER_INDEX_LWIP_GPRS);
|
||||
luat_rtos_task_handle task_handle;
|
||||
// xTaskCreateStatic(task1, "luatos", VM_STACK_SIZE, NULL, 20, s_vm_stackbuff, pxVMTaskTCBBuffer);
|
||||
luat_rtos_task_create(&task_handle, 16 * 1024, 80, "luatos", luatos_task, NULL, 0);
|
||||
|
||||
}
|
||||
extern void luat_pm_preinit(void);
|
||||
INIT_DRV_EXPORT(luat_pm_preinit, "1");
|
||||
INIT_HW_EXPORT(luatos_task_init, "1");
|
||||
|
||||
|
||||
@@ -0,0 +1,103 @@
|
||||
|
||||
#include "common_api.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>//add for memset
|
||||
#include "bget.h"
|
||||
#include "luat_base.h"
|
||||
#include "luat_malloc.h"
|
||||
|
||||
#define LUAT_LOG_TAG "vmheap"
|
||||
#include "luat_log.h"
|
||||
|
||||
|
||||
#include "mm_debug.h"//add for memory leak debug
|
||||
#include "exception_process.h"
|
||||
#include "cmsis_compiler.h"
|
||||
#include "tlsf.h"
|
||||
#include "mem_map.h"
|
||||
#ifndef LUAT_HEAP_SIZE
|
||||
#ifdef LOW_SPEED_SERVICE_ONLY
|
||||
#define LUAT_HEAP_SIZE (200*1024)
|
||||
#else
|
||||
#define LUAT_HEAP_SIZE (128*1024)
|
||||
#endif
|
||||
#endif
|
||||
static uint8_t vmheap[LUAT_HEAP_SIZE] __attribute__((aligned(8)));
|
||||
|
||||
|
||||
//------------------------------------------------
|
||||
// ---------- 管理 LuaVM所使用的内存----------------
|
||||
|
||||
#if 1
|
||||
void luat_heap_init(void) {
|
||||
bpool(vmheap, LUAT_HEAP_SIZE);
|
||||
}
|
||||
|
||||
void* luat_heap_alloc(void *ud, void *ptr, size_t osize, size_t nsize) {
|
||||
if (ptr == NULL && nsize == 0)
|
||||
return NULL;
|
||||
#if LUAT_USE_MEMORY_OPTIMIZATION_CODE_MMAP
|
||||
if (ptr != NULL) {
|
||||
uint32_t addr = (uint32_t) ptr;
|
||||
if (addr <= (uint32_t)vmheap || addr >= (uint32_t)(vmheap + LUAT_HEAP_SIZE)) {
|
||||
//LLOGD("skip ROM free %p", ptr);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (nsize)
|
||||
{
|
||||
void* ptmp = bgetr(ptr, nsize);
|
||||
if(ptmp == NULL && osize >= nsize)
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
return ptmp;
|
||||
}
|
||||
brel(ptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void luat_meminfo_luavm(size_t *total, size_t *used, size_t *max_used) {
|
||||
long curalloc, totfree, maxfree;
|
||||
unsigned long nget, nrel;
|
||||
bstats(&curalloc, &totfree, &maxfree, &nget, &nrel);
|
||||
*used = curalloc;
|
||||
*max_used = bstatsmaxget();
|
||||
*total = curalloc + totfree;
|
||||
}
|
||||
|
||||
#else
|
||||
static tlsf_t luavm_tlsf;
|
||||
|
||||
void luat_heap_init(void) {
|
||||
luavm_tlsf = tlsf_create_with_pool((void*)vmheap, LUAT_HEAP_SIZE);
|
||||
}
|
||||
|
||||
void* luat_heap_alloc(void *ud, void *ptr, size_t osize, size_t nsize) {
|
||||
if (ptr == NULL && nsize == 0)
|
||||
return NULL;
|
||||
#if LUAT_USE_MEMORY_OPTIMIZATION_CODE_MMAP
|
||||
if (ptr != NULL && nsize == 0) {
|
||||
uint32_t addr = (uint32_t) ptr;
|
||||
if (addr <= (uint32_t)vmheap || addr >= (uint32_t)(vmheap + LUAT_HEAP_SIZE)) {
|
||||
//LLOGD("skip ROM free %p", ptr);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
return tlsf_realloc(luavm_tlsf, ptr, nsize, (size_t)luat_heap_alloc);
|
||||
}
|
||||
void luat_meminfo_luavm(size_t *total, size_t *used, size_t *max_used) {
|
||||
*total = LUAT_HEAP_SIZE;
|
||||
*used = LUAT_HEAP_SIZE - tlsf_mem_size_free(luavm_tlsf);
|
||||
*max_used = LUAT_HEAP_SIZE - tlsf_mem_size_ever_min(luavm_tlsf);
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
|
||||
#include "luat_msgbus.h"
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "queue.h"
|
||||
|
||||
#define QUEUE_LENGTH 0xFF
|
||||
#define ITEM_SIZE sizeof(rtos_msg_t)
|
||||
|
||||
static StaticQueue_t xStaticQueue = {0};
|
||||
static QueueHandle_t xQueue = {0};
|
||||
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
static uint8_t ucQueueStorageArea[ QUEUE_LENGTH * ITEM_SIZE ] __attribute__((aligned (16)));
|
||||
#endif
|
||||
|
||||
void luat_msgbus_init(void) {
|
||||
if (!xQueue) {
|
||||
#if configSUPPORT_STATIC_ALLOCATION
|
||||
xQueue = xQueueCreateStatic( QUEUE_LENGTH,
|
||||
ITEM_SIZE,
|
||||
ucQueueStorageArea,
|
||||
&xStaticQueue );
|
||||
#else
|
||||
xQueue = xQueueCreate(QUEUE_LENGTH, ITEM_SIZE);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
uint32_t luat_msgbus_put(rtos_msg_t* msg, size_t timeout) {
|
||||
if (xQueue == NULL)
|
||||
return 1;
|
||||
return xQueueSendFromISR(xQueue, msg, NULL) == pdTRUE ? 0 : 1;
|
||||
}
|
||||
uint32_t luat_msgbus_get(rtos_msg_t* msg, size_t timeout) {
|
||||
if (xQueue == NULL)
|
||||
return 1;
|
||||
return xQueueReceive(xQueue, msg, timeout) == pdTRUE ? 0 : 1;
|
||||
}
|
||||
uint32_t luat_msgbus_freesize(void) {
|
||||
if (xQueue == NULL)
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,250 @@
|
||||
#include "luat_base.h"
|
||||
#include "luat_pm.h"
|
||||
#include "luat_msgbus.h"
|
||||
|
||||
#include "bsp.h"
|
||||
#include "bsp_custom.h"
|
||||
#include "osasys.h"
|
||||
#include "ostask.h"
|
||||
#include "slpman.h"
|
||||
#include "reset.h"
|
||||
//#include "psproxytask.h"
|
||||
#include "driver_gpio.h"
|
||||
#include "common_api.h"
|
||||
#include "plat_config.h"
|
||||
#include "ps_event_callback.h"
|
||||
#include "cmips.h"
|
||||
#include "ps_lib_api.h"
|
||||
|
||||
#define LUAT_LOG_TAG "luat.pm"
|
||||
#include "luat_log.h"
|
||||
|
||||
static uint8_t lastRequestMode = SLP_IDLE_STATE; // 在APP启动时设置
|
||||
static uint8_t wakeupSrc = 0;
|
||||
static uint8_t firstSlpstate;
|
||||
static uint8_t wakeup_deeptimer_id = 0xFF;
|
||||
|
||||
static const char slpStateText[5][5]={{"Actv"},{"Idle"},{"Slp1"},{"Slp2"},{"Hibn"}};
|
||||
static const char wakeupSrcStr[3][4] = {{"POR"}, {"RTC"}, {"IO"}};
|
||||
extern void soc_set_usb_sleep(uint8_t onoff);
|
||||
uint32_t inParam = 0xAABBCCDD;
|
||||
|
||||
static int luat_dtimer_cb(lua_State *L, void* ptr) {
|
||||
rtos_msg_t* msg = (rtos_msg_t*)lua_topointer(L, -1);
|
||||
lua_getglobal(L, "sys_pub");
|
||||
if (lua_isfunction(L, -1)) {
|
||||
lua_pushstring(L, "DTIMER_WAKEUP");
|
||||
lua_pushinteger(L, msg->arg1);
|
||||
lua_call(L, 2, 0);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void appTimerExpFunc(uint8_t id) {
|
||||
wakeup_deeptimer_id = id;
|
||||
LLOGI("DeepTimer Wakeup by id=%d", id);
|
||||
}
|
||||
|
||||
static slpManSlpState_t luat_user_slp_state(void)
|
||||
{
|
||||
return lastRequestMode;
|
||||
}
|
||||
|
||||
int luat_pm_request(int mode) {
|
||||
|
||||
LLOGI("request mode=%ld, prev mode=%ld", mode, lastRequestMode);
|
||||
if (mode < 0 || mode > LUAT_PM_SLEEP_MODE_STANDBY) {
|
||||
LLOGW("bad mode=%ld", mode);
|
||||
return -2;
|
||||
}
|
||||
lastRequestMode = mode;
|
||||
soc_set_usb_sleep(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_release(int mode) {
|
||||
soc_set_usb_sleep(0);
|
||||
lastRequestMode = LUAT_PM_SLEEP_MODE_IDLE;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_dtimer_start(int id, size_t timeout) {
|
||||
if (id < 0 || id > DEEPSLP_TIMER_ID6) {
|
||||
return -1;
|
||||
}
|
||||
slpManDeepSlpTimerStart(id, timeout);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_dtimer_stop(int id) {
|
||||
if (id < 0 || id > DEEPSLP_TIMER_ID6) {
|
||||
return -1;
|
||||
}
|
||||
slpManDeepSlpTimerDel(id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_dtimer_check(int id) {
|
||||
if (id < 0 || id > DEEPSLP_TIMER_ID6) {
|
||||
return false;
|
||||
}
|
||||
LLOGD("dtimer check id %d, remain %d ms", id, slpManDeepSlpTimerRemainMs(id));
|
||||
if (slpManDeepSlpTimerRemainMs(id) <= 500)
|
||||
{
|
||||
slpManDeepSlpTimerDel(id);
|
||||
}
|
||||
return slpManDeepSlpTimerIsRunning(id);
|
||||
}
|
||||
|
||||
int luat_pm_last_state(int *lastState, int *rtcOrPad) {
|
||||
*lastState = firstSlpstate;
|
||||
*rtcOrPad = wakeupSrc;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_force(int mode) {
|
||||
if (mode < 0 || mode > LUAT_PM_SLEEP_MODE_STANDBY) {
|
||||
LLOGW("bad mode=%ld", mode);
|
||||
return -2;
|
||||
}
|
||||
LLOGI("request mode=%ld, prev mode=%ld", mode, lastRequestMode);
|
||||
lastRequestMode = mode;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_check(void) {
|
||||
|
||||
return lastRequestMode;
|
||||
}
|
||||
|
||||
int luat_pm_dtimer_list(size_t* c, size_t* dlist) {
|
||||
for (uint8_t i = 0; i<= DEEPSLP_TIMER_ID6; i++) {
|
||||
if (slpManDeepSlpTimerIsRunning(i)) {
|
||||
uint32_t retime = slpManDeepSlpTimerRemainMs(i);
|
||||
if (retime != 0xffffffff) {
|
||||
*(dlist+i) = retime;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_dtimer_wakeup_id(int* id) {
|
||||
if (wakeup_deeptimer_id != 0xFF) {
|
||||
*id = wakeup_deeptimer_id;
|
||||
return 0;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
void luat_pm_preinit(void)
|
||||
{
|
||||
for(uint8_t i = 0; i <= DEEPSLP_TIMER_ID6; i++)
|
||||
{
|
||||
slpManDeepSlpTimerRegisterExpCb(i, appTimerExpFunc);
|
||||
}
|
||||
}
|
||||
|
||||
void luat_pm_init(void) {
|
||||
LLOGI("pm mode %d", apmuGetDeepestSleepMode());
|
||||
apmuSetDeepestSleepMode(AP_STATE_HIBERNATE);
|
||||
soc_set_usb_sleep(0);
|
||||
slpManSlpState_t slpstate = slpManGetLastSlpState();
|
||||
slpManWakeSrc_e src = slpManGetWakeupSrc();
|
||||
wakeupSrc = (uint8_t)src;
|
||||
if (src > WAKEUP_FROM_PAD)
|
||||
{
|
||||
src = WAKEUP_FROM_PAD;
|
||||
}
|
||||
if (slpstate == SLP_SLP2_STATE) {
|
||||
LLOGI("poweron: Wakup Sleep2 by %s %d", wakeupSrcStr[src], wakeup_deeptimer_id);
|
||||
firstSlpstate = LUAT_PM_SLEEP_MODE_DEEP;
|
||||
}
|
||||
else if (slpstate == SLP_HIB_STATE) {
|
||||
LLOGI("poweron: Wakup Hib by %s %d", wakeupSrcStr[src], wakeup_deeptimer_id);
|
||||
firstSlpstate = LUAT_PM_SLEEP_MODE_STANDBY;
|
||||
}
|
||||
else {
|
||||
firstSlpstate = LUAT_PM_SLEEP_MODE_NONE;
|
||||
LLOGI("poweron: Power/Reset");
|
||||
}
|
||||
slpManRegisterUsrSlpDepthCb(luat_user_slp_state);
|
||||
if (wakeup_deeptimer_id != 0xff)
|
||||
{
|
||||
rtos_msg_t msg = {0};
|
||||
msg.handler = luat_dtimer_cb;
|
||||
msg.arg1 = wakeup_deeptimer_id;
|
||||
luat_msgbus_put(&msg, 0);
|
||||
}
|
||||
}
|
||||
|
||||
int luat_pm_get_poweron_reason(void)
|
||||
{
|
||||
LastResetState_e apRstState,cpRstState;
|
||||
ResetStateGet(&apRstState, &cpRstState);
|
||||
int id = 0;
|
||||
switch(apRstState)
|
||||
{
|
||||
case LAST_RESET_POR:
|
||||
case LAST_RESET_NORMAL:
|
||||
id = 0;
|
||||
break;
|
||||
case LAST_RESET_SWRESET:
|
||||
id = 3;
|
||||
break;
|
||||
case LAST_RESET_HARDFAULT:
|
||||
case LAST_RESET_ASSERT:
|
||||
id = 6;
|
||||
break;
|
||||
case LAST_RESET_WDTSW:
|
||||
case LAST_RESET_WDTHW:
|
||||
case LAST_RESET_LOCKUP:
|
||||
case LAST_RESET_AONWDT:
|
||||
id = 8;
|
||||
break;
|
||||
case LAST_RESET_BATLOW:
|
||||
case LAST_RESET_TEMPHI:
|
||||
id = 9;
|
||||
break;
|
||||
case LAST_RESET_FOTA:
|
||||
id = 1;
|
||||
break;
|
||||
default:
|
||||
id = 4;
|
||||
break;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
///---------------------------------------
|
||||
|
||||
extern void pwrKeyStartPowerOff(void);
|
||||
int luat_pm_poweroff(void)
|
||||
{
|
||||
pwrKeyStartPowerOff();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_pm_power_ctrl(int id, uint8_t onoff)
|
||||
{
|
||||
switch(id)
|
||||
{
|
||||
case LUAT_PM_POWER_USB:
|
||||
soc_set_usb_sleep(!onoff);
|
||||
soc_usb_onoff(onoff);
|
||||
break;
|
||||
case LUAT_PM_POWER_GPS:
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_13, 4), 4, 0, 0);
|
||||
GPIO_Config(HAL_GPIO_13, 0, onoff);
|
||||
break;
|
||||
case LUAT_PM_POWER_GPS_ANT:
|
||||
case LUAT_PM_POWER_DAC_EN_PIN:
|
||||
GPIO_IomuxEC618(GPIO_ToPadEC618(HAL_GPIO_12, 4), 4, 0, 0);
|
||||
GPIO_Config(HAL_GPIO_12, 0, onoff);
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
#include "common_api.h"
|
||||
#include "luat_base.h"
|
||||
#include "luat_pm.h"
|
||||
#include "luat_msgbus.h"
|
||||
|
||||
#include "flash_rt.h"
|
||||
#include "mem_map.h"
|
||||
|
||||
|
||||
#define LUAT_LOG_TAG "sfd"
|
||||
#include "luat_log.h"
|
||||
|
||||
int sfd_onchip_init (void* userdata) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sfd_onchip_status (void* userdata) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sfd_onchip_read (void* userdata, char* buf, size_t offset, size_t size) {
|
||||
int ret = 0;
|
||||
if (size == 0)
|
||||
return 0;
|
||||
ret = BSP_QSPI_Read_Safe((uint8_t *)buf, (FLASH_FDB_REGION_START + offset), size);
|
||||
return ret == 0 ? size : -1;
|
||||
}
|
||||
|
||||
int sfd_onchip_write (void* userdata, const char* buf, size_t offset, size_t size) {
|
||||
int ret = 0;
|
||||
if (size == 0)
|
||||
return 0;
|
||||
// 注意, BSP_QSPI_Write_Safe 的buf不能是flash上的常量数据
|
||||
// 写入flash时XIP会关闭, 导致buf值肯定读不到
|
||||
// 下面的各种判断, 就是把常量数据拷贝到ram, 然后写入
|
||||
uint8_t tmp_small[256]; // 这里改成256的原因是fskv总是按256字节写
|
||||
uint8_t *tmp = NULL;
|
||||
uint32_t addr = (uint32_t)buf;
|
||||
if (size <= 256) {
|
||||
// 对于较小的数据, 直接在栈内存里拷贝即可,不必判断
|
||||
memcpy(tmp_small, buf, size);
|
||||
ret = BSP_QSPI_Write_Safe((uint8_t *)tmp_small, (FLASH_FDB_REGION_START + offset), size);
|
||||
}
|
||||
else if (addr >= 0x00400000 && addr <= 0x00500000) {
|
||||
// 数据已经处于ram, 可以直接写入
|
||||
ret = BSP_QSPI_Write_Safe((uint8_t *)buf, (FLASH_FDB_REGION_START + offset), size);
|
||||
}
|
||||
else {
|
||||
// 超过256字节的常量数据, 应该是不存在的吧, 下面的逻辑主要是防御代码.
|
||||
tmp = malloc(size);
|
||||
if (tmp == NULL) {
|
||||
DBG("out of memory when malloc flash write buff");
|
||||
return -1;
|
||||
}
|
||||
memcpy(tmp, buf, size);
|
||||
ret = BSP_QSPI_Write_Safe((uint8_t *)tmp, (FLASH_FDB_REGION_START + offset), size);
|
||||
free(tmp);
|
||||
}
|
||||
return ret == 0 ? size : -1;
|
||||
}
|
||||
int sfd_onchip_erase (void* userdata, size_t offset, size_t size) {
|
||||
int ret = 0;
|
||||
ret = BSP_QSPI_Erase_Safe((FLASH_FDB_REGION_START + offset), size);
|
||||
return ret == 0 ? 0 : -1;
|
||||
}
|
||||
|
||||
int sfd_onchip_ioctl (void* userdata, size_t cmd, void* buff) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// #endif
|
||||
@@ -0,0 +1,14 @@
|
||||
|
||||
#include "common_api.h"
|
||||
|
||||
#include "luat_base.h"
|
||||
#include "luat_uart.h"
|
||||
#include "luat_msgbus.h"
|
||||
#include "luat_shell.h"
|
||||
|
||||
#define LUAT_LOG_TAG "usb"
|
||||
#include "luat_log.h"
|
||||
|
||||
void luat_shell_write(char* buff, size_t len) {
|
||||
luat_uart_write(LUAT_VUART_ID_0, buff, len);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
#include "luat_base.h"
|
||||
#include "luat_gpio.h"
|
||||
#include "luat_spi.h"
|
||||
|
||||
#define LUAT_WEAK __attribute__((weak))
|
||||
#define LUAT_SPI_CS_SELECT 0
|
||||
#define LUAT_SPI_CS_CLEAR 1
|
||||
|
||||
|
||||
// luat_spi_device_t* 在lua层看到的是一个userdata
|
||||
LUAT_WEAK int luat_spi_device_setup(luat_spi_device_t* spi_dev) {
|
||||
luat_spi_bus_setup(spi_dev);
|
||||
if (spi_dev->spi_config.cs != 255)
|
||||
luat_gpio_mode(spi_dev->spi_config.cs, Luat_GPIO_OUTPUT, Luat_GPIO_DEFAULT, Luat_GPIO_HIGH); // CS
|
||||
return 0;
|
||||
}
|
||||
|
||||
//关闭SPI设备,成功返回0
|
||||
LUAT_WEAK int luat_spi_device_close(luat_spi_device_t* spi_dev) {
|
||||
return luat_spi_close(spi_dev->bus_id);
|
||||
}
|
||||
|
||||
//收发SPI数据,返回接收字节数
|
||||
LUAT_WEAK int luat_spi_device_transfer(luat_spi_device_t* spi_dev, const char* send_buf, size_t send_length, char* recv_buf, size_t recv_length) {
|
||||
int ret = -1;
|
||||
luat_spi_device_config(spi_dev);
|
||||
if (spi_dev->spi_config.cs != 255)
|
||||
luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_SELECT);
|
||||
if (spi_dev->spi_config.mode){
|
||||
ret = luat_spi_transfer(spi_dev->bus_id, send_buf, send_length, recv_buf, recv_length);
|
||||
}else{
|
||||
ret = luat_spi_send(spi_dev->bus_id, send_buf, send_length);
|
||||
ret = luat_spi_recv(spi_dev->bus_id, recv_buf, recv_length);
|
||||
}
|
||||
if (spi_dev->spi_config.cs != 255)
|
||||
luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_CLEAR);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//收SPI数据,返回接收字节数
|
||||
LUAT_WEAK int luat_spi_device_recv(luat_spi_device_t* spi_dev, char* recv_buf, size_t length) {
|
||||
luat_spi_device_config(spi_dev);
|
||||
if (spi_dev->spi_config.cs != 255)
|
||||
luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_SELECT);
|
||||
int ret = luat_spi_recv(spi_dev->bus_id, recv_buf, length);
|
||||
if (spi_dev->spi_config.cs != 255)
|
||||
luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_CLEAR);
|
||||
return ret;
|
||||
}
|
||||
|
||||
//发SPI数据,返回发送字节数
|
||||
LUAT_WEAK int luat_spi_device_send(luat_spi_device_t* spi_dev, const char* send_buf, size_t length) {
|
||||
luat_spi_device_config(spi_dev);
|
||||
if (spi_dev->spi_config.cs != 255)
|
||||
luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_SELECT);
|
||||
int ret = luat_spi_send(spi_dev->bus_id, send_buf, length);
|
||||
if (spi_dev->spi_config.cs != 255)
|
||||
luat_gpio_set(spi_dev->spi_config.cs, LUAT_SPI_CS_CLEAR);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
#include "luat_network_adapter.h"
|
||||
#include "common_api.h"
|
||||
#include "luat_rtos.h"
|
||||
|
||||
static luat_rtos_task_handle g_s_task_handle;
|
||||
static network_ctrl_t *g_s_network_ctrl;
|
||||
static int32_t luat_test_socket_callback(void *pdata, void *param)
|
||||
{
|
||||
OS_EVENT *event = (OS_EVENT *)pdata;
|
||||
DBG("%x", event->ID);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void luat_test_task(void *param)
|
||||
{
|
||||
g_s_network_ctrl = network_alloc_ctrl(NW_ADAPTER_INDEX_LWIP_GPRS);
|
||||
network_init_ctrl(g_s_network_ctrl, g_s_task_handle, luat_test_socket_callback, NULL);
|
||||
network_set_base_mode(g_s_network_ctrl, 1, 15000, 1, 300, 5, 9);
|
||||
g_s_network_ctrl->is_debug = 1;
|
||||
const char remote_ip[] = "112.125.89.8";
|
||||
const char hello[] = "hello, luatos!";
|
||||
uint8_t *rx_data = malloc(1024);
|
||||
uint32_t tx_len, rx_len;
|
||||
int result;
|
||||
uint8_t is_break,is_timeout;
|
||||
while(1)
|
||||
{
|
||||
result = network_connect(g_s_network_ctrl, remote_ip, sizeof(remote_ip), NULL, 35948, 30000);
|
||||
DBG("%d", result);
|
||||
if (!result)
|
||||
{
|
||||
result = network_tx(g_s_network_ctrl, hello, sizeof(hello), 0, NULL, 0, &tx_len, 15000);
|
||||
DBG("%d", result);
|
||||
if (!result)
|
||||
{
|
||||
while(!result)
|
||||
{
|
||||
result = network_wait_rx(g_s_network_ctrl, 30000, &is_break, &is_timeout);
|
||||
DBG("%d", result);
|
||||
if (!result)
|
||||
{
|
||||
if (!is_timeout && !is_break)
|
||||
{
|
||||
do
|
||||
{
|
||||
result = network_rx(g_s_network_ctrl, rx_data, 1024, 0, NULL, NULL, &rx_len);
|
||||
DBG("%d", result);
|
||||
if (rx_len > 0)
|
||||
{
|
||||
network_tx(g_s_network_ctrl, rx_data, rx_len, 0, NULL, 0, &tx_len, 0);
|
||||
}
|
||||
}while(!result && rx_len > 0);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
network_close(g_s_network_ctrl, 5000);
|
||||
luat_rtos_task_sleep(15000);
|
||||
}
|
||||
}
|
||||
|
||||
static void luat_test_init(void)
|
||||
{
|
||||
luat_rtos_task_create(&g_s_task_handle, 2 * 1024, 10, "test", luat_test_task, NULL, 16);
|
||||
}
|
||||
|
||||
//INIT_TASK_EXPORT(luat_test_init, "1");
|
||||
@@ -0,0 +1,102 @@
|
||||
|
||||
#include "luat_base.h"
|
||||
#include "luat_malloc.h"
|
||||
#include "luat_timer.h"
|
||||
#include "luat_msgbus.h"
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "timers.h"
|
||||
#define LUAT_LOG_TAG "timer"
|
||||
#include "luat_log.h"
|
||||
|
||||
#define FREERTOS_TIMER_COUNT 64
|
||||
static luat_timer_t* timers[FREERTOS_TIMER_COUNT] __attribute__((aligned (16)));
|
||||
|
||||
static void luat_timer_callback(TimerHandle_t xTimer) {
|
||||
//LLOGD("timer callback");
|
||||
rtos_msg_t msg;
|
||||
size_t timer_id = (size_t)pvTimerGetTimerID(xTimer);
|
||||
luat_timer_t *timer = luat_timer_get(timer_id);
|
||||
if (timer == NULL)
|
||||
return;
|
||||
msg.handler = timer->func;
|
||||
msg.ptr = timer;
|
||||
msg.arg1 = timer_id;
|
||||
msg.arg2 = 0;
|
||||
luat_msgbus_put(&msg, 0);
|
||||
// int re = luat_msgbus_put(&msg, 0);
|
||||
//LLOGD("timer msgbus re=%ld", re);
|
||||
}
|
||||
|
||||
static int nextTimerSlot() {
|
||||
for (size_t i = 0; i < FREERTOS_TIMER_COUNT; i++)
|
||||
{
|
||||
if (timers[i] == NULL) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int luat_timer_start(luat_timer_t* timer) {
|
||||
TimerHandle_t os_timer;
|
||||
int timerIndex;
|
||||
//LLOGD(">>luat_timer_start timeout=%ld", timer->timeout);
|
||||
timerIndex = nextTimerSlot();
|
||||
if (timerIndex < 0) {
|
||||
LLOGE("too many timers");
|
||||
return 1; // too many timer!!
|
||||
}
|
||||
os_timer = xTimerCreate("luat_timer", timer->timeout, 0 == timer->repeat ? 0 : 1, (void*)(timer->id), luat_timer_callback);
|
||||
//LLOGD("timer id=%ld, osTimerNew=%p", timerIndex, os_timer);
|
||||
if (!os_timer) {
|
||||
LLOGE("xTimerCreate FAIL");
|
||||
return -1;
|
||||
}
|
||||
timers[timerIndex] = timer;
|
||||
|
||||
timer->os_timer = os_timer;
|
||||
int re = xTimerStart(os_timer, 5);
|
||||
//LLOGD("timer id=%ld timeout=%ld start=%ld", timerIndex, timer->timeout, re);
|
||||
if (re != pdPASS) {
|
||||
LLOGE("xTimerStart FAIL");
|
||||
xTimerDelete(os_timer, 5);
|
||||
timers[timerIndex] = NULL;
|
||||
}
|
||||
return re == pdPASS ? 0 : -1;
|
||||
}
|
||||
|
||||
int luat_timer_stop(luat_timer_t* timer) {
|
||||
if (timer == NULL || timer->os_timer == NULL)
|
||||
return 1;
|
||||
for (size_t i = 0; i < FREERTOS_TIMER_COUNT; i++)
|
||||
{
|
||||
if (timers[i] == timer) {
|
||||
timers[i] = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
xTimerStop((TimerHandle_t)timer->os_timer, 1);
|
||||
xTimerDelete((TimerHandle_t)timer->os_timer, 1);
|
||||
timer->os_timer = NULL;
|
||||
return 0;
|
||||
};
|
||||
|
||||
luat_timer_t* luat_timer_get(size_t timer_id) {
|
||||
for (size_t i = 0; i < FREERTOS_TIMER_COUNT; i++)
|
||||
{
|
||||
if (timers[i] && timers[i]->id == timer_id) {
|
||||
return timers[i];
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
int luat_timer_mdelay(size_t ms) {
|
||||
if (ms > 0) {
|
||||
vTaskDelay(ms);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "luat_base.h"
|
||||
#include "u8g2.h"
|
||||
#include "luat_u8g2.h"
|
||||
|
||||
uint8_t u8x8_luat_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
|
||||
uint8_t u8x8_luat_byte_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
|
||||
uint8_t u8x8_luat_byte_4wire_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
|
||||
|
||||
uint8_t u8x8_luat_gpio_and_delay_default(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
|
||||
uint8_t u8x8_luat_byte_hw_i2c_default(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
|
||||
uint8_t u8x8_luat_byte_4wire_hw_spi_default(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
|
||||
|
||||
int luat_u8g2_setup_default(luat_u8g2_conf_t *conf);
|
||||
|
||||
int luat_u8g2_setup(luat_u8g2_conf_t *conf) {
|
||||
return luat_u8g2_setup_default(conf);
|
||||
}
|
||||
|
||||
uint8_t u8x8_luat_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
|
||||
return u8x8_luat_gpio_and_delay_default(u8x8, msg, arg_int, arg_ptr);
|
||||
}
|
||||
|
||||
uint8_t u8x8_luat_byte_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
|
||||
return u8x8_luat_byte_hw_i2c_default(u8x8, msg, arg_int, arg_ptr);
|
||||
}
|
||||
|
||||
uint8_t u8x8_luat_byte_4wire_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
|
||||
return u8x8_luat_byte_4wire_hw_spi_default(u8x8, msg, arg_int, arg_ptr);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#include "luat_base.h"
|
||||
#include "luat_wdt.h"
|
||||
|
||||
|
||||
int luat_wdt_setup(size_t timeout);
|
||||
|
||||
int luat_wdt_init(size_t timeout) {
|
||||
return luat_wdt_setup(timeout);
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
#include "luat_base.h"
|
||||
#include "luat_wlan.h"
|
||||
#include "luat_rtos.h"
|
||||
|
||||
#include "common_api.h"
|
||||
#include "ps_lib_api.h"
|
||||
|
||||
#define WLAN_SCAN_DONE 1
|
||||
|
||||
static const SetWifiScanParams wifiscanreq = {
|
||||
.maxTimeOut = 10000,
|
||||
.round = 1,
|
||||
.maxBssidNum = CMI_DEV_MAX_WIFI_BSSID_NUM,
|
||||
.scanTimeOut = 5,
|
||||
.wifiPriority = 0
|
||||
};
|
||||
|
||||
static GetWifiScanInfo *pWifiScanInfo = PNULL;
|
||||
|
||||
static luat_rtos_task_handle wlan_task_handle;
|
||||
|
||||
static int l_wlan_handler(lua_State *L, void* ptr) {
|
||||
rtos_msg_t* msg = (rtos_msg_t*)lua_topointer(L, -1);
|
||||
int32_t event_id = msg->arg1;
|
||||
lua_getglobal(L, "sys_pub");
|
||||
switch (event_id)
|
||||
{
|
||||
case WLAN_SCAN_DONE:
|
||||
DBG("wifi scan done");
|
||||
lua_pushstring(L, "WLAN_SCAN_DONE");
|
||||
lua_call(L, 1, 0);
|
||||
break;
|
||||
default:
|
||||
DBG("unkown event %d", event_id);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void wlan_task(void *param){
|
||||
rtos_msg_t msg = {0};
|
||||
msg.handler = l_wlan_handler;
|
||||
msg.arg1 = WLAN_SCAN_DONE;
|
||||
if (pWifiScanInfo == NULL)
|
||||
pWifiScanInfo = (GetWifiScanInfo *)malloc(sizeof(GetWifiScanInfo));
|
||||
if (pWifiScanInfo) {
|
||||
memset(pWifiScanInfo, 0, sizeof(GetWifiScanInfo));
|
||||
appGetWifiScanInfo(&wifiscanreq, pWifiScanInfo);
|
||||
luat_msgbus_put(&msg, 0);
|
||||
}
|
||||
else {
|
||||
DBG("out of memory when malloc GetWifiScanInfo");
|
||||
}
|
||||
luat_rtos_task_delete(wlan_task_handle);
|
||||
}
|
||||
|
||||
int luat_wlan_init(luat_wlan_config_t *conf){
|
||||
DBG("wifi support scan only");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_wlan_scan(void){
|
||||
if (luat_rtos_task_create(&wlan_task_handle, 2048, 20, "wlan", wlan_task, NULL, NULL)){
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luat_wlan_scan_get_result(luat_wlan_scan_result_t *results, int ap_limit){
|
||||
if (pWifiScanInfo == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (ap_limit > pWifiScanInfo->bssidNum){
|
||||
ap_limit = pWifiScanInfo->bssidNum;
|
||||
}
|
||||
for (size_t i = 0; i < ap_limit; i++){
|
||||
memcpy(results[i].ssid, pWifiScanInfo->ssidHex[i], pWifiScanInfo->ssidHexLen[i]);
|
||||
memcpy(results[i].bssid, pWifiScanInfo->bssid[i], 6);
|
||||
results[i].rssi = pWifiScanInfo->rssi[i];
|
||||
}
|
||||
return ap_limit;
|
||||
}
|
||||
233
sdk/合宙/air780e/csdk/luatos-soc-2022/project/luatos/xmake.lua
Normal file
233
sdk/合宙/air780e/csdk/luatos-soc-2022/project/luatos/xmake.lua
Normal file
@@ -0,0 +1,233 @@
|
||||
local TARGET_NAME = "luatos"
|
||||
local LIB_DIR = "$(buildir)/".. TARGET_NAME .. "/"
|
||||
local LIB_NAME = "lib" .. TARGET_NAME .. ".a "
|
||||
|
||||
local LUATOS_ROOT = SDK_TOP .. "/../LuatOS/"
|
||||
|
||||
target(TARGET_NAME)
|
||||
set_kind("static")
|
||||
set_targetdir(LIB_DIR)
|
||||
add_includedirs(SDK_TOP .. "/PLAT/core/tts/include/16k_lite_ver",{public = true}) --为了编译通过而已
|
||||
LIB_USER = LIB_USER .. SDK_TOP .. "/PLAT/core/lib/libaisound50_16K.a "
|
||||
--8K版本用下面的库,注释掉16K的库
|
||||
-- LIB_USER = LIB_USER .. SDK_TOP .. "/PLAT/core/lib/libaisound50_8K.a "
|
||||
--加入代码和头文件
|
||||
add_includedirs("./inc",{public = true})
|
||||
-- add_includedirs(SDK_TOP .. "/interface/private_include",
|
||||
-- {public = true})
|
||||
add_files("./src/*.c",{public = true})
|
||||
add_files(SDK_TOP .. "interface/src/*.c",{public = true})
|
||||
|
||||
add_includedirs(LUATOS_ROOT .. "lua/include")
|
||||
add_includedirs(LUATOS_ROOT .. "luat/include")
|
||||
add_includedirs(LUATOS_ROOT .. "components/cmux")
|
||||
add_includedirs(LUATOS_ROOT .. "components/cjson")
|
||||
add_includedirs(LUATOS_ROOT .. "components/fatfs")
|
||||
add_includedirs(LUATOS_ROOT .. "components/shell")
|
||||
|
||||
|
||||
add_files(LUATOS_ROOT .. "lua/src/*.c")
|
||||
add_files(LUATOS_ROOT .. "luat/modules/*.c")
|
||||
add_files(LUATOS_ROOT .. "luat/vfs/*.c")
|
||||
add_files(LUATOS_ROOT .. "components/cmux/*.c")
|
||||
add_files(LUATOS_ROOT .. "components/cjson/*.c")
|
||||
add_files(LUATOS_ROOT .. "components/crypto/*.c")
|
||||
|
||||
-- gtfont
|
||||
add_includedirs(LUATOS_ROOT.."components/gtfont")
|
||||
add_files(LUATOS_ROOT.."components/gtfont/*.c")
|
||||
LIB_USER = LIB_USER .. SDK_TOP .. "/lib/libgt.a "
|
||||
|
||||
-- coremark
|
||||
add_files(LUATOS_ROOT .. "components/coremark/*.c")
|
||||
add_includedirs(LUATOS_ROOT .. "components/coremark")
|
||||
|
||||
-- lua-cjson
|
||||
add_files(LUATOS_ROOT .. "components/lua-cjson/*.c")
|
||||
add_includedirs(LUATOS_ROOT .. "components/lua-cjson")
|
||||
|
||||
-- miniz
|
||||
add_files(LUATOS_ROOT .. "components/miniz/*.c")
|
||||
add_includedirs(LUATOS_ROOT .. "components/miniz")
|
||||
|
||||
-- protobuf
|
||||
add_includedirs(LUATOS_ROOT.."components/serialization/protobuf")
|
||||
add_files(LUATOS_ROOT.."components/serialization/protobuf/*.c")
|
||||
|
||||
-- fdb
|
||||
add_includedirs(SDK_TOP.."thirdparty/fal/inc")
|
||||
add_includedirs(SDK_TOP.."thirdparty/flashdb/inc")
|
||||
add_files(SDK_TOP.."thirdparty/fal/src/*.c")
|
||||
add_files(SDK_TOP.."thirdparty/flashdb/src/*.c")
|
||||
add_files(LUATOS_ROOT.."components/flashdb/src/luat_lib_fdb.c")
|
||||
|
||||
-- rsa
|
||||
add_files(LUATOS_ROOT.."components/rsa/**.c")
|
||||
|
||||
-- iotauth
|
||||
-- add_includedirs(LUATOS_ROOT.."components/iotauth")
|
||||
add_files(LUATOS_ROOT.."components/iotauth/**.c")
|
||||
|
||||
-- sfud
|
||||
add_includedirs(LUATOS_ROOT.."components/sfud")
|
||||
add_files(LUATOS_ROOT.."components/sfud/**.c")
|
||||
|
||||
-- fatfs
|
||||
add_includedirs(LUATOS_ROOT.."components/fatfs")
|
||||
add_files(LUATOS_ROOT.."components/fatfs/**.c")
|
||||
|
||||
-- libgnss
|
||||
add_includedirs(LUATOS_ROOT .. "components/minmea")
|
||||
add_files(LUATOS_ROOT.."components/minmea/**.c")
|
||||
|
||||
add_files(LUATOS_ROOT.."components/mlx90640-library/*.c")
|
||||
add_includedirs(LUATOS_ROOT.."components/mlx90640-library")
|
||||
|
||||
--------------------------------------------------------------
|
||||
-- UI类的,能不能用另说, 先加上吧
|
||||
|
||||
add_includedirs(LUATOS_ROOT.."lua/include")
|
||||
add_includedirs(LUATOS_ROOT.."luat/include")
|
||||
add_includedirs(LUATOS_ROOT.."components/lcd")
|
||||
add_includedirs(LUATOS_ROOT.."components/tjpgd")
|
||||
add_includedirs(LUATOS_ROOT.."components/eink")
|
||||
add_includedirs(LUATOS_ROOT.."components/epaper")
|
||||
add_includedirs(LUATOS_ROOT.."components/u8g2")
|
||||
add_includedirs(LUATOS_ROOT.."components/gtfont")
|
||||
add_includedirs(LUATOS_ROOT.."components/qrcode")
|
||||
|
||||
add_includedirs(LUATOS_ROOT.."components/lvgl")
|
||||
add_includedirs(LUATOS_ROOT.."components/lvgl/binding")
|
||||
add_includedirs(LUATOS_ROOT.."components/lvgl/gen")
|
||||
add_includedirs(LUATOS_ROOT.."components/lvgl/src")
|
||||
add_includedirs(LUATOS_ROOT.."components/lvgl/font")
|
||||
add_includedirs(LUATOS_ROOT.."components/lvgl/src/lv_font")
|
||||
|
||||
-- lvgl
|
||||
add_files(LUATOS_ROOT.."components/lvgl/**.c")
|
||||
-- 默认不编译lv的demos, 节省大量的编译时间
|
||||
remove_files(LUATOS_ROOT.."components/lvgl/lv_demos/**.c")
|
||||
|
||||
-- eink
|
||||
add_files(LUATOS_ROOT.."components/eink/*.c")
|
||||
add_files(LUATOS_ROOT.."components/epaper/*.c")
|
||||
remove_files(LUATOS_ROOT.."components/epaper/GUI_Paint.c")
|
||||
|
||||
-- u8g2
|
||||
add_files(LUATOS_ROOT.."components/u8g2/*.c")
|
||||
|
||||
-- lcd
|
||||
add_files(LUATOS_ROOT.."components/lcd/*.c")
|
||||
add_files(LUATOS_ROOT.."components/tjpgd/*.c")
|
||||
add_files(LUATOS_ROOT.."components/qrcode/*.c")
|
||||
|
||||
|
||||
-- network
|
||||
add_includedirs(LUATOS_ROOT .. "components/ethernet/common")
|
||||
add_includedirs(LUATOS_ROOT .. "components/common")
|
||||
add_includedirs(LUATOS_ROOT .. "components/network/adapter")
|
||||
add_includedirs(LUATOS_ROOT .. "components/mbedtls/include", {public = true})
|
||||
add_includedirs(LUATOS_ROOT .. "components/mbedtls/library", {public = true})
|
||||
add_files(LUATOS_ROOT .. "components/ethernet/common/*.c")
|
||||
add_files(LUATOS_ROOT .. "components/network/adapter/*.c")
|
||||
add_files(LUATOS_ROOT .. "components/mbedtls/library/*.c")
|
||||
|
||||
-- mqtt
|
||||
add_includedirs(LUATOS_ROOT.."components/network/libemqtt")
|
||||
add_files(LUATOS_ROOT.."components/network/libemqtt/*.c")
|
||||
|
||||
-- http
|
||||
add_includedirs(LUATOS_ROOT.."components/network/libhttp")
|
||||
-- add_files(LUATOS_ROOT.."components/network/libhttp/luat_lib_http.c")
|
||||
add_files(LUATOS_ROOT.."components/network/libhttp/luat_http_client.c")
|
||||
|
||||
-- http_parser
|
||||
add_includedirs(LUATOS_ROOT.."components/network/http_parser")
|
||||
add_files(LUATOS_ROOT.."components/network/http_parser/*.c")
|
||||
|
||||
-- websocket
|
||||
add_includedirs(LUATOS_ROOT.."components/network/websocket")
|
||||
add_files(LUATOS_ROOT.."components/network/websocket/*.c")
|
||||
|
||||
-- errdump
|
||||
add_includedirs(LUATOS_ROOT.."components/network/errdump")
|
||||
add_files(LUATOS_ROOT.."components/network/errdump/*.c")
|
||||
|
||||
-- iotauth
|
||||
add_files(LUATOS_ROOT.."components/iotauth/luat_lib_iotauth.c")
|
||||
|
||||
-- mobile
|
||||
add_includedirs(LUATOS_ROOT.."components/mobile")
|
||||
add_files(LUATOS_ROOT.."components/mobile/*.c")
|
||||
|
||||
|
||||
-- shell
|
||||
add_files(LUATOS_ROOT.."components/shell/*.c")
|
||||
|
||||
-- i2c-tools
|
||||
add_includedirs(LUATOS_ROOT.."components/i2c-tools")
|
||||
add_files(LUATOS_ROOT.."components/i2c-tools/*.c")
|
||||
|
||||
-- lora
|
||||
add_includedirs(LUATOS_ROOT.."components/lora/sx126x")
|
||||
add_files(LUATOS_ROOT.."components/lora/**.c")
|
||||
|
||||
|
||||
-- fonts
|
||||
add_includedirs(LUATOS_ROOT.."components/luatfonts")
|
||||
add_files(LUATOS_ROOT.."components/luatfonts/**.c")
|
||||
|
||||
|
||||
-- wlan
|
||||
add_includedirs(LUATOS_ROOT.."components/wlan")
|
||||
add_files(LUATOS_ROOT.."components/wlan/**.c")
|
||||
-- audio
|
||||
add_includedirs(LUATOS_ROOT.."components/multimedia/")
|
||||
add_includedirs(LUATOS_ROOT.."components/multimedia/mp3_decode")
|
||||
add_includedirs(LUATOS_ROOT.."components/multimedia/amr_decode/amr_common/dec/include")
|
||||
add_includedirs(LUATOS_ROOT.."components/multimedia/amr_decode/amr_nb/common/include")
|
||||
add_includedirs(LUATOS_ROOT.."components/multimedia/amr_decode/amr_nb/dec/include")
|
||||
add_includedirs(LUATOS_ROOT.."components/multimedia/amr_decode/amr_wb/dec/include")
|
||||
add_includedirs(LUATOS_ROOT.."components/multimedia/amr_decode/opencore-amrnb")
|
||||
add_includedirs(LUATOS_ROOT.."components/multimedia/amr_decode/opencore-amrwb")
|
||||
add_includedirs(LUATOS_ROOT.."components/multimedia/amr_decode/oscl")
|
||||
add_includedirs(LUATOS_ROOT.."components/multimedia/amr_decode/amr_nb/enc/src")
|
||||
add_files(LUATOS_ROOT.."components/multimedia/**.c")
|
||||
------------------------------------------------------------
|
||||
------------------------------------------------------------
|
||||
-- sms
|
||||
add_includedirs(LUATOS_ROOT.."components/sms")
|
||||
add_files(LUATOS_ROOT.."components/sms/*.c")
|
||||
|
||||
-- hmeta
|
||||
add_includedirs(LUATOS_ROOT.."components/hmeta")
|
||||
add_files(LUATOS_ROOT.."components/hmeta/*.c")
|
||||
|
||||
-- profiler
|
||||
add_includedirs(LUATOS_ROOT.."components/mempool/profiler/include")
|
||||
add_files(LUATOS_ROOT.."components/mempool/profiler/**.c")
|
||||
|
||||
-- hmeta
|
||||
add_includedirs(LUATOS_ROOT.."components/fskv")
|
||||
add_files(LUATOS_ROOT.."components/fskv/*.c")
|
||||
|
||||
-- sntp
|
||||
add_includedirs(LUATOS_ROOT.."components/network/libsntp")
|
||||
add_files(LUATOS_ROOT.."components/network/libsntp/*.c")
|
||||
|
||||
-- libftp
|
||||
add_includedirs(LUATOS_ROOT.."components/network/libftp")
|
||||
add_files(LUATOS_ROOT.."components/network/libftp/*.c")
|
||||
|
||||
-- sfd
|
||||
add_includedirs(LUATOS_ROOT.."components/sfd")
|
||||
add_files(LUATOS_ROOT.."components/sfd/*.c")
|
||||
|
||||
|
||||
-- 作为最后补充, 不然总是报主库没有的头文件
|
||||
add_includedirs(SDK_TOP .. "interface/include")
|
||||
|
||||
--自动链接
|
||||
LIB_USER = LIB_USER .. SDK_TOP .. LIB_DIR .. LIB_NAME .. " "
|
||||
--甚至可以加入自己的库
|
||||
target_end()
|
||||
Reference in New Issue
Block a user