update transform in rt-thread and sensor framework

it is perfect
This commit is contained in:
xuedongliang 2021-09-27 16:48:22 +08:00
commit 58b3e0b6a6
15 changed files with 454 additions and 8 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,7 +11,7 @@
*/
#include <stdio.h>
#include <string.h>
#include <user_api.h>
#include <transform.h>
extern int SensorFrameworkInit(void);
extern int AdapterFrameworkInit(void);

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

@ -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

@ -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++)
{