mirror of
https://gitee.com/beecue/fastbee.git
synced 2025-12-21 10:25:54 +08:00
更新硬件SDK
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
目前demo中aes和des测试需要到仓库根目录下将下面宏控代码添加进xmake.lua
|
||||
|
||||
add_defines("MBEDTLS_CIPHER_MODE_CBC",{public = true})
|
||||
add_defines("MBEDTLS_CIPHER_MODE_CFB",{public = true})
|
||||
add_defines("MBEDTLS_CIPHER_MODE_CTR",{public = true})
|
||||
add_defines("MBEDTLS_CIPHER_MODE_OFB",{public = true})
|
||||
add_defines("MBEDTLS_CIPHER_MODE_XTS",{public = true})
|
||||
|
||||
@@ -0,0 +1,350 @@
|
||||
#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 POLLING_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_PIN28}, // 0 : gpio13 / 2 : I2C0 SCL
|
||||
// { PAD_PIN27}, // 0 : gpio12 / 2 : I2C0 SDA
|
||||
#define RTE_I2C0_SCL_BIT 28 // AUDIO use 28
|
||||
#define RTE_I2C0_SCL_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_I2C0_SDA_BIT 27 // AUDIO use 27
|
||||
#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 1
|
||||
#define RTE_UART1_RTS_PIN_EN 1
|
||||
|
||||
// { 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_PIN21}, // 0 : gpio16 / 1 : UART1 RTS / 2 : SPI0 SSn
|
||||
// { PAD_PIN22}, // 0 : gpio11 / 1 : UART1 CTS / 2 : SPI0 MOSI
|
||||
// { PAD_PIN23}, // 0 : gpio14 / 1 : UART1 RXD / 2 : SPI0 MISO
|
||||
// { PAD_PIN24}, // 0 : gpio15 / 1 : UART1 TXD / 2 : SPI0 SCLK
|
||||
#define RTE_SPI0_SSN_BIT 21
|
||||
#define RTE_SPI0_SSN_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_SPI0_MOSI_BIT 22
|
||||
#define RTE_SPI0_MOSI_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_SPI0_MISO_BIT 23
|
||||
#define RTE_SPI0_MISO_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_SPI0_SCLK_BIT 24
|
||||
#define RTE_SPI0_SCLK_FUNC PAD_MUX_ALT2
|
||||
|
||||
#define RTE_SPI0_SSN_GPIO_INSTANCE 1
|
||||
#define RTE_SPI0_SSN_GPIO_INDEX 0
|
||||
|
||||
// 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 1
|
||||
|
||||
// { PAD_PIN13}, // 0 : gpio2 / 1 : UART0 RTSn / 3 : SPI1 SSn
|
||||
// { PAD_PIN14}, // 0 : gpio3 / 1 : UART0 CTSn / 3 : SPI1 MOSI
|
||||
// { PAD_PIN15}, // 0 : gpio4 / 1 : UART0 RXD / 3 : SPI1 MISO
|
||||
// { PAD_PIN16}, // 0 : gpio5 / 1 : UART0 TXD / 3 : SPI1 SCLK
|
||||
#define RTE_SPI1_SSN_BIT 13
|
||||
#define RTE_SPI1_SSN_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_SPI1_MOSI_BIT 14
|
||||
#define RTE_SPI1_MOSI_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_SPI1_MISO_BIT 15
|
||||
#define RTE_SPI1_MISO_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_SPI1_SCLK_BIT 16
|
||||
#define RTE_SPI1_SCLK_FUNC PAD_MUX_ALT3
|
||||
|
||||
#define RTE_SPI1_SSN_GPIO_INSTANCE 0
|
||||
#define RTE_SPI1_SSN_GPIO_INDEX 2
|
||||
|
||||
// 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
|
||||
|
||||
#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,220 @@
|
||||
/*
|
||||
* 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 "luat_rtos.h"
|
||||
#include "luat_mem.h"
|
||||
#include "luat_debug.h"
|
||||
|
||||
luat_rtos_task_handle task_handle;
|
||||
|
||||
#include "cJSON.h"
|
||||
|
||||
|
||||
#define FILE_LENGTH 520
|
||||
|
||||
void test_json_1(char* json_data)
|
||||
{
|
||||
|
||||
LUAT_DEBUG_PRINT("######## Test 12 ########\n");
|
||||
cJSON_Minify(json_data);
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", json_data);
|
||||
|
||||
// test 01
|
||||
cJSON* root = cJSON_Parse(json_data);
|
||||
cJSON* format = cJSON_GetObjectItemCaseSensitive(root, "format");
|
||||
cJSON* framerate_item = cJSON_GetObjectItemCaseSensitive(format, "frame rate");
|
||||
double framerate = 0;
|
||||
if(cJSON_IsNumber(framerate_item)) {
|
||||
framerate = framerate_item->valuedouble;
|
||||
}
|
||||
|
||||
LUAT_DEBUG_PRINT("######## Test START ########\n");
|
||||
|
||||
// test 02
|
||||
cJSON_SetNumberValue(framerate_item, 25);
|
||||
char* rendered = cJSON_Print(root);
|
||||
|
||||
LUAT_DEBUG_PRINT("######## Test 02 ########\n");
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", rendered);
|
||||
|
||||
LUAT_DEBUG_PRINT("######## Test 07 ########\n");
|
||||
LUAT_DEBUG_PRINT("root json size = %d\n", cJSON_GetArraySize(root));
|
||||
LUAT_DEBUG_PRINT("format json size = %d\n", cJSON_GetArraySize(format));
|
||||
|
||||
LUAT_DEBUG_PRINT("######## Test 08 ########\n");
|
||||
cJSON *json_item1 = cJSON_GetArrayItem(root, 0);
|
||||
cJSON *json_item2 = cJSON_GetArrayItem(root, 1);
|
||||
LUAT_DEBUG_PRINT("json_item1 data = %s\n", cJSON_Print(json_item1));
|
||||
LUAT_DEBUG_PRINT("json_item2 data = %s\n", cJSON_Print(json_item2));
|
||||
|
||||
LUAT_DEBUG_PRINT("######## Test 09 ########\n");
|
||||
cJSON* format1 = cJSON_GetObjectItem(root, "format");
|
||||
cJSON* framerate_item1 = cJSON_GetObjectItem(format1, "frame rate");
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", cJSON_Print(format1));
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", cJSON_Print(framerate_item1));
|
||||
|
||||
LUAT_DEBUG_PRINT("######## Test 10 ########\n");
|
||||
cJSON_bool isHasItem1 = cJSON_HasObjectItem(root, "format");
|
||||
cJSON_bool isHasItem2 = cJSON_HasObjectItem(root, "formai");
|
||||
LUAT_DEBUG_PRINT("has format item = %d\n", (int)isHasItem1);
|
||||
LUAT_DEBUG_PRINT("has formai item = %d\n", (int)isHasItem2);
|
||||
|
||||
LUAT_DEBUG_PRINT("######## Test 11 ########\n");
|
||||
cJSON* cjson_null = cJSON_CreateNull();
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", cJSON_Print(cjson_null));
|
||||
LUAT_DEBUG_PRINT("json data is null or not = %d\n", (int)cJSON_IsNull(cjson_null));
|
||||
cJSON_Delete(cjson_null);
|
||||
|
||||
cJSON* cjson_true = cJSON_CreateTrue();
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", cJSON_Print(cjson_true));
|
||||
LUAT_DEBUG_PRINT("json data is true or not = %d\n", (int)cJSON_IsTrue(cjson_true));
|
||||
cJSON_Delete(cjson_true);
|
||||
|
||||
cJSON* cjson_false = cJSON_CreateFalse();
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", cJSON_Print(cjson_false));
|
||||
LUAT_DEBUG_PRINT("json data is false or not = %d\n", (int)cJSON_IsFalse(cjson_false));
|
||||
cJSON_Delete(cjson_false);
|
||||
|
||||
|
||||
cJSON_bool bool_type = (cJSON_bool)1;
|
||||
cJSON* cjson_bool = cJSON_CreateBool(bool_type);
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", cJSON_Print(cjson_bool));
|
||||
LUAT_DEBUG_PRINT("json data is bool or not = %d\n", (int)cJSON_IsBool(cjson_bool));
|
||||
cJSON_Delete(cjson_bool);
|
||||
|
||||
double number_type = 88;
|
||||
cJSON* cjson_number = cJSON_CreateNumber(number_type);
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", cJSON_Print(cjson_number));
|
||||
LUAT_DEBUG_PRINT("json data is number or not = %d\n", (int)cJSON_IsNumber(cjson_number));
|
||||
cJSON_Delete(cjson_number);
|
||||
|
||||
char* string_type = "Welcome to luatOS";
|
||||
cJSON* cjson_string = cJSON_CreateString(string_type);
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", cJSON_Print(cjson_string));
|
||||
LUAT_DEBUG_PRINT("json data is string or not = %d\n", (int)cJSON_IsString(cjson_string));
|
||||
cJSON_Delete(cjson_string);
|
||||
|
||||
char* raw_type = "Welcome to luatOS raw";
|
||||
cJSON* cjson_raw = cJSON_CreateRaw(raw_type);
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", cJSON_Print(cjson_raw));
|
||||
LUAT_DEBUG_PRINT("json data is raw or not = %d\n", (int)cJSON_IsRaw(cjson_raw));
|
||||
cJSON_Delete(cjson_raw);
|
||||
|
||||
cJSON* cjson_array = cJSON_CreateArray();
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", cJSON_Print(cjson_array));
|
||||
LUAT_DEBUG_PRINT("json data is array or not = %d\n", (int)cJSON_IsArray(cjson_array));
|
||||
cJSON_Delete(cjson_array);
|
||||
|
||||
cJSON* cjson_object = cJSON_CreateObject();
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", cJSON_Print(cjson_object));
|
||||
LUAT_DEBUG_PRINT("json data is object or not = %d\n", (int)cJSON_IsObject(cjson_object));
|
||||
cJSON_Delete(cjson_object);
|
||||
|
||||
char* rendered1 = cJSON_Print(root);
|
||||
|
||||
LUAT_DEBUG_PRINT("######## Test ########\n");
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", rendered1);
|
||||
|
||||
}
|
||||
|
||||
void test_json_2()
|
||||
{
|
||||
cJSON *root;
|
||||
cJSON *fmt;
|
||||
root = cJSON_CreateObject();
|
||||
cJSON_AddItemToObject(root, "name", cJSON_CreateString("Jack (\"Bee\") Nimble"));
|
||||
cJSON_AddItemToObject(root, "format", fmt = cJSON_CreateObject());
|
||||
cJSON_AddStringToObject(fmt, "type", "rect");
|
||||
cJSON_AddNumberToObject(fmt, "width", 1920);
|
||||
cJSON_AddNumberToObject(fmt, "height", 1080);
|
||||
cJSON_AddFalseToObject(fmt, "interlace");
|
||||
cJSON_AddNumberToObject(fmt, "frame rate", 24);
|
||||
|
||||
char* result = cJSON_Print(root);
|
||||
LUAT_DEBUG_PRINT("######## Test 03 ########\n");
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", result);
|
||||
|
||||
LUAT_DEBUG_PRINT("######## Test 04 ########\n");
|
||||
LUAT_DEBUG_PRINT("json version = %s\n", cJSON_Version());
|
||||
|
||||
LUAT_DEBUG_PRINT("######## Test 05 ########\n");
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", cJSON_PrintUnformatted(root));
|
||||
|
||||
LUAT_DEBUG_PRINT("######## Test 12 ########\n");
|
||||
cJSON_AddNullToObject(root, "null");
|
||||
cJSON_AddTrueToObject(root, "true");
|
||||
cJSON_AddFalseToObject(root, "false");
|
||||
cJSON_AddBoolToObject(root, "bool", 1);
|
||||
cJSON_AddNumberToObject(root, "number", 88);
|
||||
cJSON_AddStringToObject(root, "string", "Welcome to luatOS");
|
||||
cJSON_AddRawToObject(root, "Raw", "Welcome to luatOS raw");
|
||||
LUAT_DEBUG_PRINT("json data = %s\n", cJSON_Print(root));
|
||||
}
|
||||
|
||||
|
||||
static void demo_init_cjson()
|
||||
{
|
||||
LUAT_DEBUG_PRINT("==================cjson is running==================");
|
||||
LUAT_DEBUG_PRINT("The cJSON version: %s", cJSON_Version());
|
||||
|
||||
char json_data[FILE_LENGTH] = "{\"name\": \"Jack Nimble\",\"format\": \
|
||||
{\"type\":\"rect\",\"width\":1920,\"height\":1080,\"interlace\": false,\"frame rate\": 24}}";
|
||||
|
||||
LUAT_DEBUG_PRINT("json_data = %s\n", json_data);
|
||||
|
||||
char json_test[] = "{\"class\":\"paymsg\",\"data\":{\"sn\":\"30000001\",\"type\":\"alipay\",\"content\":\"1326545647980439\",\"uuid\":\"1b56093bf93f493e904fcbeccbf0a0d0\",\"suffix\":15645548.39}}";
|
||||
|
||||
cJSON_Minify(json_test);
|
||||
LUAT_DEBUG_PRINT("---- %s", json_test);
|
||||
cJSON * a = cJSON_Parse(json_test);
|
||||
cJSON_AddLongLongToObject(a, "testlonglong", 1670751410618);
|
||||
LUAT_DEBUG_PRINT("---- %s", cJSON_Print(a));
|
||||
|
||||
|
||||
// test
|
||||
test_json_1(json_data);
|
||||
test_json_2();
|
||||
}
|
||||
|
||||
|
||||
static void task(void *param)
|
||||
{
|
||||
luat_rtos_task_sleep(1000);
|
||||
demo_init_cjson();
|
||||
|
||||
while(1)
|
||||
{
|
||||
luat_rtos_task_sleep(1000);
|
||||
LUAT_DEBUG_PRINT("==================cjson is done==================");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void task_demoE_init(void)
|
||||
{
|
||||
luat_rtos_task_create(&task_handle, 5*1024, 50, "task", task, NULL, 0);
|
||||
}
|
||||
|
||||
|
||||
//启动task_demoE_init,启动位置任务1级
|
||||
INIT_TASK_EXPORT(task_demoE_init, "1");
|
||||
@@ -0,0 +1,28 @@
|
||||
local TARGET_NAME = "example_cjson"
|
||||
local LIB_DIR = "$(buildir)/".. TARGET_NAME .. "/"
|
||||
local LIB_NAME = "lib" .. TARGET_NAME .. ".a "
|
||||
|
||||
target(TARGET_NAME)
|
||||
set_kind("static")
|
||||
set_targetdir(LIB_DIR)
|
||||
|
||||
--加入代码和头文件
|
||||
add_includedirs("./inc",{public = true})
|
||||
add_includedirs(SDK_TOP .. "/thirdparty/cJSON")
|
||||
add_files(SDK_TOP .. "/thirdparty/cJSON/**.c")
|
||||
add_files("./src/**.c")
|
||||
--路径可以随便写,可以加任意路径的代码,下面代码等效上方代码
|
||||
-- add_includedirs(SDK_TOP .. "project/" .. TARGET_NAME .. "/inc",{public = true})
|
||||
-- add_files(SDK_TOP .. "project/" .. TARGET_NAME .. "/src/*.c",{public = true})
|
||||
-- add_defines("MBEDTLS_TCPIP_LWIP",{public = true})
|
||||
-- 按需链接mbedtls
|
||||
-- add_defines("MBEDTLS_CONFIG_FILE=\"config_ec_ssl_comm.h\"")
|
||||
-- add_files(SDK_TOP .. "PLAT/middleware/thirdparty/mbedtls/library/*.c")
|
||||
-- 按需编译httpclient
|
||||
-- add_files(SDK_TOP .. "PLAT/middleware/thirdparty/httpclient/*.c")
|
||||
|
||||
--可以继续增加add_includedirs和add_files
|
||||
--自动链接
|
||||
LIB_USER = LIB_USER .. SDK_TOP .. LIB_DIR .. LIB_NAME
|
||||
--甚至可以加入自己的库
|
||||
target_end()
|
||||
Reference in New Issue
Block a user