Mouse code for the MacroRat
mbed-dev/targets/TARGET_NXP/TARGET_LPC176X/device/TOOLCHAIN_GCC_CS/sys.cpp@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 18:6a4db94011d3
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | #include "cmsis.h" |
sahilmgandhi | 18:6a4db94011d3 | 2 | #include <sys/types.h> |
sahilmgandhi | 18:6a4db94011d3 | 3 | #include <errno.h> |
sahilmgandhi | 18:6a4db94011d3 | 4 | |
sahilmgandhi | 18:6a4db94011d3 | 5 | extern "C" { |
sahilmgandhi | 18:6a4db94011d3 | 6 | |
sahilmgandhi | 18:6a4db94011d3 | 7 | struct SCS3Regions { |
sahilmgandhi | 18:6a4db94011d3 | 8 | unsigned long Dummy; |
sahilmgandhi | 18:6a4db94011d3 | 9 | unsigned long* InitRam; |
sahilmgandhi | 18:6a4db94011d3 | 10 | unsigned long* StartRam; |
sahilmgandhi | 18:6a4db94011d3 | 11 | unsigned long InitSizeRam; |
sahilmgandhi | 18:6a4db94011d3 | 12 | unsigned long ZeroSizeRam; |
sahilmgandhi | 18:6a4db94011d3 | 13 | }; |
sahilmgandhi | 18:6a4db94011d3 | 14 | |
sahilmgandhi | 18:6a4db94011d3 | 15 | extern unsigned long __cs3_regions; |
sahilmgandhi | 18:6a4db94011d3 | 16 | extern unsigned long __cs3_heap_start; |
sahilmgandhi | 18:6a4db94011d3 | 17 | |
sahilmgandhi | 18:6a4db94011d3 | 18 | int main(void); |
sahilmgandhi | 18:6a4db94011d3 | 19 | void __libc_init_array(void); |
sahilmgandhi | 18:6a4db94011d3 | 20 | void exit(int ErrorCode); |
sahilmgandhi | 18:6a4db94011d3 | 21 | |
sahilmgandhi | 18:6a4db94011d3 | 22 | static void *heap_pointer = NULL; |
sahilmgandhi | 18:6a4db94011d3 | 23 | |
sahilmgandhi | 18:6a4db94011d3 | 24 | void __cs3_start_c(void) { |
sahilmgandhi | 18:6a4db94011d3 | 25 | static SCS3Regions* pCS3Regions = (SCS3Regions*)&__cs3_regions; |
sahilmgandhi | 18:6a4db94011d3 | 26 | unsigned long* pulDest; |
sahilmgandhi | 18:6a4db94011d3 | 27 | unsigned long* pulSrc; |
sahilmgandhi | 18:6a4db94011d3 | 28 | unsigned long ByteCount; |
sahilmgandhi | 18:6a4db94011d3 | 29 | unsigned long i; |
sahilmgandhi | 18:6a4db94011d3 | 30 | |
sahilmgandhi | 18:6a4db94011d3 | 31 | pulSrc = pCS3Regions->InitRam; |
sahilmgandhi | 18:6a4db94011d3 | 32 | pulDest = pCS3Regions->StartRam; |
sahilmgandhi | 18:6a4db94011d3 | 33 | ByteCount = pCS3Regions->InitSizeRam; |
sahilmgandhi | 18:6a4db94011d3 | 34 | if (pulSrc != pulDest) { |
sahilmgandhi | 18:6a4db94011d3 | 35 | for(i = 0 ; i < ByteCount ; i += sizeof(unsigned long)) { |
sahilmgandhi | 18:6a4db94011d3 | 36 | *(pulDest++) = *(pulSrc++); |
sahilmgandhi | 18:6a4db94011d3 | 37 | } |
sahilmgandhi | 18:6a4db94011d3 | 38 | } else { |
sahilmgandhi | 18:6a4db94011d3 | 39 | pulDest = (unsigned long*)(void*)((char*)pulDest + ByteCount); |
sahilmgandhi | 18:6a4db94011d3 | 40 | } |
sahilmgandhi | 18:6a4db94011d3 | 41 | |
sahilmgandhi | 18:6a4db94011d3 | 42 | ByteCount = pCS3Regions->ZeroSizeRam; |
sahilmgandhi | 18:6a4db94011d3 | 43 | for(i = 0 ; i < ByteCount ; i += sizeof(unsigned long)) { |
sahilmgandhi | 18:6a4db94011d3 | 44 | *(pulDest++) = 0; |
sahilmgandhi | 18:6a4db94011d3 | 45 | } |
sahilmgandhi | 18:6a4db94011d3 | 46 | |
sahilmgandhi | 18:6a4db94011d3 | 47 | heap_pointer = &__cs3_heap_start; |
sahilmgandhi | 18:6a4db94011d3 | 48 | __libc_init_array(); |
sahilmgandhi | 18:6a4db94011d3 | 49 | |
sahilmgandhi | 18:6a4db94011d3 | 50 | exit(main()); |
sahilmgandhi | 18:6a4db94011d3 | 51 | } |
sahilmgandhi | 18:6a4db94011d3 | 52 | |
sahilmgandhi | 18:6a4db94011d3 | 53 | int _kill(int pid, int sig) { |
sahilmgandhi | 18:6a4db94011d3 | 54 | errno = EINVAL; |
sahilmgandhi | 18:6a4db94011d3 | 55 | return -1; |
sahilmgandhi | 18:6a4db94011d3 | 56 | } |
sahilmgandhi | 18:6a4db94011d3 | 57 | |
sahilmgandhi | 18:6a4db94011d3 | 58 | void _exit(int status) { |
sahilmgandhi | 18:6a4db94011d3 | 59 | exit(status); |
sahilmgandhi | 18:6a4db94011d3 | 60 | } |
sahilmgandhi | 18:6a4db94011d3 | 61 | |
sahilmgandhi | 18:6a4db94011d3 | 62 | int _getpid(void) { |
sahilmgandhi | 18:6a4db94011d3 | 63 | return 1; |
sahilmgandhi | 18:6a4db94011d3 | 64 | } |
sahilmgandhi | 18:6a4db94011d3 | 65 | |
sahilmgandhi | 18:6a4db94011d3 | 66 | void *_sbrk(unsigned int incr) { |
sahilmgandhi | 18:6a4db94011d3 | 67 | void *mem; |
sahilmgandhi | 18:6a4db94011d3 | 68 | |
sahilmgandhi | 18:6a4db94011d3 | 69 | unsigned int next = ((((unsigned int)heap_pointer + incr) + 7) & ~7); |
sahilmgandhi | 18:6a4db94011d3 | 70 | if (next > __get_MSP()) { |
sahilmgandhi | 18:6a4db94011d3 | 71 | mem = NULL; |
sahilmgandhi | 18:6a4db94011d3 | 72 | } else { |
sahilmgandhi | 18:6a4db94011d3 | 73 | mem = (void *)heap_pointer; |
sahilmgandhi | 18:6a4db94011d3 | 74 | } |
sahilmgandhi | 18:6a4db94011d3 | 75 | heap_pointer = (void *)next; |
sahilmgandhi | 18:6a4db94011d3 | 76 | |
sahilmgandhi | 18:6a4db94011d3 | 77 | return mem; |
sahilmgandhi | 18:6a4db94011d3 | 78 | } |
sahilmgandhi | 18:6a4db94011d3 | 79 | |
sahilmgandhi | 18:6a4db94011d3 | 80 | } |