示例#1
0
/*
*********************************************************************************************************
*                                       AnalogCaptureTask TASK
*
*********************************************************************************************************
*/
void  AnalogCaptureTask (void *p_arg)
{
  (void)p_arg;                                                /* Prevent compiler warning                                 */
  
  OS_ERR      err = 0;
  CPU_INT32U  uCount = 0;  
  
  static      ADC_CONTROL_BLOCK_t strAdcControlBlock;
  InitAdcControlBlock(&strAdcControlBlock);                  /* Initialize ADC control structures                        */
  InitADCPort();                                              /* Initialize the ADC                                       */
  
  OSSemCreate(&semAdcIntSignal,"ADC EOC Int signal",0,&err);
  OSSemCreate(&semADC_Complete,"ADC completed semaphore",0,&err); 
  OSMutexCreate(&mutADC,"ADC value",&err);
  OSMutexCreate(&mutTMR3,"PWM in",&err);
  
  while (TRUE) {
    OSTimeDlyHMSM(0, 0, 0, 50,                             /* Performs conversions every 100 ms.                       */
                  OS_OPT_TIME_HMSM_STRICT,
                  &err);
    ADC1->CR2 |= 1<<21;                                     /* Trigger the conversion                                   */
    OSSemPend(&semAdcIntSignal,                             /* Wait for the end of conversion                           */
              0,                                            /* (This semaphore is posted by the ADC1_ISR)               */
              OS_OPT_PEND_BLOCKING,
              (CPU_TS*)NULL,&err);
    
    ReportAdcSample(ADC_CHANNEL_1, &strAdcControlBlock);
    if (++uCount > 5)
    {
      BSP_LED_Toggle(2);                                  /* Toggle the BSP Led #3                                    */
      uCount = 0;
    }
  }
}
示例#2
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;
}
示例#3
0
void  OS_TLS_LockCreate (void  **p_lock)
{
    OS_TLS_LOCK   *p_tls_lock;
    OS_ERR         os_err;
    CPU_SR_ALLOC();

    
    if (p_lock == (void **)0) {
        return;
    }

    if (OS_TLS_LockPoolListPtr == (OS_TLS_LOCK *)0) {             /* If 'OS_TLS_LOCK' object pool is empty?           */
        *p_lock = (void *)0;                                      /*   return a 'NULL' pointer.                       */
        return;
    }

    p_tls_lock = OS_TLS_LockPoolListPtr;                          /* Get the first object in the list.                */

    OSMutexCreate((OS_MUTEX *)&p_tls_lock->Mutex,                 /* Create the mutex in the kernel.                  */
                  (CPU_CHAR *) 0,				       
                  (OS_ERR   *)&os_err);			       
                             					       
    if (os_err != OS_ERR_NONE) {                                  /* If the mutex create funtion fail?                */
        *p_lock = (void *)0;                                      /* ... return a 'NULL' pointer.                     */
         return;        						       
    }											       

    CPU_CRITICAL_ENTER();
    OS_TLS_LockPoolListPtr = p_tls_lock->NextPtr;                 /* Move HEAD pointer to the next object in the list.*/
    CPU_CRITICAL_EXIT();
    
    *p_lock = (void *)p_tls_lock;                                 /* Return the new 'OS_TLS_LOCK' object pointer.     */
}
void motion_CalibrationInit(void)
{
	REGISTER_LOG_CLIENT("MOTION");
	
	mtxDefaultSpeeds = OSMutexCreate(DEF_SPEED_MTX_PRIO, &OSLastError);
	LOG_TEST_OS_ERROR(OSLastError);
	
	encoder_SetDist(DEFAULT_ENCODER_DIST);
	encoder_SetResolution(DEFAULT_LEFT_TICKS_PER_M, DEFAULT_RIGHT_TICKS_PER_M);
		
	slippageThreshold = DEFAULT_SLIPPAGE;
	
	isSendErrorsEnabled = FALSE;
	
	odometrySensorUsed = MOUSE_SENSOR;
	
	pid_ConfigKP(motors[ALPHA_DELTA][ALPHA_MOTOR].PIDSys, 3000);
	pid_ConfigKI(motors[ALPHA_DELTA][ALPHA_MOTOR].PIDSys, 10);
	pid_ConfigKD(motors[ALPHA_DELTA][ALPHA_MOTOR].PIDSys, 10000);
	pid_ConfigDPeriod(motors[ALPHA_DELTA][ALPHA_MOTOR].PIDSys, 3);
	
	pid_ConfigKP(motors[ALPHA_DELTA][DELTA_MOTOR].PIDSys, 3000);
	pid_ConfigKI(motors[ALPHA_DELTA][DELTA_MOTOR].PIDSys, 10);
	pid_ConfigKD(motors[ALPHA_DELTA][DELTA_MOTOR].PIDSys, 5000);
	pid_ConfigDPeriod(motors[ALPHA_DELTA][DELTA_MOTOR].PIDSys, 3);
	
	
	pid_ConfigKP(motors[LEFT_RIGHT][LEFT_MOTOR].PIDSys, 2500);
	pid_ConfigKP(motors[LEFT_RIGHT][RIGHT_MOTOR].PIDSys, 2500);
	
	//register handlers
	protocol_SetHandler(M32_WHEEL_PID_TUNING, motion_wheelPIDTuning_handler);
	protocol_SetHandler(M32_ALPHADELTA_PID_TUNING, motion_alphaDeltaPIDTuning_handler);
	protocol_SetHandler(M32_ODOMETRY_TUNING, motion_odometryTuning_handler);
}
示例#5
0
int main() {
  uint8_t error;

  /* Initialise the hardware */ 
  bspInit();
  interfaceInit(NO_DEVICE);

  /* Initialise the OS */
  OSInit();                                                   

  /* Create Tasks */
  OSTaskCreate(appTaskCanReceive,                               
               (void *)0,
               (OS_STK *)&appTaskCanReceiveStk[APP_TASK_CAN_RECEIVE_STK_SIZE - 1],
               APP_TASK_CAN_RECEIVE_PRIO);
 
  OSTaskCreate(appTaskCanMonitor,                               
               (void *)0,
               (OS_STK *)&appTaskCanMonitorStk[APP_TASK_CAN_MONITOR_STK_SIZE - 1],
               APP_TASK_CAN_MONITOR_PRIO);

  /* Create Semaphores and Mutexes */
  can1RxSem = OSSemCreate(0);
  displayMutex = OSMutexCreate(DISPLAY_MUTEX_PRIO, &error);
      
  /* Start the OS */
  OSStart();                                                  
  
  /* Should never arrive here */ 
  return 0;      
}
示例#6
0
// ------------------------------------------------------------------------------------------------
void TaskOdo_Main(void *p_arg)
{
	INT8U err		= ERR__NO_ERROR;
	static int i	= 0;				// Refresh sending UART

	unsigned char no_movement_flag = 1;
	
	AppDebugMsg("OUFFF TEAM 2013 : Odo online\n");

	SemOdo = OSSemCreate(0);
	MutexCurrentPos = OSMutexCreate(APP_MUTEX_ODO_PRIO, &err);
	if((NULL == MutexCurrentPos) || (NULL == SemOdo))
	{
		AppDebugMsg("DEBUG (TaskOdo.c) : Error -> Unable to create Semaphore or Mutex\n");
		AppDebugMsg("DEBUG (TaskOdo.c) : Entering in sleeping mode...\n");	
		while(OS_TRUE)		// Infinite Loop
			OSTimeDlyHMSM(1, 0, 0, 0);		
	}


	#ifdef _TARGET_440H
		while(OS_TRUE)
		{
			// Update current Odo value

			TaskDebug_UpdateValueFloat(TASKDEBUG_ID_POS_X, TaskOdo_CurrentPos.x);
			TaskDebug_UpdateValueFloat(TASKDEBUG_ID_POS_Y, TaskOdo_CurrentPos.y);
			TaskDebug_UpdateValueAngle(TASKDEBUG_ID_POS_ANGLE, TaskOdo_CurrentPos.angle);
			
			OSTimeDlyHMSM(0, 0, 1, 0);		
		}
	#endif

	init_position_manager();

	TMR2_Init();

	while(OS_TRUE)
	{
		OSSemPend(SemOdo,100,&err);
		if(err==OS_NO_ERR)
		{
			#ifdef ODO_CALIBRATION
				encoders_calibration_measure();
			#else
				position_manager_process();

				//no_movement_flag = movement_detection();
			#endif
		}

		// Update current Odo value
		TaskDebug_UpdateValueFloat(TASKDEBUG_ID_POS_X, TaskOdo_CurrentPos.x);
		TaskDebug_UpdateValueFloat(TASKDEBUG_ID_POS_Y, TaskOdo_CurrentPos.y);
		TaskDebug_UpdateValueAngle(TASKDEBUG_ID_POS_ANGLE, TaskOdo_CurrentPos.angle);

		OSTimeDly(1);
	}
}
示例#7
0
文件: app.c 项目: Lyanzh/StepCounter
int  main (void)
{
    OS_ERR  err;

#if (CPU_CFG_NAME_EN == DEF_ENABLED)
    CPU_ERR     cpu_err;
#endif


    CPU_Init();                                                 /* Initialize the CPU abstraction layer.                */

    Mem_Init();                                                 /* Initialize the Memory Management Module.             */

    Math_Init();                                                /* Initialize the Mathematical Module.                  */

#if (CPU_CFG_NAME_EN == DEF_ENABLED)
    CPU_NameSet((CPU_CHAR *)"MKL46Z256VLL4",
                (CPU_ERR  *)&cpu_err);
#endif

    BSP_IntDisAll();                                            /* Disable all interrupts.                              */

#if (defined(TRACE_CFG_EN) && (TRACE_CFG_EN > 0u))
    TRACE_INIT();                                               /* Initialize the µC/Trace recorder.                    */
    TRACE_START();                                              /* Start recording.                                     */
#endif

    OSInit(&err);                                               /* Initialize "uC/OS-III, The Real-Time Kernel".        */
	
    OSMutexCreate((OS_MUTEX  *)&AppMutex,
                 (CPU_CHAR   *)"My App. Mutex",
                 (OS_ERR     *)&err);
  
    OSQCreate    ((OS_Q      *)&AppQ,
                 (CPU_CHAR   *)"My App Queue",
                 (OS_MSG_QTY  )10,
                 (OS_ERR     *)&err);

    OSTaskCreate((OS_TCB     *)&App_TaskStartTCB,               /* Create the startup task.                             */
                 (CPU_CHAR   *)"Startup Task",
                 (OS_TASK_PTR ) App_TaskStart,
                 (void       *) 0,
                 (OS_PRIO     ) APP_CFG_TASK_START_PRIO,
                 (CPU_STK    *)&App_TaskStartStk[0],
                 (CPU_STK     )(APP_CFG_TASK_START_STK_SIZE / 10u),
                 (CPU_STK_SIZE) APP_CFG_TASK_START_STK_SIZE,
                 (OS_MSG_QTY  ) 0,
                 (OS_TICK     ) 0,
                 (void       *) 0,
                 (OS_OPT      )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
                 (OS_ERR     *)&err);

    OSStart(&err);                                              /* Start multitasking (i.e. give control to uC/OS-III). */

    while(DEF_ON) {                                             /* Should Never Get Here                                */
    };
}
示例#8
0
CAN_RESULT CANBufInit(void)
{
  INT8U err;
  CANBufClear();
  buffer_mutex = OSMutexCreate(CAN_MUTEX_PRIO, &err);
  if (err != OS_ERR_NONE)
    return CAN_NO_MUTEX;
  return CAN_OK;
}
void main(){
	OSInit(); 
	OSTaskCreate(task1, (void *)0, &task1_stack[255], 5); 
	OSTaskCreate(task2, (void *)0, &task2_stack[255], 6);
	mymutex = OSMutexCreate(4,&err);
	myq = OSQCreate(qmsg, 10);
	u1init();
	DDRC=0xff;
	OSStart(); 
}
示例#10
0
void alt_iniche_init(void)
{
   extern OS_EVENT * mheap_sem_ptr;
   extern void *net_task_sem_ptr;

   /* initialize the npalloc() heap semaphore */
   mheap_sem_ptr = OSSemCreate(1);
   if (!mheap_sem_ptr)
      panic("mheap_sem_ptr create err"); 

   /* get the uCOS semaphore used for LOCK_NET_RESOURCE(NET_RESID) */
   net_task_sem_ptr = (void*)OSSemCreate(1);
   if (!net_task_sem_ptr)
      panic("net_task_sem_ptr create err"); 

   rcvdq_sem_ptr = OSSemCreate(0);
   if (!rcvdq_sem_ptr)
      panic("rcvdq_sem_ptr create err"); 

#ifdef OS_PREEMPTIVE
   ping_sem_ptr = OSSemCreate(0);       /* PING app */
   if (!ping_sem_ptr)
      panic("ping_sem_ptr create err");  
      
   ftpc_sem_ptr = OSSemCreate(0);       /* FTP Client app */
   if (!ftpc_sem_ptr)
      panic("ftpc_sem_ptr create err");  
#endif  /* OS_PREEMPTIVE */

#ifndef TCPWAKE_RTOS
   /* 
    * clear global_TCPwakeup_set
    */
   {
      int i;

      for (i = 0; i < GLOBWAKE_SZ; i++)
      {
         global_TCPwakeup_set[i].ctick = 0;
      }
      global_TCPwakeup_setIndx = 0;
   }

   {
      INT8U mute_err;

      global_wakeup_Mutex = OSMutexCreate(WAKEUP_MUTEX_PRIO, &mute_err);
      if (mute_err != OS_NO_ERR)
      {
         dprintf("*** uCOS init, can't create global_wakeup_Mutex = %d\n", mute_err);
         dtrap();
      }
   }
#endif  /* TCPWAKE_RTOS */
}
示例#11
0
文件: main.c 项目: fjbali/stm32-diy
int main(void)
{
	INT8U err = 1;

    OSInit();	 //初始化 uC/OS-II 
	mutex=OSMutexCreate(3,&err);	// 建立互斥信号量
	key_Sem = OSSemCreate(0);  	    // 建立信号量  起始值为0 
    OSTaskCreate(TaskStart,(void*)0,&TaskStartStk[TASK_START_STK_SIZE-1],1); // 创建起始任务,赋予最高优先级1 
    OSStart();					   //开始多任务
	D1_H;D2_H;D3_H;D4_H;D5_H;D6_H;D7_H;D1_H;D8_H;D9_H;D10_H;D11_H;D12_H;D13_H;D14_H;D15_H;D16_H;D18_H;
}
示例#12
0
int ff_cre_syncobj (	/* !=0:Function succeeded, ==0:Could not create due to any error */
	BYTE vol,			/* Corresponding logical drive being processed */
	_SYNC_t *sobj		/* Pointer to return the created sync object */
)
{
	int ret;
    OS_ERR err;
	OSMutexCreate(sobj, "fatfs_mutex", &err);		/* uC/OS-III */
	ret = (int)(err == OS_ERR_NONE);
	return ret;
}
示例#13
0
/*!
* @brief Initialize the reentrant LCD driver.
*/
void protected_lcd_init(void)
{
    OS_ERR err;
    
    OSMutexCreate(&lcd_mutex, "LCD Mutex", &err);
    assert(OS_ERR_NONE == err);
    OSMutexPend(&lcd_mutex, 0, OS_OPT_PEND_BLOCKING, 0, &err);
    assert(OS_ERR_NONE == err);
    InitialiseLCD();
    OSMutexPost(&lcd_mutex, OS_OPT_POST_NONE, &err);
    assert(OS_ERR_NONE == err);
}
示例#14
0
/* Init OS */
void GUI_X_InitOS(void)
{
	OS_ERR err;
	
	/* Create Mutex lock */
	OSMutexCreate(&xQueueMutex, "QueueMutex", &err);
	//configASSERT (err == OS_ERR_NONE);

	/* Queue Semaphore */ 
	OSSemCreate( &xSemaTxDone, "TxDoneSem", 0, &err);
	//configASSERT ( err == OS_ERR_NONE );
}
示例#15
0
bool_t osCreateMutex(OsMutex *mutex)
{
   OS_ERR err;

   //Create a mutex
   OSMutexCreate(mutex, "MUTEX", &err);

   //Check whether the mutex was successfully created
   if(err == OS_ERR_NONE)
      return TRUE;
   else
      return FALSE;
}
示例#16
0
bool Solenoid::init(){
	INT8U err = OS_NO_ERR;
	solenoidSem = OSSemCreate(0);
	if (solenoidSem == NULL){
		printf("Error initializing solenoid semaphore");
		return false;
	}

	solenoidMutex = OSMutexCreate(0, &err);
	if(err != OS_NO_ERR){
		printf("Error initializing solenoid mutex\n");
		return false;
	}
	return true;
}
示例#17
0
void network_adapter_init(void)
{
	unsigned char err = 0;

	TCPServerFd = -1;
	UDPServerFd = -1;

	/* Alloc TCP server recv buffer */
    TCPServerRecv_data = malloc(TCP_SERVER_BUFFER_SIZE);
	UDPServerRecv_data = malloc(UDP_SERVER_BUFFER_SIZE);

	/* Init Agent cloud resource */    
    cloud_send_mutex_lock = OSMutexCreate(CLOUD_MUTEX_LOCK_PRIO, &err);
	Agent_cloud_init();
}
/*FUNCTION**********************************************************************
 *
 * Function Name : OSA_MutexCreate
 * Description   : This function is used to create a mutex.
 * Return kStatus_OSA_Success if create successfully, otherwise return
 * kStatus_OSA_Error.
 *
 *END**************************************************************************/
osa_status_t OSA_MutexCreate(mutex_t *pMutex)
{
    OS_ERR err;

    OSMutexCreate(pMutex, "mutex", &err);

    if (OS_ERR_NONE == err)
    {
        return kStatus_OSA_Success;
    }
    else
    {
        return kStatus_OSA_Error;
    }
}
CPU_BOOLEAN  BSP_OS_RIIC0_MutexCreate (void)
{
    OS_ERR  err;

    
    OSMutexCreate(&RIIC0_Mutex,
                  "RIIC0 Mutex",
                  &err);
                    
    if (err != OS_ERR_NONE) {
        return (DEF_FAIL);
    }
    
    return (DEF_OK);
}
CPU_BOOLEAN  BSP_OS_GLCD_MutexCreate (void)
{
    OS_ERR  err;


    OSMutexCreate(&GLCD_Mutex,
                  "GLCD Mutex",
                  &err);

    if (err != OS_ERR_NONE) {
        return (DEF_FAIL);
    }

    return (DEF_OK);
}
/*FUNCTION**********************************************************************
 *
 * Function Name : OSA_MutexCreate
 * Description   : This function is used to create a mutex.
 * Return kStatus_OSA_Success if create successfully, otherwise return
 * kStatus_OSA_Error.
 *
 *END**************************************************************************/
osa_status_t OSA_MutexCreate(mutex_t *pMutex)
{
    INT8U err;

    /* NOTE: uC/OS-II does not support priority inherit but only priority protect */
    *pMutex = OSMutexCreate(OS_PRIO_MUTEX_CEIL_DIS, &err);

    if (OS_ERR_NONE == err)
    {
        return kStatus_OSA_Success;
    }
    else
    {
        return kStatus_OSA_Error;
    }
}
示例#22
0
void UART_init(INT8U priority)
{  
  UART_CTRL1 = 0x12;               /* Configure the SCI */ 
  /* SCI1C3: R8=0,T8=0,TXDIR=0,TXINV=0,ORIE=0,NEIE=0,FEIE=0,PEIE=0 */  
  UART_CTRL3 = 0x00;               /* Disable error interrupts */ 
  /* SCI1S2: ??=0,??=0,??=0,??=0,??=0,BRK13=0,??=0,RAF=0 */
  UART_STAT2 = 0x00;                
  /* SCI1C2: TIE=0,TCIE=0,RIE=0,ILIE=0,TE=0,RE=0,RWU=0,SBK=0 */
  UART_CTRL2 = 0x00;               /* Disable all interrupts */ 
  
  // 0x4E = 19200 bauds at 24Mhz /////  0x52 = 19200 bauds at 25.33Mhz
  // 0x20 = 38400 bauds at 24Mhz /////  0x29 = 38400 bauds at 25.33Mhz
  // 0x16 = 57600 bauds at 24Mhz /////  0x1B = 57600 bauds at 25.33Mhz
  UART_BDH = 0x00;   /* Set high divisor register (enable device) */
  UART_BDL = 0x1B;   /* Set low divisor register (enable device) */        /* Configure the SCI */ 
  
  /* SCI1C3: ORIE=1,NEIE=1,FEIE=1,PEIE=1 */
  UART_CTRL3 |= 0x0F;                      /* Enable error interrupts */
  //SCI1C2 |= ( SCI1C2_TE_MASK | SCI1C2_RE_MASK | SCI1C2_RIE_MASK); /*  Enable transmitter, Enable receiver, Enable receiver interrupt */
  UART_CTRL2 = 0x2C;
  
  (void)UART_STAT1;    /* Leitura do registrador SCI1S1 para analisar o estado da transmissão */
  (void)UART_STAT2;    /* Leitura do registrador SCI1S1 para analisar o estado da transmissão */
  (void)UART_CTRL3;    /* Leitura do registrador SCI1C3 para limpar o bit de paridade */  

  // Cria um mutex com contador = 1, informando que o recurso está disponível
  // após a inicialização
  // Prioridade máxima a acessar o recurso = priority
  if (OSMutexCreate(&SerialResource,priority) != ALLOC_EVENT_OK)
  {
    while(1){};
  }  
  
  if (OSSemCreate(0, &SerialTX) != ALLOC_EVENT_OK)
  {
    while(1){};
  }  
  
  if (OSQueueCreate(&SerialPortBuffer,SERIALPORT_BUFFERSIZE, &Serial) != ALLOC_EVENT_OK)
  {
    while(1){};
  } 
  
}
示例#23
0
int ff_cre_syncobj (	/* !=0:Function succeeded, ==0:Could not create due to any error */
	BYTE vol,			/* Corresponding logical drive being processed */
	_SYNC_t *sobj		/* Pointer to return the created sync object */
)
{
	int ret;


//	*sobj = CreateMutex(NULL, FALSE, NULL);		/* Win32 */
//	ret = (int)(*sobj != INVALID_HANDLE_VALUE);

//	*sobj = SyncObjects[vol];			/* uITRON (give a static created sync object) */
//	ret = 1;							/* The initial value of the semaphore must be 1. */

	*sobj = OSMutexCreate(0, &err);		/* uC/OS-II */
	ret = (int)(err == OS_NO_ERR);

//	*sobj = xSemaphoreCreateMutex();	/* FreeRTOS */
//	ret = (int)(*sobj != NULL);

	return ret;
}
示例#24
0
void main()
{
	INT8U err;
	OSInit();
	InitDisplay();
	// create tasks with 512 byte stacks.
	OSTaskCreate(MasterTask, NULL, 512, 6);
	OSTaskCreate(UserTask,   NULL, 512, 7);

	// create mutex used by tasks.  Priority inversion
	// priority is set to 5 (1 less that highest priority
	// task).
	GuessMutex = OSMutexCreate(5, &err);
	if(err != OS_NO_ERR)
		exit(err);

	// create event flags used by tasks, initially set to 0.
	ColorFlags = OSFlagCreate(0x00, &err);
	if(err != OS_NO_ERR)
		exit(err);
	OSStart();
}
示例#25
0
/*
*********************************************************************************************************
*                                          AppObjCreate()
*
* Description : Create Application Kernel Objects.
*
* Argument(s) : none
*
* Return(s)   : none
*
* Caller(s)   : AppTaskStart()
*
* Note(s)     : none.
*********************************************************************************************************
*/
static  void  AppObjCreate (void)
{
    OS_ERR  os_err;


#if (OS_CFG_SEM_EN > 0u)
    OSSemCreate(&AppTaskObjSem,
                "Sem Test",
                 0u,
                &os_err);

    OSSemCreate(&AppTraceSem,
                "Trace Lock",
                 1u,
                &os_err);
#endif

#if (OS_CFG_MUTEX_EN > 0u)
    OSMutexCreate(&AppTaskObjMutex,
                  "Mutex Test",
                  &os_err);
#endif

#if (OS_CFG_Q_EN > 0u)
    OSQCreate(&AppTaskObjQ,
              "Queue Test",
               1,
              &os_err);
#endif

#if (OS_CFG_FLAG_EN > 0u)
    OSFlagCreate(&AppTaskObjFlag,
                 "Flag Test",
                  DEF_BIT_NONE,
                 &os_err);
#endif
}
示例#26
0
void test_mutex()
{
	INT8U err;

	if(1 == test_switch) {

		return;
	}

	test_switch = 1;

	p_mutex = OSMutexCreate(4, &err); 

	if(0 == p_mutex) {
	
		printk("error in OSMutexCreate\n");
	}

	OSTaskCreate( test_task1, 0, &stk1[STK_LEN -1], 5);

	OSTaskCreate( test_task2, 0, &stk2[STK_LEN -1], 6);
	

}
示例#27
0
文件: os_tmr.c 项目: binhfile/stm32
void  OS_TmrInit (OS_ERR  *p_err)
{
#ifdef OS_SAFETY_CRITICAL
    if (p_err == (OS_ERR *)0) {
        OS_SAFETY_CRITICAL_EXCEPTION();
        return;
    }
#endif

#if OS_CFG_DBG_EN > 0u
    OSTmrDbgListPtr = (OS_TMR *)0;
#endif

    OSTmrListPtr        = (OS_TMR *)0;                      /* Create an empty timer list                             */
    OSTmrListEntries    = 0u;

    if (OSCfg_TmrTaskRate_Hz > (OS_RATE_HZ)0) {
        OSTmrUpdateCnt  = OSCfg_TickRate_Hz / OSCfg_TmrTaskRate_Hz;
    } else {
        OSTmrUpdateCnt  = OSCfg_TickRate_Hz / (OS_RATE_HZ)10;
    }
    OSTmrUpdateCtr      = OSTmrUpdateCnt;

    OSTmrTickCtr        = (OS_TICK)0;

    OSTmrTaskTimeMax    = (CPU_TS)0;

#if   OS_CFG_MUTEX_EN > 0u
    OSMutexCreate(&OSTmrMutex,                              /* Use a mutex to protect the timers                      */
                  "OS Tmr Mutex", 
                  p_err);
    if (*p_err != OS_ERR_NONE) {
        return;
    }
#endif

                                                            /* ---------------- CREATE THE TIMER TASK --------------- */
    if (OSCfg_TmrTaskStkBasePtr == (CPU_STK*)0) {
       *p_err = OS_ERR_TMR_STK_INVALID;
        return;
    }

    if (OSCfg_TmrTaskStkSize < OSCfg_StkSizeMin) {
       *p_err = OS_ERR_TMR_STK_SIZE_INVALID;
        return;
    }

    if (OSCfg_TmrTaskPrio >= (OS_CFG_PRIO_MAX - 1u)) {
       *p_err = OS_ERR_TMR_PRIO_INVALID;
        return;
    }

    OSTaskCreate((OS_TCB     *)&OSTmrTaskTCB,
                 (CPU_CHAR   *)((void *)"uC/OS-III Timer Task"),
                 (OS_TASK_PTR )OS_TmrTask,
                 (void       *)0,
                 (OS_PRIO     )OSCfg_TmrTaskPrio,
                 (CPU_STK    *)OSCfg_TmrTaskStkBasePtr,
                 (CPU_STK_SIZE)OSCfg_TmrTaskStkLimit,
                 (CPU_STK_SIZE)OSCfg_TmrTaskStkSize,
                 (OS_MSG_QTY  )0,
                 (OS_TICK     )0,
                 (void       *)0,
                 (OS_OPT      )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR | OS_OPT_TASK_NO_TLS),
                 (OS_ERR     *)p_err);
}
示例#28
0
/*
*********************************************************************************************************
*                                          AppCreateIPCS
*
* Description : This function creates all IPCS objects
* Arguments   : None
*********************************************************************************************************
*/
void AppCreateIPCS()
{
	INT8U perr;

    // Mutex
   	App_MutexCmdToTaskMvt = OSMutexCreate(APP_MUTEX_MVT_PRIO, &perr);
	App_MutexCmdToTaskAsser = OSMutexCreate(APP_MUTEX_ASSER_PRIO, &perr);
	if((NULL == App_MutexCmdToTaskMvt) || (NULL == App_MutexCmdToTaskAsser))
	{
		AppDebugMsg("DEBUG (App.c) : Error -> Unable to create Semaphore or Mutex\n");
		AppDebugMsg("DEBUG (App.c) : Entering in sleeping mode...\n");	
		while(OS_TRUE)		// Infinite Loop
			OSTimeDlyHMSM(1, 0, 0, 0);		
	}

#if APP_USE_DEBUG > 0
   	App_MutexUART1 = OSMutexCreate(APP_MUTEX_UART1_PRIO, &perr);
	App_MutexUART2 = OSMutexCreate(APP_MUTEX_UART2_PRIO, &perr);
#else
   	App_MutexCmdToTaskMvt = NULL;
	App_MutexCmdToTaskAsser = NULL;

#endif

#if APP_QUEUE_SENSORS_SIZE > 0
	// Create an empty queue for asser process
	AppQueueSensors = OSQCreate(AppQSensorsStk, APP_QUEUE_SENSORS_SIZE);
	if(NULL == AppQueueSensors)		// Check if Queue is well created
	{
		AppDebugMsg("DEBUG (App.c) : Error -> Unable to create AsserQueue\n");
		AppDebugMsg("DEBUG (App.c) : Entering in sleeping mode...\n");	

        while(OS_TRUE)		// Infinite Loop
			OSTimeDlyHMSM(1, 0, 0, 0);		
	}
#endif

	// Flags
	AppFlags = OSFlagCreate(APP_PARAM_APPFLAG_INITAL_VALUE, &perr);
	if(NULL == AppFlags)
	{
		AppDebugMsg("DEBUG (App.c) : Error -> Unable to create Appliction Flag\n");
		AppDebugMsg("DEBUG (App.c) : Entering in sleeping mode...\n");	

        while(OS_TRUE)		// Infinite Loop
			OSTimeDlyHMSM(1, 0, 0, 0);		
	}

	// Strategy Flags
	AppStrategyFlags = OSFlagCreate(APP_PARAM_STRATEGYFLAG_INITAL_VALUE, &perr);
	if(NULL == AppStrategyFlags)
	{
		AppDebugMsg("DEBUG (App.c) : Error -> Unable to create Strategy Flag\n");
		AppDebugMsg("DEBUG (App.c) : Entering in sleeping mode...\n");	

        while(OS_TRUE)		// Infinite Loop
			OSTimeDlyHMSM(1, 0, 0, 0);		
	}

	return;
}
示例#29
0
文件: tarefas.c 项目: monkaco/BRTOS
void Terminal(void)
{
	char data;

   if (OSSemCreate(0,&sUART) != ALLOC_EVENT_OK)
   {
     // Oh Oh
     // Não deveria entrar aqui !!!
     BlockTask(th6);
   };

   if (OSMutexCreate(&mutexTx,6) != ALLOC_EVENT_OK)
   {
     // Oh Oh
     // Não deveria entrar aqui !!!
     BlockTask(th6);
   };

   if (OSQueueCreate(64, &qUART) != ALLOC_EVENT_OK)
   {
     // Oh Oh
     // Não deveria entrar aqui !!!
	 BlockTask(th6);
   };

	//
	// Enable the peripherals used by this example.
	// The UART itself needs to be enabled, as well as the GPIO port
	// containing the pins that will be used.
	//
	SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);

	//
	// Configure the GPIO pin muxing for the UART function.
	// This is only necessary if your part supports GPIO pin function muxing.
	// Study the data sheet to see which functions are allocated per pin.
	// TODO: change this to select the port/pin you are using
	//
	GPIOPinConfigure(GPIO_PA0_U0RX);
	GPIOPinConfigure(GPIO_PA1_U0TX);

	//
	// Since GPIO A0 and A1 are used for the UART function, they must be
	// configured for use as a peripheral function (instead of GPIO).
	// TODO: change this to match the port/pin you are using
	//
	GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

	//
	// Configure the UART for 115,200, 8-N-1 operation.
	// This function uses SysCtlClockGet() to get the system clock
	// frequency.  This could be also be a variable or hard coded value
	// instead of a function call.
	//
	UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
						(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
						 UART_CONFIG_PAR_NONE));

	UARTFIFODisable(UART0_BASE);

	//
	// Enable the UART interrupt.
	//
	ROM_IntEnable(INT_UART0);
	ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);

    //
    // Put a character to show start of example.  This will display on the
    // terminal.
    //
    UARTPutString(UART0_BASE, "Iniciou!\n\r\n\r");

    while(1)
    {
    	if(!OSQueuePend(qUART, (INT8U*)&data, 0))
    	{
    		if (data != 13)
    		{
    			UARTPutChar(UART0_BASE, data);
    		}else
    		{
    			UARTPutString(UART0_BASE, "\n\r");
    		}
    	}
    }
}
示例#30
0
void uart_init(INT8U uart, INT16U baudrate, INT16U buffersize, INT8U mutex, INT8U priority)
{
	
	/* check if UART 1 is already init */
	if(uart == 1 && Serial1 != NULL)
	{
		if(Serial1->OSEventAllocated == TRUE)
		{
			return;
		}
	}
	
	/* check if UART 2 is already init */
	if(uart == 2 && Serial2 != NULL)
	{
		if(Serial2->OSEventAllocated == TRUE)
		{
			return;
		}
	}
			
		// Configure UART 1
#if (ENABLE_UART1 == TRUE)
		if (uart == 1)
		{
			
			switch (CONF_UART1_PINS)
			{
				case UART1_PTA1_PTA2:
					SOPT3 = SOPT3 & 0xBF;
					break;
				case UART1_PTD6_PTD7:
					SOPT3 = SOPT3 | 0x40;
					break;
				default:
					break;
			}
			
			SCGC1 |= SCGC1_SCI1_MASK; /* Enables sci1 clock */
			
			/* set baudrate and parity type */
			uart1_set(baudrate,NONE);

			/* Cria um mutex com contador = 1, e prioridade máxima a acessar o recurso = priority */
		
			if (mutex == TRUE)
			{
				if (OSMutexCreate(&SerialResource1, priority) != ALLOC_EVENT_OK)
				{
					while (1){};
				}
			}

			if (OSSemCreate(0, &SerialTX1) != ALLOC_EVENT_OK)
			{
				while (1){};
			}

			if (OSQueueCreate(buffersize,&Serial1) != ALLOC_EVENT_OK)
			{
				while (1){};
			}
		}		
#endif

		// Configure UART 2
#if (ENABLE_UART2 == TRUE)
		if (uart == 2)
		{
			switch (CONF_UART2_PINS)
			{			
				case UART2_PTE5_PTE6:
					SOPT3 = SOPT3 & 0x7F;
					break;
				case UART2_PTF1_PTF2:
					SOPT3 = SOPT3 | 0x80;
					break;
				default:
					break;
			}
			
			SCGC1 |= SCGC1_SCI2_MASK; /* Enables sci2 clock */
			
			/* set baudrate and parity type */
			uart2_set(baudrate,NONE);

			/* Cria um mutex com contador = 1, e prioridade máxima a acessar o recurso = priority */
			if (mutex == TRUE)
			{
				if (OSMutexCreate(&SerialResource2, priority) != ALLOC_EVENT_OK)
				{
					while (1){};
				}
			}

			if (OSSemCreate(0, &SerialTX2) != ALLOC_EVENT_OK)
			{
				while (1){};
			}

			if (OSQueueCreate(buffersize,&Serial2) != ALLOC_EVENT_OK)
			{
				while (1){};
			}
		}
#endif

}