Added C library support in sandbox (newlib).
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12994 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
parent
2224bd26a7
commit
fd723895ec
|
@ -121,6 +121,7 @@ LDSCRIPT= ./sandbox.ld
|
|||
# setting.
|
||||
CSRC = $(ALLCSRC) \
|
||||
$(TESTSRC) \
|
||||
$(CHIBIOS)/os/sb/various/syscalls.c \
|
||||
main.c
|
||||
|
||||
# C++ sources that can be compiled in ARM or THUMB mode depending on the global
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "sbuser.h"
|
||||
|
||||
|
@ -41,7 +42,8 @@ int main(void) {
|
|||
#endif
|
||||
while (true) {
|
||||
msg_t msg = sbMsgWait();
|
||||
sbFileWrite(1U, (const uint8_t *)"Hello World!!\r\n", 15U);
|
||||
printf("Hello World (%u)!!\r\n", (unsigned)msg);
|
||||
// sbFileWrite(1U, (const uint8_t *)"Hello World!!\r\n", 15U);
|
||||
sbMsgReply(msg);
|
||||
// sbSleepMilliseconds(500);
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
*/
|
||||
MEMORY
|
||||
{
|
||||
flash0 : org = 0x080FC000, len = 16k
|
||||
flash0 : org = 0x080F8000, len = 32k
|
||||
ram0 : org = 0x20017000, len = 4k
|
||||
}
|
||||
|
||||
|
|
|
@ -19,14 +19,14 @@
|
|||
*/
|
||||
MEMORY
|
||||
{
|
||||
flash0 : org = 0x08000000, len = 1M - 16k
|
||||
flash0 : org = 0x08000000, len = 1M - 32k
|
||||
flash1 : org = 0x00000000, len = 0
|
||||
flash2 : org = 0x00000000, len = 0
|
||||
flash3 : org = 0x00000000, len = 0
|
||||
flash4 : org = 0x00000000, len = 0
|
||||
flash5 : org = 0x00000000, len = 0
|
||||
flash6 : org = 0x00000000, len = 0
|
||||
flash7 : org = 0x08000000 + 1M - 16k, len = 16k
|
||||
flash7 : org = 0x08000000 + 1M - 32k, len = 32k
|
||||
ram0 : org = 0x20000000, len = 96k - 4k
|
||||
ram1 : org = 0x00000000, len = 0
|
||||
ram2 : org = 0x00000000, len = 0
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
<intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="2"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><contentList><content id="psp-SVC_Handler-(format)" val="4"/><content id="s_psp-SVC_Handler-(format)" val="4"/><content id="s_psp-port_unprivileged_jump-(format)" val="4"/><content id="r0-(format)" val="4"/><content id="r1-(format)" val="4"/><content id="r2-(format)" val="4"/><content id="xPSR-(format)" val="4"/></contentList>"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.FORMAT" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?><contentList><content id="xPSR-(format)" val="4"/><content id="r2-(format)" val="4"/><content id="r1-(format)" val="4"/><content id="r0-(format)" val="4"/><content id="s_psp-port_unprivileged_jump-(format)" val="4"/><content id="s_psp-SVC_Handler-(format)" val="4"/><content id="psp-SVC_Handler-(format)" val="4"/></contentList>"/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <globalVariableList/> "/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <memoryBlockExpressionList> <memoryBlockExpressionItem> <expression text="0x20000300"/> </memoryBlockExpressionItem> </memoryBlockExpressionList> "/>
|
||||
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="./build/ch.elf"/>
|
||||
|
|
|
@ -30,6 +30,7 @@ sb_class_t sbx1;
|
|||
*/
|
||||
static THD_WORKING_AREA(waThread1, 128);
|
||||
static THD_FUNCTION(Thread1, arg) {
|
||||
unsigned i = 1U;
|
||||
|
||||
(void)arg;
|
||||
chRegSetThreadName("blinker");
|
||||
|
@ -42,7 +43,8 @@ static THD_FUNCTION(Thread1, arg) {
|
|||
chThdSleepMilliseconds(50);
|
||||
palSetLine(LINE_LED_RED);
|
||||
chThdSleepMilliseconds(200);
|
||||
(void) sbSendMessage(&sbx1, 0xF00F55AAU);
|
||||
(void) sbSendMessage(&sbx1, (msg_t)i);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -75,7 +77,7 @@ static THD_FUNCTION(Unprivileged1, arg) {
|
|||
sb_config.r0_base,
|
||||
MPU_RASR_ATTR_AP_RO_RO |
|
||||
MPU_RASR_ATTR_CACHEABLE_WT_NWA |
|
||||
MPU_RASR_SIZE_16K |
|
||||
MPU_RASR_SIZE_32K |
|
||||
MPU_RASR_ENABLE);
|
||||
mpuConfigureRegion(MPU_REGION_1,
|
||||
sb_config.r1_base,
|
||||
|
|
|
@ -0,0 +1,117 @@
|
|||
/*
|
||||
ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
|
||||
|
||||
Licensed 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 <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "sbuser.h"
|
||||
|
||||
#define MAKERR(e) (-(int)(e))
|
||||
|
||||
__attribute__((used))
|
||||
int _close_r(struct _reent *r, int file) {
|
||||
uint32_t err;
|
||||
|
||||
err = sbFileClose((uint32_t)file);
|
||||
if (SB_ERR_ISERROR(err)) {
|
||||
__errno_r(r) = MAKERR(err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((used))
|
||||
int _write_r(struct _reent *r, int file, char * ptr, int len) {
|
||||
uint32_t err;
|
||||
|
||||
err = sbFileWrite((uint32_t)file, (const uint8_t *)ptr, (size_t)len);
|
||||
if (SB_ERR_ISERROR(err)) {
|
||||
__errno_r(r) = MAKERR(err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (int)err;
|
||||
}
|
||||
|
||||
__attribute__((used))
|
||||
int _read_r(struct _reent *r, int file, char * ptr, int len) {
|
||||
uint32_t err;
|
||||
|
||||
err = sbFileRead((uint32_t)file, (uint8_t *)ptr, (size_t)len);
|
||||
if (SB_ERR_ISERROR(err)) {
|
||||
__errno_r(r) = MAKERR(err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (int)err;
|
||||
}
|
||||
|
||||
__attribute__((used))
|
||||
int _lseek_r(struct _reent *r, int file, int ptr, int dir) {
|
||||
uint32_t err;
|
||||
|
||||
err = sbFileSeek((uint32_t)file, (uint32_t)ptr, (uint32_t)dir);
|
||||
if (SB_ERR_ISERROR(err)) {
|
||||
__errno_r(r) = MAKERR(err);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return (int)err;
|
||||
}
|
||||
|
||||
__attribute__((used))
|
||||
int _fstat_r(struct _reent *r, int file, struct stat * st) {
|
||||
(void)r;
|
||||
(void)file;
|
||||
|
||||
memset(st, 0, sizeof(*st));
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
__attribute__((used))
|
||||
int _isatty_r(struct _reent *r, int fd) {
|
||||
(void)r;
|
||||
(void)fd;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
__attribute__((used))
|
||||
caddr_t _sbrk_r(struct _reent *r, int incr) {
|
||||
extern uint8_t __heap_end__, __heap_base__;
|
||||
static uint8_t *p = &__heap_base__;
|
||||
uint8_t *prevp;
|
||||
|
||||
prevp = p;
|
||||
if ((p + incr > &__heap_end__) ||
|
||||
(p + incr < &__heap_base__)) {
|
||||
__errno_r(r) = ENOMEM;
|
||||
return (caddr_t)-1;
|
||||
}
|
||||
|
||||
p += incr;
|
||||
return (caddr_t)prevp;
|
||||
}
|
||||
|
||||
/*** EOF ***/
|
Loading…
Reference in New Issue