Beispiel #1
0
int main (int argc, char* argv[], char* envp[])
{

  INT8U error_code;

  /* Clear the RTOS timer */
  OSTimeSet(0);

  /* SSSInitialTask will initialize the NicheStack
   * TCP/IP Stack and then initialize the rest of the Nios II Simple Socket Server example
   * RTOS structures and tasks.
   */
  error_code = OSTaskCreateExt(SSSInitialTask,
                             NULL,
                             (void *)&SSSInitialTaskStk[TASK_STACKSIZE],
                             SSS_INITIAL_TASK_PRIORITY,
                             SSS_INITIAL_TASK_PRIORITY,
                             SSSInitialTaskStk,
                             TASK_STACKSIZE,
                             NULL,
                             0);
  alt_uCOSIIErrorHandler(error_code, 0);

  /*
   * As with all MicroC/OS-II designs, once the initial thread(s) and
   * associated RTOS resources are declared, we start the RTOS. That's it!
   */
  OSStart();


  while(1); /* Correct Program Flow never gets here. */

  return -1;
}
void ModifyLocalTime(struct timeval* tv)
{
    unsigned int ticks, time;
    time = tv->tv_sec - 1417305600;
    ticks = time * OS_TICKS_PER_SEC; 
    OSTimeSet(ticks);
}
Beispiel #3
0
int main(void)
{
   CPU_INT08U os_err;

   //禁止CPU中断
   CPU_IntDis();
   
   //UCOS 初始化
   OSInit();                                                   /* Initialize "uC/OS-II, The Real-Time Kernel".         */
   
   //硬件平台初始化
	SystemInit();
   BSP_Init();                                                 /* Initialize BSP functions.  */
   
   //默认LED闪烁间隔500ms
   milsec1=1000;   
   //建立主任务, 优先级最高  建立这个任务另外一个用途是为了以后使用统计任务
   os_err = OSTaskCreate((void (*) (void *)) App_TaskStart,	  		  		//指向任务代码的指针
                          (void *) 0,								  		//任务开始执行时,传递给任务的参数的指针
               (OS_STK *) &App_TaskStartStk[APP_TASK_START_STK_SIZE - 1],	//分配给任务的堆栈的栈顶指针   从顶向下递减
               (INT8U) APP_TASK_START_PRIO);								//分配给任务的优先级
   
   //ucos的节拍计数器清0    节拍计数器是0-4294967295    对于节拍频率100hz时, 每隔497天就重新计数 
   OSTimeSet(0);
   OSStart();                                                  /* Start multitasking (i.e. give control to uC/OS-II).  */
                                                 /* Start multitasking (i.e. give control to uC/OS-II).  */
 
   return (os_err);
}
Beispiel #4
0
int main(void)
{
	GPIO_InitTypeDef GPIO_InitStructure;
	 CPU_INT08U os_err;
	 //BSP_Init();			
	 //BSP_IntDisAll();																						/* Disable all ints until we are ready to accept them.	*/
	 CPU_IntDis();
	 
	 OSInit();																									 /* Initialize "uC/OS-II, The Real-Time Kernel".				 */

	 BSP_Init();																								 /* Initialize BSP functions.	*/
	GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
	GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
	GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOC, &GPIO_InitStructure);
	GPIOC->BSRR = 1<<0;

	 os_err = OSTaskCreate((void (*) (void *)) App_TaskStart,
							 /* Create the start task.															 */
													(void *) 0,
							 (OS_STK *) &App_TaskStartStk[APP_TASK_START_STK_SIZE - 1],
							 (INT8U) APP_TASK_START_PRIO);
	 
#if (OS_TASK_NAME_SIZE >= 11)
	 OSTaskNameSet(APP_TASK_START_PRIO, (CPU_INT08U *) "Start Task", &os_err);
#endif

//	 InfoSem = OSSemCreate(0); 
//	 Disp_Box = OSMboxCreate((void *) 0);							 
	 OSTimeSet(0);
	 OSStart();																									/* Start multitasking (i.e. give control to uC/OS-II).	*/

	 return (0);
}
Beispiel #5
0
int main(void)
{
	CPU_INT08U os_err;
	
	//禁止CPU中断
	CPU_IntDis();
	
	//UCOS 初始化
	OSInit();                                                   /* Initialize "uC/OS-II, The Real-Time Kernel".         */
	
	//硬件平台初始化
	BSP_Init();                                                 /* Initialize BSP functions.  */
	/* Configure FSMC Bank1 NOR/PSRAM */

	I2C_Ini();
    HMC5883L_Init();
	HMC5883L_Start();
	MPU6050_Init();	 

		
   //建立主任务, 优先级最高  建立这个任务另外一个用途是为了以后使用统计任务
   os_err = OSTaskCreate((void (*) (void *)) App_TaskStart,	  		  		//指向任务代码的指针
                          (void *) 0,								  		//任务开始执行时,传递给任务的参数的指针
               (OS_STK *) &App_TaskStartStk[APP_TASK_START_STK_SIZE - 1],	//分配给任务的堆栈的栈顶指针   从顶向下递减
               (INT8U) APP_TASK_START_PRIO);								//分配给任务的优先级
   os_err =os_err;
   //ucos的节拍计数器清0    节拍计数器是0-4294967295    对于节拍频率100hz时, 每隔497天就重新计数 
   OSTimeSet(0);
   OSStart();                                                  /* Start multitasking (i.e. give control to uC/OS-II).  */
                                                 /* Start multitasking (i.e. give control to uC/OS-II).  */
 
   return (0);
}
Beispiel #6
0
int main (int argc, char* argv[], char* envp[])
{
  
  INT8U error_code;
  int rc;

  /* Clear the RTOS timer */
  OSTimeSet(0);

  /* Flash LEDs and reset ethernet PHY - $M$*/
#ifdef LED_PIO_BASE
   IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xaa);
   printf("LEDs set to 0xAA\n");
#endif
   rc = usleep(1000000);  // Delay 1 sec

#ifdef NENET_REG_RESET_BASE
  /* Reset the Ethernet PHY */
   printf("Reseting Ethernet PHY...");
   IOWR_ALTERA_AVALON_PIO_DATA(NENET_REG_RESET_BASE, 0x1);  // Be sure it's hi first
   rc = usleep(250000);  // Delay .25 sec
   IOWR_ALTERA_AVALON_PIO_DATA(NENET_REG_RESET_BASE, 0x0);  // Go low for reset
   rc = usleep(250000);  // Delay .25 sec
   IOWR_ALTERA_AVALON_PIO_DATA(NENET_REG_RESET_BASE, 0x1);  // Back to hi - inactive
   printf(" Done\n");
   rc = usleep(250000);  // Delay .25 sec
#endif
#ifdef LED_PIO_BASE
   IOWR_ALTERA_AVALON_PIO_DATA(LED_PIO_BASE, 0xaa);
   printf("LEDs set to 0x55\n");
#endif

  /* SSSInitialTask will initialize the NicheStack
   * TCP/IP Stack and then initialize the rest of the Simple Socket Server example 
   * RTOS structures and tasks. 
   */  
  error_code = OSTaskCreateExt(SSSInitialTask,
                             NULL,
                             (void *)&SSSInitialTaskStk[TASK_STACKSIZE],
                             SSS_INITIAL_TASK_PRIORITY,
                             SSS_INITIAL_TASK_PRIORITY,
                             SSSInitialTaskStk,
                             TASK_STACKSIZE,
                             NULL,
                             0);
  alt_uCOSIIErrorHandler(error_code, 0);

  /*
   * As with all MicroC/OS-II designs, once the initial thread(s) and 
   * associated RTOS resources are declared, we start the RTOS. That's it!
   */
  OSStart();

  
  while(1); /* Correct Program Flow never gets here. */

  return -1;
}
Beispiel #7
0
void ipmi_main_start(void)
{
    // 操作系统初始化
    OSInit();

    // 创建任务并运行
    OSTaskCreate(ipmi_task_main, (void*)0, (OS_STK*)&ipmi_task_stk[STK_SIZE-1], (INT8U)1);
    OSTimeSet(0);
    OSStart();
}
Beispiel #8
0
/* The main function creates two task and starts multi-tasking */
int main(void)
{
  task t1 = {4,60}; // CPU exec, Period
  task t2 = {1,70};
  task t3 = {2,80};
  
  INT8U err;
  
  OSInit();
  OSTaskCreateExt(task1,
                  &t1,
                  (void *)&task1_stk[TASK_STACKSIZE-1],
                  TASK1_PRIORITY,
                  TASK1_PRIORITY,
                  task1_stk,
                  TASK_STACKSIZE,
                  NULL,
                  0,
                  t1.period);
              
               
  OSTaskCreateExt(task2,
                  &t2,
                  (void *)&task2_stk[TASK_STACKSIZE-1],
                  TASK2_PRIORITY,
                  TASK2_PRIORITY,
                  task2_stk,
                  TASK_STACKSIZE,
                  NULL,
                  0,
                  t2.period);
                  
  OSTaskCreateExt(task3,
                  &t3,
                  (void *)&task3_stk[TASK_STACKSIZE-1],
                  TASK3_PRIORITY,
                  TASK3_PRIORITY,
                  task3_stk,
                  TASK_STACKSIZE,
                  NULL,
                  0,
                  t3.period);
                  
  R1 = OSMutexCreate(R1_PRIO, &err);
  R2 = OSMutexCreate(R2_PRIO, &err);
  
  printf("====== SRP Task Set 2 { t1(9,60), t2(3,70), t3(0,80) } (Arrival,Period) ======\n");
  printf("------------------------------------------------------------------------------\n");
  printf("Current Time     Event            System Ceiling                              \n");
  printf("------------------------------------------------------------------------------\n");
  OSTimeSet(0);
  OSStart();
  return 0;
}
Beispiel #9
0
int main(void)
{
	INT8U err;
	OSInit();
	OSTaskCreate(	start_task, 
			(void *)0, //空指针 即NULL
			(OS_STK *)START_TASK_STK[START_STK_SIZE - 1],//最后一个元素作为栈顶
			START_TASK_PRIO);//创建起始任务
	OSTimeSet(0);
	OSStart();
}
//外部中断初始化程序  //初始化PA.0,PC.13为中断输入. 
void EXTI0_IRQHandler(void)
{  	
   OS_ERR 	err;
   OSIntEnter();
   EXTI->PR =EXTI_Line0; ;//清中断标志位
   if (UITtime==0) 
   {
     OSTimeSet(0,(OS_ERR *)err);
   }
   SysTick->VAL=0;
   OSIntExit();
}
Beispiel #11
0
int main(void)
{
    OSInit();
    OSTaskCreate(	start_task,
                    (void *)0, //空指针 即NULL
                    (OS_STK *)START_TASK_STK[START_STK_SIZE - 1],//最后一个元素作为栈顶
                    START_TASK_PRIO);//创建起始任务
    OSTimeSet(0);
    //创建信号量
    pkey = OSSemCreate(0);//参数为cnt,表示计数值
    OSStart();
}
int main(void){  
  
  BSP_Init();
  OSInit();
  OSTaskCreate(Task_Start,(void *)0, 
               &startup_task_stk[STARTUP_TASK_STK_SIZE-1], STARTUP_TASK_PRIO); 
  
  OSTimeSet(0);
  OSStart(); 
 
  return 0;

}
Beispiel #13
0
Datei: main.c Projekt: Gewin/Ucos
int Main(int argc, char **argv)
{
	//初始化目标板
	TargetInit(); 

	//初始化uCOS-II
	OSInit ();	 

	//初始化系统时基
	OSTimeSet(0);

	//创建系统初始任务
	OSTaskCreate (MainTask,(void *)0, &MainTaskStk[MainTaskStkLengh - 1], MainTaskPrio);

	//开始任务
	OSStart ();

	return 0;
}
int main (int argc, char* argv[], char* envp[])
{
  /* Initialize the current flash block, for flash programming. */
  
  current_flash_block = -1;
  
  INT8U error_code;

  /* Clear the RTOS timer */
  OSTimeSet(0);
  
  /* WSInitialTask will initialize the NicheStack TCP/IP Stack and then 
   * initialize the rest of the web server's tasks.
   */ 

  error_code = OSTaskCreateExt(WSInitialTask,
                             NULL,
                             (void *)&WSInitialTaskStk[TASK_STACKSIZE-1],
                             WS_INITIAL_TASK_PRIO,
                             WS_INITIAL_TASK_PRIO,
                             WSInitialTaskStk,
                             TASK_STACKSIZE,
                             NULL,
                             0);
  alt_uCOSIIErrorHandler(error_code, 0);


  /*
   * As with all MicroC/OS-II designs, once the initial thread(s) and 
   * associated RTOS resources are declared, we start the RTOS. That's it!
   */
  OSStart();
  
  while(1); /* Correct Program Flow never gets here. */

  return -1;
}
Beispiel #15
0
/*
*********************************************************************************************************
* Output PWM
*********************************************************************************************************
*
*********************************************************************************************************
*/
void OutputTask(void *p_arg)
{
  CPU_TS ts;
  OS_ERR  err;
  
  CPU_INT16U Commande;
  CPU_INT16U value;
  CPU_INT16U last_value;
  
  float angle_value;
  float angle_Commande;
  
  float PID;
  
  //Flush the first conversion, the data is sometime wrong
  OSSemPend(&semADC_Complete,0,OS_OPT_PEND_BLOCKING,&ts,&err);
  //Reset the ticks for calculation of the frequency of the PID
  OSTimeSet(0,&err);
  
  while (1)
  {
    
    //Pend on data ready from the ADC interrupt
    OSSemPend(&semADC_Complete,0,OS_OPT_PEND_BLOCKING,&ts,&err);
    
    //Get the ADC value
    OSMutexPend(&mutADC,0,OS_OPT_PEND_BLOCKING,&ts,&err);
    value = strSemADC.uValue;
    OSMutexPost(&mutADC,OS_OPT_POST_NONE,&err);
    
    //Get the Command value from Timer3
    OSMutexPend(&mutTMR3,0,OS_OPT_PEND_BLOCKING,&ts,&err);
    Commande = Command;
    OSMutexPost(&mutTMR3,OS_OPT_POST_NONE,&err);
    
    
    //Regression Linéaire
    angle_value = (value-290.45)/19.12;
    angle_Commande = (Commande-600)/10;
    
    
    //Timestamp Print shows that
    //a delay of 50ms is usualy precise on a long period of time so
    // there is no need to calculate it software like
    //float PIDcal(float setpoint,float actual_position,(TIMESTAMP-LASTTIMESTAMP)*Tick_Period)
    //instead we will use a defined value in PID.h for the deltaT
    //To see the veracity of this affirmation, simply enable this printf
    // printf("TS = %d\n\r", GetTimeStamp());
    //According to the usage of the CPU, the delay between calls to this function can change
    //Make sure there is enough process to calculate an efficient PID or use the TIMESTAMP-LASTTIMESTAMP
    //in PID to make sure deltaT is correct
    
    //Calcul du PID
    PID=PIDcal(angle_Commande,angle_value);
    
    //Protection du moteur
    //Arret du moteur si on approxime la commande
    if(abs(angle_Commande - angle_value) < .8)
      TIM1->CCR1=0;
    //Réduction de la vitesse si on approxime la commande
    else if(abs(angle_Commande - angle_value) < 5)
      TIM1->CCR1=(int)(400+150*abs((int)PID));
    //Vérification des limites physique du moteur
    else if(value-last_value > 0)
    {
      if(value-(last_value - value) < 500) //Limite atteinte
        TIM1->CCR1=500;
      else
        TIM1->CCR1=(int)(500+700*abs((int)PID)); //Fonctionnement normal
    }
    else
    {
      if(2*value-last_value > 3500)         //Limite atteinte
        TIM1->CCR1=500;
      else
        TIM1->CCR1=(int)(500+700*abs((int)PID)); //Fonctionnement normal
    }
    
    //Determine le sens du moteur
    if (PID>0)
      TIM1->CCER=0x01;
    else
      TIM1->CCER=0x04;
    
  }
  
}
Beispiel #16
0
int
main(void)
{
   INT8U mute_err;
   int priort;
   int i;

   iniche_net_ready = 0;
   
/* OSInit(); */
   OSTimeSet(0);

   /* create all of the various semaphores */
   mheap_sem_ptr = OSSemCreate(1);      /* npalloc() heap */
   if (!mheap_sem_ptr)
      panic("mheap_sem_ptr create err");

   rcvdq_sem_ptr = OSSemCreate(0);      /* RCVD queue "ready" */
   if (!rcvdq_sem_ptr)
      panic("rcvdq_sem_ptr create err"); 

#ifdef OS_PREEMPTIVE
   for (i = 0; i <= MAX_RESID; i++)
   {
      resid_semaphore[i] = OSSemCreate(1);
      if (!resid_semaphore[i])
         panic("resid_semaphore create err");  
   }
   for (i = 0; i <= MAX_SEMID; i++)
   {
      app_semaphore[i] = OSSemCreate(1);
      if (!app_semaphore[i])
         panic("app_semaphore create err");  
   }
#endif  /* OS_PREEMPTIVE */

#ifndef TCPWAKE_RTOS
   /* 
    * clear global_TCPwakeup_set
    */
   for (i = 0; i < GLOBWAKE_SZ; i++)
   {
      global_TCPwakeup_set[i].ctick = 0;
      global_TCPwakeup_set[i].soc_event = NULL;
      global_TCPwakeup_set[i].semaphore = OSSemCreate(0);
      if (!global_TCPwakeup_set[i].semaphore)
         panic("globwake_semaphore create err");  
   }
   global_TCPwakeup_setIndx = 0;

#endif /* TCPWAKE_RTOS */

   /* We have to lock scheduler while creating net tasks. Even though the RTOS
    * technically running yet, the ISR hooks to change tasks don't know this.
    * Since the UART uses interrupts heavly, we have to resort to this to
    * get console output during net_init.
    */
   OSLockNesting++;
   netmain();        /* Create net tasks */
   OSLockNesting--;

   dprintf("+++ uCOS init, app_priority = %d\n", app_priority);

   OSStart();        /* Jump to uCOS-II - Start system; never returns */
   panic("uCOS-II returned");

   return 0;
}
Beispiel #17
0
/* The main function creates two task and starts multi-tasking */
int main(void)
{
  task t1 = {1*SCALE,5*SCALE};
  task t2 = {2*SCALE,6*SCALE};
  task t3 = {3*SCALE,10*SCALE};
  task t4 = {5*SCALE,15*SCALE};
  

  OSInit();
  OSTaskCreateExt(task1,
                  &t1,
                  (void *)&task1_stk[TASK_STACKSIZE-1],
                  TASK1_PRIORITY,
                  TASK1_PRIORITY,
                  task1_stk,
                  TASK_STACKSIZE,
                  NULL,
                  0,
                  t1.period);
              
               
  OSTaskCreateExt(task2,
                  &t2,
                  (void *)&task2_stk[TASK_STACKSIZE-1],
                  TASK2_PRIORITY,
                  TASK2_PRIORITY,
                  task2_stk,
                  TASK_STACKSIZE,
                  NULL,
                  0,
                  t2.period);
                  
  OSTaskCreateExt(task3,
                  &t3,
                  (void *)&task3_stk[TASK_STACKSIZE-1],
                  TASK3_PRIORITY,
                  TASK3_PRIORITY,
                  task3_stk,
                  TASK_STACKSIZE,
                  NULL,
                  0,
                  t3.period);
  
  OSTaskCreateExt(task4,
                  &t4,
                  (void *)&task4_stk[TASK_STACKSIZE-1],
                  TASK4_PRIORITY,
                  TASK4_PRIORITY,
                  task4_stk,
                  TASK_STACKSIZE,
                  NULL,
                  0,
                  t4.period);
                  
  printf("======= EDF Task Set 2 { t1(1,5) , t2(2,6) , t3(3,10) , t4(5,15) }=============\n");
  printf("------------------------------------------------------------------------------\n");
  printf("Current Time     Event       From Task ID        To Task ID      Response Time\n");
  printf("------------------------------------------------------------------------------\n");
  OSTimeSet(0);
  OSStart();
  return 0;
}
Beispiel #18
0
/* The main function creates two task and starts multi-tasking */
int main(void)
{
  task t1 = {1*SCALE,5*SCALE};
  task t2 = {2*SCALE,8*SCALE};
  task t3 = {3*SCALE,10*SCALE};

  OSInit();
  OSTaskCreateExt(task1,
                  &t1,
                  (void *)&task1_stk[TASK_STACKSIZE-1],
                  TASK1_PRIORITY,
                  TASK1_PRIORITY,
                  task1_stk,
                  TASK_STACKSIZE,
                  NULL,
                  0,
                  t1.period
                  );
              
               
  OSTaskCreateExt(task2,
                  &t2,
                  (void *)&task2_stk[TASK_STACKSIZE-1],
                  TASK2_PRIORITY,
                  TASK2_PRIORITY,
                  task2_stk,
                  TASK_STACKSIZE,
                  NULL,
                  0,
                  t2.period
                  );
                  
  OSTaskCreateExt(task3,
                  &t3,
                  (void *)&task3_stk[TASK_STACKSIZE-1],
                  TASK3_PRIORITY,
                  TASK3_PRIORITY,
                  task3_stk,
                  TASK_STACKSIZE,
                  NULL,
                  0,
                  t3.period
                  );
                  
  OSTaskCreateExt(aptask,
                  NULL,
                  (void *)&aptask_stk[TASK_STACKSIZE-1],
                  APTASK_PRIORITY,
                  APTASK_PRIORITY,
                  aptask_stk,
                  TASK_STACKSIZE,
                  NULL,
                  0,
                  65535
                  );
                  
  printf("============ CUS Task Set 1 { t1(1,5) , t2(2,8) , t3(3,10) }==================\n");
  printf("========================= CUS Server Size = 2/8 ==============================\n");
  printf("------------------------------------------------------------------------------\n");
  printf("Current Time     Event       From Task ID        To Task ID      Response Time\n");
  printf("------------------------------------------------------------------------------\n");
  OSTimeSet(0);
  OSStart();
  return 0;
}