forked from xuos/xiuos
Add sensor, modify makefile
This commit is contained in:
3
APP_Framework/lib/Makefile
Normal file
3
APP_Framework/lib/Makefile
Normal file
@@ -0,0 +1,3 @@
|
||||
SRC_DIR := app_newlib
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
3
APP_Framework/lib/app_newlib/Makefile
Normal file
3
APP_Framework/lib/app_newlib/Makefile
Normal file
@@ -0,0 +1,3 @@
|
||||
SRC_FILES := stdio.c
|
||||
|
||||
include $(KERNEL_ROOT)/compiler.mk
|
||||
97
APP_Framework/lib/app_newlib/fs_syscalls.c
Normal file
97
APP_Framework/lib/app_newlib/fs_syscalls.c
Normal file
@@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file fs_syscalls.c
|
||||
* @brief support newlib file system
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: fs_syscalls.c
|
||||
Description: support newlib file system
|
||||
Others: take RT-Thread v4.0.2/components/libc/compilers/newlib/syscalls.c for references
|
||||
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
|
||||
History:
|
||||
1. Date: 2021-04-25
|
||||
Author: AIIT XUOS Lab
|
||||
Modification: Use file system functions
|
||||
*************************************************/
|
||||
|
||||
#include <sys/errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int _close_r(struct _reent *ptr, int fd)
|
||||
{
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
int _fstat_r(struct _reent *ptr, int fd, struct stat *pstat)
|
||||
{
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _isatty_r(struct _reent *ptr, int fd)
|
||||
{
|
||||
if (fd >=0 && fd < 3)
|
||||
return 1;
|
||||
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int _link_r(struct _reent *ptr, const char *old, const char *new)
|
||||
{
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
_off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence)
|
||||
{
|
||||
return lseek(fd, pos, whence);
|
||||
}
|
||||
|
||||
int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
|
||||
{
|
||||
return open(file, flags, mode);
|
||||
}
|
||||
|
||||
_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
|
||||
{
|
||||
return read(fd, buf, nbytes);
|
||||
}
|
||||
|
||||
void * _sbrk_r(struct _reent *ptr, ptrdiff_t incr)
|
||||
{
|
||||
return NONE;
|
||||
}
|
||||
|
||||
int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat)
|
||||
{
|
||||
return stat(file, pstat);
|
||||
}
|
||||
|
||||
int _unlink_r(struct _reent *ptr, const char *file)
|
||||
{
|
||||
return unlink(file);
|
||||
}
|
||||
|
||||
int _wait_r(struct _reent *ptr, int *status)
|
||||
{
|
||||
ptr->_errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
_ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
|
||||
{
|
||||
return write(fd, buf, nbytes);
|
||||
}
|
||||
29
APP_Framework/lib/app_newlib/include/libc.h
Normal file
29
APP_Framework/lib/app_newlib/include/libc.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* 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 libc.h
|
||||
* @brief using newlib need include
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-25
|
||||
*/
|
||||
|
||||
#ifndef _LIBC_H__
|
||||
#define _LIBC_H__
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdarg.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#endif
|
||||
|
||||
70
APP_Framework/lib/app_newlib/mem_syscalls.c
Normal file
70
APP_Framework/lib/app_newlib/mem_syscalls.c
Normal file
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file mem_syscalls.c
|
||||
* @brief support newlib memory
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: mem_syscalls.c
|
||||
Description: support newlib memory
|
||||
Others: take RT-Thread v4.0.2/components/libc/compilers/newlib/syscalls.c for references
|
||||
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
|
||||
History:
|
||||
1. Date: 2021-04-25
|
||||
Author: AIIT XUOS Lab
|
||||
Modification: Use malloc, realloc, calloc and free functions
|
||||
*************************************************/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
void *_malloc_r (struct _reent *ptr, size_t size)
|
||||
{
|
||||
void* result = (void*)UserMalloc(size);
|
||||
|
||||
if (result == NULL)
|
||||
{
|
||||
ptr->_errno = 12;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void *_realloc_r (struct _reent *ptr, void *old, size_t newlen)
|
||||
{
|
||||
void* result = (void*)UserRealloc(old, newlen);
|
||||
|
||||
if (result == NULL)
|
||||
{
|
||||
ptr->_errno = 12;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void *_calloc_r (struct _reent *ptr, size_t size, size_t len)
|
||||
{
|
||||
void* result = (void*)UserCalloc(size, len);
|
||||
|
||||
if (result == NULL)
|
||||
{
|
||||
ptr->_errno = 12;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void _free_r (struct _reent *ptr, void *address)
|
||||
{
|
||||
UserFree (address);
|
||||
}
|
||||
155
APP_Framework/lib/app_newlib/stdio.c
Normal file
155
APP_Framework/lib/app_newlib/stdio.c
Normal file
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2017/10/15 bernard the first version
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file stdio.c
|
||||
* @brief support newlib stdio
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: stdio.c
|
||||
Description: support newlib stdio
|
||||
Others: take RT-Thread v4.0.2/components/libc/compilers/newlib/stdio.c for references
|
||||
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
|
||||
History:
|
||||
1. Date: 2021-04-25
|
||||
Author: AIIT XUOS Lab
|
||||
Modification: Use set and get console functions
|
||||
*************************************************/
|
||||
|
||||
#include <libc.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define STDIO_DEVICE_NAME_MAX 32
|
||||
|
||||
static FILE* std_console = NULL;
|
||||
|
||||
/**
|
||||
* This function will set system console device.
|
||||
*
|
||||
* @param device_name the name of device
|
||||
* @param mode the mode
|
||||
*
|
||||
* @return file number on success; or -1 on failure
|
||||
*/
|
||||
int LibcStdioSetConsole(const char* device_name, int mode)
|
||||
{
|
||||
FILE *fp;
|
||||
char name[STDIO_DEVICE_NAME_MAX];
|
||||
char *file_mode;
|
||||
|
||||
snprintf(name, sizeof(name) - 1, "/dev/%s", device_name);
|
||||
name[STDIO_DEVICE_NAME_MAX - 1] = '\0';
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
case O_RDWR:
|
||||
file_mode = "r+";
|
||||
break;
|
||||
|
||||
case O_WRONLY:
|
||||
file_mode = "wb";
|
||||
break;
|
||||
|
||||
default:
|
||||
file_mode = "rb";
|
||||
break;
|
||||
}
|
||||
|
||||
/* try to open file */
|
||||
fp = fopen(name, file_mode);
|
||||
if (fp)
|
||||
{
|
||||
/* set the fp buffer */
|
||||
setvbuf(fp, NULL, _IONBF, 0);
|
||||
|
||||
if (std_console)
|
||||
/* try to close console device */
|
||||
fclose(std_console);
|
||||
std_console = fp;
|
||||
|
||||
if (mode == O_RDWR)
|
||||
{
|
||||
/* set _stdin as std_console */
|
||||
_GLOBAL_REENT->_stdin = std_console;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* set NULL */
|
||||
_GLOBAL_REENT->_stdin = NULL;
|
||||
}
|
||||
|
||||
if (mode == O_RDONLY)
|
||||
{
|
||||
/* set the _stdout as NULL */
|
||||
_GLOBAL_REENT->_stdout = NULL;
|
||||
/* set the _stderr as NULL */
|
||||
_GLOBAL_REENT->_stderr = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* set the _stdout as std_console */
|
||||
_GLOBAL_REENT->_stdout = std_console;
|
||||
/* set the _stderr as std_console */
|
||||
_GLOBAL_REENT->_stderr = std_console;
|
||||
}
|
||||
/* set the __sdidinit as 1 */
|
||||
_GLOBAL_REENT->__sdidinit = 1;
|
||||
}
|
||||
|
||||
if (std_console)
|
||||
/* return the file number */
|
||||
return fileno(std_console);
|
||||
/* failure and return -1 */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will get system console device.
|
||||
*
|
||||
* @return file number on success; or -1 on failure
|
||||
*/
|
||||
int LibcStdioGetConsole(void) {
|
||||
if (std_console)
|
||||
/* return the file number */
|
||||
return fileno(std_console);
|
||||
else
|
||||
/* failure and return -1 */
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will initialize the c library system.
|
||||
*
|
||||
* @return 0
|
||||
*/
|
||||
int LibcSystemInit(void)
|
||||
{
|
||||
#if defined(KERNEL_CONSOLE)
|
||||
HardwareDevType console;
|
||||
/* try to get console device */
|
||||
console = ObtainConsole();
|
||||
if (console)
|
||||
{
|
||||
#if defined(LIB_POSIX)
|
||||
/* set console device mode */
|
||||
LibcStdioSetConsole(console->dev_name, O_RDWR);
|
||||
#else
|
||||
/* set console device mode */
|
||||
LibcStdioSetConsole(console->dev_name, O_WRONLY);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
43
APP_Framework/lib/app_newlib/task_syscalls.c
Normal file
43
APP_Framework/lib/app_newlib/task_syscalls.c
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (c) 2006-2018, RT-Thread Development Team
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file task_syscalls.c
|
||||
* @brief support newlib abort
|
||||
* @version 1.0
|
||||
* @author AIIT XUOS Lab
|
||||
* @date 2021-04-25
|
||||
*/
|
||||
|
||||
/*************************************************
|
||||
File name: task_syscalls.c
|
||||
Description: support newlib abort
|
||||
Others: take RT-Thread v4.0.2/components/libc/compilers/newlib/syscalls.c for references
|
||||
https://github.com/RT-Thread/rt-thread/tree/v4.0.2
|
||||
History:
|
||||
1. Date: 2021-04-25
|
||||
Author: AIIT XUOS Lab
|
||||
Modification: Use abort function
|
||||
*************************************************/
|
||||
|
||||
|
||||
void abort(void)
|
||||
{
|
||||
KTaskDescriptorType current = GetKTaskDescriptor();
|
||||
if (current)
|
||||
{
|
||||
KPrintf("Task:%-8.*s will be aborted!\n", NAME_NUM_MAX, current->task_base_info.name);
|
||||
/* pend current task */
|
||||
SuspendKTask(current->id.id);
|
||||
/* schedule */
|
||||
DO_KTASK_ASSIGN;
|
||||
}
|
||||
|
||||
while (1);
|
||||
}
|
||||
32
APP_Framework/lib/app_newlib/time_syscalls.c
Normal file
32
APP_Framework/lib/app_newlib/time_syscalls.c
Normal file
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* 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 <sys/time.h>
|
||||
|
||||
time_t time(time_t *t)
|
||||
{
|
||||
NULL_PARAM_CHECK(t);
|
||||
time_t current = 0;
|
||||
|
||||
#ifdef RESOURCES_RTC
|
||||
struct RtcSetParam rtc_set_param;
|
||||
rtc_set_param.rtc_set_cmd = OPER_RTC_GET_TIME;
|
||||
rtc_set_param.time = ¤t;
|
||||
|
||||
RtcDrvSetFunction(RTC_DRV_NAME, &rtc_set_param);
|
||||
#endif
|
||||
|
||||
*t = current;
|
||||
|
||||
return current;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user