Merge branch 'prepare_for_master' of https://git.trustie.net/xuos/xiuos into xidatong

This commit is contained in:
Liu_Weichao 2022-08-24 10:09:43 +08:00
commit 6fc09a8864
1012 changed files with 116685 additions and 4 deletions

View File

@ -6,6 +6,10 @@ config ADAPTER_E220
bool "Using lora adapter device E220-400T22S"
default n
config ADAPTER_E22
bool "Using lora adapter device E22-400T33D"
default n
choice
prompt "Lora device adapter select net role type "
default AS_LORA_CLIENT_ROLE
@ -39,4 +43,8 @@ endif
if ADAPTER_E220
source "$APP_DIR/Framework/connection/lora/e220/Kconfig"
endif
if ADAPTER_E22
source "$APP_DIR/Framework/connection/lora/e22/Kconfig"
endif

View File

@ -28,6 +28,10 @@ extern AdapterProductInfoType Sx1278Attach(struct Adapter *adapter);
extern AdapterProductInfoType E220Attach(struct Adapter *adapter);
#endif
#ifdef ADAPTER_E22
extern AdapterProductInfoType E22Attach(struct Adapter *adapter);
#endif
//#define CLIENT_UPDATE_MODE
#define GATEWAY_CMD_MODE
@ -887,6 +891,19 @@ int AdapterLoraInit(void)
adapter->done = product_info->model_done;
#endif
#ifdef ADAPTER_E22
AdapterProductInfoType product_info = E22Attach(adapter);
if (!product_info) {
printf("AdapterLoraInit e22 attach error\n");
PrivFree(adapter);
return -1;
}
adapter->product_info_flag = 1;
adapter->info = product_info;
adapter->done = product_info->model_done;
#endif
PrivSemaphoreCreate(&adapter->sem, 0, 0);
PrivSemaphoreCreate(&gateway_recv_data_sem, 0, 0);

View File

@ -0,0 +1,28 @@
config ADAPTER_LORA_E22
string "E22-400T33D adapter name"
default "e22"
if ADD_XIZI_FETURES
endif
if ADD_NUTTX_FETURES
config ADAPTER_E22_M0_PATH
string "E22 M0 pin device"
default "/dev/gpio0"
config ADAPTER_E22_M1_PATH
string "E22 M1 pin device"
default "/dev/gpio1"
config ADAPTER_E22_DRIVER
string "E22 device uart driver path"
default "/dev/ttyS3"
endif
if ADD_RTTHREAD_FETURES
endif

View File

@ -0,0 +1,6 @@
############################################################################
# APP_Framework/Framework/connection/lora/e22/Make.defs
############################################################################
ifneq ($(CONFIG_ADAPTER_E22),)
CONFIGURED_APPS += $(APPDIR)/../../../APP_Framework/Framework/connection/lora/e22
endif

View File

@ -0,0 +1,7 @@
include $(KERNEL_ROOT)/.config
ifeq ($(CONFIG_ADD_NUTTX_FETURES),y)
include $(APPDIR)/Make.defs
CSRCS += e22.c
include $(APPDIR)/Application.mk
endif

View File

@ -0,0 +1,509 @@
/*
* 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 e22.c
* @brief Implement the connection E22-400T22S lora adapter function
* @version 2.0
* @author AIIT XUOS Lab
* @date 2022.4.20
*/
#include <adapter.h>
#define E22_GATEWAY_ADDRESS 0xFFFF
#define E22_CHANNEL 0x05
#ifdef AS_LORA_GATEWAY_ROLE
#define E22_ADDRESS E22_GATEWAY_ADDRESS
#endif
#ifdef AS_LORA_CLIENT_ROLE
#define E22_ADDRESS ADAPTER_LORA_NET_ROLE_ID
#endif
#define E22_UART_BAUD_RATE 115200
enum E22LoraMode
{
DATA_TRANSFER_MODE = 0, //M1 : M0 = 0 : 0
WOR_SEND_MODE, //M1 : M0 = 0 : 1
CONFIGURE_MODE, //M1 : M0 = 1 : 0
SLEEP_MODE, //M1 : M0 = 1 : 1
};
/**
* @description: Config E22 work mode by set M1/M0 pin
* @param mode Lora working mode
* @return NULL
*/
static void E22LoraModeConfig(enum E22LoraMode mode)
{
int m0_fd, m1_fd;
//delay 1s , wait AUX ready
PrivTaskDelay(1000);
m0_fd = PrivOpen(ADAPTER_E22_M0_PATH, O_RDWR);
if (m0_fd < 0) {
printf("open %s error\n", ADAPTER_E22_M0_PATH);
return;
}
m1_fd = PrivOpen(ADAPTER_E22_M1_PATH, O_RDWR);
if (m1_fd < 0) {
printf("open %s error\n", ADAPTER_E22_M1_PATH);
return;
}
//Both M0 and M1 GPIO are outputs mode, set M0 and M1 high or low
switch (mode)
{
case DATA_TRANSFER_MODE:
PrivIoctl(m1_fd, GPIOC_WRITE, (unsigned long)GPIO_LOW);
PrivIoctl(m0_fd, GPIOC_WRITE, (unsigned long)GPIO_LOW);
break;
case WOR_SEND_MODE:
PrivIoctl(m1_fd, GPIOC_WRITE, (unsigned long)GPIO_LOW);
PrivIoctl(m0_fd, GPIOC_WRITE, (unsigned long)GPIO_HIGH);
break;
case CONFIGURE_MODE:
PrivIoctl(m1_fd, GPIOC_WRITE, (unsigned long)GPIO_HIGH);
PrivIoctl(m0_fd, GPIOC_WRITE,(unsigned long)GPIO_LOW);
break;
case SLEEP_MODE:
PrivIoctl(m1_fd, GPIOC_WRITE, (unsigned long)GPIO_HIGH);
PrivIoctl(m0_fd, GPIOC_WRITE, (unsigned long)GPIO_HIGH);
break;
default:
break;
}
PrivClose(m0_fd);
PrivClose(m1_fd);
//delay 20ms , wait mode switch done
PrivTaskDelay(20);
}
/**
* @description: Switch baud rate to register bit
* @param baud_rate - baud_rate
* @return baud_rate_bit
*/
static uint8 E22BaudRateSwitch(uint32 baud_rate)
{
uint8 baud_rate_bit;
switch (baud_rate)
{
case 1200:
baud_rate_bit = 0x0;
break;
case 2400:
baud_rate_bit = 0x1;
break;
case 4800:
baud_rate_bit = 0x2;
break;
case 9600:
baud_rate_bit = 0x3;
break;
case 19200:
baud_rate_bit = 0x4;
break;
case 38400:
baud_rate_bit = 0x5;
break;
case 57600:
baud_rate_bit = 0x6;
break;
case 115200:
baud_rate_bit = 0x7;
break;
default:
break;
}
return baud_rate_bit;
}
/**
* @description: Set E22 register, such as addresschannelbaud rate...
* @param adapter - lora adapter
* @param address - address
* @param channel - channel
* @param baud_rate - baud_rate
* @return success: 0, failure: -1
*/
static int E22SetRegisterParam(struct Adapter *adapter, uint16 address, uint8 channel, uint32 baud_rate)
{
int ret;
uint8 buffer[50] = {0};
uint8 baud_rate_bit = E22BaudRateSwitch(baud_rate);
E22LoraModeConfig(CONFIGURE_MODE);
PrivTaskDelay(30);
buffer[0] = 0xC0; //write register order
buffer[1] = 0x00; //register start-address
buffer[2] = 0x09; //register length
buffer[3] = (address >> 8) & 0xFF; //high address
buffer[4] = address & 0xFF; //low adderss
buffer[5] = 0x00; //net id
buffer[6] = ((baud_rate_bit << 5) & 0xE0) | 0x04; // baud、stop bits、air rate
buffer[7] = 0x00;
buffer[8] = channel; //channel
buffer[9] = 0x03;
buffer[10] = 0; //high-cipher
buffer[11] = 0; //low-cipher
ret = PrivWrite(adapter->fd, (void *)buffer, 12);
if(ret < 0){
printf("E22SetRegisterParam send failed %d!\n", ret);
}
PrivTaskDelay(1000);
ret = PrivRead(adapter->fd, buffer, 19);
if(ret < 0){
printf("E22 RegisterParam get failed %d!\n", ret);
}
E22LoraModeConfig(DATA_TRANSFER_MODE);
PrivTaskDelay(1000);
return 0;
}
/**
* @description: Get E22 register, such as addresschannelbaud rate...
* @param buf - data buf
* @return success: 0, failure: -1
*/
static int E22GetRegisterParam(uint8 *buf)
{
int ret;
uint8 buffer[20] = {0};
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_LORA_NAME);
if (NULL == adapter) {
printf("E22GetRegisterParam find lora adapter error\n");
return -1;
}
E22LoraModeConfig(CONFIGURE_MODE);
PrivTaskDelay(30);
buffer[0] = 0xC1; //read register order
buffer[1] = 0x00; //register start-address
buffer[2] = 0x09; //register length
ret = PrivWrite(adapter->fd, (void *)buffer, 3);
if(ret < 0){
printf("E22GetRegisterParam send failed %d!\n", ret);
}
PrivTaskDelay(1000);
ret = PrivRead(adapter->fd, buf, 19);
if(ret < 0){
printf("E22 RegisterParam get failed %d!\n", ret);
}
E22LoraModeConfig(DATA_TRANSFER_MODE);
PrivTaskDelay(1000);
return 0;
}
/**
* @description: Open E22 uart function
* @param adapter - Lora device pointer
* @return success: 0, failure: -1
*/
static int E22Open(struct Adapter *adapter)
{
int ret = 0;
struct termios cfg;
/*step1: open e22 uart port*/
adapter->fd = PrivOpen(ADAPTER_E22_DRIVER, O_RDWR);
if (adapter->fd < 0) {
printf("E22Open get uart %s fd error\n", ADAPTER_E22_DRIVER);
return -1;
}
tcgetattr(adapter->fd, &cfg);
cfsetspeed(&cfg, BAUD_RATE_9600);
tcsetattr(adapter->fd, TCSANOW, &cfg);
E22SetRegisterParam(adapter, E22_ADDRESS, E22_CHANNEL, E22_UART_BAUD_RATE);
cfsetspeed(&cfg, E22_UART_BAUD_RATE);
tcsetattr(adapter->fd, TCSANOW, &cfg);
ADAPTER_DEBUG("E22Open done\n");
return 0;
}
/**
* @description: Close E22 uart function
* @param adapter - Lora device pointer
* @return success: 0, failure: -1
*/
static int E22Close(struct Adapter *adapter)
{
/*step1: close e22 uart port*/
int ret;
ret = PrivClose(adapter->fd);
if(ret < 0) {
printf("E22 close failed: %d!\n", ret);
return -1;
}
ADAPTER_DEBUG("E22 Close done\n");
return 0;
}
/**
* @description: E22 ioctl function
* @param adapter - Lora device pointer
* @param cmd - ioctl cmd
* @param args - iotl params
* @return success: 0, failure: -1
*/
static int E22Ioctl(struct Adapter *adapter, int cmd, void *args)
{
/*to do*/
return 0;
}
/**
* @description: E22 join lora net group function
* @param adapter - Lora device pointer
* @param priv_net_group - priv_net_group params
* @return success: 0, failure: -1
*/
static int E22Join(struct Adapter *adapter, unsigned char *priv_net_group)
{
int ret;
struct AdapterData *priv_net_group_data = (struct AdapterData *)priv_net_group;
ret = PrivWrite(adapter->fd, (void *)priv_net_group_data->buffer, priv_net_group_data->len);
if(ret < 0) {
printf("E22 Join net group failed: %d!\n", ret);
}
return ret;
}
/**
* @description: E22 send data function
* @param adapter - Lora device pointer
* @param buf - data buffers
* @param len - data len
* @return success: 0, failure: -1
*/
static int E22Send(struct Adapter *adapter, const void *buf, size_t len)
{
int ret;
ret = PrivWrite(adapter->fd, (void *)buf, len);
if(ret < 0){
printf("send failed %d!\n", ret);
}
return ret;
}
/**
* @description: E22 receive data function
* @param adapter - Lora device pointer
* @param buf - data buffers
* @param len - data len
* @return success: 0, failure: -1
*/
static int E22Recv(struct Adapter *adapter, void *buf, size_t len)
{
int recv_len, recv_len_continue;
uint8 *recv_buf = PrivMalloc(len);
recv_len = PrivRead(adapter->fd, recv_buf, len);
if (recv_len) {
while (recv_len < len) {
recv_len_continue = PrivRead(adapter->fd, recv_buf + recv_len, len - recv_len);
if (recv_len_continue) {
recv_len += recv_len_continue;
} else {
recv_len = 0;
break;
}
}
memcpy(buf, recv_buf, len);
}
PrivFree(recv_buf);
return recv_len;
}
/**
* @description: E22 quit lora net group function
* @param adapter - Lora device pointer
* @param priv_net_group - priv_net_group params
* @return success: 0, failure: -1
*/
static int E22Quit(struct Adapter *adapter, unsigned char *priv_net_group)
{
int ret;
struct AdapterData *priv_net_group_data = (struct AdapterData *)priv_net_group;
ret = PrivWrite(adapter->fd, (void *)priv_net_group_data->buffer, priv_net_group_data->len);
if(ret < 0){
printf("E22 quit net group failed %d!\n", ret);
}
return ret;
}
static const struct PrivProtocolDone e22_done =
{
.open = E22Open,
.close = E22Close,
.ioctl = E22Ioctl,
.setup = NULL,
.setdown = NULL,
.setaddr = NULL,
.setdns = NULL,
.setdhcp = NULL,
.ping = NULL,
.netstat = NULL,
.join = E22Join,
.send = E22Send,
.recv = E22Recv,
.quit = E22Quit,
};
AdapterProductInfoType E22Attach(struct Adapter *adapter)
{
struct AdapterProductInfo *product_info = malloc(sizeof(struct AdapterProductInfo));
if (!product_info) {
printf("E22Attach malloc product_info error\n");
return NULL;
}
strncpy(product_info->model_name, ADAPTER_LORA_E22,sizeof(product_info->model_name));
product_info->model_done = (void *)&e22_done;
return product_info;
}
//###################TEST####################
static void LoraOpen(void)
{
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_LORA_NAME);
if (NULL == adapter) {
printf("LoraReceive find lora adapter error\n");
return;
}
E22Open(adapter);
}
static void LoraRead(void *parameter)
{
int RevLen;
int i, cnt = 0;
uint8 buffer[256];
memset(buffer, 0, 256);
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_LORA_NAME);
if (NULL == adapter) {
printf("LoraRead find lora adapter error\n");
return;
}
while (1)
{
printf("ready to read lora data\n");
RevLen = E22Recv(adapter, buffer, 256);
if (RevLen) {
printf("lora get data %u\n", RevLen);
for (i = 0; i < RevLen; i ++) {
printf("i %u data 0x%x\n", i, buffer[i]);
}
memset(buffer, 0, 256);
PrivTaskDelay(1000);
cnt ++;
E22Send(adapter, &cnt, 1);
}
}
}
void E22LoraReceive(void)
{
int ret;
pthread_t thread;
pthread_attr_t attr = PTHREAD_ATTR_INITIALIZER;
attr.priority = 80;
attr.stacksize = 2048;
LoraOpen();
ret = PrivTaskCreate(&thread, &attr, (void*)LoraRead, NULL);
if (ret < 0) {
printf("task lora read create failed, status=%d\n", ret);
return;
}
}
void E22LoraSend(int argc, char *argv[])
{
struct Adapter *adapter = AdapterDeviceFindByName(ADAPTER_LORA_NAME);
if (NULL == adapter) {
printf("LoraRead find lora adapter error\n");
return;
}
if (argc == 2) {
char Msg[256] = {0};
strncpy(Msg, argv[1], 256);
E22Open(adapter);
E22Send(adapter, Msg, strlen(Msg));
E22Close(adapter);
}
}

View File

@ -0,0 +1,30 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#
config EXAMPLES_E22
tristate "E22 driver example"
default n
depends on STM32_USART3
---help---
Enable the e22 driver example
if EXAMPLES_E22
config EXAMPLES_E22_PROGNAME
string "Program name"
default "e22"
---help---
This is the name of the program that will be used when the NSH ELF
program is installed.
config EXAMPLES_E22_PRIORITY
int "E22 task priority"
default 100
config EXAMPLES_E22_STACKSIZE
int "E22 stack size"
default DEFAULT_TASK_STACKSIZE
endif

View File

@ -0,0 +1,23 @@
############################################################################
# apps/examples/gpio/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifneq ($(CONFIG_EXAMPLES_E22),)
CONFIGURED_APPS += $(APPDIR)/examples/e22_demo
endif

View File

@ -0,0 +1,34 @@
############################################################################
# apps/examples/gpio/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(APPDIR)/Make.defs
# GPIO, World! built-in application info
PROGNAME = $(CONFIG_EXAMPLES_E22_PROGNAME)
PRIORITY = $(CONFIG_EXAMPLES_E22_PRIORITY)
STACKSIZE = $(CONFIG_EXAMPLES_E22_STACKSIZE)
MODULE = $(CONFIG_EXAMPLES_E22)
# GPIO, World! Example
MAINSRC = e22_main.c
include $(APPDIR)/Application.mk

View File

@ -0,0 +1,109 @@
/*
* Copyright (c) 2020 AIIT XUOS Lab
* XiOS 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 e22_main.c
* @brief e22 demo
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022.05.20
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>
#include <nuttx/ioexpander/gpio.h>
int main(int argc, FAR char *argv[])
{
int fd, m0fd, m1fd;
int ret;
int i;
struct termios tio;
char sendbuffer1[4] = {0xC0,0x05,0x01,0x09};
char sendbuffer2[7] = {0xC0,0x00,0x04,0x12,0x34,0x00,0x61};
char sendbuffer3[3] = {0xC1,0x00,0x04};
char buffer[256];
int readlen;
fd = open("/dev/ttyS3", O_RDWR);
if(fd < 0)
{
printf("Error opening serial: %d\n", fd);;
}
ret = tcgetattr(fd, &tio);
if (ret < 0)
{
printf("Error getting attributes: %d\n", ret);
}
ret = cfsetspeed(&tio, B9600);
if (ret < 0)
{
printf("Error setting baud rate: %d\n", ret);
}
ret = tcsetattr(fd, TCSANOW, &tio);
if (ret < 0)
{
printf("Error getting attributes: %d\n", ret);
}
m0fd = open("/dev/gpout0", O_RDWR);
m1fd = open("/dev/gpout1", O_RDWR);
ioctl(m0fd, GPIOC_WRITE, (unsigned long)0);
ioctl(m1fd, GPIOC_WRITE, (unsigned long)1);
sleep(1);
write(fd, sendbuffer1,4);
sleep(1);
readlen = read(fd, buffer, 256);
printf("readlen1 = %d\n", readlen);
for(i = 0;i< readlen; ++i)
{
printf("0x%x\n", buffer[i]);
}
write(fd, sendbuffer2,7);
sleep(1);
readlen = read(fd, buffer, 256);
printf("readlen1 = %d\n", readlen);
for(i = 0;i< readlen; ++i)
{
printf("0x%x\n", buffer[i]);
}
write(fd, sendbuffer3,3);
sleep(1);
readlen = read(fd, buffer, 256);
printf("readlen1 = %d\n", readlen);
for(i = 0;i< readlen; ++i)
{
printf("0x%x\n", buffer[i]);
}
close(fd);
close(m0fd);
close(m1fd);
return 0;
}

View File

@ -635,6 +635,14 @@ config NSH_DISABLE_E220_LORA_SEND
bool "Disable e220 Lora send."
default n
config NSH_DISABLE_E22_LORA_RECEIVE
bool "Disable e22 Lora receive."
default n
config NSH_DISABLE_E22_LORA_SEND
bool "Disable e22 Lora send."
default n
config NSH_DISABLE_ADAPTER_BLUETOOTH_TEST
bool "Disable hc08 AdapterBlueToothTest."
default n

View File

@ -1527,7 +1527,8 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb,
int cmd_recvzigbee(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif
#if (defined(CONFIG_ADAPTER_LORA_SX1278) || defined(CONFIG_ADAPTER_LORA_E220)) && !defined(CONFIG_NSH_DISABLE_ADAPTER_LORATEST)
#if (defined(CONFIG_ADAPTER_LORA_SX1278) || defined(CONFIG_ADAPTER_LORA_E220) || defined(CONFIG_ADAPTER_LORA_E22)) && \
!defined(CONFIG_NSH_DISABLE_ADAPTER_LORATEST)
int cmd_AdapterLoraTest(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif
@ -1543,6 +1544,14 @@ int nsh_foreach_var(FAR struct nsh_vtbl_s *vtbl, nsh_foreach_var_t cb,
int cmd_E220LoraSend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif
#if defined(CONFIG_ADAPTER_LORA_E22) && !defined(CONFIG_NSH_DISABLE_E22_LORA_RECEIVE)
int cmd_E22LoraReceive(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif
#if defined(CONFIG_ADAPTER_LORA_E22) && !defined(CONFIG_NSH_DISABLE_E22_LORA_SEND)
int cmd_E22LoraSend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif
#if defined(CONFIG_ADAPTER_BLUETOOTH_HC08) && !defined(CONFIG_NSH_DISABLE_ADAPTER_BLUETOOTH_TEST)
int cmd_AdapterBlueToothTest(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv);
#endif

View File

@ -36,6 +36,8 @@
#include "nsh.h"
#include "nsh_console.h"
extern int FrameworkInit(void);
/****************************************************************************
* Name: cmd_Ch438
****************************************************************************/
@ -322,7 +324,8 @@ int cmd_AdapterWifiTest(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
}
#endif
#if (defined(CONFIG_ADAPTER_LORA_SX1278) || defined(CONFIG_ADAPTER_LORA_E220)) && !defined(CONFIG_NSH_DISABLE_ADAPTER_LORATEST)
#if (defined(CONFIG_ADAPTER_LORA_SX1278) || defined(CONFIG_ADAPTER_LORA_E220) || defined(CONFIG_ADAPTER_LORA_E22)) && \
!defined(CONFIG_NSH_DISABLE_ADAPTER_LORATEST)
extern int AdapterLoraTest(void);
int cmd_AdapterLoraTest(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
@ -366,6 +369,28 @@ int cmd_E220LoraSend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
}
#endif
#if defined(CONFIG_ADAPTER_LORA_E22) && !defined(CONFIG_NSH_DISABLE_E22_LORA_RECEIVE)
void E22LoraReceive(void);
int cmd_E22LoraReceive(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
nsh_output(vtbl, "Hello, world!\n");
FrameworkInit();
E22LoraReceive();
return OK;
}
#endif
#if defined(CONFIG_ADAPTER_LORA_E22) && !defined(CONFIG_NSH_DISABLE_E22_LORA_SEND)
extern void E22LoraSend(int argc, char *argv[]);
int cmd_E22LoraSend(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)
{
nsh_output(vtbl, "Hello, world!\n");
FrameworkInit();
E22LoraSend(argc,argv);
return OK;
}
#endif
#if defined(CONFIG_ADAPTER_BLUETOOTH_HC08) && !defined(CONFIG_NSH_DISABLE_ADAPTER_BLUETOOTH_TEST)
extern int AdapterBlueToothTest(void);
int cmd_AdapterBlueToothTest(FAR struct nsh_vtbl_s *vtbl, int argc, char **argv)

View File

@ -672,8 +672,9 @@ static const struct cmdmap_s g_cmdmap[] =
{ "recvzigbee", cmd_recvzigbee, 1, 1, "[receive message.]" },
#endif
#if (defined(CONFIG_ADAPTER_LORA_SX1278) || defined(CONFIG_ADAPTER_LORA_E220)) && !defined(CONFIG_NSH_DISABLE_ADAPTER_LORATEST)
{ "AdapterLoraTest", cmd_AdapterLoraTest, 1, 1, "[Lora sx128 test.]" },
#if (defined(CONFIG_ADAPTER_LORA_SX1278) || defined(CONFIG_ADAPTER_LORA_E220) || defined(CONFIG_ADAPTER_LORA_E22)) && \
!defined(CONFIG_NSH_DISABLE_ADAPTER_LORATEST)
{ "AdapterLoraTest", cmd_AdapterLoraTest, 1, 1, "[Lora test.]" },
#endif
#if defined(CONFIG_ADAPTER_4G_EC200T) && !defined(CONFIG_NSH_DISABLE_ADAPTER_4GTEST)
@ -688,6 +689,14 @@ static const struct cmdmap_s g_cmdmap[] =
{ "E220Send", cmd_E220LoraSend, 1, 2, "[e220loraSend <message>]" },
#endif
#if defined(CONFIG_ADAPTER_LORA_E22) && !defined(CONFIG_NSH_DISABLE_E22_LORA_RECEIVE)
{ "E22Receive", cmd_E22LoraReceive, 1, 1, "[e22 lora receive.]" },
#endif
#if defined(CONFIG_ADAPTER_LORA_E22) && !defined(CONFIG_NSH_DISABLE_E22_LORA_SEND)
{ "E22Send", cmd_E22LoraSend, 1, 2, "[e22loraSend <message>]" },
#endif
#if defined(CONFIG_ADAPTER_BLUETOOTH_HC08) && !defined(CONFIG_NSH_DISABLE_ADAPTER_BLUETOOTH_TEST)
{ "AdapterBlueToothTest", cmd_AdapterBlueToothTest, 1, 1, "[BlueTooth hc08 test.]" },
#endif

View File

@ -2051,6 +2051,18 @@ source "binfmt/Kconfig"
endmenu
menu "Library Routines"
choice
prompt "Selcet C library,built-in libc or musl libc."
default NUTTX_BUILT_IN_LIBC
config NUTTX_BUILT_IN_LIBC
bool "nuttx built-in libc"
config MUSL_LIBC
bool "musl libc"
endchoice
source "libs/libc/Kconfig"
source "libs/libxx/Kconfig"
source "libs/libdsp/Kconfig"

View File

@ -0,0 +1,68 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_ARCH_FPU is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_CMDPARMS is not set
CONFIG_ADD_NUTTX_FETURES=y
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="stm32f4discovery"
CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP="stm32"
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F407VG=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LATE_INITIALIZE=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BUILTIN=y
CONFIG_EXAMPLES_HELLO=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_HOST_WINDOWS=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_MM_REGIONS=2
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=114688
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_PWR=y
CONFIG_STM32_SPI1=y
CONFIG_STM32_USART2=y
CONFIG_STM32_USART3=y
CONFIG_SERIAL_TERMIOS=y
CONFIG_SYSTEM_NSH=y
CONFIG_USART2_RXBUFSIZE=128
CONFIG_USART2_SERIAL_CONSOLE=y
CONFIG_USART2_TXBUFSIZE=128
CONFIG_DEV_GPIO=y
CONFIG_BOARDCTL_RESET=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_READLINE_CMD_HISTORY_LEN=100
CONFIG_READLINE_CMD_HISTORY_LINELEN=120
CONFIG_READLINE_TABCOMPLETION=y
CONFIG_SUPPORT_CONNECTION_FRAMEWORK=y
CONFIG_CONNECTION_FRAMEWORK_DEBUG=y
CONFIG_CONNECTION_ADAPTER_LORA=y
CONFIG_ADAPTER_E22=y
CONFIG_ADAPTER_LORA_E22="e22"
CONFIG_ADAPTER_E22_M0_PATH="/dev/gpio0"
CONFIG_ADAPTER_E22_M1_PATH="/dev/gpio1"
CONFIG_ADAPTER_E22_DRIVER="/dev/ttyS3"

View File

@ -0,0 +1,60 @@
#
# This file is autogenerated: PLEASE DO NOT EDIT IT.
#
# You can use "make menuconfig" to make any modifications to the installed .config file.
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
# modifications.
#
# CONFIG_ARCH_FPU is not set
# CONFIG_NSH_ARGCAT is not set
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
# CONFIG_NSH_CMDPARMS is not set
CONFIG_ADD_NUTTX_FETURES=y
CONFIG_ARCH="arm"
CONFIG_ARCH_BOARD="stm32f4discovery"
CONFIG_ARCH_BOARD_STM32F4_DISCOVERY=y
CONFIG_ARCH_BUTTONS=y
CONFIG_ARCH_CHIP="stm32"
CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F407VG=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BOARD_LATE_INITIALIZE=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_BUILTIN=y
CONFIG_EXAMPLES_HELLO=y
CONFIG_FS_PROCFS=y
CONFIG_HAVE_CXX=y
CONFIG_HAVE_CXXINITIALIZE=y
CONFIG_HOST_WINDOWS=y
CONFIG_INIT_ENTRYPOINT="nsh_main"
CONFIG_INTELHEX_BINARY=y
CONFIG_MM_REGIONS=2
CONFIG_NSH_BUILTIN_APPS=y
CONFIG_NSH_FILEIOSIZE=512
CONFIG_NSH_LINELEN=64
CONFIG_NSH_READLINE=y
CONFIG_PREALLOC_TIMERS=4
CONFIG_RAM_SIZE=114688
CONFIG_RAM_START=0x20000000
CONFIG_RAW_BINARY=y
CONFIG_RR_INTERVAL=200
CONFIG_SCHED_WAITPID=y
CONFIG_START_DAY=6
CONFIG_START_MONTH=12
CONFIG_START_YEAR=2011
CONFIG_STM32_JTAG_SW_ENABLE=y
CONFIG_STM32_PWR=y
CONFIG_STM32_SPI1=y
CONFIG_STM32_USART2=y
CONFIG_STM32_USART3=y
CONFIG_SERIAL_TERMIOS=y
CONFIG_SYSTEM_NSH=y
CONFIG_USART2_RXBUFSIZE=128
CONFIG_USART2_SERIAL_CONSOLE=y
CONFIG_USART2_TXBUFSIZE=128
CONFIG_DEV_GPIO=y
CONFIG_BOARDCTL_RESET=y
CONFIG_READLINE_CMD_HISTORY=y
CONFIG_READLINE_CMD_HISTORY_LEN=100
CONFIG_READLINE_CMD_HISTORY_LINELEN=120
CONFIG_READLINE_TABCOMPLETION=y

View File

@ -0,0 +1,184 @@
############################################################################
# boards/arm/stm32/stm32f4discovery/src/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
include $(TOPDIR)/Make.defs
CSRCS = stm32_boot.c stm32_bringup.c stm32_spi.c stm32_perfcount.c
ifeq ($(CONFIG_ARCH_LEDS),y)
CSRCS += stm32_autoleds.c
else
CSRCS += stm32_userleds.c
endif
ifeq ($(CONFIG_AUDIO_CS43L22),y)
CSRCS += stm32_cs43l22.c
endif
ifeq ($(CONFIG_ARCH_BUTTONS),y)
CSRCS += stm32_buttons.c
endif
ifeq ($(CONFIG_STM32_CAN_CHARDRIVER),y)
CSRCS += stm32_can.c
endif
ifeq ($(CONFIG_STM32_OTGFS),y)
CSRCS += stm32_usb.c
endif
ifeq ($(CONFIG_LCD_ST7567),y)
CSRCS += stm32_st7567.c
endif
ifeq ($(CONFIG_ENC28J60),y)
CSRCS += stm32_enc28j60.c
endif
ifeq ($(CONFIG_LPWAN_SX127X),y)
CSRCS += stm32_sx127x.c
endif
ifeq ($(CONFIG_LCD_MAX7219),y)
CSRCS += stm32_max7219.c
endif
ifeq ($(CONFIG_LCD_ST7032),y)
CSRCS += stm32_st7032.c
endif
ifeq ($(CONFIG_PCA9635PW),y)
CSRCS += stm32_pca9635.c
endif
ifeq ($(CONFIG_STM32_SDIO),y)
CSRCS += stm32_sdio.c
endif
ifeq ($(CONFIG_STM32_ETHMAC),y)
CSRCS += stm32_ethernet.c
endif
ifeq ($(CONFIG_LEDS_MAX7219),y)
CSRCS += stm32_max7219_leds.c
endif
ifeq ($(CONFIG_RGBLED),y)
CSRCS += stm32_rgbled.c
endif
ifeq ($(CONFIG_RTC_DS1307),y)
CSRCS += stm32_ds1307.c
endif
ifeq ($(CONFIG_PWM),y)
CSRCS += stm32_pwm.c
endif
ifeq ($(CONFIG_BOARDCTL),y)
CSRCS += stm32_appinit.c
ifeq ($(CONFIG_BOARDCTL_RESET),y)
CSRCS += stm32_reset.c
endif
endif
ifeq ($(CONFIG_ARCH_CUSTOM_PMINIT),y)
CSRCS += stm32_pm.c
endif
ifeq ($(CONFIG_PM_BUTTONS),y)
CSRCS += stm32_pmbuttons.c
endif
ifeq ($(CONFIG_ARCH_IDLE_CUSTOM),y)
CSRCS += stm32_idle.c
endif
ifeq ($(CONFIG_STM32_FSMC),y)
CSRCS += stm32_extmem.c
ifeq ($(CONFIG_LCD_SSD1289),y)
CSRCS += stm32_ssd1289.c
endif
endif
ifeq ($(CONFIG_LCD_SSD1351),y)
CSRCS += stm32_ssd1351.c
endif
ifeq ($(CONFIG_LCD_UG2864AMBAG01),y)
CSRCS += stm32_ug2864ambag01.c
endif
ifeq ($(CONFIG_LCD_UG2864HSWEG01),y)
CSRCS += stm32_ug2864hsweg01.c
endif
ifeq ($(CONFIG_TESTING_OSTEST),y)
CSRCS += stm32_ostest.c
endif
ifeq ($(CONFIG_TIMER),y)
CSRCS += stm32_timer.c
endif
ifeq ($(CONFIG_STM32_HCIUART),y)
ifeq ($(CONFIG_BLUETOOTH_UART),y)
CSRCS += stm32_hciuart.c
endif
endif
ifeq ($(CONFIG_STM32_ROMFS),y)
CSRCS += stm32_romfs_initialize.c
endif
ifeq ($(CONFIG_BOARDCTL_UNIQUEID),y)
CSRCS += stm32_uid.c
endif
ifeq ($(CONFIG_USBMSC),y)
CSRCS += stm32_usbmsc.c
endif
ifneq ($(CONFIG_STM32_ETHMAC),y)
ifeq ($(CONFIG_NETDEVICES),y)
CSRCS += stm32_netinit.c
endif
endif
ifeq ($(CONFIG_MMCSD_SPI),y)
CSRCS += stm32_mmcsd.c
endif
ifeq ($(CONFIG_WL_GS2200M),y)
CSRCS += stm32_gs2200m.c
endif
ifeq ($(CONFIG_LCD_ST7789),y)
CSRCS += stm32_st7789.c
endif
ifeq ($(CONFIG_DEV_GPIO),y)
CSRCS += stm32_gpio.c
endif
DEPPATH += --dep-path board
VPATH += :board
CFLAGS += $(shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board)

View File

@ -571,5 +571,14 @@ int stm32_bringup(void)
}
#endif /* CONFIG_SENSORS_HS300X */
#ifdef CONFIG_DEV_GPIO
ret = stm32_gpio_initialize();
if (ret < 0)
{
syslog(LOG_ERR, "Failed to initialize GPIO Driver: %d\n", ret);
return ret;
}
#endif
return ret;
}

View File

@ -0,0 +1,344 @@
/****************************************************************************
* boards/arm/stm32/stm32f4discovery/src/stm32_goio.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file stm32_goio.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-05-19
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/clock.h>
#include <nuttx/wdog.h>
#include <nuttx/ioexpander/gpio.h>
#include <arch/board/board.h>
#include "chip.h"
#include "stm32.h"
#include "stm32f4discovery.h"
#if defined(CONFIG_DEV_GPIO) && !defined(CONFIG_GPIO_LOWER_HALF)
/****************************************************************************
* Private Types
****************************************************************************/
struct stm32gpio_dev_s
{
struct gpio_dev_s gpio;
uint8_t id;
};
struct stm32gpint_dev_s
{
struct stm32gpio_dev_s stm32gpio;
pin_interrupt_t callback;
};
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
#if BOARD_NGPIOIN > 0
static int gpin_read(FAR struct gpio_dev_s *dev, FAR bool *value);
#endif
#if BOARD_NGPIOOUT > 0
static int gpout_read(FAR struct gpio_dev_s *dev, FAR bool *value);
static int gpout_write(FAR struct gpio_dev_s *dev, bool value);
#endif
#if BOARD_NGPIOINT > 0
static int stm32gpio_interrupt(int irq, void *context, void *arg);
static int gpint_read(FAR struct gpio_dev_s *dev, FAR bool *value);
static int gpint_attach(FAR struct gpio_dev_s *dev,
pin_interrupt_t callback);
static int gpint_enable(FAR struct gpio_dev_s *dev, bool enable);
#endif
/****************************************************************************
* Private Data
****************************************************************************/
#if BOARD_NGPIOIN > 0
static const struct gpio_operations_s gpin_ops =
{
.go_read = gpin_read,
.go_write = NULL,
.go_attach = NULL,
.go_enable = NULL,
};
/* This array maps the GPIO pins used as INPUT */
static const uint32_t g_gpioinputs[BOARD_NGPIOIN] =
{
};
static struct stm32gpio_dev_s g_gpin[BOARD_NGPIOIN];
#endif
#if BOARD_NGPIOOUT > 0
static const struct gpio_operations_s gpout_ops =
{
.go_read = gpout_read,
.go_write = gpout_write,
.go_attach = NULL,
.go_enable = NULL,
};
/* This array maps the GPIO pins used as OUTPUT */
static const uint32_t g_gpiooutputs[BOARD_NGPIOOUT] =
{
GPIO_E22_M0,
GPIO_E22_M1,
};
static struct stm32gpio_dev_s g_gpout[BOARD_NGPIOOUT];
#endif
#if BOARD_NGPIOINT > 0
static const struct gpio_operations_s gpint_ops =
{
.go_read = gpint_read,
.go_write = NULL,
.go_attach = gpint_attach,
.go_enable = gpint_enable,
};
/* This array maps the GPIO pins used as INTERRUPT INPUTS */
static const uint32_t g_gpiointinputs[BOARD_NGPIOINT] =
{
};
static struct stm32gpint_dev_s g_gpint[BOARD_NGPIOINT];
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
#if BOARD_NGPIOIN > 0
static int gpin_read(FAR struct gpio_dev_s *dev, FAR bool *value)
{
FAR struct stm32gpio_dev_s *stm32gpio =
(FAR struct stm32gpio_dev_s *)dev;
DEBUGASSERT(stm32gpio != NULL && value != NULL);
DEBUGASSERT(stm32gpio->id < BOARD_NGPIOIN);
gpioinfo("Reading...\n");
*value = stm32_gpioread(g_gpioinputs[stm32gpio->id]);
return OK;
}
#endif
#if BOARD_NGPIOOUT > 0
static int gpout_read(FAR struct gpio_dev_s *dev, FAR bool *value)
{
FAR struct stm32gpio_dev_s *stm32gpio =
(FAR struct stm32gpio_dev_s *)dev;
DEBUGASSERT(stm32gpio != NULL && value != NULL);
DEBUGASSERT(stm32gpio->id < BOARD_NGPIOOUT);
gpioinfo("Reading...\n");
*value = stm32_gpioread(g_gpiooutputs[stm32gpio->id]);
return OK;
}
static int gpout_write(FAR struct gpio_dev_s *dev, bool value)
{
FAR struct stm32gpio_dev_s *stm32gpio =
(FAR struct stm32gpio_dev_s *)dev;
DEBUGASSERT(stm32gpio != NULL);
DEBUGASSERT(stm32gpio->id < BOARD_NGPIOOUT);
gpioinfo("Writing %d\n", (int)value);
stm32_gpiowrite(g_gpiooutputs[stm32gpio->id], value);
return OK;
}
#endif
#if BOARD_NGPIOINT > 0
static int stm32gpio_interrupt(int irq, void *context, void *arg)
{
FAR struct stm32gpint_dev_s *stm32gpint =
(FAR struct stm32gpint_dev_s *)arg;
DEBUGASSERT(stm32gpint != NULL && stm32gpint->callback != NULL);
gpioinfo("Interrupt! callback=%p\n", stm32gpint->callback);
stm32gpint->callback(&stm32gpint->stm32gpio.gpio,
stm32gpint->stm32gpio.id);
return OK;
}
static int gpint_read(FAR struct gpio_dev_s *dev, FAR bool *value)
{
FAR struct stm32gpint_dev_s *stm32gpint =
(FAR struct stm32gpint_dev_s *)dev;
DEBUGASSERT(stm32gpint != NULL && value != NULL);
DEBUGASSERT(stm32gpint->stm32gpio.id < BOARD_NGPIOINT);
gpioinfo("Reading int pin...\n");
*value = stm32_gpioread(g_gpiointinputs[stm32gpint->stm32gpio.id]);
return OK;
}
static int gpint_attach(FAR struct gpio_dev_s *dev,
pin_interrupt_t callback)
{
FAR struct stm32gpint_dev_s *stm32gpint =
(FAR struct stm32gpint_dev_s *)dev;
gpioinfo("Attaching the callback\n");
/* Make sure the interrupt is disabled */
stm32_gpiosetevent(g_gpiointinputs[stm32gpint->stm32gpio.id], false,
false, false, NULL, NULL);
gpioinfo("Attach %p\n", callback);
stm32gpint->callback = callback;
return OK;
}
static int gpint_enable(FAR struct gpio_dev_s *dev, bool enable)
{
FAR struct stm32gpint_dev_s *stm32gpint =
(FAR struct stm32gpint_dev_s *)dev;
if (enable)
{
if (stm32gpint->callback != NULL)
{
gpioinfo("Enabling the interrupt\n");
/* Configure the interrupt for rising edge */
stm32_gpiosetevent(g_gpiointinputs[stm32gpint->stm32gpio.id],
true, false, false, stm32gpio_interrupt,
&g_gpint[stm32gpint->stm32gpio.id]);
}
}
else
{
gpioinfo("Disable the interrupt\n");
stm32_gpiosetevent(g_gpiointinputs[stm32gpint->stm32gpio.id],
false, false, false, NULL, NULL);
}
return OK;
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: stm32_gpio_initialize
*
* Description:
* Initialize GPIO drivers for use with /apps/examples/gpio
*
****************************************************************************/
int stm32_gpio_initialize(void)
{
int i;
int pincount;
#if BOARD_NGPIOIN > 0
pincount = 0;
for (i = 0; i < BOARD_NGPIOIN; i++)
{
/* Setup and register the GPIO pin */
g_gpin[i].gpio.gp_pintype = GPIO_INPUT_PIN;
g_gpin[i].gpio.gp_ops = &gpin_ops;
g_gpin[i].id = i;
gpio_pin_register(&g_gpin[i].gpio, pincount);
/* Configure the pin that will be used as input */
stm32_configgpio(g_gpioinputs[i]);
pincount++;
}
#endif
#if BOARD_NGPIOOUT > 0
pincount = 0;
for (i = 0; i < BOARD_NGPIOOUT; i++)
{
/* Setup and register the GPIO pin */
g_gpout[i].gpio.gp_pintype = GPIO_OUTPUT_PIN;
g_gpout[i].gpio.gp_ops = &gpout_ops;
g_gpout[i].id = i;
gpio_pin_register(&g_gpout[i].gpio, pincount);
/* Configure the pin that will be used as output */
stm32_gpiowrite(g_gpiooutputs[i], 0);
stm32_configgpio(g_gpiooutputs[i]);
pincount++;
}
#endif
#if BOARD_NGPIOINT > 0
pincount = 0;
for (i = 0; i < BOARD_NGPIOINT; i++)
{
/* Setup and register the GPIO pin */
g_gpint[i].stm32gpio.gpio.gp_pintype = GPIO_INTERRUPT_PIN;
g_gpint[i].stm32gpio.gpio.gp_ops = &gpint_ops;
g_gpint[i].stm32gpio.id = i;
gpio_pin_register(&g_gpint[i].stm32gpio.gpio, pincount);
/* Configure the pin that will be used as interrupt input */
stm32_configgpio(g_gpiointinputs[i]);
pincount++;
}
#endif
return 0;
}
#endif /* CONFIG_DEV_GPIO && !CONFIG_GPIO_LOWER_HALF */

View File

@ -0,0 +1,885 @@
/****************************************************************************
* boards/arm/stm32/stm32f4discovery/src/stm32f4discovery.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file stm32f4discovery.h
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-05-19
*/
#ifndef __BOARDS_ARM_STM32_STM32F4DISCOVERY_SRC_STM32F4DISCOVERY_H
#define __BOARDS_ARM_STM32_STM32F4DISCOVERY_SRC_STM32F4DISCOVERY_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
#include <stdint.h>
#include <arch/stm32/chip.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* How many SPI modules does this chip support? */
#if STM32_NSPI < 1
# undef CONFIG_STM32_SPI1
# undef CONFIG_STM32_SPI2
# undef CONFIG_STM32_SPI3
#elif STM32_NSPI < 2
# undef CONFIG_STM32_SPI2
# undef CONFIG_STM32_SPI3
#elif STM32_NSPI < 3
# undef CONFIG_STM32_SPI3
#endif
#define PCA9635_I2CBUS 1
#define PCA9635_I2CADDR 0x40
/* Assume that we have everything */
#define HAVE_USBDEV 1
#define HAVE_USBHOST 1
#define HAVE_USBMONITOR 1
#define HAVE_SDIO 1
#define HAVE_CS43L22 1
#define HAVE_RTC_DRIVER 1
#define HAVE_NETMONITOR 1
#define HAVE_HCIUART 1
/* Can't support USB host or device features if USB OTG FS is not enabled */
#ifndef CONFIG_STM32_OTGFS
# undef HAVE_USBDEV
# undef HAVE_USBHOST
#endif
/* Can't support USB device if USB device is not enabled */
#ifndef CONFIG_USBDEV
# undef HAVE_USBDEV
#endif
/* Can't support USB host is USB host is not enabled */
#ifndef CONFIG_USBHOST
# undef HAVE_USBHOST
#endif
/* Check if we should enable the USB monitor before starting NSH */
#ifndef CONFIG_USBMONITOR
# undef HAVE_USBMONITOR
#endif
#ifndef HAVE_USBDEV
# undef CONFIG_USBDEV_TRACE
#endif
#ifndef HAVE_USBHOST
# undef CONFIG_USBHOST_TRACE
#endif
#if !defined(CONFIG_USBDEV_TRACE) && !defined(CONFIG_USBHOST_TRACE)
# undef HAVE_USBMONITOR
#endif
/* Can't support MMC/SD features if mountpoints are disabled or if SDIO
* support is not enabled.
*/
#if defined(CONFIG_DISABLE_MOUNTPOINT) || !defined(CONFIG_STM32_SDIO)
# undef HAVE_SDIO
#endif
#undef SDIO_MINOR /* Any minor number, default 0 */
#define SDIO_SLOTNO 0 /* Only one slot */
#ifdef HAVE_SDIO
# if !defined(CONFIG_NSH_MMCSDSLOTNO)
# define CONFIG_NSH_MMCSDSLOTNO SDIO_SLOTNO
# elif CONFIG_NSH_MMCSDSLOTNO != 0
# warning "Only one MMC/SD slot, slot 0"
# undef CONFIG_NSH_MMCSDSLOTNO
# define CONFIG_NSH_MMCSDSLOTNO SDIO_SLOTNO
# endif
# if defined(CONFIG_NSH_MMCSDMINOR)
# define SDIO_MINOR CONFIG_NSH_MMCSDMINOR
# else
# define SDIO_MINOR 0
# endif
#endif
/* The CS43L22 depends on the CS43L22 driver, I2C1, and I2S3 support */
#if !defined(CONFIG_AUDIO_CS43L22) || !defined(CONFIG_STM32_I2C1) || \
!defined(CONFIG_STM32_I2S3)
# undef HAVE_CS43L22
#endif
#ifdef HAVE_CS43L22
/* The CS43L22 communicates on I2C1, I2C address 0x1a for control
* operations
*/
# define CS43L22_I2C_BUS 1
# define CS43L22_I2C_ADDRESS (0x94 >> 1)
/* The CS43L22 transfers data on I2S3 */
# define CS43L22_I2S_BUS 3
#endif
/* Check if we can support the RTC driver */
#if !defined(CONFIG_RTC) || !defined(CONFIG_RTC_DRIVER)
# undef HAVE_RTC_DRIVER
#endif
/* NSH Network monitor */
#if !defined(CONFIG_NET) || !defined(CONFIG_STM32_EMACMAC)
# undef HAVE_NETMONITOR
#endif
#if !defined(CONFIG_NSH_NETINIT_THREAD) || !defined(CONFIG_ARCH_PHY_INTERRUPT) || \
!defined(CONFIG_NETDEV_PHY_IOCTL) || !defined(CONFIG_NET_UDP)
# undef HAVE_NETMONITOR
#endif
/* The NSH Network Monitor cannot be used with the STM32F4DIS-BB base board.
* That is because the LAN8720 is configured in REF_CLK OUT mode. In that
* mode, the PHY interrupt is not supported. The NINT pin serves instead as
* REFLCK0.
*/
#ifdef CONFIG_STM32F4DISBB
# undef HAVE_NETMONITOR
#endif
/* procfs File System */
#ifdef CONFIG_FS_PROCFS
# ifdef CONFIG_NSH_PROC_MOUNTPOINT
# define STM32_PROCFS_MOUNTPOINT CONFIG_NSH_PROC_MOUNTPOINT
# else
# define STM32_PROCFS_MOUNTPOINT "/proc"
# endif
#endif
/* Check if we have the prerequisites for an HCI UART */
#if !defined(CONFIG_STM32_HCIUART) || !defined(CONFIG_BLUETOOTH_UART)
# undef HAVE_HCIUART
#elif defined(CONFIG_STM32_USART1_HCIUART)
# define HCIUART_SERDEV HCIUART1
#elif defined(CONFIG_STM32_USART2_HCIUART)
# define HCIUART_SERDEV HCIUART2
#elif defined(CONFIG_STM32_USART3_HCIUART)
# define HCIUART_SERDEV HCIUART3
#elif defined(CONFIG_STM32_USART6_HCIUART)
# define HCIUART_SERDEV HCIUART6
#elif defined(CONFIG_STM32_UART7_HCIUART)
# define HCIUART_SERDEV HCIUART7
#elif defined(CONFIG_STM32_UART8_HCIUART)
# define HCIUART_SERDEV HCIUART8
#else
# error No HCI UART specifified
#endif
/* STM32F4 Discovery GPIOs **************************************************/
/* LEDs */
#define GPIO_LED1 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTD|GPIO_PIN12)
#define GPIO_LED2 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTD|GPIO_PIN13)
#define GPIO_LED3 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTD|GPIO_PIN14)
#define GPIO_LED4 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTD|GPIO_PIN15)
/* BUTTONS -- NOTE that all have EXTI interrupts configured */
#define MIN_IRQBUTTON BUTTON_USER
#define MAX_IRQBUTTON BUTTON_USER
#define NUM_IRQBUTTONS 1
#define GPIO_BTN_USER (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTA|GPIO_PIN0)
#define GPIO_CS43L22_RESET (GPIO_OUTPUT|GPIO_SPEED_50MHz|GPIO_PORTD|GPIO_PIN4)
/* LoRa SX127x */
#define GPIO_SX127X_DIO0 (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTD|GPIO_PIN0)
#define GPIO_SX127X_RESET (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_OUTPUT_CLEAR|\
GPIO_SPEED_50MHz|GPIO_PORTD|GPIO_PIN4)
/* PWM
*
* The STM32F4 Discovery has no real on-board PWM devices, but the board can
* be configured to output a pulse train using TIM4 CH2 on PD13.
*/
#define STM32F4DISCOVERY_PWMTIMER 4
#define STM32F4DISCOVERY_PWMCHANNEL 2
/* SPI chip selects */
#define GPIO_CS_MEMS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN3)
#define GPIO_MAX31855_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTD|GPIO_PIN8)
#define GPIO_MAX6675_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTD|GPIO_PIN8)
#define GPIO_SX127X_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTD|GPIO_PIN8)
#define GPIO_MAX7219_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTC|GPIO_PIN3)
#define GPIO_GS2200M_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN5)
#define GPIO_ENC28J60_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTA|GPIO_PIN4)
#define GPIO_ENC28J60_RESET (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTE|GPIO_PIN1)
#define GPIO_ENC28J60_INTR (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|\
GPIO_OPENDRAIN|GPIO_PORTE|GPIO_PIN4)
/* USB OTG FS
*
* PA9 OTG_FS_VBUS VBUS sensing (also connected to the green LED)
* PC0 OTG_FS_PowerSwitchOn
* PD5 OTG_FS_Overcurrent
*/
#define GPIO_OTGFS_VBUS (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\
GPIO_OPENDRAIN|GPIO_PORTA|GPIO_PIN9)
#define GPIO_OTGFS_PWRON (GPIO_OUTPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\
GPIO_PUSHPULL|GPIO_PORTC|GPIO_PIN0)
#ifdef CONFIG_USBHOST
# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_EXTI|GPIO_FLOAT|\
GPIO_SPEED_100MHz|GPIO_PUSHPULL|\
GPIO_PORTD|GPIO_PIN5)
#else
# define GPIO_OTGFS_OVER (GPIO_INPUT|GPIO_FLOAT|GPIO_SPEED_100MHz|\
GPIO_PUSHPULL|GPIO_PORTD|GPIO_PIN5)
#endif
#define BOARD_NGPIOIN 0 /* Amount of GPIO Input pins */
#define BOARD_NGPIOOUT 2 /* Amount of GPIO Output pins */
#define BOARD_NGPIOINT 0 /* Amount of GPIO Input w/ Interruption pins */
#define GPIO_E22_M0 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTC|GPIO_PIN6)
#define GPIO_E22_M1 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTC|GPIO_PIN7)
/* UG-2864AMBAG01 or UG-2864HSWEG01 OLED Display (SPI 4-wire):
*
* --------------------------+----------------------------------------------
* Connector CON10 J1: | STM32F4Discovery
* --------------+-----------+----------------------------------------------
* CON10 J1: | CON20 J2: | P1/P2:
* --------------+-----------+----------------------------------------------
* 1 3v3 | 3,4 3v3 | P2 3V
* 3 /RESET | 8 /RESET | P2 PB6 (Arbitrary selection)
* 5 /CS | 7 /CS | P2 PB7 (Arbitrary selection)
* 7 A0|D/C | 9 A0|D/C | P2 PB8 (Arbitrary selection)
* 9 LED+ (N/C) | ----- | -----
* 2 5V Vcc | 1,2 Vcc | P2 5V
* 4 DI | 18 D1/SI | P1 PA7 (GPIO_SPI1_MOSI == GPIO_SPI1_MOSI_1(1))
* 6 SCLK | 19 D0/SCL | P1 PA5 (GPIO_SPI1_SCK == GPIO_SPI1_SCK_1(1))
* 8 LED- (N/C) | ----- | ------
* 10 GND | 20 GND | P2 GND
* --------------+-----------+----------------------------------------------
* (1) Required because of on-board MEMS
* -------------------------------------------------------------------------
*/
#if defined(CONFIG_LCD_UG2864AMBAG01) || defined(CONFIG_LCD_UG2864HSWEG01) || \
defined(CONFIG_LCD_SSD1351)
# define GPIO_OLED_RESET (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTB|GPIO_PIN6)
# define GPIO_OLED_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN7)
# define GPIO_OLED_A0 (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_CLEAR|GPIO_PORTB|GPIO_PIN8)
# define GPIO_OLED_DC GPIO_OLED_A0
#endif
/* Display JLX12864G */
#define STM32_LCD_RST (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN6)
#define STM32_LCD_CS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN7)
#define STM32_LCD_RS (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTB|GPIO_PIN8)
/* STM32F4DIS-BB MicroSD
*
* ---------- ------------- ------------------------------
* PIO SIGNAL Comments
* ---------- ------------- ------------------------------
* PB15 NCD Pulled up externally
* PC9 DAT1 Configured by driver
* PC8 DAT0 " " "" " "
* PC12 CLK " " "" " "
* PD2 CMD " " "" " "
* PC11 CD/DAT3 " " "" " "
* PC10 DAT2 " " "" " "
* ---------- ------------- ------------------------------
*/
#if defined(CONFIG_STM32F4DISBB) && defined(CONFIG_STM32_SDIO)
# define GPIO_SDIO_NCD (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|\
GPIO_PORTB|GPIO_PIN15)
#endif
/* STM32F4DIS-BB LAN8720
*
* ---------- ------------- ------------------------------
* PIO SIGNAL Comments
* ---------- ------------- ------------------------------
* PB11 TXEN Configured by driver
* PB12 TXD0 " " "" " "
* PB13 TXD1 " " "" " "
* PC4 RXD0/MODE0 " " "" " "
* PC5 RXD1/MODE1 " " "" " "
* PA7 CRS_DIV/MODE2 " " "" " "
* PA2 MDIO " " "" " "
* PC1 MDC " " "" " "
* PA1 NINT/REFCLK0 " " "" " "
* PE2 DAT2 " " "" " "
* ---------- ------------- ------------------------------
*/
#if defined(CONFIG_STM32F4DISBB) && defined(CONFIG_STM32_ETHMAC)
# define GPIO_EMAC_NINT (GPIO_INPUT|GPIO_PULLUP|GPIO_EXTI|\
GPIO_PORTA|GPIO_PIN1)
# define GPIO_EMAC_NRST (GPIO_OUTPUT|GPIO_PUSHPULL|GPIO_SPEED_50MHz|\
GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN2)
#endif
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#ifndef __ASSEMBLY__
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: stm32_bringup
*
* Description:
* Perform architecture-specific initialization
*
* CONFIG_BOARD_LATE_INITIALIZE=y :
* Called from board_late_initialize().
*
* CONFIG_BOARD_LATE_INITIALIZE=y && CONFIG_BOARDCTL=y :
* Called from the NSH library
*
****************************************************************************/
int stm32_bringup(void);
/****************************************************************************
* Name: stm32_spidev_initialize
*
* Description:
* Called to configure SPI chip select GPIO pins for the stm32f4discovery
* board.
*
****************************************************************************/
void weak_function stm32_spidev_initialize(void);
/****************************************************************************
* Name: stm32_i2sdev_initialize
*
* Description:
* Called to configure I2S chip select GPIO pins for the stm32f4discovery
* board.
*
****************************************************************************/
void weak_function stm32_i2sdev_initialize(void);
/****************************************************************************
* Name: stm32_bh1750initialize
*
* Description:
* Called to configure an I2C and to register BH1750FVI for the
* stm32f4discovery board.
*
****************************************************************************/
#ifdef CONFIG_SENSORS_BH1750FVI
int stm32_bh1750initialize(FAR const char *devpath);
#endif
/****************************************************************************
* Name: stm32_lpwaninitialize
*
* Description:
* Initialize SX127X LPWAN interaface.
****************************************************************************/
#ifdef CONFIG_LPWAN_SX127X
int stm32_lpwaninitialize(void);
#endif
/****************************************************************************
* Name: stm32_mmcsdinitialize
*
* Description:
* Sets up MMC/SD interface.
*
****************************************************************************/
#ifdef CONFIG_MMCSD_SPI
int stm32_mmcsd_initialize(int port, int minor);
#endif
/****************************************************************************
* Name: nunchuck_initialize
*
* Description:
* Initialize and register the button joystick driver
*
****************************************************************************/
#ifdef CONFIG_INPUT_NUNCHUCK
int nunchuck_initialize(FAR char *devname);
#endif
/****************************************************************************
* Name: stm32_max7219init
*
* Description:
* Initialize and register the max7219 numeric display controller
*
****************************************************************************/
#ifdef CONFIG_LEDS_MAX7219
int stm32_max7219init(FAR const char *devpath);
#endif
/****************************************************************************
* Name: stm32_ds1307_init
*
* Description:
* Initialize and register the DS1307 RTC
*
****************************************************************************/
#ifdef CONFIG_RTC_DS1307
int stm32_ds1307_init(void);
#endif
/****************************************************************************
* Name: stm32_st7032init
*
* Description:
* Initialize and register the Sitronix ST7032i
*
****************************************************************************/
int stm32_st7032init(FAR const char *devpath);
/****************************************************************************
* Name: stm32_usbinitialize
*
* Description:
* Called from stm32_usbinitialize very early in initialization to setup
* USB-related GPIO pins for the STM32F4Discovery board.
*
****************************************************************************/
#ifdef CONFIG_STM32_OTGFS
void weak_function stm32_usbinitialize(void);
#endif
/****************************************************************************
* Name: stm32_usbhost_initialize
*
* Description:
* Called at application startup time to initialize the USB host
* functionality. This function will start a thread that will monitor for
* device connection/disconnection events.
*
****************************************************************************/
#if defined(CONFIG_STM32_OTGFS) && defined(CONFIG_USBHOST)
int stm32_usbhost_initialize(void);
#endif
/****************************************************************************
* Name: stm32_pwm_setup
*
* Description:
* Initialize PWM and register the PWM device.
*
****************************************************************************/
#ifdef CONFIG_PWM
int stm32_pwm_setup(void);
#endif
/****************************************************************************
* Name: stm32_can_setup
*
* Description:
* Initialize CAN and register the CAN device
*
****************************************************************************/
#ifdef CONFIG_STM32_CAN_CHARDRIVER
int stm32_can_setup(void);
#endif
/****************************************************************************
* Name: stm32_extmemgpios
*
* Description:
* Initialize GPIOs for external memory usage
*
****************************************************************************/
#ifdef CONFIG_STM32_FSMC
void stm32_extmemgpios(const uint32_t *gpios, int ngpios);
#endif
/****************************************************************************
* Name: stm32_extmemaddr
*
* Description:
* Initialize address line GPIOs for external memory access
*
****************************************************************************/
#ifdef CONFIG_STM32_FSMC
void stm32_extmemaddr(int naddrs);
#endif
/****************************************************************************
* Name: stm32_extmemdata
*
* Description:
* Initialize data line GPIOs for external memory access
*
****************************************************************************/
#ifdef CONFIG_STM32_FSMC
void stm32_extmemdata(int ndata);
#endif
/****************************************************************************
* Name: stm32_led_pminitialize
*
* Description:
* Enable logic to use the LEDs on the STM32F4Discovery to support power
* management testing
*
****************************************************************************/
#ifdef CONFIG_PM
void stm32_led_pminitialize(void);
#endif
/****************************************************************************
* Name: stm32_pm_buttons
*
* Description:
* Configure the user button of the STM32f4discovery board as EXTI,
* so it is able to wakeup the MCU from the PM_STANDBY mode
*
****************************************************************************/
#if defined(CONFIG_PM) && defined(CONFIG_ARCH_IDLE_CUSTOM) && \
defined(CONFIG_PM_BUTTONS)
void stm32_pm_buttons(void);
#endif
/****************************************************************************
* Name: stm32_sdio_initialize
*
* Description:
* Initialize SDIO-based MMC/SD card support
*
****************************************************************************/
#if !defined(CONFIG_DISABLE_MOUNTPOINT) && defined(CONFIG_STM32_SDIO)
int stm32_sdio_initialize(void);
#endif
/****************************************************************************
* Name: stm32_netinitialize
*
* Description:
* Configure board resources to support networking.
*
****************************************************************************/
#ifdef HAVE_NETMONITOR
void weak_function stm32_netinitialize(void);
#endif
/****************************************************************************
* Name: stm32_zerocross_initialize
*
* Description:
* Initialize and register the zero cross driver
*
****************************************************************************/
#ifdef CONFIG_SENSORS_ZEROCROSS
int stm32_zerocross_initialize(void);
#endif
/****************************************************************************
* Name: stm32_max31855initialize
*
* Description:
* Initialize and register the MAX31855 Temperature Sensor driver.
*
* Input Parameters:
* devpath - The full path to the driver to register. E.g., "/dev/temp0"
* bus - Bus number (for hardware that has multiple SPI interfaces)
* devid - ID associated to the device. E.g., 0, 1, 2, etc.
*
* Returned Value:
* Zero (OK) on success; a negated errno value on failure.
*
****************************************************************************/
#ifdef CONFIG_SENSORS_MAX31855
int stm32_max31855initialize(FAR const char *devpath, int bus,
uint16_t devid);
#endif
/****************************************************************************
* Name: stm32_mlx90614init
*
* Description:
* Called to configure an I2C and to register MLX90614 for the
* stm32f103-minimum board.
*
****************************************************************************/
#ifdef CONFIG_SENSORS_MLX90614
int stm32_mlx90614init(FAR const char *devpath);
#endif
/****************************************************************************
* Name: stm32_max6675initialize
*
* Description:
* Initialize and register the max6675 driver
*
****************************************************************************/
#ifdef CONFIG_SENSORS_MAX6675
int stm32_max6675initialize(FAR const char *devpath);
#endif
/****************************************************************************
* Name: stm32_cs43l22_initialize
*
* Description:
* This function is called by platform-specific, setup logic to configure
* and register the CS43L22 device. This function will register the
* driver as /dev/cs43l22[x] where x is determined by the minor device
* number.
*
* Input Parameters:
* minor - The input device minor number
*
* Returned Value:
* Zero is returned on success. Otherwise, a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
#ifdef HAVE_CS43L22
int stm32_cs43l22_initialize(int minor);
#endif /* HAVE_CS43L22 */
/****************************************************************************
* Name: stm32_pca9635_initialize
*
* Description:
* This function is called by board initialization logic to configure the
* LED PWM chip. This function will register the driver as /dev/leddrv0.
*
* Input Parameters:
* None
*
* Returned Value:
* Zero is returned on success. Otherwise, a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
#ifdef CONFIG_PCA9635PW
int stm32_pca9635_initialize(void);
#endif
/****************************************************************************
* Name: stm32_rgbled_setup
*
* Description:
* This function is called by board initialization logic to configure the
* RGB LED driver. This function will register the driver as /dev/rgbled0.
*
* Input Parameters:
* None
*
* Returned Value:
* Zero is returned on success. Otherwise, a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
#ifdef CONFIG_RGBLED
int stm32_rgbled_setup(void);
#endif
/****************************************************************************
* Name: stm32_timer_driver_setup
*
* Description:
* Configure the timer driver.
*
* Input Parameters:
* devpath - The full path to the timer device. This should be of the
* form /dev/timer0
* timer - The timer's number.
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
#ifdef CONFIG_TIMER
int stm32_timer_driver_setup(FAR const char *devpath, int timer);
#endif
/****************************************************************************
* Name: xen1210_archinitialize
*
* Description:
* Each board that supports an xen1210 device must provide this function.
* This function is called by application-specific, setup logic to
* configure the accelerometer device. This function will register the
* driver as /dev/accelN where N is the minor device number.
*
* Input Parameters:
* minor - The input device minor number
*
* Returned Value:
* Zero is returned on success. Otherwise, a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
#ifdef CONFIG_SENSORS_XEN1210
int xen1210_archinitialize(int minor);
#endif
/****************************************************************************
* Name: hciuart_dev_initialize
*
* Description:
* This function is called by board initialization logic to configure the
* Bluetooth HCI UART driver
*
* Input Parameters:
* None
*
* Returned Value:
* Zero is returned on success. Otherwise, a negated errno value is
* returned to indicate the nature of the failure.
*
****************************************************************************/
#ifdef HAVE_HCIUART
int hciuart_dev_initialize(void);
#endif
/****************************************************************************
* Name: stm32_gs2200m_initialize
*
* Description:
* Configure the gs2200m driver.
*
* Input Parameters:
* devpath - The full path to the device.
* bus - The SPI bus number
*
* Returned Value:
* Zero (OK) is returned on success; A negated errno value is returned
* to indicate the nature of any failure.
*
****************************************************************************/
#ifdef CONFIG_WL_GS2200M
int stm32_gs2200m_initialize(FAR const char *devpath, int bus);
#endif
#ifdef CONFIG_DEV_GPIO
int stm32_gpio_initialize(void);
#endif
#endif /* __ASSEMBLY__ */
#endif /* __BOARDS_ARM_STM32_STM32F4DISCOVERY_SRC_STM32F4DISCOVERY_H */

View File

@ -0,0 +1,614 @@
/****************************************************************************
* include/nuttx/lib/math.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_LIB_MATH_H
#define __INCLUDE_NUTTX_LIB_MATH_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/* If CONFIG_ARCH_MATH_H is defined, then the top-level Makefile will copy
* this header file to include/math.h where it will become the system math.h
* header file. In this case, the architecture specific code must provide
* an arch/<architecture>/include/math.h file which will be included below:
*/
#ifdef CONFIG_ARCH_MATH_H
# include <arch/math.h>
/* If CONFIG_LIBM is enabled, then the math library at lib/math will be
* built. This library was taken from the math library developed for the
* Rhombus OS by Nick Johnson (https://github.com/nickbjohnson4224/rhombus).
* The port or the Rhombus math library was contributed by Darcy Gong.
*/
#elif defined(CONFIG_LIBM)
/****************************************************************************
* Copyright (C) 2009-2011 Nick Johnson <nickbjohnson4224 at gmail.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/compiler.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* General Constants ********************************************************/
#define INFINITY (1.0/0.0)
#define NAN (0.0/0.0)
#define HUGE_VAL INFINITY
#define INFINITY_F (1.0F/0.0F)
#define NAN_F (0.0F/0.0F)
#define isnan(x) ((x) != (x))
#define isinf(x) (((x) == INFINITY) || ((x) == -INFINITY))
#define isfinite(x) (!(isinf(x) || isnan(x)))
#define isinf_f(x) (((x) == INFINITY_F) || ((x) == -INFINITY_F))
/* Exponential and Logarithmic constants ************************************/
#define M_E 2.7182818284590452353602874713526625
#define M_SQRT2 1.4142135623730950488016887242096981
#define M_SQRT1_2 0.7071067811865475244008443621048490
#define M_LOG2E 1.4426950408889634073599246810018921
#define M_LOG10E 0.4342944819032518276511289189166051
#define M_LN2 0.6931471805599453094172321214581765
#define M_LN10 2.3025850929940456840179914546843642
/* Trigonometric Constants **************************************************/
#define M_PI 3.1415926535897932384626433832795029
#define M_PI_2 1.5707963267948966192313216916397514
#define M_PI_4 0.7853981633974483096156608458198757
#define M_1_PI 0.3183098861837906715377675267450287
#define M_2_PI 0.6366197723675813430755350534900574
#define M_2_SQRTPI 1.1283791670955125738961589031215452
#define M_PI_F ((float)M_PI)
#define M_PI_2_F ((float)M_PI_2)
/****************************************************************************
* Type Declarations
****************************************************************************/
/* Floating point types */
typedef float float_t;
#ifndef CONFIG_HAVE_DOUBLE
typedef float double_t;
#else
typedef double double_t;
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#if defined(__cplusplus)
extern "C"
{
#endif
/* General Functions ********************************************************/
float ceilf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double ceil (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double ceill (long double x);
#endif
float floorf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double floor (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double floorl(long double x);
#endif
float roundf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double round (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double roundl(long double x);
#endif
long int lroundf(float x);
#ifdef CONFIG_HAVE_DOUBLE
long int lround(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long int lroundl(long double x);
#endif
#ifdef CONFIG_HAVE_LONG_LONG
long long int llroundf(float x);
#ifdef CONFIG_HAVE_DOUBLE
long long int llround (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long long int llroundl(long double x);
#endif
#endif
float rintf(float x); /* Not implemented */
#ifdef CONFIG_HAVE_DOUBLE
double rint(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double rintl(long double x); /* Not implemented */
#endif
long int lrintf(float x);
#ifdef CONFIG_HAVE_DOUBLE
long int lrint(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long int lrintl(long double x);
#endif
#ifdef CONFIG_HAVE_LONG_LONG
long long int llrintf(float x);
#ifdef CONFIG_HAVE_DOUBLE
long long int llrint(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long long int llrintl(long double x);
#endif
#endif
float fabsf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double fabs (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fabsl (long double x);
#endif
float modff (float x, float *iptr);
#ifdef CONFIG_HAVE_DOUBLE
double modf (double x, double *iptr);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double modfl (long double x, long double *iptr);
#endif
float fmodf (float x, float div);
#ifdef CONFIG_HAVE_DOUBLE
double fmod (double x, double div);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fmodl (long double x, long double div);
#endif
/* Exponential and Logarithmic Functions ************************************/
float powf (float b, float e);
#ifdef CONFIG_HAVE_DOUBLE
double pow (double b, double e);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double powl (long double b, long double e);
#endif
float expf (float x);
float exp2f (float x);
float expm1f(float x);
#ifdef CONFIG_HAVE_DOUBLE
double exp (double x);
double exp2 (double x);
double expm1 (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double expl (long double x);
long double exp2l (long double x);
long double expm1l(long double x);
#endif
float fdimf(float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double fdim(double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fdiml(long double x, long double y);
#endif
float fmaf(float x, float y, float z);
#ifdef CONFIG_HAVE_DOUBLE
double fma(double x, double y, double z);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fmal(long double x, long double y, long double z);
#endif
float fmaxf(float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double fmax(double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fmaxl(long double x, long double y);
#endif
float fminf(float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double fmin(double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double fminl(long double x, long double y);
#endif
float hypotf(float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double hypot(double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double hypotl(long double x, long double y);
#endif
float lgammaf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double __cos(double x, double y);
double __sin(double x, double y, int iy);
double gamma(double x);
double lgamma(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double lgammal(long double x);
#endif
float tgammaf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double tgamma(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double tgammal(long double x);
#endif
float logf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double log (double x);
#ifdef CONFIG_MUSL_LIBC
double log1p(double x);
#endif
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double logl (long double x);
#endif
float log10f(float x);
#ifdef CONFIG_HAVE_DOUBLE
double log10 (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double log10l(long double x);
#endif
float log1pf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double log1p (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double log1pl(long double x);
#endif
float log2f (float x);
#ifdef CONFIG_HAVE_DOUBLE
double log2 (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double log2l (long double x);
#endif
float logbf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double logb (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double logbl (long double x);
#endif
int ilogbf (float x);
#ifdef CONFIG_HAVE_DOUBLE
int ilogb (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
int ilogbl (long double x);
#endif
float sqrtf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double sqrt (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double sqrtl (long double x);
#endif
float ldexpf(float x, int n);
#ifdef CONFIG_HAVE_DOUBLE
double ldexp (double x, int n);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double ldexpl(long double x, int n);
#endif
float frexpf(float x, int *exp);
#ifdef CONFIG_HAVE_DOUBLE
double frexp (double x, int *exp);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double frexpl(long double x, int *exp);
#endif
/* Trigonometric Functions **************************************************/
float sinf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double sin (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double sinl (long double x);
#endif
float cosf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double cos (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double cosl (long double x);
#endif
float tanf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double tan (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double tanl (long double x);
#endif
float asinf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double asin (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double asinl (long double x);
#endif
float acosf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double acos (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double acosl (long double x);
#endif
float atanf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double atan (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double atanl (long double x);
#endif
float atan2f(float y, float x);
#ifdef CONFIG_HAVE_DOUBLE
double atan2 (double y, double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double atan2l(long double y, long double x);
#endif
float sinhf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double sinh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double sinhl (long double x);
#endif
float coshf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double cosh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double coshl (long double x);
#endif
float cbrtf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double cbrt (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double cbrtl (long double x);
#endif
float tanhf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double tanh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double tanhl (long double x);
#endif
float asinhf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double asinh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double asinhl (long double x);
#endif
float acoshf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double acosh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double acoshl (long double x);
#endif
float atanhf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double atanh (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double atanhl (long double x);
#endif
float erff (float x);
float erfcf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double erf (double x);
double erfc(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double erfl (long double x);
long double erfcl(long double x);
#endif
float copysignf (float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double copysign (double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double copysignl (long double x, long double y);
#endif
float truncf (float x);
#ifdef CONFIG_HAVE_DOUBLE
double trunc (double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double truncl (long double x);
#endif
float nanf(const char *tagp);
#ifdef CONFIG_HAVE_DOUBLE
double nan(const char *tagp);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double nanl(const char *tagp);
#endif
float nearbyintf(float x);
#ifdef CONFIG_HAVE_DOUBLE
double nearbyint(double x);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double nearbyintl(long double x);
#endif
float nextafterf(float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double nextafter(double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double nextafterl(long double x, long double y);
#endif
float nexttowardf(float x, long double y);
#ifdef CONFIG_HAVE_DOUBLE
double nexttoward(double x, long double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double nexttowardl(long double x, long double y);
#endif
float remainderf(float x, float y);
#ifdef CONFIG_HAVE_DOUBLE
double remainder(double x, double y);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double remainderl(long double x, long double y);
#endif
float remquof(float x, float y, int *quo);
#ifdef CONFIG_HAVE_DOUBLE
double remquo(double x, double y, int *quo);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double remquol(long double x, long double y, int *quo);
#endif
float scalblnf(float x, long int n);
#ifdef CONFIG_HAVE_DOUBLE
double scalbln(double x, long int n);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double scalblnl(long double x, long int n);
#endif
float scalbnf(float x, int n);
#ifdef CONFIG_HAVE_DOUBLE
double scalbn(double x, int n);
#endif
#ifdef CONFIG_HAVE_LONG_DOUBLE
long double scalbnl(long double x, int n);
#endif
#define FP_INFINITE 0
#define FP_NAN 1
#define FP_NORMAL 2
#define FP_SUBNORMAL 3
#define FP_ZERO 4
#define fpclassify(x) \
__builtin_fpclassify(FP_NAN, FP_INFINITE, FP_NORMAL, FP_SUBNORMAL, \
FP_ZERO, x)
#define isunordered(x, y) __builtin_isunordered(x, y)
#define isgreater(x, y) __builtin_isgreater(x, y)
#define isgreaterequal(x, y) __builtin_isgreaterequal(x, y)
#define isless(x, y) __builtin_isless(x, y)
#define islessequal(x, y) __builtin_islessequal(x, y)
#define islessgreater(x, y) __builtin_islessgreater(x, y)
#define isnormal(x) __builtin_isnormal(x)
#define signbit(x) __builtin_signbit(x)
#if defined(__cplusplus)
}
#endif
#endif /* CONFIG_LIBM */
#endif /* __INCLUDE_NUTTX_LIB_MATH_H */

View File

@ -0,0 +1,2 @@
/exec_symtab.c
/modlib_symtab.c

View File

@ -0,0 +1,202 @@
############################################################################
# libs/libc-musl/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
###########################################################################
include $(TOPDIR)/Make.defs
include aio/Make.defs
include assert/Make.defs
include audio/Make.defs
include builtin/Make.defs
include ctype/Make.defs
include dirent/Make.defs
include dlfcn/Make.defs
include endian/Make.defs
include errno/Make.defs
include eventfd/Make.defs
include fixedmath/Make.defs
include grp/Make.defs
include hex2bin/Make.defs
include inttypes/Make.defs
include libgen/Make.defs
include locale/Make.defs
include lzf/Make.defs
include machine/Make.defs
include math/Make.defs
include misc/Make.defs
include modlib/Make.defs
include net/Make.defs
include netdb/Make.defs
include pthread/Make.defs
include pwd/Make.defs
include queue/Make.defs
include sched/Make.defs
include semaphore/Make.defs
include signal/Make.defs
include spawn/Make.defs
include stdio/Make.defs
include stdlib/Make.defs
include stream/Make.defs
include string/Make.defs
include symtab/Make.defs
include syslog/Make.defs
include termios/Make.defs
include time/Make.defs
include tls/Make.defs
include uio/Make.defs
include unistd/Make.defs
include userfs/Make.defs
include uuid/Make.defs
include wchar/Make.defs
include wctype/Make.defs
include wqueue/Make.defs
CFLAGS += ${shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)libs$(DELIM)libc-musl}
# Rule for the symbol table generation
MKSYMTAB = $(TOPDIR)$(DELIM)tools$(DELIM)mksymtab$(HOSTEXEEXT)
$(MKSYMTAB):
$(Q) $(MAKE) -C $(TOPDIR)$(DELIM)tools -f Makefile.host mksymtab
# C library and math library symbols should be available in the FLAT
# and PROTECTED builds. KERNEL builds are separately linked and so should
# not need symbol tables.
CSVFILES = $(TOPDIR)$(DELIM)libs$(DELIM)libc-musl$(DELIM)libc-musl.csv
CSVFILES += $(TOPDIR)$(DELIM)libs$(DELIM)libc-musl$(DELIM)math.csv
# In the PROTECTED and KERNEL builds, the applications could link with
# libproxy which will provide symbol-compatible access to OS functions
# via a call gate, but the applications which link with these functions
# directly could remove the repeat proxy code to save the space.
CSVFILES += $(TOPDIR)$(DELIM)syscall$(DELIM)syscall.csv
ifeq ($(CONFIG_EXECFUNCS_SYSTEM_SYMTAB),y)
exec_symtab.c : $(CSVFILES) $(MKSYMTAB)
$(Q) cat $(CSVFILES) | LC_ALL=C sort >$@.csv
$(Q) $(MKSYMTAB) $@.csv $@ $(CONFIG_EXECFUNCS_SYMTAB_ARRAY) $(CONFIG_EXECFUNCS_NSYMBOLS_VAR)
$(Q) rm -f $@.csv
CSRCS += exec_symtab.c
endif
ifeq ($(CONFIG_MODLIB_SYSTEM_SYMTAB),y)
modlib_sys_symtab.c : $(CSVFILES) $(MKSYMTAB)
$(Q) cat $(CSVFILES) | LC_ALL=C sort >$@.csv
$(Q) $(MKSYMTAB) $@.csv $@ $(CONFIG_MODLIB_SYMTAB_ARRAY) $(CONFIG_MODLIB_NSYMBOLS_VAR)
$(Q) rm -f $@.csv
CSRCS += modlib_sys_symtab.c
endif
BINDIR ?= bin
AOBJS = $(patsubst %.S, $(BINDIR)$(DELIM)%$(OBJEXT), $(ASRCS))
COBJS = $(patsubst %.c, $(BINDIR)$(DELIM)%$(OBJEXT), $(CSRCS))
SRCS = $(ASRCS) $(CSRCS)
OBJS = $(AOBJS) $(COBJS)
KBIN = libkc$(LIBEXT)
BIN ?= libc-musl$(LIBEXT)
all: $(BIN)
.PHONY: clean distclean
$(AOBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)
$(COBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.c
$(call COMPILE, $<, $@)
# C library for the flat build and
# the user phase of the two-pass kernel build
$(BIN): $(OBJS)
$(call ARCHIVE, $@, $(OBJS))
ifeq ($(CONFIG_LIBC_ZONEINFO_ROMFS),y)
$(Q) $(MAKE) -C zoneinfo all BIN=$(BIN)
endif
# C library for the kernel phase of the two-pass kernel build
ifneq ($(BIN),$(KBIN))
$(KBIN):
$(Q) $(MAKE) $(KBIN) BIN=$(KBIN) BINDIR=kbin EXTRAFLAGS="$(EXTRAFLAGS)"
endif
# Context
context::
ifeq ($(CONFIG_LIBC_ZONEINFO_ROMFS),y)
$(Q) $(MAKE) -C zoneinfo context BIN=$(BIN)
endif
# Dependencies
makedepfile: $(CSRCS:.c=.ddc) $(ASRCS:.S=.dds)
$(call CATFILE, bin/Make.dep, $^)
$(call DELFILE, $^)
makekdepfile: $(CSRCS:.c=.ddc) $(ASRCS:.S=.dds)
$(call CATFILE, kbin/Make.dep, $^)
$(call DELFILE, $^)
.depend: Makefile $(SRCS) $(TOPDIR)$(DELIM).config
$(Q) $(MAKE) makedepfile OBJPATH="bin"
ifneq ($(CONFIG_BUILD_FLAT),y)
$(Q) $(MAKE) makekdepfile CFLAGS="$(CFLAGS) $(KDEFINE)" OBJPATH="kbin"
endif
ifeq ($(CONFIG_LIBC_ZONEINFO_ROMFS),y)
$(Q) $(MAKE) -C zoneinfo depend BIN=$(BIN)
endif
$(Q) touch $@
depend:: .depend
# Clean most derived files, retaining the configuration
clean::
$(Q) $(MAKE) -C bin clean
$(Q) $(MAKE) -C kbin clean
$(Q) $(MAKE) -C zoneinfo clean BIN=$(BIN)
$(call DELFILE, $(BIN))
$(call DELFILE, $(KBIN))
$(call CLEAN)
# Deep clean -- removes all traces of the configuration
distclean:: clean
$(Q) $(MAKE) -C bin distclean
$(Q) $(MAKE) -C kbin distclean
$(Q) $(MAKE) -C zoneinfo distclean BIN=$(BIN)
$(call DELFILE, exec_symtab.c)
$(call DELFILE, bin/Make.dep)
$(call DELFILE, kbin/Make.dep)
$(call DELFILE, .depend)
-include bin/Make.dep
-include kbin/Make.dep

View File

@ -0,0 +1,143 @@
lib
===
This directory contains numerous, small functions typically associated with
what you would expect to find in a standard C library. The sub-directories
in this directory contain standard interface that can be executed by user-
mode programs.
Normally, NuttX is built with no protection and all threads running in kerne-
mode. In that model, there is no real architectural distinction between
what is a kernel-mode program and what is a user-mode program; the system is
more like on multi-threaded program that all runs in kernel-mode.
But if the CONFIG_BUILD_PROTECTED option is selected, NuttX will be built
into distinct user-mode and kernel-mode sections. In that case, most of the
code in the nuttx/ directory will run in kernel-mode with exceptions
of (1) the user-mode "proxies" found in syscall/proxies, and (2) the
standard C library functions found in this directory. In this build model,
it is critical to separate the user-mode OS interfaces in this way.
If CONFIG_BUILD_KERNEL is selected, then only a NuttX kernel will be built
with no applications.
Sub-Directories
===============
The files in the libs/libc-musl/ directory are organized (mostly) according which file
in the include/ directory provides the prototype for library functions. So
we have:
audio - This part of the audio system: nuttx/audio/audio.h
builtin - Support for builtin applications. Used by nuttx/binfmt and NSH.
dlfcn - dlfcn.h
endian - endian.h
errno - errno.h
hex2bin - hex2bin.h
libgen - libgen.h
locale - locale.h
lzf - lzf.h
fixedmath - fixedmath.h
grp - grp.h
inttypes - inttypes.h
machine - Various architecture-specific implementations.
math - math.h
modlib - Part of module and shared library logic: nuttx/lib/modlib.h
net - Various network-related header files: netinet/ether.h, arpa/inet.h
pthread - pthread.h
pwd - pwd.h
queue - queue.h
sched - sched.h
semaphore - semaphore.h
stdio - stdio.h
stdlib - stdlib.h
string - string.h (and legacy strings.h and non-standard nuttx/b2c.h)
time - time.h
uio - sys/uio.h
unistd - unistd.h
wchar - wchar.h
wctype - wctype.h
Most of these are "standard" header files; some are not: hex2bin.h and
fixemath.h are non-standard.
There is also a misc/ subdirectory that contains various internal functions
and interfaces from header files that are too few to warrant their own sub-
directory:
misc - Nonstandard "glue" logic, debug.h, crc32.h, dirent.h
Library Database
================
Information about functions available in the NuttX C library information is
maintained in a database. That "database" is implemented as a simple comma-
separated-value file, libc-musl.csv. Most spreadsheets programs will accept this
format and can be used to maintain the library database.
This library database will (eventually) be used to generate symbol library
symbol table information that can be exported to external applications.
The format of the CSV file for each line is:
Field 1: Function name
Field 2: The header file that contains the function prototype
Field 3: Condition for compilation
Field 4: The type of function return value.
Field 5 - N+5: The type of each of the N formal parameters of the function
Each type field has a format as follows:
type name:
For all simpler types
formal type | actual type:
For array types where the form of the formal (eg. int parm[2])
differs from the type of actual passed parameter (eg. int*). This
is necessary because you cannot do simple casts to array types.
formal type | union member actual type | union member fieldname:
A similar situation exists for unions. For example, the formal
parameter type union sigval -- You cannot cast a uintptr_t to
a union sigval, but you can cast to the type of one of the union
member types when passing the actual parameter. Similarly, we
cannot cast a union sigval to a uinptr_t either. Rather, we need
to cast a specific union member fieldname to uintptr_t.
NOTE: The tool mksymtab can be used to generate a symbol table from this CSV
file. See nuttx/tools/README.txt for further details about the use of mksymtab.
symtab
======
Symbol Tables and Build Modes
-----------------------------
This directory provide support for a symbol table which provides all/most of
system and C library services/functions to the application and NSH.
Symbol tables have differing usefulness in different NuttX build modes:
1. In the FLAT build (CONFIG_BUILD_FLAT), symbol tables are used to bind
addresses in loaded ELF or NxFLAT modules to base code that usually
resides in FLASH memory. Both OS interfaces and user/application
libraries are made available to the loaded module via symbol tables.
2. Symbol tables may be of value in a protected build
(CONFIG_BUILD_PROTECTED) where the newly started user task must
share resources with other user code (but should use system calls to
interact with the OS).
3. But in the kernel build mode (CONFIG_BUILD_LOADABLE), only fully linked
executables loadable via execl(), execv(), or posix_spawan() can used.
There is no use for a symbol table with the kernel build since all
memory resources are separate; nothing is share-able with the newly
started process.
Code/Text Size Implications
---------------------------
The option can have substantial effect on system image size, mainly
code/text. That is because the instructions to generate symtab.inc
above will cause EVERY interface in the NuttX RTOS and the C library to be
included into build. Add to that the size of a huge symbol table.
In order to reduce the code/text size, you may want to manually prune the
auto-generated symtab.inc file to remove all interfaces that you do
not wish to include into the base FLASH image.

View File

@ -0,0 +1,31 @@
############################################################################
# libs/libc-musl/aio/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_FS_AIO),y)
# Add the asynchronous I/O C files to the build
CSRCS += aio_error.c aio_return.c aio_suspend.c lio_listio.c
# Add the asynchronous I/O directory to the build
DEPPATH += --dep-path aio
VPATH += :aio
endif

View File

@ -0,0 +1,72 @@
/****************************************************************************
* libs/libc-musl/aio/aio.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file aio.h
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#ifndef __LIBS_LIBC_AIO_AIO_H
#define __LIBS_LIBC_AIO_AIO_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#ifdef CONFIG_FS_AIO
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Types
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#undef EXTERN
#if defined(__cplusplus)
}
#endif
#endif /* CONFIG_FS_AIO */
#endif /* __LIBS_LIBC_AIO_AIO_H */

View File

@ -0,0 +1,109 @@
/****************************************************************************
* libs/libc-musl/aio/aio_error.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file aio_error.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <aio.h>
#include <assert.h>
#include <errno.h>
#ifdef CONFIG_FS_AIO
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: aio_error
*
* Description:
* The aio_error() function returns the error status associated with the
* aiocb structure referenced by the aiocbp argument. The error status fo
* an asynchronous I/O operation is the errno value that would be set by
* the corresponding read(), write(), fdatasync(), or fsync() operation. If
* the operation has not yet completed, then the error status will be equal
* to EINPROGRESS.
*
* Input Parameters:
* aiocbp - A pointer to an instance of struct aiocb
*
* Returned Value:
* If the asynchronous I/O operation has completed successfully, then 0
* will be returned. If the asynchronous operation has completed
* unsuccessfully, then the error status, as described for read(),
* write(), fdatasync(), and fsync(), will be returned. If the
* asynchronous I/O operation has not yet completed, then EINPROGRESS will
* be returned.
*
* The aio_error() function may fail if:
*
* EINVAL - The aiocbp argument does not refer to an asynchronous
* operation whose return status has not yet been retrieved.
*
****************************************************************************/
int aio_error(FAR const struct aiocb *aiocbp)
{
DEBUGASSERT(aiocbp);
if (aiocbp->aio_result < 0)
{
return -aiocbp->aio_result;
}
return OK;
}
#endif /* CONFIG_FS_AIO */

View File

@ -0,0 +1,113 @@
/****************************************************************************
* libs/libc-musl/aio/aio_return.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file aio_return.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <aio.h>
#include <assert.h>
#include <errno.h>
#ifdef CONFIG_FS_AIO
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: aio_return
*
* Description:
* The aio_return() function returns the return status associated with
* the aiocb structure referenced by the aiocbp argument. The return
* status for an asynchronous I/O operation is the value that would be
* returned by the corresponding read(), write(), or fsync() function
* call. If the error status for the operation is equal to EINPROGRESS,
* then the return status for the operation is undefined. The aio_return()
* function may be called exactly once to retrieve the return status of
* a given asynchronous operation; thereafter, if the same aiocb structure
* is used in a call to aio_return() or aio_error(), an error may be
* returned. When the aiocb structure referred to by aiocbp is used to
* submit another asynchronous operation, then aio_return() may be
* successfully used to retrieve the return status of that operation.
*
* Input Parameters:
* aiocbp - A pointer to an instance of struct aiocb
*
* Returned Value:
* If the asynchronous I/O operation has completed, then the return
* status, as described for read(), write(), and fsync(), will be
* returned. If the asynchronous I/O operation has not yet completed,
* the results of aio_return() are undefined.
*
* The aio_return() function may fail if:
*
* EINVAL - The aiocbp argument does not refer to an asynchronous
* operation whose return status has not yet been retrieved.
*
****************************************************************************/
ssize_t aio_return(FAR struct aiocb *aiocbp)
{
DEBUGASSERT(aiocbp);
if (aiocbp->aio_result < 0)
{
set_errno((int)-aiocbp->aio_result);
return (ssize_t)ERROR;
}
return aiocbp->aio_result;
}
#endif /* CONFIG_FS_AIO */

View File

@ -0,0 +1,142 @@
/****************************************************************************
* libs/libc-musl/aio/aio_suspend.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file aio_suspend.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sched.h>
#include <signal.h>
#include <aio.h>
#include <assert.h>
#include <errno.h>
#ifdef CONFIG_FS_AIO
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: aio_suspend
*
* Description:
* The aio_suspend() function suspends the calling thread until at least
* one of the asynchronous I/O operations referenced by the 'list' argument
* has completed, until a signal interrupts the function, or, if 'timeout'
* is not NULL, until the time interval specified by 'timeout' has passed.
* If any of the aiocb structures in the list correspond to completed
* asynchronous I/O operations (that is, the error status for the
* operation is not equal to EINPROGRESS) at the time of the call, the
* function returns without suspending the calling thread.
*
* Each aiocb structure pointed to must have been used in initiating an
* asynchronous I/O request via aio_read(), aio_write(), or lio_listio().
* This array may contain NULL pointers, which are ignored. If this
* array contains pointers that refer to aiocb structures that have not
* been used in submitting asynchronous I/O, the effect is undefined.
*
* Input Parameters:
* list - An array of pointers to asynchronous I/O control blocks.
* nent - The number of elements in the array.
* aiocbp - A pointer to an array
* timeout - If not NULL, this parameter is pointer to a timespec
* structure that determines a timeout on the operation. If
* the time referred to timeout passes before any of the I/O
* operations referenced by list are completed, then
* aio_suspend() returns with an error.
*
* Returned Value:
* If the aio_suspend() function returns after one or more asynchronous
* I/O operations have completed, the function returns zero. Otherwise,
* the function returns a value of -1 and sets errno to indicate the
* error. The application may determine which asynchronous I/O completed
* by scanning the associated error and return status using aio_error()
* and aio_return(), respectively.
*
* The aio_suspend() function will fail if:
*
* EAGAIN - No asynchronous I/O indicated in the list referenced by
* list completed in the time interval indicated by timeout.
* EINTR - A signal interrupted the aio_suspend() function.
*
****************************************************************************/
int aio_suspend(FAR const struct aiocb * const list[], int nent,
FAR const struct timespec *timeout)
{
sigset_t set;
int ret;
int i;
DEBUGASSERT(list);
/* Lock the scheduler so that no I/O events can complete on the worker
* thread until we set our wait set up. Pre-emption will, of course, be
* re-enabled while we are waiting for the signal.
*/
sched_lock();
/* Check each entry in the list. Break out of the loop if any entry
* has completed.
*/
for (i = 0; i < nent; i++)
{
/* Check if the I/O has completed */
if (list[i] && list[i]->aio_result != -EINPROGRESS)
{
/* Yes, return success */
sched_unlock();
return OK;
}
}
/* Then wait for SIGPOLL. On success sigtimedwait() will return the
* signal number that cause the error (SIGPOLL). It will set errno
* appropriately for this function on errors.
*
* NOTE: If completion of the I/O causes other signals to be generated
* first, then this will wake up and return EINTR instead of success.
*/
sigemptyset(&set);
sigaddset(&set, SIGPOLL);
ret = sigtimedwait(&set, NULL, timeout);
sched_unlock();
return ret >= 0 ? OK : ERROR;
}
#endif /* CONFIG_FS_AIO */

View File

@ -0,0 +1,705 @@
/****************************************************************************
* libs/libc-musl/aio/lio_listio.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lio_listio.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <unistd.h>
#include <signal.h>
#include <aio.h>
#include <assert.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/signal.h>
#include "libc-musl.h"
#include "aio/aio.h"
#ifdef CONFIG_FS_AIO
/****************************************************************************
* Private Types
****************************************************************************/
struct lio_sighand_s
{
FAR struct aiocb * const *list; /* List of I/O operations */
FAR struct sigevent sig; /* Describes how to signal the caller */
int nent; /* Number or elements in list[] */
pid_t pid; /* ID of client */
sigset_t oprocmask; /* sigprocmask to restore */
struct sigaction oact; /* Signal handler to restore */
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: lio_checkio
*
* Description:
* Check if all I/O operations in the list are complete.
*
* Input Parameters:
* list - The list of I/O operations to be performed
* nent - The number of elements in the list
*
* Returned Value:
* Zero (OK) is returned if all I/O completed successfully.
* -EINPROGRESS is returned if one or more I/Os have not yet completed.
* The negated errno value if first error noted in the case where all I/O
* completed but one or more I/Os completed with an error.
*
* Assumptions:
* The scheduler is locked and no I/O can complete asynchronously with
* the logic in this function.
*
****************************************************************************/
static int lio_checkio(FAR struct aiocb * const *list, int nent)
{
FAR struct aiocb *aiocbp;
int ret;
int i;
ret = OK; /* Assume success */
/* Check each entry in the list. Break out of the loop if any entry
* has not completed.
*/
for (i = 0; i < nent; i++)
{
/* Skip over NULL entries */
aiocbp = list[i];
if (aiocbp)
{
/* Check if the I/O has completed */
if (aiocbp->aio_result == -EINPROGRESS)
{
/* No.. return -EINPROGRESS */
return -EINPROGRESS;
}
/* Check for an I/O error */
else if (aiocbp->aio_result < 0 && ret == OK)
{
/* Some other error other than -EINPROGRESS */
ret = aiocbp->aio_result;
}
}
}
/* All of the I/Os have completed */
return ret;
}
/****************************************************************************
* Name: lio_sighandler
*
* Description:
* Handle the SIGPOLL signal.
*
* Input Parameters:
* signo - The number of the signal that we caught (SIGPOLL)
* info - Information accompanying the signal
* context - Not used in NuttX
*
* Returned Value:
* None
*
****************************************************************************/
static void lio_sighandler(int signo, siginfo_t *info, void *ucontext)
{
FAR struct aiocb *aiocbp;
FAR struct lio_sighand_s *sighand;
int ret;
DEBUGASSERT(signo == SIGPOLL && info);
/* The info structure should contain a pointer to the AIO control block */
aiocbp = (FAR struct aiocb *)info->si_value.sival_ptr;
DEBUGASSERT(aiocbp && aiocbp->aio_result != -EINPROGRESS);
/* Recover our private data from the AIO control block */
sighand = (FAR struct lio_sighand_s *)aiocbp->aio_priv;
DEBUGASSERT(sighand && sighand->list);
aiocbp->aio_priv = NULL;
/* Prevent any asynchronous I/O completions while the signal handler runs */
sched_lock();
/* Check if all of the pending I/O has completed */
ret = lio_checkio(sighand->list, sighand->nent);
if (ret != -EINPROGRESS)
{
/* All pending I/O has completed */
/* Restore the signal handler */
sigaction(SIGPOLL, &sighand->oact, NULL);
/* Restore the sigprocmask */
sigprocmask(SIG_SETMASK, &sighand->oprocmask, NULL);
/* Signal the client */
DEBUGVERIFY(nxsig_notification(sighand->pid, &sighand->sig,
SI_ASYNCIO, &aiocbp->aio_sigwork));
/* And free the container */
lib_free(sighand);
}
sched_unlock();
}
/****************************************************************************
* Name: lio_sigsetup
*
* Description:
* Setup a signal handler to detect when until all I/O completes.
*
* Input Parameters:
* list - The list of I/O operations to be performed
* nent - The number of elements in the list
*
* Returned Value:
* Zero (OK) is returned if all I/O completed successfully; Otherwise, a
* negated errno value is returned corresponding to the first error
* detected.
*
* Assumptions:
* The scheduler is locked and no I/O can complete asynchronously with
* the logic in this function.
*
****************************************************************************/
static int lio_sigsetup(FAR struct aiocb * const *list, int nent,
FAR struct sigevent *sig)
{
FAR struct aiocb *aiocbp;
FAR struct lio_sighand_s *sighand;
sigset_t set;
struct sigaction act;
int status;
int i;
/* Allocate a structure to pass data to the signal handler */
sighand = lib_zalloc(sizeof(struct lio_sighand_s));
if (!sighand)
{
ferr("ERROR: lib_zalloc failed\n");
return -ENOMEM;
}
/* Initialize the allocated structure */
sighand->list = list;
sighand->sig = *sig;
sighand->nent = nent;
sighand->pid = getpid();
/* Save this structure as the private data attached to each aiocb */
for (i = 0; i < nent; i++)
{
/* Skip over NULL entries in the list */
aiocbp = list[i];
if (aiocbp)
{
FAR void *priv = NULL;
/* Check if I/O is pending for this entry */
if (aiocbp->aio_result == -EINPROGRESS)
{
priv = (FAR void *)sighand;
}
aiocbp->aio_priv = priv;
}
}
/* Make sure that SIGPOLL is not blocked */
sigemptyset(&set);
sigaddset(&set, SIGPOLL);
status = sigprocmask(SIG_UNBLOCK, &set, &sighand->oprocmask);
if (status != OK)
{
int errcode = get_errno();
ferr("ERROR sigprocmask failed: %d\n", errcode);
DEBUGASSERT(errcode > 0);
return -errcode;
}
/* Attach our signal handler */
finfo("Registering signal handler\n");
act.sa_sigaction = lio_sighandler;
act.sa_flags = SA_SIGINFO;
sigfillset(&act.sa_mask);
sigdelset(&act.sa_mask, SIGPOLL);
status = sigaction(SIGPOLL, &act, &sighand->oact);
if (status != OK)
{
int errcode = get_errno();
ferr("ERROR sigaction failed: %d\n", errcode);
DEBUGASSERT(errcode > 0);
return -errcode;
}
return OK;
}
/****************************************************************************
* Name: lio_waitall
*
* Description:
* Wait for all I/O operations in the list to be complete.
*
* Input Parameters:
* list - The list of I/O operations to be performed
* nent - The number of elements in the list
*
* Returned Value:
* Zero (OK) is returned if all I/O completed successfully; Otherwise, a
* negated errno value is returned corresponding to the first error
* detected.
*
* Assumptions:
* The scheduler is locked and no I/O can complete asynchronously with
* the logic in this function.
*
****************************************************************************/
static int lio_waitall(FAR struct aiocb * const *list, int nent)
{
sigset_t set;
int ret;
/* Loop until all I/O completes */
for (; ; )
{
/* Check if all I/O has completed */
ret = lio_checkio(list, nent);
if (ret != -EINPROGRESS)
{
/* All I/O has completed.. We are finished. */
return ret;
}
/* Then wait for SIGPOLL -- indefinitely.
*
* NOTE: If completion of the I/O causes other signals to be generated
* first, then this will wake up and return EINTR instead of success.
*/
sigemptyset(&set);
sigaddset(&set, SIGPOLL);
ret = sigwaitinfo(&set, NULL);
if (ret < 0)
{
int errcode = get_errno();
/* The most likely reason that we would get here is because some
* unrelated signal has been received.
*/
ferr("ERROR: sigwaitinfo failed: %d\n", errcode);
DEBUGASSERT(errcode > 0);
return -errcode;
}
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: lio_listio
*
* Description:
* The lio_listio() function initiates a list of I/O requests with a
* single function call.
*
* The 'mode' argument takes one of the values LIO_WAIT or LIO_NOWAIT
* declared in <aio.h> and determines whether the function returns when
* the I/O operations have been completed, or as soon as the operations
* have been queued. If the 'mode' argument is LIO_WAIT, the function will
* wait until all I/O is complete and the 'sig' argument will be ignored.
*
* If the 'mode' argument is LIO_NOWAIT, the function will return
* immediately, and asynchronous notification will occur, according to the
* 'sig' argument, when all the I/O operations complete. If 'sig' is NULL,
* then no asynchronous notification will occur. If 'sig' is not NULL,
* asynchronous notification occurs when all the requests in 'list' have
* completed.
*
* The I/O requests enumerated by 'list' are submitted in an unspecified
* order.
*
* The 'list' argument is an array of pointers to aiocb structures. The
* array contains 'nent 'elements. The array may contain NULL elements,
* which will be ignored.
*
* If the buffer pointed to by 'list' or the aiocb structures pointed to
* by the elements of the array 'list' become illegal addresses before all
* asynchronous I/O completed and, if necessary, the notification is
* sent, then the behavior is undefined. If the buffers pointed to by the
* aio_buf member of the aiocb structure pointed to by the elements of
* the array 'list' become illegal addresses prior to the asynchronous
* I/O associated with that aiocb structure being completed, the behavior
* is undefined.
*
* The aio_lio_opcode field of each aiocb structure specifies the
* operation to be performed. The supported operations are LIO_READ,
* LIO_WRITE, and LIO_NOP; these symbols are defined in <aio.h>. The
* LIO_NOP operation causes the list entry to be ignored. If the
* aio_lio_opcode element is equal to LIO_READ, then an I/O operation is
* submitted as if by a call to aio_read() with the aiocbp equal to the
* address of the aiocb structure. If the aio_lio_opcode element is equal
* to LIO_WRITE, then an I/O operation is submitted as if by a call to
* aio_write() with the aiocbp equal to the address of the aiocb
* structure.
*
* The aio_fildes member specifies the file descriptor on which the
* operation is to be performed.
*
* The aio_buf member specifies the address of the buffer to or from which
* the data is transferred.
*
* The aio_nbytes member specifies the number of bytes of data to be
* transferred.
*
* The members of the aiocb structure further describe the I/O operation
* to be performed, in a manner identical to that of the corresponding
* aiocb structure when used by the aio_read() and aio_write() functions.
*
* The 'nent' argument specifies how many elements are members of the list;
* that is, the length of the array.
*
* Input Parameters:
* mode - Either LIO_WAIT or LIO_NOWAIT
* list - The list of I/O operations to be performed
* nent - The number of elements in the list
* sig - Used to notify the caller when the I/O is performed
* asynchronously.
*
* Returned Value:
* If the mode argument has the value LIO_NOWAIT, the lio_listio()
* function will return the value zero if the I/O operations are
* successfully queued; otherwise, the function will return the value
* -1 and set errno to indicate the error.
*
* If the mode argument has the value LIO_WAIT, the lio_listio() function
* will return the value zero when all the indicated I/O has completed
* successfully. Otherwise, lio_listio() will return a value of -1 and
* set errno to indicate the error.
*
* In either case, the return value only indicates the success or failure
* of the lio_listio() call itself, not the status of the individual I/O
* requests. In some cases one or more of the I/O requests contained in
* the list may fail. Failure of an individual request does not prevent
* completion of any other individual request. To determine the outcome
* of each I/O request, the application must examine the error status
* associated with each aiocb control block. The error statuses so
* returned are identical to those returned as the result of an aio_read()
* or aio_write() function.
*
* The lio_listio() function will fail if:
*
* EAGAIN - The resources necessary to queue all the I/O requests were
* not available. The application may check the error status for each
* aiocb to determine the individual request(s) that failed.
* EAGAIN - The number of entries indicated by 'nent' would cause the
* system-wide limit {AIO_MAX} to be exceeded.
* EINVAL - The mode argument is not a proper value, or the value of
* 'nent' was greater than {AIO_LISTIO_MAX}.
* EINTR - A signal was delivered while waiting for all I/O requests to
* complete during an LIO_WAIT operation. Note that, since each I/O
* operation invoked by lio_listio() may possibly provoke a signal when
* it completes, this error return may be caused by the completion of
* one (or more) of the very I/O operations being awaited. Outstanding
* I/O requests are not cancelled, and the application will examine
* each list element to determine whether the request was initiated,
* cancelled, or completed.
* EIO - One or more of the individual I/O operations failed. The
* application may check the error status for each aiocb structure to
* determine the individual request(s) that failed.
*
* In addition to the errors returned by the lio_listio() function, if the
* lio_listio() function succeeds or fails with errors of EAGAIN, EINTR, or
* EIO, then some of the I/O specified by the list may have been initiated.
* If the lio_listio() function fails with an error code other than EAGAIN,
* EINTR, or EIO, no operations from the list will have been initiated. The
* I/O operation indicated by each list element can encounter errors
* specific to the individual read or write function being performed. In
* this event, the error status for each aiocb control block contains the
* associated error code. The error codes that can be set are the same as
* would be set by a read() or write() function, with the following
* additional error codes possible:
*
* EAGAIN - The requested I/O operation was not queued due to resource
* limitations.
* ECANCELED - The requested I/O was cancelled before the I/O completed
* due to an explicit aio_cancel() request.
* EFBIG - The aiocbp->aio_lio_opcode is LIO_WRITE, the file is a
* regular file, aiocbp->aio_nbytes is greater than 0, and the
* aiocbp->aio_offset is greater than or equal to the offset maximum
* in the open file description associated with aiocbp->aio_fildes.
* EINPROGRESS - The requested I/O is in progress.
* EOVERFLOW - The aiocbp->aio_lio_opcode is LIO_READ, the file is a
* regular file, aiocbp->aio_nbytes is greater than 0, and the
* aiocbp->aio_offset is before the end-of-file and is greater than
* or equal to the offset maximum in the open file description
* associated with aiocbp->aio_fildes.
*
****************************************************************************/
int lio_listio(int mode, FAR struct aiocb * const list[], int nent,
FAR struct sigevent *sig)
{
FAR struct aiocb *aiocbp = NULL;
int nqueued;
int errcode;
int retcode;
int status;
int ret;
int i;
DEBUGASSERT(mode == LIO_WAIT || mode == LIO_NOWAIT);
DEBUGASSERT(list);
nqueued = 0; /* No I/O operations yet queued */
ret = OK; /* Assume success */
/* Lock the scheduler so that no I/O events can complete on the worker
* thread until we set our wait set up. Pre-emption will, of course, be
* re-enabled while we are waiting for the signal.
*/
sched_lock();
/* Submit each asynchronous I/O operation in the list, skipping over NULL
* entries.
*/
for (i = 0; i < nent; i++)
{
/* Skip over NULL entries */
aiocbp = list[i];
if (aiocbp)
{
/* Submit the operation according to its opcode */
status = OK;
switch (aiocbp->aio_lio_opcode)
{
case LIO_NOP:
{
/* Mark the do-nothing operation complete */
aiocbp->aio_result = OK;
}
break;
case LIO_READ:
case LIO_WRITE:
{
if (aiocbp->aio_lio_opcode == LIO_READ)
{
/* Submit the asynchronous read operation */
status = aio_read(aiocbp);
}
else
{
/* Submit the asynchronous write operation */
status = aio_write(aiocbp);
}
if (status < 0)
{
/* Failed to queue the I/O. Set up the error return. */
errcode = get_errno();
ferr("ERROR: aio_read/write failed: %d\n", errcode);
DEBUGASSERT(errcode > 0);
aiocbp->aio_result = -errcode;
ret = ERROR;
}
else
{
/* Increment the count of successfully queue operations */
nqueued++;
}
}
break;
default:
{
/* Make the invalid operation complete with an error */
ferr("ERROR: Unrecognized opcode: %d\n",
aiocbp->aio_lio_opcode);
aiocbp->aio_result = -EINVAL;
ret = ERROR;
}
break;
}
}
}
/* If there was any failure in queuing the I/O, EIO will be returned */
retcode = EIO;
/* Now what? Three possibilities:
*
* Case 1: mode == LIO_WAIT
*
* Ignore the sig argument; Do no return until all I/O completes.
*/
if (mode == LIO_WAIT)
{
/* Don't wait if all if no I/O was queue */
if (nqueued > 0)
{
/* Wait until all I/O completes. The scheduler will be unlocked
* while we are waiting.
*/
status = lio_waitall(list, nent);
if (status < 0 && ret == OK)
{
/* Something bad happened while waiting and this is the first
* error to be reported.
*/
retcode = -status;
ret = ERROR;
}
}
}
/* Case 2: mode == LIO_NOWAIT and sig != NULL
*
* If any I/O was queued, then setup to signal the caller when all of
* the transfers complete.
*
* If no I/O was queue, then we I suppose that we need to signal the
* caller ourself?
*/
else if (sig != NULL)
{
if (nqueued > 0)
{
/* Setup a signal handler to detect when until all I/O completes. */
status = lio_sigsetup(list, nent, sig);
if (status < 0 && ret == OK)
{
/* Something bad happened while setting up the signal and this
* is the first error to be reported.
*/
retcode = -status;
ret = ERROR;
}
}
else
{
status = nxsig_notification(getpid(), sig,
SI_ASYNCIO, &aiocbp->aio_sigwork);
if (status < 0 && ret == OK)
{
/* Something bad happened while performing the notification
* and this is the first error to be reported.
*/
retcode = -status;
ret = ERROR;
}
}
}
/* Case 3: mode == LIO_NOWAIT and sig == NULL
*
* Just return now.
*/
sched_unlock();
if (ret < 0)
{
set_errno(retcode);
return ERROR;
}
return OK;
}
#endif /* CONFIG_FS_AIO */

View File

@ -0,0 +1,30 @@
############################################################################
# libs/libc-musl/assert/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
CSRCS += lib_assert.c
ifeq ($(CONFIG_STACK_CANARIES),y)
CSRCS += lib_stackchk.c
endif
# Add the assert directory to the build
DEPPATH += --dep-path assert
VPATH += :assert

View File

@ -0,0 +1,47 @@
/****************************************************************************
* libs/libc-musl/assert/lib_assert.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_assert.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/arch.h>
#include <assert.h>
#include <stdlib.h>
/****************************************************************************
* Public Functions
****************************************************************************/
void _assert(FAR const char *filename, int linenum)
{
up_assert(filename, linenum);
exit(EXIT_FAILURE);
}

View File

@ -0,0 +1,69 @@
/****************************************************************************
* libs/libc-musl/assert/lib_stackchk.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_stackchk.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <assert.h>
#ifdef CONFIG_STACK_CANARIES
/****************************************************************************
* Public Data
****************************************************************************/
FAR const void *const __stack_chk_guard = &__stack_chk_guard;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: __stack_chk_fail
*
* Description:
* The interface __stack_chk_fail() shall abort the function that called
* it with a message that a stack overflow has been detected. The program
* that called the function shall then exit.
*
* Input Parameters:
* None
*
* Returned Value:
* None.
*
****************************************************************************/
void __stack_chk_fail(void)
{
PANIC();
}
#endif /* CONFIG_STACK_CANARIES */

View File

@ -0,0 +1,30 @@
############################################################################
# libs/libc-musl/audio/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_AUDIO),y)
CSRCS += lib_buffer.c
include audio/libsrc/Make.defs
# Add the audio/ directory to the build
DEPPATH += --dep-path audio
VPATH += :audio
endif

View File

@ -0,0 +1,180 @@
/****************************************************************************
* libs/libc-musl/audio/lib_buffer.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_buffer.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/audio/audio.h>
#include <nuttx/usb/audio.h>
#include "libc-musl.h"
#if defined(CONFIG_AUDIO)
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: apb_semtake
*
* Take an Audio Pipeline Buffer.
*
****************************************************************************/
static void apb_semtake(FAR struct ap_buffer_s *apb)
{
int ret;
/* Take the semaphore (perhaps waiting) */
while (_SEM_WAIT(&apb->sem) < 0)
{
/* The only case that an error should occr here is if
* the wait was awakened by a signal.
*/
DEBUGASSERT(_SEM_ERRNO(ret) == EINTR || _SEM_ERRNO(ret) == ECANCELED);
UNUSED(ret);
}
}
/****************************************************************************
* Name: apb_semgive
****************************************************************************/
#define apb_semgive(b) _SEM_POST(&b->sem)
/****************************************************************************
* Name: apb_alloc
*
* Allocate an Audio Pipeline Buffer for use in the Audio sub-system. This
* will perform the actual allocate based on buffer data format, number of
* channels, etc. and prepare the buffer for consumption.
*
****************************************************************************/
int apb_alloc(FAR struct audio_buf_desc_s *bufdesc)
{
uint32_t bufsize;
int ret;
struct ap_buffer_s *apb;
DEBUGASSERT(bufdesc->u.pbuffer != NULL);
/* Perform a user mode allocation */
bufsize = sizeof(struct ap_buffer_s) + bufdesc->numbytes;
apb = lib_umalloc(bufsize);
*bufdesc->u.pbuffer = apb;
/* Test if the allocation was successful or not */
if (*bufdesc->u.pbuffer == NULL)
{
ret = -ENOMEM;
}
else
{
/* Populate the buffer contents */
memset(apb, 0, bufsize);
apb->i.channels = 1;
apb->crefs = 1;
apb->nmaxbytes = bufdesc->numbytes;
apb->nbytes = 0;
apb->flags = 0;
apb->samp = (FAR uint8_t *)(apb + 1);
#ifdef CONFIG_AUDIO_MULTI_SESSION
apb->session = bufdesc->session;
#endif
_SEM_INIT(&apb->sem, 0, 1);
ret = sizeof(struct audio_buf_desc_s);
}
return ret;
}
/****************************************************************************
* Name: apb_free
*
* Free's a previously allocated or referenced Audio Pipeline Buffer
*
****************************************************************************/
void apb_free(FAR struct ap_buffer_s *apb)
{
int refcount;
/* Perform a reference count decrement and possibly release the memory */
apb_semtake(apb);
refcount = apb->crefs--;
apb_semgive(apb);
if (refcount <= 1)
{
audinfo("Freeing %p\n", apb);
_SEM_DESTROY(&apb->sem);
lib_ufree(apb);
}
}
/****************************************************************************
* Name: apb_reference
*
* Claim a reference to an Audio Pipeline Buffer. Each call to apb_reference
* will increment the reference count and must have a matching apb_free
* call. When the refcount decrements to zero, the buffer will be freed.
*
****************************************************************************/
void apb_reference(FAR struct ap_buffer_s *apb)
{
/* Do we need any thread protection here? Almost certaily... */
apb_semtake(apb);
apb->crefs++;
apb_semgive(apb);
}
#endif /* CONFIG_AUDIO */

View File

@ -0,0 +1,64 @@
############################################################################
# libs/libc-musl/audio/libsrc/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_AUDIO_SRC),y)
PACKAGE=libsamplerate
VERSION=0.1.9
libsamplerate:
$(Q) curl -L https://codeload.github.com/libsndfile/libsamplerate/zip/master -o libsamplerate.zip
$(Q) unzip -o libsamplerate.zip
$(Q) mv libsamplerate-master libsamplerate
$(Q) cp -rf libsamplerate/include/samplerate.h $(TOPDIR)$(DELIM)include$(DELIM)nuttx$(DELIM)audio$(DELIM)
context:: libsamplerate
CSRCS += samplerate.c
CSRCS += src_sinc.c
CSRCS += src_linear.c
CSRCS += src_zoh.c
CFLAGS += -DPACKAGE=\"$(PACKAGE)\" -DVERSION=\"$(VERSION)\"
CFLAGS += ${shell $(INCDIR) "$(CC)" $(TOPDIR)$(DELIM)include$(DELIM)nuttx$(DELIM)audio}
ifeq ($(CONFIG_SINC_FAST_CONVERTER),y)
CFLAGS += -DENABLE_SINC_FAST_CONVERTER
endif
ifeq ($(CONFIG_SINC_MEDIUM_CONVERTER),y)
CFLAGS += -DENABLE_SINC_MEDIUM_CONVERTER
endif
ifeq ($(CONFIG_SINC_BEST_CONVERTER),y)
CFLAGS += -DENABLE_SINC_BEST_CONVERTER
endif
VPATH += libsamplerate/src
SUBDIRS += libsamplerate/src
DEPPATH += --dep-path libsamplerate/src
distclean::
$(call DELDIR, $(TOPDIR)$(DELIM)include$(DELIM)nuttx$(DELIM)audio$(DELIM)samplerate.h)
$(call DELDIR, libsamplerate)
$(call DELFILE, libsamplerate.zip)
endif

View File

@ -0,0 +1,33 @@
############################################################################
# libs/libc-musl/bin/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
###########################################################################
include $(TOPDIR)/Make.defs
all:
.PHONY: clean distclean
# Clean Targets:
clean:
$(call CLEAN)
# Deep clean -- removes all traces of the configuration
distclean: clean

View File

@ -0,0 +1,36 @@
############################################################################
# libs/libc-musl/builtin/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_BUILTIN),y)
# Builtin library files
CSRCS += lib_builtin_getname.c lib_builtin_isavail.c lib_builtin_forindex.c
ifeq ($(CONFIG_BUILD_PROTECTED),y)
CSRCS += lib_builtin_setlist.c
endif
# Hook the builtin subdirectory into the build
DEPPATH += --dep-path builtin
VPATH += builtin
endif

View File

@ -0,0 +1,69 @@
/****************************************************************************
* libs/libc-musl/builtin/lib_builtin_forindex.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_builtin_forindex.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/lib/builtin.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: builtin_for_index
*
* Description:
* Returns the builtin_s structure for the selected built-in.
* If support for built-in functions is enabled in the NuttX
* configuration, then this function must be provided by the application
* code.
*
* Input Parameters:
* index, from 0 and on...
*
* Returned Value:
* Returns valid pointer pointing to the builtin_s structure if index is
* valid.
* Otherwise, NULL is returned.
*
****************************************************************************/
FAR const struct builtin_s *builtin_for_index(int index)
{
if (index < g_builtin_count)
{
return &g_builtins[index];
}
return NULL;
}

View File

@ -0,0 +1,70 @@
/****************************************************************************
* libs/libc-musl/builtin/lib_builtin_getname.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_builtin_getname.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/lib/builtin.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: builtin_getname
*
* Description:
* Returns pointer the a name of the application at 'index' in the table
* of built-in applications.
*
* Input Parameters:
* index - From 0 and on ...
*
* Returned Value:
* Returns valid pointer pointing to the app name if index is valid.
* Otherwise NULL is returned.
*
****************************************************************************/
FAR const char *builtin_getname(int index)
{
FAR const struct builtin_s *builtin;
builtin = builtin_for_index(index);
if (builtin != NULL)
{
return builtin->name;
}
return NULL;
}

View File

@ -0,0 +1,79 @@
/****************************************************************************
* libs/libc-musl/builtin/lib_builtin_isavail.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_builtin_isavail.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <limits.h>
#include <errno.h>
#include <nuttx/lib/builtin.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: builtin_isavail
*
* Description:
* Checks for availability of an application named 'appname' registered
* during compile time and, if available, returns the index into the table
* of built-in applications.
*
* Input Parameters:
* filename - Name of the linked-in binary to be started.
*
* Returned Value:
* This is an internal function, used by by the NuttX binfmt logic and
* by the application built-in logic. It returns a non-negative index to
* the application entry in the table of built-in applications on success
* or a negated errno value in the event of a failure.
*
****************************************************************************/
int builtin_isavail(FAR const char *appname)
{
FAR const char *name;
int i;
for (i = 0; (name = builtin_getname(i)) != NULL; i++)
{
if (strcmp(name, appname) == 0)
{
return i;
}
}
return -ENOENT;
}

View File

@ -0,0 +1,82 @@
/****************************************************************************
* libs/libc-musl/builtin/lib_builtin_setlist.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_builtin_setlist.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/lib/builtin.h>
#if defined(CONFIG_BUILD_PROTECTED) && defined(__KERNEL__)
/****************************************************************************
* Public Functions
****************************************************************************/
FAR const struct builtin_s *g_builtins;
int g_builtin_count;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: builtin_setlist
*
* Description:
* Saves the user-space list of built-in applications for use by BINFS in
* protected mode. Normally this is small set of globals provided by
* user-space logic. It provides name-value pairs for associating
* built-in application names with user-space entry point addresses.
* These globals are only needed for use by BINFS which executes built-in
* applications from kernel-space in PROTECTED mode. In the FLAT build,
* the user space globals are readily available. (BINFS is not
* supportable in KERNEL mode since user-space address have no general
* meaning that configuration).
*
* Input Parameters:
* builtins - The list of built-in functions. Each entry is a name-value
* pair that maps a built-in function name to its user-space
* entry point address.
* count - The number of name-value pairs in the built-in list.
*
* Returned Value:
* None
*
****************************************************************************/
void builtin_setlist(FAR const struct builtin_s *builtins, int count)
{
g_builtins = builtins;
g_builtin_count = count;
}
#endif /* CONFIG_BUILD_PROTECTED && __KERNEL__ */

View File

@ -0,0 +1,29 @@
############################################################################
# libs/libc/libc-musl/ctype/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Add the ctype C files to the build
CSRCS += isalnum.c isalpha.c isascii.c isblank.c
CSRCS += iscntrl.c isdigit.c isgraph.c islower.c
CSRCS += isprint.c ispunct.c isspace.c isupper.c
CSRCS += isxdigit.c tolower.c toupper.c
DEPPATH += --dep-path ctype
VPATH += :ctype

View File

@ -0,0 +1,15 @@
/**
* @file isalnum.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int isalnum(int c)
{
return isalpha(c) || isdigit(c);
}

View File

@ -0,0 +1,16 @@
/**
* @file isalpha.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isalpha
int isalpha(int c)
{
return ((unsigned)c|32)-'a' < 26;
}

View File

@ -0,0 +1,16 @@
/**
* @file isascii.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isascii
int isascii(int c)
{
return !(c&~0x7f);
}

View File

@ -0,0 +1,15 @@
/**
* @file isblank.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int isblank(int c)
{
return (c == ' ' || c == '\t');
}

View File

@ -0,0 +1,15 @@
/**
* @file iscntrl.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int iscntrl(int c)
{
return (unsigned)c < 0x20 || c == 0x7f;
}

View File

@ -0,0 +1,16 @@
/**
* @file isdigit.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isdigit
int isdigit(int c)
{
return (unsigned)c-'0' < 10;
}

View File

@ -0,0 +1,16 @@
/**
* @file isgraph.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isgraph
int isgraph(int c)
{
return (unsigned)c-0x21 < 0x5e;
}

View File

@ -0,0 +1,16 @@
/**
* @file islower.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef islower
int islower(int c)
{
return (unsigned)c-'a' < 26;
}

View File

@ -0,0 +1,16 @@
/**
* @file isprint.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isprint
int isprint(int c)
{
return (unsigned)c-0x20 < 0x5f;
}

View File

@ -0,0 +1,15 @@
/**
* @file ispunct.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int ispunct(int c)
{
return isgraph(c) && !isalnum(c);
}

View File

@ -0,0 +1,16 @@
/**
* @file isspace.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isspace
int isspace(int c)
{
return c == ' ' || (unsigned)c-'\t' < 5;
}

View File

@ -0,0 +1,16 @@
/**
* @file isupper.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
#undef isupper
int isupper(int c)
{
return (unsigned)c-'A' < 26;
}

View File

@ -0,0 +1,15 @@
/**
* @file isxdigit.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int isxdigit(int c)
{
return isdigit(c) || ((unsigned)c|32)-'a' < 6;
}

View File

@ -0,0 +1,16 @@
/**
* @file tolower.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int tolower(int c)
{
if (isupper(c)) return c | 32;
return c;
}

View File

@ -0,0 +1,16 @@
/**
* @file toupper.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <ctype.h>
int toupper(int c)
{
if (islower(c)) return c & 0x5f;
return c;
}

View File

@ -0,0 +1,29 @@
############################################################################
# libs/libc-musl/dirent/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Add the dirent C files to the build
CSRCS += lib_readdirr.c lib_telldir.c lib_alphasort.c lib_scandir.c
CSRCS += lib_ftw.c lib_nftw.c
# Add the dirent directory to the build
DEPPATH += --dep-path dirent
VPATH += :dirent

View File

@ -0,0 +1,69 @@
/****************************************************************************
* libs/libc-musl/dirent/lib_alphasort.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_alphasort.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <dirent.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: alphasort
*
* Description:
* The alphasort() function can be used as the comparison function
* compar() for scandir(). It sorts directory entries using strcoll on the
* strings (*a)->d_name and (*b)->d_name.
*
* Input Parameters:
* a - The first direntry to compare
* b - The second direntry to compare
*
* Returned Value:
* An integer less than, equal to, or greater than zero if the first
* argument is considered to be respectively less than, equal to, or
* greater than the second.
*
****************************************************************************/
int alphasort(FAR const struct dirent **a, FAR const struct dirent **b)
{
#ifdef CONFIG_LIBC_LOCALE
return strcoll((*a)->d_name, (*b)->d_name);
#else
return strcmp((*a)->d_name, (*b)->d_name);
#endif
}

View File

@ -0,0 +1,54 @@
/****************************************************************************
* libs/musl/dirent/lib_ftw.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_ftw.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <ftw.h>
/****************************************************************************
* Public Functions
****************************************************************************/
int ftw(FAR const char *path, ftw_cb_t fn, int fdlimit)
{
/* The following cast assumes that calling a function with one
* argument more than it needs behaves as expected. This is
* actually undefined, but works on all real-world machines.
*/
union
{
ftw_cb_t ftw;
nftw_cb_t nftw;
} u;
u.ftw = fn;
return nftw(path, u.nftw, fdlimit, FTW_PHYS);
}

View File

@ -0,0 +1,250 @@
/****************************************************************************
* libs/libc-musl/dirent/lib_nftw.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_nftw.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <ftw.h>
#include <dirent.h>
#include <sys/stat.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <limits.h>
#include "libc-musl.h"
/****************************************************************************
* Private Functions
****************************************************************************/
static int
call_nftw(FAR char *path, nftw_cb_t fn, int flags, int base,
int level, FAR const struct stat *buf, int info)
{
struct FTW ftw =
{
base, level
};
int r;
#ifndef CONFIG_DISABLE_ENVIRON
if (flags & FTW_CHDIR)
{
if (base > 1)
{
path[base - 1] = '\0';
r = chdir(path);
path[base - 1] = '/';
}
else
{
r = chdir("/");
}
if (r < 0)
{
return r;
}
}
#endif
r = fn(path, buf, info, &ftw);
#ifndef CONFIG_DISABLE_ENVIRON
if (flags & FTW_CHDIR)
{
lib_restoredir();
}
#endif
return r;
}
static int
do_nftw(FAR char *path, nftw_cb_t fn, int fdlimit, int flags, int level)
{
FAR DIR *dir = NULL;
struct stat buf;
size_t base;
size_t j;
int info;
int r;
j = strlen(path);
while (j > 1 && path[j - 1] == '/')
{
path[--j] = '\0';
}
base = j - 1;
while (base > 0 && path[base - 1] != '/')
{
--base;
}
r = flags & FTW_PHYS ? lstat(path, &buf) : stat(path, &buf);
if (r < 0)
{
if (!(flags & FTW_PHYS) &&
get_errno() == ENOENT && !lstat(path, &buf))
{
info = FTW_SLN;
}
else if (get_errno() == EACCES)
{
info = FTW_NS;
}
else
{
return -1;
}
}
else if (S_ISDIR(buf.st_mode))
{
if (flags & FTW_DEPTH)
{
info = FTW_DP;
}
else
{
info = FTW_D;
}
}
else if (S_ISLNK(buf.st_mode))
{
if (flags & FTW_PHYS)
{
info = FTW_SL;
}
else
{
info = FTW_SLN;
}
}
else
{
info = FTW_F;
}
if (info == FTW_D || info == FTW_DP)
{
dir = opendir(path);
if (dir)
{
if (fdlimit <= 0)
{
closedir(dir);
dir = NULL;
}
}
else if (get_errno() == EACCES)
{
info = FTW_DNR;
}
else
{
return -1;
}
}
if (!(flags & FTW_DEPTH))
{
r = call_nftw(path, fn, flags, base, level, &buf, info);
if (r)
{
return r;
}
}
if (dir)
{
FAR struct dirent *de;
size_t l = j;
if (path[j - 1] != '/')
{
path[j++] = '/';
}
while ((de = readdir(dir)))
{
if (de->d_name[0] == '.' && (!de->d_name[1] ||
(de->d_name[1] == '.' && !de->d_name[2])))
{
continue;
}
if (strlen(de->d_name) > PATH_MAX - j)
{
set_errno(ENAMETOOLONG);
closedir(dir);
return -1;
}
strcpy(path + j, de->d_name);
r = do_nftw(path, fn, fdlimit - 1, flags, level + 1);
if (r)
{
closedir(dir);
return r;
}
}
path[l] = '\0';
closedir(dir);
}
if (flags & FTW_DEPTH)
{
r = call_nftw(path, fn, flags, base, level, &buf, info);
if (r)
{
return r;
}
}
return 0;
}
/****************************************************************************
* Public Functions
****************************************************************************/
int nftw(FAR const char *path, nftw_cb_t fn, int fdlimit, int flags)
{
char pathbuf[PATH_MAX + 1];
strncpy(pathbuf, path, PATH_MAX);
pathbuf[PATH_MAX] = '\0';
return do_nftw(pathbuf, fn, fdlimit, flags, 0);
}

View File

@ -0,0 +1,117 @@
/****************************************************************************
* libs/libc-musl/dirent/lib_readdirr.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_readdirr.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <nuttx/fs/fs.h>
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: readdir_r
*
* Description:
* The readdir() function returns a pointer to a dirent
* structure representing the next directory entry in the
* directory stream pointed to by dir. It returns NULL on
* reaching the end-of-file or if an error occurred.
*
* Input Parameters:
* dirp -- An instance of type DIR created by a previous
* call to opendir();
* entry -- The storage pointed to by entry must be large
* enough for a dirent with an array of char d_name
* members containing at least {NAME_MAX}+1 elements.
* result -- Upon successful return, the pointer returned
* at *result shall have the same value as the
* argument entry. Upon reaching the end of the directory
* stream, this pointer shall have the value NULL.
*
* Returned Value:
* If successful, the readdir_r() function return s zero;
* otherwise, an error number is returned to indicate the
* error.
*
* EBADF - Invalid directory stream descriptor dir
*
****************************************************************************/
int readdir_r(FAR DIR *dirp, FAR struct dirent *entry,
FAR struct dirent **result)
{
struct dirent *tmp;
/* NOTE: The following use or errno is *not* thread-safe */
set_errno(0);
tmp = readdir(dirp);
if (!tmp)
{
int error = get_errno();
if (!error)
{
if (result)
{
*result = NULL;
}
return 0;
}
else
{
return error;
}
}
if (entry)
{
memcpy(entry, tmp, sizeof(struct dirent));
}
if (result)
{
*result = entry;
}
return 0;
}

View File

@ -0,0 +1,237 @@
/****************************************************************************
* libs/libc-musl/dirent/lib_scandir.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_scandir.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <dirent.h>
#include <errno.h>
#include <stdlib.h>
#include "libc-musl.h"
/* The scandir() function is not appropriate for use within the kernel in its
* current form because it uses user space memory allocators and modifies
* the errno value.
*/
#ifndef __KERNEL__
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: scandir
*
* Description:
* The scandir() function scans the directory dirp, calling filter() on
* each directory entry. Entries for which filter() returns nonzero are
* stored in strings allocated via malloc(), sorted using qsort() with
* comparison function compar(), and collected in array namelist which is
* allocated via malloc(). If filter is NULL, all entries are selected.
*
* Input Parameters:
* path - Pathname of the directory to scan
* namelist - An array of pointers to directory entries, which is allocated
* by scandir via malloc. Each directory entry is allocated via
* malloc as well. The caller is responsible to free said
* objects.
* filter - Directory entries for which filter returns zero are not
* included in the namelist. If filter is NULL, all entries are
* included.
* compar - Comparison function used with qsort() to sort the namelist.
*
* Returned Value:
* If successful, the scandir() function returns the number of entries in
* the namelist. Otherwise, it returns -1 and errno is set to indicate the
* error.
*
****************************************************************************/
int scandir(FAR const char *path, FAR struct dirent ***namelist,
CODE int (*filter)(FAR const struct dirent *),
CODE int (*compar)(FAR const struct dirent **,
FAR const struct dirent **))
{
FAR struct dirent *d;
FAR struct dirent *dnew;
FAR struct dirent **list = NULL;
size_t listsize = 0;
size_t cnt = 0;
int errsv;
int result;
FAR DIR *dirp;
/* This scandir implementation relies on errno being set by other service
* functions that it is calling to figure if it was successful. We save
* the original errno value to be able to restore it in case of success.
*/
errsv = get_errno();
dirp = opendir(path);
if (!dirp)
{
return -1;
}
/* opendir might have set errno. Reset to zero. */
set_errno(0);
for (d = readdir(dirp); d != NULL; d = readdir(dirp))
{
size_t dsize;
/* If the caller provided a filter function which tells scandir to skip
* the current directory entry, do so.
*/
if (filter && !filter(d))
{
continue;
}
/* The caller provided filter function might have set errno. Reset to
* zero.
*/
set_errno(0);
/* Grow the directory entry list, if required. */
if (cnt == listsize)
{
struct dirent **newlist;
if (!listsize)
{
listsize = 4;
}
else
{
listsize *= 2;
}
newlist = lib_realloc(list, listsize * sizeof(*list));
if (!newlist)
{
/* realloc failed and set errno. This will tell follow up code
* that we failed.
*/
break;
}
list = newlist;
}
/* Allocate a new directory entry, but restrict its heap size to what
* is really required given the directories' path name.
*/
dsize = (size_t)(&d->d_name[strlen(d->d_name) + 1] - (char *)d);
dnew = lib_malloc(dsize);
if (!dnew)
{
/* malloc failed and set errno. This will tell follow up code that
* we failed.
*/
break;
}
/* Copy directory entry to newly allocated one and update the list
* accordingly.
*/
memcpy(dnew, d, dsize);
list[cnt] = dnew;
cnt++;
/* Some service function might have set errno as a side effect. Reset
* to zero.
*/
set_errno(0);
}
if (get_errno() == 0)
{
/* If the caller provided a comparison function, use it to sort the
* list of directory entries.
*/
if (compar)
{
typedef int (*compar_fn_t)(FAR const void *, FAR const void *);
qsort(list, cnt, sizeof(*list), (compar_fn_t)compar);
}
/* Set the output parameters. */
*namelist = list;
result = (int)cnt;
}
else
{
size_t i;
/* Something failed along the way. Clean up. */
for (i = 0; i < cnt; i++)
{
lib_free(list[i]);
}
lib_free(list);
result = -1;
}
closedir(dirp);
if (result >= 0)
{
/* Restore original errno value in case of success. */
set_errno(errsv);
}
return result;
}
#endif /* __KERNEL__ */

View File

@ -0,0 +1,84 @@
/****************************************************************************
* libs/libc-musl/dirent/lib_telldir.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_telldir.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <nuttx/fs/fs.h>
#include <nuttx/fs/dirent.h>
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: telldir
*
* Description:
* The telldir() function returns the current location
* associated with the directory stream dirp.
*
* Input Parameters:
* dirp -- An instance of type DIR created by a previous
* call to opendir();
*
* Returned Value:
* On success, the telldir() function returns the current
* location in the directory stream. On error, -1 is
* returned, and errno is set appropriately.
*
* EBADF - Invalid directory stream descriptor dir
*
****************************************************************************/
off_t telldir(FAR DIR *dirp)
{
struct fs_dirent_s *idir = (struct fs_dirent_s *)dirp;
if (!idir || !idir->fd_root)
{
set_errno(EBADF);
return (off_t)-1;
}
/* Just return the current position */
return idir->fd_position;
}

View File

@ -0,0 +1,32 @@
############################################################################
# libs/libc-musl/dlfcn/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_LIBC_DLFCN),y)
# Add the dlfcn.h files to the build
CSRCS += lib_dlopen.c lib_dlclose.c lib_dlsym.c lib_dlerror.c lib_dlsymtab.c
# Add the dlfcn.h directory to the build
DEPPATH += --dep-path dlfcn
VPATH += :dlfcn
endif

View File

@ -0,0 +1,261 @@
/****************************************************************************
* libs/libc-musl/dlfcn/lib_dlclose.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_dlclose.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dlfcn.h>
#include <assert.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/module.h>
#include <nuttx/lib/modlib.h>
#include "libc-musl.h"
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: dlremove
*
* Description:
* Remove a previously installed shared library from memory.
*
* Input Parameters:
* handle - The shared library handle previously returned by dlopen().
*
* Returned Value:
* Zero (OK) on success. On any failure, -1 (ERROR) is returned the
* errno value is set appropriately.
*
****************************************************************************/
#ifdef CONFIG_BUILD_PROTECTED
static inline int dlremove(FAR void *handle)
{
FAR struct module_s *modp = (FAR struct module_s *)handle;
int ret;
DEBUGASSERT(modp != NULL);
/* Get exclusive access to the module registry */
modlib_registry_lock();
/* Verify that the module is in the registry */
ret = modlib_registry_verify(modp);
if (ret < 0)
{
serr("ERROR: Failed to verify module: %d\n", ret);
goto errout_with_lock;
}
#if CONFIG_MODLIB_MAXDEPEND > 0
/* Refuse to remove any module that other modules may depend upon. */
if (modp->dependents > 0)
{
serr("ERROR: Module has dependents: %d\n", modp->dependents);
ret = -EBUSY;
goto errout_with_lock;
}
#endif
/* Is there an uninitializer? */
if (modp->modinfo.uninitializer != NULL)
{
/* Try to uninitialize the module */
ret = modp->modinfo.uninitializer(modp->modinfo.arg);
/* Did the module successfully uninitialize? */
if (ret < 0)
{
serr("ERROR: Failed to uninitialize the module: %d\n", ret);
goto errout_with_lock;
}
/* Nullify so that the uninitializer cannot be called again */
modp->modinfo.uninitializer = NULL;
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
modp->initializer = NULL;
modp->modinfo.arg = NULL;
modp->modinfo.exports = NULL;
modp->modinfo.nexports = 0;
#endif
}
/* Release resources held by the module */
if (modp->textalloc != NULL)
{
/* Free the module memory */
lib_free((FAR void *)modp->textalloc);
/* Nullify so that the memory cannot be freed again */
modp->textalloc = NULL;
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
modp->textsize = 0;
#endif
}
if (modp->dataalloc != NULL)
{
/* Free the module memory */
lib_free((FAR void *)modp->dataalloc);
/* Nullify so that the memory cannot be freed again */
modp->dataalloc = NULL;
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
modp->datasize = 0;
#endif
}
/* Remove the module from the registry */
ret = modlib_registry_del(modp);
if (ret < 0)
{
serr("ERROR: Failed to remove the module from the registry: %d\n",
ret);
goto errout_with_lock;
}
#if CONFIG_MODLIB_MAXDEPEND > 0
/* Eliminate any dependencies that this module has on other modules */
modlib_undepend(modp);
#endif
modlib_registry_unlock();
/* And free the registry entry */
lib_free(modp);
return OK;
errout_with_lock:
modlib_registry_unlock();
set_errno(-ret);
return ERROR;
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: dlclose
*
* Description:
* dlclose() is used to inform the system that the object referenced by a
* handle returned from a previous dlopen() invocation is no longer needed
* by the application.
*
* The use of dlclose() reflects a statement of intent on the part of the
* process, but does not create any requirement upon the implementation,
* such as removal of the code or symbols referenced by handle. Once an
* object has been closed using dlclose() an application should assume
* that its symbols are no longer available to dlsym(). All objects loaded
* automatically as a result of invoking dlopen() on the referenced object
* are also closed.
*
* Although a dlclose() operation is not required to remove structures
* from an address space, neither is an implementation prohibited from
* doing so. The only restriction on such a removal is that no object will
* be removed to which references have been relocated, until or unless all
* such references are removed. For instance, an object that had been
* loaded with a dlopen() operation specifying the RTLD_GLOBAL flag might
* provide a target for dynamic relocations performed in the processing of
* other objects - in such environments, an application may assume that no
* relocation, once made, will be undone or remade unless the object
* requiring the relocation has itself been removed.
*
* Input Parameters:
* handle - The opaque, non-NULL value returned by a previous successful
* call to dlopen().
*
* Returned Value:
* If the referenced object was successfully closed, dlclose() returns 0.
* If the object could not be closed, or if handle does not refer to an
* open object, dlclose() returns a non-zero value. More detailed
* diagnostic information will be available through dlerror().
*
* Reference: OpenGroup.org
*
****************************************************************************/
int dlclose(FAR void *handle)
{
#if defined(CONFIG_BUILD_FLAT)
/* In the FLAT build, a shared library is essentially the same as a kernel
* module.
*/
return rmmod(handle);
#elif defined(CONFIG_BUILD_PROTECTED)
/* The PROTECTED build is equivalent to the FLAT build EXCEPT that there
* must be two copies of the module logic: One residing in kernel
* space and using the kernel symbol table and one residing in user space
* using the user space symbol table.
*
* dlremove() is essentially a clone of rmmod().
*/
return dlremove(handle);
#else /* if defined(CONFIG_BUILD_KERNEL) */
/* The KERNEL build is considerably more complex: In order to be shared,
* the .text portion of the module must be (1) build for PIC/PID operation
* and (2) must like in a shared memory region accessible from all
* processes. The .data/.bss portion of the module must be allocated in
* the user space of each process, but must lie at the same virtual address
* so that it can be referenced from the one copy of the text in the shared
* memory region.
*/
#warning Missing logic
return -ENOSYS;
#endif
}

View File

@ -0,0 +1,68 @@
/****************************************************************************
* libs/libc-musl/dlfcn/lib_dlerror.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_dlerror.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <errno.h>
#include <dlfcn.h>
#include <string.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: dlerror
*
* Description:
* dlerror() returns a null-terminated character string (with no trailing
* newline) that describes the last error that occurred during dynamic
* linking processing. If no dynamic linking errors have occurred since
* the last invocation of dlerror(), dlerror() returns NULL. Thus,
* invoking dlerror() a second time, immediately following a prior
* invocation, will result in NULL being returned.
*
* Input Parameters:
* If successful, dlerror() returns a null-terminated character string.
* Otherwise, NULL is returned.
*
* Returned Value:
*
* Reference: OpenGroup.org
*
****************************************************************************/
FAR char *dlerror(void)
{
return (FAR char *)strerror(get_errno());
}

View File

@ -0,0 +1,474 @@
/****************************************************************************
* libs/libc-musl/dlfcn/lib_dlopen.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_dlopen.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <dlfcn.h>
#include <assert.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/envpath.h>
#include <nuttx/module.h>
#include <nuttx/lib/modlib.h>
#include "libc-musl.h"
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: dldump_loadinfo
****************************************************************************/
#ifdef CONFIG_BUILD_PROTECTED
#if defined(CONFIG_DEBUG_INFO) && defined(CONFIG_DEBUG_BINFMT)
static void dldump_loadinfo(FAR struct mod_loadinfo_s *loadinfo)
{
int i;
binfo("LOAD_INFO:\n");
binfo(" textalloc: %08lx\n", (long)loadinfo->textalloc);
binfo(" datastart: %08lx\n", (long)loadinfo->datastart);
binfo(" textsize: %ld\n", (long)loadinfo->textsize);
binfo(" datasize: %ld\n", (long)loadinfo->datasize);
binfo(" filelen: %ld\n", (long)loadinfo->filelen);
binfo(" filfd: %d\n", loadinfo->filfd);
binfo(" symtabidx: %d\n", loadinfo->symtabidx);
binfo(" strtabidx: %d\n", loadinfo->strtabidx);
binfo("ELF Header:\n");
binfo(" e_ident: %02x %02x %02x %02x\n",
loadinfo->ehdr.e_ident[0], loadinfo->ehdr.e_ident[1],
loadinfo->ehdr.e_ident[2], loadinfo->ehdr.e_ident[3]);
binfo(" e_type: %04x\n", loadinfo->ehdr.e_type);
binfo(" e_machine: %04x\n", loadinfo->ehdr.e_machine);
binfo(" e_version: %08x\n", loadinfo->ehdr.e_version);
binfo(" e_entry: %08lx\n", (long)loadinfo->ehdr.e_entry);
binfo(" e_phoff: %d\n", loadinfo->ehdr.e_phoff);
binfo(" e_shoff: %d\n", loadinfo->ehdr.e_shoff);
binfo(" e_flags: %08x\n" , loadinfo->ehdr.e_flags);
binfo(" e_ehsize: %d\n", loadinfo->ehdr.e_ehsize);
binfo(" e_phentsize: %d\n", loadinfo->ehdr.e_phentsize);
binfo(" e_phnum: %d\n", loadinfo->ehdr.e_phnum);
binfo(" e_shentsize: %d\n", loadinfo->ehdr.e_shentsize);
binfo(" e_shnum: %d\n", loadinfo->ehdr.e_shnum);
binfo(" e_shstrndx: %d\n", loadinfo->ehdr.e_shstrndx);
if (loadinfo->shdr && loadinfo->ehdr.e_shnum > 0)
{
for (i = 0; i < loadinfo->ehdr.e_shnum; i++)
{
FAR Elf_Shdr *shdr = &loadinfo->shdr[i];
binfo("Sections %d:\n", i);
binfo(" sh_name: %08x\n", shdr->sh_name);
binfo(" sh_type: %08x\n", shdr->sh_type);
binfo(" sh_flags: %08x\n", shdr->sh_flags);
binfo(" sh_addr: %08x\n", shdr->sh_addr);
binfo(" sh_offset: %d\n", shdr->sh_offset);
binfo(" sh_size: %d\n", shdr->sh_size);
binfo(" sh_link: %d\n", shdr->sh_link);
binfo(" sh_info: %d\n", shdr->sh_info);
binfo(" sh_addralign: %d\n", shdr->sh_addralign);
binfo(" sh_entsize: %d\n", shdr->sh_entsize);
}
}
}
#else
# define dldump_loadinfo(i)
#endif
#endif
/****************************************************************************
* Name: dldump_initializer
****************************************************************************/
#ifdef CONFIG_BUILD_PROTECTED
#ifdef CONFIG_MODLIB_DUMPBUFFER
static void dldump_initializer(mod_initializer_t initializer,
FAR struct mod_loadinfo_s *loadinfo)
{
modlib_dumpbuffer("Initializer code", (FAR const uint8_t *)initializer,
MIN(loadinfo->textsize - loadinfo->ehdr.e_entry, 512));
}
#else
# define dldump_initializer(b,l)
#endif
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: dlinsert
*
* Description:
* Verify that the file is an ELF module binary and, if so, load the
* shared library into user memory and initialize it for use.
*
* NOTE: modlib_setsymtab() had to have been called by application logic
* logic prior to calling this. Otherwise, dlinsert will be unable to
* resolve symbols in the OS module.
*
* Input Parameters:
* filename - Full path to the shared library file to be loaded
*
* Returned Value:
* A non-NULL module handle that can be used on subsequent calls to other
* shared library interfaces is returned on success. If insmod() was
* unable to load the module insmod() will return a NULL handle and the
* errno variable will be set appropriately.
*
****************************************************************************/
#ifdef CONFIG_BUILD_PROTECTED
/* The PROTECTED build is equivalent to the FLAT build EXCEPT that there
* must be two copies of the module logic: One residing in kernel
* space and using the kernel symbol table and one residing in user space
* using the user space symbol table.
*
* dlinsert() is essentially a clone of insmod().
*/
static inline FAR void *dlinsert(FAR const char *filename)
{
struct mod_loadinfo_s loadinfo;
FAR struct module_s *modp;
mod_initializer_t initializer;
int ret;
binfo("Loading file: %s\n", filename);
/* Get exclusive access to the module registry */
modlib_registry_lock();
/* Initialize the ELF library to load the program binary. */
ret = modlib_initialize(filename, &loadinfo);
dldump_loadinfo(&loadinfo);
if (ret != 0)
{
serr("ERROR: Failed to initialize to load module: %d\n", ret);
goto errout_with_lock;
}
/* Allocate a module registry entry to hold the module data */
modp = (FAR struct module_s *)lib_zalloc(sizeof(struct module_s));
if (ret != 0)
{
binfo("Failed to initialize for load of ELF program: %d\n", ret);
goto errout_with_loadinfo;
}
/* Load the program binary */
ret = modlib_load(&loadinfo);
dldump_loadinfo(&loadinfo);
if (ret != 0)
{
binfo("Failed to load ELF program binary: %d\n", ret);
goto errout_with_registry_entry;
}
/* Bind the program to the kernel symbol table */
ret = modlib_bind(modp, &loadinfo);
if (ret != 0)
{
binfo("Failed to bind symbols program binary: %d\n", ret);
goto errout_with_load;
}
/* Save the load information */
modp->textalloc = (FAR void *)loadinfo.textalloc;
modp->dataalloc = (FAR void *)loadinfo.datastart;
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
modp->textsize = loadinfo.textsize;
modp->datasize = loadinfo.datasize;
#endif
/* Get the module initializer entry point */
initializer = (mod_initializer_t)(loadinfo.textalloc +
loadinfo.ehdr.e_entry);
#if defined(CONFIG_FS_PROCFS) && !defined(CONFIG_FS_PROCFS_EXCLUDE_MODULE)
modp->initializer = initializer;
#endif
dldump_initializer(initializer, &loadinfo);
/* Call the module initializer */
ret = initializer(&modp->modinfo);
if (ret < 0)
{
binfo("Failed to initialize the module: %d\n", ret);
goto errout_with_load;
}
/* Add the new module entry to the registry */
modlib_registry_add(modp);
modlib_uninitialize(&loadinfo);
modlib_registry_unlock();
return (FAR void *)modp;
errout_with_load:
modlib_unload(&loadinfo);
modlib_undepend(modp);
errout_with_registry_entry:
lib_free(modp);
errout_with_loadinfo:
modlib_uninitialize(&loadinfo);
errout_with_lock:
modlib_registry_unlock();
set_errno(-ret);
return NULL;
}
#elif defined(CONFIG_BUILD_FLAT)
/* In the FLAT build, a shared library is essentially the same as a kernel
* module.
*
* REVISIT: Missing functionality:
* - No automatic binding of symbols
* - No dependencies
* - mode is ignored.
*/
static inline FAR void *dlinsert(FAR const char *filename)
{
FAR void *handle;
FAR char *name;
DEBUGASSERT(filename != NULL);
name = strdup(filename);
if (name == NULL)
{
return NULL;
}
/* Then install the file using the basename of the file as the module
* name.
*/
handle = insmod(filename, basename(name));
lib_free(name);
return handle;
}
#else /* if defined(CONFIG_BUILD_KERNEL) */
/* The KERNEL build is considerably more complex: In order to be shared,
* the .text portion of the module must be (1) build for PIC/PID operation
* and (2) must like in a shared memory region accessible from all
* processes. The .data/.bss portion of the module must be allocated in
* the user space of each process, but must lie at the same virtual address
* so that it can be referenced from the one copy of the text in the shared
* memory region.
*/
static inline FAR void *dlinsert(FAR const char *filename)
{
#warning Missing logic
return NULL;
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: dlopen
*
* Description:
* dlopen() makes an executable object file specified by file available to
* the calling program. The class of files eligible for this operation and
* the manner of their construction are specified by the implementation,
* though typically such files are executable objects such as shared
* libraries, relocatable files or programs. Note that some implementations
* permit the construction of dependencies between such objects that are
* embedded within files. In such cases, a dlopen() operation will load
* such dependencies in addition to the object referenced by file.
* Implementations may also impose specific constraints on the construction
* of programs that can employ dlopen() and its related services.
*
* If a file is specified in multiple dlopen() invocations, mode is
* interpreted at each invocation. Note, however, that once RTLD_NOW has
* been specified all relocations will have been completed rendering
* further RTLD_NOW operations redundant and any further RTLD_LAZY
* operations irrelevant. Similarly note that once RTLD_GLOBAL has been
* specified the object will maintain the RTLD_GLOBAL status regardless
* of any previous or future specification of RTLD_LOCAL, so long as the
* object remains in the address space (see dlclose()).
*
* Symbols introduced into a program through calls to dlopen() may be
* used in relocation activities. Symbols so introduced may duplicate
* symbols already defined by the program or previous dlopen()
* operations. To resolve the ambiguities such a situation might
* present, the resolution of a symbol reference to symbol definition is
* based on a symbol resolution order. Two such resolution orders are
* defined: load or dependency ordering. Load order establishes an
* ordering among symbol definitions, such that the definition first
* loaded (including definitions from the image file and any dependent
* objects loaded with it) has priority over objects added later (via
* dlopen()). Load ordering is used in relocation processing. Dependency
* ordering uses a breadth-first order starting with a given object,
* then all of its dependencies, then any dependents of those, iterating
* until all dependencies are satisfied. With the exception of the global
* symbol object obtained via a dlopen() operation on a file of 0,
* dependency ordering is used by the dlsym() function. Load ordering is
* used in dlsym() operations upon the global symbol object.
*
* When an object is first made accessible via dlopen() it and its
* dependent objects are added in dependency order. Once all the objects
* are added, relocations are performed using load order. Note that if an
* object or its dependencies had been previously loaded, the load and
* dependency orders may yield different resolutions.
*
* The symbols introduced by dlopen() operations, and available through
* dlsym() are at a minimum those which are exported as symbols of global
* scope by the object. Typically such symbols will be those that were
* specified in (for example) C source code as having extern linkage. The
* precise manner in which an implementation constructs the set of
* exported symbols for a dlopen() object is specified by that
* implementation.
*
* Input Parameters:
* file - Used to construct a pathname to the object file. If file
* contains a slash character, the file argument is used as the
* pathname for the file. Otherwise, file is used in an
* implementation-dependent manner to yield a pathname.
*
* If the value of file is 0, dlopen() provides a handle on a
* global symbol object. This object provides access to the symbols
* from an ordered set of objects consisting of the original
* program image file, together with any objects loaded at program
* startup as specified by that process image file (for example,
* shared libraries), and the set of objects loaded using a
* dlopen() operation together with the RTLD_GLOBAL flag. As the
* latter set of objects can change during execution, the set
* identified by handle can also change dynamically.
*
* Only a single copy of an object file is brought into the address
* space, even if dlopen() is invoked multiple times in reference
* to the file, and even if different pathnames are used to
* reference the file.
* mode - Describes how dlopen() will operate upon file with respect to
* the processing of relocations and the scope of visibility of the
* symbols provided within file. When an object is brought into the
* address space of a process, it may contain references to symbols
* whose addresses are not known until the object is loaded. These
* references must be relocated before the symbols can be accessed.
* The mode parameter governs when these relocations take place.
* See definitions above for values of the mode parameter:.
*
* Returned Value:
* A successful dlopen() returns a handle which the caller may use on
* subsequent calls to dlsym() and dlclose(). The value of this handle
* should not be interpreted in any way by the caller.
*
* If file cannot be found, cannot be opened for reading, is not of an
* appropriate object format for processing by dlopen(), or if an error
* occurs during the process of loading file or relocating its symbolic
* references, dlopen() will return NULL. More detailed diagnostic
* information will be available through dlerror().
*
* Reference: OpenGroup.org
*
****************************************************************************/
FAR void *dlopen(FAR const char *file, int mode)
{
FAR void *handle = NULL;
#ifdef CONFIG_LIBC_ENVPATH
if (file[0] != '/')
{
FAR const char *relpath;
FAR char *fullpath;
ENVPATH_HANDLE env;
/* Set aside the relative path */
relpath = file;
/* Initialize to traverse the LD_LIBRARY_PATH variable */
env = envpath_init("LD_LIBRARY_PATH");
if (env)
{
/* Get the next absolute file path */
while ((fullpath = envpath_next(env, relpath)) != NULL)
{
/* Try to load the file at this path */
handle = dlinsert(fullpath);
/* Free the allocated fullpath */
lib_free(fullpath);
/* Break out of the loop with handle != NULL on success */
if (handle != NULL)
{
break;
}
}
/* Release the traversal handle */
envpath_release(env);
}
}
else
#endif
{
/* We already have the one and only absolute path to the file to
* be loaded.
*/
handle = dlinsert(file);
}
return handle;
}

View File

@ -0,0 +1,186 @@
/****************************************************************************
* libs/libc-musl/dlfcn/lib_dlsym.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_dlsym.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dlfcn.h>
#include <assert.h>
#include <debug.h>
#include <errno.h>
#include <nuttx/module.h>
#include <nuttx/symtab.h>
#include <nuttx/lib/modlib.h>
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: dlgetsym
*
* Description:
* dlgetsym() implements dlsym() for the PROTECTED build.
*
* Input Parameters:
* handle - The opaque, non-NULL value returned by a previous successful
* call to insmod().
* name - A pointer to the symbol name string.
*
* Returned Value:
* See dlsym().
*
****************************************************************************/
#ifdef CONFIG_BUILD_PROTECTED
static inline FAR const void *dlgetsym(FAR void *handle,
FAR const char *name)
{
FAR struct module_s *modp = (FAR struct module_s *)handle;
FAR const struct symtab_s *symbol;
int err;
int ret;
/* Verify that the module is in the registry */
modlib_registry_lock();
ret = modlib_registry_verify(modp);
if (ret < 0)
{
serr("ERROR: Failed to verify module: %d\n", ret);
err = -ret;
goto errout_with_lock;
}
/* Does the module have a symbol table? */
if (modp->modinfo.exports == NULL || modp->modinfo.nexports == 0)
{
serr("ERROR: Module has no symbol table\n");
err = ENOENT;
goto errout_with_lock;
}
/* Search the symbol table for the matching symbol */
symbol = symtab_findbyname(modp->modinfo.exports, name,
modp->modinfo.nexports);
if (symbol == NULL)
{
serr("ERROR: Failed to find symbol in symbol \"%s\" in table\n", name);
err = ENOENT;
goto errout_with_lock;
}
/* Return the address within the module associated with the symbol */
modlib_registry_unlock();
DEBUGASSERT(symbol->sym_value != NULL);
return symbol->sym_value;
errout_with_lock:
modlib_registry_unlock();
set_errno(err);
return NULL;
}
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: dlsym
*
* Description:
* dlsym() allows a process to obtain the address of a symbol defined
* within an object made accessible through a dlopen() call. handle is the
* value returned from a call to dlopen() (and which has not since been
* released via a call to dlclose()), name is the symbol's name as a
* character string.
*
* dlsym() will search for the named symbol in all objects loaded
* automatically as a result of loading the object referenced by handle
* (see dlopen()). Load ordering is used in dlsym() operations upon the
* global symbol object. The symbol resolution algorithm used will be
* dependency order as described in dlopen().
*
* Input Parameters:
* handle - The opaque, non-NULL value returned by a previous successful
* call to dlopen().
* name - A pointer to the symbol name string.
*
* Returned Value:
* If handle does not refer to a valid object opened by dlopen(), or if
* the named symbol cannot be found within any of the objects associated
* with handle, dlsym() will return NULL. More detailed diagnostic
* information will be available through dlerror().
*
* Reference: OpenGroup.org
*
****************************************************************************/
FAR void *dlsym(FAR void *handle, FAR const char *name)
{
#if defined(CONFIG_BUILD_FLAT)
/* In the FLAT build, a shared library is essentially the same as a kernel
* module.
*/
return (FAR void *)modsym(handle, name);
#elif defined(CONFIG_BUILD_PROTECTED)
/* The PROTECTED build is equivalent to the FLAT build EXCEPT that there
* must be two copies of the module logic: One residing in kernel
* space and using the kernel symbol table and one residing in user space
* using the user space symbol table.
*
* dlgetsem() is essentially a clone of modsym().
*/
return (FAR void *)dlgetsym(handle, name);
#else /* if defined(CONFIG_BUILD_KERNEL) */
/* The KERNEL build is considerably more complex: In order to be shared,
* the .text portion of the module must be (1) build for PIC/PID operation
* and (2) must like in a shared memory region accessible from all
* processes. The .data/.bss portion of the module must be allocated in
* the user space of each process, but must lie at the same virtual address
* so that it can be referenced from the one copy of the text in the shared
* memory region.
*/
#warning Missing logic
return NULL;
#endif
}

View File

@ -0,0 +1,86 @@
/****************************************************************************
* libs/libc-musl/dlfcn/lib_dlsymtab.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_dlsymtab.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <dlfcn.h>
#include <errno.h>
#include <nuttx/module.h>
#include <nuttx/lib/modlib.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: dlsymtab
*
* Description:
* dlsymtab() is a non-standard shared library interface. It selects the
* symbol table to use when binding a shared library to the base firmware
* which may be in FLASH memory.
*
* Input Parameters:
* symtab - The new symbol table.
* nsymbols - The number of symbols in the symbol table.
*
* Returned Value:
* Always returns OK.
*
****************************************************************************/
int dlsymtab(FAR const struct symtab_s *symtab, int nsymbols)
{
#ifdef CONFIG_BUILD_KERNEL
/* The KERNEL build is considerably more complex: In order to be shared,
* the .text portion of the module must be (1) build for PIC/PID operation
* and (2) must like in a shared memory region accessible from all
* processes. The .data/.bss portion of the module must be allocated in
* the user space of each process, but must lie at the same virtual address
* so that it can be referenced from the one copy of the text in the shared
* memory region.
*/
#warning Missing logic
return -ENOSYS;
#else
/* Set the symbol take information that will be used by this instance of
* the module library.
*/
modlib_setsymtab(symtab, nsymbols);
return OK;
#endif
}

View File

@ -0,0 +1,28 @@
############################################################################
# libs/libc-musl/endian/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Add the endian.h C files to the build
CSRCS += swap16.c swap32.c swap64.c
# Add the endian directory to the build
DEPPATH += --dep-path endian
VPATH += :endian

View File

@ -0,0 +1,22 @@
/**
* @file swap16.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <stdint.h>
#include <endian.h>
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef __SWAP_UINT16_ISMACRO
uint16_t __swap_uint16(uint16_t n)
{
return n<<8 | n>>8;
}
#endif

View File

@ -0,0 +1,22 @@
/**
* @file swap32.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <stdint.h>
#include <endian.h>
/****************************************************************************
* Public Functions
****************************************************************************/
#ifndef __SWAP_UINT32_ISMACRO
uint32_t __swap_uint32(uint32_t n)
{
return (n>>24) | (n>>8&0xff00) | (n<<8&0xff0000) | (n<<24);
}
#endif

View File

@ -0,0 +1,24 @@
/**
* @file swap64.c
* @brief musl source code
* https://github.com/bminor/musl.git
* @version 1.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#include <nuttx/compiler.h>
#include <stdint.h>
#include <endian.h>
/****************************************************************************
* Public Functions
****************************************************************************/
#ifdef CONFIG_HAVE_LONG_LONG
uint64_t __swap_uint64(uint64_t n)
{
return (__swap_uint32(n)+ (0ULL<<32)) | __swap_uint32(n>>32);
}
#endif

View File

@ -0,0 +1,26 @@
############################################################################
# libs/libc-musl/errno/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
CSRCS += lib_errno.c
# Include errno build support
DEPPATH += --dep-path errno
VPATH += :errno

View File

@ -0,0 +1,74 @@
/****************************************************************************
* libs/libc-musl/errno/lib_errno.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_errno.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/arch.h>
#include <nuttx/tls.h>
/****************************************************************************
* Private Data
****************************************************************************/
static int g_errno;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: __errno
*
* Description:
* Return a pointer to the thread specific errno.
*
* Input Parameters:
* None
*
* Returned Value:
* A pointer to the per-thread errno variable.
*
* Assumptions:
*
****************************************************************************/
FAR int *__errno(void)
{
/* Get the TLS tls_info_s structure instance for this thread */
FAR struct tls_info_s *tlsinfo = up_tls_info();
/* And return the return refernce to the error number */
return tlsinfo ? &tlsinfo->tl_errno : &g_errno;
}

View File

@ -0,0 +1,27 @@
############################################################################
# libs/libc-musl/eventfd/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_EVENT_FD),y)
CSRCS += lib_eventfd.c
DEPPATH += --dep-path eventfd
VPATH += :eventfd
endif

View File

@ -0,0 +1,51 @@
/****************************************************************************
* libs/libc-musl/eventfd/lib_eventfd.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_eventfd.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <sys/eventfd.h>
#include <sys/ioctl.h>
#include <unistd.h>
/****************************************************************************
* Public Functions
****************************************************************************/
int eventfd_read(int fd, FAR eventfd_t *value)
{
return read(fd, value, sizeof (eventfd_t)) != sizeof (eventfd_t) ? -1 : 0;
}
int eventfd_write(int fd, eventfd_t value)
{
return write(fd, &value,
sizeof (eventfd_t)) != sizeof (eventfd_t) ? -1 : 0;
}

View File

@ -0,0 +1,29 @@
############################################################################
# libs/libc-musl/fixedmath/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Add the fixed precision math C files to the build
CSRCS += lib_fixedmath.c lib_b16sin.c lib_b16cos.c lib_b16atan2.c
CSRCS += lib_ubsqrt.c
# Add the fixed precision math directory to the build
DEPPATH += --dep-path fixedmath
VPATH += :fixedmath

View File

@ -0,0 +1,102 @@
/****************************************************************************
* libs/libc-musl/fixedmath/lib_b16atan2.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_b16atan2.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <fixedmath.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define B16_C1 0x00000373 /* 0.013480470 */
#define B16_C2 0x00000eb7 /* 0.057477314 */
#define B16_C3 0x00001f0a /* 0.121239071 */
#define B16_C4 0x00003215 /* 0.195635925 */
#define B16_C5 0x0000553f /* 0.332994597 */
#define B16_C6 0x00010000 /* 0.999995630 */
#define B16_HALFPI 0x00019220 /* 1.570796327 */
#define B16_PI 0x00032440 /* 3.141592654 */
#ifndef MAX
# define MAX(a,b) (a > b ? a : b)
#endif
#ifndef MIN
# define MIN(a,b) (a < b ? a : b)
#endif
#ifndef ABS
# define ABS(a) (a < 0 ? -a : a)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: b16atan2
*
* Description:
* atan2 calculates the arctangent of y/x. (Based on a algorithm I saw
* posted on the internet... now I have lost the link -- sorry).
*
****************************************************************************/
b16_t b16atan2(b16_t y, b16_t x)
{
b16_t t0;
b16_t t1;
b16_t t2;
b16_t t3;
t2 = ABS(x);
t1 = ABS(y);
t0 = MAX(t2, t1);
t1 = MIN(t2, t1);
t2 = ub16inv(t0);
t2 = b16mulb16(t1, t2);
t3 = b16mulb16(t2, t2);
t0 = - B16_C1;
t0 = b16mulb16(t0, t3) + B16_C2;
t0 = b16mulb16(t0, t3) - B16_C3;
t0 = b16mulb16(t0, t3) + B16_C4;
t0 = b16mulb16(t0, t3) - B16_C5;
t0 = b16mulb16(t0, t3) + B16_C6;
t2 = b16mulb16(t0, t2);
t2 = (ABS(y) > ABS(x)) ? B16_HALFPI - t2 : t2;
t2 = (x < 0) ? B16_PI - t2 : t2;
t2 = (y < 0) ? -t2 : t2;
return t2;
}

View File

@ -0,0 +1,59 @@
/****************************************************************************
* libs/libc-musl/fixedmath/lib_b16cos.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_b16cos.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <fixedmath.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: b16cos
****************************************************************************/
b16_t b16cos(b16_t rad)
{
/* Compute cosine: sin(rad + PI/2) = cos(rad) */
rad += b16HALFPI;
if (rad > b16PI)
{
rad -= b16TWOPI;
}
return b16sin(rad);
}

View File

@ -0,0 +1,104 @@
/****************************************************************************
* libs/libc-musl/fixedmath/lib_b16sin.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_b16sin.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <fixedmath.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define b16_P225 0x0000399a
#define b16_P405284735 0x000067c1
#define b16_1P27323954 0x000145f3
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: b16sin
* Ref:
* lab.polygonal.de/2007/07/18/fast-and-accurate-sinecosine-approximation/
****************************************************************************/
b16_t b16sin(b16_t rad)
{
b16_t tmp1;
b16_t tmp2;
b16_t tmp3;
/* Force angle into the good range */
if (rad < -b16PI)
{
rad += b16TWOPI;
}
else if (rad > b16PI)
{
rad -= b16TWOPI;
}
/* tmp1 = 1.27323954 * rad
* tmp2 = .405284735 * rad * rad
*/
tmp1 = b16mulb16(b16_1P27323954, rad);
tmp2 = b16mulb16(b16_P405284735, b16sqr(rad));
if (rad < 0)
{
/* tmp3 = 1.27323954 * rad + .405284735 * rad * rad */
tmp3 = tmp1 + tmp2;
}
else
{
/* tmp3 = 1.27323954 * rad - 0.405284735 * rad * rad */
tmp3 = tmp1 - tmp2;
}
/* tmp1 = tmp3*tmp3 */
tmp1 = b16sqr(tmp3);
if (tmp3 < 0)
{
/* tmp1 = tmp3 * -tmp3 */
tmp1 = -tmp1;
}
/* Return sin = .225 * (tmp3 * (+/-tmp3) - tmp3) + tmp3 */
return b16mulb16(b16_P225, (tmp1 - tmp3)) + tmp3;
}

View File

@ -0,0 +1,268 @@
/****************************************************************************
* libs/libc-musl/fixedmath/lib_fixedmath.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_fixedmath.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <fixedmath.h>
#ifndef CONFIG_HAVE_LONG_LONG
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Type Declarations
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Name: fixsign
****************************************************************************/
static void fixsign(b16_t *parg1, b16_t *parg2, bool *pnegate)
{
bool negate = false;
b16_t arg;
arg = *parg1;
if (arg < 0)
{
*parg1 = -arg;
negate = true;
}
arg = *parg2;
if (arg < 0)
{
*parg2 = -arg;
negate ^= true;
}
*pnegate = negate;
}
/****************************************************************************
* Name: adjustsign
****************************************************************************/
static b16_t adjustsign(b16_t result, bool negate)
{
/* If the product is negative, then we overflowed */
if (result < 0)
{
if (result)
{
return b16MIN;
}
else
{
return b16MAX;
}
}
/* correct the sign of the result */
if (negate)
{
return -result;
}
return result;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: b16mulb16
****************************************************************************/
b16_t b16mulb16(b16_t m1, b16_t m2)
{
bool negate;
b16_t product;
fixsign(&m1, &m2, &negate);
product = (b16_t)ub16mulub16((ub16_t)m1, (ub16_t)m2);
return adjustsign(product, negate);
}
/****************************************************************************
* Name: ub16mulub16
****************************************************************************/
ub16_t ub16mulub16(ub16_t m1, ub16_t m2)
{
/* Let:
*
* m1 = m1i*2**16 + m1f (b16)
* m2 = m2i*2**16 + m2f (b16)
*
* Then:
*
* m1*m2 = (m1i*m2i)*2**32 + (m1i*m2f + m2i*m1f)*2**16 + m1f*m2f (b32)
* = (m1i*m2i)*2**16 + (m1i*m2f + m2i*m1f) + m1f*m2f*2**-16 (b16)
* = a*2**16 + b + c*2**-16
*/
uint32_t m1i = ((uint32_t)m1 >> 16);
uint32_t m2i = ((uint32_t)m1 >> 16);
uint32_t m1f = ((uint32_t)m1 & 0x0000ffff);
uint32_t m2f = ((uint32_t)m2 & 0x0000ffff);
return (m1i*m2i << 16) + m1i*m2f + m2i*m1f + (((m1f*m2f) + b16HALF) >> 16);
}
/****************************************************************************
* Name: b16sqr
****************************************************************************/
b16_t b16sqr(b16_t a)
{
b16_t sq;
/* The result is always positive. Just take the absolute value */
if (a < 0)
{
a = -a;
}
/* Overflow occurred if the result is negative */
sq = (b16_t)ub16sqr(a);
if (sq < 0)
{
sq = b16MAX;
}
return sq;
}
/****************************************************************************
* Name: b16divb16
****************************************************************************/
ub16_t ub16sqr(ub16_t a)
{
/* Let:
*
* m = mi*2**16 + mf (b16)
*
* Then:
*
* m*m = (mi*mi)*2**32 + 2*(m1*m2)*2**16 + mf*mf (b32)
* = (mi*mi)*2**16 + 2*(mi*mf) + mf*mf*2**-16 (b16)
*/
uint32_t mi = ((uint32_t)a >> 16);
uint32_t mf = ((uint32_t)a & 0x0000ffff);
return (mi*mi << 16) + (mi*mf << 1) + ((mf*mf + b16HALF) >> 16);
}
/****************************************************************************
* Name: b16divb16
****************************************************************************/
b16_t b16divb16(b16_t num, b16_t denom)
{
bool negate;
b16_t quotient;
fixsign(&num, &denom, &negate);
quotient = (b16_t)ub16divub16((ub16_t)num, (ub16_t)denom);
return adjustsign(quotient, negate);
}
/****************************************************************************
* Name: ub16divub16
****************************************************************************/
ub16_t ub16divub16(ub16_t num, ub16_t denom)
{
uint32_t term1;
uint32_t numf;
uint32_t product;
/* Let:
*
* num = numi*2**16 + numf (b16)
* den = deni*2**16 + denf (b16)
*
* Then:
*
* num/den = numi*2**16 / den + numf / den (b0)
* = numi*2**32 / den + numf*2**16 /den (b16)
*/
/* Check for overflow in the first part of the quotient */
term1 = ((uint32_t)num & 0xffff0000) / denom;
if (term1 >= 0x00010000)
{
return ub16MAX; /* Will overflow */
}
/* Finish the division */
numf = num - term1 * denom;
term1 <<= 16;
product = term1 + (numf + (denom >> 1)) / denom;
/* Check for overflow */
if (product < term1)
{
return ub16MAX; /* Overflowed */
}
return product;
}
#endif

View File

@ -0,0 +1,131 @@
/****************************************************************************
* libs/libc-musl/fixedmath/lib_ubsqrt.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_ubsqrt.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <fixedmath.h>
/****************************************************************************
* Public Functions
****************************************************************************/
#ifdef CONFIG_HAVE_LONG_LONG
/****************************************************************************
* Name: ub32sqrtub16
*
* Description:
* ub32sqrtub16 calculates square root for 'a'
*
****************************************************************************/
ub16_t ub32sqrtub16(ub32_t a)
{
uint64_t n = a;
uint64_t xk = n;
/* Direct conversion of ub32_t to uint64_t is same operation as multiplying
* 'a' by 2^32, therefore n = a * 2^32.
*/
if (xk == UINT64_MAX)
{
/* Avoid 'xk + n / xk' overflow on first iteration. */
xk = (uint64_t)1 << 63;
}
do
{
uint64_t xk1 = (xk + n / xk) >> 1;
if (xk1 >= xk)
{
break;
}
xk = xk1;
}
while (1);
/* 'xk' now holds 'sqrt(n)' => 'sqrt(a * 2^32)' => 'sqrt(a) * 2^16', thus
* 'xk' holds square root of 'a' in ub16_t format.
*/
return (ub16_t)xk;
}
#endif
/****************************************************************************
* Name: ub16sqrtub8
*
* Description:
* ub16sqrtub8 calculates square root for 'a'
*
****************************************************************************/
ub8_t ub16sqrtub8(ub16_t a)
{
uint32_t n = a;
uint32_t xk = n;
/* Direct conversion of ub16_t to uint32_t is same operation as multiplying
* 'a' by 2^16, therefore n = a * 2^16.
*/
if (xk == UINT32_MAX)
{
/* Avoid 'xk + n / xk' overflow on first iteration. */
xk = (uint32_t)1 << 31;
}
do
{
uint32_t xk1 = (xk + n / xk) >> 1;
if (xk1 >= xk)
{
break;
}
xk = xk1;
}
while (1);
/* 'xk' now holds 'sqrt(n)' => 'sqrt(a * 2^16)' => 'sqrt(a) * 2^8', thus
* 'xk' holds square root of 'a' in ub8_t format.
*/
return (ub8_t)xk;
}

View File

@ -0,0 +1,35 @@
############################################################################
# libs/libc-musl/grp/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
# Add the grp C files to the build
CSRCS += lib_getgrgid.c lib_getgrgidr.c lib_getgrnam.c lib_getgrnamr.c
CSRCS += lib_initgroups.c
ifeq ($(CONFIG_LIBC_GROUP_FILE),y)
CSRCS += lib_find_grpfile.c lib_grp_globals.c
else
CSRCS += lib_getgrbuf.c lib_getgrbufr.c
endif
# Add the grp directory to the build
DEPPATH += --dep-path grp
VPATH += :grp

View File

@ -0,0 +1,346 @@
/****************************************************************************
* libs/libc-musl/grp/lib_find_grpfile.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_find_grpfile.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <grp.h>
#include <assert.h>
#include "grp/lib_grp.h"
/****************************************************************************
* Private Types
****************************************************************************/
typedef CODE int (grp_foreach_match_t)(FAR const struct group *entry,
uintptr_t arg);
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: grp_match_name
*
* Description:
* Called for each record in the group file. Returns "1" if the record
* matches the group name (passed as arg)
*
* Input Parameters:
* entry - The parsed group file record
* arg - A pointer to the group name to match
*
* Returned Value:
* < 0 : An error has occurred.
* = 0 : No entry name does not match.
* = 1 : The entry name matches
*
****************************************************************************/
static int grp_match_name(FAR const struct group *entry, uintptr_t arg)
{
FAR const char *gname = (FAR const char *)arg;
return strcmp(entry->gr_name, gname) == 0 ? 1 : 0;
}
/****************************************************************************
* Name: grp_match_gid
*
* Description:
* Called for each record in the group file. Returns "1" if the record
* matches the group ID (passed as arg)
*
* Input Parameters:
* entry - The parsed group file record
* arg - The group ID to match
*
* Returned Value:
* < 0 : An error has occurred.
* = 0 : No entry name does not match.
* = 1 : The entry name matches
*
****************************************************************************/
static int grp_match_gid(FAR const struct group *entry, uintptr_t arg)
{
int match_gid = (int)arg;
return match_gid == entry->gr_gid ? 1 : 0;
}
/****************************************************************************
* Name: grp_foreach
*
* Description:
* Visit each record in group file.
*
* Input Parameters:
* match - The match function to call on each record
* arg - Argument passed to the match function
* entry - Location to return the parsed group file entry
* buffer - I/O buffer used to access the group file
* buflen - The size of the I/O buffer in bytes
*
* Returned Value:
* < 0 : An error has occurred.
* = 0 : No entry with this name was found.
* = 1 : The entry with this name was found.
*
****************************************************************************/
static int grp_foreach(grp_foreach_match_t match, uintptr_t arg,
FAR struct group *entry, FAR char *buffer,
size_t buflen)
{
FAR FILE *stream;
FAR char *ptr;
FAR char *line;
FAR char *save;
size_t linelen;
unsigned int nmembers;
int ret;
stream = fopen(CONFIG_LIBC_GROUP_FILEPATH, "r");
if (stream == NULL)
{
int errcode = get_errno();
DEBUGASSERT(errcode > 0);
return -errcode;
}
/* Read the password file line by line until the record with the matching
* username is found, or until the end of the file is reached.
*
* The format of the password file is:
*
* user:x:uid:gid:home
*
* Where:
* user: User name
* x: Encrypted password
* uid: User ID
* gid: Group ID
* home: Login directory
*/
DEBUGASSERT(buflen > MEMBER_SIZE); /* Buffer must also be aligned */
line = buffer + MEMBER_SIZE;
linelen = buflen - MEMBER_SIZE;
while (fgets(line, linelen, stream) != NULL)
{
ptr = line;
entry->gr_name = ptr;
/* Skip to the end of the name and properly terminate it. The name
* must be terminated with the field delimiter ':'.
*/
for (; *ptr != '\n' && *ptr != '\0' && *ptr != ':'; ptr++)
{
}
if (*ptr == '\n' || *ptr == '\0')
{
/* Bad line format? */
continue;
}
*ptr++ = '\0';
entry->gr_passwd = ptr;
/* Skip to the end of the password and properly terminate it. The
* password must be terminated with the field delimiter ':'.
*/
for (; *ptr != '\n' && *ptr != '\0' && *ptr != ':'; ptr++)
{
}
if (*ptr == '\n' || *ptr == '\0')
{
/* Bad line format? */
continue;
}
*ptr++ = '\0';
save = ptr;
/* Skip to the end of the group ID and properly terminate it. The
* group ID must be terminated with the field delimiter ':'.
*/
for (; *ptr != '\n' && *ptr != '\0' && *ptr != ':'; ptr++)
{
}
if (*ptr == '\n' || *ptr == '\0')
{
/* Bad line format? */
continue;
}
*ptr++ = '\0';
entry->gr_gid = (gid_t)atoi(save);
/* This is followed by a variable number of user names. The ':'
* delimited will be followed by '\n' or '\0' if there are no users
* in the group
*/
nmembers = 0;
entry->gr_mem = (FAR char **)buffer;
if (*ptr != '\n' && *ptr != '\0')
{
for (; ; )
{
/* Add the next user name */
entry->gr_mem[nmembers] = ptr;
nmembers++;
if (nmembers >= CONFIG_LIBC_GROUP_NUSERS)
{
break;
}
/* Skip to the end of the user name and properly terminate it.
* The user name must be terminated with either (1) ','
* meaning that another user name is present, or (2) '\n' or
* '\0' meaning that we have reached the end of the line and
* there are no further user names.
*/
for (; *ptr != '\n' && *ptr != '\0' && *ptr != ','; ptr++)
{
}
if (*ptr == '\n' || *ptr == '\0')
{
*ptr = '\0';
break;
}
*ptr++ = '\0';
}
}
/* The list terminates with a NULL pointer */
entry->gr_mem[nmembers] = NULL;
/* Check for a match */
ret = match(entry, arg);
if (ret != 0)
{
/* We either have the match or an error occurred. */
fclose(stream);
return ret;
}
}
fclose(stream);
return 0;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: grp_findby_name
*
* Description:
* Find group file entry using the group name.
*
* Input Parameters:
* gname - The group name
* entry - Location to return the parsed group file entry
* buffer - I/O buffer used to access the group file
* buflen - The size of the I/O buffer in bytes
*
* Returned Value:
* < 0 : An error has occurred.
* = 0 : No entry with this name was found.
* = 1 : The entry with this name was found.
*
****************************************************************************/
int grp_findby_name(FAR const char *gname, FAR struct group *entry,
FAR char *buffer, size_t buflen)
{
return grp_foreach(grp_match_name, (uintptr_t)gname,
entry, buffer, buflen);
}
/****************************************************************************
* Name: grp_findby_gid
*
* Description:
* Find group file entry using the group ID.
*
* Input Parameters:
* gid - The group ID
* entry - Location to return the parsed group file entry
* buffer - I/O buffer used to access the group file
* buflen - The size of the I/O buffer in bytes
*
* Returned Value:
* < 0 : An error has occurred.
* = 0 : No entry with this name was found.
* = 1 : The entry with this name was found.
*
****************************************************************************/
int grp_findby_gid(gid_t gid, FAR struct group *entry, FAR char *buffer,
size_t buflen)
{
/* Verify that the GID is in the valid range of 0 through INT16_MAX.
* OpenGroup.org does not specify a GID_MAX or GID_MIN. Instead we use a
* priori knowledge that gid_t is type int16_t.
*/
if ((uint16_t)gid > INT16_MAX)
{
return -EINVAL;
}
return grp_foreach(grp_match_gid, (uintptr_t)gid, entry, buffer, buflen);
}

View File

@ -0,0 +1,121 @@
/****************************************************************************
* libs/libc-musl/grp/lib_getgrbuf.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_getgrbuf.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <grp.h>
#include "grp/lib_grp.h"
#include "libc-musl.h"
/****************************************************************************
* Private Data
****************************************************************************/
static FAR char *g_buf;
static FAR struct group *g_grp;
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getgrbuf
*
* Description:
* libc-musl/grp internal helper function for getgrgid and getgrnam to allocate
* and setup a group structure once a matching entry has been found.
*
* Input Parameters:
* gid - Value to set the group structure's gr_gid field to.
* name - Value to set the group structure's gr_name field to.
* passwd - Value to set the group structure's passwd field to.
*
* Returned Value:
* A pointer to a statically allocated group structure, or NULL if an
* error occurs, in which case errno is set appropriately.
*
****************************************************************************/
FAR struct group *getgrbuf(gid_t gid, FAR const char *name,
FAR const char *passwd)
{
FAR struct group *result;
FAR char *newbuf;
size_t buflen;
int err;
buflen = sizeof(FAR char **) + strlen(name) + 1 + strlen(passwd) + 1;
newbuf = (FAR char *)lib_realloc(g_buf, buflen);
if (!newbuf)
{
err = ENOMEM;
goto error;
}
g_buf = newbuf;
if (!g_grp)
{
g_grp = (FAR struct group *)lib_malloc(sizeof(struct group));
}
if (!g_grp)
{
err = ENOMEM;
goto error;
}
err = getgrbuf_r(gid, name, passwd, g_grp, g_buf, buflen, &result);
if (err)
{
goto error;
}
return result;
error:
lib_free(g_grp);
lib_free(g_buf);
g_grp = NULL;
g_buf = NULL;
set_errno(err);
return NULL;
}

View File

@ -0,0 +1,105 @@
/****************************************************************************
* libs/libc-musl/grp/lib_getgrbufr.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_getgrbufr.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <grp.h>
#include "grp/lib_grp.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getgrbuf_r
*
* Description:
* libc-musl/grp internal helper function for getgrgid_r and getgrnam_r to setup
* the caller supplied 'grp' and 'buf' buffers once a matching entry has
* been found.
*
* Input Parameters:
* gid - Value to set grp->gr_gid to.
* name - Value to set grp->gr_name to.
* passwd - Value to set grp->passwd to.
* grp - Pointer to the space to store the retrieved group structure in.
* buf - String fields pointed to by the group struct are stored here.
* buflen - The length of buf in bytes.
* result - Pointer to the resulting group struct, or NULL in case of fail.
*
* Returned Value:
* On success getgrgid_r returns 0 and sets *result to grp. In case of
* failure an error number is returned.
*
****************************************************************************/
int getgrbuf_r(gid_t gid, FAR const char *name, FAR const char *passwd,
FAR struct group *grp, FAR char *buf, size_t buflen,
FAR struct group **result)
{
size_t reqdlen;
size_t padlen;
/* In 'buf' a NULL pointer value will be stored, which must be naturally
* aligned, followed by the null terminated group name string and the null
* terminated passwd string 'x' (indicating 'no password'). Make sure
* sufficient buffer space was supplied by the caller.
*/
padlen = sizeof(FAR void *) - ((uintptr_t)buf % sizeof(FAR char *));
reqdlen = sizeof(FAR void *) + strlen(name) + 1 + strlen(passwd) + 1;
if (buflen < padlen + reqdlen)
{
/* Insufficient buffer space supplied. */
*result = NULL;
return ERANGE;
}
grp->gr_mem = (FAR char **)&buf[padlen];
grp->gr_name = &buf[padlen + sizeof(FAR char *)];
grp->gr_passwd = &buf[padlen + sizeof(FAR char *) + strlen(name) + 1];
strcpy(grp->gr_name, name);
strcpy(grp->gr_passwd, passwd);
grp->gr_gid = gid;
*grp->gr_mem = NULL;
*result = grp;
return 0;
}

View File

@ -0,0 +1,83 @@
/****************************************************************************
* libs/libc-musl/grp/lib_getgrgid.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_getgrgid.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <grp.h>
#include "grp/lib_grp.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getgrgid
*
* Description:
* The getgrgid() function searches the group database for an entry with
* a matching gid.
*
* Input Parameters:
* gid - The gid to return a group structure for
*
* Returned Value:
* A pointer to a statically allocated group structure, or NULL if no
* matching entry is found or an error occurs. Applications wishing to
* check for error situations should set errno to 0 before calling
* getgrgid(). If getgrgid() returns a null pointer and errno is set to
* non-zero, an error occurred.
*
****************************************************************************/
FAR struct group *getgrgid(gid_t gid)
{
#ifdef CONFIG_LIBC_GROUP_FILE
int ret;
ret = grp_findby_gid(gid, &g_group, g_group_buffer, GRPBUF_RESERVE_SIZE);
if (ret != 1)
{
return NULL;
}
return &g_group;
#else
if (gid != ROOT_GID)
{
return NULL;
}
return getgrbuf(ROOT_GID, ROOT_NAME, ROOT_PASSWD);
#endif
}

View File

@ -0,0 +1,95 @@
/****************************************************************************
* libs/libc-musl/grp/lib_getgrgidr.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_getgrgidr.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <grp.h>
#include "grp/lib_grp.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getgrgid_r
*
* Description:
* The getgrgid_r() function searches the group database for an entry with
* a matching gid and stores the retrieved group structure in the space
* pointed to by grp.
*
* Input Parameters:
* gid - The gid to return a group structure for.
* grp - Pointer to the space to store the retrieved group structure in.
* buf - The string fields pointed to by the group struct are stored here.
* buflen - The length of buf in bytes.
* result - Pointer to the resulting group struct, or NULL in case of fail.
*
* Returned Value:
* On success getgrgid_r returns 0 and sets *result to grp. If no match
* is found, 0 is returned and *result is set to NULL. In case of failure
* an error number is returned.
*
****************************************************************************/
int getgrgid_r(gid_t gid, FAR struct group *grp, FAR char *buf,
size_t buflen, FAR struct group **result)
{
#ifdef CONFIG_LIBC_GROUP_FILE
int ret;
ret = grp_findby_gid(gid, grp, buf, buflen);
if (ret != 1)
{
*result = NULL;
return ret < 0 ? -ret : 0;
}
*result = grp;
return 0;
#else
if (gid != ROOT_GID)
{
/* The only known group is 'root', which has a gid of 0. Thus, report
* back that no match was found.
*/
*result = NULL;
return 0;
}
return getgrbuf_r(ROOT_GID, ROOT_NAME, ROOT_PASSWD, grp, buf, buflen,
result);
#endif
}

View File

@ -0,0 +1,84 @@
/****************************************************************************
* libs/libc-musl/grp/lib_getgrnam.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_getgrnam.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <grp.h>
#include "grp/lib_grp.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getgrnam
*
* Description:
* The getgrnam() function searches the group database for an entry with
* a matching name.
*
* Input Parameters:
* name - The group name to return a group structure for
*
* Returned Value:
* A pointer to a statically allocated group structure, or NULL if no
* matching entry is found or an error occurs. Applications wishing to
* check for error situations should set errno to 0 before calling
* getgrnam(). If getgrnam() returns a null pointer and errno is set to
* non-zero, an error occurred.
*
****************************************************************************/
FAR struct group *getgrnam(FAR const char *name)
{
#ifdef CONFIG_LIBC_GROUP_FILE
int ret;
ret = grp_findby_name(name, &g_group, g_group_buffer, GRPBUF_RESERVE_SIZE);
if (ret != 1)
{
return NULL;
}
return &g_group;
#else
if (strcmp(name, "root"))
{
return NULL;
}
return getgrbuf(ROOT_GID, ROOT_NAME, ROOT_PASSWD);
#endif
}

View File

@ -0,0 +1,97 @@
/****************************************************************************
* libs/libc-musl/grp/lib_getgrnamr.c
*
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_getgrnamr.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <grp.h>
#include "grp/lib_grp.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getgrnam_r
*
* Description:
* The getgrnam_r() function searches the group database for an entry with
* a matching name and stores the retrieved group structure in the space
* pointed to by grp.
*
* Input Parameters:
* name - The name of the group to return a group structure for.
* grp - Pointer to the space to store the retrieved group structure in.
* buf - The string fields pointed to by the group struct are stored here.
* buflen - The length of buf in bytes.
* result - Pointer to the resulting group struct, or NULL in case of fail.
*
* Returned Value:
* On success getgrnam_r returns 0 and sets *result to grp. If no match
* is found, 0 is returned and *result is set to NULL. In case of failure
* an error number is returned.
*
****************************************************************************/
int getgrnam_r(FAR const char *name, FAR struct group *grp, FAR char *buf,
size_t buflen, FAR struct group **result)
{
#ifdef CONFIG_LIBC_GROUP_FILE
int ret;
ret = grp_findby_name(name, grp, buf, buflen);
if (ret != 1)
{
*result = NULL;
return ret < 0 ? -ret : 0;
}
*result = grp;
return 0;
#else
if (strcmp(name, ROOT_NAME))
{
/* The only known group is 'root', which has a gid of 0. Thus, report
* back that no match was found.
*/
*result = NULL;
return 0;
}
return getgrbuf_r(ROOT_GID, ROOT_NAME, ROOT_PASSWD, grp, buf, buflen,
result);
#endif
}

View File

@ -0,0 +1,100 @@
/****************************************************************************
* libs/libc-musl/grp/lib_grp.h
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_grp.h
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
#ifndef __LIBS_LIBC_GRP_LIB_GRP_H
#define __LIBS_LIBC_GRP_LIB_GRP_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <grp.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ROOT_GID 0
#define ROOT_NAME "root"
#define ROOT_PASSWD "x"
/* Reserver space for a NULL terminated list for group member names */
#define MEMBER_SIZE ((CONFIG_LIBC_GROUP_NUSERS + 1) * sizeof(FAR char *))
/* Reserve space for the maximum line in the group file PLUS space for an
* array of Member names.
*/
#define GRPBUF_RESERVE_SIZE (CONFIG_LIBC_GROUP_LINESIZE + MEMBER_SIZE)
/****************************************************************************
* Public Data
****************************************************************************/
#ifdef __cplusplus
#define EXTERN extern "C"
extern "C"
{
#else
#define EXTERN extern
#endif
#ifdef CONFIG_LIBC_GROUP_FILE
/* Data for non-reentrant group functions */
EXTERN struct group g_group;
EXTERN char g_group_buffer[GRPBUF_RESERVE_SIZE];
#endif
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
FAR struct group *getgrbuf(gid_t gid, FAR const char *name,
FAR const char *passwd);
int getgrbuf_r(gid_t gid, FAR const char *name, FAR const char *passwd,
FAR struct group *grp, FAR char *buf, size_t buflen,
FAR struct group **result);
#ifdef CONFIG_LIBC_GROUP_FILE
int grp_findby_name(FAR const char *gname, FAR struct group *entry,
FAR char *buffer, size_t buflen);
int grp_findby_gid(gid_t gid, FAR struct group *entry, FAR char *buffer,
size_t buflen);
#endif
#undef EXTERN
#ifdef __cplusplus
}
#endif
#endif /* __LIBS_LIBC_GRP_LIB_GRP_H */

View File

@ -0,0 +1,53 @@
/****************************************************************************
* libs/libc-musl/grp/lib_grp_globals.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_grp_globals.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include "grp/lib_grp.h"
#ifdef CONFIG_LIBC_GROUP_FILE
/****************************************************************************
* Public Data
****************************************************************************/
/* Data for non-reentrant group functions */
struct group g_group;
char g_group_buffer[GRPBUF_RESERVE_SIZE];
/****************************************************************************
* Public Functions
****************************************************************************/
#endif /* CONFIG_LIBC_GROUP_FILE */

View File

@ -0,0 +1,68 @@
/****************************************************************************
* libs/libc-musl/grp/lib_initgroups.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_initgroups.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <grp.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: initgroups
*
* Description:
* The group database /etc/group is read to determine all groups of which
* user is a member. The additional group group is also added to this set,
* which is then used to set the supplementary group IDs of the calling
* process.
*
* Input Parameters:
* user - Name of the user to query the /etc/group database for.
* group - Additional gid to add to the list of group IDs.
*
* Returned Value:
* The initgroups() function returns zero if successful, and -1 in case of
* failure, in which case errno is set appropriately.
*
****************************************************************************/
int initgroups(FAR const char *user, gid_t group)
{
/* There currently is no support for supplementary group IDs in NuttX.
* Thus, just ignore this request silently and report success.
*/
return 0;
}

View File

@ -0,0 +1,32 @@
############################################################################
# libs/libc-musl/hex2bin/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################
ifeq ($(CONFIG_LIBC_HEX2BIN),y)
# Add the hex2bin sources to the build
CSRCS += lib_fhex2mem.c lib_hex2bin.c lib_hex2mem.c
# Add the hex2bin directory to the build
DEPPATH += --dep-path hex2bin
VPATH += :hex2bin
endif

View File

@ -0,0 +1,97 @@
/****************************************************************************
* libs/libc-musl/hex2bin/lib_fhex2mem.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_fhex2mem.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <assert.h>
#include <hex2bin.h>
#include <nuttx/streams.h>
#ifdef CONFIG_LIBC_HEX2BIN
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: fhex2mem
*
* Description:
* Read the Intel HEX ASCII data provided on the standard stream
* 'instream' and write the binary to memory.
*
* If, for example, instream is stdin, then the HEX ASCII data would be
* taken from the console and written to memory.
*
* Input Parameters:
* instream - The incoming standard stream from which Intel HEX data
* will be received.
* baseaddr - The base address of the memory region stream.
* endpaddr - The end address (plus 1) of the memory region.
* swap - Controls byte ordering. See enum hex2bin_swap_e for
* description of the values.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* failure.
*
****************************************************************************/
int fhex2mem(FAR FILE *instream, uint32_t baseaddr, uint32_t endpaddr,
enum hex2bin_swap_e swap)
{
struct lib_stdinstream_s stdinstream;
struct lib_memsostream_s memoutstream;
/* Check memory addresses */
DEBUGASSERT(instream != NULL && endpaddr > baseaddr);
/* Wrap the file descriptor as raw stream; wrap the memory as a memory
* stream.
*/
lib_stdinstream(&stdinstream, instream);
lib_memsostream(&memoutstream, (FAR char *)baseaddr,
(int)(endpaddr - baseaddr));
/* And do the deed */
return hex2bin(&stdinstream.public, &memoutstream.public,
(uint32_t)baseaddr, (uint32_t)endpaddr,
(enum hex2bin_swap_e)swap);
}
#endif /* CONFIG_LIBC_HEX2BIN */

View File

@ -0,0 +1,695 @@
/****************************************************************************
* libs/libc-musl/hex2bin/lib_hex2bin.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/
/**
* @file lib_hex2bin.c
* @brief nuttx source code
* https://github.com/apache/incubator-nuttx.git
* @version 10.3.0
* @author AIIT XUOS Lab
* @date 2022-08-04
*/
/****************************************************************************
* References:
* - http://en.wikipedia.org/wiki/Intel_HEX
* - Hexadecimal Object File Format Specification, Revision A January 6,
* 1988, Intel
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdint.h>
#include <debug.h>
#include <errno.h>
#include <hex2bin.h>
#include <nuttx/streams.h>
#include "libc-musl.h"
#ifdef CONFIG_LIBC_HEX2BIN
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* ASCII record sizes */
#define BYTECOUNT_ASCSIZE 2
#define ADDRESS_ASCSIZE 4
#define RECTYPE_ASCSIZE 2
#define BYTECOUNT_LINENDX (0)
#define ADDRESS_LINENDX (BYTECOUNT_LINENDX + BYTECOUNT_ASCSIZE)
#define RECTYPE_LINENDX (ADDRESS_LINENDX + ADDRESS_ASCSIZE)
#define DATA_LINENDX (RECTYPE_LINENDX + RECTYPE_ASCSIZE)
#define HEADER_ASCSIZE DATA_LINENDX
#define CHECKSUM_ASCSIZE 2
#define TRAILER_SIZE (CHECKSUM_ASCSIZE)
#define MAXDATA_BINSIZE 255
#define RECORD_ASCSIZE(n) (HEADER_ASCSIZE + TRAILER_SIZE + 2*(n))
#define MAXRECORD_ASCSIZE RECORD_ASCSIZE(MAXDATA_BINSIZE)
#define MINRECORD_ASCSIZE RECORD_ASCSIZE(0)
#define LINE_ALLOC MAXRECORD_ASCSIZE
/* Binary record sizes */
#define BYTECOUNT_BINSIZE 1
#define ADDRESS_BINSIZE 2
#define RECTYPE_BINSIZE 1
#define BYTECOUNT_BINNDX (0)
#define ADDRESS_BINNDX (BYTECOUNT_BINNDX + BYTECOUNT_BINSIZE)
#define RECTYPE_BINNDX (ADDRESS_BINNDX + ADDRESS_BINSIZE)
#define DATA_BINNDX (RECTYPE_BINNDX + RECTYPE_BINSIZE)
#define HEADER_BINSIZE DATA_BINNDX
#define CHECKSUM_BINSIZE 1
#define TRAILER_BINSIZE CHECKSUM_BINSIZE
#define RECORD_BINSIZE(n) (HEADER_BINSIZE + TRAILER_BINSIZE + (n))
#define MAXRECORD_BINSIZE RECORD_BINSIZE(MAXDATA_BINSIZE)
#define MINRECORD_BKINSIZE RECORD_BINSIZE(0)
#define BIN_ALLOC MAXRECORD_BINSIZE
/* Record start code */
#define RECORD_STARTCODE ':'
/* Record Types */
#define RECORD_DATA 0 /* Data */
#define RECORD_EOF 1 /* End of file */
#define RECORD_EXT_SEGADDR 2 /* Extended segment address record */
#define RECORD_START_SEGADDR 3 /* Start segment address record */
#define RECORD_EXT_LINADDR 4 /* Extended linear address record */
#define RECORD_START_LINADDR 5 /* Start linear address record */
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: nibble2bin
****************************************************************************/
static int nibble2bin(uint8_t ascii)
{
if (ascii >= '0' && ascii <= '9')
{
return (ascii - 0x30);
}
else if (ascii >= 'a' && ascii <= 'f')
{
return (ascii - 'a' + 10);
}
else if (ascii >= 'A' && ascii <= 'F')
{
return (ascii - 'A' + 10);
}
return -EINVAL;
}
/****************************************************************************
* Name: byte2bin
****************************************************************************/
static int byte2bin(FAR const uint8_t *ascii)
{
int nibble;
int byte;
/* Get the MS nibble (big endian order) */
nibble = nibble2bin(*ascii++);
if (nibble < 0)
{
return nibble;
}
byte = (nibble << 4);
/* Get the MS nibble */
nibble = nibble2bin(*ascii);
if (nibble < 0)
{
return nibble;
}
byte |= nibble;
return byte;
}
/****************************************************************************
* Name: word2bin
****************************************************************************/
#if 0 /* Not used */
static int word2bin(FAR const char *ascii)
{
int byte;
int word;
/* Get the MS byte (big endian order) */
byte = word2bin(ascii);
if (byte < 0)
{
return byte;
}
word = (byte << 8);
/* Get the MS byte */
byte = word2bin(ascii + 2);
if (byte < 0)
{
return byte;
}
word |= byte;
return word;
}
#endif
/****************************************************************************
* Name: data2bin
****************************************************************************/
int data2bin(FAR uint8_t *dest, FAR const uint8_t *src, int nsrcbytes)
{
int byte;
/* An even number of source bytes is expected */
if ((nsrcbytes & 1) != 0)
{
return -EINVAL;
}
/* Convert src bytes in groups of 2, writing one byte to the output on each
* pass through the loop.
*/
while (nsrcbytes > 0)
{
/* Get the MS nibble (big endian order) */
byte = byte2bin(src);
if (byte < 0)
{
return byte;
}
src += 2;
/* And write the byte to the destination */
*dest++ = byte;
nsrcbytes -= 2;
}
return OK;
}
/****************************************************************************
* Name: readstream
****************************************************************************/
static int readstream(FAR struct lib_instream_s *instream,
FAR uint8_t *line, unsigned int lineno)
{
int nbytes = 0;
int ch;
/* Skip until the beginning of line start code is encountered */
ch = instream->get(instream);
while (ch != RECORD_STARTCODE && ch != EOF)
{
ch = instream->get(instream);
}
/* Skip over the startcode */
if (ch != EOF)
{
ch = instream->get(instream);
}
/* Then read, verify, and buffer until the end of line is encountered */
while (ch != EOF && nbytes < (MAXRECORD_ASCSIZE - 1))
{
if (ch == '\n' || ch == '\r')
{
*line = '\0';
return nbytes;
}
/* Only hex data goes into the line buffer */
else if (isxdigit(ch))
{
*line++ = ch;
nbytes++;
}
else if (!isspace(ch)) /* Not expected */
{
lerr("Line %u ERROR: Unexpected character %c[%02x] in stream\n",
lineno, isprint(ch) ? ch : '.', ch);
break;
}
/* Read the next character from the input stream */
ch = instream->get(instream);
}
/* Some error occurred: Unexpected EOF, line too long, or bad character in
* stream
*/
lerr("Line %u ERROR: Failed to read line. %d characters read\n",
lineno, nbytes);
return EOF;
}
/****************************************************************************
* Name: hex2bin_swap16 and hex2bin_swap32
****************************************************************************/
static inline void hex2bin_swap16(FAR uint8_t *data, int bytecount)
{
for (; bytecount > 0; bytecount -= 2)
{
uint8_t b0 = data[0];
uint8_t b1 = data[1];
*data++ = b1;
*data++ = b0;
}
}
static inline void hex2bin_swap32(FAR uint8_t *data, int bytecount)
{
for (; bytecount > 0; bytecount -= 4)
{
uint8_t b0 = data[0];
uint8_t b1 = data[1];
uint8_t b2 = data[2];
uint8_t b3 = data[3];
*data++ = b3;
*data++ = b2;
*data++ = b1;
*data++ = b0;
}
}
/****************************************************************************
* Name: writedata
****************************************************************************/
static inline void writedata(FAR struct lib_sostream_s *outstream,
FAR uint8_t *data, int bytecount)
{
for (; bytecount > 0; bytecount--)
{
outstream->put(outstream, *data++);
}
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: hex2bin
*
* Description:
* Read the Intel HEX ASCII data provided on the serial IN stream and write
* the binary to the seek-able serial OUT stream.
*
* These streams may be files or, in another usage example, the IN stream
* could be a serial port and the OUT stream could be a memory stream.
* This would decode and write the serial input to memory.
*
* Input Parameters:
* instream - The incoming stream from which Intel HEX data will be
* received.
* outstream - The outgoing stream in which binary data will be written.
* baseaddr - The base address of the outgoing stream. Seeking in the
* output stream will be relative to this address.
* endpaddr - The end address (plus 1) of the outgoing stream. This
* value is used only for range checking. endpaddr must
* be larger than baseaddr. A zero value for endpaddr
* disables range checking.
* swap - Controls byte ordering. See enum hex2bin_swap_e for
* description of the values.
*
* Returned Value:
* Zero (OK) is returned on success; a negated errno value is returned on
* failure.
*
****************************************************************************/
int hex2bin(FAR struct lib_instream_s *instream,
FAR struct lib_sostream_s *outstream, uint32_t baseaddr,
uint32_t endpaddr, enum hex2bin_swap_e swap)
{
FAR uint8_t *alloc;
FAR uint8_t *line;
FAR uint8_t *bin;
int nbytes;
int bytecount;
uint32_t address;
uint32_t endaddr;
uint32_t expected;
uint32_t extension;
uint16_t address16;
uint8_t checksum;
unsigned int lineno;
int i;
int ret = OK;
/* Allocate buffer memory */
alloc = (FAR uint8_t *)lib_malloc(LINE_ALLOC + BIN_ALLOC);
if (alloc == NULL)
{
lerr("ERROR: Failed to allocate memory\n");
return -ENOMEM;
}
line = alloc;
bin = &alloc[LINE_ALLOC];
extension = 0;
expected = 0;
lineno = 0;
/* Read and process the HEX input stream stream until the end of file
* record is received (or until an error occurs)
*/
while ((nbytes = readstream(instream, line, lineno)) != EOF)
{
/* Increment the line number */
lineno++;
/* Did we read enough data to do anything? */
if (nbytes < MINRECORD_ASCSIZE)
{
lerr("Line %u ERROR: Record too short: %d\n", lineno, nbytes);
goto errout_with_einval;
}
/* We should always read an even number of bytes */
if ((nbytes & 1) != 0)
{
lerr("Line %u ERROR: Record length is odd: %d\n", lineno, nbytes);
goto errout_with_einval;
}
/* Get the data byte count */
bytecount = byte2bin(&line[BYTECOUNT_LINENDX]);
if (bytecount < 0)
{
lerr("Line %u ERROR: Failed to read bytecount: %d\n",
lineno, bytecount);
ret = bytecount;
goto errout_with_buffers;
}
/* Verify that the bytecount matches the length of the record */
if (RECORD_ASCSIZE(bytecount) != nbytes)
{
lerr("Line %u ERROR: Expected %d bytes, read %d\n",
lineno, RECORD_ASCSIZE(bytecount), nbytes);
goto errout_with_einval;
}
/* Convert the entire line to binary. We need to do this for
* checksum calculation which includes the entire line (minus
* the start code and the checksum at the end of the line itself)
*/
ret = data2bin(bin, line, nbytes);
if (ret < 0)
{
lerr("Line %u ERROR: Failed to convert line to binary: %d\n",
lineno, ret);
goto errout_with_buffers;
}
/* Calculate and verify the checksum over all of the data */
nbytes >>= 1; /* Number of bytes in bin[] */
checksum = 0;
for (i = 0; i < nbytes; i++)
{
checksum += bin[i];
}
if (checksum != 0)
{
lerr("Line %u ERROR: Bad checksum %02x\n", lineno, checksum);
goto errout_with_einval;
}
/* Get the 16-bit (unextended) address from the record */
address16 = (uint16_t)bin[ADDRESS_BINNDX] << 8 |
(uint16_t)bin[ADDRESS_BINNDX + 1];
/* Handle the record by its record type */
switch (bin[RECTYPE_BINNDX])
{
case RECORD_DATA: /* Data */
{
/* Swap data in place in the binary buffer as required */
switch (swap)
{
case HEX2BIN_NOSWAP: /* No swap, stream is the correct byte order */
break;
case HEX2BIN_SWAP16: /* Swap bytes in 16-bit values */
{
if ((bytecount & 1) != 0)
{
lerr("Line %d ERROR: Byte count %d is not a multiple "
"of 2\n",
lineno, bytecount);
goto errout_with_einval;
}
/* Do the byte swap */
hex2bin_swap16(&bin[DATA_BINNDX], bytecount);
}
break;
case HEX2BIN_SWAP32: /* Swap bytes in 32-bit values */
{
if ((bytecount & 3) != 0)
{
lerr("Line %d ERROR: Byte count %d is not a multiple "
"of 4\n",
lineno, bytecount);
goto errout_with_einval;
}
/* Do the byte swap */
hex2bin_swap32(&bin[DATA_BINNDX], bytecount);
}
break;
default:
{
lerr("ERROR: Invalid swap argument: %d\n", swap);
goto errout_with_einval;
}
}
/* Get and verify the full 32-bit address */
address = extension + (uint32_t)address16;
endaddr = address + bytecount;
if (address < baseaddr || (endpaddr != 0 && endaddr >= endpaddr))
{
lerr("Line %d ERROR: Extended address %08lx is out of "
"range\n",
lineno, (unsigned long)address);
goto errout_with_einval;
}
/* Seek to the correct position in the OUT stream if we have
* made an unexpected jump in the data address.
*/
if (address != expected)
{
off_t pos = outstream->seek(outstream,
address - baseaddr, SEEK_SET);
if (pos == (off_t)-1)
{
lerr("Line %u ERROR: Seek to address %08lu failed\n",
lineno, (unsigned long)address);
ret = -ESPIPE;
goto errout_with_buffers;
}
}
/* Transfer data to the OUT stream */
writedata(outstream, &bin[DATA_BINNDX], bytecount);
/* This is the next data address that we expect to see */
expected = address + bytecount;
}
break;
case RECORD_EOF: /* End of file */
/* End Of File record. Must occur exactly once per file in the
* last line of the file. The byte count is 00 and the data field
* is empty. Usually the address field is also 0000.
*/
if (bytecount == 0)
{
ret = OK;
goto exit_with_buffers;
}
lerr("Line %u ERROR: Nonzero bytecount %d in EOF\n",
lineno, bytecount);
goto errout_with_einval;
case RECORD_EXT_SEGADDR: /* Extended segment address record */
/* The address specified by the data field is multiplied by 16
* (shifted 4 bits left) and added to the subsequent data record
* addresses. This allows addressing of up to a megabyte of
* address space. The address field of this record has to be
* 0000, the byte count is 02 (the segment is 16-bit). The
* least significant hex digit of the segment address is always
* 0.
*/
if (bytecount != 2 || address16 != 0 || bin[DATA_BINNDX + 1] != 0)
{
lerr("Line %u ERROR: Invalid segment address\n", lineno);
lerr(" bytecount=%d address=%04x segment=%02x%02x\n",
bytecount, address16, bin[DATA_BINNDX],
bin[DATA_BINNDX + 1]);
goto errout_with_einval;
}
extension = (uint32_t)bin[DATA_BINNDX] << 12;
break;
case RECORD_START_SEGADDR: /* Start segment address record */
/* For 80x86 processors, it specifies the initial content of
* the CS:IP registers. The address field is 0000, the byte
* count is 04, the first two bytes are the CS value, the
* latter two are the IP value.
*/
break;
case RECORD_EXT_LINADDR: /* Extended linear address record */
/* The address field is 0000, the byte count is 02. The two
* data bytes (two hex digit pairs in big endian order)
* represent the upper 16 bits of the 32 bit address for
* all subsequent 00 type records until the next 04 type
* record comes. If there is not a 04 type record, the
* upper 16 bits default to 0000. To get the absolute
* address for subsequent 00 type records, the address
* specified by the data field of the most recent 04 record
* is added to the 00 record addresses.
*/
if (bytecount != 2 || address16 != 0)
{
lerr("Line %u ERROR: Invalid linear address\n", lineno);
lerr(" bytecount=%d address=%04x\n", bytecount, address16);
goto errout_with_einval;
}
extension = (uint32_t)bin[DATA_BINNDX] << 24 |
(uint32_t)bin[DATA_BINNDX + 1] << 16;
break;
case RECORD_START_LINADDR: /* Start linear address record */
/* The address field is 0000, the byte count is 04. The 4
* data bytes represent the 32-bit value loaded into the EIP
* register of the 80386 and higher CPU.
*/
break;
default:
break;
}
}
lerr("ERROR: No EOF record found\n");
errout_with_einval:
ret = -EINVAL;
errout_with_buffers:
exit_with_buffers:
lib_free(alloc);
return ret;
}
#endif /* CONFIG_LIBC_HEX2BIN */

Some files were not shown because too many files have changed in this diff Show More