This is an error for sure:
Code: Select all
chSysLock();
flags = chEvtGetAndClearFlags(&Writer);
chSysUnlock();
Calling a normal API from a critical zone. You should enable the state checker in chconf.h, it finds this kind of errors.
Giovanni
Moderator: RoccoMarco
Code: Select all
chSysLock();
flags = chEvtGetAndClearFlags(&Writer);
chSysUnlock();
Code: Select all
chSysLock();
flags = chEvtGetAndClearFlags(&elGPSdata);
chSysUnlock();Code: Select all
chprintf((BaseSequentialStream*)&SD2,"%s","ABCDEF\n\r"); // write something over SD2
eventflags_t flags;
do{
chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
chSysLock();
flags = chEvtGetAndClearFlags(&Writer);
chSysUnlock();
if (flags & CHN_OUTPUT_EMPTY) {
chMtxLock(&mtx);
chprintf((BaseSequentialStream *)&SD1,"out buffer empty\r\n");
chMtxUnlock(&mtx);
break;
}
}while(1);Code: Select all
chMtxLock(&mtxRs485);
palSetPad(GPIOC, GPIOC_RS485_DE);//put external chip in to writing mode
chprintf((BaseSequentialStream*)&SD2,"%s","ABCDEF\n\r");
eventflags_t flags;
do{
chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
flags = chEvtGetAndClearFlags(&Writer);
if (flags & CHN_OUTPUT_EMPTY) {
chMtxLock(&mtx);
chprintf((BaseSequentialStream *)&SD1,"out buffer empty\r\n");
chMtxUnlock(&mtx);
break;
}
}while(1);
chThdSleepMilliseconds(1000);//wait for test a very big amount of time
palClearPad(GPIOC, GPIOC_RS485_DE);// put external chip to reading mode
chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(40));
flags = chEvtGetAndClearFlags(&Listener);
if (flags & CHN_INPUT_AVAILABLE) {
chMtxLock(&mtx);
chprintf((BaseSequentialStream *)&SD1,"Got data to be read\r\n");
chMtxUnlock(&mtx);
msg_t charbuf;
do
{
charbuf = chnGetTimeout(&SD2, TIME_IMMEDIATE);
if ( charbuf != Q_TIMEOUT )
{
chMtxLock(&mtx);
chprintf((BaseSequentialStream *)&SD1,"%c ",(char)charbuf);
chMtxUnlock(&mtx);
}
}while (charbuf != Q_TIMEOUT);
chMtxLock(&mtx);
chprintf((BaseSequentialStream *)&SD1,"\r\n");
chMtxUnlock(&mtx);
}
chMtxUnlock(&mtxRs485);Code: Select all
chEvtRegister(chnGetEventSource(&SD2),&Listener, EVENT_MASK(1));
chEvtRegister(chnGetEventSource(&SD2),&Writer, EVENT_MASK(1));Code: Select all
/* Waiting for space into the transmit buffer (CHN_OUTPUT_EMPTY).*/
chEventWait(.....);
/* Switching to TX mode.*/
palSetPad(....);
/* Writing data.*/
chprintf(&SD1, "Hello World");
/* Now data has been written, switching to RX mode.*/
palClearPad(....);
Code: Select all
/* Switching to TX mode.*/
palSetPad(....);
/* Writing data, no need to wait for anything.*/
chprintf(&SD1, "Hello World");
/* Waiting for transmission to complete (CHN_TRANSMISSION_END).*/
chEventWait(.....);
/* Now data has been written, switching to RX mode.*/
palClearPad(....);