Author Topic: Chibios and Event on Serial  (Read 3902 times)

0 Members and 1 Guest are viewing this topic.

Offline antoniolinuxTopic starter

  • Newbie
  • Posts: 2
  • Country: it
Chibios and Event on Serial
« on: October 24, 2015, 10:22:43 am »
hi to all, i'm newbie of embedded word i have this problem write this thread in chibiOS
 
Code: [Select]

static THD_WORKING_AREA(waRead5, 128);
static THD_FUNCTION(Thread5,arg) {
  (void)arg;
  chRegSetThreadName("th_Buffer");
  palSetPadMode(GPIOA, 9, PAL_MODE_ALTERNATE(7));
  palSetPadMode(GPIOA, 10, PAL_MODE_ALTERNATE(7));
  sdStart(&SD1, NULL);
  event_listener_t Uart1Data;
  eventmask_t flags;
  chEvtRegisterMask((event_source_t *)chnGetEventSource(&SD1), &Uart1Data, EVENT_MASK(1));
  while (TRUE) {
       chEvtWaitAll(EVENT_MASK(1));
     
       flags =chEvtGetAndClearFlags(&Uart1Data);
   
       if (flags & CHN_INPUT_AVAILABLE)
                {
              sdWrite(&SD2,"OK\r\n",4);
                }
      }
}

i want start a event when arrived data on SD1, in this code when arrive data on SD1 i write ok on SD2
i have this strange situation if i press reset the board and later i press button i see  the event but later this i don't see nothing,
i use chEvtGetAndClearFlags for clear the flags but don't work
can you help me?


best  regards
A.


 

Offline ralphd

  • Frequent Contributor
  • **
  • Posts: 445
  • Country: ca
    • Nerd Ralph
Re: Chibios and Event on Serial
« Reply #1 on: October 24, 2015, 10:59:12 pm »
Can't offer any help but it is interesting to see some sample ChibiOS code.  Seems overly complicated for basic IO.
Unthinking respect for authority is the greatest enemy of truth. Einstein
 

Offline photovore

  • Newbie
  • Posts: 9
  • Country: de
Re: Chibios and Event on Serial
« Reply #2 on: October 25, 2015, 03:32:14 am »
You should post this in the CibiOS forum. The author, Giovanni, is very active there and can probably provide the most correct solution.
 

Offline Jeroen3

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: nl
  • Embedded Engineer
    • jeroen3.nl
Re: Chibios and Event on Serial
« Reply #3 on: October 25, 2015, 04:26:57 pm »
There is no need to explicitly subscribe to an event of the serial io queue.
When you call sdRead you actually call
Code: [Select]
chIQReadTimeout(&(sdp)->iqueue, b, n, TIME_INFINITE)Which will wait indefinitely for data, there is also sdReadTimeout, which obviously only waits the specified timeout to allow the thread to read other events. Such as an request to kill itself.

Yes, it is complicated. Especially when you start to dissect the code and find the ingenious method used for inheritance in C.
« Last Edit: October 25, 2015, 04:30:15 pm by Jeroen3 »
 

Offline antoniolinuxTopic starter

  • Newbie
  • Posts: 2
  • Country: it
Re: Chibios and Event on Serial
« Reply #4 on: October 26, 2015, 10:27:38 am »
Hi to all, hanks for your feedback, i fix it with this code:
 
Code: [Select]
static THD_WORKING_AREA(waRead5, 128);
static THD_FUNCTION(Thread5,arg) {
  (void)arg;
  chRegSetThreadName("th_Riempio_Buffer");

  event_listener_t Uart1Data;
  eventmask_t activeEvents;
  eventflags_t flags;
  chEvtRegisterMask((event_source_t *)chnGetEventSource(&SD1), &Uart1Data, EVENT_MASK(1));
  while (TRUE) {
    activeEvents=chEvtWaitAll(EVENT_MASK(1));

       flags =chEvtGetAndClearFlags(&Uart1Data);

       if (flags)
                {
              sdWrite(&SD2,"OK\r\n",4);
                }
      }
  return 0;
}
i see the problem is the   
Code: [Select]
CHN_INPUT_AVAILABLEnoe i want to use the idea of Jeroen3
 
Code: [Select]
chIQReadTimeout(&(sdp)->iqueue, b, n, TIME_INFINITE)
i hope this post can help other people.
Best regards
A.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf