sync the upstream branch

This commit is contained in:
Wang_Weigen 2021-09-27 17:02:34 +08:00
commit ebbb30c763
26 changed files with 578 additions and 155 deletions

View File

@ -1,9 +1,15 @@
import os
Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
SOURCES = ['framework_init.c']
path = [cwd]
objs = []
group = DefineGroup('sensor', SOURCES, depend = [], CPPPATH = [cwd])
objs = objs + group
list = os.listdir(cwd)
for d in list:

View File

@ -11,12 +11,13 @@
*/
#include <stdio.h>
#include <string.h>
#include <user_api.h>
#include <transform.h>
extern int SensorFrameworkInit(void);
extern int AdapterFrameworkInit(void);
extern int Adapter4GInit(void);
extern int AdapterBlueToothInit(void);
extern int AdapterWifiInit(void);
extern int AdapterZigbeeInit(void);
@ -90,13 +91,16 @@ static struct InitDesc sensor_desc[] =
static struct InitDesc connection_desc[] =
{
#ifdef ADAPTER_4G
#ifdef CONNECTION_ADAPTER_4G
{ "4G adpter", Adapter4GInit},
#endif
#ifdef CONNECTION_ADAPTER_ZIGBEE
{ "zigbee adpter", AdapterZigbeeInit},
#endif
#ifdef ADAPTER_WIFI
#ifdef CONNECTION_ADAPTER_BLUETOOTH
{ "BlueTooth adpter", AdapterBlueToothInit},
#endif
#ifdef CONNECTION_ADAPTER_WIFI
{ "Wifi adpter", AdapterWifiInit},
#endif
{ "NULL", NULL },

View File

@ -0,0 +1,14 @@
import os
Import('RTT_ROOT')
from building import *
cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(path, 'SConscript'))
Return('objs')

View File

@ -0,0 +1,11 @@
import os
from building import *
Import('RTT_ROOT')
Import('rtconfig')
cwd = GetCurrentDir()
DEPENDS = [""]
SOURCES = ['double_list.c'] + ['single_list.c']
path = [cwd]
objs = DefineGroup('list', src = SOURCES, depend = DEPENDS,CPPPATH = path)
Return("objs")

View File

@ -23,7 +23,7 @@
#define __LIST_H__
#include "libc.h"
#include<stddef.h>
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -0,0 +1,20 @@
import os
from building import *
Import('RTT_ROOT')
Import('rtconfig')
cwd = GetCurrentDir()
DEPENDS = ["SUPPORT_SENSOR_FRAMEWORK"]
SOURCES = []
if GetDepend(['APPLICATION_SENSOR_CO2_ZG09']):
SOURCES = ['co2_zg09.c'] + SOURCES
if GetDepend(['APPLICATION_SENSOR_PM1_0_PS5308']):
SOURCES = ['pm1_0_ps5308.c.c'] + SOURCES
if GetDepend(['APPLICATION_SENSOR_VOICE_D124']):
SOURCES = ['voice_d124.c'] + SOURCES
if GetDepend(['APPLICATION_SENSOR_HUMIDITY_HS300X']):
SOURCES = ['humidity_hs300x.c'] + SOURCES
if GetDepend(['APPLICATION_SENSOR_TEMPERATURE_HS300X']):
SOURCES = ['temperature_hs300x.c'] + SOURCES
path = [cwd]
objs = DefineGroup('sensor_app', src = SOURCES, depend = DEPENDS,CPPPATH = path)
Return("objs")

View File

@ -18,7 +18,7 @@
* @date 2021.04.23
*/
#include <user_api.h>
#include <transform.h>
#include <sensor.h>
/**

View File

@ -253,11 +253,11 @@ AdapterProductInfoType Ec200tAttach(struct Adapter *adapter)
struct AdapterProductInfo *product_info = malloc(sizeof(struct AdapterProductInfo));
if (!product_info) {
printf("Ec200tAttach malloc product_info error\n");
free(product_info);
PrivFree(product_info);
return NULL;
}
product_info->model_name = ADAPTER_4G_EC200T;
strcpy(product_info->model_name, ADAPTER_4G_EC200T);
product_info->model_done = (void *)&ec200t_done;

View File

@ -1,14 +1,8 @@
config ADAPTER_4G
bool "Using 4G adapter function"
config ADAPTER_EC200T
bool "Using 4G adapter device EC200T"
default y
if ADAPTER_4G
config ADAPTER_EC200T
bool "Using 4G adapter device EC200T"
default y
if ADAPTER_EC200T
source "$APP_DIR/Framework/connection/4G/EC200T/Kconfig"
endif
if ADAPTER_EC200T
source "$APP_DIR/Framework/connection/4G/EC200T/Kconfig"
endif
endif

View File

@ -1,26 +1,26 @@
SRC_FILES := adapter.c adapter_agent.c
ifeq ($(CONFIG_ADAPTER_LORA),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_LORA),y)
SRC_DIR += lora
endif
ifeq ($(CONFIG_ADAPTER_4G),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_4G),y)
SRC_DIR += 4G
endif
ifeq ($(CONFIG_ADAPTER_NB),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_NB),y)
SRC_DIR += nbiot
endif
ifeq ($(CONFIG_ADAPTER_WIFI),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_WIFI),y)
SRC_DIR += wifi
endif
ifeq ($(CONFIG_ADAPTER_ETHERNET),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_ETHERNET),y)
SRC_DIR += ethernet
endif
ifeq ($(CONFIG_ADAPTER_BLUETOOTH),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_BLUETOOTH),y)
SRC_DIR += bluetooth
endif
@ -28,7 +28,7 @@ ifeq ($(CONFIG_CONNECTION_ADAPTER_ZIGBEE),y)
SRC_DIR += zigbee
endif
ifeq ($(CONFIG_ADAPTER_5G),y)
ifeq ($(CONFIG_CONNECTION_ADAPTER_5G),y)
SRC_DIR += 5G
endif

View File

@ -39,15 +39,6 @@ extern "C" {
#define ADAPTER_LWIP_OPERATION 2
#define ADAPTER_RAWIP_OPERATION 3
#define ADAPTER_LORA_FUNC ((uint32_t)(1 << ATAPTER_LORA))
#define ADAPTER_4G_FUNC ((uint32_t)(1 << ADAPTER_4G))
#define ADAPTER_NBIOT_FUNC ((uint32_t)(1 << ADAPTER_NBIOT))
#define ADAPTER_WIFI_FUNC ((uint32_t)(1 << ADAPTER_WIFI))
#define ADAPTER_ETHERNET_FUNC ((uint32_t)(1 << ADAPTER_ETHERNET))
#define ADAPTER_BLUETOOTH_FUNC ((uint32_t)(1 << ADAPTER_BLUETOOTH))
#define ADAPTER_ZIGBEE_FUNC ((uint32_t)(1 << ADAPTER_ZIGBEE))
#define ADAPTER_5G_FUNC ((uint32_t)(1 << ADAPTER_5G))
#ifdef CONNECTION_FRAMEWORK_DEBUG
#define ADAPTER_DEBUG printf
#else
@ -113,8 +104,8 @@ enum IpType
struct AdapterProductInfo
{
uint32_t functions;
const char *vendor_name;
const char *model_name;
char vendor_name[NAME_NUM_MAX];
char model_name[NAME_NUM_MAX];
uint32_t work_mode;
void *model_done;
@ -158,7 +149,7 @@ struct PrivProtocolDone
struct Adapter
{
char name[32];
char name[NAME_NUM_MAX];
int fd;
int product_info_flag;

View File

@ -27,7 +27,6 @@
#include <stdlib.h>
#include <string.h>
#include <user_api.h>
#include <bus.h>
#define AT_CMD_MAX_LEN 128
#define AT_AGENT_MAX 2
@ -36,12 +35,13 @@ static uint32 last_cmd_len = 0;
static struct ATAgent at_agent_table[AT_AGENT_MAX] = {0};
uint IpTint(char *ipstr){
unsigned int IpTint(char *ipstr)
{
if (ipstr == NULL)
return 0;
char *token;
uint i = 3, total = 0, cur;
unsigned int i = 3, total = 0, cur;
token = strtok(ipstr, ".");
@ -70,7 +70,7 @@ void SwapStr(char *str, int begin, int end)
}
}
char *IpTstr(uint ipint)
char *IpTstr(unsigned int ipint)
{
int LEN = 16;
char *new = (char *)malloc(LEN);
@ -124,13 +124,17 @@ uint32 ATSprintf(int fd, const char *format, va_list params)
PrivWrite(fd, send_buf, last_cmd_len);
}
int ATOrderSend(ATAgentType agent, uint32 timeout, ATReplyType reply, const char *cmd_expr, ...)
int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const char *cmd_expr, ...)
{
if (agent == NULL){
printf("ATAgent is null");
return -ERROR;
}
struct timespec abstime;
abstime.tv_sec = timeout_s;
agent->receive_mode = AT_MODE;
memset(agent->maintain_buffer, 0x00, agent->maintain_max);
@ -152,7 +156,7 @@ int ATOrderSend(ATAgentType agent, uint32 timeout, ATReplyType reply, const char
va_start(params, cmd_expr);
ATSprintf(agent->fd, cmd_expr, params);
va_end(params);
if (UserSemaphoreObtain(agent->rsp_sem, timeout) != EOK){
if (PrivSemaphoreObtainWait(&agent->rsp_sem, &abstime) != EOK){
result = -ETIMEOUT;
goto __out;
}
@ -185,22 +189,24 @@ int EntmSend(ATAgentType agent, const char *data, int len)
memcpy(send_buf, data, len);
memcpy(send_buf + len, "!@", 2);
write(agent->fd, send_buf, len + 2);
PrivWrite(agent->fd, send_buf, len + 2);
return EOK;
}
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int time_out)
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s)
{
UserTaskDelay(1000);
struct timespec abstime;
abstime.tv_sec = timeout_s;
PrivTaskDelay(1000);
memset(agent->entm_recv_buf, 0, ENTM_RECV_MAX);
agent->entm_recv_len = 0;
UserSemaphoreSetValue(agent->entm_rx_notice, 0);
if (UserSemaphoreObtain(agent->entm_rx_notice, time_out)){
return -ERROR;
if (PrivSemaphoreObtainWait(&agent->entm_rx_notice, &abstime)){
return ERROR;
}
if (buffer_len < agent->entm_recv_len){
@ -225,16 +231,17 @@ static int GetCompleteATReply(ATAgentType agent)
agent->maintain_len = 0;
while (1){
read(agent->fd, &ch, 1);
PrivRead(agent->fd, &ch, 1);
printf(" %c(0x%x)\n", ch, ch);
if (agent->receive_mode == ENTM_MODE){
if (agent->entm_recv_len < ENTM_RECV_MAX){
agent->entm_recv_buf[agent->entm_recv_len++] = ch;
agent->entm_recv_buf[agent->entm_recv_len] = ch;
agent->entm_recv_len++;
if (last_ch == '!' && ch == '@'){
UserSemaphoreAbandon(agent->entm_rx_notice);
PrivSemaphoreAbandon(&agent->entm_rx_notice);
}
last_ch = ch;
@ -245,7 +252,8 @@ static int GetCompleteATReply(ATAgentType agent)
}
else if (agent->receive_mode == AT_MODE){
if (read_len < agent->maintain_max){
agent->maintain_buffer[read_len++] = ch;
agent->maintain_buffer[read_len] = ch;
read_len++;
agent->maintain_len = read_len;
}else{
printf("maintain_len is_full ...\n");
@ -289,25 +297,25 @@ static int DeleteATAgent(ATAgentType agent)
}
if (agent->entm_rx_notice){
UserSemaphoreDelete(agent->entm_rx_notice);
PrivSemaphoreDelete(&agent->entm_rx_notice);
}
if (agent->fd > 0){
close(agent->fd);
PrivClose(agent->fd);
}
if (agent->rsp_sem){
UserSemaphoreDelete(agent->rsp_sem);
PrivSemaphoreDelete(&agent->rsp_sem);
}
if (agent->maintain_buffer){
free(agent->maintain_buffer);
PrivFree(agent->maintain_buffer);
}
memset(agent, 0x00, sizeof(struct ATAgent));
}
static void ATAgentReceiveProcess(void *param)
static void *ATAgentReceiveProcess(void *param)
{
ATAgentType agent = (ATAgentType)param;
const struct at_urc *urc;
@ -329,7 +337,7 @@ static void ATAgentReceiveProcess(void *param)
}
agent->reply = NULL;
UserSemaphoreAbandon(agent->rsp_sem);
PrivSemaphoreAbandon(&agent->rsp_sem);
}
}
}
@ -339,56 +347,51 @@ static int ATAgentInit(ATAgentType agent)
{
int result = EOK;
UtaskType at_utask;
do
{
agent->maintain_len = 0;
agent->maintain_buffer = (char *)malloc(agent->maintain_max);
if (agent->maintain_buffer == NONE){
break;
}
agent->maintain_len = 0;
agent->maintain_buffer = (char *)malloc(agent->maintain_max);
agent->entm_rx_notice = UserSemaphoreCreate(0);
if (agent->entm_rx_notice == 0){
break;
}
if (agent->maintain_buffer == NONE){
printf("ATAgentInit malloc maintain_buffer error\n");
goto __out;
}
agent->rsp_sem = UserSemaphoreCreate(0);
if (agent->rsp_sem == 0){
break;
}
if(PrivMutexCreate(&agent->lock, 0) < 0) {
printf("AdapterFrameworkInit mutex create failed.\n");
}
if (agent->lock == 0){
break;
}
result = PrivSemaphoreCreate(&agent->entm_rx_notice, 0, 0);
if (result < 0){
printf("ATAgentInit create entm sem error\n");
goto __out;
}
agent->receive_mode = ENTM_MODE;
result = PrivSemaphoreCreate(&agent->rsp_sem, 0, 0);
if (result < 0){
printf("ATAgentInit create rsp sem error\n");
goto __out;
}
strncpy(at_utask.name, "recv_task", strlen("recv_task"));
at_utask.func_entry = ATAgentReceiveProcess;
at_utask.func_param = agent;
at_utask.stack_size = 2048;
at_utask.prio = 18;
if(PrivMutexCreate(&agent->lock, 0) < 0) {
printf("AdapterFrameworkInit mutex create failed.\n");
goto __out;
}
agent->at_handler = UserTaskCreate(at_utask);
agent->receive_mode = ENTM_MODE;
// struct SerialDataCfg data_cfg;
// memset(&data_cfg, 0, sizeof(struct SerialDataCfg));
// data_cfg.serial_baud_rate = 57600;
// ioctl(agent->fd, OPE_INT, &data_cfg);
pthread_attr_t attr;
attr.schedparam.sched_priority = 18;
attr.stacksize = 2048;
if (agent->at_handler == 0) {
break;
}
PrivTaskCreate(&agent->at_handler, &attr, ATAgentReceiveProcess, agent);
result = EOK;
return result;
} while (1);
// struct SerialDataCfg data_cfg;
// memset(&data_cfg, 0, sizeof(struct SerialDataCfg));
// data_cfg.serial_baud_rate = 57600;
// ioctl(agent->fd, OPE_INT, &data_cfg);
return result;
__out:
DeleteATAgent(agent);
result = -ERROR;
return result;
}
@ -424,7 +427,7 @@ int InitATAgent(const char *agent_name, int agent_fd, uint32 maintain_max)
result = ATAgentInit(agent);
if (result == EOK)
{
UserTaskStartup(agent->at_handler);
PrivTaskStartup(&agent->at_handler);
}
return result;
@ -445,7 +448,7 @@ ATReplyType CreateATReply(uint32 reply_max_len)
reply->reply_buffer = (char *)malloc(reply_max_len);
if (reply->reply_buffer == NULL){
printf("no more memory\n");
free(reply);
PrivFree(reply);
return NULL;
}
memset(reply->reply_buffer,0,reply_max_len);
@ -456,13 +459,13 @@ void DeleteATReply(ATReplyType reply)
{
if (reply){
if (reply->reply_buffer){
free(reply->reply_buffer);
PrivFree(reply->reply_buffer);
reply->reply_buffer = NULL;
}
}
if (reply){
free(reply);
PrivFree(reply);
reply = NULL;
}
}

View File

@ -54,7 +54,7 @@ struct ATAgent
ATReplyType reply;
int rsp_sem;
int32 at_handler;
pthread_t at_handler;
#define ENTM_RECV_MAX 256
char entm_recv_buf[ENTM_RECV_MAX];
@ -65,7 +65,7 @@ struct ATAgent
typedef struct ATAgent *ATAgentType;
int EntmSend(ATAgentType agent, const char *data, int len);
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int time_out);
int EntmRecv(ATAgentType agent, char *rev_buffer, int buffer_len, int timeout_s);
char *GetReplyText(ATReplyType reply);
ATReplyType CreateATReply(uint32 reply_max_len);
uint IpTint(char *ipstr);
@ -75,7 +75,7 @@ ATAgentType GetATAgent(const char *agent_name);
int InitATAgent(const char *agent_name, int fd, uint32 maintain_max);
int ParseATReply(char* str, const char *format, ...);
void DeleteATReply(ATReplyType reply);
int ATOrderSend(ATAgentType agent, uint32 timeout, ATReplyType reply, const char *cmd_expr, ...);
int ATOrderSend(ATAgentType agent, uint32 timeout_s, ATReplyType reply, const char *cmd_expr, ...);
#define REPLY_TIME_OUT 3000

View File

@ -1,14 +1,7 @@
config ADAPTER_BLUETOOTH
bool "Using bluetooth adapter function"
config ADAPTER_HC08
bool "Using bluetooth adapter device HC08"
default y
if ADAPTER_BLUETOOTH
config ADAPTER_HC08
bool "Using bluetooth adapter device HC08"
default y
if ADAPTER_HC08
source "$APP_DIR/Framework/connection/bluetooth/HC08/Kconfig"
endif
endif
if ADAPTER_HC08
source "$APP_DIR/Framework/connection/bluetooth/HC08/Kconfig"
endif

View File

@ -210,10 +210,10 @@ static int Hfa21SetAddr(struct Adapter *adapter, const char *ip, const char *gat
char *gw_str = NULL;
char *mask_str = NULL;
dhcp_mode = (char *) UserCalloc(1, 8);
ip_str = (char *) UserCalloc(1, 17);
gw_str = (char *) UserCalloc(1, 17);
mask_str = (char *) UserCalloc(1, 17);
dhcp_mode = (char *) PrivCalloc(1, 8);
ip_str = (char *) PrivCalloc(1, 17);
gw_str = (char *) PrivCalloc(1, 17);
mask_str = (char *) PrivCalloc(1, 17);
Hfa21InitAtCmd(adapter->agent);
@ -260,8 +260,8 @@ static int Hfa21Ping(struct Adapter *adapter, const char *destination)
{
char *ping_result = NONE;
char *dst = NONE;
ping_result = (char *) UserCalloc(1, 17);
dst = (char *) UserCalloc(1, 17);
ping_result = (char *) PrivCalloc(1, 17);
dst = (char *) PrivCalloc(1, 17);
strcpy(dst, destination);
strcat(dst, "\r");
@ -327,11 +327,11 @@ static int Hfa21Netstat(struct Adapter *adapter)
char *local_ipaddr = NULL;
char *gateway = NULL;
char *netmask = NULL;
local_ipaddr = (char *) UserCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
gateway = (char *) UserCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
netmask = (char *) UserCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
work_mode = (char *) UserCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
ip_mode = (char *) UserCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
local_ipaddr = (char *) PrivCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
gateway = (char *) PrivCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
netmask = (char *) PrivCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
work_mode = (char *) PrivCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
ip_mode = (char *) PrivCalloc(1, HFA21_NETSTAT_IPADDR_SIZE);
reply = CreateATReply(HFA21_NETSTAT_RESP_SIZE);
if (reply == NULL) {
@ -391,13 +391,13 @@ __exit:
if (reply)
DeleteATReply(reply);
if (local_ipaddr)
UserFree(local_ipaddr);
PrivFree(local_ipaddr);
if (netmask)
UserFree(netmask);
PrivFree(netmask);
if (gateway)
UserFree(gateway);
PrivFree(gateway);
if (work_mode)
UserFree(work_mode);
PrivFree(work_mode);
}
static int Hfa21Connect(struct Adapter *adapter, enum NetRoleType net_role, const char *ip, const char *port, enum IpType ip_type)
@ -504,11 +504,11 @@ AdapterProductInfoType Hfa21Attach(struct Adapter *adapter)
struct AdapterProductInfo *product_info = malloc(sizeof(struct AdapterProductInfo));
if (!product_info) {
printf("Hfa21Attach Attach malloc product_info error\n");
free(product_info);
PrivFree(product_info);
return NULL;
}
product_info->model_name = ADAPTER_WIFI_HFA21;
strcpy(product_info->model_name, ADAPTER_WIFI_HFA21);
product_info->model_done = (void *)&hfa21_done;

View File

@ -1,14 +1,7 @@
config ADAPTER_WIFI
bool "Using WIFI adapter function"
config ADAPTER_HFA21
bool "Using wifi adapter device HFA21"
default y
if ADAPTER_WIFI
config ADAPTER_HFA21
bool "Using wifi adapter device HFA21"
default y
if ADAPTER_HFA21
source "$APP_DIR/Framework/connection/wifi/HFA21/Kconfig"
endif
endif
if ADAPTER_HFA21
source "$APP_DIR/Framework/connection/wifi/HFA21/Kconfig"
endif

View File

@ -439,7 +439,7 @@ AdapterProductInfoType E18Attach(struct Adapter *adapter)
return NULL;
}
product_info->model_name = ADAPTER_ZIGBEE_E18;
strncpy(product_info->model_name, ADAPTER_ZIGBEE_E18,sizeof(product_info->model_name));
product_info->model_done = (void *)&E18_done;
return product_info;

View File

@ -0,0 +1,21 @@
import os
Import('RTT_ROOT')
Import('rtconfig')
from building import *
cwd = GetCurrentDir()
SOURCES = []
if GetDepend(['SUPPORT_SENSOR_FRAMEWORK']):
SOURCES = ['sensor.c'] + SOURCES
path = [cwd]
objs = []
group = DefineGroup('sensor', SOURCES, depend = [], CPPPATH = [cwd])
objs = objs + group
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(path, 'SConscript'))
Return('objs')

View File

@ -0,0 +1,14 @@
import os
Import('RTT_ROOT')
from building import *
cwd = GetCurrentDir()
objs = []
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
objs = objs + SConscript(os.path.join(path, 'SConscript'))
Return('objs')

View File

@ -0,0 +1,10 @@
from building import *
import os
cwd = GetCurrentDir()
src = []
if GetDepend(['SENSOR_D124']):
src += ['d124.c']
group = DefineGroup('sensor voice d124', src, depend = [], CPPPATH = [cwd])
Return('group')

View File

@ -21,7 +21,7 @@
#include <sensor.h>
static struct SensorDevice d124;
static int32_t active_task_id;
static pthread_t active_task_id;
static pthread_mutex_t buff_lock;
static struct SensorProductInfo info =

View File

@ -5,7 +5,7 @@ Import('rtconfig')
cwd = GetCurrentDir()
DEPENDS = [""]
SOURCES = []
SOURCES = ['transform.c']
path = [cwd]
objs = DefineGroup('transform', src = SOURCES, depend = DEPENDS,CPPPATH = path)
Return("objs")

View File

@ -0,0 +1,191 @@
/*
* 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 xiuos.c
* @brief Converts the framework interface to an operating system interface
* @version 1.0
* @author AIIT XUOS Lab
* @date 2021.06.07
*/
#include <transform.h>
/**************************mutex***************************/
/* private mutex API */
int PrivMutexCreate(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr)
{
return pthread_mutex_init(p_mutex, attr);
}
int PrivMutexDelete(pthread_mutex_t *p_mutex)
{
return pthread_mutex_destroy(p_mutex);
}
int PrivMutexObtain(pthread_mutex_t *p_mutex)
{
return pthread_mutex_lock(p_mutex);
}
int PrivMutexAbandon(pthread_mutex_t *p_mutex)
{
return pthread_mutex_unlock(p_mutex);
}
/**********************semaphore****************************/
int PrivSemaphoreCreate(sem_t *sem, int pshared, unsigned int value)
{
return sem_init(sem, pshared, value);
}
int PrivSemaphoreDelete(sem_t *sem)
{
return sem_destroy(sem);
}
int PrivSemaphoreObtainWait(sem_t *sem, const struct timespec *abstime)
{
return sem_timedwait(sem, abstime);
}
int PrivSemaphoreObtainNoWait(sem_t *sem)
{
return sem_trywait(sem);
}
int PrivSemaphoreAbandon(sem_t *sem)
{
return sem_post(sem);
}
/**************************task*************************/
int PrivTaskCreate(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine)(void *), void *arg)
{
pthread_attr_t attrtmp ;
pthread_attr_init(&attrtmp);
pthread_attr_setschedparam(&attrtmp, &(attr->schedparam)); /* 修改属性对应的优先级 */
pthread_attr_setstacksize(&attrtmp, (size_t)((attr->stacksize)));
return pthread_create(thread, &attrtmp, start_routine, arg);
}
int PrivTaskStartup(pthread_t *thread)
{
return 0;
}
int PrivTaskDelete(pthread_t thread, int sig)
{
_pthread_data_t *ptd;
ptd = _pthread_get_data(thread);
return rt_thread_detach(ptd->tid);
}
void PrivTaskQuit(void *value_ptr)
{
pthread_exit(value_ptr);
}
int PrivTaskDelay(int32_t ms)
{
rt_thread_mdelay(ms);
}
/*********************fs**************************/
/************************Driver Posix Transform***********************/
int PrivOpen(const char *path, int flags)
{
return open(path, flags);
}
int PrivClose(int fd)
{
return close(fd);
}
int PrivRead(int fd, void *buf, size_t len)
{
return read(fd, buf, len);
}
int PrivWrite(int fd, const void *buf, size_t len)
{
return write(fd, buf, len);
}
static int PrivSerialIoctl(int fd, int cmd, void *args)
{
struct dfs_fd *rt_fd;
int ret = 0;
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT;
struct SerialDataCfg *serial_cfg = (struct SerialDataCfg *)args;
config.baud_rate = serial_cfg->serial_baud_rate;
config.data_bits = serial_cfg->serial_data_bits;
config.stop_bits = serial_cfg->serial_stop_bits;
config.bufsz = RT_SERIAL_RB_BUFSZ;
config.parity = serial_cfg->serial_parity_mode;
config.invert = serial_cfg->serial_invert_mode;
rt_fd = fd_get(fd);
ret = rt_fd->fops->ioctl(rt_fd, RT_DEVICE_CTRL_CONFIG, &config);
return ret;
}
static int PrivPinIoctl(int fd, int cmd, void *args)
{
struct PinParam *pin_cfg = (struct PinParam *)args;
return ioctl(fd, cmd, pin_cfg);
}
int PrivIoctl(int fd, int cmd, void *args)
{
int ret;
struct PrivIoctlCfg *ioctl_cfg = (struct PrivIoctlCfg *)args;
switch (ioctl_cfg->ioctl_driver_type)
{
case SERIAL_TYPE:
ret = PrivSerialIoctl(fd, cmd, ioctl_cfg->args);
break;
case PIN_TYPE:
ret = PrivPinIoctl(fd, cmd, ioctl_cfg->args);
break;
default:
break;
}
return ret;
}
/********************memory api************/
void *PrivMalloc(size_t size)
{
return malloc(size);
}
void *PrivRealloc(void *pointer, size_t size)
{
return realloc(pointer, size);
}
void *PrivCalloc(size_t count, size_t size)
{
return calloc(count, size);
}
void PrivFree(void *pointer)
{
free(pointer);
}

View File

@ -30,19 +30,23 @@
#include <sys/time.h>
#include <errno.h>
#include <pthread.h>
#include <pthread_internal.h>
#include <semaphore.h>
#include <sched.h>
#include <unistd.h>
#include <dfs_poll.h>
#include <dfs_posix.h>
#include <dfs.h>
#ifdef RT_USING_POSIX_TERMIOS
#include <posix_termios.h>
#endif
#ifdef DRV_USING_OV2640
#include <drv_ov2640.h>
#endif
#if defined(RT_USING_SAL)
#if defined(RT_USING_SAL)&& defined (RT_USING_LWIP)
#include <netdb.h>
#include <sys/socket.h>
#else
#elif defined RT_USING_LWIP
#include <lwip/netdb.h>
#include <lwip/sockets.h>
#endif /* RT_USING_SAL */
@ -50,6 +54,139 @@
extern "C" {
#endif
typedef signed char int8;
typedef signed short int16;
typedef signed int int32;
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
#ifdef ARCH_CPU_64BIT
typedef signed long int64;
typedef unsigned long uint64;
#else
typedef signed long long int64;
typedef unsigned long long uint64;
#endif
#define OPE_INT 0x0000
#define OPE_CFG 0x0001
#define NAME_NUM_MAX 32
/*********************GPIO define*********************/
#define GPIO_LOW 0x00
#define GPIO_HIGH 0x01
#define GPIO_CFG_OUTPUT 0x00
#define GPIO_CFG_INPUT 0x01
#define GPIO_CFG_INPUT_PULLUP 0x02
#define GPIO_CFG_INPUT_PULLDOWN 0x03
#define GPIO_CFG_OUTPUT_OD 0x04
#define GPIO_CONFIG_MODE 0xffffffff
#ifndef SERIAL_RB_BUFSZ
#define SERIAL_RB_BUFSZ 128
#endif
struct PinDevIrq
{
int irq_mode;//< RISING/FALLING/HIGH/LOW
void (*hdr) (void *args);//< callback function
void *args;//< the params of callback function
};
struct PinParam
{
int cmd;//< cmd:GPIO_CONFIG_MODE/GPIO_IRQ_REGISTER/GPIO_IRQ_FREE/GPIO_IRQ_DISABLE/GPIO_IRQ_ENABLE
long pin;//< pin number
int mode;//< pin mode: input/output
struct PinDevIrq irq_set;//< pin irq set
uint64_t arg;
};
struct PinStat
{
long pin;//< pin number
uint16_t val;//< pin level
};
enum ExtSerialPortConfigure
{
PORT_CFG_INIT = 0,
PORT_CFG_PARITY_CHECK,
PORT_CFG_DISABLE,
PORT_CFG_DIV,
};
struct SerialDataCfg
{
uint32_t serial_baud_rate;
uint8_t serial_data_bits;
uint8_t serial_stop_bits;
uint8_t serial_parity_mode;
uint8_t serial_bit_order;
uint8_t serial_invert_mode;
uint16_t serial_buffer_size;
uint8_t ext_uart_no;
enum ExtSerialPortConfigure port_configure;
};
enum IoctlDriverType
{
SERIAL_TYPE = 0,
SPI_TYPE,
I2C_TYPE,
PIN_TYPE,
DEFAULT_TYPE,
};
struct PrivIoctlCfg
{
enum IoctlDriverType ioctl_driver_type;
void *args;
};
/**********************mutex**************************/
int PrivMutexCreate(pthread_mutex_t *p_mutex, const pthread_mutexattr_t *attr);
int PrivMutexDelete(pthread_mutex_t *p_mutex);
int PrivMutexObtain(pthread_mutex_t *p_mutex);
int PrivMutexAbandon(pthread_mutex_t *p_mutex);
/*********************semaphore**********************/
int PrivSemaphoreCreate(sem_t *sem, int pshared, unsigned int value);
int PrivSemaphoreDelete(sem_t *sem);
int PrivSemaphoreObtainWait(sem_t *sem, const struct timespec *abstime);
int PrivSemaphoreObtainNoWait(sem_t *sem);
int PrivSemaphoreAbandon(sem_t *sem);
int32_t PrivSemaphoreSetValue(int32_t sem, uint16_t val);
/*********************task**************************/
int PrivTaskCreate(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine)(void *), void *arg);
int PrivTaskStartup(pthread_t *thread);
int PrivTaskDelete(pthread_t thread, int sig);
void PrivTaskQuit(void *value_ptr);
int PrivTaskDelay(int32_t ms);
/*********************driver*************************/
int PrivOpen(const char *path, int flags);
int PrivRead(int fd, void *buf, size_t len);
int PrivWrite(int fd, const void *buf, size_t len);
int PrivClose(int fd);
int PrivIoctl(int fd, int cmd, void *args);
/*********************memory***********************/
void *PrivMalloc(size_t size);
void *PrivRealloc(void *pointer, size_t size);
void *PrivCalloc(size_t count, size_t size);
void PrivFree(void *pointer);
#ifdef __cplusplus

View File

@ -24,9 +24,8 @@
int sem_init(sem_t *sem, int pshared, unsigned int value)
{
int32 ret = 0;
ret = UserSemaphoreCreate(value);
if (ret < 0) {
*sem = UserSemaphoreCreate(value);
if (*sem < 0) {
return -1;
}

View File

@ -1,3 +1,12 @@
/*
* @Author: chunyexixiaoyu
* @Date: 2021-09-24 16:33:15
* @LastEditTime: 2021-09-24 15:48:30
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \xiuos\Ubiquitous\RT_Thread\bsp\stm32f407-atk-coreboard\applications\main.c
*/
/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
@ -10,14 +19,27 @@
#include <rtthread.h>
#include <board.h>
#include <stdio.h>
#include <string.h>
#ifdef RT_USING_POSIX
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <dfs_poll.h>
#include <dfs_posix.h>
#include <dfs.h>
#ifdef RT_USING_POSIX_TERMIOS
#include <posix_termios.h>
#endif
#endif
#define LED0_PIN GET_PIN(F, 9)
extern int FrameworkInit();
int main(void)
{
int count = 1;
rt_pin_mode(LED0_PIN, PIN_MODE_OUTPUT);
rt_thread_mdelay(100);
FrameworkInit();
printf("XIUOS stm32f4 build %s %s\n",__DATE__,__TIME__);
while (count++)
{