Need help 4 taskts and delay

hi all, i was trying to run 4 tasks, 4 difrent prioritys. just basic to see how it works. source i made wil only show 2 task because the last 2 basicly are the same.: int main(void) {      DDRD = 0xff;      PORTD = 0x00;      taskstarter();      vTaskStartScheduler(); } void taskstarter() {    xTaskCreate(task1, (dunno what i must put after this priority 1 or something)    xTaskCreate(task2, (dunno what i must put after this priority 2 or something)    xTaskCreate(task3, (dunno what i must put after this priority 3 or something)    xTaskCreate(task4, (dunno what i must put after this priority 4 or something) } void task1(void) {      portTickType xDelay, xNextTime;      xNextTime = xTaskGetTickCount () + ( portTickType ) 10;           for(;;)      {          xDelay = xNextTime – xTaskGetTickCount ();          xNextTime += ( portTickType ) 10;          PORTD = 0x20;         // led 1 on          vTaskDelay(xDelay);          PORTD = 0x00;         // all leds off      } } void task2(void) {      portTickType xDelay, xNextTime;      xNextTime = xTaskGetTickCount () + ( portTickType ) 10;      for(;;)      {          xDelay = xNextTime – xTaskGetTickCount ();          xNextTime += ( portTickType ) 10;          PORTD = 0x40;        // led 2 on          vTaskDelay(xDelay);          PORTD = 0x00;        // all leds off      } } my questions: 1) what values must i give to xTaskCreate() 2) how do i @ those tasks to the Scheduler. 3) vTaskDelay can i make that something like vTaskDelay(100); i found this xDelay in an example but i stil don’t know how manny msec or sec this delay takes. got a 8Mhz crystal on the microcontroler. thanks for your time and help Dragie

Need help 4 taskts and delay

> int main(void) > { >      DDRD = 0xff; >      PORTD = 0x00; >      taskstarter(); >      vTaskStartScheduler(); > } Looks like you are using a PIC of some description? <snip> > void task1(void) This needs to be task1( void *pvParameters ), see http://www.freertos.org/a00015.html#ImplementingTasks > { >      portTickType xDelay, xNextTime; >      xNextTime = xTaskGetTickCount () + ( portTickType ) 10; > >      >      for(;;) >      { >          xDelay = xNextTime – xTaskGetTickCount (); >          xNextTime += ( portTickType ) 10; > >          PORTD = 0x20;         // led 1 on >          vTaskDelay(xDelay); >          PORTD = 0x00;         // all leds off >      } > } Well I was going to say this code looks a little odd, but I have just checked the online documentation and it looks like you copied it from there.  This is bad documentation that relates back to a time before the xTaskDelayUntil() function was available.  I will change it ASAP. If you want to process something with a fixed interval use xTaskDelayUntil() as described here: http://www.freertos.org/vtaskdelayuntil.html  If you want to block for a fixed number of ticks (rather than wake at fixed intervals) use vTaskDelay() in a simpler way than the online docs show.  Set xDelay to the time in ticks you want to block for, then remove the two lines:           xDelay = xNextTime – xTaskGetTickCount ();           xNextTime += ( portTickType ) 10; Take a look at the FreeRTOS/Demo/Common/minimal/flash.c file for an example of using xTaskDelayUntil(). > my questions: > > 1) what values must i give to xTaskCreate() The idea of the demo applications is that you have a working example to start with, if you are using the same hardware, or a very good starting point if not using the same hardware.  Check the documentation for xTaskCreate() (which should be better than that for vTaskDelay()!), and look at the numerous examples in the Demo/Common/minimal directory. > 2) how do i @ those tasks to the Scheduler. Just calling xTaskCreate() will add them to the scheduler. > 3) vTaskDelay can i make that something like vTaskDelay(100); Yes – that is the idea.  I will change the docs to do the same.  Search for vTaskDelay() in the C files within the demo directory. The delay period is in ticks, the frequency of the ticks depends on your settings and hardware.  configTICK_RATE_HZ should be defined in FreeRTOSConfig.h, and this can be used to convert ticks to seconds (ms being more normal). Regards.

Need help 4 taskts and delay

I have updated the documentation page: http://www.freertos.org/a00127.html  You might need to refresh to see the new page. Regards.

Need help 4 taskts and delay

ty for quick reply wil check it out now. i am using the AT90USB1287 by the way :). dragie

Need help 4 taskts and delay

back again, makeing tasks = working now. toggeling leds = working. the delay i can’t get working. i did the following: void vTaskLed1(void *pvParameters) {    const portTickType xDelay = 500 / oirtTick_RATE_MS;    (void) pvParameters;    for(;;)    {       PORTD = 0x40; // toggle a led       vTaskDelay (xDelay);       PORTD = 0x00; // toggle all leds off;       vTaskDelay (xDelay);    } } so the led must go on 1 for 500 ms and then turn off for 500 ms. he turns on but never turns off :(. i got a 8Mhz Crystal so i put in FreeRTOSConfig.h #define configCPU_CLOCK_HZ ((unsigned portLONG) 8000000) anny1 know what might is going wrong?? regards, dragie

Need help 4 taskts and delay

vTaskDelay = turned to 1 in that config to didn’t see an edit button :(

Need help 4 taskts and delay

If you are writing to PORTD from more than one task you might get conflicts. Do you want to do a PORTD |= and PORTD &= rather than setting it directly. Also you might want to put a critical section around it. for(;;){ portENTER_CRITICAL(); PORTD |= 0x40; portEXIT_CRITICAL(); vTaskDelay( xDelay ); portENTER_CRITICAL(); PORTD &= ~0x40; portEXIT_CRITICAL(); vTaskDelay( xDelay ); }

Need help 4 taskts and delay

ty for quick reply i know |= and &= is bether to use i changed it 😛 was just testing to run some task with  basic leds so was some "quick and dirty source". dunno if those portENTER_CRITICAL i searcht on it and it says something about interrupts. but i tryed it and stil the leds don’t go off just seems the delay aint working :( anny1 got an other idee why delay aint working?? regards dragie