Added syscalls.
This commit is contained in:
parent
836a9d3add
commit
3d119e132c
|
@ -7,10 +7,10 @@ project(hello)
|
||||||
set(TARGET_LDSCRIPT "${CMAKE_SOURCE_DIR}/stx7105.ld")
|
set(TARGET_LDSCRIPT "${CMAKE_SOURCE_DIR}/stx7105.ld")
|
||||||
|
|
||||||
set(TARGET_SOURCES
|
set(TARGET_SOURCES
|
||||||
"lib/printf/printf.c"
|
|
||||||
"src/main.c"
|
"src/main.c"
|
||||||
"src/stx7105_exc.c"
|
"src/stx7105_exc.c"
|
||||||
"src/stx7105_utils.c"
|
"src/stx7105_utils.c"
|
||||||
|
"src/syscalls.c"
|
||||||
"startup_stx7105.S"
|
"startup_stx7105.S"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
21
src/main.c
21
src/main.c
|
@ -1,7 +1,6 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "printf.h"
|
|
||||||
#include "stx7105.h"
|
#include "stx7105.h"
|
||||||
#include "stx7105_utils.h"
|
#include "stx7105_utils.h"
|
||||||
|
|
||||||
|
@ -16,8 +15,8 @@
|
||||||
#define SYSTEM_CONFIG34 (0xFE001188U) /* PIO4 */
|
#define SYSTEM_CONFIG34 (0xFE001188U) /* PIO4 */
|
||||||
#define SYSTEM_CONFIG7 (0xFE00111CU) /* RXSEL */
|
#define SYSTEM_CONFIG7 (0xFE00111CU) /* RXSEL */
|
||||||
|
|
||||||
#define MEMTEST_START 0x80010000
|
#define MEMTEST_START 0x82000000
|
||||||
#define MEMTEST_END 0x8FFE0000
|
#define MEMTEST_END 0x8F000000
|
||||||
|
|
||||||
void uart_init(void) {
|
void uart_init(void) {
|
||||||
PIO4->CLR_PC0 = 1U; /* PC = 110, AFOUT, PP */
|
PIO4->CLR_PC0 = 1U; /* PC = 110, AFOUT, PP */
|
||||||
|
@ -39,19 +38,19 @@ static void memory_test(void) {
|
||||||
*(uint32_t *)i = i;
|
*(uint32_t *)i = i;
|
||||||
|
|
||||||
if (i % 0x10000 == 0U) {
|
if (i % 0x10000 == 0U) {
|
||||||
printf("Write to 0x%08x...\r\n", i);
|
printf("Write to 0x%08lx...\r\n", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (uint32_t i = MEMTEST_START; i < MEMTEST_END; i += 4) {
|
for (uint32_t i = MEMTEST_START; i < MEMTEST_END; i += 4) {
|
||||||
if (*(uint32_t *)i != i) {
|
if (*(uint32_t *)i != i) {
|
||||||
printf("Read back error at 0x%08x\r\n", i);
|
printf("Read back error at 0x%08lx\r\n", i);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i % 0x10000 == 0U) {
|
if (i % 0x10000 == 0U) {
|
||||||
printf("Read from 0x%08x...\r\n", i);
|
printf("Read from 0x%08lx...\r\n", i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -60,6 +59,9 @@ int main(void) {
|
||||||
init_led(LED_RED_GPIO, LED_RED_PIN, 0U);
|
init_led(LED_RED_GPIO, LED_RED_PIN, 0U);
|
||||||
init_led(LED_BLUE_GPIO, LED_BLUE_PIN, 0U);
|
init_led(LED_BLUE_GPIO, LED_BLUE_PIN, 0U);
|
||||||
|
|
||||||
|
setbuf(stdout,NULL);
|
||||||
|
setbuf(stderr,NULL);
|
||||||
|
|
||||||
uart_init();
|
uart_init();
|
||||||
|
|
||||||
printf("Hello world\r\n");
|
printf("Hello world\r\n");
|
||||||
|
@ -86,10 +88,3 @@ int main(void) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void _putchar(char ch) {
|
|
||||||
while (CONSOLE_ASC->STA & 1 << 9U) {
|
|
||||||
// wait for TX FIFO slot.
|
|
||||||
}
|
|
||||||
CONSOLE_ASC->TX_BUF = ch;
|
|
||||||
}
|
|
|
@ -0,0 +1,69 @@
|
||||||
|
#include <sys/errno.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include "stx7105.h"
|
||||||
|
|
||||||
|
#define CONSOLE_ASC ASC2
|
||||||
|
|
||||||
|
#define HEAP_SIZE 0x10000
|
||||||
|
|
||||||
|
extern char _end;
|
||||||
|
static uint32_t s_heap_size = 0U;
|
||||||
|
|
||||||
|
caddr_t _sbrk(int incr) {
|
||||||
|
char *heap_base = &_end;
|
||||||
|
|
||||||
|
caddr_t ret = heap_base + s_heap_size;
|
||||||
|
|
||||||
|
if (s_heap_size + incr >= HEAP_SIZE) {
|
||||||
|
return (void *)(-ENOMEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
s_heap_size += incr;
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _write(int file, char *ptr, int len) {
|
||||||
|
for (int i = 0; i < len; i++) {
|
||||||
|
while (CONSOLE_ASC->STA & 1 << 9U) {
|
||||||
|
// wait for TX FIFO slot.
|
||||||
|
}
|
||||||
|
CONSOLE_ASC->TX_BUF = ptr[i];
|
||||||
|
}
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _open(const char *name, int flags, int mode) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int _read(int file, char *ptr, int len) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _lseek(int file, int ptr, int dir) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _close(int file) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _isatty(int file) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
pid_t _getpid(void) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void _kill(int pid, int sig) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int _fstat(int file, struct stat *st) {
|
||||||
|
st->st_mode = S_IFCHR;
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue