/** * Initialize UART. * * \param baudrate Baudrate * * PB6 USART1_TXD * PB7 USART1_RXD * */ void init_apc220(int baudrate) { GPIO_InitTypeDef GPIO_InitStruct; // this is for the GPIO pins used as TX and RX USART_InitTypeDef USART_InitStruct; // this is for the USART1 initilization NVIC_InitTypeDef NVIC_InitStructure; // this is used to configure the NVIC (nested vector interrupt controller) /* This sequence sets up the TX and RX pins * so they work correctly with the USART1 peripheral */ GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; // Pins 6 (TX) and 7 (RX) are used GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; // the pins are configured as alternate function so the USART peripheral has access to them GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; // this defines the IO speed and has nothing to do with the baudrate! GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; // this defines the output type as push pull mode (as opposed to open drain) GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; // this activates the pullup resistors on the IO pins GPIO_Init(GPIOB, &GPIO_InitStruct); // now all the values are passed to the GPIO_Init() function which sets the GPIO registers /* The RX and TX pins are now connected to their AF * so that the USART1 can take over control of the * pins */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1); // GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1); /* Now the USART_InitStruct is used to define the * properties of USART1 */ USART_InitStruct.USART_BaudRate = baudrate; // the baudrate is set to the value we passed into this init function USART_InitStruct.USART_WordLength = USART_WordLength_8b;// we want the data frame size to be 8 bits (standard) USART_InitStruct.USART_StopBits = USART_StopBits_1; // we want 1 stop bit (standard) USART_InitStruct.USART_Parity = USART_Parity_No; // we don't want a parity bit (standard) USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; // we don't want flow control (standard) USART_InitStruct.USART_Mode = USART_Mode_Tx | USART_Mode_Rx; // we want to enable the transmitter and the receiver USART_Init(USART1, &USART_InitStruct); // again all the properties are passed to the USART_Init function which takes care of all the bit setting /* Here the USART1 receive interrupt is enabled * and the interrupt controller is configured * to jump to the USART1_IRQHandler() function * if the USART1 receive interrupt occurs */ USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); // enable the USART1 receive interrupt NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn; // we want to configure the USART1 interrupts NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;// this sets the priority group of the USART1 interrupts NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // this sets the subpriority inside the group NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // the USART1 interrupts are globally enabled NVIC_Init(&NVIC_InitStructure); // the properties are passed to the NVIC_Init function which takes care of the low level stuff // finally this enables the complete USART1 peripheral USART_Cmd(USART1, ENABLE); // Create semaphores to protect the rx_buf and tx_buf variables xSemaphoreTx = xSemaphoreCreateMutex(); xSemaphoreRx = xSemaphoreCreateMutex(); // initialize stats uart_stats.rx_bytes = 0; uart_stats.tx_bytes = 0; uart_stats.rx_buff1_busy = 0; }
/** * Initialise the telemetry module * \return -1 if initialisation failed * \return 0 on success */ int32_t OveroSyncStart(void) { overosync = (struct overosync *)pios_malloc(sizeof(*overosync)); if (overosync == NULL) { return -1; } overosync->transaction_lock = xSemaphoreCreateMutex(); if (overosync->transaction_lock == NULL) { return -1; } overosync->buffer_lock = xSemaphoreCreateMutex(); if (overosync->buffer_lock == NULL) { return -1; } overosync->active_transaction_id = 0; overosync->loading_transaction_id = 0; overosync->write_pointer = 0; overosync->sent_bytes = 0; overosync->framesync_error = 0; // Process all registered objects and connect queue for updates UAVObjIterate(®isterObject); // Start telemetry tasks xTaskCreate(overoSyncTask, (signed char *)"OveroSync", STACK_SIZE_BYTES / 4, NULL, TASK_PRIORITY, &overoSyncTaskHandle); PIOS_TASK_MONITOR_RegisterTask(TASKINFO_RUNNING_OVEROSYNC, overoSyncTaskHandle); return 0; }
///////////////////////////////////////////////////////////////////////////// // This hook is called after startup to initialize the application ///////////////////////////////////////////////////////////////////////////// void APP_Init(void) { s32 i; // initialize all LEDs MIOS32_BOARD_LED_Init(0xffffffff); // MUST be initialized before the SPI functions xSPI0Semaphore = xSemaphoreCreateMutex(); xSDCardSemaphore = xSemaphoreCreateMutex(); // Init filesystem and start SD Card monitoring thread FS_Init(0); xTaskCreate(TASK_Period1S, (signed portCHAR *)"Period1S", configMINIMAL_STACK_SIZE, NULL, ( tskIDLE_PRIORITY + 4 ), NULL); // start uIP task UIP_TASK_Init(0); // print first message print_msg = PRINT_MSG_INIT; // 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"); }
/** * @brief The main task for the CAN2 channel * @param pvParameters: * @retval None */ void can2Task(void *pvParameters) { /* Mutex semaphore to manage when it's ok to send and receive new data */ xSemaphore = xSemaphoreCreateMutex(); /* Mutex semaphore for accessing the settings for this channel */ xSettingsSemaphore = xSemaphoreCreateMutex(); /* Create software timers */ prvBuffer1ClearTimer = xTimerCreate("Buf1Clear4", 10, pdFALSE, 0, prvBuffer1ClearTimerCallback); prvBuffer2ClearTimer = xTimerCreate("Buf2Clear5", 10, pdFALSE, 0, prvBuffer2ClearTimerCallback); /* Initialize hardware */ prvHardwareInit(); vTaskDelay(2000); // can2SetTermination(CANTermination_Connected); can2SetConnection(CANConnection_Connected); /* The parameter in vTaskDelayUntil is the absolute time * in ticks at which you want to be woken calculated as * an increment from the time you were last woken. */ TickType_t xNextWakeTime; /* Initialize xNextWakeTime - this only needs to be done once. */ xNextWakeTime = xTaskGetTickCount(); while (1) { vTaskDelayUntil(&xNextWakeTime, 1000 / portTICK_PERIOD_MS); } }
int main(void) { /* Initializing shared Queues */ dispatcherQueue = xQueueCreate(25, sizeof(DispCmd)); #if(SCH_TASKEXECUTER_INSIDE_TASKDISPATCHER==1) //no Queue creation #else executerCmdQueue = xQueueCreate(1,sizeof(ExeCmd)); executerStatQueue = xQueueCreate(1,sizeof(int)); #endif i2cRxQueue = xQueueCreate(I2C_MTU, sizeof(char)); //TRX_GOMSPACE /* Initializing shared Semaphore */ statusRepositorySem = xSemaphoreCreateMutex(); consolePrintfSem = xSemaphoreCreateMutex(); rtcPrintSem = xSemaphoreCreateMutex(); /* Configure Peripherals */ /* NOTA: EL TIMER 1 Y SU INTERRUPCION ESTAN CONFIGURADOS POR EL S.0. (FreeRTOS) */ default_PIC_config(); /* Initializing LibCSP*/ com_csp_initialization(); //Issue #8: Initialize libcsp before trx /* System initialization */ dep_init_suchai_hw(); dep_init_suchai_repos(); /////////////////////////////////////////////// // Uncomment section only for debug purposes // /////////////////////////////////////////////// // int arg_param = 1; // thk_executeBeforeFlight((void *)&arg_param); // int tries = 1; // thk_deployment_registration(&tries); /////////////////////////////////////////////// // Uncomment section only for debug purposes // /////////////////////////////////////////////// /* Crating SUCHAI tasks */ dep_init_suchai_tasks(); /* Start the scheduler. Should never return */ printf("\nStarting FreeRTOS [->]\r\n"); vTaskStartScheduler(); while(1) { /* * El sistema solo llega hasta aca si el Scheduler falla debido * a falta de memoria u otro problema */ printf("\n>>FreeRTOS [FAIL]\n"); ppc_reset(NULL); } return 0; }
static void init_captors() { world.sharp_mutex = xSemaphoreCreateMutex(); world.ultra_mutex = xSemaphoreCreateMutex(); world.prev_sharp_vals[0] = 0; world.prev_sharp_vals[1] = 0; world.prev_ultra_vals[0] = 0; world.prev_ultra_vals[1] = 0; }
SimpleMotionComm::SimpleMotionComm( Serial *port, System *parent, int nodeAddress ) /*: localInstantCmdInterpreter(parent), localBufferedCmdInterpreter(parent)*/ { parentSystem=parent; //physicalIO=&parent->physIO; comm = port; userCmds.allocate( CMDBUFSIZE ); userCmdRets.allocate( CMDBUFSIZE ); myAddress = nodeAddress; cmdClock = 0; setBusTimeout(1000);//default 0.1sec setBusBufferedCmdPeriod(100);//default 1/100s bufferedCmdStatus=SM_BUFCMD_STAT_IDLE; setBusBaudRate(460800); setBusMode(1); resetReceiverState(); receptionBeginTime=0; //create queue localInstantCmdDelayQueue = xQueueCreate( 4, sizeof( SMPayloadCommandForQueue ) ); //localInstantCmdDelayQueue = xQueueCreate( 10, sizeof( SMPayloadCommandForQueue ) ); //set Q naming for kernel aware debugging, otherwise useless: vQueueAddToRegistry(localInstantCmdDelayQueue,(signed char*)"485InstDlyQ"); //create queue localBufferedCmdDelayQueue= xQueueCreate( 10, sizeof( SMPayloadCommandForQueue ) ); //set Q naming for kernel aware debugging, otherwise useless: vQueueAddToRegistry(localBufferedCmdDelayQueue,(signed char*)"485BufDlyQ"); payloadIn.allocate(PAYLOAD_BUFSIZE); payloadOut.allocate(PAYLOAD_BUFSIZE); mutex = xSemaphoreCreateMutex(); if( mutex == NULL ) { parentSystem->setFault(FLT_SM485_ERROR|FLT_FIRMWARE|FLT_ALLOC,480101); } bufferMutex = xSemaphoreCreateMutex(); if(bufferMutex==NULL) { parentSystem->setFault( FLT_SM485_ERROR|FLT_FIRMWARE|FLT_ALLOC,480102); } vSemaphoreCreateBinary( SimpleMotionBufferedTaskSemaphore ); if(SimpleMotionBufferedTaskSemaphore==NULL) { parentSystem->setFault( FLT_SM485_ERROR|FLT_FIRMWARE|FLT_ALLOC,480103); } //xSemaphoreGive( mutex ); }
/** * @brief The main task for the CAN1 channel * @param pvParameters: * @retval None */ void can1Task(void *pvParameters) { /* Mutex semaphore to manage when it's ok to send and receive new data */ xSemaphore = xSemaphoreCreateMutex(); /* Mutex semaphore for accessing the settings for this channel */ xSettingsSemaphore = xSemaphoreCreateMutex(); /* Create software timers */ prvBuffer1ClearTimer = xTimerCreate("Buf1ClearCan1", 10, pdFALSE, 0, prvBuffer1ClearTimerCallback); prvBuffer2ClearTimer = xTimerCreate("Buf2ClearCan1", 10, pdFALSE, 0, prvBuffer2ClearTimerCallback); /* Initialize hardware */ prvHardwareInit(); /* Wait to make sure the SPI FLASH is initialized */ while (SPI_FLASH_Initialized() == false) { vTaskDelay(100 / portTICK_PERIOD_MS); } /* Try to read the settings from SPI FLASH */ prvReadSettingsFromSpiFlash(); can1Clear(); /* The parameter in vTaskDelayUntil is the absolute time * in ticks at which you want to be woken calculated as * an increment from the time you were last woken. */ TickType_t xNextWakeTime; /* Initialize xNextWakeTime - this only needs to be done once. */ xNextWakeTime = xTaskGetTickCount(); uint8_t count = 0; prvDoneInitializing = true; while (1) { vTaskDelayUntil(&xNextWakeTime, 1000 / portTICK_PERIOD_MS); // /* Transmit debug data */ // if (prvCurrentSettings.connection == CANConnection_Connected) // { // /* Set the data to be transmitted */ // uint8_t data[2] = {0xAA, count}; // can1Transmit(0x321, data, CANDataLength_2, 50); // count++; // // if (count % 10 == 0) // { // uint8_t data2[5] = {0x72, 0x21, 0xDE, 0x03, 0xFA}; // can1Transmit(0x321, data2, CANDataLength_5, 50); // } // } } }
/** * @brief The main task for the UART1 channel * @param pvParameters: * @retval None */ void uart1Task(void *pvParameters) { /* Mutex semaphore to manage when it's ok to send and receive new data */ xSemaphore = xSemaphoreCreateMutex(); /* Mutex semaphore for accessing the settings for this channel */ xSettingsSemaphore = xSemaphoreCreateMutex(); /* Create software timers */ prvBuffer1ClearTimer = xTimerCreate("Buf1ClearUart1", 10, pdFALSE, 0, prvBuffer1ClearTimerCallback); prvBuffer2ClearTimer = xTimerCreate("Buf2ClearUart1", 10, pdFALSE, 0, prvBuffer2ClearTimerCallback); /* Initialize hardware */ prvHardwareInit(); /* Wait to make sure the SPI FLASH is initialized */ while (SPI_FLASH_Initialized() == false) { vTaskDelay(100 / portTICK_PERIOD_MS); } /* Try to read the settings from SPI FLASH */ prvReadSettingsFromSpiFlash(); /* * TODO: Figure out a good way to allow saved data in SPI FLASH to be read next time we wake up so that we * don't have to do a clear every time we start up the device. */ uart1Clear(); // uint8_t* data = "UART1 Debug! "; uint8_t* data = "Prevas Student Embedded Awards 2014 - "; /* The parameter in vTaskDelayUntil is the absolute time * in ticks at which you want to be woken calculated as * an increment from the time you were last woken. */ TickType_t xNextWakeTime; /* Initialize xNextWakeTime - this only needs to be done once. */ xNextWakeTime = xTaskGetTickCount(); prvDoneInitializing = true; while (1) { vTaskDelayUntil(&xNextWakeTime, 1000 / portTICK_PERIOD_MS); /* Transmit debug data if that mode is active */ if (prvCurrentSettings.connection == UARTConnection_Connected && prvCurrentSettings.mode == UARTMode_DebugTX) uart1Transmit(data, strlen(data)); } /* Something has gone wrong */ error: while (1); }
void uart0_init() { Init_UART0_PinMux(); vSemaphoreCreateBinary(sem_uart_ready); vSemaphoreCreateBinary(sem_uart_read_ready); mutex_uart_in_use = xSemaphoreCreateMutex(); mutex_uart_read_in_use = xSemaphoreCreateMutex(); // FreeRTOS craziness!!! xSemaphoreTake(sem_uart_ready, 0); xSemaphoreTake(sem_uart_read_ready, 0); uart_ready = false; }
static void init_state() { world.x = INIT_X_1; world.y = INIT_Y_1; world.phi = INIT_PHI_1; world.stop = true; world.state_mutex = xSemaphoreCreateMutex(); world.update_state_mutex = xSemaphoreCreateMutex(); world.current_speed.left_speed = INIT_LEFT_SPEED; world.current_speed.right_speed = INIT_RIGHT_SPEED; }
void vWireInit() { static char isInitialized = 0; if( 0 == isInitialized ) { xMutexBus1 = xSemaphoreCreateMutex(); xMutexBus2 = xSemaphoreCreateMutex(); xMutexBus3 = xSemaphoreCreateMutex(); xMutexBus4 = xSemaphoreCreateMutex(); xMutexBus5 = xSemaphoreCreateMutex(); isInitialized = 1; } }
/** * \brief Initialize tasks and resources for demo * * This function initializes the \ref oled1_xpro_io_group instance and the * \ref edbg_cdc_rx_group instance for reception, then creates all * the objects for FreeRTOS to run the demo. */ void demotasks_init(void) { // Initialize hardware for the OLED1 Xplained Pro driver instance oled1_init(&oled1); // Configure SERCOM USART for reception from EDBG Virtual COM Port cdc_rx_init(&cdc_usart, &cdc_rx_handler); display_mutex = xSemaphoreCreateMutex(); terminal_mutex = xSemaphoreCreateMutex(); terminal_in_queue = xQueueCreate(64, sizeof(uint8_t)); xTaskCreate(about_task, (const char *)"About", configMINIMAL_STACK_SIZE, NULL, ABOUT_TASK_PRIORITY, &about_task_handle); xTaskCreate(graph_task, (const char *)"Graph", configMINIMAL_STACK_SIZE, NULL, GRAPH_TASK_PRIORITY, NULL); xTaskCreate(main_task, (const char *) "Main", configMINIMAL_STACK_SIZE, NULL, MAIN_TASK_PRIORITY, NULL); xTaskCreate(terminal_task, (const char *)"Term.", configMINIMAL_STACK_SIZE, NULL, TERMINAL_TASK_PRIORITY, &terminal_task_handle); xTaskCreate(uart_task, (const char *) "UART", configMINIMAL_STACK_SIZE, NULL, UART_TASK_PRIORITY, NULL); // Suspend these since the main task will control their execution vTaskSuspend(about_task_handle); vTaskSuspend(terminal_task_handle); }
void FS_Console_Init( FS_Console_InitStruct_t * initStruct, FS_Console_InitReturnsStruct_t * returns ) { // Create a mutex to protect the list of IO streams. io.mutex = xSemaphoreCreateMutex(); // Transfer the pertinent fields from the init struct. echo = initStruct->echo; echoToAllOutputStreams = initStruct->echoToAllOutputStreams; instance = initStruct->instance; // Copy in the default IO stream interface. io.interfaces[0] = initStruct->io; io.defaultInterfaceIndex = 0; // Bind the instance to the implementation. instance->printf = consolePrintf; instance->registerCommand = registerCommand; // Populate the returns struct. returns->addIOStreamCallback = addIOStreamCallback; returns->removeIOStreamCallback = removeIOStreamCallback; returns->mainLoop = mainLoop; returns->success = true; // Add the built-in commands to the command table. registerCommand("help", help, "TEST HELP STRING"); }
/** * Message dispatcher initialisation. Run it before running inputTaskInit(). */ retcode msgDispatcherInit() { dispatcher.curPointerPosX = 0; dispatcher.curPointerPosY = 0; if (dispatcherMutex == NULL) dispatcherMutex = xSemaphoreCreateMutex(); if (dispatcherMutex == NULL) { return ERR_NO_MEMMORY; } if (xSemaphoreTake(dispatcherMutex, portMAX_DELAY)) { INIT_LIST_HEAD(&dispatcher.listenersList); xSemaphoreGive(dispatcherMutex); } else { MUTEX_ERROR(); return ERR_MUTEX; } return SUCCESS; }
/*! \brief WEB server main task * check for incoming connection and process it * * \param pvParameters Input. Not Used. * */ portTASK_FUNCTION( vBasicZwaveServer, pvParameters ) { struct netconn *pxZwaveListener, *pxNewConnection; /*We create FreeRTOS tools for ipc and locking*/ zw_tcp_recv_queue = xQueueCreate(100, 1); xRxSem = xSemaphoreCreateMutex(); /* Create a new tcp connection handle */ vParTestToggleLED(1); vTaskDelay(500*portTICK_RATE_MS); vParTestToggleLED(1); pxZwaveListener = netconn_new( NETCONN_TCP ); netconn_bind(pxZwaveListener, NULL, zwavePORT ); netconn_listen( pxZwaveListener ); vTaskDelay(500*portTICK_RATE_MS); vParTestToggleLED(2); vTaskDelay(1000*portTICK_RATE_MS); vParTestToggleLED(2); /* Loop forever */ for( ;; ) { /* Wait for a first connection. */ pxNewConnection = netconn_accept(pxZwaveListener); if(pxNewConnection != NULL) { prvweb_HandleZwaveSession(pxNewConnection); }/* end if new connection */ vTaskDelay(500*portTICK_RATE_MS); } /* end infinite loop */ }
/** * @brief Configures the USART3 Peripheral. * @param USART speed * @retval None */ void USART3_Config(uint32_t speed) { USART_InitTypeDef USART_InitStructure; GPIO_InitTypeDef GPIO_InitStructure; NVIC_InitTypeDef NVIC_InitStructure; /* Enable GPIO clock */ RCC_AHBPeriphClockCmd(USART3_TX_GPIO_CLK | USART3_RX_GPIO_CLK, ENABLE); /* Enable USART clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); /* Connect PXx to USART3_Tx */ GPIO_PinAFConfig(USART3_TX_GPIO_PORT, USART3_TX_SOURCE, USART3_TX_AF); /* Connect PXx to USART3_Rx */ GPIO_PinAFConfig(USART3_RX_GPIO_PORT, USART3_RX_SOURCE, USART3_RX_AF); /* Configure USART Tx and Rx as alternate function push-pull */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_InitStructure.GPIO_Pin = USART3_TX_PIN; GPIO_Init(USART3_TX_GPIO_PORT, &GPIO_InitStructure); GPIO_InitStructure.GPIO_Pin = USART3_RX_PIN; GPIO_Init(USART3_RX_GPIO_PORT, &GPIO_InitStructure); /* USART3 configuration ----------------------------------------------------*/ /* USART3 configured as follow: - BaudRate = 9600 baud - Word Length = 8 Bits - one Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive enabled */ USART_InitStructure.USART_BaudRate = speed; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx|USART_Mode_Tx; USART_Init(USART3, &USART_InitStructure); USART_ITConfig(USART3, USART_IT_RXNE, ENABLE); usart3_rx_buf_pos = 0; /* Enable USART3 RX IRQ */ NVIC_InitStructure.NVIC_IRQChannel = USART3_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configGPS_INTERRUPT_PRIORITY; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); xUSART3Semaphore = xSemaphoreCreateMutex(); }
void mac_tdma_init (uint16_t addr) { if (tdma_mutex == NULL) { tdma_mutex = xSemaphoreCreateMutex(); } /* Init libs. */ soft_timer_init(); packet_init(); /* Init tdma modules. */ tdma_frame_init(); tdma_slot_init(); /* eventually generate address */ if (addr == 0x0000 || addr == 0xffff) { addr = uid->uid16[0] ^ uid->uid16[1] ^ uid->uid16[2] ^ uid->uid16[3] ^ uid->uid16[4] ^ uid->uid16[5]; if (addr == 0x0000 || addr == 0xffff) { addr ^= 0x00ff; } log_info("Generating address from id -> %04x", addr); } /* Init structure */ tdma_data.addr = addr; tdma_data.state = TDMA_IDLE; tdma_data.slot_cb = NULL; }
/**************************************************************************** * * fn_initvolume * * initiate a volume, this function has to be called 1st to set physical * driver function to a given volume * * RETURNS * * error code or zero if successful * ***************************************************************************/ unsigned char fn_initvolume ( F_DRIVERINIT initfunc ) { #if F_FS_THREAD_AWARE == 1 { extern xSemaphoreHandle fs_lock_semaphore; if( fs_lock_semaphore == NULL ) { fs_lock_semaphore = xSemaphoreCreateMutex(); if( fs_lock_semaphore == NULL ) { return F_ERR_OS; } } } #endif /* F_FS_THREAD_AWARE */ gl_volume.state = F_STATE_NONE; mdrv = initfunc( 0 ); if ( mdrv == NULL ) { return F_ERR_INITFUNC; } gl_volume.state = F_STATE_NEEDMOUNT; #if F_FILE_CHANGED_EVENT f_filechangedevent = 0; #endif return _f_getvolume(); } /* fn_initvolume */
esp_err_t spi_init(spi_host_t host, spi_config_t *config) { SPI_CHECK(host < SPI_NUM_MAX, "host num error", ESP_ERR_INVALID_ARG); SPI_CHECK(host > CSPI_HOST, "CSPI_HOST can't support now", ESP_FAIL); SPI_CHECK(NULL == spi_object[host], "spi has been initialized", ESP_FAIL); spi_object[host] = (spi_object_t *)malloc(sizeof(spi_object_t)); SPI_CHECK(spi_object[host], "malloc fail", ESP_ERR_NO_MEM); spi_object[host]->trans_mux = xSemaphoreCreateMutex(); if (NULL == spi_object[host]->trans_mux) { spi_deinit(host); SPI_CHECK(false, "Semaphore create fail", ESP_ERR_NO_MEM); } uint16_t dummy_bitlen = 0; spi_set_event_callback(host, &config->event_cb); spi_set_mode(host, &config->mode); spi_set_interface(host, &config->interface); spi_set_clk_div(host, &config->clk_div); spi_set_dummy(host, &dummy_bitlen); spi_set_intr_enable(host, &config->intr_enable); spi_intr_register(spi_intr, NULL); spi_intr_enable(); if (spi_object[host]->event_cb) { spi_object[host]->event_cb(SPI_INIT_EVENT, NULL); } return ESP_OK; }
void logInit(void) { int i; if(isInit) return; logs = &_log_start; logsLen = &_log_stop - &_log_start; logsCrc = crcSlow(logs, logsLen); // Big lock that protects the log datastructures logLock = xSemaphoreCreateMutex(); for (i=0; i<logsLen; i++) { if(!(logs[i].type & LOG_GROUP)) logsCount++; } //Manually free all log blocks for(i=0; i<LOG_MAX_BLOCKS; i++) logBlocks[i].id = BLOCK_ID_FREE; //Init data structures and set the log subsystem in a known state logReset(); //Start the log task xTaskCreate(logTask, (const signed char * const)"log", configMINIMAL_STACK_SIZE, NULL, /*priority*/1, NULL); isInit = true; }
portBASE_TYPE xNetworkInterfaceInitialise( void ) { portBASE_TYPE xReturn = pdFALSE; pcap_if_t *pxAllNetworkInterfaces; if( xPCAPMutex == NULL ) { xPCAPMutex = xSemaphoreCreateMutex(); configASSERT( xPCAPMutex ); } /* Query the computer the simulation is being executed on to find the network interfaces it has installed. */ pxAllNetworkInterfaces = prvPrintAvailableNetworkInterfaces(); /* Open the network interface. The number of the interface to be opened is set by the configNETWORK_INTERFACE_TO_USE constant in FreeRTOSConfig.h. Calling this function will set the pxOpenedInterfaceHandle variable. If, after calling this function, pxOpenedInterfaceHandle is equal to NULL, then the interface could not be opened. */ if( pxAllNetworkInterfaces != NULL ) { prvOpenSelectedNetworkInterface( pxAllNetworkInterfaces ); } if( pxOpenedInterfaceHandle != NULL ) { xReturn = pdPASS; } return xReturn; }
int main( void ) { /* Before a semaphore is used it must be explicitly created. In this example a mutex type semaphore is created. */ xMutex = xSemaphoreCreateMutex(); /* The tasks are going to use a pseudo random delay, seed the random number generator. */ srand( 567 ); /* Only create the tasks if the semaphore was created successfully. */ if( xMutex != NULL ) { /* Create two instances of the tasks that attempt to write stdout. The string they attempt to write is passed in as the task parameter. The tasks are created at different priorities so some pre-emption will occur. */ xTaskCreate( prvPrintTask, "Print1", 240, "Task 1 ******************************************\n", 1, NULL ); xTaskCreate( prvPrintTask, "Print2", 240, "Task 2 ------------------------------------------\n", 2, NULL ); /* Start the scheduler so the created tasks start executing. */ vTaskStartScheduler(); } /* If all is well we will never reach here as the scheduler will now be running the tasks. If we do reach here then it is likely that there was insufficient heap memory available for a resource to be created. */ for( ;; ); return 0; }
void vStartUART_NAVITask(unsigned portBASE_TYPE uxPriority) { /* Creating semaphore related to this task */ xSemaphoreUART_NAVIRX = NULL; xSemaphoreUART_NAVIRX = xSemaphoreCreateBinary(); xSemaphoreUART_NAVITX = NULL; xSemaphoreUART_NAVITX = xSemaphoreCreateMutex(); /* Creating queue which is responsible for handling IMU_t typedef data */ xQueueUART_1xIMU_t = xQueueCreate(1, sizeof(IMU_t) ); /* Creating queue which is responsible for handling SENSOR_t typedef data */ xQueueUART_1xSENSOR_t = xQueueCreate(1, sizeof(SENSOR_t) ); /* Creating task [sending IMU data frames] 25 Hz task */ xTaskHandle xHandleTaskUART_NAVIimu; xTaskCreate( vTaskUART_NAVIimu, "UART_NAVI_TXimu", configMINIMAL_STACK_SIZE, NULL, uxPriority, &xHandleTaskUART_NAVIimu ); /* Creating task [sending SENSOR data frames] 10 Hz task*/ xTaskHandle xHandleTaskUART_NAVIsns; xTaskCreate( vTaskUART_NAVIsns, "UART_NAVI_TXsns", configMINIMAL_STACK_SIZE, NULL, uxPriority, &xHandleTaskUART_NAVIsns ); }
__attribute__((constructor)) void fio_init() { memset(fio_fds, 0, sizeof(fio_fds)); fio_fds[0].fdread = stdin_read; fio_fds[1].fdwrite = stdout_write; fio_fds[2].fdwrite = stdout_write; fio_sem = xSemaphoreCreateMutex(); }
/**************************************************************************** MAIN APPLICATION ENTRY POINT ****************************************************************************/ int main(void) { // Queue creation - will be used for communication between the stack and other tasks xQueue = xQueueCreate(3, sizeof (int)); xSemFrontEnd = xSemaphoreCreateMutex(); // Initialize application specific hardware HWInit(HWDEFAULT); UARTInit(1,19200); UARTOn(1); // RTOS starting if (xSemFrontEnd != NULL) { // Creates the task to handle all HiLo functions xTaskCreate(GSMTask, (signed char*) "GSM", STACK_SIZE_GSM, NULL, tskIDLE_PRIORITY + 1, &hGSMTask); // Start of the RTOS scheduler, this function should never return vTaskStartScheduler(); } #if defined (STACK_USE_UART) UARTWrite(1, "Unexpected end of program...\r\n"); #endif while(1); return -1; }
int main( void ) { const uint32_t ulLongTime_ms = 250UL; /* Create a mutex that is used to guard against the console being accessed by more than one task simultaniously. */ xConsoleMutex = xSemaphoreCreateMutex(); /* Initialise the network interface. Tasks that use the network are created in the network event hook when the network is connected and ready for use. The address values passed in here are used if ipconfigUSE_DHCP is set to 0, or if ipconfigUSE_DHCP is set to 1 but a DHCP server cannot be contacted. */ FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress ); /* Register commands with the FreeRTOS+CLI command interpreter. */ vRegisterCLICommands(); /* Start the RTOS scheduler. */ vTaskStartScheduler(); /* If all is well, the scheduler will now be running, and the following line will never be reached. If the following line does execute, then there was insufficient FreeRTOS heap memory available for the idle and/or timer tasks to be created. See the memory management section on the FreeRTOS web site for more details (this is standard text that is not not really applicable to the Win32 simulator port). */ for( ;; ) { Sleep( ulLongTime_ms ); } }
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); #ifdef OS *sobj = xSemaphoreCreateMutex(); /* FreeRTOS */ ret = (*sobj != NULL) ? 1 : 0; #else int *pint = malloc(4); *pint = 0; *sobj = pint; ret = 1; #endif return ret; }
I2C_Base::I2C_Base(LPC_I2C_TypeDef* pI2CBaseAddr) : mpI2CRegs(pI2CBaseAddr), mDisableOperation(false) { mI2CMutex = xSemaphoreCreateMutex(); vSemaphoreCreateBinary(mReadCompSig); /// Binary semaphore needs to be taken after creating it xSemaphoreTake(mReadCompSig, 0); if((unsigned int)mpI2CRegs == LPC_I2C0_BASE) { mIRQ = I2C0_IRQn; } else if((unsigned int)mpI2CRegs == LPC_I2C1_BASE) { mIRQ = I2C1_IRQn; } else if((unsigned int)mpI2CRegs == LPC_I2C2_BASE) { mIRQ = I2C2_IRQn; } else { mIRQ = (IRQn_Type)99; // Using invalid IRQ on purpose } }
/*---------------------------------------------------------------------------------------------------------*/ static uint32_t ESP8266_Start( ) { size_t i; for(i=0;i<4;i++) { sockets[i].handle=(void*)i; sockets[i].ioctl=DEV_API_dummy_ioctl_func; sockets[i].pwrite=ESP8266_socket_pwrite; } xQueue = xQueueCreate( ESP8266_MAX_QUEUE_LEN , sizeof( xMessage_t ) ); sendDataMutex = xSemaphoreCreateMutex(); SystemTick_API_CreateTimeoutTimer( &timeoutTimer ); xTaskCreate( ESP8266_Task, "ESP8266_Task", ESP8266_TASK_STACK_SIZE,(void*) NULL, ESP8266_TASK_PRIORITY , NULL ); initDone=1; return 0; }