function Serial.attach()
Moderator: RoccoMarco
-
antoniolinux
- Posts: 38
- Joined: Thu Dec 19, 2013 12:59 pm
function Serial.attach()
hi to all, in mbed plattform i have a little applicatio that use GSM Shield, i use the function Serial.attach(rxCallback() ). This function, rxCallback() , is called when a character goes into the RX buffer. and i use it for load the my buffer for store the Shiled Response.
do you know if chibios have this funcion or similar function?
best regards
Antonio
do you know if chibios have this funcion or similar function?
best regards
Antonio
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
-
antoniolinux
- Posts: 38
- Joined: Thu Dec 19, 2013 12:59 pm
Re: function Serial.attach()
thanks giovanni for your answer,
you want that i create a event on serial drive that call the function, I understood your answer,
can you see where i read a exemple or how to, because i don't have more doumentation.
best regards
A
you want that i create a event on serial drive that call the function, I understood your answer,
can you see where i read a exemple or how to, because i don't have more doumentation.
best regards
A
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
-
antoniolinux
- Posts: 38
- Joined: Thu Dec 19, 2013 12:59 pm
Re: function Serial.attach()
Thanks giovanni for your answer,
i set
i don't activete the Debug option and write thise threads
when i build i have this error "unknown type name 'EventListener'", i think don't load the class Event, but i don't know where i activate it, can you help?
bye
A.
i set
Code: Select all
#define CH_CFG_USE_EVENTS TRUE
#define CH_CFG_USE_EVENTS_TIMEOUT TRUE
i don't activete the Debug option and write thise threads
Code: Select all
static THD_WORKING_AREA(waRead5, 128);
static THD_FUNCTION(Thread5,arg) {
chRegSetThreadName("th_Riempio_Buffer");
EventListener Uart1Data;
flagsmask_t flags;
chEvtRegisterMask((EventSource *)chnGetEventSource(&SD1), &Uart1Data, EVENT_MASK(1));
while (TRUE) {
chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
chSysLock();
flags = chEvtGetAndClearFlags(&Uart1Data);
chSysUnlock();
if (flags & CHN_INPUT_AVAILABLE)
{
msg_t charbuf;
int count=0;
do
{
charbuf = chnGetTimeout(&SD1, TIME_IMMEDIATE);
if (charbuf != Q_TIMEOUT)
{
// Riempio il Buffer
while((bufferMsg[count] != '\n') && (count < BUFFER_SIZE)) {
bufferMsg[count]= (uint8_t) charbuf;
count++;
}
}
}
while (charbuf != Q_TIMEOUT);
}
}
}
when i build i have this error "unknown type name 'EventListener'", i think don't load the class Event, but i don't know where i activate it, can you help?
bye
A.
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: function Serial.attach()
Hi,
Type names changed in 3.0, it is now event_listener_t, other changed in a similar way.
Giovanni
Type names changed in 3.0, it is now event_listener_t, other changed in a similar way.
Giovanni
-
antoniolinux
- Posts: 38
- Joined: Thu Dec 19, 2013 12:59 pm
Re: function Serial.attach()
hi to all, i write this code but don't work,
i see that don't go in
i don't know because have this problem,
acn you help me?
Code: Select all
/*RIEMPIMENTO BUFFER*/
static THD_WORKING_AREA(waRead5, 128);
static THD_FUNCTION(Thread5,arg) {
chRegSetThreadName("th_Riempio_Buffer");
msg_t charbuf;
int count=0;
uint8_t c;
event_listener_t Uart1Data;
eventflags_t flags;
chEvtRegisterMask((event_source_t *)chnGetEventSource(&SD1), &Uart1Data, EVENT_MASK(1));
while (TRUE) {
chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
chSysLock();
flags = chEvtGetAndClearFlags(&Uart1Data);
chSysUnlock();
// don't go in this if, why?????
if (flags & CHN_INPUT_AVAILABLE)
{
/**Qui devo caricare il buffer*/
do
{
// charbuf = chnGetTimeout(&SD1, TIME_IMMEDIATE);
charbuf = chnGetTimeout(&SD1, MS2ST(20));
if (charbuf != Q_TIMEOUT)
{
c=(uint8_t) charbuf;
while((c != '\n') && (count < BUFFER_SIZE)) {
// uint8_t c = sdGet(&SD1);
bufferMsg[count]= c;
count++;
}
}
}
while (charbuf != Q_TIMEOUT);
}
}
}i see that don't go in
Code: Select all
if (flags & CHN_INPUT_AVAILABLE)i don't know because have this problem,
acn you help me?
- Giovanni
- Site Admin
- Posts: 14892
- Joined: Wed May 27, 2009 8:48 am
- Has thanked: 1202 times
- Been thanked: 996 times
Re: function Serial.attach()
Probably the state checker is stopping you in chEvtGetAndClearFlags(), it is not an I-class function.
Giovanni
Giovanni
-
antoniolinux
- Posts: 38
- Joined: Thu Dec 19, 2013 12:59 pm
Re: function Serial.attach()
hi to all,
now i can start the event but i have two problem:
1) i don't store the answer in the buffer,
2) i want start event when sd1 recive the data from sd1 , but i don't know if work well, because when i active the th_callbach thread, i see the event start, if i don't active the thread i don't see nothing
can you help me?
bye
A.
now i can start the event but i have two problem:
1) i don't store the answer in the buffer,
2) i want start event when sd1 recive the data from sd1 , but i don't know if work well, because when i active the th_callbach thread, i see the event start, if i don't active the thread i don't see nothing
Code: Select all
static THD_WORKING_AREA(waRead, 128);
static THD_FUNCTION(Thread,arg) {
(void)arg;
chRegSetThreadName("th_callback");
while (TRUE){
/* This will wait for a character to be received */
uint8_t c = sdGet(&SD1); //questo prende il carattere
sdPut(&SD2, c); // questo lo spara alla terminale
}
}
/*RIEMPIMENTO BUFFER*/
static THD_WORKING_AREA(waRead5, 128);
static THD_FUNCTION(Thread5,arg) {
chRegSetThreadName("th_Riempio_Buffer");
msg_t charbuf;
int count=0;
uint8_t c;
event_listener_t Uart1Data;
eventmask_t flags;
chEvtRegisterMask((event_source_t *)chnGetEventSource(&SD1), &Uart1Data, EVENT_MASK(1));
while (TRUE) {
chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
chSysLock();
flags =chEvtGetAndClearFlags(&Uart1Data);
chSysUnlock();
if (flags & CHN_INPUT_AVAILABLE)
{
do
{
charbuf = chnGetTimeout(&SD1,TIME_IMMEDIATE);
if (charbuf != Q_TIMEOUT)
{
while((charbuf != '\n') && (count < 128)) {
sdWrite(&SD2, (uint8_t *)B3,4); // va bene
bufferMsg[count]= charbuf;
count++;
}
}
}
while (charbuf != Q_TIMEOUT);
}
}
}
can you help me?
bye
A.
Re: function Serial.attach()
Hi antoniolinux,
how do you fix this if check??
antoniolinux wrote:i see that don't go inCode: Select all
if (flags & CHN_INPUT_AVAILABLE)
i don't know because have this problem,
acn you help me?
how do you fix this if check??