这篇教程C++ xQueueCreate函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中xQueueCreate函数的典型用法代码示例。如果您正苦于以下问题:C++ xQueueCreate函数的具体用法?C++ xQueueCreate怎么用?C++ xQueueCreate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了xQueueCreate函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: xSerialPortInitMinimal/* * See the serial2.h header file. */xComPortHandle xSerialPortInitMinimal( unsigned long ulWantedBaud, unsigned portBASE_TYPE uxQueueLength ){xComPortHandle xReturn;UART_InitTypeDef UART_InitStructure;GPIO_InitTypeDef GPIO_InitStructure;EIC_IRQInitTypeDef EIC_IRQInitStructure; /* Create the queues used to hold Rx and Tx characters. */ xRxedChars = xQueueCreate( uxQueueLength, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); xCharsForTx = xQueueCreate( uxQueueLength + 1, ( unsigned portBASE_TYPE ) sizeof( signed char ) ); /* If the queues were created correctly then setup the serial port hardware. */ if( ( xRxedChars != serINVALID_QUEUE ) && ( xCharsForTx != serINVALID_QUEUE ) ) { portENTER_CRITICAL(); { /* Enable the UART0 Clock. */ MRCC_PeripheralClockConfig( MRCC_Peripheral_UART0, ENABLE ); /* Configure the UART0_Tx as alternate function */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11; GPIO_Init(GPIO0, &GPIO_InitStructure); /* Configure the UART0_Rx as input floating */ GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; GPIO_Init(GPIO0, &GPIO_InitStructure); /* Configure UART0. */ UART_InitStructure.UART_WordLength = UART_WordLength_8D; UART_InitStructure.UART_StopBits = UART_StopBits_1; UART_InitStructure.UART_Parity = UART_Parity_No; UART_InitStructure.UART_BaudRate = ulWantedBaud; UART_InitStructure.UART_HardwareFlowControl = UART_HardwareFlowControl_None; UART_InitStructure.UART_Mode = UART_Mode_Tx_Rx; UART_InitStructure.UART_TxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */ UART_InitStructure.UART_RxFIFOLevel = UART_FIFOLevel_1_2; /* FIFO size 16 bytes, FIFO level 8 bytes */ UART_Init(UART0, &UART_InitStructure); /* Enable the UART0 */ UART_Cmd(UART0, ENABLE); /* Configure the IEC for the UART interrupts. */ EIC_IRQInitStructure.EIC_IRQChannelCmd = ENABLE; EIC_IRQInitStructure.EIC_IRQChannel = UART0_IRQChannel; EIC_IRQInitStructure.EIC_IRQChannelPriority = 1; EIC_IRQInit(&EIC_IRQInitStructure); xQueueEmpty = pdTRUE; UART_ITConfig( UART0, UART_IT_Transmit | UART_IT_Receive, ENABLE ); } portEXIT_CRITICAL(); } else { xReturn = ( xComPortHandle ) 0; } /* This demo file only supports a single port but we have to return something to comply with the standard demo header file. */ return xReturn;}
开发者ID:DuinOS,项目名称:FreeRTOS,代码行数:67,
示例2: adc_initvoid adc_init(adc_t* adc){ static int already_initialized = 0; gpio_clock_init(adc->GPIOx); GPIO_InitTypeDef GPIO_InitStructure = { .GPIO_Pin = adc->GPIO_Pin_x, .GPIO_Speed = GPIO_Speed_2MHz, .GPIO_Mode = GPIO_Mode_IN_FLOATING, }; GPIO_Init(adc->GPIOx, &GPIO_InitStructure); // avoid configuring ADC2 again: if (already_initialized) return; already_initialized = 1; adc_clock_init(ADC2); xADCMutex = xSemaphoreCreateMutex(); xADCQueue = xQueueCreate(10, sizeof(unsigned short)); ADC_Cmd(ADC2, ENABLE); // Wait until it stabilizes wait_us(1000); ADC_InitTypeDef ADC_InitStructure; ADC_StructInit(&ADC_InitStructure); ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; ADC_InitStructure.ADC_ScanConvMode = ENABLE; ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None; ADC_InitStructure.ADC_NbrOfChannel = 1; ADC_Init(ADC2, &ADC_InitStructure); ADC_StartCalibration(ADC2); while (ADC_GetCalibrationStatus(ADC2)); ADC_Cmd(ADC2, DISABLE); ADC_ITConfig(ADC2, ADC_IT_EOC, ENABLE); // Enable interrupt UART: NVIC_InitTypeDef NVIC_InitStructure = { .NVIC_IRQChannel = ADC1_2_IRQn, .NVIC_IRQChannelPreemptionPriority = 7, .NVIC_IRQChannelSubPriority = 0, .NVIC_IRQChannelCmd = ENABLE, }; NVIC_Init(&NVIC_InitStructure); ADC_Cmd(ADC2, ENABLE);}void ADC1_2_IRQHandler(void){ signed portBASE_TYPE xHigherPriorityTaskWoken; unsigned short in_buffer = ADC2->DR & 0xfff; xQueueSendToBackFromISR(xADCQueue, &in_buffer, &xHigherPriorityTaskWoken); portEND_SWITCHING_ISR(xHigherPriorityTaskWoken);}unsigned short adc_read(adc_t* adc){ unsigned short in_buffer; xSemaphoreTake(xADCMutex, portMAX_DELAY); // we use the same ADC for all peripherals ADC_RegularChannelConfig(ADC2, adc->ADC_Channel, 1, ADC_SampleTime_239Cycles5); ADC_Cmd(ADC2, ENABLE); xQueueReceive(xADCQueue, &in_buffer, portMAX_DELAY); xSemaphoreGive(xADCMutex); return in_buffer;}
开发者ID:RoseWheel,项目名称:RoseWheel,代码行数:74,
示例3: vStartAltBlockingQueueTasksvoid vStartAltBlockingQueueTasks( unsigned portBASE_TYPE uxPriority ){xBlockingQueueParameters *pxQueueParameters1, *pxQueueParameters2;xBlockingQueueParameters *pxQueueParameters3, *pxQueueParameters4;xBlockingQueueParameters *pxQueueParameters5, *pxQueueParameters6;const unsigned portBASE_TYPE uxQueueSize1 = 1, uxQueueSize5 = 5;const portTickType xBlockTime = ( portTickType ) 1000 / portTICK_RATE_MS;const portTickType xDontBlock = ( portTickType ) 0; /* Create the first two tasks as described at the top of the file. */ /* First create the structure used to pass parameters to the consumer tasks. */ pxQueueParameters1 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); /* Create the queue used by the first two tasks to pass the incrementing number. Pass a pointer to the queue in the parameter structure. */ pxQueueParameters1->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned portSHORT ) ); /* The consumer is created first so gets a block time as described above. */ pxQueueParameters1->xBlockTime = xBlockTime; /* Pass in the variable that this task is going to increment so we can check it is still running. */ pxQueueParameters1->psCheckVariable = &( sBlockingConsumerCount[ 0 ] ); /* Create the structure used to pass parameters to the producer task. */ pxQueueParameters2 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); /* Pass the queue to this task also, using the parameter structure. */ pxQueueParameters2->xQueue = pxQueueParameters1->xQueue; /* The producer is not going to block - as soon as it posts the consumer will wake and remove the item so the producer should always have room to post. */ pxQueueParameters2->xBlockTime = xDontBlock; /* Pass in the variable that this task is going to increment so we can check it is still running. */ pxQueueParameters2->psCheckVariable = &( sBlockingProducerCount[ 0 ] ); /* Note the producer has a lower priority than the consumer when the tasks are spawned. */ xTaskCreate( vBlockingQueueConsumer, ( signed portCHAR * ) "QConsB1", blckqSTACK_SIZE, ( void * ) pxQueueParameters1, uxPriority, NULL ); xTaskCreate( vBlockingQueueProducer, ( signed portCHAR * ) "QProdB2", blckqSTACK_SIZE, ( void * ) pxQueueParameters2, tskIDLE_PRIORITY, NULL ); /* Create the second two tasks as described at the top of the file. This uses the same mechanism but reverses the task priorities. */ pxQueueParameters3 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); pxQueueParameters3->xQueue = xQueueCreate( uxQueueSize1, ( unsigned portBASE_TYPE ) sizeof( unsigned portSHORT ) ); pxQueueParameters3->xBlockTime = xDontBlock; pxQueueParameters3->psCheckVariable = &( sBlockingProducerCount[ 1 ] ); pxQueueParameters4 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); pxQueueParameters4->xQueue = pxQueueParameters3->xQueue; pxQueueParameters4->xBlockTime = xBlockTime; pxQueueParameters4->psCheckVariable = &( sBlockingConsumerCount[ 1 ] ); xTaskCreate( vBlockingQueueConsumer, ( signed portCHAR * ) "QProdB3", blckqSTACK_SIZE, ( void * ) pxQueueParameters3, tskIDLE_PRIORITY, NULL ); xTaskCreate( vBlockingQueueProducer, ( signed portCHAR * ) "QConsB4", blckqSTACK_SIZE, ( void * ) pxQueueParameters4, uxPriority, NULL ); /* Create the last two tasks as described above. The mechanism is again just the same. This time both parameter structures are given a block time. */ pxQueueParameters5 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); pxQueueParameters5->xQueue = xQueueCreate( uxQueueSize5, ( unsigned portBASE_TYPE ) sizeof( unsigned portSHORT ) ); pxQueueParameters5->xBlockTime = xBlockTime; pxQueueParameters5->psCheckVariable = &( sBlockingProducerCount[ 2 ] ); pxQueueParameters6 = ( xBlockingQueueParameters * ) pvPortMalloc( sizeof( xBlockingQueueParameters ) ); pxQueueParameters6->xQueue = pxQueueParameters5->xQueue; pxQueueParameters6->xBlockTime = xBlockTime; pxQueueParameters6->psCheckVariable = &( sBlockingConsumerCount[ 2 ] ); xTaskCreate( vBlockingQueueProducer, ( signed portCHAR * ) "QProdB5", blckqSTACK_SIZE, ( void * ) pxQueueParameters5, tskIDLE_PRIORITY, NULL ); xTaskCreate( vBlockingQueueConsumer, ( signed portCHAR * ) "QConsB6", blckqSTACK_SIZE, ( void * ) pxQueueParameters6, tskIDLE_PRIORITY, NULL );}
开发者ID:InSoonPark,项目名称:FreeRTOS,代码行数:80,
示例4: SerialOpen/*---------------------------------------------------------------------------// Communication port init & open & close/---------------------------------------------------------------------------*/xCOM SerialOpen(xCOM USARTx, u32 BaudRate, portBASE_TYPE uxQueueLength){ GPIO_InitTypeDef GPIO_InitStruct; USART_InitTypeDef USART_InitStruct; NVIC_InitTypeDef NVIC_InitStruct; xCOM xResult = (xCOM)NULL; u8 portNo = USARTx == USART1 ? 0 : 1; // Create Queue if(USARTx == USART1) { if(xUSART1_RxQueue == serINVALID_QUEUE) xUSART1_RxQueue = xQueueCreate(uxQueueLength, (unsigned portBASE_TYPE)sizeof(signed portCHAR)); if(xUSART1_TxQueue == serINVALID_QUEUE) xUSART1_TxQueue = xQueueCreate(uxQueueLength, (unsigned portBASE_TYPE)sizeof(signed portCHAR)); if(xUSART1_RxQueue == serINVALID_QUEUE || xUSART1_TxQueue == serINVALID_QUEUE) return xResult; } else if(USARTx == USART6) { if(xUSART6_RxQueue == serINVALID_QUEUE) xUSART6_RxQueue = xQueueCreate(uxQueueLength, (unsigned portBASE_TYPE)sizeof(signed portCHAR)); if(xUSART6_TxQueue == serINVALID_QUEUE) xUSART6_TxQueue = xQueueCreate(uxQueueLength, (unsigned portBASE_TYPE)sizeof(signed portCHAR)); if(xUSART6_RxQueue == serINVALID_QUEUE || xUSART6_TxQueue == serINVALID_QUEUE) return xResult; } // queue init xQueueInit(USARTx); // Enable USARTx clock if(USARTx == USART1) { RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_USART1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); } else if(USARTx == USART6) { RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART6, ENABLE); GPIO_PinAFConfig(GPIOC, GPIO_PinSource6, GPIO_AF_USART6); GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_USART6); } //Configure USART1 Rx (PA10) as input floating GPIO_InitStruct.GPIO_OType = GPIO_OType_PP; GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStruct.GPIO_Pin = (USARTx == USART1 ? (GPIO_Pin_9 | GPIO_Pin_10) : (GPIO_Pin_6 | GPIO_Pin_7)); GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; GPIO_Init(GPIOA, &GPIO_InitStruct); // USART staus USART_InitStruct.USART_BaudRate = BaudRate; USART_InitStruct.USART_WordLength = USART_WordLength_8b; USART_InitStruct.USART_StopBits = USART_StopBits_1; USART_InitStruct.USART_Parity = USART_Parity_No ; USART_InitStruct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStruct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_Init(USARTx, &USART_InitStruct); // RX Interrupt USART_ITConfig( USARTx, USART_IT_RXNE, ENABLE ); // Interrupt handler NVIC_InitStruct.NVIC_IRQChannel = (USARTx == USART1 ? USART1_IRQn : USART6_IRQn); NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_Init( &NVIC_InitStruct ); // Set communication port USART_Cmd( USARTx, ENABLE ); // Flag gIsComState[portNo] = TRUE; // C++ xQueueReceiveFromISR函数代码示例 C++ xPortRaisePrivilege函数代码示例
|