Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12604 Discussions

The microc don't do anothers tasks

Altera_Forum
Honored Contributor II
962 Views

Hi, I was reading the example code "hello_ucosii.c", but when I modify the code he made only the task1. My code modified is: 

 

# include <stdio.h># include "includes.h"# include "system.h"# include <unistd.h># include "altera_avalon_pio_regs.h"# include "alt_types.h" /* Definition of Task Stacks */# define TASK_STACKSIZE 2048 OS_STK task1_stk; OS_STK task2_stk; /* Definition of Task Priorities */ # define TASK1_PRIORITY 1# define TASK2_PRIORITY 2 /*Subroutine for wait a necessary time for each level of PWM signal*/ int count(float n, float f) { int i; float a, x; x=(1/f)*2000000; a=n*x; for(i=1; i<=a; i++) { x=0; } return n; } /* Gerate a PWM Signal */ void task1(void* pdata) { int signal, control; float f, n; f=100;//22Hz in practice while(1) { control=IORD_ALTERA_AVALON_PIO_DATA(DUTY_PIO_BASE); if(control==0x0) { signal=0x0; IOWR_ALTERA_AVALON_PIO_DATA(PWM_PIO_BASE, signal); } if(control==0x1) { n=0.25*(1/f); signal=0x1; IOWR_ALTERA_AVALON_PIO_DATA(PWM_PIO_BASE, signal); n=count(n,f); n=(1-0.25)*(1/f); signal=0x0; IOWR_ALTERA_AVALON_PIO_DATA(PWM_PIO_BASE, signal); n=count(n,f); } if(control==0x3) { n=0.50*(1/f); signal=0x1; IOWR_ALTERA_AVALON_PIO_DATA(PWM_PIO_BASE, signal); n=count(n,f); n=(1-0.50)*(1/f); signal=0x0; IOWR_ALTERA_AVALON_PIO_DATA(PWM_PIO_BASE, signal); n=count(n,f); } if(control==0x7) { n=0.75*(1/f); signal=0x1; IOWR_ALTERA_AVALON_PIO_DATA(PWM_PIO_BASE, signal); n=count(n,f); n=(1-0.75)*(1/f); signal=0x0; IOWR_ALTERA_AVALON_PIO_DATA(PWM_PIO_BASE, signal); n=count(n,f); } if(control==0xf) { signal=0x1; IOWR_ALTERA_AVALON_PIO_DATA(PWM_PIO_BASE, signal); } } } /* Prints "Hello World" and sleeps for three seconds */ void task2(void* pdata) { while (1) { printf("Hello from task2\n"); OSTimeDlyHMSM(0, 0, 3, 0); } } /* The main function creates two task and starts multi-tasking */ int main(void) { OSTaskCreateExt(task1, NULL, (void *)&task1_stk, TASK1_PRIORITY, TASK1_PRIORITY, task1_stk, TASK_STACKSIZE, NULL, 0); OSTaskCreateExt(task2, NULL, (void *)&task2_stk, TASK2_PRIORITY, TASK2_PRIORITY, task2_stk, TASK_STACKSIZE, NULL, 0); OSStart(); return 0; }  

 

I'm use Quartus II 9.1 sp2 web edition, Nios II EDS 9.1 sp2 and the DE2 board series. 

 

Thank you in advance
0 Kudos
4 Replies
Altera_Forum
Honored Contributor II
233 Views

Your tasks probably need to explicilty sleep, otherwise the current task will run forever. 

Even if your tasks had the same priority you'll need to do some call in order to get the other task to run.
0 Kudos
Altera_Forum
Honored Contributor II
233 Views

The highest priority task runs until it blocks. 

 

In your code snippet, "TASK1" has the highest priority but never blocks, while "TASK2" has lower priority but sleeps for 3 seconds at a time. 

 

Switch the priorities around and try again.
0 Kudos
Altera_Forum
Honored Contributor II
233 Views

I change the priority of the tasks and worked, but I wish that the two tasks were performed simultaneously. Is that possible?

0 Kudos
Altera_Forum
Honored Contributor II
233 Views

Well, "simultaneously" is not possible. 

 

If you want round-robin scheduling ("timeslicing"), it is not available in version II of this RTOS, but it is available in version III. 

 

The snippet you posted looks like a simple polling loop. If you are simply saying you have many of such polling loops, just use one task and execute the polling loops one after the other. 

e.g. 

while(1) { 

poll_blockA(); 

poll_blockB(); 

poll_blockC(); 

 

 

Other than that, you are left to crafting your own application level scheduling using e.g. mutex or messages to get your polling to happen in the order you would like. Or, you could start using interrupts and only run your polling when your inputs change, for example.
0 Kudos
Reply