function Serial.attach()

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

antoniolinux
Posts: 38
Joined: Thu Dec 19, 2013 12:59 pm

function Serial.attach()

Post by antoniolinux »

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
User avatar
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()

Post by Giovanni »

Events in the serial driver is what we have.

Giovanni
antoniolinux
Posts: 38
Joined: Thu Dec 19, 2013 12:59 pm

Re: function Serial.attach()

Post by antoniolinux »

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
User avatar
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()

Post by Giovanni »

antoniolinux
Posts: 38
Joined: Thu Dec 19, 2013 12:59 pm

Re: function Serial.attach()

Post by antoniolinux »

Thanks giovanni for your answer,

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.
User avatar
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()

Post by Giovanni »

Hi,

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()

Post by antoniolinux »

hi to all, i write this code but don't work,

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?
User avatar
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()

Post by Giovanni »

Probably the state checker is stopping you in chEvtGetAndClearFlags(), it is not an I-class function.

Giovanni
antoniolinux
Posts: 38
Joined: Thu Dec 19, 2013 12:59 pm

Re: function Serial.attach()

Post by antoniolinux »

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

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.
User avatar
AlSith
Posts: 20
Joined: Thu Oct 01, 2015 10:41 am

Re: function Serial.attach()

Post by AlSith »

Hi antoniolinux,

antoniolinux wrote: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?



how do you fix this if check??
Post Reply