Thread for Serial Event

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

Moderator: RoccoMarco

Post Reply
User avatar
AlSith
Posts: 20
Joined: Thu Oct 01, 2015 10:41 am

Thread for Serial Event

Post by AlSith »

Hi.

I have to realize a thread to manage the serial port. Exactly, i would use thread system to verify continually if my USART2-Rx pin receive a character.
Looking to the various example on net and also on this forum, I'm trying to write code in this way:

Code: Select all

static THD_WORKING_AREA(waSerThd, 128);
static msg_t SerThd(void *arg) {
  while(TRUE) {
    // --- Enable GPIOA Port, at Pin: 2-3, to use USART. [Tx-Rx]
    palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7));
    palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7));
    sdStart(&SD2, &uartCfg); // starts the serial driver with uartCfg as a config

//    // --- Show welcome message
//    sdWrite(&SD2, (uint8_t *) stringRUN, strlen(stringRUN));
//    chThdSleepMilliseconds(500);

    event_listener_t elSerData;
    eventmask_t flags;
    chEvtRegisterMask((EventSource *)chnGetEventSource(&SD2), &elSerData, EVENT_MASK(1));

    while(TRUE) {
       chEvtWaitOneTimeout(EVENT_MASK(1), MS2ST(10));
       flags = chEvtGetAndClearFlags(&elSerData);
       if(flags & CHN_INPUT_AVAILABLE) {
          msg_t charbuf;
          do {
             charbuf = chnGetTimeout(&SD2, TIME_IMMEDIATE);
             if( charbuf != Q_TIMEOUT ) {
               chSequentialStreamPut(&SD2, charbuf);
             }
          }
          while (charbuf != Q_TIMEOUT);
       }
    }

    return 0;
  }
}


..but i have a compilation error when Thread-code launch the command

Code: Select all

chEvtRegisterMask


..an error regarding on the eventSource.
Where I wrong..?? Is possible do what i would do or there are gap in my conception of ChibiOS system..??

Thanks, Alfonso
User avatar
Giovanni
Site Admin
Posts: 14893
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: Thread for Serial Event

Post by Giovanni »

Incidentally, already answered less than one hour ago here: viewtopic.php?f=16&t=2898#p22616

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

Re: Thread for Serial Event

Post by antoniolinux »

Hi Alsith, i think, in chibios, don't possible use the Serial Driver for use he event, infact if you see the uart exemple you can see this:
UARTConfig you can use more configuretion and callback function

Code: Select all

 @brief End of transmission buffer callback.
   */
  uartcb_t                  txend1_cb;
  /**
   * @brief Physical end of transmission callback.
   */
  uartcb_t                  txend2_cb;
  /**
   * @brief Receive buffer filled callback.
   */
  uartcb_t                  rxend_cb;
  /**
   * @brief Character received while out if the @p UART_RECEIVE state.
   */
  uartccb_t                 rxchar_cb;
  /**
   * @brief Receive error callback.
   */
  uartecb_t                 rxerr_cb;
  /* End of the mandatory fields.*/

i think use this for store the answer of GSM, what do you think?
bye
A.
Post Reply