mbed library sources modified for open wear
Dependents: openwear-lifelogger-example
Fork of mbed-src by
targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/TOOLCHAIN_GCC_CS/sys.cpp@310:6188e0254baa, 2014-09-16 (annotated)
- Committer:
- janekm
- Date:
- Tue Sep 16 22:42:01 2014 +0000
- Revision:
- 310:6188e0254baa
- Parent:
- 30:91c1d09ada54
N/A
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 30:91c1d09ada54 | 1 | #include "cmsis.h" |
mbed_official | 30:91c1d09ada54 | 2 | #include <sys/types.h> |
mbed_official | 30:91c1d09ada54 | 3 | #include <errno.h> |
mbed_official | 30:91c1d09ada54 | 4 | |
mbed_official | 30:91c1d09ada54 | 5 | extern "C" { |
mbed_official | 30:91c1d09ada54 | 6 | |
mbed_official | 30:91c1d09ada54 | 7 | struct SCS3Regions { |
mbed_official | 30:91c1d09ada54 | 8 | unsigned long Dummy; |
mbed_official | 30:91c1d09ada54 | 9 | unsigned long* InitRam; |
mbed_official | 30:91c1d09ada54 | 10 | unsigned long* StartRam; |
mbed_official | 30:91c1d09ada54 | 11 | unsigned long InitSizeRam; |
mbed_official | 30:91c1d09ada54 | 12 | unsigned long ZeroSizeRam; |
mbed_official | 30:91c1d09ada54 | 13 | }; |
mbed_official | 30:91c1d09ada54 | 14 | |
mbed_official | 30:91c1d09ada54 | 15 | extern unsigned long __cs3_regions; |
mbed_official | 30:91c1d09ada54 | 16 | extern unsigned long __cs3_heap_start; |
mbed_official | 30:91c1d09ada54 | 17 | |
mbed_official | 30:91c1d09ada54 | 18 | int main(void); |
mbed_official | 30:91c1d09ada54 | 19 | void __libc_init_array(void); |
mbed_official | 30:91c1d09ada54 | 20 | void exit(int ErrorCode); |
mbed_official | 30:91c1d09ada54 | 21 | |
mbed_official | 30:91c1d09ada54 | 22 | static void *heap_pointer = NULL; |
mbed_official | 30:91c1d09ada54 | 23 | |
mbed_official | 30:91c1d09ada54 | 24 | void __cs3_start_c(void) { |
mbed_official | 30:91c1d09ada54 | 25 | static SCS3Regions* pCS3Regions = (SCS3Regions*)&__cs3_regions; |
mbed_official | 30:91c1d09ada54 | 26 | unsigned long* pulDest; |
mbed_official | 30:91c1d09ada54 | 27 | unsigned long* pulSrc; |
mbed_official | 30:91c1d09ada54 | 28 | unsigned long ByteCount; |
mbed_official | 30:91c1d09ada54 | 29 | unsigned long i; |
mbed_official | 30:91c1d09ada54 | 30 | |
mbed_official | 30:91c1d09ada54 | 31 | pulSrc = pCS3Regions->InitRam; |
mbed_official | 30:91c1d09ada54 | 32 | pulDest = pCS3Regions->StartRam; |
mbed_official | 30:91c1d09ada54 | 33 | ByteCount = pCS3Regions->InitSizeRam; |
mbed_official | 30:91c1d09ada54 | 34 | if (pulSrc != pulDest) { |
mbed_official | 30:91c1d09ada54 | 35 | for(i = 0 ; i < ByteCount ; i += sizeof(unsigned long)) { |
mbed_official | 30:91c1d09ada54 | 36 | *(pulDest++) = *(pulSrc++); |
mbed_official | 30:91c1d09ada54 | 37 | } |
mbed_official | 30:91c1d09ada54 | 38 | } else { |
mbed_official | 30:91c1d09ada54 | 39 | pulDest = (unsigned long*)(void*)((char*)pulDest + ByteCount); |
mbed_official | 30:91c1d09ada54 | 40 | } |
mbed_official | 30:91c1d09ada54 | 41 | |
mbed_official | 30:91c1d09ada54 | 42 | ByteCount = pCS3Regions->ZeroSizeRam; |
mbed_official | 30:91c1d09ada54 | 43 | for(i = 0 ; i < ByteCount ; i += sizeof(unsigned long)) { |
mbed_official | 30:91c1d09ada54 | 44 | *(pulDest++) = 0; |
mbed_official | 30:91c1d09ada54 | 45 | } |
mbed_official | 30:91c1d09ada54 | 46 | |
mbed_official | 30:91c1d09ada54 | 47 | heap_pointer = &__cs3_heap_start; |
mbed_official | 30:91c1d09ada54 | 48 | __libc_init_array(); |
mbed_official | 30:91c1d09ada54 | 49 | exit(main()); |
mbed_official | 30:91c1d09ada54 | 50 | } |
mbed_official | 30:91c1d09ada54 | 51 | |
mbed_official | 30:91c1d09ada54 | 52 | int _kill(int pid, int sig) { |
mbed_official | 30:91c1d09ada54 | 53 | errno = EINVAL; |
mbed_official | 30:91c1d09ada54 | 54 | return -1; |
mbed_official | 30:91c1d09ada54 | 55 | } |
mbed_official | 30:91c1d09ada54 | 56 | |
mbed_official | 30:91c1d09ada54 | 57 | void _exit(int status) { |
mbed_official | 30:91c1d09ada54 | 58 | exit(status); |
mbed_official | 30:91c1d09ada54 | 59 | } |
mbed_official | 30:91c1d09ada54 | 60 | |
mbed_official | 30:91c1d09ada54 | 61 | int _getpid(void) { |
mbed_official | 30:91c1d09ada54 | 62 | return 1; |
mbed_official | 30:91c1d09ada54 | 63 | } |
mbed_official | 30:91c1d09ada54 | 64 | |
mbed_official | 30:91c1d09ada54 | 65 | void *_sbrk(unsigned int incr) { |
mbed_official | 30:91c1d09ada54 | 66 | void *mem; |
mbed_official | 30:91c1d09ada54 | 67 | |
mbed_official | 30:91c1d09ada54 | 68 | unsigned int next = ((((unsigned int)heap_pointer + incr) + 7) & ~7); |
mbed_official | 30:91c1d09ada54 | 69 | if (next > __get_MSP()) { |
mbed_official | 30:91c1d09ada54 | 70 | mem = NULL; |
mbed_official | 30:91c1d09ada54 | 71 | } else { |
mbed_official | 30:91c1d09ada54 | 72 | mem = (void *)heap_pointer; |
mbed_official | 30:91c1d09ada54 | 73 | } |
mbed_official | 30:91c1d09ada54 | 74 | heap_pointer = (void *)next; |
mbed_official | 30:91c1d09ada54 | 75 | |
mbed_official | 30:91c1d09ada54 | 76 | return mem; |
mbed_official | 30:91c1d09ada54 | 77 | } |
mbed_official | 30:91c1d09ada54 | 78 | |
mbed_official | 30:91c1d09ada54 | 79 | } |