forked from xuos/xiuos
Merge branch 'prepare_for_master' of https://gitlink.org.cn/xuos/xiuos into prepare_for_master
This commit is contained in:
@@ -2,7 +2,7 @@ include $(KERNEL_ROOT)/.config
|
||||
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += framework_init.c
|
||||
CSRCS +=
|
||||
include $(APPDIR)/Application.mk
|
||||
endif
|
||||
|
||||
@@ -10,7 +10,7 @@ endif
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_DIR := general_functions app_test
|
||||
|
||||
SRC_FILES := main.c framework_init.c
|
||||
SRC_FILES := main.c
|
||||
ifeq ($(CONFIG_LIB_LV),y)
|
||||
SRC_DIR += lv_app
|
||||
endif
|
||||
|
||||
@@ -164,7 +164,7 @@ void TcpSocketRecvTest(int argc, char *argv[])
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip);
|
||||
lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, tcp_socket_ip);
|
||||
sys_thread_new("TcpSocketRecvTask", TcpSocketRecvTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
#endif
|
||||
|
||||
@@ -231,7 +231,7 @@ void TcpSocketSendTest(int argc, char *argv[])
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, tcp_socket_ip);
|
||||
lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, tcp_socket_ip);
|
||||
sys_thread_new("Tcp Socket Send", TcpSocketSendTask, NULL, LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
#endif
|
||||
#ifdef ADD_NUTTX_FETURES
|
||||
|
||||
@@ -144,7 +144,7 @@ void UdpSocketRecvTest(int argc, char *argv[])
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip);
|
||||
lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, udp_socket_ip);
|
||||
sys_thread_new("UdpSocketRecvTask", UdpSocketRecvTask, NULL,
|
||||
LWIP_TASK_STACK_SIZE, LWIP_DEMO_TASK_PRIO);
|
||||
#endif
|
||||
@@ -207,7 +207,7 @@ void UdpSocketSendTest(int argc, char *argv[])
|
||||
}
|
||||
|
||||
#ifdef ADD_XIZI_FETURES
|
||||
lwip_config_tcp(lwip_ipaddr, lwip_netmask, udp_socket_ip);
|
||||
lwip_config_tcp(0, lwip_ipaddr, lwip_netmask, udp_socket_ip);
|
||||
sys_thread_new("UdpSocketSendTask", UdpSocketSendTask, NULL, LWIP_TASK_STACK_SIZE,
|
||||
LWIP_DEMO_TASK_PRIO);
|
||||
#endif
|
||||
|
||||
@@ -18,6 +18,32 @@
|
||||
* @date 2022.9.27
|
||||
*/
|
||||
|
||||
#include <control.h>
|
||||
|
||||
void ControlOmronTest(void)
|
||||
{
|
||||
int i = 0;
|
||||
uint16_t read_data_length = 0;
|
||||
uint8_t read_data[1024] = {0};
|
||||
ControlProtocolType fins_protocol = ControlProtocolFind();
|
||||
if (NULL == fins_protocol) {
|
||||
printf("%s get fins protocol %p failed\n", __func__, fins_protocol);
|
||||
return;
|
||||
}
|
||||
|
||||
printf("%s get fins protocol %p successfull\n", __func__, fins_protocol);
|
||||
|
||||
if (CONTROL_REGISTERED == fins_protocol->protocol_status) {
|
||||
ControlProtocolOpen(fins_protocol);
|
||||
|
||||
for (;;) {
|
||||
read_data_length = ControlProtocolRead(fins_protocol, read_data, sizeof(read_data));
|
||||
printf("%s read [%d] fins data %d using receipe file\n", __func__, i, read_data_length);
|
||||
i++;
|
||||
PrivTaskDelay(100000);
|
||||
}
|
||||
|
||||
//ControlProtocolClose(fins_protocol);
|
||||
}
|
||||
}
|
||||
PRIV_SHELL_CMD_FUNCTION(ControlOmronTest, Omron Plc FINS Demo, PRIV_SHELL_CMD_MAIN_ATTR);
|
||||
|
||||
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
|
||||
extern int SensorFrameworkInit(void);
|
||||
extern int AdapterFrameworkInit(void);
|
||||
|
||||
extern int Adapter4GInit(void);
|
||||
extern int AdapterNbiotInit(void);
|
||||
extern int AdapterBlueToothInit(void);
|
||||
extern int AdapterWifiInit(void);
|
||||
extern int AdapterEthernetInit(void);
|
||||
extern int AdapterEthercatInit(void);
|
||||
extern int AdapterZigbeeInit(void);
|
||||
extern int AdapterLoraInit(void);
|
||||
|
||||
extern int D124VoiceInit(void);
|
||||
extern int Hs300xTemperatureInit(void);
|
||||
extern int Hs300xHumidityInit(void);
|
||||
extern int Ps5308Pm1_0Init(void);
|
||||
extern int Ps5308Pm2_5Init(void);
|
||||
extern int Ps5308Pm10Init(void);
|
||||
extern int Zg09Co2Init(void);
|
||||
extern int G8sCo2Init(void);
|
||||
extern int As830Ch4Init(void);
|
||||
extern int Tb600bIaq10IaqInit(void);
|
||||
extern int Tb600bTvoc10TvocInit(void);
|
||||
extern int Tb600bWqHcho1osInit(void);
|
||||
extern int QsFxWindDirectionInit(void);
|
||||
extern int QsFsWindSpeedInit(void);
|
||||
|
||||
extern int lv_port_init(void);
|
||||
|
||||
typedef int (*InitFunc)(void);
|
||||
struct InitDesc
|
||||
{
|
||||
const char* fn_name;
|
||||
const InitFunc fn;
|
||||
};
|
||||
|
||||
static int AppInitDesc(struct InitDesc sub_desc[])
|
||||
{
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
for( i = 0; sub_desc[i].fn != NULL; i++ ) {
|
||||
ret = sub_desc[i].fn();
|
||||
printf("initialize %s %s\n",sub_desc[i].fn_name, ret == 0 ? "success" : "failed");
|
||||
if(0 != ret) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static struct InitDesc framework[] =
|
||||
{
|
||||
#ifdef SUPPORT_SENSOR_FRAMEWORK
|
||||
{ "sensor_framework", SensorFrameworkInit },
|
||||
#endif
|
||||
|
||||
#ifdef SUPPORT_CONNECTION_FRAMEWORK
|
||||
{ "connection_framework", AdapterFrameworkInit },
|
||||
#endif
|
||||
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
||||
static struct InitDesc sensor_desc[] =
|
||||
{
|
||||
#ifdef SENSOR_DEVICE_D124
|
||||
{ "d124_voice", D124VoiceInit },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_DEVICE_HS300X
|
||||
#ifdef SENSOR_QUANTITY_HS300X_TEMPERATURE
|
||||
{ "hs300x_temperature", Hs300xTemperatureInit },
|
||||
#endif
|
||||
#ifdef SENSOR_QUANTITY_HS300X_HUMIDITY
|
||||
{ "hs300x_humidity", Hs300xHumidityInit },
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_PS5308
|
||||
#ifdef SENSOR_QUANTITY_PS5308_PM1_0
|
||||
{ "ps5308_pm1_0", Ps5308Pm1_0Init },
|
||||
#endif
|
||||
#ifdef SENSOR_QUANTITY_PS5308_PM2_5
|
||||
{ "ps5308_pm2_5", Ps5308Pm2_5Init },
|
||||
#endif
|
||||
#ifdef SENSOR_QUANTITY_PS5308_PM10
|
||||
{ "ps5308_pm10", Ps5308Pm10Init },
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_ZG09
|
||||
{ "zg09_co2", Zg09Co2Init },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_G8S
|
||||
{ "g8s_co2", G8sCo2Init },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_QS_FX
|
||||
{ "qs_fx_wind_direction", QsFxWindDirectionInit },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_QS_FS
|
||||
{ "qs_fs_wind_speed", QsFsWindSpeedInit },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_AS830
|
||||
{ "ch4_as830", As830Ch4Init },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_TB600B_IAQ10
|
||||
{ "iaq_tb600b_iaq10", Tb600bIaq10IaqInit },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_TB600B_TVOC10
|
||||
{ "tvoc_tb600b_tvoc10", Tb600bTvoc10TvocInit },
|
||||
#endif
|
||||
|
||||
#ifdef SENSOR_TB600B_WQ_HCHO1OS
|
||||
{ "tvoc_tb600b_wq_hcho1os", Tb600bWqHcho1osInit },
|
||||
#endif
|
||||
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
||||
static struct InitDesc connection_desc[] =
|
||||
{
|
||||
#ifdef CONNECTION_ADAPTER_4G
|
||||
{ "4G adapter", Adapter4GInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_NB
|
||||
{ "NB adpter", AdapterNbiotInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_ZIGBEE
|
||||
{ "zigbee adapter", AdapterZigbeeInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_BLUETOOTH
|
||||
{ "bluetooth adapter", AdapterBlueToothInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_WIFI
|
||||
{ "wifi adapter", AdapterWifiInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_ETHERNET
|
||||
{ "ethernet adapter", AdapterEthernetInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_ETHERCAT
|
||||
{ "ethercat adapter", AdapterEthercatInit},
|
||||
#endif
|
||||
#ifdef CONNECTION_ADAPTER_LORA
|
||||
{ "lora adapter", AdapterLoraInit},
|
||||
#endif
|
||||
{ "NULL", NULL },
|
||||
};
|
||||
|
||||
/**
|
||||
* This function will init sensor framework and all sub sensors
|
||||
* @param sub_desc framework
|
||||
*
|
||||
*/
|
||||
static int SensorDeviceFrameworkInit(struct InitDesc sub_desc[])
|
||||
{
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
for ( i = 0; sub_desc[i].fn != NULL; i++ ) {
|
||||
if (0 == strncmp(sub_desc[i].fn_name, "sensor_framework", strlen("sensor_framework"))) {
|
||||
ret = sub_desc[i].fn();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == ret) {
|
||||
printf("initialize sensor_framework success.\n");
|
||||
AppInitDesc(sensor_desc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will init connection framework and all sub components
|
||||
* @param sub_desc framework
|
||||
*
|
||||
*/
|
||||
static int ConnectionDeviceFrameworkInit(struct InitDesc sub_desc[])
|
||||
{
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
for ( i = 0; sub_desc[i].fn != NULL; i++ ) {
|
||||
if (0 == strncmp(sub_desc[i].fn_name, "connection_framework", strlen("connection_framework"))) {
|
||||
ret = sub_desc[i].fn();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (0 == ret) {
|
||||
printf("initialize connection_framework success.\n");
|
||||
AppInitDesc(connection_desc);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will init system framework
|
||||
*
|
||||
*/
|
||||
int FrameworkInit(void)
|
||||
{
|
||||
#ifdef SUPPORT_SENSOR_FRAMEWORK
|
||||
SensorDeviceFrameworkInit(framework);
|
||||
#endif
|
||||
|
||||
#ifdef SUPPORT_CONNECTION_FRAMEWORK
|
||||
ConnectionDeviceFrameworkInit(framework);
|
||||
#endif
|
||||
|
||||
#ifdef LIB_LV
|
||||
lv_port_init();
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
SRC_DIR := list
|
||||
SRC_DIR := list circular_area
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
@@ -0,0 +1,11 @@
|
||||
include $(KERNEL_ROOT)/.config
|
||||
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
|
||||
include $(APPDIR)/Make.defs
|
||||
CSRCS += circular_area_app.c
|
||||
include $(APPDIR)/Application.mk
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_ADD_XIZI_FETURES),y)
|
||||
SRC_FILES := circular_area_app.c
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
endif
|
||||
@@ -0,0 +1,11 @@
|
||||
import os
|
||||
from building import *
|
||||
Import('RTT_ROOT')
|
||||
Import('rtconfig')
|
||||
cwd = GetCurrentDir()
|
||||
DEPENDS = [""]
|
||||
|
||||
SOURCES = ['circular_area_app.c']
|
||||
path = [cwd]
|
||||
objs = DefineGroup('circular_area', src = SOURCES, depend = DEPENDS,CPPPATH = path)
|
||||
Return("objs")
|
||||
@@ -0,0 +1,281 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: circular_area_app.c
|
||||
* @brief: circular area file for applications
|
||||
* @version: 3.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2022/11/21
|
||||
*
|
||||
*/
|
||||
|
||||
#include "circular_area_app.h"
|
||||
|
||||
/**
|
||||
* This function will return whether the circular_area is full or not
|
||||
*
|
||||
* @param circular_area CircularAreaApp descriptor
|
||||
*/
|
||||
int CircularAreaAppIsFull(CircularAreaAppType circular_area)
|
||||
{
|
||||
CA_PARAM_CHECK(circular_area);
|
||||
|
||||
if((circular_area->readidx == circular_area->writeidx) && (circular_area->b_status)) {
|
||||
printf("the circular area is full\n");
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will return whether the circular_area is empty or not
|
||||
*
|
||||
* @param circular_area CircularAreaApp descriptor
|
||||
*/
|
||||
int CircularAreaAppIsEmpty(CircularAreaAppType circular_area)
|
||||
{
|
||||
CA_PARAM_CHECK(circular_area);
|
||||
|
||||
if((circular_area->readidx == circular_area->writeidx) && (!circular_area->b_status)) {
|
||||
printf("the circular area is empty\n");
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will reset the circular_area and set the descriptor to default
|
||||
*
|
||||
* @param circular_area CircularAreaApp descriptor
|
||||
*/
|
||||
void CircularAreaAppReset(CircularAreaAppType circular_area)
|
||||
{
|
||||
circular_area->writeidx = 0;
|
||||
circular_area->readidx = 0;
|
||||
circular_area->b_status = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will release the circular_area descriptor and free the memory
|
||||
*
|
||||
* @param circular_area CircularAreaApp descriptor
|
||||
*/
|
||||
void CircularAreaAppRelease(CircularAreaAppType circular_area)
|
||||
{
|
||||
circular_area->readidx = 0;
|
||||
circular_area->writeidx = 0;
|
||||
circular_area->p_head = NULL;
|
||||
circular_area->p_tail = NULL;
|
||||
circular_area->b_status = 0;
|
||||
circular_area->area_length = 0;
|
||||
|
||||
PrivFree(circular_area->data_buffer);
|
||||
PrivFree(circular_area);
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will get the circual_area max length
|
||||
*
|
||||
* @param circular_area CircularAreaApp descriptor
|
||||
*/
|
||||
uint32_t CircularAreaAppGetMaxLength(CircularAreaAppType circular_area)
|
||||
{
|
||||
CA_PARAM_CHECK(circular_area);
|
||||
|
||||
return circular_area->area_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will get the data length of the circular_area
|
||||
*
|
||||
* @param circular_area CircularAreaApp descriptor
|
||||
*/
|
||||
uint32_t CircularAreaAppGetDataLength(CircularAreaAppType circular_area)
|
||||
{
|
||||
CA_PARAM_CHECK(circular_area);
|
||||
|
||||
if(CircularAreaAppIsFull(circular_area)) {
|
||||
return circular_area->area_length;
|
||||
} else {
|
||||
return (circular_area->writeidx - circular_area->readidx + circular_area->area_length) % circular_area->area_length;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will return whether it is need to divide the read data into two parts or not
|
||||
*
|
||||
* @param circular_area CircularAreaApp descriptor
|
||||
* @param data_length output data length
|
||||
*/
|
||||
static uint32_t CircularAreaAppDivideRdData(CircularAreaAppType circular_area, uint32_t data_length)
|
||||
{
|
||||
CA_PARAM_CHECK(circular_area);
|
||||
|
||||
if(circular_area->readidx + data_length <= circular_area->area_length) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will return whether it is need to divide the write data into two parts or not
|
||||
*
|
||||
* @param circular_area CircularAreaApp descriptor
|
||||
* @param data_length input data length
|
||||
*/
|
||||
static uint32_t CircularAreaAppDivideWrData(CircularAreaAppType circular_area, uint32_t data_length)
|
||||
{
|
||||
CA_PARAM_CHECK(circular_area);
|
||||
|
||||
if(circular_area->writeidx + data_length <= circular_area->area_length) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will read data from the circular_area
|
||||
*
|
||||
* @param circular_area CircularAreaApp descriptor
|
||||
* @param output_buffer output data buffer poniter
|
||||
* @param data_length output data length
|
||||
*/
|
||||
int CircularAreaAppRead(CircularAreaAppType circular_area, uint8_t *output_buffer, uint32_t data_length)
|
||||
{
|
||||
CA_PARAM_CHECK(circular_area);
|
||||
CA_PARAM_CHECK(output_buffer);
|
||||
CHECK(data_length > 0);
|
||||
|
||||
if(CircularAreaAppIsEmpty(circular_area)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t read_length = (data_length > CircularAreaAppGetDataLength(circular_area)) ? CircularAreaAppGetDataLength(circular_area) : data_length;
|
||||
// if (data_length > CircularAreaAppGetDataLength(circular_area)) {
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
if(CircularAreaAppDivideRdData(circular_area, read_length)) {
|
||||
uint32_t read_len_up = circular_area->area_length - circular_area->readidx;
|
||||
uint32_t read_len_down = read_length - read_len_up;
|
||||
|
||||
memcpy(output_buffer, &circular_area->data_buffer[circular_area->readidx], read_len_up);
|
||||
memcpy(output_buffer + read_len_up, circular_area->p_head, read_len_down);
|
||||
|
||||
circular_area->readidx = read_len_down;
|
||||
} else {
|
||||
memcpy(output_buffer, &circular_area->data_buffer[circular_area->readidx], read_length);
|
||||
circular_area->readidx = (circular_area->readidx + read_length) % circular_area->area_length;
|
||||
}
|
||||
|
||||
circular_area->b_status = 0;
|
||||
|
||||
return read_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will write data to the circular_area
|
||||
*
|
||||
* @param circular_area CircularAreaApp descriptor
|
||||
* @param input_buffer input data buffer poniter
|
||||
* @param data_length input data length
|
||||
* @param b_force whether to force to write data disregard the length limit
|
||||
*/
|
||||
int CircularAreaAppWrite(CircularAreaAppType circular_area, uint8_t *input_buffer, uint32_t data_length, int b_force)
|
||||
{
|
||||
CA_PARAM_CHECK(circular_area);
|
||||
CA_PARAM_CHECK(input_buffer);
|
||||
CHECK(data_length > 0);
|
||||
|
||||
if(CircularAreaAppIsFull(circular_area) && (!b_force)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint32_t write_data_length = circular_area->area_length - CircularAreaAppGetDataLength(circular_area);
|
||||
//data_length = (data_length > write_data_length) ? write_data_length : data_length;
|
||||
if (data_length > write_data_length) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(CircularAreaAppDivideWrData(circular_area, data_length)) {
|
||||
uint32_t write_len_up = circular_area->area_length - circular_area->writeidx;
|
||||
uint32_t write_len_down = data_length - write_len_up;
|
||||
|
||||
memcpy(&circular_area->data_buffer[circular_area->writeidx], input_buffer, write_len_up);
|
||||
memcpy(circular_area->p_head, input_buffer + write_len_up, write_len_down);
|
||||
|
||||
circular_area->writeidx = write_len_down;
|
||||
} else {
|
||||
memcpy(&circular_area->data_buffer[circular_area->writeidx], input_buffer, data_length);
|
||||
circular_area->writeidx = (circular_area->writeidx + data_length) % circular_area->area_length;
|
||||
}
|
||||
|
||||
circular_area->b_status = 1;
|
||||
|
||||
if(b_force) {
|
||||
circular_area->readidx = circular_area->writeidx;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct CircularAreaAppOps CircularAreaAppOperations =
|
||||
{
|
||||
CircularAreaAppRead,
|
||||
CircularAreaAppWrite,
|
||||
CircularAreaAppRelease,
|
||||
CircularAreaAppReset,
|
||||
};
|
||||
|
||||
/**
|
||||
* This function will initialize the circular_area
|
||||
*
|
||||
* @param circular_area_length circular_area length
|
||||
*/
|
||||
CircularAreaAppType CircularAreaAppInit(uint32_t circular_area_length)
|
||||
{
|
||||
CHECK(circular_area_length > 0);
|
||||
|
||||
circular_area_length = CA_ALIGN_DOWN(circular_area_length, 8);
|
||||
|
||||
CircularAreaAppType circular_area = PrivMalloc(sizeof(struct CircularAreaApp));
|
||||
if(NULL == circular_area) {
|
||||
printf("CircularAreaAppInit malloc struct circular_area failed\n");
|
||||
PrivFree(circular_area);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
CircularAreaAppReset(circular_area);
|
||||
|
||||
circular_area->data_buffer = PrivMalloc(circular_area_length);
|
||||
if(NULL == circular_area->data_buffer) {
|
||||
printf("CircularAreaAppInit malloc circular_area data_buffer failed\n");
|
||||
PrivFree(circular_area->data_buffer);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
circular_area->p_head = circular_area->data_buffer;
|
||||
circular_area->p_tail = circular_area->data_buffer + circular_area_length;
|
||||
circular_area->area_length = circular_area_length;
|
||||
|
||||
printf("CircularAreaAppInit done p_head %8p p_tail %8p length %u\n",
|
||||
circular_area->p_head, circular_area->p_tail, circular_area->area_length);
|
||||
|
||||
circular_area->CircularAreaAppOperations = &CircularAreaAppOperations;
|
||||
|
||||
return circular_area;
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (c) 2020 AIIT XUOS Lab
|
||||
* XiUOS is licensed under Mulan PSL v2.
|
||||
* You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||
* You may obtain a copy of Mulan PSL v2 at:
|
||||
* http://license.coscl.org.cn/MulanPSL2
|
||||
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
|
||||
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
|
||||
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
|
||||
* See the Mulan PSL v2 for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file: circular_area_app.h
|
||||
* @brief: function declaration and structure defintion of circular area for applications
|
||||
* @version: 3.0
|
||||
* @author: AIIT XUOS Lab
|
||||
* @date: 2022/11/21
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef CIRCULAR_AREA_APP_H
|
||||
#define CIRCULAR_AREA_APP_H
|
||||
|
||||
#include <string.h>
|
||||
#include <transform.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define CA_PARAM_CHECK(param) \
|
||||
do \
|
||||
{ \
|
||||
if(param == NULL) { \
|
||||
KPrintf("PARAM CHECK FAILED ...%s %d %s is NULL.\n", __func__, __LINE__, #param); \
|
||||
while(1); \
|
||||
} \
|
||||
}while (0)
|
||||
|
||||
#define CA_ALIGN_DOWN(size, align) ((size)/(align)*(align))
|
||||
|
||||
typedef struct CircularAreaApp *CircularAreaAppType;
|
||||
|
||||
struct CircularAreaAppOps
|
||||
{
|
||||
int (*read) (CircularAreaAppType circular_area, uint8_t *output_buffer, uint32_t data_length);
|
||||
int (*write) (CircularAreaAppType circular_area, uint8_t *input_buffer, uint32_t data_length, int b_force);
|
||||
void (*release) (CircularAreaAppType circular_area);
|
||||
void (*reset) (CircularAreaAppType circular_area);
|
||||
};
|
||||
|
||||
struct CircularAreaApp
|
||||
{
|
||||
uint8_t *data_buffer;
|
||||
|
||||
uint32_t readidx;
|
||||
uint32_t writeidx;
|
||||
|
||||
uint8_t *p_head;
|
||||
uint8_t *p_tail;
|
||||
|
||||
uint32_t area_length;
|
||||
int b_status;
|
||||
|
||||
struct CircularAreaAppOps *CircularAreaAppOperations;
|
||||
};
|
||||
|
||||
/*This function will return whether the circular_area is full or not*/
|
||||
int CircularAreaAppIsFull(CircularAreaAppType circular_area);
|
||||
|
||||
/*This function will return whether the circular_area is empty or not*/
|
||||
int CircularAreaAppIsEmpty(CircularAreaAppType circular_area);
|
||||
|
||||
/*This function will reset the circular_area and set the descriptor to default*/
|
||||
void CircularAreaAppReset(CircularAreaAppType circular_area);
|
||||
|
||||
/*This function will release the circular_area descriptor and free the memory*/
|
||||
void CircularAreaAppRelease(CircularAreaAppType circular_area);
|
||||
|
||||
/*This function will read data from the circular_area*/
|
||||
int CircularAreaAppRead(CircularAreaAppType circular_area, uint8_t *output_buffer, uint32_t data_length);
|
||||
|
||||
/*This function will write data to the circular_area*/
|
||||
int CircularAreaAppWrite(CircularAreaAppType circular_area, uint8_t *input_buffer, uint32_t data_length, int b_force);
|
||||
|
||||
/*This function will get the circual_area max length*/
|
||||
uint32_t CircularAreaAppGetMaxLength(CircularAreaAppType circular_area);
|
||||
|
||||
/*This function will get the data length of the circular_area*/
|
||||
uint32_t CircularAreaAppGetDataLength(CircularAreaAppType circular_area);
|
||||
|
||||
/*This function will initialize the circular_area*/
|
||||
CircularAreaAppType CircularAreaAppInit(uint32_t circular_area_length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user