Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
%DASHBOARD{ section="banner" | ||||||||
Line: 73 to 73 | ||||||||
Changed: | ||||||||
< < | ||||||||
> > | ||||||||
Interrupts and Forth | ||||||||
Changed: | ||||||||
< < | Mecrisp uses R7 as data stack pointer and R6 as TOS. If Forth rules the system R7 is always the data stack pointer and you can use the data stack pointer within a interrupt service routine. But in a mixed system, where C routines are used, there is no guarantee that the register R7 remains unchanged. When the interrupt occurs while a C routine is executed, the data stack pointer is invalid and Forth words can't be used in interrupt service routines. | |||||||
> > | Mecrisp uses R7 as data stack pointer and R6 as TOS. If Forth rules the system R7 is always the data stack pointer and you can use the data stack pointer within a interrupt service routine. But in a mixed system, where C routines are used, there is no guarantee that the register R7 remains unchanged. When the interrupt occurs while a C routine is executed, the data stack pointer is invalid and Forth words can't be used in interrupt service routines. A possible solution would be a separate data stack for the ISRs. I don't do that and use C for the ISRs. The Forth threads are synchronized by RTOS IPCs like semaphores.
For details see bsp.c.
/** * @brief Output Compare callback in non-blocking mode * @param htim TIM OC handle * @retval None */ void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef *htim) { if (htim->Instance == TIM2) { if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) { // D5, PA15 osSemaphoreRelease(ICOC_CH1_SemaphoreID); } if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_3) { // D1, PA2 osSemaphoreRelease(ICOC_CH3_SemaphoreID); } if(htim->Channel == HAL_TIM_ACTIVE_CHANNEL_4) { // D0, PA3 osSemaphoreRelease(ICOC_CH4_SemaphoreID); } } } /** * @brief * Waits for Output Compare. * @param[in] * pin_number port pin 0 D0, 1 D1, or 5 D5 * @return * none */ void BSP_waitOC(int pin_number) { switch (pin_number) { case 0: osSemaphoreAcquire(ICOC_CH4_SemaphoreID, osWaitForever); break; case 1: osSemaphoreAcquire(ICOC_CH3_SemaphoreID, osWaitForever); break; case 5: osSemaphoreAcquire(ICOC_CH1_SemaphoreID, osWaitForever); break; } } OCwait Forth word waits for the event Output Compare, timer interrupt assigned to a port pin. Details bsp.s.
@ ----------------------------------------------------------------------------- Wortbirne Flag_visible, "OCwait" OCwait: @ ( a -- ) wait for the end of output capture pin a // void BSP_waitOC(int pin_number); @ ----------------------------------------------------------------------------- push {r0-r3, lr} movs r0, tos // pin_number drop bl BSP_waitOC pop {r0-r3, pc} | |||||||