forked from xuos/xiuos
APP_Framework/Framework/:update transform layer in rt-thread.
This commit is contained in:
parent
4a07f534d8
commit
3fdc18e837
|
@ -5,7 +5,7 @@ Import('rtconfig')
|
||||||
cwd = GetCurrentDir()
|
cwd = GetCurrentDir()
|
||||||
DEPENDS = [""]
|
DEPENDS = [""]
|
||||||
|
|
||||||
SOURCES = []
|
SOURCES = ['transform.c']
|
||||||
path = [cwd]
|
path = [cwd]
|
||||||
objs = DefineGroup('transform', src = SOURCES, depend = DEPENDS,CPPPATH = path)
|
objs = DefineGroup('transform', src = SOURCES, depend = DEPENDS,CPPPATH = path)
|
||||||
Return("objs")
|
Return("objs")
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
|
@ -30,19 +30,23 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <pthread_internal.h>
|
||||||
|
#include <semaphore.h>
|
||||||
#include <sched.h>
|
#include <sched.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <dfs_poll.h>
|
#include <dfs_poll.h>
|
||||||
|
#include <dfs_posix.h>
|
||||||
|
#include <dfs.h>
|
||||||
#ifdef RT_USING_POSIX_TERMIOS
|
#ifdef RT_USING_POSIX_TERMIOS
|
||||||
#include <posix_termios.h>
|
#include <posix_termios.h>
|
||||||
#endif
|
#endif
|
||||||
#ifdef DRV_USING_OV2640
|
#ifdef DRV_USING_OV2640
|
||||||
#include <drv_ov2640.h>
|
#include <drv_ov2640.h>
|
||||||
#endif
|
#endif
|
||||||
#if defined(RT_USING_SAL)
|
#if defined(RT_USING_SAL)&& defined (RT_USING_LWIP)
|
||||||
#include <netdb.h>
|
#include <netdb.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#else
|
#elif defined RT_USING_LWIP
|
||||||
#include <lwip/netdb.h>
|
#include <lwip/netdb.h>
|
||||||
#include <lwip/sockets.h>
|
#include <lwip/sockets.h>
|
||||||
#endif /* RT_USING_SAL */
|
#endif /* RT_USING_SAL */
|
||||||
|
@ -50,6 +54,139 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Reference in New Issue