function Serial.attach()

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

Moderators: barthess, RoccoMarco

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

function Serial.attach()

Postby antoniolinux » Fri Oct 09, 2015 3:53 pm

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: 13074
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 758 times
Been thanked: 637 times
Contact:

Re: function Serial.attach()

Postby Giovanni » Fri Oct 09, 2015 3:58 pm

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

Postby antoniolinux » Sat Oct 10, 2015 10:38 am

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: 13074
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 758 times
Been thanked: 637 times
Contact:

Re: function Serial.attach()

Postby Giovanni » Sat Oct 10, 2015 10:43 am


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

Re: function Serial.attach()

Postby antoniolinux » Mon Oct 12, 2015 10:32 am

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: 13074
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 758 times
Been thanked: 637 times
Contact:

Re: function Serial.attach()

Postby Giovanni » Mon Oct 12, 2015 11:34 am

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

Postby antoniolinux » Mon Oct 12, 2015 1:46 pm

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: 13074
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 758 times
Been thanked: 637 times
Contact:

Re: function Serial.attach()

Postby Giovanni » Mon Oct 12, 2015 1:55 pm

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

Postby antoniolinux » Tue Oct 13, 2015 10:37 am

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

Postby AlSith » Wed Oct 14, 2015 12:45 pm

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??


Return to “STM32 Support”

Who is online

Users browsing this forum: No registered users and 5 guests