PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)

Committer:
spinal
Date:
Sun Nov 18 15:47:54 2018 +0000
Revision:
64:6e6c6c2b664e
Parent:
5:ea7377f3d1af
added fix for directrectangle()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Pokitto 5:ea7377f3d1af 1 extern "C" {
Pokitto 5:ea7377f3d1af 2
Pokitto 5:ea7377f3d1af 3 #include "LPC11U6x.h"
Pokitto 5:ea7377f3d1af 4 #define WEAK __attribute__ ((weak))
Pokitto 5:ea7377f3d1af 5 #define ALIAS(f) __attribute__ ((weak, alias (#f)))
Pokitto 5:ea7377f3d1af 6 #define AFTER_VECTORS __attribute__ ((section(".after_vectors")))void ResetISR(void);
Pokitto 5:ea7377f3d1af 7
Pokitto 5:ea7377f3d1af 8 // Patch the AEABI integer divide functions to use MCU's romdivide library
Pokitto 5:ea7377f3d1af 9 #ifdef __USE_ROMDIVIDE
Pokitto 5:ea7377f3d1af 10 // Location in memory that holds the address of the ROM Driver table
Pokitto 5:ea7377f3d1af 11 #define PTR_ROM_DRIVER_TABLE ((unsigned int *)(0x1FFF1FF8))
Pokitto 5:ea7377f3d1af 12 // Variables to store addresses of idiv and udiv functions within MCU ROM
Pokitto 5:ea7377f3d1af 13 unsigned int *pDivRom_idiv;
Pokitto 5:ea7377f3d1af 14 unsigned int *pDivRom_uidiv;
Pokitto 5:ea7377f3d1af 15 #endif
Pokitto 5:ea7377f3d1af 16
Pokitto 5:ea7377f3d1af 17
Pokitto 5:ea7377f3d1af 18 extern unsigned int __data_section_table;
Pokitto 5:ea7377f3d1af 19 extern unsigned int __data_section_table_end;
Pokitto 5:ea7377f3d1af 20 extern unsigned int __bss_section_table;
Pokitto 5:ea7377f3d1af 21 extern unsigned int __bss_section_table_end;
Pokitto 5:ea7377f3d1af 22
Pokitto 5:ea7377f3d1af 23
Pokitto 5:ea7377f3d1af 24 extern void __libc_init_array(void);
Pokitto 5:ea7377f3d1af 25 extern int main(void);
Pokitto 5:ea7377f3d1af 26 extern void _vStackTop(void);
Pokitto 5:ea7377f3d1af 27 extern void (* const g_pfnVectors[])(void);
Pokitto 5:ea7377f3d1af 28
Pokitto 5:ea7377f3d1af 29 void ResetISR(void);
Pokitto 5:ea7377f3d1af 30 WEAK void NMI_Handler(void);
Pokitto 5:ea7377f3d1af 31 WEAK void HardFault_Handler(void);
Pokitto 5:ea7377f3d1af 32 WEAK void SVC_Handler(void);
Pokitto 5:ea7377f3d1af 33 WEAK void PendSV_Handler(void);
Pokitto 5:ea7377f3d1af 34 WEAK void SysTick_Handler(void);
Pokitto 5:ea7377f3d1af 35 WEAK void IntDefaultHandler(void);
Pokitto 5:ea7377f3d1af 36
Pokitto 5:ea7377f3d1af 37 void PIN_INT0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 38 void PIN_INT1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 39 void PIN_INT2_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 40 void PIN_INT3_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 41 void PIN_INT4_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 42 void PIN_INT5_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 43 void PIN_INT6_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 44 void PIN_INT7_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 45 void GINT0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 46 void GINT1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 47 void I2C1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 48 void USART1_4_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 49 void USART2_3_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 50 void SCT0_1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 51 void SSP1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 52 void I2C0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 53 void TIMER16_0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 54 void TIMER16_1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 55 void TIMER32_0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 56 void TIMER32_1_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 57 void SSP0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 58 void USART0_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 59 void USB_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 60 void USB_FIQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 61 void ADCA_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 62 void RTC_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 63 void BOD_WDT_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 64 void FMC_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 65 void DMA_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 66 void ADCB_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 67 void USBWakeup_IRQHandler (void) ALIAS(IntDefaultHandler);
Pokitto 5:ea7377f3d1af 68
Pokitto 5:ea7377f3d1af 69 __attribute__ ((section(".isr_vector")))
Pokitto 5:ea7377f3d1af 70 void (* const g_pfnVectors[])(void) = {
Pokitto 5:ea7377f3d1af 71 // Core Level - CM0
Pokitto 5:ea7377f3d1af 72 &_vStackTop, // The initial stack pointer
Pokitto 5:ea7377f3d1af 73 ResetISR, // The reset handler
Pokitto 5:ea7377f3d1af 74 NMI_Handler, // The NMI handler
Pokitto 5:ea7377f3d1af 75 HardFault_Handler, // The hard fault handler
Pokitto 5:ea7377f3d1af 76 0, // Reserved
Pokitto 5:ea7377f3d1af 77 0, // Reserved
Pokitto 5:ea7377f3d1af 78 0, // Reserved
Pokitto 5:ea7377f3d1af 79 0, // Reserved
Pokitto 5:ea7377f3d1af 80 0, // Reserved
Pokitto 5:ea7377f3d1af 81 0, // Reserved
Pokitto 5:ea7377f3d1af 82 0, // Reserved
Pokitto 5:ea7377f3d1af 83 SVC_Handler, // SVCall handler
Pokitto 5:ea7377f3d1af 84 0, // Reserved
Pokitto 5:ea7377f3d1af 85 0, // Reserved
Pokitto 5:ea7377f3d1af 86 PendSV_Handler, // The PendSV handler
Pokitto 5:ea7377f3d1af 87 SysTick_Handler, // The SysTick handler
Pokitto 5:ea7377f3d1af 88
Pokitto 5:ea7377f3d1af 89 // Chip Level - LPC11U68
Pokitto 5:ea7377f3d1af 90 PIN_INT0_IRQHandler, // 0 - GPIO pin interrupt 0
Pokitto 5:ea7377f3d1af 91 PIN_INT1_IRQHandler, // 1 - GPIO pin interrupt 1
Pokitto 5:ea7377f3d1af 92 PIN_INT2_IRQHandler, // 2 - GPIO pin interrupt 2
Pokitto 5:ea7377f3d1af 93 PIN_INT3_IRQHandler, // 3 - GPIO pin interrupt 3
Pokitto 5:ea7377f3d1af 94 PIN_INT4_IRQHandler, // 4 - GPIO pin interrupt 4
Pokitto 5:ea7377f3d1af 95 PIN_INT5_IRQHandler, // 5 - GPIO pin interrupt 5
Pokitto 5:ea7377f3d1af 96 PIN_INT6_IRQHandler, // 6 - GPIO pin interrupt 6
Pokitto 5:ea7377f3d1af 97 PIN_INT7_IRQHandler, // 7 - GPIO pin interrupt 7
Pokitto 5:ea7377f3d1af 98 GINT0_IRQHandler, // 8 - GPIO GROUP0 interrupt
Pokitto 5:ea7377f3d1af 99 GINT1_IRQHandler, // 9 - GPIO GROUP1 interrupt
Pokitto 5:ea7377f3d1af 100 I2C1_IRQHandler, // 10 - I2C1
Pokitto 5:ea7377f3d1af 101 USART1_4_IRQHandler, // 11 - combined USART1 & 4 interrupt
Pokitto 5:ea7377f3d1af 102 USART2_3_IRQHandler, // 12 - combined USART2 & 3 interrupt
Pokitto 5:ea7377f3d1af 103 SCT0_1_IRQHandler, // 13 - combined SCT0 and 1 interrupt
Pokitto 5:ea7377f3d1af 104 SSP1_IRQHandler, // 14 - SPI/SSP1 Interrupt
Pokitto 5:ea7377f3d1af 105 I2C0_IRQHandler, // 15 - I2C0
Pokitto 5:ea7377f3d1af 106 TIMER16_0_IRQHandler, // 16 - CT16B0 (16-bit Timer 0)
Pokitto 5:ea7377f3d1af 107 TIMER16_1_IRQHandler, // 17 - CT16B1 (16-bit Timer 1)
Pokitto 5:ea7377f3d1af 108 TIMER32_0_IRQHandler, // 18 - CT32B0 (32-bit Timer 0)
Pokitto 5:ea7377f3d1af 109 TIMER32_1_IRQHandler, // 19 - CT32B1 (32-bit Timer 1)
Pokitto 5:ea7377f3d1af 110 SSP0_IRQHandler, // 20 - SPI/SSP0 Interrupt
Pokitto 5:ea7377f3d1af 111 USART0_IRQHandler, // 21 - USART0
Pokitto 5:ea7377f3d1af 112 USB_IRQHandler, // 22 - USB IRQ
Pokitto 5:ea7377f3d1af 113 USB_FIQHandler, // 23 - USB FIQ
Pokitto 5:ea7377f3d1af 114 ADCA_IRQHandler, // 24 - ADC A(A/D Converter)
Pokitto 5:ea7377f3d1af 115 RTC_IRQHandler, // 25 - Real Time CLock interrpt
Pokitto 5:ea7377f3d1af 116 BOD_WDT_IRQHandler, // 25 - Combined Brownout/Watchdog interrupt
Pokitto 5:ea7377f3d1af 117 FMC_IRQHandler, // 27 - IP2111 Flash Memory Controller
Pokitto 5:ea7377f3d1af 118 DMA_IRQHandler, // 28 - DMA interrupt
Pokitto 5:ea7377f3d1af 119 ADCB_IRQHandler, // 24 - ADC B (A/D Converter)
Pokitto 5:ea7377f3d1af 120 USBWakeup_IRQHandler, // 30 - USB wake-up interrupt
Pokitto 5:ea7377f3d1af 121 0, // 31 - Reserved
Pokitto 5:ea7377f3d1af 122 };
Pokitto 5:ea7377f3d1af 123 /* End Vector */
Pokitto 5:ea7377f3d1af 124
Pokitto 5:ea7377f3d1af 125 AFTER_VECTORS void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
Pokitto 5:ea7377f3d1af 126 unsigned int *pulDest = (unsigned int*) start;
Pokitto 5:ea7377f3d1af 127 unsigned int *pulSrc = (unsigned int*) romstart;
Pokitto 5:ea7377f3d1af 128 unsigned int loop;
Pokitto 5:ea7377f3d1af 129 for (loop = 0; loop < len; loop = loop + 4) *pulDest++ = *pulSrc++;
Pokitto 5:ea7377f3d1af 130 }
Pokitto 5:ea7377f3d1af 131
Pokitto 5:ea7377f3d1af 132 AFTER_VECTORS void bss_init(unsigned int start, unsigned int len) {
Pokitto 5:ea7377f3d1af 133 unsigned int *pulDest = (unsigned int*) start;
Pokitto 5:ea7377f3d1af 134 unsigned int loop;
Pokitto 5:ea7377f3d1af 135 for (loop = 0; loop < len; loop = loop + 4) *pulDest++ = 0;
Pokitto 5:ea7377f3d1af 136 }
Pokitto 5:ea7377f3d1af 137
Pokitto 5:ea7377f3d1af 138
Pokitto 5:ea7377f3d1af 139 /* Reset entry point*/
Pokitto 5:ea7377f3d1af 140 extern "C" void software_init_hook(void) __attribute__((weak));
Pokitto 5:ea7377f3d1af 141
Pokitto 5:ea7377f3d1af 142 AFTER_VECTORS void ResetISR(void) {
Pokitto 5:ea7377f3d1af 143 unsigned int LoadAddr, ExeAddr, SectionLen;
Pokitto 5:ea7377f3d1af 144 unsigned int *SectionTableAddr;
Pokitto 5:ea7377f3d1af 145
Pokitto 5:ea7377f3d1af 146 SectionTableAddr = &__data_section_table;
Pokitto 5:ea7377f3d1af 147
Pokitto 5:ea7377f3d1af 148 while (SectionTableAddr < &__data_section_table_end) {
Pokitto 5:ea7377f3d1af 149 LoadAddr = *SectionTableAddr++;
Pokitto 5:ea7377f3d1af 150 ExeAddr = *SectionTableAddr++;
Pokitto 5:ea7377f3d1af 151 SectionLen = *SectionTableAddr++;
Pokitto 5:ea7377f3d1af 152 data_init(LoadAddr, ExeAddr, SectionLen);
Pokitto 5:ea7377f3d1af 153 }
Pokitto 5:ea7377f3d1af 154 while (SectionTableAddr < &__bss_section_table_end) {
Pokitto 5:ea7377f3d1af 155 ExeAddr = *SectionTableAddr++;
Pokitto 5:ea7377f3d1af 156 SectionLen = *SectionTableAddr++;
Pokitto 5:ea7377f3d1af 157 bss_init(ExeAddr, SectionLen);
Pokitto 5:ea7377f3d1af 158 }
Pokitto 5:ea7377f3d1af 159
Pokitto 5:ea7377f3d1af 160 // Patch the AEABI integer divide functions to use MCU's romdivide library
Pokitto 5:ea7377f3d1af 161 #ifdef __USE_ROMDIVIDE
Pokitto 5:ea7377f3d1af 162 // Get address of Integer division routines function table in ROM
Pokitto 5:ea7377f3d1af 163 unsigned int *div_ptr = (unsigned int *)((unsigned int *)*(PTR_ROM_DRIVER_TABLE))[4];
Pokitto 5:ea7377f3d1af 164 // Get addresses of integer divide routines in ROM
Pokitto 5:ea7377f3d1af 165 // These address are then used by the code in aeabi_romdiv_patch.s
Pokitto 5:ea7377f3d1af 166 pDivRom_idiv = (unsigned int *)div_ptr[0];
Pokitto 5:ea7377f3d1af 167 pDivRom_uidiv = (unsigned int *)div_ptr[1];
Pokitto 5:ea7377f3d1af 168 #endif
Pokitto 5:ea7377f3d1af 169
Pokitto 5:ea7377f3d1af 170
Pokitto 5:ea7377f3d1af 171 SystemInit();
Pokitto 5:ea7377f3d1af 172 if (software_init_hook)
Pokitto 5:ea7377f3d1af 173 software_init_hook();
Pokitto 5:ea7377f3d1af 174 else {
Pokitto 5:ea7377f3d1af 175 __libc_init_array();
Pokitto 5:ea7377f3d1af 176 main();
Pokitto 5:ea7377f3d1af 177 }
Pokitto 5:ea7377f3d1af 178 while (1) {;}
Pokitto 5:ea7377f3d1af 179 }
Pokitto 5:ea7377f3d1af 180
Pokitto 5:ea7377f3d1af 181 AFTER_VECTORS void NMI_Handler (void) {}
Pokitto 5:ea7377f3d1af 182 AFTER_VECTORS void HardFault_Handler (void) {}
Pokitto 5:ea7377f3d1af 183 AFTER_VECTORS void MemManage_Handler (void) {}
Pokitto 5:ea7377f3d1af 184 AFTER_VECTORS void BusFault_Handler (void) {}
Pokitto 5:ea7377f3d1af 185 AFTER_VECTORS void UsageFault_Handler(void) {}
Pokitto 5:ea7377f3d1af 186 AFTER_VECTORS void SVC_Handler (void) {}
Pokitto 5:ea7377f3d1af 187 AFTER_VECTORS void DebugMon_Handler (void) {}
Pokitto 5:ea7377f3d1af 188 AFTER_VECTORS void PendSV_Handler (void) {}
Pokitto 5:ea7377f3d1af 189 AFTER_VECTORS void SysTick_Handler (void) {}
Pokitto 5:ea7377f3d1af 190 AFTER_VECTORS void IntDefaultHandler (void) {}
Pokitto 5:ea7377f3d1af 191
Pokitto 5:ea7377f3d1af 192 int __aeabi_atexit(void *object, void (*destructor)(void *), void *dso_handle) {return 0;}
Pokitto 5:ea7377f3d1af 193 }
Pokitto 5:ea7377f3d1af 194
Pokitto 5:ea7377f3d1af 195 #include <stdlib.h>
Pokitto 5:ea7377f3d1af 196
Pokitto 5:ea7377f3d1af 197 void *operator new(size_t size) {return malloc(size);}
Pokitto 5:ea7377f3d1af 198 void *operator new[](size_t size){return malloc(size);}
Pokitto 5:ea7377f3d1af 199
Pokitto 5:ea7377f3d1af 200 void operator delete(void *p) {free(p);}
Pokitto 5:ea7377f3d1af 201 void operator delete[](void *p) {free(p);}