/* 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 }
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; }
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; } } } }
/** \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); } }
/** \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); }
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; }
/*--------------------------------------------------------------------------- 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); }
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); }
/*---------------------------------------------------------------------------- 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); }
//----------------------------------------------------------- void rtc_init() { HAL_RTCEx_DeactivateWakeUpTimer(&hrtc); HAL_RTCEx_BKUPWrite(&hrtc, RTC_BKP_DR2, 0xaaaa); osMutexDef(rtc_mutex); rtc_mutex = osMutexCreate(osMutex(rtc_mutex)); }
/** \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); } } }
void vMBus_Mutex_Init( void ) { mutexBus_MBM = osMutexCreate ( osMutex ( mutex_MBus )); assert( NULL != mutexBus_MBM ); }
/*---------------------------------------------------------------------------- * 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); }
/*---------------------------------------------------------------------------- * 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); }
/** * @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)); }
/*----------------------------------------------------------------------------- * 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; }
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); }
/* 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 }
/**---------------------------------------------------------------------------- * 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); } }
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 }
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(); }
/** * @brief create a thread for temperature measurement * @param None * @retval The thread ID for temperature */ osThreadId temperature_Thread_Create(void) { //initialize ADC temperature_Init(); pwm_alarm_init(); //create semaphore tempeature_semaphore = osSemaphoreCreate(osSemaphore(tempeature_semaphore), 1); //initialize filter filter_init(&temperature_filter_struct, 20); temperature_filter_struct.mutexId = osMutexCreate(osMutex (temperatureFilterMutex)); //create temperature thread tempeature_thread_id = osThreadCreate(osThread(temperature_Thread), NULL); return tempeature_thread_id; }
/*! @brief Program entry point */ int main (void) { // ID for threads osThreadId tid_transmit; osThreadId tid_receive; osThreadId tid_accelerometer; // Start wireless uint8_t status; status = init_wireless(); printf("CC2500 Ready (%x) \n",status); osDelay(1000); //Create Update Mutex measureUpdate = osMutexCreate(osMutex(measure_update)); //Start either the Transmitter or Receiver if (IS_TRANSMITTER) { init_accelerometer(); transmit_locked = 0; enableKeyboard(); enableKeyboardINT(); //printf("Transmitter starting threads \n"); tid_transmit = osThreadCreate(osThread(transmit_thread), NULL); tid_accelerometer = osThreadCreate(osThread(accelerometer_thread), NULL); tid_keyboard = osThreadCreate(osThread(keyboard_thread), &measurements); } else { motorEnable(); init_accelerometer(); enableLEDS(); measurements.follow = 1; //Set Motors to follow received values //printf("Receiver starting threads \n"); timerid_motor = osTimerCreate(osTimer(MotorTimer),osTimerPeriodic,&exec); tid_accelerometer = osThreadCreate(osThread(accelerometer_thread), NULL); tid_motor = osThreadCreate(osThread(motor_thread), &measurements); tid_receive = osThreadCreate(osThread(receive_thread), NULL); } // The main thread does nothing while(1){ osDelay(osWaitForever); } }
/** \brief Test case: TC_MutexBasic \details - Create a mutex object - Try to release mutex that was not obtained before - Obtain a mutex object - Release a mutex object - Delete a mutex object */ void TC_MutexBasic (void) { osMutexId m_id; /* - Create a mutex object */ m_id = osMutexCreate (osMutex (MutexBas)); ASSERT_TRUE (m_id != NULL); if (m_id != NULL) { /* - Try to release mutex that was not obtained before */ ASSERT_TRUE (osMutexRelease (m_id) == osErrorResource); /* - Obtain a mutex object */ ASSERT_TRUE (osMutexWait (m_id, 0) == osOK); /* - Release a mutex object */ ASSERT_TRUE (osMutexRelease (m_id) == osOK); /* - Delete a mutex object */ ASSERT_TRUE (osMutexDelete (m_id) == osOK); } }
/*---------------------------------------------------------------------------- Main Thread 'main' *---------------------------------------------------------------------------*/ int main (void) { LED_Init (); /* Initialize the LEDs */ GLCD_Init(); /* Initialize the GLCD */ GLCD_Clear(White); /* Clear the GLCD */ mut_GLCD = osMutexCreate(osMutex(mut_GLCD)); tid_phaseA = osThreadCreate(osThread(phaseA), NULL); tid_phaseB = osThreadCreate(osThread(phaseB), NULL); tid_phaseC = osThreadCreate(osThread(phaseC), NULL); tid_phaseD = osThreadCreate(osThread(phaseD), NULL); tid_clock = osThreadCreate(osThread(clock), NULL); tid_lcd = osThreadCreate(osThread(lcd), NULL); osSignalSet(tid_phaseA, 0x0001); /* set signal to phaseA thread */ osDelay(osWaitForever); while(1); }
/** * @brief Function that initializes the transmitter. * @param *transmitter: Pointer to a Transmitter structure. * @param *tid_thread_transmitter: Pointer to the pushbutton thread control block. * @retval None */ void init_transmitter(struct Transmitter *transmitter, osThreadId **tid_thread_transmitter) { transmitter->state = 0; transmitter->buffer_space = 0; uint32_t i; for (i=0; i<sizeof(transmitter->data)/sizeof(transmitter->data[0]); i++) { transmitter->data[i] = 0; } CC2500_Init(); CC2500_config_transmitter(); goToTX(&(transmitter->state), &(transmitter->buffer_space)); osThreadDef(transmitterThread, osPriorityNormal, 1, 0); transmitter->threadID = osThreadCreate(osThread(transmitterThread), transmitter); osMutexDef(transmitterMutex); transmitter->mutexID=osMutexCreate(osMutex(transmitterMutex)); *tid_thread_transmitter = &(transmitter->threadID); }
/** \brief Test case: TC_MutexInterrupts \details - Call all mutex management functions from the ISR */ void TC_MutexInterrupts (void) { TST_IRQHandler = Mutex_IRQHandler; NVIC_EnableIRQ((IRQn_Type)SWI_HANDLER); Isr.Ex_Num = 0; /* Test: osMutexCreate */ NVIC_SetPendingIRQ((IRQn_Type)SWI_HANDLER); __DMB(); ASSERT_TRUE (ISR_MutexId == NULL); Isr.Ex_Num = 1; /* Test: osMutexWait */ /* Create valid mutex, to be used for ISR function calls */ ISR_MutexId = osMutexCreate (osMutex (MutexIsr)); ASSERT_TRUE (ISR_MutexId != NULL); if (ISR_MutexId != NULL) { NVIC_SetPendingIRQ((IRQn_Type)SWI_HANDLER); __DMB(); ASSERT_TRUE (ISR_OsStat == osErrorISR); Isr.Ex_Num = 2; /* Test: osMutexRelease */ NVIC_SetPendingIRQ((IRQn_Type)SWI_HANDLER); __DMB(); ASSERT_TRUE (ISR_OsStat == osErrorISR); Isr.Ex_Num = 3; /* Test: osMutexDelete */ NVIC_SetPendingIRQ((IRQn_Type)SWI_HANDLER); __DMB(); ASSERT_TRUE (ISR_OsStat == osErrorISR); /* Delete mutex */ ASSERT_TRUE (osMutexDelete (ISR_MutexId) == osOK); } NVIC_DisableIRQ((IRQn_Type)SWI_HANDLER); }
/*--------------------------------------------------------------------------- TITLE : main WORK : ARG : void RET : void ---------------------------------------------------------------------------*/ int main(void) { Main_Init(); //-- Thread 정의 // osThreadDef( THREAD_LED , Thread_LED , osPriorityNormal, 0, configMINIMAL_STACK_SIZE ); osThreadDef( THREAD_MAIN , Thread_Main , osPriorityNormal, 0, configMINIMAL_STACK_SIZE ); //-- Thread 생성 // Thread_Handle_Led = osThreadCreate(osThread(THREAD_LED) , NULL); Thread_Handle_Main = osThreadCreate(osThread(THREAD_MAIN), NULL); osMutexDef(osMutex_VCom); osMutex_VCom = osMutexCreate(osMutex(osMutex_VCom)); PowerON = 1; //-- 스케줄러 시작 // osKernelStart(); while(1) { } }
} else { return ; } } #elif defined(WOLFSSL_MDK_ARM)|| defined(WOLFSSL_CMSIS_RTOS) #if defined(WOLFSSL_CMSIS_RTOS) #include "cmsis_os.h" #define CMSIS_NMUTEX 10 osMutexDef(wolfSSL_mt0) ; osMutexDef(wolfSSL_mt1) ; osMutexDef(wolfSSL_mt2) ; osMutexDef(wolfSSL_mt3) ; osMutexDef(wolfSSL_mt4) ; osMutexDef(wolfSSL_mt5) ; osMutexDef(wolfSSL_mt6) ; osMutexDef(wolfSSL_mt7) ; osMutexDef(wolfSSL_mt8) ; osMutexDef(wolfSSL_mt9) ; static const osMutexDef_t *CMSIS_mutex[] = { osMutex(wolfSSL_mt0), osMutex(wolfSSL_mt1), osMutex(wolfSSL_mt2), osMutex(wolfSSL_mt3), osMutex(wolfSSL_mt4), osMutex(wolfSSL_mt5), osMutex(wolfSSL_mt6), osMutex(wolfSSL_mt7), osMutex(wolfSSL_mt8), osMutex(wolfSSL_mt9) } ; static osMutexId CMSIS_mutexID[CMSIS_NMUTEX] = {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 ; }
/********************************************************************* * @fn AlgorithmTask * This task is responsible for running the sensor algorithms * on the incoming sensor data (could be raw or filtered) and * processing output results * * @param none * * @return none * **********************************************************************/ ASF_TASK void AlgorithmTask (ASF_TASK_ARG) { MessageBuffer *rcvMsg = NULLP; OSP_STATUS_t OSP_Status; int alg_count; OSP_GetLibraryVersion(&version); D1_printf("OSP Version: %s\r\n", version->VersionString); /* Initialize the mutex */ mutex_id = osMutexCreate(osMutex(mutexCritSection)); OSP_Status = OSP_Initialize(&gSystemDesc); ASF_assert_msg(OSP_STATUS_OK == OSP_Status, "OSP_Initialize Failed"); OSP_SetCalibrationConfig( 0x1); // disable rotational cal. D0_printf("--Alg Task %i\r\n", __LINE__); // Register the input sensors OSP_Status = OSP_RegisterInputSensor(&_AccSensDesc, &_AccHandle); ASF_assert_msg(OSP_STATUS_OK == OSP_Status, "OSP_RegisterInputSensor (accel) Failed"); OSP_Status = OSP_RegisterInputSensor(&_MagSensDesc, &_MagHandle); ASF_assert_msg(OSP_STATUS_OK == OSP_Status, "OSP_RegisterInputSensor (mag) Failed"); OSP_Status = OSP_RegisterInputSensor(&_GyroSensDesc, &_GyroHandle); ASF_assert_msg(OSP_STATUS_OK == OSP_Status, "OSP_RegisterInputSensor (gyro) Failed"); #if 0 SENSOR_SUBSCRIBE(SENSOR_STEP_COUNTER); SENSOR_SUBSCRIBE(SENSOR_STEP_DETECTOR); SENSOR_SUBSCRIBE(SENSOR_SIGNIFICANT_MOTION); SENSOR_SUBSCRIBE(SENSOR_GYROSCOPE_UNCALIBRATED); SENSOR_SUBSCRIBE(SENSOR_MAGNETIC_FIELD_UNCALIBRATED); SENSOR_SUBSCRIBE(SENSOR_GYROSCOPE); SENSOR_SUBSCRIBE(SENSOR_ACCELEROMETER); SENSOR_SUBSCRIBE(SENSOR_MAGNETIC_FIELD); SENSOR_SUBSCRIBE(SENSOR_ORIENTATION); SENSOR_SUBSCRIBE(SENSOR_GRAVITY); SENSOR_SUBSCRIBE(SENSOR_LINEAR_ACCELERATION); SENSOR_SUBSCRIBE(SENSOR_ROTATION_VECTOR); SENSOR_SUBSCRIBE(SENSOR_GAME_ROTATION_VECTOR); SENSOR_SUBSCRIBE(SENSOR_GEOMAGNETIC_ROTATION_VECTOR); // Subscribing private sensor results PRIVATE_SENSOR_SUBSCRIBE(AP_PSENSOR_ACCELEROMETER_UNCALIBRATED); #endif D0_printf("%s: --Alg Task init done\r\n", __func__); while (1) { ASFReceiveMessage(ALGORITHM_TASK_ID, &rcvMsg); if (!(mycount % 64)) { LED_Toggle(LED_GREEN); } switch (rcvMsg->msgId) { case MSG_MAG_DATA: // SendBgTrigger(); case MSG_ACC_DATA: case MSG_GYRO_DATA: mycount++; HandleSensorData(rcvMsg); //keep doing foreground computation until its finished /* Bump clock speed while processing? HY-DBG */ alg_count = 0; do { OSP_Status = OSP_DoForegroundProcessing(); ASF_assert(OSP_Status != OSP_STATUS_UNSPECIFIED_ERROR); alg_count++; if (alg_count > 5) { D0_printf("%s:%i Taking too long\r\n", __func__, __LINE__); break; } } while(OSP_Status != OSP_STATUS_IDLE); /* DBG: * Run background here as the backgound taks doesn't seem to run enough */ while(OSP_DoBackgroundProcessing() != OSP_STATUS_IDLE); break; case MSG_PRESS_DATA: PressureDataResultCallback(&rcvMsg->msg.msgPressData); break; default: /* Unhandled messages */ D1_printf("Alg-FG:!!!UNHANDLED MESSAGE:%d!!!\r\n", rcvMsg->msgId); break; } ASFDeleteMessage( ALGORITHM_TASK_ID, &rcvMsg ); #ifdef DEBUG_TEST_SENSOR_SUBSCRIPTION // Testing subscribe and unsubscribe sensors DebugTestSensorSubscription(); #endif } }