c - Scheduling the transmision of frames in RTOS -


i'm planning use stm32 board send can frames. implemented simple scheduler contains 10 tasks;one task responsible send frames.

to job declared structure can frame:

typedef struct {     unsigned int id;     unsigned char data[];     unsigned char dlc;     unsigned int timeofsend  //this time in ms in frame should sent }tframe; 

and declared table of frames sent

aubframes[max_frames] = {     {0x12, 0xaabbcc, 4,  100},     {0x12, 0xaabbcc, 4, 1000},     {0x12, 0xaabbcc, 4, 2000},     {0x12, 0xaabbcc, 4, 2010} }; 

this tell board send first frame after 100 ms, second after 1000 ms, etc.

what do:

i added new task in scheduler period of 10 ms. task check aubframes table , if it's time send frame sends concerned frame, else nothing done. problem solution there big loss of time. example, send first frame scheduler access task 9 times, nothing do.

is there solution scheduling more effective?

i thought use timer interrupt, don't think that's solution since there 4 timers on board , number of frames more four, in opinion configuring timers generate interrupts different period of time won't work.

most rtoses have couple of features seem appropriate.

one method task suspend appropriate amount of time (rather waking periodically poll whether it's time). example, freertos has vtaskdelay function, blocks task specified amount of time. task knows doesn't have 100 or 1000 ms should delay amount of time.

another method use software timer rather hardware timer. rtos apparently getting periodic tick because knows wake task every 10 ms. has software timer service this one freertos. software timer service driven hardware timer rtos scheduler uses. , allows set variety of periodic , single-shot software timers without need hardware timer. task read aubframes array , setup one-shot timer each frame, expire @ appropriate times. if don't idea of software timers running @ once set next timer previous timer expires.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -