[sync] sync from internal repo

* use nuttx libc, disable system libc
* use tlsf as default
* update lhal flash driver
* add example readme
* add flash ini for new flash tool
* add fw header for new flash tool
This commit is contained in:
jzlv 2023-01-17 20:54:15 +08:00
parent 89592fc9a3
commit 356f258e83
554 changed files with 79150 additions and 46596 deletions

View file

@ -0,0 +1,12 @@
cmake_minimum_required(VERSION 3.15)
include(proj.conf)
find_package(bouffalo_sdk REQUIRED HINTS $ENV{BL_SDK_BASE})
sdk_set_main_file(main.c)
target_sources(app PRIVATE mqueues_test.c semaphores_test.c)
sdk_add_include_directories(.)
project(posix)

View file

@ -0,0 +1,135 @@
/*
* FreeRTOS Kernel V10.2.1
* Copyright (C) 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of
* this software and associated documentation files (the "Software"), to deal in
* the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
* the Software, and to permit persons to whom the Software is furnished to do so,
* subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
#if defined(BL602) || defined(BL702) || defined(BL702L)
#define configMTIME_BASE_ADDRESS (0x02000000UL + 0xBFF8UL)
#define configMTIMECMP_BASE_ADDRESS (0x02000000UL + 0x4000UL)
#else
#if __riscv_xlen == 64
#define configMTIME_BASE_ADDRESS (0)
#define configMTIMECMP_BASE_ADDRESS ((0xE4000000UL) + 0x4000UL)
#else
#define configMTIME_BASE_ADDRESS ((0xE0000000UL) + 0xBFF8UL)
#define configMTIMECMP_BASE_ADDRESS ((0xE0000000UL) + 0x4000UL)
#endif
#endif
#define configSUPPORT_STATIC_ALLOCATION 1
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ((uint32_t)(1 * 1000 * 1000))
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES (7)
#define configMINIMAL_STACK_SIZE ((unsigned short)2048) /* Only needs to be this high as some demo tasks also use this constant. In production only the idle task would use this. */
#define configTOTAL_HEAP_SIZE ((size_t)24 * 1024)
#define configMAX_TASK_NAME_LEN (16)
#define configUSE_TRACE_FACILITY 1
#define configUSE_STATS_FORMATTING_FUNCTIONS 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 0
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configCHECK_FOR_STACK_OVERFLOW 2
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_MALLOC_FAILED_HOOK 1
#define configUSE_APPLICATION_TASK_TAG 1
#define configUSE_COUNTING_SEMAPHORES 1
#define configGENERATE_RUN_TIME_STATS 0
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 1
#define configUSE_TICKLESS_IDLE 0
#define configUSE_POSIX_ERRNO 1
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES (2)
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY (configMAX_PRIORITIES - 1)
#define configTIMER_QUEUE_LENGTH 4
#define configTIMER_TASK_STACK_DEPTH (configMINIMAL_STACK_SIZE)
/* Task priorities. Allow these to be overridden. */
#ifndef uartPRIMARY_PRIORITY
#define uartPRIMARY_PRIORITY (configMAX_PRIORITIES - 3)
#endif
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 1
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_eTaskGetState 1
#define INCLUDE_xTimerPendFunctionCall 1
#define INCLUDE_xTaskAbortDelay 1
#define INCLUDE_xTaskGetHandle 1
#define INCLUDE_xSemaphoreGetMutexHolder 1
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
void vApplicationMallocFailedHook(void);
void vAssertCalled(void);
#include <stdio.h>
#define configASSERT(x) \
if ((x) == 0) { \
printf("file [%s]\r\n", __FILE__); \
printf("func [%s]\r\n", __FUNCTION__); \
printf("line [%d]\r\n", __LINE__); \
printf("%s\r\n", (const char *)(#x)); \
vAssertCalled(); \
}
#if (configUSE_TICKLESS_IDLE != 0)
void vApplicationSleep(uint32_t xExpectedIdleTime);
#define portSUPPRESS_TICKS_AND_SLEEP(xExpectedIdleTime) vApplicationSleep(xExpectedIdleTime)
#endif
// #define portUSING_MPU_WRAPPERS
#endif /* FREERTOS_CONFIG_H */

View file

@ -0,0 +1,13 @@
SDK_DEMO_PATH ?= .
BL_SDK_BASE ?= $(SDK_DEMO_PATH)/../../..
export BL_SDK_BASE
CHIP ?= bl616
BOARD ?= bl616dk
CROSS_COMPILE ?= riscv64-unknown-elf-
# add custom cmake definition
#cmake_definition+=-Dxxx=sss
include $(BL_SDK_BASE)/project.build

View file

@ -0,0 +1,44 @@
# shell_no_os
## Support CHIP
| CHIP | Remark |
|:----------------:|:------:|
|BL602/BL604 | |
|BL702/BL704/BL706 | |
|BL616/BL618 | |
|BL808 | |
## Compile
- BL602/BL604
```
make CHIP=bl602 BOARD=bl602dk
```
- BL702/BL704/BL706
```
make CHIP=bl702 BOARD=bl702dk
```
- BL616/BL618
```
make CHIP=bl616 BOARD=bl616dk
```
- BL808
```
make CHIP=bl808 BOARD=bl808dk CPU_ID=m0
make CHIP=bl808 BOARD=bl808dk CPU_ID=d0
```
## Flash
```
make flash CHIP=chip_name COMX=xxx # xxx is your com name
```

View file

@ -0,0 +1,11 @@
[cfg]
# 0: no erase, 1:programmed section erase, 2: chip erase
erase = 1
# skip mode set first para is skip addr, second para is skip len, multi-segment region with ; separated
skip_mode = 0x0, 0x0
# 0: not use isp mode, #1: isp mode
boot2_isp_mode = 0
[FW]
filedir = ./build/build_out/posix*_$(CHIPNAME).bin
address = 0x000000

View file

@ -0,0 +1,27 @@
#include <FreeRTOS.h>
#include "semphr.h"
#include "board.h"
static void proc_hellow_entry(void *pvParameters)
{
extern int mqueues_test(void);
mqueues_test();
extern int semaphores_test(void);
semaphores_test();
vTaskDelete(NULL);
}
int main(void)
{
board_init();
puts("[OS] Starting proc_hellow_entry task...\r\n");
xTaskCreate(proc_hellow_entry, (char*)"hellow", 2048, NULL, 6, NULL);
vTaskStartScheduler();
while (1) {
}
}

View file

@ -0,0 +1,146 @@
/*
* Copyright (c) 2002, Intel Corporation. All rights reserved.
* Created by: crystal.xiong REMOVE-THIS AT intel DOT com
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*
* 1. Two threads sending/receiving on different message queue.
* 2. Set different Priority to the messages in the message queue, to
* see whether the highest priority is received first.
*/
// #include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "FreeRTOS_POSIX.h"
#include "FreeRTOS_POSIX/fcntl.h"
#include "FreeRTOS_POSIX/pthread.h"
#include "FreeRTOS_POSIX/mqueue.h"
#define MQ_NAME_1 "/testmsg1"
#define MQ_NAME_2 "/testmsg2"
#define MSG_SIZE 128
#define MAX_MSG 3
extern int FreeRTOS_errno;
static const char *s_msg_ptr[] = { "msg test 1", "msg test 2", "msg test 3" };
static char r_msg_ptr_1[MAX_MSG][MSG_SIZE];
static char r_msg_ptr_2[MAX_MSG][MSG_SIZE];
static pthread_t send1, send2, rev1, rev2;
static void send_1(void *mq)
{
int i;
mqd_t mq1 = *(mqd_t *) mq;
printf("Enter into send_1 \r\n");
for (i = 0; i < MAX_MSG; i++) {
if (-1 == mq_send(mq1, s_msg_ptr[i], MSG_SIZE, i)) {
printf("mq_send doesn't return success \r\n");
pthread_exit((void *)1);
}
printf("[%d] send '%s' in thread send_1. \r\n", i + 1,
s_msg_ptr[i]);
}
pthread_exit(NULL);
}
static void send_2(void *mq)
{
int i;
mqd_t mq2 = *(mqd_t *) mq;
printf("Enter into send_2 \r\n");
for (i = 0; i < MAX_MSG; i++) {
if (-1 == mq_send(mq2, s_msg_ptr[i], MSG_SIZE, i)) {
printf("mq_send doesn't return success \r\n");
pthread_exit((void *)1);
}
printf("[%d] send '%s' in thread send_2. \r\n", i + 1,
s_msg_ptr[i]);
}
pthread_exit(NULL);
}
static void receive_1(void *mq)
{
int i;
mqd_t mq1 = *(mqd_t *) mq;
printf("Enter into receive_1 \r\n");
for (i = 0; i < MAX_MSG; i++) {
retry:
if (-1 == mq_receive(mq1, r_msg_ptr_1[i], MSG_SIZE, NULL)) {
printf("errno: %d \r\n", FreeRTOS_errno);
if (FreeRTOS_errno == 11)
goto retry;
printf("mq_receive doesn't return success \r\n");
pthread_exit((void *)1);
}
printf("[%d] receive '%s' in thread receive_1. \r\n", i + 1,
r_msg_ptr_1[i]);
}
pthread_exit(NULL);
}
static void receive_2(void *mq)
{
int i;
mqd_t mq2 = *(mqd_t *) mq;
printf("Enter into receive_2 \r\n");
for (i = 0; i < MAX_MSG; i++) {
retry:
if (-1 == mq_receive(mq2, r_msg_ptr_2[i], MSG_SIZE, NULL)) {
printf("errno: %d \r\n", FreeRTOS_errno);
if (FreeRTOS_errno == 11)
goto retry;
printf("mq_receive doesn't return success \r\n");
pthread_exit((void *)1);
}
printf("[%d] receive '%s' in thread receive_2. \r\n", i + 1,
r_msg_ptr_2[i]);
}
pthread_exit(NULL);
}
int mqueues_test(void)
{
mqd_t mq1 = 0, mq2 = 0;
struct mq_attr mqstat;
int oflag = O_CREAT | O_NONBLOCK | O_RDWR;
memset(&mqstat, 0, sizeof(mqstat));
mqstat.mq_maxmsg = MAX_MSG;
mqstat.mq_msgsize = MSG_SIZE;
mqstat.mq_flags = 0;
if ((mq1 = mq_open(MQ_NAME_1, oflag, 0777, &mqstat)) == (mqd_t)-1) {
printf("mq_open doesn't return success \r\n");
return -1;
}
if ((mq2 = mq_open(MQ_NAME_2, oflag, 0777, &mqstat)) == (mqd_t)-1) {
printf("mq_open doesn't return success \r\n");
return -1;
}
pthread_create(&send1, NULL, (void *)send_1, (void *)&mq1);
pthread_create(&send2, NULL, (void *)send_2, (void *)&mq2);
pthread_create(&rev1, NULL, (void *)receive_1, (void *)&mq1);
pthread_create(&rev2, NULL, (void *)receive_2, (void *)&mq2);
pthread_join(send1, NULL);
pthread_join(send2, NULL);
pthread_join(rev1, NULL);
pthread_join(rev2, NULL);
mq_close(mq1);
mq_close(mq2);
mq_unlink(MQ_NAME_1);
mq_unlink(MQ_NAME_2);
printf("mq PASS \r\n");
return 0;
}

View file

@ -0,0 +1,2 @@
set(CONFIG_FREERTOS 1)
set(CONFIG_POSIX 1)

View file

@ -0,0 +1,124 @@
/*
* Copyright (c) 2002, Intel Corporation. All rights reserved.
* Created by: crystal.xiong REMOVE-THIS AT intel DOT com
* This file is licensed under the GPL license. For the full content
* of this license, see the COPYING file at the top level of this
* source tree.
*
* This is a test about producer and consumer. Producer sends data
* to a buffer. Consumer keeps reading data from the buffer.
*/
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "FreeRTOS_POSIX.h"
#include "FreeRTOS_POSIX/fcntl.h"
#include "FreeRTOS_POSIX/pthread.h"
#include "FreeRTOS_POSIX/semaphore.h"
#define BUF_SIZE 5
#define Max_Num 10
typedef struct {
int buffer[BUF_SIZE];
sem_t occupied;
sem_t empty;
sem_t lock;
} buf_t;
static int in, out;
static void producer(buf_t * buf)
{
int data;
int i;
for (i = 0; i < Max_Num; i++) {
if (-1 == sem_wait(&buf->occupied)) {
printf("sem_wait didn't return success \r\n");
pthread_exit((void *)1);
}
if (-1 == sem_wait(&buf->lock)) {
printf("sem_wait didn't return success \r\n");
pthread_exit((void *)1);
}
data = 100 * i;
buf->buffer[in] = data;
printf("producer has added %d to the buffer[%d] \r\n", data, in);
in = (in + 1) % BUF_SIZE;
if (-1 == sem_post(&buf->lock)) {
printf("sem_wait didn't return success \r\n");
pthread_exit((void *)1);
}
if (-1 == sem_post(&buf->empty)) {
printf("sem_wait didn't return success \r\n");
pthread_exit((void *)1);
}
}
pthread_exit(NULL);
}
static void consumer(buf_t * buf)
{
int data;
int i;
for (i = 0; i < Max_Num; i++) {
if (-1 == sem_wait(&buf->empty)) {
printf("sem_wait didn't return success \r\n");
pthread_exit((void *)1);
}
if (-1 == sem_wait(&buf->lock)) {
printf("sem_wait didn't return success \r\n");
pthread_exit((void *)1);
}
data = buf->buffer[out];
printf("consumer has taken %d from buffer[%d] \r\n", data, out);
out = (out + 1) % BUF_SIZE;
if (-1 == sem_post(&buf->lock)) {
printf("sem_wait didn't return success \r\n");
pthread_exit((void *)1);
}
if (-1 == sem_post(&buf->occupied)) {
printf("sem_wait didn't return success \r\n");
pthread_exit((void *)1);
}
}
pthread_exit(0);
}
int semaphores_test(void)
{
int shared = 1;
int occupied_value = BUF_SIZE;
int empty_value = 0;
int lock_value = 1;
buf_t buf;
pthread_t con, pro;
if (-1 == sem_init(&buf.occupied, shared, occupied_value)) {
printf("sem_init didn't return success \r\n");
return -1;
}
if (-1 == sem_init(&buf.empty, shared, empty_value)) {
printf("sem_init didn't return success \r\n");
return -1;
}
if (-1 == sem_init(&buf.lock, shared, lock_value)) {
printf("sem_init didn't return success \r\n");
return -1;
}
in = out = 0;
pthread_create(&con, NULL, (void *)consumer, &buf);
pthread_create(&pro, NULL, (void *)producer, &buf);
pthread_join(con, NULL);
pthread_join(pro, NULL);
sem_destroy(&buf.occupied);
sem_destroy(&buf.empty);
printf("sema PASS\r\r\n");
return 0;
}