Quantcast
Channel: Altera Forums
Viewing all articles
Browse latest Browse all 19390

The microc don't do anothers tasks

$
0
0
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:

Code:

#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[TASK_STACKSIZE];
OS_STK    task2_stk[TASK_STACKSIZE];

/* 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[TASK_STACKSIZE-1],
                  TASK1_PRIORITY,
                  TASK1_PRIORITY,
                  task1_stk,
                  TASK_STACKSIZE,
                  NULL,
                  0);
             
             
  OSTaskCreateExt(task2,
                  NULL,
                  (void *)&task2_stk[TASK_STACKSIZE-1],
                  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

Viewing all articles
Browse latest Browse all 19390

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>