/** * Initialize the UAVTalk library * \param[in] connection UAVTalkConnection to be used * \param[in] outputStream Function pointer that is called to send a data buffer * \return 0 Success * \return -1 Failure */ UAVTalkConnection UAVTalkInitialize(UAVTalkOutputStream outputStream) { // allocate object UAVTalkConnectionData *connection = pios_malloc(sizeof(UAVTalkConnectionData)); if (!connection) { return 0; } connection->canari = UAVTALK_CANARI; connection->iproc.rxPacketLength = 0; connection->iproc.state = UAVTALK_STATE_SYNC; connection->outStream = outputStream; connection->lock = xSemaphoreCreateRecursiveMutex(); connection->transLock = xSemaphoreCreateRecursiveMutex(); // allocate buffers connection->rxBuffer = pios_malloc(UAVTALK_MAX_PACKET_LENGTH); if (!connection->rxBuffer) { return 0; } connection->txBuffer = pios_malloc(UAVTALK_MAX_PACKET_LENGTH); if (!connection->txBuffer) { return 0; } vSemaphoreCreateBinary(connection->respSema); xSemaphoreTake(connection->respSema, 0); // reset to zero UAVTalkResetStats((UAVTalkConnection)connection); return (UAVTalkConnection)connection; }
///////////////////////////////////////////////////////////////////////////// // This hook is called after startup to initialize the application ///////////////////////////////////////////////////////////////////////////// void APP_Init(void) { // create semaphores xMIDIINSemaphore = xSemaphoreCreateRecursiveMutex(); xMIDIOUTSemaphore = xSemaphoreCreateRecursiveMutex(); // install SysEx callback MIOS32_MIDI_SysExCallback_Init(APP_SYSEX_Parser); // install MIDI Rx/Tx callback functions MIOS32_MIDI_DirectRxCallback_Init(&NOTIFY_MIDI_Rx); MIOS32_MIDI_DirectTxCallback_Init(&NOTIFY_MIDI_Tx); // install timeout callback function MIOS32_MIDI_TimeOutCallback_Init(&NOTIFY_MIDI_TimeOut); // limit the number of DIN/DOUT SRs which will be scanned for faster scan rate MIOS32_SRIO_ScanNumSet(2); // init keyboard functions KEYBOARD_Init(0); // read EEPROM content PRESETS_Init(0); // init MIDI port/router handling MIDI_PORT_Init(0); MIDI_ROUTER_Init(0); // init terminal TERMINAL_Init(0); // init MIDImon MIDIMON_Init(0); // start uIP task UIP_TASK_Init(0); // print welcome message on MIOS terminal MIOS32_MIDI_SendDebugMessage("\n"); MIOS32_MIDI_SendDebugMessage("=================\n"); MIOS32_MIDI_SendDebugMessage("%s\n", MIOS32_LCD_BOOT_MSG_LINE1); MIOS32_MIDI_SendDebugMessage("=================\n"); MIOS32_MIDI_SendDebugMessage("\n"); // speed up SPI transfer rate (was MIOS32_SPI_PRESCALER_128, initialized by MIOS32_SRIO_Init()) MIOS32_SPI_TransferModeInit(MIOS32_SRIO_SPI, MIOS32_SPI_MODE_CLK1_PHASE1, MIOS32_SPI_PRESCALER_128); // prescaler 64 results into a transfer rate of 0.64 uS per bit // when 2 SRs are transfered, we are able to scan the whole 16x8 matrix in 300 uS // standard SRIO scan has been disabled in programming_models/traditional/main.c via MIOS32_DONT_SERVICE_SRIO_SCAN in mios32_config.h // start the scan here - and retrigger it whenever it's finished APP_SRIO_ServicePrepare(); MIOS32_SRIO_ScanStart(APP_SRIO_ServiceFinish); // start tasks xTaskCreate(TASK_Period_1mS, (signed portCHAR *)"1mS", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD_1mS, NULL); }
///////////////////////////////////////////////////////////////////////////// // This hook is called after startup to initialize the application ///////////////////////////////////////////////////////////////////////////// void APP_Init(void) { int i; // create semaphores xMIDIINSemaphore = xSemaphoreCreateRecursiveMutex(); xMIDIOUTSemaphore = xSemaphoreCreateRecursiveMutex(); // clear SysEx buffers for(i=0; i<NUM_SYSEX_BUFFERS; ++i) sysex_buffer_len[i] = 0; // install SysEx callback MIOS32_MIDI_SysExCallback_Init(APP_SYSEX_Parser); // read EEPROM content PRESETS_Init(0); // init terminal TERMINAL_Init(0); // init MIDImon MIDIMON_Init(0); // start uIP task UIP_TASK_Init(0); // initialize status LED MIOS32_BOARD_LED_Init(0xffffffff); MIOS32_BOARD_LED_Set(1, 0); led_pwm_counter[0] = LED_PWM_PERIOD; led_trigger[0] = LED_PWM_PERIOD; // trigger LED on startup for complete PWM cycle // initialize additional LEDs connected to J5A for(i=1; i<NUM_LED_TRIGGERS; ++i) { led_pwm_counter[i] = LED_PWM_PERIOD; led_trigger[i] = LED_PWM_PERIOD; // trigger LED on startup for complete PWM cycle MIOS32_BOARD_J5_PinInit(i-1, MIOS32_BOARD_PIN_MODE_OUTPUT_PP); MIOS32_BOARD_J5_PinSet(i-1, 0); } // initialize J5B/J5C pins as inputs with pull-up enabled // these pins control diagnostic options of the MIDI monitor for(i=4; i<12; ++i) MIOS32_BOARD_J5_PinInit(i, MIOS32_BOARD_PIN_MODE_INPUT_PU); // install timer function which is called each 100 uS MIOS32_TIMER_Init(0, 100, APP_Periodic_100uS, MIOS32_IRQ_PRIO_MID); // print welcome message on MIOS terminal MIOS32_MIDI_SendDebugMessage("\n"); MIOS32_MIDI_SendDebugMessage("=====================\n"); MIOS32_MIDI_SendDebugMessage("%s\n", MIOS32_LCD_BOOT_MSG_LINE1); MIOS32_MIDI_SendDebugMessage("=====================\n"); MIOS32_MIDI_SendDebugMessage("\n"); }
dispatch_queue::dispatch_queue(std::string name, size_t thread_cnt, size_t thread_stack_size) : name_(name), threads_(thread_cnt) { // Create the Mutex mutex_ = xSemaphoreCreateRecursiveMutex(); assert(mutex_ != NULL && "Failed to create mutex!"); // Create the event flags notify_flags_ = xEventGroupCreate(); assert(notify_flags_ != NULL && "Failed to create event group!"); // Dispatch thread setup for(size_t i = 0; i < threads_.size(); i++) { // Define the name threads_[i].name = std::string("Dispatch Thread " + std::to_string(i)); // Create the thread BaseType_t status = xTaskCreate(reinterpret_cast<void(*)(void*)>( BOUNCE(dispatch_queue, dispatch_thread_handler)), threads_[i].name.c_str(), thread_stack_size, reinterpret_cast<void*>(this), DISPATCH_Q_PRIORITY, &threads_[i].thread); assert(status == pdPASS && "Failed to create thread!"); } }
/** * Initialize the object manager * \return 0 Success * \return -1 Failure */ int32_t UAVObjInitialize() { // Initialize variables objList = NULL; memset(&stats, 0, sizeof(UAVObjStats)); // Create mutex mutex = xSemaphoreCreateRecursiveMutex(); if (mutex == NULL) return -1; // Initialize default metadata structure (metadata of metaobjects) defMetadata.access = ACCESS_READWRITE; defMetadata.gcsAccess = ACCESS_READWRITE; defMetadata.telemetryAcked = 1; defMetadata.telemetryUpdateMode = UPDATEMODE_ONCHANGE; defMetadata.telemetryUpdatePeriod = 0; defMetadata.gcsTelemetryAcked = 1; defMetadata.gcsTelemetryUpdateMode = UPDATEMODE_ONCHANGE; defMetadata.gcsTelemetryUpdatePeriod = 0; defMetadata.loggingUpdateMode = UPDATEMODE_ONCHANGE; defMetadata.loggingUpdatePeriod = 0; // Done return 0; }
/** * Initialize the Packet Handler library * \param[in] txWinSize The transmission window size (number of tx packet buffers). * \param[in] streme A callback function for transmitting the packet. * \param[in] id The source ID of transmitter. * \return PHInstHandle The Pachet Handler instance data. * \return 0 Failure */ PHInstHandle PHInitialize(PacketHandlerConfig *cfg) { // Allocate the primary structure PHPacketDataHandle data = pvPortMalloc(sizeof(PHPacketData)); if (!data) return 0; data->cfg = *cfg; data->tx_seq_id = 0; // Allocate the packet windows data->tx_packets = pvPortMalloc(sizeof(PHPacket) * data->cfg.winSize); data->rx_packets = pvPortMalloc(sizeof(PHPacket) * data->cfg.winSize); // Initialize the windows data->tx_win_start = data->tx_win_end = 0; data->rx_win_start = data->rx_win_end = 0; for (uint8_t i = 0; i < data->cfg.winSize; ++i) { data->tx_packets[i].header.type = PACKET_TYPE_NONE; data->rx_packets[i].header.type = PACKET_TYPE_NONE; } // Create the lock data->lock = xSemaphoreCreateRecursiveMutex(); // Initialize the ECC library. initialize_ecc(); // Return the structure. return (PHInstHandle)data; }
///////////////////////////////////////////////////////////////////////////// // This hook is called after startup to initialize the application ///////////////////////////////////////////////////////////////////////////// void APP_Init(void) { // initialize all LEDs MIOS32_BOARD_LED_Init(0xffffffff); // create semaphores xSDCardSemaphore = xSemaphoreCreateRecursiveMutex(); // initialize the Notestack NOTESTACK_Init(¬estack, NOTESTACK_MODE_PUSH_TOP, ¬estack_items[0], NOTESTACK_SIZE); // init Synth SYNTH_Init(0); // initialize all J10 pins as inputs with internal Pull-Up int pin; for(pin=0; pin<8; ++pin) MIOS32_BOARD_J10_PinInit(pin, MIOS32_BOARD_PIN_MODE_INPUT_PU); // initialize Standard Control Surface SCS_Init(0); // initialize local SCS configuration SCS_CONFIG_Init(0); // initialize file system SYNTH_FILE_Init(0); // start task xTaskCreate(TASK_Periodic_1mS, (signed portCHAR *)"Periodic_1mS", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIODIC_1MS, NULL); xTaskCreate(TASK_Period_1mS_LP, (signed portCHAR *)"1mS_LP", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD_1mS_LP, NULL); }
///////////////////////////////////////////////////////////////////////////// // This hook is called after startup to initialize the application ///////////////////////////////////////////////////////////////////////////// void APP_Init(void) { // initialize all LEDs MIOS32_BOARD_LED_Init(0xffffffff); // turn off gate LED MIOS32_BOARD_LED_Set(1, 0); // create semaphores xSDCardSemaphore = xSemaphoreCreateRecursiveMutex(); // initialize file functions FILE_Init(0); // initialize MIDI handler SEQ_MIDI_OUT_Init(0); // initialize sequencer SEQ_Init(0); // install MIDI Rx callback function MIOS32_MIDI_DirectRxCallback_Init(NOTIFY_MIDI_Rx); // install sequencer task xTaskCreate(TASK_SEQ, (signed portCHAR *)"SEQ", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_SEQ, NULL); }
/** * Initialize library */ int32_t TaskMonitorInitialize(void) { lock = xSemaphoreCreateRecursiveMutex(); memset(handles, 0, sizeof(xTaskHandle)*TASKINFO_RUNNING_NUMELEM); lastMonitorTime = portGET_RUN_TIME_COUNTER_VALUE(); return 0; }
int pbntf_init(void) { m_watcher.mutw = xSemaphoreCreateRecursiveMutex(); if (NULL == m_watcher.mutw) { return -1; } m_watcher.xFD_set = FreeRTOS_CreateSocketSet(); if (NULL == m_watcher.xFD_set) { vSemaphoreDelete(m_watcher.mutw); return -1; } if (pdPASS != xTaskCreate( socket_watcher_task, "Pubnub socket watcher", SOCKET_WATCHER_STACK_DEPTH, &m_watcher, PUBNUB_TASK_PRIORITY, &m_watcher.task )) { vSemaphoreDelete(m_watcher.mutw); FreeRTOS_DeleteSocketSet(m_watcher.xFD_set); return -1; } return 0; }
void simpleQueueInitialize(struct SimpleQueue* queue){ queue->xSemHandle=xSemaphoreCreateRecursiveMutex(); //TODO Check if xSemHandle is NULL queue->head = NULL; queue->tail= NULL; queue->size = 0; }
/*----------------------------------------------------------------------- * Debug serial port display update functions *------------------------------------------------------------------------ */ static void vCreatePrintfSemaphore( void ) { if (semPrintfGate == 0) { semPrintfGate = xSemaphoreCreateRecursiveMutex(); vQueueAddToRegistry( ( QueueHandle_t ) semPrintfGate, "g_printf_Mutex" ); } }
void W5100_Init(void) { SPImutex = xSemaphoreCreateRecursiveMutex(); /* bring reset pin low */ // ETH_RESET_ClrVal(); // WAIT1_Waitms(10); // ETH_RESET_SetVal(); /* gateway IP register */ }
/** * Initialize the alarms library */ int32_t AlarmsInitialize(void) { lock = xSemaphoreCreateRecursiveMutex(); //do not change the default states of the alarms, let the init code generated by the uavobjectgenerator handle that //AlarmsClearAll(); //AlarmsDefaultAll(); return 0; }
/** * @brief Create and Initialize a Recursive Mutex * @param mutex_def mutex definition referenced with \ref osMutex. * @retval mutex ID for reference by other functions or NULL in case of error.. */ osMutexId osRecursiveMutexCreate (const osMutexDef_t *mutex_def) { (void) mutex_def; #if (configUSE_RECURSIVE_MUTEXES == 1) return xSemaphoreCreateRecursiveMutex(); #else return NULL; #endif }
int osi_mutex_global_init(void) { gl_mutex = xSemaphoreCreateRecursiveMutex(); if (gl_mutex == NULL) { return -1; } return 0; }
bool CRecursiveMutex::Create() { #if (configUSE_RECURSIVE_MUTEXES == 1 && configUSE_MUTEXES ==1) xSemaphoreHandle handle = xSemaphoreCreateRecursiveMutex(); if (handle != NULL) Attach(handle); #endif return IsValid(); }
void RFID_Init(void) { rfidSem = xSemaphoreCreateRecursiveMutex(); if (rfidSem==NULL) { /* creation failed? */ for(;;); } vQueueAddToRegistry(rfidSem, "rfidSem"); if (xTaskCreate(RfidTask, "RFID", 600/sizeof(StackType_t), NULL, tskIDLE_PRIORITY+1, NULL) != pdPASS) { for(;;){} /* error */ } }
/** * * @brief Creates a recursive mutex. * * @returns instance of @p struct pios_recursive mutex or NULL on failure * */ struct pios_recursive_mutex *PIOS_Recursive_Mutex_Create(void) { struct pios_recursive_mutex *mtx = PIOS_malloc(sizeof(struct pios_recursive_mutex)); if (mtx == NULL) return NULL; mtx->mtx_handle = (uintptr_t)xSemaphoreCreateRecursiveMutex(); return mtx; }
int mrb_freertos_rwlock_init(mrb_state *mrb, mrb_rwlock_t *lock) { //debugc('i'); xSemaphoreHandle mutex = xSemaphoreCreateRecursiveMutex(); if (mutex == NULL) { return -1; } lock->rwlock = (mrb_gem_rwlock_t)mutex; return RWLOCK_STATUS_OK; }
///////////////////////////////////////////////////////////////////////////// // Initialize all tasks ///////////////////////////////////////////////////////////////////////////// s32 TASKS_Init(u32 mode) { // create semaphores xSDCardSemaphore = xSemaphoreCreateRecursiveMutex(); xMIDIINSemaphore = xSemaphoreCreateRecursiveMutex(); xMIDIOUTSemaphore = xSemaphoreCreateRecursiveMutex(); xLCDSemaphore = xSemaphoreCreateRecursiveMutex(); xJ16Semaphore = xSemaphoreCreateRecursiveMutex(); // TODO: here we could check for NULL and bring MBSEQ into halt state // start tasks xTaskCreate(TASK_MIDI, (signed portCHAR *)"MIDI", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_MIDI, NULL); xTaskCreate(TASK_Period1mS, (signed portCHAR *)"Period1mS", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD1MS, NULL); xTaskCreate(TASK_Period1mS_LowPrio, (signed portCHAR *)"Period1mS_LP", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD1MS_LOW_PRIO, NULL); xTaskCreate(TASK_Pattern, (signed portCHAR *)"Pattern", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PATTERN, &xPatternHandle); // finally init the uIP task UIP_TASK_Init(0); return 0; // no error }
/** Create a new mutex * @param mutex pointer to the mutex to create * @return a new mutex */ err_t sys_mutex_new(sys_mutex_t *pxMutex) { *pxMutex = xSemaphoreCreateRecursiveMutex(); if (*pxMutex == NULL) { SYS_STATS_INC(mutex.err); return ERR_MEM; } SYS_STATS_INC_USED(mutex); return ERR_OK; }
static wiced_result_t wiced_freertos_init_malloc_mutex ( void ) { malloc_mutex = xSemaphoreCreateRecursiveMutex( ); if( malloc_mutex ) { return WICED_SUCCESS; } else { /* we were unable to create a mutex */ return WICED_ERROR; } }
///////////////////////////////////////////////////////////////////////////// // Initialize the uIP task ///////////////////////////////////////////////////////////////////////////// s32 UIP_TASK_Init(u32 mode) { if( mode > 0 ) return -1; // only mode 0 supported yet xUIPSemaphore = xSemaphoreCreateRecursiveMutex(); xTaskCreate(UIP_TASK_Handler, (signed portCHAR *)"uIP", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_UIP, NULL); services_running = 0; return 0; // no error }
static void prvExerciseSemaphoreAPI( void ) { SemaphoreHandle_t xSemaphore; const UBaseType_t uxMaxCount = 5, uxInitialCount = 0; /* Most of the semaphore API is common to the queue API and is already being used. This function uses a few semaphore functions that are unique to the RTOS objects, rather than generic and used by queues also. First create and use a counting semaphore. */ xSemaphore = xSemaphoreCreateCounting( uxMaxCount, uxInitialCount ); configASSERT( xSemaphore ); /* Give the semaphore a couple of times and ensure the count is returned correctly. */ xSemaphoreGive( xSemaphore ); xSemaphoreGive( xSemaphore ); configASSERT( uxSemaphoreGetCount( xSemaphore ) == 2 ); vSemaphoreDelete( xSemaphore ); /* Create a recursive mutex, and ensure the mutex holder and count are returned returned correctly. */ xSemaphore = xSemaphoreCreateRecursiveMutex(); configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 ); configASSERT( xSemaphore ); xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK ); xSemaphoreTakeRecursive( xSemaphore, mainDONT_BLOCK ); configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() ); configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetHandle( mainTASK_TO_DELETE_NAME ) ); xSemaphoreGiveRecursive( xSemaphore ); configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 ); xSemaphoreGiveRecursive( xSemaphore ); configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 ); configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL ); vSemaphoreDelete( xSemaphore ); /* Create a normal mutex, and sure the mutex holder and count are returned returned correctly. */ xSemaphore = xSemaphoreCreateMutex(); configASSERT( xSemaphore ); xSemaphoreTake( xSemaphore, mainDONT_BLOCK ); xSemaphoreTake( xSemaphore, mainDONT_BLOCK ); configASSERT( uxSemaphoreGetCount( xSemaphore ) == 0 ); /* Not recursive so can only be 1. */ configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == xTaskGetCurrentTaskHandle() ); xSemaphoreGive( xSemaphore ); configASSERT( uxSemaphoreGetCount( xSemaphore ) == 1 ); configASSERT( xSemaphoreGetMutexHolder( xSemaphore ) == NULL ); vSemaphoreDelete( xSemaphore ); }
///////////////////////////////////////////////////////////////////////////// // Initialize all tasks ///////////////////////////////////////////////////////////////////////////// s32 TASKS_Init(u32 mode) { #if USE_MSD // disable MSD by default (has to be enabled in SID_UI_FILE menu) msd_state = MSD_DISABLED; #endif // start tasks xTaskCreate(TASK_Period1mS, (signed portCHAR *)"Period1mS", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD1MS, NULL); xTaskCreate(TASK_Period1mS_LowPrio, (signed portCHAR *)"Period1mS_LP", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD1MS_LOW_PRIO, NULL); xTaskCreate(TASK_Period1S, (signed portCHAR *)"Period1S", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_PERIOD1S, NULL); #if USE_MSD xTaskCreate(TASK_MSD, (signed portCHAR *)"MSD", configMINIMAL_STACK_SIZE, NULL, PRIORITY_TASK_MSD, &xMSDHandle); #endif // create semaphores xSDCardSemaphore = xSemaphoreCreateRecursiveMutex(); xMIDIINSemaphore = xSemaphoreCreateRecursiveMutex(); xMIDIOUTSemaphore = xSemaphoreCreateRecursiveMutex(); xLCDSemaphore = xSemaphoreCreateRecursiveMutex(); // TODO: here we could check for NULL and bring MBSEQ into halt state return 0; // no error }
/** * Initialize the scheduler * must be called before any other functions are called * \return Success (0), failure (-1) */ int32_t CallbackSchedulerInitialize() { // Initialize variables schedulerTasks = NULL; schedulerStarted = false; // Create mutex mutex = xSemaphoreCreateRecursiveMutex(); if (mutex == NULL) { return -1; } // Done return 0; }
///////////////////////////////////////////////////////////////////////////// // Initialize the uIP task ///////////////////////////////////////////////////////////////////////////// s32 UIP_TASK_Init(u32 mode) { if( mode > 0 ) return -1; // only mode 0 supported yet // initialize OSC client (in distance to OSC server: only once after startup...) OSC_CLIENT_Init(0); xUIPSemaphore = xSemaphoreCreateRecursiveMutex(); xTaskCreate(UIP_TASK_Handler, (signed portCHAR *)"uIP", UIP_TASK_STACK_SIZE/4, NULL, PRIORITY_TASK_UIP, NULL); services_running = 0; udp_monitor_level = UDP_MONITOR_LEVEL_0_OFF; return 0; // no error }
static void prvCreateAndDeleteStaticallyAllocatedRecursiveMutexes( void ) { SemaphoreHandle_t xSemaphore; /* StaticSemaphore_t is a publicly accessible structure that has the same size and alignment requirements as the real semaphore structure. It is provided as a mechanism for applications to know the size of the semaphore (which is dependent on the architecture and configuration file settings) without breaking the strict data hiding policy by exposing the real semaphore internals. This StaticSemaphore_t variable is passed into the xSemaphoreCreateRecursiveMutexStatic() function calls within this function. */ StaticSemaphore_t xSemaphoreBuffer; /* Create the semaphore. xSemaphoreCreateRecursiveMutexStatic() has one more parameter than the usual xSemaphoreCreateRecursiveMutex() function. The parameter is a pointer to the pre-allocated StaticSemaphore_t structure, which will hold information on the semaphore in an anonymous way. If the pointer is passed as NULL then the structure will be allocated dynamically, just as when xSemaphoreCreateRecursiveMutex() is called. */ xSemaphore = xSemaphoreCreateRecursiveMutexStatic( &xSemaphoreBuffer ); /* The semaphore handle should equal the static semaphore structure passed into the xSemaphoreCreateBinaryStatic() function. */ configASSERT( xSemaphore == ( SemaphoreHandle_t ) &xSemaphoreBuffer ); /* Ensure the semaphore passes a few sanity checks as a valid recursive semaphore. */ prvSanityCheckCreatedRecursiveMutex( xSemaphore ); /* Delete the semaphore again so the buffers can be reused. */ vSemaphoreDelete( xSemaphore ); /* Now do the same using dynamically allocated buffers to ensure the delete functions are working correctly in both the static and dynamic memory allocation cases. */ #if( configSUPPORT_DYNAMIC_ALLOCATION == 1 ) { xSemaphore = xSemaphoreCreateRecursiveMutex(); configASSERT( xSemaphore != NULL ); prvSanityCheckCreatedRecursiveMutex( xSemaphore ); vSemaphoreDelete( xSemaphore ); } #endif }
void vStartRecursiveMutexTasks( void ) { /* Just creates the mutex and the three tasks. */ xMutex = xSemaphoreCreateRecursiveMutex(); /* vQueueAddToRegistry() adds the mutex to the registry, if one is in use. The registry is provided as a means for kernel aware debuggers to locate mutex and has no purpose if a kernel aware debugger is not being used. The call to vQueueAddToRegistry() will be removed by the pre-processor if configQUEUE_REGISTRY_SIZE is not defined or is defined to be less than 1. */ vQueueAddToRegistry( ( QueueHandle_t ) xMutex, "Recursive_Mutex" ); if( xMutex != NULL ) { xTaskCreate( prvRecursiveMutexControllingTask, "Rec1", configMINIMAL_STACK_SIZE, NULL, recmuCONTROLLING_TASK_PRIORITY, &xControllingTaskHandle ); xTaskCreate( prvRecursiveMutexBlockingTask, "Rec2", configMINIMAL_STACK_SIZE, NULL, recmuBLOCKING_TASK_PRIORITY, &xBlockingTaskHandle ); xTaskCreate( prvRecursiveMutexPollingTask, "Rec3", configMINIMAL_STACK_SIZE, NULL, recmuPOLLING_TASK_PRIORITY, NULL ); } }