当前位置: 首页>>代码示例>>C++>>正文


C++ xSemaphoreCreateMutex函数代码示例

本文整理汇总了C++中xSemaphoreCreateMutex函数的典型用法代码示例。如果您正苦于以下问题:C++ xSemaphoreCreateMutex函数的具体用法?C++ xSemaphoreCreateMutex怎么用?C++ xSemaphoreCreateMutex使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xSemaphoreCreateMutex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init_apc220

/**
 * 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;
}
开发者ID:AlexFielding,项目名称:luba,代码行数:69,代码来源:apc220.c

示例2: OveroSyncStart

/**
 * 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(&registerObject);

    // 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;
}
开发者ID:B-robur,项目名称:OpenPilot,代码行数:38,代码来源:overosync.c

示例3: APP_Init

/////////////////////////////////////////////////////////////////////////////
// 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");
}
开发者ID:JKcompute,项目名称:395_midi_controller,代码行数:31,代码来源:app.c

示例4: can2Task

/**
 * @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);

    }
}
开发者ID:efimefimefim,项目名称:HexConnect,代码行数:37,代码来源:can2_task.c

示例5: main

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;
}
开发者ID:spel-uchile,项目名称:SUCHAI,代码行数:58,代码来源:main.c

示例6: init_captors

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;
}
开发者ID:eurobotMTR2014,项目名称:eurobot_os,代码行数:9,代码来源:world.c

示例7: localInstantCmdInterpreter

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 );

}
开发者ID:CaseyHsu,项目名称:ArgonServoDriveFirmware,代码行数:56,代码来源:sm485.cpp

示例8: can1Task

/**
 * @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);
//			}
//		}
	}
}
开发者ID:efimefimefim,项目名称:HexConnect,代码行数:60,代码来源:can1_task.c

示例9: uart1Task

/**
 * @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);
}
开发者ID:efimefimefim,项目名称:HexConnect,代码行数:59,代码来源:uart1_task.c

示例10: uart0_init

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;
}
开发者ID:jmeed,项目名称:teamRocket,代码行数:12,代码来源:uart0.c

示例11: init_state

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;
}
开发者ID:eurobotMTR2014,项目名称:eurobot_os,代码行数:12,代码来源:world.c

示例12: vWireInit

void vWireInit()
{
    static char isInitialized = 0;
    if( 0 == isInitialized ) {
        xMutexBus1 = xSemaphoreCreateMutex();
        xMutexBus2 = xSemaphoreCreateMutex();
        xMutexBus3 = xSemaphoreCreateMutex();
        xMutexBus4 = xSemaphoreCreateMutex();
        xMutexBus5 = xSemaphoreCreateMutex();
        isInitialized = 1;
    }
}
开发者ID:DerekAJohnson,项目名称:cysat,代码行数:12,代码来源:wire.c

示例13: demotasks_init

/**
 * \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);
}
开发者ID:InSoonPark,项目名称:asf,代码行数:58,代码来源:demotasks.c

示例14: FS_Console_Init

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");
}
开发者ID:firmwaresavvy,项目名称:FS_System,代码行数:28,代码来源:fs_console.c

示例15: msgDispatcherInit

/**
 * 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;
}
开发者ID:erhemeshjs,项目名称:intensesx,代码行数:29,代码来源:msgDispatcher.c


注:本文中的xSemaphoreCreateMutex函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。