#include "lpc11xx.h" #include <core_cm0.h> extern "C" void SystemTimer_ISR(void); volatile uint_fast32_t SysTickWas; __attribute__ ((__section__(".ramfunc"))) void SystemTimer_ISR() { SysTickWas=1; } int main() { LPC_GPIO0->DIR=(1<<7); LPC_GPIO0->DATA=0; uint16_t tick_counter=0; SysTick_Config(48000); while (1) { if (SysTickWas) { SysTickWas=0; uint16_t tick_limit = (LPC_GPIO0->DATA&(1<<7)) ? (30) : (970); if (++tick_counter>=tick_limit) { tick_counter=0; LPC_GPIO0->DATA^=(1<<7); } } } } |
.ramfunc : { . = ALIGN(4); _sdata = .; /* start of .data label */ *(.ramfunc) *(.ramfunc.*) } > RAM AT > TEXT _sidata = LOADADDR(.ramfunc); /* start of initialized data label */ |
__attribute__ ((section(".isr_vector"))) void (* const g_pfnVectors[])(void) = { /* Core interrupt vectors */ (intfunc)_estack, Reset_Handler, NMI_Handler, HardFault_Handler, 0, 0, 0, 0, 0, 0, 0, SVC_Handler, 0, 0, PendSVC_ISR, SystemTimer_ISR, // .....other handlers |
void (* const g_pfnVectors[])(void) = { &_vStackTop, // The initial stack pointer ResetISR, // The reset handler NMI_Handler, // The NMI handler HardFault_Handler, // The hard fault handler 0, ..... |
__attribute__ ((__section__(".ramfunc"))) void SystemTimer_ISR() { SysTickWas=1; } |
void SystemTimer_ISR() { SysTickWas=1; } |
void SysTick_Handler(void) { while(1) { } } |
/* Core interrupt vectors */ (intfunc)_estack, Reset_Handler, 0, 0, 0, 0, 0, 0, 0, 0, 0, SVC_Handler, 0, 0, PendSVC_ISR, SystemTimer_ISR, |
Reset_Handler, NMI_Handler, // The NMI handler HardFault_Handler, 0, 0, 0, 0, 0, 0, 0, SVC_Handler, 0, 0, PendSVC_ISR, SystemTimer_ISR, |
extern "C" void HardFault_Handler() { uint8_t blink_counter=0; while (++blink_counter<100) { LPC_GPIO0->DATA&=~(1<<7); volatile uint32_t delay=0; while (++delay<1000000) ; delay=0; LPC_GPIO0->DATA|=(1<<7); while (++delay<10000) ; } NVIC_SystemReset(); } |
void SysTick_Handler(void) { while(1) { } } |