Page 1 of 2

function Serial.attach()

Posted: Fri Oct 09, 2015 3:53 pm
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

Re: function Serial.attach()

Posted: Fri Oct 09, 2015 3:58 pm
by Giovanni
Events in the serial driver is what we have.

Giovanni

Re: function Serial.attach()

Posted: Sat Oct 10, 2015 10:38 am
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

Re: function Serial.attach()

Posted: Sat Oct 10, 2015 10:43 am
by Giovanni

Re: function Serial.attach()

Posted: Mon Oct 12, 2015 10:32 am
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.

Re: function Serial.attach()

Posted: Mon Oct 12, 2015 11:34 am
by Giovanni
Hi,

Type names changed in 3.0, it is now event_listener_t, other changed in a similar way.

Giovanni

Re: function Serial.attach()

Posted: Mon Oct 12, 2015 1:46 pm
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?

Re: function Serial.attach()

Posted: Mon Oct 12, 2015 1:55 pm
by Giovanni
Probably the state checker is stopping you in chEvtGetAndClearFlags(), it is not an I-class function.

Giovanni

Re: function Serial.attach()

Posted: Tue Oct 13, 2015 10:37 am
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.

Re: function Serial.attach()

Posted: Wed Oct 14, 2015 12:45 pm
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??