[core hwtimer] [cpu arm]
* adapted core and arm cpu
This commit is contained in:
parent
09721a2230
commit
918a31cf8c
@ -107,7 +107,7 @@ void hwtimer_wait(unsigned long ticks)
|
|||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
|
||||||
#include <board.h>
|
|
||||||
static int _hwtimer_set(unsigned long offset, void (*callback)(void*), void *ptr, bool absolute)
|
static int _hwtimer_set(unsigned long offset, void (*callback)(void*), void *ptr, bool absolute)
|
||||||
{
|
{
|
||||||
if (!inISR()) {
|
if (!inISR()) {
|
||||||
|
|||||||
@ -11,7 +11,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "board.h"
|
|
||||||
#include "bitarithm.h"
|
#include "bitarithm.h"
|
||||||
#include "hwtimer_cpu.h"
|
#include "hwtimer_cpu.h"
|
||||||
#include "hwtimer_arch.h"
|
#include "hwtimer_arch.h"
|
||||||
@ -133,6 +132,7 @@ void hwtimer_arch_set(unsigned long offset, short timer) {
|
|||||||
volatile unsigned long base = get_base_address(timer);
|
volatile unsigned long base = get_base_address(timer);
|
||||||
// Calculate match register address of corresponding timer
|
// Calculate match register address of corresponding timer
|
||||||
timer %= 4;
|
timer %= 4;
|
||||||
|
unsigned long cpsr = disableIRQ();
|
||||||
volatile unsigned long* addr = VULP(base + TXMR0 + 4 * timer);
|
volatile unsigned long* addr = VULP(base + TXMR0 + 4 * timer);
|
||||||
// Calculate match register value
|
// Calculate match register value
|
||||||
unsigned long value = *VULP(base + TXTC) + offset;
|
unsigned long value = *VULP(base + TXTC) + offset;
|
||||||
@ -140,6 +140,7 @@ void hwtimer_arch_set(unsigned long offset, short timer) {
|
|||||||
*VULP(base+TXIR) = 0x01 << timer; // reset interrupt register value for corresponding match register
|
*VULP(base+TXIR) = 0x01 << timer; // reset interrupt register value for corresponding match register
|
||||||
*VULP(base+TXMCR) &= ~(7 << (3 * timer)); // Clear all bits
|
*VULP(base+TXMCR) &= ~(7 << (3 * timer)); // Clear all bits
|
||||||
*VULP(base+TXMCR) |= (MR0I << (3 * timer)); // enable interrupt for match register
|
*VULP(base+TXMCR) |= (MR0I << (3 * timer)); // enable interrupt for match register
|
||||||
|
restoreIRQ(cpsr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hwtimer_arch_set_absolute(unsigned long value, short timer) {
|
void hwtimer_arch_set_absolute(unsigned long value, short timer) {
|
||||||
|
|||||||
@ -31,9 +31,9 @@ and the mailinglist (subscription via web site)
|
|||||||
*
|
*
|
||||||
* @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project
|
* @author Freie Universität Berlin, Computer Systems & Telematics, FeuerWhere project
|
||||||
* @author Michael Baar <michael.baar@fu-berlin.de>
|
* @author Michael Baar <michael.baar@fu-berlin.de>
|
||||||
* @version $Revision$
|
* @version $Revision: 3914 $
|
||||||
*
|
*
|
||||||
* @note $Id$
|
* @note $Id: syscalls.c 3914 2012-02-14 09:31:06Z hwill $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -43,11 +43,19 @@ and the mailinglist (subscription via web site)
|
|||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/unistd.h>
|
#include <sys/unistd.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <board.h>
|
|
||||||
|
|
||||||
// core
|
// core
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
// sys
|
||||||
|
#include "lpm.h"
|
||||||
|
#include "tracelog.h"
|
||||||
|
#include "hal-syscalls.h"
|
||||||
|
|
||||||
|
/* When using the HAL standard in and out are handled by HAL
|
||||||
|
devices. */
|
||||||
|
#if FEUERWARE_CONF_ENABLE_HAL
|
||||||
|
#include "hal.h"
|
||||||
|
#include "interface-chardevice.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define DEBUG_SYSCALLS 0
|
#define DEBUG_SYSCALLS 0
|
||||||
#if DEBUG_SYSCALLS
|
#if DEBUG_SYSCALLS
|
||||||
@ -56,26 +64,48 @@ and the mailinglist (subscription via web site)
|
|||||||
#define PRINTF(...)
|
#define PRINTF(...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODULE_FAT
|
||||||
|
#include "ff_ansi.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name Heaps (defined in linker script)
|
* @name Heaps (defined in linker script)
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
#define NUM_HEAPS 2
|
#define NUM_HEAPS 3//2
|
||||||
|
|
||||||
extern uintptr_t __heap1_start; ///< start of heap memory space
|
extern uintptr_t __heap1_start; ///< start of heap memory space
|
||||||
extern uintptr_t __heap1_max; ///< maximum for end of heap memory space
|
extern uintptr_t __heap1_max; ///< maximum for end of heap memory space
|
||||||
extern uintptr_t __heap2_start; ///< start of heap memory space
|
extern uintptr_t __heap2_start; ///< start of heap memory space
|
||||||
extern uintptr_t __heap2_max; ///< maximum for end of heap memory space
|
extern uintptr_t __heap2_max; ///< maximum for end of heap memory space
|
||||||
|
extern uintptr_t __heap3_start; ///< start of heap memory space
|
||||||
|
extern uintptr_t __heap3_max; ///< maximum for end of heap memory space
|
||||||
|
|
||||||
|
|
||||||
/// current position in heap
|
/// current position in heap
|
||||||
static caddr_t heap[NUM_HEAPS] = {(caddr_t)&__heap1_start,(caddr_t)&__heap2_start};
|
static caddr_t heap[NUM_HEAPS] = {(caddr_t)&__heap1_start,(caddr_t)&__heap3_start,(caddr_t)&__heap2_start}; // add heap3 before heap2 cause Heap3 address is lower then addr of heap2
|
||||||
/// maximum position in heap
|
/// maximum position in heap
|
||||||
static const caddr_t heap_max[NUM_HEAPS] = {(caddr_t)&__heap1_max,(caddr_t)&__heap2_max};
|
static const caddr_t heap_max[NUM_HEAPS] = {(caddr_t)&__heap1_max,(caddr_t)&__heap3_max,(caddr_t)&__heap2_max};
|
||||||
|
// start position in heap
|
||||||
|
static const caddr_t heap_start[NUM_HEAPS] = {(caddr_t)&__heap1_start,(caddr_t)&__heap3_start,(caddr_t)&__heap2_start};
|
||||||
|
// current heap in use
|
||||||
|
volatile static uint8_t iUsedHeap = 0;
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
/*-----------------------------------------------------------------------------------*/
|
||||||
|
void heap_stats(void) {
|
||||||
|
for(int i = 0; i < NUM_HEAPS; i++)
|
||||||
|
printf("# heap %i: %p -- %p -> %p (%li of %li free)\n", i, heap_start[i], heap[i], heap_max[i],
|
||||||
|
(uint32_t)heap_max[i] - (uint32_t)heap[i], (uint32_t)heap_max[i] - (uint32_t)heap_start[i]);
|
||||||
|
}
|
||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
void __assert_func(const char *file, int line, const char *func, const char *failedexpr)
|
void __assert_func(const char *file, int line, const char *func, const char *failedexpr)
|
||||||
{
|
{
|
||||||
|
#if SYSLOG_CONF_ASSERT
|
||||||
|
trace_number(TRACELOG_EV_ASSERTION, line);
|
||||||
|
syslog(SL_EMERGENCY, "assert", "%s() in %s:%u\n", func, file, line);
|
||||||
|
#endif
|
||||||
printf("#! assertion %s failed\n\t%s() in %s:%u\n", failedexpr, func, file, line );
|
printf("#! assertion %s failed\n\t%s() in %s:%u\n", failedexpr, func, file, line );
|
||||||
_exit(3);
|
_exit(3);
|
||||||
}
|
}
|
||||||
@ -87,21 +117,41 @@ void __assert(const char *file, int line, const char *failedexpr)
|
|||||||
/*-----------------------------------------------------------------------------------*/
|
/*-----------------------------------------------------------------------------------*/
|
||||||
caddr_t _sbrk_r(struct _reent *r, size_t incr)
|
caddr_t _sbrk_r(struct _reent *r, size_t incr)
|
||||||
{
|
{
|
||||||
/* check all heaps for a chunk of the requested size */
|
if(incr < 0)
|
||||||
for( int i = 0; i < NUM_HEAPS; i++ ) {
|
{
|
||||||
caddr_t new_heap = heap[i] + incr;
|
puts("[syscalls] Negative Values for _sbrk_r are not supported");
|
||||||
|
r->_errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if( new_heap <= heap_max[i] ) {
|
uint32_t cpsr = disableIRQ();
|
||||||
caddr_t prev_heap = heap[i];
|
|
||||||
heap[i] = new_heap;
|
/* check all heaps for a chunk of the requested size */
|
||||||
|
for( ; iUsedHeap < NUM_HEAPS; iUsedHeap++ ) {
|
||||||
|
caddr_t new_heap = heap[iUsedHeap] + incr;
|
||||||
|
|
||||||
|
#ifdef MODULE_TRACELOG
|
||||||
|
trace_pointer(TRACELOG_EV_MEMORY, heap[iUsedHeap]);
|
||||||
|
#endif
|
||||||
|
if( new_heap <= heap_max[iUsedHeap] ) {
|
||||||
|
caddr_t prev_heap = heap[iUsedHeap];
|
||||||
|
#ifdef MODULE_TRACELOG
|
||||||
|
trace_pointer(TRACELOG_EV_MEMORY, new_heap);
|
||||||
|
#endif
|
||||||
|
heap[iUsedHeap] = new_heap;
|
||||||
|
|
||||||
r->_errno = 0;
|
r->_errno = 0;
|
||||||
|
restoreIRQ(cpsr);
|
||||||
return prev_heap;
|
return prev_heap;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
restoreIRQ(cpsr);
|
||||||
return NULL;
|
#ifdef MODULE_TRACELOG
|
||||||
|
trace_string(TRACELOG_EV_MEMORY, "heap!"); // heap full
|
||||||
|
#endif
|
||||||
|
|
||||||
|
r->_errno = ENOMEM;
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int _isatty_r(struct _reent *r, int fd)
|
int _isatty_r(struct _reent *r, int fd)
|
||||||
@ -119,6 +169,9 @@ _off_t _lseek_r(struct _reent *r, int fd, _off_t pos, int whence)
|
|||||||
PRINTF("lseek [%i] pos %li whence %i\n", fd, pos, whence);
|
PRINTF("lseek [%i] pos %li whence %i\n", fd, pos, whence);
|
||||||
|
|
||||||
r->_errno = ENODEV;
|
r->_errno = ENODEV;
|
||||||
|
#ifdef MODULE_FAT
|
||||||
|
result = ff_lseek_r(r, fd, pos, whence);
|
||||||
|
#endif
|
||||||
|
|
||||||
PRINTF("lseek returned %li (0 is success)\n", result);
|
PRINTF("lseek returned %li (0 is success)\n", result);
|
||||||
return result;
|
return result;
|
||||||
@ -129,7 +182,10 @@ int _open_r(struct _reent *r, const char *name, int mode)
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
PRINTF("open '%s' mode %#x\n", name, mode);
|
PRINTF("open '%s' mode %#x\n", name, mode);
|
||||||
|
|
||||||
r->_errno = ENODEV;
|
r->_errno = ENODEV; // no such device
|
||||||
|
#ifdef MODULE_FAT
|
||||||
|
ret = ff_open_r(r,name,mode);
|
||||||
|
#endif
|
||||||
|
|
||||||
PRINTF("open [%i] errno %i\n", ret, r->_errno);
|
PRINTF("open [%i] errno %i\n", ret, r->_errno);
|
||||||
return ret;
|
return ret;
|
||||||
@ -138,9 +194,12 @@ int _open_r(struct _reent *r, const char *name, int mode)
|
|||||||
int _stat_r(struct _reent *r, char *name, struct stat *st)
|
int _stat_r(struct _reent *r, char *name, struct stat *st)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
PRINTF("_stat_r '%s' \n", name);
|
||||||
r->_errno = ENODEV;
|
r->_errno = ENODEV; // no such device
|
||||||
|
#ifdef MODULE_FAT
|
||||||
|
ret = ff_stat_r(r,name,st);
|
||||||
|
#endif
|
||||||
|
PRINTF("_stat_r [%i] errno %i\n", ret, r->_errno);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
@ -148,34 +207,48 @@ int _fstat_r(struct _reent *r, int fd, struct stat * st)
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
|
r->_errno = 0;
|
||||||
memset(st, 0, sizeof(*st));
|
memset(st, 0, sizeof(*st));
|
||||||
if( fd == STDOUT_FILENO || fd == STDERR_FILENO ) {
|
if( fd == STDOUT_FILENO || fd == STDERR_FILENO ) {
|
||||||
st->st_mode = S_IFCHR;
|
st->st_mode = S_IFCHR;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
#ifdef MODULE_FAT
|
||||||
|
PRINTF("_fstat_r '%i' \n", fd);
|
||||||
|
|
||||||
|
ret = ff_fstat_r(r,fd,st);
|
||||||
|
PRINTF("_fstat_r [%i] errno %i\n", ret, r->_errno);
|
||||||
|
|
||||||
|
#else
|
||||||
r->_errno = ENODEV;
|
r->_errno = ENODEV;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern int fw_puts(char* data, int count);
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int _write_r(struct _reent *r, int fd, const void *data, unsigned int count)
|
int _write_r(struct _reent *r, int fd, const void *data, unsigned int count)
|
||||||
{
|
{
|
||||||
int result = EOF;
|
int result = EOF;
|
||||||
r->_errno = 0;
|
r->_errno = EBADF;
|
||||||
|
|
||||||
switch(fd) {
|
switch(fd) {
|
||||||
case STDOUT_FILENO:
|
case STDOUT_FILENO:
|
||||||
case STDERR_FILENO:
|
case STDERR_FILENO:
|
||||||
|
#if FEUERWARE_CONF_ENABLE_HAL
|
||||||
|
if( stdio != NULL )
|
||||||
|
result = chardevice_write(stdio, (char*)data, count);
|
||||||
|
else if( hal_state == HAL_NOT_INITIALIZED )
|
||||||
|
result = fw_puts((char*)data, count);
|
||||||
|
#else
|
||||||
result = fw_puts((char*)data, count);
|
result = fw_puts((char*)data, count);
|
||||||
|
#endif
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
PRINTF("write [%i] data @%p count %i\n", fd, data, count);
|
#ifdef MODULE_FAT
|
||||||
|
result = ff_write_r(r, fd, data, count);
|
||||||
PRINTF("write [%i] returned %i errno %i\n", fd, result, r->_errno);
|
#endif
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,46 +257,44 @@ int _write_r(struct _reent *r, int fd, const void *data, unsigned int count)
|
|||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count)
|
int _read_r(struct _reent *r, int fd, void *buffer, unsigned int count)
|
||||||
{
|
{
|
||||||
int result = EOF;
|
int result = -1;
|
||||||
r->_errno = 0;
|
r->_errno = EBADF;
|
||||||
|
#ifdef MODULE_FAT
|
||||||
PRINTF("read [%i] buffer @%p count %i\n", fd, buffer, count);
|
result = ff_read_r(r, fd, buffer, count);
|
||||||
PRINTF("read [%i] returned %i\n", fd, result);
|
#endif
|
||||||
|
return result;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int _close_r(struct _reent *r, int fd)
|
int _close_r(struct _reent *r, int fd)
|
||||||
{
|
{
|
||||||
int result = 0;
|
int ret = -1;
|
||||||
r->_errno = 0;
|
r->_errno = EBADF;
|
||||||
|
#ifdef MODULE_FAT
|
||||||
PRINTF("close [%i]\n", fd);
|
ret = ff_close_r(r, fd);
|
||||||
PRINTF("close returned %i errno %i\n", result, errno);
|
#endif
|
||||||
|
return ret;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int _unlink_r(struct _reent *r, char* path)
|
int _unlink_r(struct _reent *r, char* path)
|
||||||
{
|
{
|
||||||
int result = -1;
|
int ret = -1;
|
||||||
r->_errno = ENODEV;
|
r->_errno = ENODEV;
|
||||||
|
#ifdef MODULE_FAT
|
||||||
PRINTF("unlink '%s'\n", path);
|
ret = ff_unlink_r(r, path);
|
||||||
PRINTF("unlink returned %i errno %i\n", result, errno);
|
#endif
|
||||||
|
return ret;
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void _exit(int n)
|
void _exit(int n)
|
||||||
{
|
{
|
||||||
|
#ifdef MODULE_TRACELOG
|
||||||
|
trace_number(TRACELOG_EV_EXIT, n);
|
||||||
|
#endif
|
||||||
printf("#! exit %i: resetting\n", n);
|
printf("#! exit %i: resetting\n", n);
|
||||||
|
|
||||||
stdio_flush();
|
stdio_flush();
|
||||||
|
|
||||||
while(1);
|
|
||||||
|
|
||||||
arm_reset();
|
arm_reset();
|
||||||
|
while(1);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int _getpid(void)
|
int _getpid(void)
|
||||||
@ -233,9 +304,10 @@ int _getpid(void)
|
|||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
int _kill_r(struct _reent *r, int pid, int sig)
|
int _kill_r(struct _reent *r, int pid, int sig)
|
||||||
{
|
{
|
||||||
|
/* not implemented */
|
||||||
r->_errno = ESRCH; // no such process
|
r->_errno = ESRCH; // no such process
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
void _init(void){}
|
||||||
void _fini(void) {}
|
void _fini(void){}
|
||||||
|
|||||||
@ -62,7 +62,9 @@ void cpu_clock_scale(uint32_t source, uint32_t target, uint32_t* prescale) {
|
|||||||
|
|
||||||
lpc2387_pclk_scale(source, target, &pclksel, prescale);
|
lpc2387_pclk_scale(source, target, &pclksel, prescale);
|
||||||
|
|
||||||
PCLKSEL0 = (PCLKSEL0 & ~(BIT2|BIT3)) | (pclksel << 2);
|
PCLKSEL0 = (PCLKSEL0 & ~(BIT2|BIT3)) | (pclksel << 2); // timer 0
|
||||||
|
PCLKSEL0 = (PCLKSEL0 & ~(BIT4|BIT5)) | (pclksel << 4); // timer 1
|
||||||
|
PCLKSEL1 = (PCLKSEL1 & ~(BIT12|BIT13)) | (pclksel << 12); // timer 2
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user