diff --git a/cpu/kw2x/Makefile.include b/cpu/kw2x/Makefile.include index c5fb24c077..579fc002a9 100644 --- a/cpu/kw2x/Makefile.include +++ b/cpu/kw2x/Makefile.include @@ -1,29 +1,17 @@ +# define the CPU architecture for the kw2x export CPU_ARCH = cortex-m4 -# this CPU implementation is using the explicit core/CPU interface -export CFLAGS += -DCOREIF_NG=1 - -# export the peripheral drivers to be linked into the final binary -export USEMODULE += periph - -# tell the build system that the CPU depends on the Cortex-M common files -export USEMODULE += cortexm_common - # tell the build system that the CPU depends on the Kinetis common files export USEMODULE += kinetis_common # define path to kinetis module, which is needed for this CPU export KINETIS_COMMON = $(RIOTCPU)/kinetis_common/ - -# CPU depends on the cortex-m common module, so include it -include $(RIOTCPU)/cortexm_common/Makefile.include - # CPU depends on the kinetis module, so include it include $(KINETIS_COMMON)Makefile.include export LINKFLAGS += -L$(RIOTCPU)/kinetis_common/ldscripts # define the linker script to use for this CPU -export LINKERSCRIPT = $(RIOTCPU)/$(CPU)/ldscripts/$(CPU_MODEL).ld +export LINKERSCRIPT = $(CPU_MODEL).ld #export the CPU model MODEL = $(shell echo $(CPU_MODEL)|tr 'a-z' 'A-Z') @@ -31,9 +19,10 @@ export CFLAGS += -DCPU_MODEL_$(MODEL) ARCH = $(shell echo $(CPU_ARCH) | tr 'a-z-' 'A-Z_') export CFLAGS += -DCPU_ARCH_$(ARCH) -# include CPU specific includes -export INCLUDES += -I$(RIOTCPU)/$(CPU)/include +# this CPU implementation is using kinetis common startup +export COMMON_STARTUP = $(KINETIS_COMMON) # add the CPU specific system calls implementations for the linker export UNDEF += $(BINDIR)cpu/interrupt-vector.o -export UNDEF += $(BINDIR)cpu/syscalls.o + +include $(RIOTCPU)/Makefile.include.cortexm_common diff --git a/cpu/kw2x/cpu.c b/cpu/kw2x/cpu.c index 678bb276e0..888c7adca2 100644 --- a/cpu/kw2x/cpu.c +++ b/cpu/kw2x/cpu.c @@ -20,6 +20,7 @@ */ #include +#include "cpu.h" #include "cpu_conf.h" #define FLASH_BASE (0x00000000) diff --git a/cpu/kw2x/reboot_arch.c b/cpu/kw2x/reboot_arch.c deleted file mode 100644 index c630456b9b..0000000000 --- a/cpu/kw2x/reboot_arch.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for more - * details. - */ - -/** - * @ingroup cpu_kw2x - * @{ - * - * @file - * @brief Implementation of the kernels reboot interface - * - * @author Hauke Petersen - * - * @} - */ - -#include - -#include "arch/reboot_arch.h" -#include "cpu.h" - - -int reboot_arch(int mode) -{ - printf("Going into reboot, mode %i\n", mode); - - NVIC_SystemReset(); - - return 0; -} diff --git a/cpu/kw2x/syscalls.c b/cpu/kw2x/syscalls.c deleted file mode 100644 index 9296e075fd..0000000000 --- a/cpu/kw2x/syscalls.c +++ /dev/null @@ -1,345 +0,0 @@ -/* - * Copyright (C) 2014 Freie Universität Berlin - * - * This file is subject to the terms and conditions of the GNU Lesser General - * Public License v2.1. See the file LICENSE in the top level directory for more - * details. - */ - -/** - * @ingroup cpu_kw2x - * @{ - * - * @file - * @brief NewLib system call implementations for KW2xD SiP - * - * @author Michael Baar - * @author Stefan Pfeiffer - * @author Hauke Petersen - * @author Johann Fischer - * - * @} - */ - -#include -#include -#include -#include -#include -#include -#include - -#include "board.h" -#include "thread.h" -#include "kernel.h" -#include "mutex.h" -#include "ringbuffer.h" -#include "irq.h" -#include "periph/uart.h" - -#ifdef MODULE_UART0 -#include "board_uart0.h" -#endif - -/** - * manage the heap - */ -extern uintptr_t __heap_start; /* start of heap memory space */ -extern uintptr_t __heap_max; /* maximum for end of heap memory space */ - -/* current position in heap */ -static caddr_t heap = {(caddr_t) &__heap_start}; -/* maximum position in heap */ -static const caddr_t heap_max = {(caddr_t) &__heap_max}; -/* start position in heap */ -static const caddr_t heap_start = {(caddr_t) &__heap_start}; - -#ifndef MODULE_UART0 -/** - * @brief use mutex for waiting on incoming UART chars - */ -static mutex_t uart_rx_mutex; -static char rx_buf_mem[STDIO_RX_BUFSIZE]; -static ringbuffer_t rx_buf; -#endif - -/** - * @brief Receive a new character from the UART and put it into the receive buffer - */ -void rx_cb(void *arg, char data) -{ -#ifndef MODULE_UART0 - (void)arg; - - ringbuffer_add_one(&rx_buf, data); - mutex_unlock(&uart_rx_mutex); -#else - - if (uart0_handler_pid) { - uart0_handle_incoming(data); - - uart0_notify_thread(); - } - -#endif -} - -/** - * @brief Initialize NewLib, called by __libc_init_array() from the startup script - */ -void _init(void) -{ -#ifndef MODULE_UART0 - mutex_init(&uart_rx_mutex); - ringbuffer_init(&rx_buf, rx_buf_mem, STDIO_RX_BUFSIZE); -#endif - uart_init(STDIO, STDIO_BAUDRATE, rx_cb, 0, 0); -} - -/** - * @brief Free resources on NewLib de-initialization, not used for RIOT - */ -void _fini(void) -{ - /* nothing to do here */ -} - -/** - * @brief Exit a program without cleaning up files - * - * If your system doesn't provide this, it is best to avoid linking with subroutines that - * require it (exit, system). - * - * @param n the exit code, 0 for all OK, >0 for not OK - */ -void _exit(int n) -{ - printf("#!exit %i: resetting\n", n); - NVIC_SystemReset(); - - while (1); -} - -/** - * @brief Allocate memory from the heap. - * - * The current heap implementation is very rudimentary, it is only able to allocate - * memory. But it does not - * - check if the returned address is valid (no check if the memory very exists) - * - have any means to free memory again - * - * @return [description] - */ -caddr_t _sbrk_r(struct _reent *r, size_t incr) -{ - uint32_t cpsr = disableIRQ(); - - caddr_t new_heap = heap + incr; - - /* check the heap for a chunk of the requested size */ - if (new_heap <= heap_max) { - caddr_t prev_heap = heap; - heap = new_heap; - - r->_errno = 0; - restoreIRQ(cpsr); - return prev_heap; - } - - restoreIRQ(cpsr); - r->_errno = ENOMEM; - return NULL; -} - -/** - * @brief Get the process-ID of the current thread - * - * @return the process ID of the current thread - */ -int _getpid(void) -{ - return sched_active_thread->pid; -} - -/** - * @brief Send a signal to a given thread - * - * @param r TODO - * @param pid TODO - * @param sig TODO - * - * @return TODO - */ -int _kill_r(struct _reent *r, int pid, int sig) -{ - r->_errno = ESRCH; /* not implemented yet */ - return -1; -} - -/** - * @brief Open a file - * - * @param r TODO - * @param name TODO - * @param mode TODO - * - * @return TODO - */ -int _open_r(struct _reent *r, const char *name, int mode) -{ - r->_errno = ENODEV; /* not implemented yet */ - return -1; -} - -/** - * @brief Read from a file - * - * All input is read from UART_0. The function will block until a byte is actually read. - * - * Note: the read function does not buffer - data will be lost if the function is not - * called fast enough. - * - * TODO: implement more sophisticated read call. - * - * @param r TODO - * @param fd TODO - * @param buffer TODO - * @param int TODO - * - * @return TODO - */ -int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count) -{ -#ifndef MODULE_UART0 - - while (rx_buf.avail == 0) { - mutex_lock(&uart_rx_mutex); - } - - return ringbuffer_get(&rx_buf, (char *)buffer, rx_buf.avail); -#else - char *res = (char *)buffer; - res[0] = (char)uart0_readc(); - return 1; -#endif -} - -/** - * @brief Write characters to a file - * - * All output is currently directed to UART_0, independent of the given file descriptor. - * The write call will further block until the byte is actually written to the UART. - * - * TODO: implement more sophisticated write call. - * - * @param r TODO - * @param fd TODO - * @param data TODO - * @param int TODO - * - * @return TODO - */ -int _write_r(struct _reent *r, int fd, const void *data, unsigned int count) -{ - char *c = (char *)data; - - for (int i = 0; i < count; i++) { - uart_write_blocking(STDIO, c[i]); - } - - return count; -} - -/** - * @brief Close a file - * - * @param r TODO - * @param fd TODO - * - * @return TODO - */ -int _close_r(struct _reent *r, int fd) -{ - r->_errno = ENODEV; /* not implemented yet */ - return -1; -} - -/** - * @brief Set position in a file - * - * @param r TODO - * @param fd TODO - * @param pos TODO - * @param dir TODO - * - * @return TODO - */ -_off_t _lseek_r(struct _reent *r, int fd, _off_t pos, int dir) -{ - r->_errno = ENODEV; /* not implemented yet */ - return -1; -} - -/** - * @brief Status of an open file - * - * @param r TODO - * @param fd TODO - * @param stat TODO - * - * @return TODO - */ -int _fstat_r(struct _reent *r, int fd, struct stat *st) -{ - r->_errno = ENODEV; /* not implemented yet */ - return -1; -} - -/** - * @brief Status of a file (by name) - * - * @param r TODO - * @param name TODO - * @param stat TODO - * - * @return TODO - */ -int _stat_r(struct _reent *r, char *name, struct stat *st) -{ - r->_errno = ENODEV; /* not implemented yet */ - return -1; -} - -/** - * @brief Query whether output stream is a terminal - * - * @param r TODO - * @param fd TODO - * - * @return TODO - */ -int _isatty_r(struct _reent *r, int fd) -{ - r->_errno = 0; - - if (fd == STDOUT_FILENO || fd == STDERR_FILENO) { - return 1; - } - else { - return 0; - } -} - -/** - * @brief Remove a file's directory entry - * - * @param r TODO - * @param path TODO - * - * @return TODO - */ -int _unlink_r(struct _reent *r, char *path) -{ - r->_errno = ENODEV; /* not implemented yet */ - return -1; -}