Esempio n. 1
0
int UART_Initialize()
{
	usart1_mutex_id = osMutexCreate(osMutex(usart1_mutex));
	usart2_mutex_id = osMutexCreate(osMutex(usart2_mutex));
	usart6_mutex_id = osMutexCreate(osMutex(usart6_mutex));

	if ((usart1_mutex_id == NULL) || (usart2_mutex_id == NULL) ||
			(usart6_mutex_id == NULL)) {
		ERROR_MiscRTOS("Failed to create a uart mutex");
	}

	/* UART2 configured as follow:
	  - Word Length = 8 Bits
	  - Stop Bit = One Stop bit
	  - Parity = Disabled
	  - BaudRate = 38400 baud
	  - Hardware flow control disabled (RTS and CTS signals) */
	handles[INDEX_USART2].Instance          = USART2;

	handles[INDEX_USART2].Init.BaudRate     = 38400;
	handles[INDEX_USART2].Init.WordLength   = UART_WORDLENGTH_8B;
	handles[INDEX_USART2].Init.StopBits     = UART_STOPBITS_1;
	handles[INDEX_USART2].Init.Parity       = UART_PARITY_NONE;
	handles[INDEX_USART2].Init.HwFlowCtl    = UART_HWCONTROL_NONE;
	handles[INDEX_USART2].Init.Mode         = UART_MODE_TX_RX;
	handles[INDEX_USART2].Init.OverSampling = UART_OVERSAMPLING_16;

	if(HAL_UART_Init(&handles[INDEX_USART2]) != HAL_OK) {
		return -1;
	}
	
	initialized[INDEX_USART2] = 1;
	
	return 0;
}
Esempio n. 2
0
/* This functions creates mutex for the file system. Since Fatfs doesn't supports 
 * extended partition feature, only 4 logical partitions can be created.
 */
void FATFS003_Init()
{
#if _FS_REENTRANT
 /* Drive0 Mutex 1 */
  FATFS003_MutexInfo[0].MutexId = osMutexCreate (osMutex(Drive0Mutex1));
  if (/* !N_DBG*/(NULL ==  FATFS003_MutexInfo[0].MutexId ))
  {
    ERROR(GID_FATFS003, FATFS003_MUTEX_CREATE_FAILED, 0, 0);
  }
  
  FATFS003_MutexInfo[1].MutexId = osMutexCreate (osMutex(Drive1Mutex2));
  if (/* !N_DBG*/(NULL ==  FATFS003_MutexInfo[1].MutexId ))
  {
    ERROR(GID_FATFS003, FATFS003_MUTEX_CREATE_FAILED, 0, 0);
  }
  
  FATFS003_MutexInfo[2].MutexId = osMutexCreate (osMutex(Drive2Mutex3));
  if (/* !N_DBG*/(NULL == FATFS003_MutexInfo[2].MutexId ))
  {
    ERROR(GID_FATFS003, FATFS003_MUTEX_CREATE_FAILED, 0, 0);
  }
  FATFS003_MutexInfo[3].MutexId = osMutexCreate (osMutex(Drive3Mutex4));
  if (/* !N_DBG*/(NULL ==  FATFS003_MutexInfo[3].MutexId ))
  {
    ERROR(GID_FATFS003, FATFS003_MUTEX_CREATE_FAILED, 0, 0);
  }
  
  FATFS003_MutexProtectId = osMutexCreate (osMutex(MutexToProtect));
  if (/* !N_DBG*/(NULL ==  FATFS003_MutexProtectId ))
  {
    ERROR(GID_FATFS003, FATFS003_MUTEX_CREATE_FAILED, 0, 0);
  }
#endif
}
Esempio n. 3
0
void tskEthernetManager(void const * argument)
{
	uint8_t preLinkStatus;
	uint8_t curLinkStatus;
	int8_t ret;
	sockMutexId = osMutexCreate(osMutex(sockMutex));
	spiMutexId = osMutexCreate(osMutex(spiMutex));
	NetMemPoolId = osPoolCreate(osPool(NetMemPool));

#if NETINFO_NTP_USE
	
	osThreadDef(ntptask, tskNTP, osPriorityBelowNormal, 0, 512);
	tskNTPId = osThreadCreate(osThread(ntptask), NULL);
#endif //NETINFO_NTP_USE

	wizSystemInit();
#if WIZSYSTEM_DEBUG
	printf("TASK: Ethernet manager start.\r\n");
#endif
	while(1)
	{
		osDelay(1000);// Every sec
		curLinkStatus = isLinked();
		if(preLinkStatus != curLinkStatus)
		{
			preLinkStatus = curLinkStatus;
			if(curLinkStatus)
			{
				leaseTime = 0;
			}
			else
			{
#if WIZSYSTEM_DEBUG
				printf("Ethernet Unliked. W5500 Reinitialize.\r\n");
				wizSystemInit(); //W5500 initialize
#endif
			}
		}
		if(NetInfo.dhcp == NETINFO_DHCP && DHCPLeasedTime+leaseTime < time(NULL))
		{
			ret = DHCPTimeOut(NETINFO_DHCP_TIMEOUT);
			if(ret == DHCP_IP_LEASED)
			{
				DHCPLeasedTime = time(NULL);
				return;
			}
			else
			{
				leaseTime = 0;
			}
		}
	}
}
Esempio n. 4
0
//-----------------------------------------------------------
void rtc_init()
{
  HAL_RTCEx_DeactivateWakeUpTimer(&hrtc);
	HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR2, 0xaaaa);
	osMutexDef(rtc_mutex); 
	rtc_mutex = osMutexCreate(osMutex(rtc_mutex));
}
void tasks_input_init()
{
  /* Mutexes */
  osMutexDef(mutex_menu);
  mutex_menuHandle = osMutexCreate(osMutex(mutex_menu));

  /* Semaphores */
  /* sem_input_touch_pen */
  osSemaphoreDef(sem_input_touch_pen);
  sem_input_touch_penHandle = osSemaphoreCreate(osSemaphore(sem_input_touch_pen), 1);

  /* sem_input_button_short_press */
  osSemaphoreDef(sem_input_button_short_press);
  sem_input_button_short_pressHandle = osSemaphoreCreate(osSemaphore(sem_input_button_short_press), 1);

  /* sem_input_button_long_press */
  osSemaphoreDef(sem_input_button_long_press);
  sem_input_button_long_pressHandle = osSemaphoreCreate(osSemaphore(sem_input_button_long_press), 1);

  /* Queues */
  /* queue_input_click */
  osMailQDef(queue_input_click, 16, click_t);
  queue_input_clickHandle = osMailCreate(osMailQ(queue_input_click), NULL);

  /* queue_input_menu */
  osMailQDef(queue_input_menu, 4, menu_t *);
  queue_input_menuHandle = osMailCreate(osMailQ(queue_input_menu), NULL);
}
Esempio n. 6
0
/**
\brief Test case: TC_MutexNestedAcquire
\details
- Create a mutex object
- Obtain a mutex object
- Create a high priority thread that waits for the same mutex
- Recursively acquire and release a mutex object
- Release a mutex
- Verify that every subsequent call released the mutex
- Delete a mutex object
- Mutex object must be released after each acquisition
*/
void TC_MutexNestedAcquire (void) {
  osStatus stat;
  
  /* - Create a mutex object */
  G_MutexId = osMutexCreate (osMutex (Mutex_Nest));
  ASSERT_TRUE (G_MutexId != NULL);

  if (G_MutexId  != NULL) {
    /* - Obtain a mutex object */
    stat = osMutexWait (G_MutexId, 0);
    ASSERT_TRUE (stat == osOK);
    
    if (stat == osOK) {
      /* - Create a high priority thread that will wait for the same mutex */
      G_Mutex_ThreadId = osThreadCreate (osThread (Th_MutexWait), NULL);
      ASSERT_TRUE (G_Mutex_ThreadId != NULL);
    
      /* - Recursively acquire and release a mutex object */
      RecursiveMutexAcquire (5, 5);

      /* - Release a mutex */
      stat = osMutexRelease (G_MutexId);
      ASSERT_TRUE (stat == osOK);

      /* - Verify that every subsequent call released the mutex */
      ASSERT_TRUE (osMutexRelease (G_MutexId) == osErrorResource);
    }
    /* - Delete a mutex object */
    ASSERT_TRUE (osMutexDelete (G_MutexId) == osOK);
  }
}
Esempio n. 7
0
void	vMBus_Mutex_Init( void )
{

	mutexBus_MBM = osMutexCreate ( osMutex ( mutex_MBus ));

	assert( NULL != mutexBus_MBM );
}
Esempio n. 8
0
EventLogger_Status_TypeDef EventLogger_Init(EventLogger_Handle_TypeDef *plog, EventLogger_Interface_TypeDef *ploginterface){

	if(Attached_Once == 0){
		if(plog->LogFile == NULL) plog->LogFile = LOGFILE_DEFAULT;
		plog->Interface = ploginterface;

		plog->LogStatus = plog->Interface->Init(plog);
#if (LOG_USE_OS == 1)
		osMutexDef(Log_Mutex);
		Log_Mutex = osMutexCreate(osMutex(Log_Mutex));
#if (LOG_USE_BUFFERING == 1)
		for(int i = 0; i< LOG_MAX_BUFF; i++) LogIndex_List[i] = 0;
		osMessageQDef(Log_Queue, LOG_MAX_BUFF, uint16_t);
		plog->os_event = osMessageCreate (osMessageQ(Log_Queue), NULL);
		osThreadDef(LogCollector, LogCollector_Process_OS, osPriorityHigh, 0, (8 * configMINIMAL_STACK_SIZE));
		plog->thread = osThreadCreate (osThread(LogCollector), plog);
		plog->pLogData = 0;
#endif	//END BUFFRING
#endif	//END OS
#if (LOG_USE_BUFFERING == 0)
		plog->pLogData = &LogMsg;
#endif

		Attached_Once = 1;
	}
	else{
		plog->Interface = ploginterface;
		Attached_Once = 1;
	}
	return plog->LogStatus;
}
Esempio n. 9
0
/*----------------------------------------------------------------------------
  Main Thread 'main'
 *---------------------------------------------------------------------------*/
int main (void) {                         /* program execution starts here   */

  GLCD_Init();                            /* initialize GLCD                 */
  SER_Init ();                            /* initialize serial interface     */
  LED_Init ();                            /* initialize LEDs                 */
  KBD_Init ();                            /* initialize Push Button          */

  mut_GLCD = osMutexCreate(osMutex(mut_GLCD));
                                          /* create and start clock timer    */
  clock1s = osTimerCreate(osTimer(clock1s), osTimerPeriodic, NULL);                                          
  if (clock1s) osTimerStart(clock1s, 1000);                                          
                                          /* start thread lcd                */
  tid_lcd = osThreadCreate(osThread(lcd), NULL);

  osDelay(500);
                                          /* start command thread            */
  tid_command = osThreadCreate(osThread(command), NULL);
                                          /* start lights thread             */
  tid_lights  = osThreadCreate(osThread(lights), NULL);
                                          /* start keyread thread            */
  tid_keyread = osThreadCreate(osThread(keyread), NULL);

  osDelay(osWaitForever);
  while(1);
}
Esempio n. 10
0
/*---------------------------------------------------------------------------
     TITLE   : thread_main
     WORK    : 
     ARG     : void
     RET     : void
---------------------------------------------------------------------------*/
void thread_main(void)
{


	Mutex_Loop = osMutexCreate( osMutex(MUTEX1) );

	if( Mutex_Loop == NULL ) DEBUG_PRINT("Mutex Fail\r\n");


    //-- Thread 1 definition
    //
    osThreadDef(TASK1, thread_mw  , osPriorityNormal, 0, configMINIMAL_STACK_SIZE);
    osThreadDef(TASK2, thread_menu, osPriorityNormal, 0, configMINIMAL_STACK_SIZE);
    osThreadDef(TASK3, thread_lcd,  osPriorityNormal, 0, configMINIMAL_STACK_SIZE);



    //-- Start thread
    //
    Thread_Handle_mw   = osThreadCreate(osThread(TASK1), NULL);
    Thread_Handle_menu = osThreadCreate(osThread(TASK2), NULL);
    Thread_Handle_lcd  = osThreadCreate(osThread(TASK3), NULL);



    //-- Start scheduler
    //
    osKernelStart(NULL, NULL);


    while(1);
}
Esempio n. 11
0
/**
\brief Test case: TC_MutexOwnership
\details
- Create a mutex object
- Create a child thread and wait until acquires mutex
- Create a child thread that trys to release a mutex
- Only thread that obtains a mutex can release it.
*/
void TC_MutexOwnership (void) {
  osThreadId ctrl_id, id[2];

  /* Ensure that priority of the control thread is set to normal */
  ctrl_id = osThreadGetId();
  ASSERT_TRUE (osThreadSetPriority (ctrl_id, osPriorityNormal) == osOK);
  
  /* - Create a mutex object */
  G_MutexId = osMutexCreate (osMutex (Mutex_Ownership));
  ASSERT_TRUE (G_MutexId != NULL);
  
  if (G_MutexId != NULL) {
    /* - Create a child thread and wait until acquires mutex */
    id[0] = osThreadCreate (osThread (Th_MutexAcqLow), NULL);
    ASSERT_TRUE (id[0] != NULL);
    
    if (id[0] != NULL) {
      osDelay(10);
      /* - Create a child thread that trys to release a mutex */
      id[1] = osThreadCreate (osThread (Th_MutexRelHigh), NULL);
      ASSERT_TRUE (id[1] != NULL);
      
      /* Terminate both threads */
      if (id[1] != NULL) {
        ASSERT_TRUE (osThreadTerminate (id[1]) == osOK);
      }
      ASSERT_TRUE (osThreadTerminate (id[0]) == osOK);
    }
  }
  /* - Delete a mutex object */
  ASSERT_TRUE (osMutexDelete (G_MutexId) == osOK);
}
Esempio n. 12
0
/**
\brief Test case: TC_MutexTimeout
\details
- Create and initialize a mutex object
- Create a thread that acquires a mutex but never release it
- Wait for mutex release until timeout
*/
void TC_MutexTimeout (void) {
  osThreadId ctrl_id, lock_id;
  osEvent    evt;

  /* Get control thread id */
  ctrl_id = osThreadGetId ();
  ASSERT_TRUE (ctrl_id != NULL);
  
  if (ctrl_id != NULL) {
    /* - Create and initialize a mutex object */
    G_MutexId = osMutexCreate (osMutex (MutexTout));
    ASSERT_TRUE (G_MutexId != NULL);
    
    if (G_MutexId != NULL) {
      /* - Create a thread that acquires a mutex but never release it */
      lock_id = osThreadCreate (osThread (Th_MutexLock), &ctrl_id);
      ASSERT_TRUE (lock_id != NULL);
      
      if (lock_id != NULL) {
        /* - Wait for mutex release until timeout */
        ASSERT_TRUE (osMutexWait (G_MutexId, 10) == osErrorTimeoutResource);
        /* - Release a mutex */
        osSignalSet (lock_id, 0x01);
        evt = osSignalWait (0x01, 100);
        ASSERT_TRUE (evt.status == osEventSignal);
        /* - Terminate locking thread */
        ASSERT_TRUE (osThreadTerminate (lock_id)  == osOK);
      }
      /* Delete mutex object */
      ASSERT_TRUE (osMutexDelete (G_MutexId)  == osOK);
    }
  }
}
Esempio n. 13
0
/*----------------------------------------------------------------------------
 *      Create the thread within RTOS context
 *---------------------------------------------------------------------------*/
int start_Thread_ACCELEROMETER (void) 
{
  tid_Thread_ACCELEROMETER = osThreadCreate(osThread(Thread_ACCELEROMETER), NULL); // Start ACCELEROMETER Thread
  if (!tid_Thread_ACCELEROMETER) return(-1);

  accel_mutex = osMutexCreate(osMutex(accel_mutex));
	
  return(0);
}
Esempio n. 14
0
/*----------------------------------------------------------------------------
 *      Create the thread within RTOS context
 *---------------------------------------------------------------------------*/
int start_Thread_SEGMENT (void)
{
  tid_Thread_SEGMENT = osThreadCreate(osThread(Thread_SEGMENT), NULL); // Start SEGMENT Thread
  if (!tid_Thread_SEGMENT) return(-1);

  segment_mutex = osMutexCreate(osMutex(segment_mutex));
	
  return(0);
}
Esempio n. 15
0
Mutex::Mutex() {
#ifdef CMSIS_OS_RTX
    memset(_mutex_data, 0, sizeof(_mutex_data));
    _osMutexDef.mutex = _mutex_data;
#endif
    _osMutexId = osMutexCreate(&_osMutexDef);
    if (_osMutexId == NULL) {
        //error("Error initializing the mutex object\n");
    }
}
/**  
  * @brief  Function that initializes receiver. 
  * @param  *receiver: pointer to Receiver structure.
  * @retval None  
  */
void init_receiver(struct Receiver *receiver) {
	receiver->state = 0;
	receiver->buffer_space = 0;
	
	CC2500_Init();
	CC2500_config_transmitter();
	goToTX(&(receiver->state), &(receiver->buffer_space));
	
	osMutexDef(receiverMutex);
	receiver->mutexID=osMutexCreate(osMutex(receiverMutex));
}
Esempio n. 17
0
/** Create a new mutex
 * @param mutex pointer to the mutex to create
 * @return a new mutex */
err_t sys_mutex_new(sys_mutex_t *mutex) {
#ifdef CMSIS_OS_RTX
    memset(mutex->data, 0, sizeof(int32_t)*3);
    mutex->def.mutex = mutex->data;
#endif
    mutex->id = osMutexCreate(&mutex->def);
    if (mutex->id == NULL)
        return ERR_MEM;
    
    return ERR_OK;
}
Esempio n. 18
0
/*-----------------------------------------------------------------------------
 *      Default IRQ Handler
 *----------------------------------------------------------------------------*/
void Mutex_IRQHandler (void) {
  uint32_t res = 0;
  
  switch (Isr.Ex_Num) {
    case 0: ISR_MutexId = osMutexCreate  (osMutex (MutexIsr));  break;
    case 1: ISR_OsStat  = osMutexWait    (ISR_MutexId, 0);      break;
    case 2: ISR_OsStat  = osMutexRelease (ISR_MutexId);         break;
    case 3: ISR_OsStat  = osMutexDelete  (ISR_MutexId);         break;
  }
  
  Isr.Ex_Res  = res;
}
Esempio n. 19
0
 int InitMutex(wolfSSL_Mutex* m)
 {
     int i ;
     for (i=0; i<CMSIS_NMUTEX; i++) {
         if(CMSIS_mutexID[i] == 0) {
             CMSIS_mutexID[i] = osMutexCreate(CMSIS_mutex[i]) ;
             (*m) = CMSIS_mutexID[i] ;
         return 0 ;
         }
     }
     return -1 ;
 }
Esempio n. 20
0
int Init_Mutex (void) {

  mid_Thread_Mutex = osMutexCreate  (osMutex (SampleMutex));
  if (!tid_Thread_Mutex)  {
    ; // Mutex object not created, handle failure
  }
  
  tid_Thread_Mutex    = osThreadCreate (osThread(Thread_Mutex),   NULL);
  if(!tid_Thread_Mutex) return(-1);
  
  return(0);
}
Esempio n. 21
0
/**  ADC Configuration
   * @brief  Configures ADC1 Channel 16 so that temperature values can be read
   */
void ADC_config(void) {  // TODO: Make this configuration proper so that it actually works

	ADC_ChannelConfTypeDef ADC1_ch16;
	
	
	// Initialize values for ADC1 handle type def
	ADC1_Handle.Instance = ADC1;
	ADC1_Handle.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
	ADC1_Handle.Init.Resolution = ADC_RESOLUTION_12B;    									 
	ADC1_Handle.Init.DataAlign = ADC_DATAALIGN_RIGHT;         						
	ADC1_Handle.Init.ScanConvMode = DISABLE;           
	ADC1_Handle.Init.EOCSelection = DISABLE;         			
	ADC1_Handle.Init.ContinuousConvMode = ENABLE;      //
	ADC1_Handle.Init.DMAContinuousRequests = DISABLE;  
	ADC1_Handle.Init.NbrOfConversion = 1;       													
	ADC1_Handle.Init.DiscontinuousConvMode = DISABLE;  
	ADC1_Handle.Init.NbrOfDiscConversion = 0;    
	ADC1_Handle.Init.ExternalTrigConv = ADC_EXTERNALTRIGCONV_T1_CC1;       //
	ADC1_Handle.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;  //
	
	
	// Initialize values for temperature sensor (Temperature analog channel is Ch16 of ADC1)
	ADC1_ch16.Channel = ADC_CHANNEL_16;
	ADC1_ch16.Rank = 1;
	ADC1_ch16.SamplingTime = ADC_SAMPLETIME_480CYCLES;
	ADC1_ch16.Offset = 0;
	
	
	// Enable ADC clock
	__ADC1_CLK_ENABLE();
	
	// Initialize clock with error handling

	if(HAL_ADC_Init(&ADC1_Handle)!=HAL_OK){
		//Error_Handler(ADC_INIT_FAIL);
		printf("adc init fail\n");
	}
	// Configure temperature sensor peripheral 
	HAL_ADC_ConfigChannel(&ADC1_Handle, &ADC1_ch16);
	
	HAL_ADC_Start(&ADC1_Handle);
	
	// Allot values to the kalman filtration struct for the temperature sensor
	kalman_temperature.q = 0.3;
	kalman_temperature.r = 1.2;
	kalman_temperature.x = 1000.0;
	kalman_temperature.p = 0.0;
	kalman_temperature.k = 0.0;
	
	// Initialize temperature sensor mutex
	temperatureMutex = osMutexCreate(temperatureMutexPtr);
	
}
/**----------------------------------------------------------------------------
 *      Thread  'Thread_angles': set Pitch and Roll display
 *---------------------------------------------------------------------------*/
	void Thread_angles (void const *argument) {
		
		pitch_mutex = osMutexCreate(osMutex(pitch_mutex));
		roll_mutex = osMutexCreate(osMutex(roll_mutex));
		
		while(1){
			float out[3], acc[3];
			
			osSignalWait(1, osWaitForever);
			
			LIS3DSH_ReadACC(out);

			/* Calculations based on Eq 8 and 9 in Doc 15*/
			/* Y direction is towards mini usb connector, Z is downwards*/
			/* Use RHR to digure out X*/

			acc[0] = out[0] - XOFFSET;
			acc[1] = out[1] - YOFFSET;
			acc[2] = out[2] - ZOFFSET;
			
			filtered_acc[0] = kalmanfilter_c(acc[0],&xacc_state);
			filteredX = filtered_acc[0];
			filtered_acc[1] = kalmanfilter_c(acc[1],&yacc_state);
			filteredY = filtered_acc[1];
			filtered_acc[2] = kalmanfilter_c(acc[2],&zacc_state);
			filteredZ = filtered_acc[2];

			osSignalSet(tid_Thread_doubleTap, 1);
			
			osMutexWait(pitch_mutex, osWaitForever);
			pitch = 90 + (180/M_PI)*atan2(filtered_acc[1], sqrt(pow(filtered_acc[0], 2) + pow(filtered_acc[2], 2))); //Pitch in degrees
			osMutexRelease(pitch_mutex);
	
			osMutexWait(roll_mutex, osWaitForever);
			roll  = 90 + (180/M_PI)*atan2(filtered_acc[0], sqrt(pow(filtered_acc[1], 2) + pow(filtered_acc[2], 2))); //Roll in degrees
			osMutexRelease(roll_mutex);
			
			osSignalClear(tid_Thread_angles, 1);
		}
	}
Esempio n. 23
0
void InitializeAppShooter()
{
  TimerId = osTimerCreate (osTimer(PeriodicTimer), osTimerPeriodic, NULL);
  if (TimerId) {
    osTimerStart (TimerId, 8);
  }
	
  /* Prepare display */
	GLCD_SetBackgroundColor (GLCD_COLOR_BLACK);
  GLCD_SetForegroundColor (GLCD_COLOR_WHITE);
  GLCD_ClearScreen();
	
	// Variables initialization
	timerTick_01 = 0;										// Timer counter for Main
	timerTick_02 = 0;										// Timer counter for drawing the Objects
	plane_x = 0;												// Plane X position
	plane_y = 110;											// Plane Y position
	actualBallNumber = 0;
	newBall = false;										// Tells to the routine S_MoveBall to create a new ball
	objectNumb = 0;
	objectColor = 1;
	stopThreads = false;
	ballTimer = 0;
	stopShooter = false;
	playerScore = 0;
	machineScore = 0;
	
	S_IncPlayerScore();
	S_IncMachineScore();
	
	if(S_firstTime){
		glcd_semaph_id = osSemaphoreCreate(osSemaphore(glcd_semaph), 1); // Semaphore binaire, only one thread at the same time
		planeVar_mutex_id = osMutexCreate(osMutex(planeVar_mutex));
		objectVar_mutex_id = osMutexCreate(osMutex(objectVar_mutex));
		S_firstTime = false;
	}
	
	idThreadPlane = osThreadCreate (osThread (S_Thread_MovePlane), NULL);   // create the thread

}
/* This functions creates mutex for the file system. */
void FATFS002_Init()
{
#if _FS_REENTRANT
 /* Drive0 Mutex 1 */
  FATFS002_MutexInfo[0].MutexId = osMutexCreate (osMutex(Drive0Mutex1));
  if (/* !N_DBG*/(NULL ==  FATFS002_MutexInfo[0].MutexId ))
  {
    ERROR(GID_FATFS002, FATFS002_MUTEX_CREATE_FAILED, 0, 0);
  }
  
  FATFS002_MutexInfo[1].MutexId = osMutexCreate (osMutex(Drive0Mutex2));
  if (/* !N_DBG*/(NULL ==  FATFS002_MutexInfo[1].MutexId ))
  {
    ERROR(GID_FATFS002, FATFS002_MUTEX_CREATE_FAILED, 0, 0);
  }
  
  FATFS002_MutexInfo[2].MutexId = osMutexCreate (osMutex(Drive0Mutex3));
  if (/* !N_DBG*/(NULL == FATFS002_MutexInfo[2].MutexId ))
  {
    ERROR(GID_FATFS002, FATFS002_MUTEX_CREATE_FAILED, 0, 0);
  }
  FATFS002_MutexInfo[3].MutexId = osMutexCreate (osMutex(Drive0Mutex4));
  if (/* !N_DBG*/(NULL ==  FATFS002_MutexInfo[3].MutexId ))
  {
    ERROR(GID_FATFS002, FATFS002_MUTEX_CREATE_FAILED, 0, 0);
  }
 /* Drive1 Mutex 1 */
  FATFS002_MutexInfo[4].MutexId  = osMutexCreate (osMutex(Drive1Mutex1));
  if (/* !N_DBG*/(NULL ==  FATFS002_MutexInfo[4].MutexId ))
  {
    ERROR(GID_FATFS002, FATFS002_MUTEX_CREATE_FAILED, 0, 0);
  }

  FATFS002_MutexInfo[5].MutexId = osMutexCreate (osMutex(Drive1Mutex2));
  if (/* !N_DBG*/(NULL ==  FATFS002_MutexInfo[5].MutexId ))
  {
    ERROR(GID_FATFS002, FATFS002_MUTEX_CREATE_FAILED, 0, 0);
  }
  FATFS002_MutexInfo[6].MutexId  = osMutexCreate (osMutex(Drive1Mutex3));
  if (/* !N_DBG*/(NULL ==  FATFS002_MutexInfo[6].MutexId ))
  {
    ERROR(GID_FATFS002, FATFS002_MUTEX_CREATE_FAILED, 0, 0);
  }
  FATFS002_MutexInfo[7].MutexId = osMutexCreate (osMutex(Drive1Mutex4));
  if (/* !N_DBG*/(NULL ==  FATFS002_MutexInfo[7].MutexId))
  {
    ERROR(GID_FATFS002, FATFS002_MUTEX_CREATE_FAILED, 0, 0);
  }
#endif
}
static void page_allocator_mutex_aquire()
{
    if (g_page_allocator_mutex_id == NULL) {
        /* Create mutex if not already done. */
        g_page_allocator_mutex_id = osMutexCreate(&g_page_allocator_mutex);
        if (g_page_allocator_mutex_id == NULL) {
            /* Mutex failed to be created. */
            return;
        }
    }

    osMutexWait(g_page_allocator_mutex_id, osWaitForever);
}
Esempio n. 26
0
error_t udpInit(void)
{
   //Create a mutex to prevent simultaneous access to the callback table
   udpCallbackMutex = osMutexCreate(FALSE);
   //Any error to report?
   if(udpCallbackMutex == OS_INVALID_HANDLE)
      return ERROR_OUT_OF_RESOURCES;

   //Initialize callback table
   memset(udpCallbackTable, 0, sizeof(udpCallbackTable));
   //Successful initialization
   return NO_ERROR;
}
Esempio n. 27
0
int main() {
	GPIO_InitTypeDef GPIO_InitDef;
	
	SystemClock_Config();
	SystemCoreClockUpdate();
	
	HAL_Init();
	
	/* driver init */
	lsm303dlhc_init();
	l3gd20_init();
	
	osKernelInitialize();
	Init_Timers();
	
	
	handlerThread_id = osThreadCreate(osThread(handlerThread), NULL);
	gyroHandlerThread_id = osThreadCreate(osThread(gyroHandlerThread), NULL);
	visioThread_id = osThreadCreate(osThread(visioThread), NULL);
	
	accelBuffer_mutex_id = osMutexCreate(osMutex(accelBuffer_mutex));
	gyroBuffer_mutex_id = osMutexCreate(osMutex(gyroBuffer_mutex));
	
	// enable clock for GPIOE
	//__HAL_RCC_GPIOE_CLK_ENABLE();

	// init GPIO pin
	GPIO_InitDef.Pin = GPIO_PIN_9;
	GPIO_InitDef.Mode = GPIO_MODE_OUTPUT_PP;
	GPIO_InitDef.Speed = GPIO_SPEED_FREQ_LOW;
	
	HAL_GPIO_Init(GPIOE, &GPIO_InitDef);
	
	// set LD3
	HAL_GPIO_WritePin(GPIOE, GPIO_PIN_9, GPIO_PIN_SET);
	
	osKernelStart();
}
/* Init OS */
void GUI_X_InitOS(void)
{
  /* Create Mutex lock */
  osMutexDef(MUTEX);

  /* Create the Mutex used by the two threads */
  osMutex = osMutexCreate(osMutex(MUTEX));

  /* Create Semaphore lock */
  osSemaphoreDef(SEM);

  /* Create the Semaphore used by the two threads */
  osSemaphore= osSemaphoreCreate(osSemaphore(SEM), 1);
}
Esempio n. 29
0
error_t arpInit(NetInterface *interface)
{
   //Create a mutex to prevent simultaneous access to ARP cache
   interface->arpCacheMutex = osMutexCreate(FALSE);
   //Any error to report?
   if(interface->arpCacheMutex == OS_INVALID_HANDLE)
      return ERROR_OUT_OF_RESOURCES;

   //Initialize ARP cache
   memset(interface->arpCache, 0, sizeof(interface->arpCache));

   //Successful initialization
   return NO_ERROR;
}
Esempio n. 30
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  /* STM32F4xx HAL library initialization:
       - Configure the Flash prefetch, instruction and Data caches
       - Configure the Systick to generate an interrupt each 1 msec
       - Set NVIC Group Priority to 4
       - Global MSP (MCU Support Package) initialization
     */
  HAL_Init();  
  
  /* Configure the system clock to 180 MHz */
  SystemClock_Config();
  
  /* Initialize IO expander */
#if defined(USE_IOEXPANDER)  
  BSP_IO_Init();
#endif

  /* Configure LED1, LED2, LED3 and LED4 */
  BSP_LED_Init(LED1);
  BSP_LED_Init(LED2);
  BSP_LED_Init(LED3);
  BSP_LED_Init(LED4); 
  
  /* Creates the mutex */
  osMutexDef(osMutex);
  osMutex = osMutexCreate(osMutex(osMutex));
  
  if(osMutex != NULL)
  {
    /* Define and create the high priority thread */
    osThreadDef(MutHigh, MutexHighPriorityThread, osPriorityBelowNormal, 0, configMINIMAL_STACK_SIZE);
    osHighPriorityThreadHandle = osThreadCreate(osThread(MutHigh), NULL);
    
    /* Define and create the medium priority thread */
    osThreadDef(MutMedium, MutexMeduimPriorityThread, osPriorityLow, 0, configMINIMAL_STACK_SIZE);
    osMediumPriorityThreadHandle = osThreadCreate(osThread(MutMedium), NULL);
    
    /* Define and create the low priority thread */
    osThreadDef(MutLow, MutexLowPriorityThread, osPriorityIdle, 0, configMINIMAL_STACK_SIZE);
    osThreadCreate(osThread(MutLow), NULL);
  }
  
  /* Start scheduler */
  osKernelStart();
  
  /* We should never get here as control is now taken by the scheduler */
  for(;;);
}