void SysCall(void) { LED^=1; // just for the test __asm("thread_exit:"); __asm("SVC 0"); // return to handler mode }void SysTick_Handler(void) __attribute__ ((naked));void SysTick_Handler(void) { __asm("PUSH {r4,lr}"); // preserve EXC_RETURN (and SP align) __asm("LDR r0,=thread_exit"); // thread LR must generate an exit __asm("LDR r1,=SysCall"); // thread PC is our real handler __asm("LDR r2,=0x01000000"); // PSR for thread in Thumb-state __asm("PUSH {r0-r2}"); // create LR, PC and PSR __asm("SUB sp,sp,#(5*4)"); // allocate space for r0-r3 and r12 __asm("LDR r0,=0xFFFFFFF9"); // thread using MSP return __asm("BX r0"); // return to newly created thread}void SVC_Handler(void) __attribute__ ((naked));void SVC_Handler(void) { __asm("ADD sp,sp,#(9*4)"); // remove thread and r4 from stack __asm("POP {pc}"); // perform standard exception return }