Page 2 of 2
Re: SPI interrupt with FPU-Thread not working properly
Posted: Fri Jul 11, 2014 4:18 pm
by Nikhil V R
CH_IRQ_HANDLER(SysTickVector) {
CH_IRQ_PROLOGUE();
chSysLockFromIsr();
chSysTimerHandlerI();
chSysUnlockFromIsr();
CH_IRQ_EPILOGUE();
}
This part is giving debug error as SV#8 and when I comment CH_IRQ_PROLOGUE(); and CH_IRQ_EPILOGUE(); debug error changed to SV#6.How can I sole this?
CH_IRQ_PROLOGUE() is not called any where in my code other than here.Do i need to call CH_IRQ_PROLOGUE() before calling chSysLockFromIsr(); inside all other ISR?
Re: SPI interrupt with FPU-Thread not working properly
Posted: Fri Jul 11, 2014 4:50 pm
by Nikhil V R
I found the problem as stack overflow whenever SPI interrupt is enabled?Can any body suggest how to solve this? Is the problem is with ISR stack?
Re: SPI interrupt with FPU-Thread not working properly
Posted: Fri Jul 11, 2014 5:17 pm
by Giovanni
In general, if you are going to use any ChibiOS function from an ISR then you need the ISR to be written using ALL those macro, essential OS operations can be performed in there.
If into a library you have an ISR function called xyz() just call xyz() from an ISR written according to rules.
About the stack overflow, it could happen in any stack, not just the IRQ stack, try enlarging all them if you suspect there is an overflow.
About the SPI, why the ST library if I may ask?
Giovanni
Re: SPI interrupt with FPU-Thread not working properly
Posted: Sat Jul 12, 2014 1:10 pm
by Nikhil V R
do {
cp = cp->p_next;
} while (cp->p_prio >= tp->p_prio);
after solving stack overflow my code is getting stuck inside this loop.Any suggestions pls?
Re: SPI interrupt with FPU-Thread not working properly
Posted: Sat Jul 12, 2014 2:05 pm
by Giovanni
That can happen only because a corruption of the ready list, you must be doing something strange somewhere but I have no elements for a meaningful suggestion.
Giovanni
Re: SPI interrupt with FPU-Thread not working properly
Posted: Sat Jul 12, 2014 3:55 pm
by Giovanni
Something like this could be caused by readying up a thread that is already in the ready list, search for something that could cause this. It is strange that some assertion has not been triggered.
Giovanni
Re: SPI interrupt with FPU-Thread not working properly
Posted: Mon Jul 14, 2014 10:50 am
by Nikhil V R
Hi Giovanni,
When I made CH_DBG_SYSTEM_STATE_CHECK = TRUE, panic msg shows as SV#4, misplaced @p chSysLock()
I have four threads and initialization is given below,
void Initialize_Threads(void) {
static WORKING_AREA(Task1, 1536);
static WORKING_AREA(Task2, 3584);
static WORKING_AREA(Task3, 3524);
static WORKING_AREA(Task4, 1024);
Thread_Id1 = chThdCreateStatic(Task1, sizeof(Task1), HIGHPRIO, Thread1, NULL);
Thread_Id2 = chThdCreateStatic(Task2, sizeof(Task2), HIGHPRIO, Thread2, NULL);
Thread_Id3 = chThdCreateStatic(Task3, sizeof(Task3), HIGHPRIO, Thread3, NULL);
Thread_Id4 = chThdCreateStatic(Task4, sizeof(Task4), HIGHPRIO, Thread4, NULL);
}
msg_t Thread1(void *arg)
{
(void)arg;
chRegSetThreadName("Thread1");
while (TRUE) {
/* Task */
chThdSleepMilliseconds( 2 );
}
}
Thread 2 thread 3 and thread 4 are also same like thread1. Before calling chThdSleepMilliseconds( 2 ); dbg_lock_cnt = 1.This variable is setting by
chSchWakeupS(tp = chThdCreateI(wsp, size, prio, pf, arg), RDY_OK);while creating the thread.
So Im getting a debugging error as SV#4, misplaced @p chSysLock().How can I solve this?
without giving chThdSleepMilliseconds how can I achieve context switching?
Re: SPI interrupt with FPU-Thread not working properly
Posted: Mon Jul 14, 2014 11:09 am
by Giovanni
sv#4 means that somewhere there are probably two consecutive chSysLock(), the function is not reentrant and that is the error you are getting.
In order to yield control to other threads (with equal priority) the function to call is chThdYield().
Giovanni
Re: SPI interrupt with FPU-Thread not working properly
Posted: Mon Jul 14, 2014 11:34 am
by Nikhil V R
Is it possible to change priority of main thread?