Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed-src by
vendor/NXP/LPC11U24/cmsis/GCC_CS/sys.cpp@10:3bc89ef62ce7, 2013-06-14 (annotated)
- Committer:
- emilmont
- Date:
- Fri Jun 14 17:49:17 2013 +0100
- Revision:
- 10:3bc89ef62ce7
Unify mbed library sources
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emilmont | 10:3bc89ef62ce7 | 1 | #include "cmsis.h" |
emilmont | 10:3bc89ef62ce7 | 2 | #include <sys/types.h> |
emilmont | 10:3bc89ef62ce7 | 3 | #include <errno.h> |
emilmont | 10:3bc89ef62ce7 | 4 | |
emilmont | 10:3bc89ef62ce7 | 5 | extern "C" { |
emilmont | 10:3bc89ef62ce7 | 6 | |
emilmont | 10:3bc89ef62ce7 | 7 | struct SCS3Regions { |
emilmont | 10:3bc89ef62ce7 | 8 | unsigned long Dummy; |
emilmont | 10:3bc89ef62ce7 | 9 | unsigned long* InitRam; |
emilmont | 10:3bc89ef62ce7 | 10 | unsigned long* StartRam; |
emilmont | 10:3bc89ef62ce7 | 11 | unsigned long InitSizeRam; |
emilmont | 10:3bc89ef62ce7 | 12 | unsigned long ZeroSizeRam; |
emilmont | 10:3bc89ef62ce7 | 13 | }; |
emilmont | 10:3bc89ef62ce7 | 14 | |
emilmont | 10:3bc89ef62ce7 | 15 | extern unsigned long __cs3_regions; |
emilmont | 10:3bc89ef62ce7 | 16 | extern unsigned long __cs3_heap_start; |
emilmont | 10:3bc89ef62ce7 | 17 | |
emilmont | 10:3bc89ef62ce7 | 18 | int main(void); |
emilmont | 10:3bc89ef62ce7 | 19 | void __libc_init_array(void); |
emilmont | 10:3bc89ef62ce7 | 20 | void exit(int ErrorCode); |
emilmont | 10:3bc89ef62ce7 | 21 | |
emilmont | 10:3bc89ef62ce7 | 22 | static void *heap_pointer = NULL; |
emilmont | 10:3bc89ef62ce7 | 23 | |
emilmont | 10:3bc89ef62ce7 | 24 | void __cs3_start_c(void) { |
emilmont | 10:3bc89ef62ce7 | 25 | static SCS3Regions* pCS3Regions = (SCS3Regions*)&__cs3_regions; |
emilmont | 10:3bc89ef62ce7 | 26 | unsigned long* pulDest; |
emilmont | 10:3bc89ef62ce7 | 27 | unsigned long* pulSrc; |
emilmont | 10:3bc89ef62ce7 | 28 | unsigned long ByteCount; |
emilmont | 10:3bc89ef62ce7 | 29 | unsigned long i; |
emilmont | 10:3bc89ef62ce7 | 30 | |
emilmont | 10:3bc89ef62ce7 | 31 | pulSrc = pCS3Regions->InitRam; |
emilmont | 10:3bc89ef62ce7 | 32 | pulDest = pCS3Regions->StartRam; |
emilmont | 10:3bc89ef62ce7 | 33 | ByteCount = pCS3Regions->InitSizeRam; |
emilmont | 10:3bc89ef62ce7 | 34 | if (pulSrc != pulDest) { |
emilmont | 10:3bc89ef62ce7 | 35 | for(i = 0 ; i < ByteCount ; i += sizeof(unsigned long)) { |
emilmont | 10:3bc89ef62ce7 | 36 | *(pulDest++) = *(pulSrc++); |
emilmont | 10:3bc89ef62ce7 | 37 | } |
emilmont | 10:3bc89ef62ce7 | 38 | } else { |
emilmont | 10:3bc89ef62ce7 | 39 | pulDest = (unsigned long*)(void*)((char*)pulDest + ByteCount); |
emilmont | 10:3bc89ef62ce7 | 40 | } |
emilmont | 10:3bc89ef62ce7 | 41 | |
emilmont | 10:3bc89ef62ce7 | 42 | ByteCount = pCS3Regions->ZeroSizeRam; |
emilmont | 10:3bc89ef62ce7 | 43 | for(i = 0 ; i < ByteCount ; i += sizeof(unsigned long)) { |
emilmont | 10:3bc89ef62ce7 | 44 | *(pulDest++) = 0; |
emilmont | 10:3bc89ef62ce7 | 45 | } |
emilmont | 10:3bc89ef62ce7 | 46 | |
emilmont | 10:3bc89ef62ce7 | 47 | heap_pointer = &__cs3_heap_start; |
emilmont | 10:3bc89ef62ce7 | 48 | __libc_init_array(); |
emilmont | 10:3bc89ef62ce7 | 49 | exit(main()); |
emilmont | 10:3bc89ef62ce7 | 50 | } |
emilmont | 10:3bc89ef62ce7 | 51 | |
emilmont | 10:3bc89ef62ce7 | 52 | int _kill(int pid, int sig) { |
emilmont | 10:3bc89ef62ce7 | 53 | errno = EINVAL; |
emilmont | 10:3bc89ef62ce7 | 54 | return -1; |
emilmont | 10:3bc89ef62ce7 | 55 | } |
emilmont | 10:3bc89ef62ce7 | 56 | |
emilmont | 10:3bc89ef62ce7 | 57 | void _exit(int status) { |
emilmont | 10:3bc89ef62ce7 | 58 | exit(status); |
emilmont | 10:3bc89ef62ce7 | 59 | } |
emilmont | 10:3bc89ef62ce7 | 60 | |
emilmont | 10:3bc89ef62ce7 | 61 | int _getpid(void) { |
emilmont | 10:3bc89ef62ce7 | 62 | return 1; |
emilmont | 10:3bc89ef62ce7 | 63 | } |
emilmont | 10:3bc89ef62ce7 | 64 | |
emilmont | 10:3bc89ef62ce7 | 65 | void *_sbrk(unsigned int incr) { |
emilmont | 10:3bc89ef62ce7 | 66 | void *mem; |
emilmont | 10:3bc89ef62ce7 | 67 | |
emilmont | 10:3bc89ef62ce7 | 68 | unsigned int next = ((((unsigned int)heap_pointer + incr) + 7) & ~7); |
emilmont | 10:3bc89ef62ce7 | 69 | if (next > __get_MSP()) { |
emilmont | 10:3bc89ef62ce7 | 70 | mem = NULL; |
emilmont | 10:3bc89ef62ce7 | 71 | } else { |
emilmont | 10:3bc89ef62ce7 | 72 | mem = (void *)heap_pointer; |
emilmont | 10:3bc89ef62ce7 | 73 | } |
emilmont | 10:3bc89ef62ce7 | 74 | heap_pointer = (void *)next; |
emilmont | 10:3bc89ef62ce7 | 75 | |
emilmont | 10:3bc89ef62ce7 | 76 | return mem; |
emilmont | 10:3bc89ef62ce7 | 77 | } |
emilmont | 10:3bc89ef62ce7 | 78 | |
emilmont | 10:3bc89ef62ce7 | 79 | } |