I will be very glad if I get help
I'm really trying to understand how to use interruptions and locked code blocks
I tried to realize interruptions by timer
I have not find smth like "cycle timer" (an timer object, that alarm by a period, until it will be enabled) yet, maybe it does not exist in ChibiOS
So I wanted to restart the timer inside the interrupt
(I'm run this code on nucleo-F411RE using J-link)
I run this code
Code: Select all
#include "ch.h"
#include "hal.h"
#include "rt_test_root.h"
#include "oslib_test_root.h"
#include "submodules/print_lib/print_lib.h"
int timer_time = 500;
static virtual_timer_t vTimer;
void timef_foo(void);
CH_IRQ_HANDLER(foo) {
CH_IRQ_PROLOGUE();
printString(" INTERRUPTION ");
chVTSet(&vTimer, TIME_MS2I(timer_time), (vtfunc_t)timef_foo, NULL);
CH_IRQ_EPILOGUE();
}
void timef_foo(void){ foo(); }
bool flag = 0;
static THD_WORKING_AREA(waThread1, 256);
static THD_FUNCTION(Thread1, arg) {
(void)arg;
chRegSetThreadName("blinker1");
systime_t prev = chVTGetSystemTime();
while (true) {
printString("th1");
palSetPad(GPIOA, GPIOA_LED_GREEN);
flag = 1;
prev = chThdSleepUntilWindowed(prev, chTimeAddX(prev, TIME_MS2I(500)));
palClearPad(GPIOA, GPIOA_LED_GREEN);
flag = 0;
prev = chThdSleepUntilWindowed(prev, chTimeAddX(prev, TIME_MS2I(1000)));
chThdYield();
}
}
static THD_WORKING_AREA(waThread2, 256);
static THD_FUNCTION(Thread2, arg) {
(void)arg;
chRegSetThreadName("blinker2");
systime_t prev = chVTGetSystemTime();
while (true){
if (!flag){
chSysLock(); // LOKKING
printString("th2");
palClearPad(GPIOA, GPIOA_LED_GREEN);
printString("3");
prev = chThdSleepUntilWindowed(prev, chTimeAddX(prev, TIME_MS2I(50)));
palSetPad(GPIOA, GPIOA_LED_GREEN);
printString("4");
prev = chThdSleepUntilWindowed(prev, chTimeAddX(prev, TIME_MS2I(50)));
printString("5");
chSysUnlock(); //UNLOKKING
}
}
}
int main(void) {
halInit();
chSysInit();
sdStart(&SD2, NULL);
chVTObjectInit(&vTimer);
chVTSet(&vTimer, TIME_MS2I(timer_time), (vtfunc_t)timef_foo, NULL);
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO+1, Thread1, NULL);
chThdCreateStatic(waThread2, sizeof(waThread2), NORMALPRIO, Thread2, NULL);
while (true) {
if (!palReadPad(GPIOC, GPIOC_BUTTON)) {
test_execute((BaseSequentialStream *)&SD2, &rt_test_suite);
test_execute((BaseSequentialStream *)&SD2, &oslib_test_suite);
}
chThdSleepMilliseconds(500);
}
}
But I get this output
Code: Select all
>> th1 INTERRUPTION th2345th2345th2345th2345th2345th2345th2345th2345th2345th234 INTERRUPTION 5th23
Using debug I found the file and line, where it stops:
file: /home/username/ChibiStudio/chibios_stable-21.11.x/os/common/startup/ARMCMx/compilers/GCC/vectors.S
line: 1027
I can not understand, why it stop every time and why locking section does not work
( I see this:
lock thread block
print: th2
print: 3
print: 4
print from IQR: INTERRUPTION (why IQR interrupting my locked block here??)
print: 5
unlock thread block
)
P.s.: perhaps there are grammatical errors in my address.. please excuse me, this is not my native language