本文整理汇总了C++中xEventGroupWaitBits函数的典型用法代码示例。如果您正苦于以下问题:C++ xEventGroupWaitBits函数的具体用法?C++ xEventGroupWaitBits怎么用?C++ xEventGroupWaitBits使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xEventGroupWaitBits函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: wifi_cmd_sta_join
static bool wifi_cmd_sta_join(const char* ssid, const char* pass)
{
int bits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 0);
wifi_config_t wifi_config = { 0 };
strlcpy((char*) wifi_config.sta.ssid, ssid, sizeof(wifi_config.sta.ssid));
if (pass) {
strncpy((char*) wifi_config.sta.password, pass, sizeof(wifi_config.sta.password));
}
if (bits & CONNECTED_BIT) {
reconnect = false;
xEventGroupClearBits(wifi_event_group, CONNECTED_BIT);
ESP_ERROR_CHECK( esp_wifi_disconnect() );
xEventGroupWaitBits(wifi_event_group, DISCONNECTED_BIT, 0, 1, portTICK_RATE_MS);
}
reconnect = true;
ESP_ERROR_CHECK( esp_wifi_set_mode(WIFI_MODE_STA) );
ESP_ERROR_CHECK( esp_wifi_set_config(ESP_IF_WIFI_STA, &wifi_config) );
ESP_ERROR_CHECK( esp_wifi_connect() );
xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT, 0, 1, 5000/portTICK_RATE_MS);
return true;
}
示例2: event_group_wait_bits_wrapper
static uint32_t IRAM_ATTR event_group_wait_bits_wrapper(void *event, uint32_t bits_to_wait_for, int clear_on_exit, int wait_for_all_bits, uint32_t block_time_tick)
{
if (block_time_tick == OSI_FUNCS_TIME_BLOCKING) {
return (uint32_t)xEventGroupWaitBits(event, bits_to_wait_for, clear_on_exit, wait_for_all_bits, portMAX_DELAY);
} else {
return (uint32_t)xEventGroupWaitBits(event, bits_to_wait_for, clear_on_exit, wait_for_all_bits, block_time_tick);
}
}
示例3: prvTestAbortingEventGroupWait
static void prvTestAbortingEventGroupWait( void )
{
TickType_t xTimeAtStart;
EventGroupHandle_t xEventGroup;
EventBits_t xBitsToWaitFor = ( EventBits_t ) 0x01, xReturn;
#if( configSUPPORT_STATIC_ALLOCATION == 1 )
{
static StaticEventGroup_t xEventGroupBuffer;
/* Create the event group. Statically allocated memory is used so the
creation cannot fail. */
xEventGroup = xEventGroupCreateStatic( &xEventGroupBuffer );
}
#else
{
xEventGroup = xEventGroupCreate();
configASSERT( xEventGroup );
}
#endif
/* Note the time before the delay so the length of the delay is known. */
xTimeAtStart = xTaskGetTickCount();
/* This first delay should just time out. */
xReturn = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdTRUE, xMaxBlockTime );
if( xReturn != 0x00 )
{
xErrorOccurred = pdTRUE;
}
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
/* Note the time before the delay so the length of the delay is known. */
xTimeAtStart = xTaskGetTickCount();
/* This second delay should be aborted by the primary task half way
through. */
xReturn = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdTRUE, xMaxBlockTime );
if( xReturn != 0x00 )
{
xErrorOccurred = pdTRUE;
}
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xHalfMaxBlockTime );
/* Note the time before the delay so the length of the delay is known. */
xTimeAtStart = xTaskGetTickCount();
/* This third delay should just time out again. */
xReturn = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdTRUE, xMaxBlockTime );
if( xReturn != 0x00 )
{
xErrorOccurred = pdTRUE;
}
prvCheckExpectedTimeIsWithinAnAcceptableMargin( xTimeAtStart, xMaxBlockTime );
/* Not really necessary in this case, but for completeness. */
vEventGroupDelete( xEventGroup );
}
示例4: xEventGroupSetBits
dispatch_queue::~dispatch_queue()
{
BaseType_t status;
// Signal to dispatch threads that it's time to wrap up
quit_ = true;
// We will join each thread to confirm exiting
for (size_t i = 0; i < threads_.size(); ++i) {
eTaskState state;
do {
// Signal wake - check exit flag
xEventGroupSetBits(notify_flags_, DISPATCH_WAKE_EVT);
// Wait until a thread signals exit. Timeout is acceptable.
xEventGroupWaitBits(notify_flags_, DISPATCH_EXIT_EVT, pdTRUE, pdFALSE, 10);
// If it was not thread_[i], that is ok, but we will loop around
// until threads_[i] has exited
state = eTaskGetState(threads_[i].thread);
} while (state != eDeleted);
threads_[i].name.clear();
}
// Cleanup event flags and mutex
vEventGroupDelete(notify_flags_);
vSemaphoreDelete(mutex_);
}
示例5: meca_fish_sweep_right
void meca_fish_sweep_right(int wait, int high)
{
meca_fish_state_t st = MECA_FISH_SWEEP_RIGHT;
if(high)
{
st = MECA_FISH_SWEEP_HIGH_RIGHT;
}
if(wait)
{
xEventGroupClearBits(busy, 0xFF);
}
if(current_state == st)
{
wait = 0;
}
next_state = st;
if(wait)
{
xEventGroupWaitBits(busy, 0xFF, pdFALSE, pdFALSE, portMAX_DELAY);
}
}
示例6: prvSelectiveBitsTestSlaveFunction
static void prvSelectiveBitsTestSlaveFunction( void )
{
EventBits_t uxPendBits, uxReturned;
/* Used in a test that blocks two tasks on various different bits within an
event group - then sets each bit in turn and checks that the correct tasks
unblock at the correct times.
This function is called by two different tasks - each of which will use a
different bit. Check the task handle to see which task the function was
called by. */
if( xTaskGetCurrentTaskHandle() == xSyncTask1 )
{
uxPendBits = ebSELECTIVE_BITS_1;
}
else
{
uxPendBits = ebSELECTIVE_BITS_2;
}
for( ;; )
{
/* Wait until it is time to perform the next cycle of the test. The
task is unsuspended by the tests implemented in the
prvSelectiveBitsTestMasterFunction() function. */
vTaskSuspend( NULL );
uxReturned = xEventGroupWaitBits( xEventGroup, uxPendBits, pdTRUE, pdFALSE, portMAX_DELAY );
if( uxReturned == ( EventBits_t ) 0 )
{
break;
}
}
}
示例7: mcual_i2c_transmit
mcual_i2c_status_t mcual_i2c_transmit(mcual_i2c_id_t id, uint8_t addr, uint8_t * txbuf, uint8_t tx_size, uint8_t * rxbuf, uint8_t rx_size)
{
(void)rxbuf;
(void)rx_size;
I2C_TypeDef * reg = mcual_i2c_get_register(id);
int i;
addr <<= 1;
xEventGroupClearBits(transfer_done[id], 0xFF);
xQueueReset(tx_queues[id]);
xQueueSend(tx_queues[id], &addr, portMAX_DELAY);
for(i = 0; i < tx_size; i += 1)
{
xQueueSend(tx_queues[id], txbuf + i, portMAX_DELAY);
}
reg->CR2 |= I2C_CR2_ITEVTEN | I2C_CR2_ITERREN;
reg->CR1 = I2C_CR1_START | I2C_CR1_PE;
EventBits_t result = xEventGroupWaitBits(transfer_done[id], 0xFF, pdFALSE, pdFALSE, 1000 / portTICK_PERIOD_MS);
I2C1->CR1 = I2C_CR1_STOP;
if(result & (1 << MCUAL_I2C_SUCCESS))
{
return MCUAL_I2C_SUCCESS;
}
return MCUAL_I2C_FAIL;
}
示例8: prvExerciseEventGroupAPI
static void prvExerciseEventGroupAPI( void )
{
EventGroupHandle_t xEventGroup;
EventBits_t xBits;
const EventBits_t xBitsToWaitFor = ( EventBits_t ) 0xff, xBitToClear = ( EventBits_t ) 0x01;
/* Exercise some event group functions. */
xEventGroup = xEventGroupCreate();
configASSERT( xEventGroup );
/* No bits should be set. */
xBits = xEventGroupWaitBits( xEventGroup, xBitsToWaitFor, pdTRUE, pdFALSE, mainDONT_BLOCK );
configASSERT( xBits == ( EventBits_t ) 0 );
/* Set bits and read back to ensure the bits were set. */
xEventGroupSetBits( xEventGroup, xBitsToWaitFor );
xBits = xEventGroupGetBits( xEventGroup );
configASSERT( xBits == xBitsToWaitFor );
/* Clear a bit and read back again using a different API function. */
xEventGroupClearBits( xEventGroup, xBitToClear );
xBits = xEventGroupSync( xEventGroup, 0x00, xBitsToWaitFor, mainDONT_BLOCK );
configASSERT( xBits == ( xBitsToWaitFor & ~xBitToClear ) );
/* Finished with the event group. */
vEventGroupDelete( xEventGroup );
}
示例9: uart2_unpack_task
static void uart2_unpack_task(void *pvParameters)
{
int rLen = 0;
DmaUartProtocolPacket rxPacket;
EventBits_t uxBits;
const TickType_t xTicksToWait = 100 / portTICK_PERIOD_MS;
/* Just to stop compiler warnings. */
( void ) pvParameters;
udprintf("\r\n[TEST] uart2_unpack_task running...");
for (;;)
{
rLen = 0;
uxBits = xEventGroupWaitBits(
xUart2RxEventGroup, // The event group being tested.
UART_DMA_RX_COMPLETE_EVENT_BIT \
| UART_DMA_RX_INCOMPLETE_EVENT_BIT, // The bits within the event group to wait for.
pdTRUE, // BIT_COMPLETE and BIT_TIMEOUT should be cleared before returning.
pdFALSE, // Don't wait for both bits, either bit will do.
xTicksToWait ); // Wait a maximum of 100ms for either bit to be set.
memset(&rxPacket, 0x00, sizeof(DmaUartProtocolPacket));
if( ( uxBits & UART_DMA_RX_COMPLETE_EVENT_BIT ) != 0 )
{
rLen = Uart2Read((char *)&rxPacket, sizeof(DmaUartProtocolPacket));
if (rLen > 0)
{
test_uart2_rx_count += rLen;
}
TEST_UART2_INFO("Uart2Read COMPLETE rLen=%d",rLen);
}
else if( ( uxBits & UART_DMA_RX_INCOMPLETE_EVENT_BIT ) != 0 )
{
rLen = Uart2Read((char *)&rxPacket, sizeof(DmaUartProtocolPacket));
if (rLen > 0)
{
test_uart2_rx_count += rLen;
}
TEST_UART2_INFO("Uart2Read INCOMPLETE rLen=%d",rLen);
}
else
{
}
if (rLen <= 0) continue;
if ((DMA_UART_START_HEADER_TAG == rxPacket.StartHeader ) \
&& (DMA_UART_END_HEADER_TAG == rxPacket.EndHeader) \
&& (DMA_UART_PACKET_PARITY_OK == rxPacket.ParityTag))
{
TEST_UART2_INFO("PKT_ID=0X%02X, Data=%s",rxPacket.ID ,rxPacket.Data);
}
else
{
TEST_UART2_INFO("PKT ERROR");
}
}
}
示例10: prvSyncTask
static void prvSyncTask( void *pvParameters )
{
EventBits_t uxSynchronisationBit, uxReturned;
/* A few tests that check the behaviour when two tasks are blocked on
various different bits within an event group are performed before this task
enters its infinite loop to carry out its main demo function. */
prvSelectiveBitsTestSlaveFunction();
/* The bit to use to indicate this task is at the synchronisation point is
passed in as the task parameter. */
uxSynchronisationBit = ( EventBits_t ) pvParameters;
for( ;; )
{
/* Now this task takes part in a task synchronisation - sometimes known
as a 'rendezvous'. Its execution pattern is controlled by the 'test
master' task, which is responsible for taking this task out of the
Suspended state when it is time to test the synchronisation behaviour.
See: http://www.freertos.org/xEventGroupSync.html. */
vTaskSuspend( NULL );
/* Set the bit that indicates this task is at the synchronisation
point. The first time this is done the 'test master' task has a lower
priority than this task so this task will get to the sync point before
the set bits task. */
uxReturned = xEventGroupSync( xEventGroup, /* The event group used for the synchronisation. */
uxSynchronisationBit, /* The bit to set in the event group to indicate this task is at the sync point. */
ebALL_SYNC_BITS,/* The bits to wait for - these bits are set by the other tasks taking part in the sync. */
portMAX_DELAY );/* The maximum time to wait for the sync condition to be met before giving up. */
/* A max delay was used, so this task should only exit the above
function call when the sync condition is met. Check this is the
case. */
configASSERT( ( uxReturned & ebALL_SYNC_BITS ) == ebALL_SYNC_BITS );
/* Remove compiler warning if configASSERT() is not defined. */
( void ) uxReturned;
/* Wait until the 'test master' task unsuspends this task again. */
vTaskSuspend( NULL );
/* Set the bit that indicates this task is at the synchronisation
point again. This time the 'test master' task has a higher priority
than this task so will get to the sync point before this task. */
uxReturned = xEventGroupSync( xEventGroup, uxSynchronisationBit, ebALL_SYNC_BITS, portMAX_DELAY );
/* Again a max delay was used, so this task should only exit the above
function call when the sync condition is met. Check this is the
case. */
configASSERT( ( uxReturned & ebALL_SYNC_BITS ) == ebALL_SYNC_BITS );
/* Block on the event group again. This time the event group is going
to be deleted while this task is blocked on it so it is expected that 0
be returned. */
uxReturned = xEventGroupWaitBits( xEventGroup, ebALL_SYNC_BITS, pdFALSE, pdTRUE, portMAX_DELAY );
configASSERT( uxReturned == 0 );
}
}
示例11: graph_task
/**
* \brief Graph task
*
* This task runs in the background to draw a pseudo-random graph to a dedicated
* display buffer. If the user selects a different screen than the graph, it
* will continue to update even though it is not visible until the graph screen
* is selected again.
*
* \param params Parameters for the task. (Not used.)
*/
static void graph_task(void *params)
{
gfx_coord_t x, y, old_y;
uint8_t current_value;
EventBits_t event_bits;
const TickType_t ticks_to_wait = 10 / portTICK_PERIOD_MS;
x = 0;
current_value = graph_noise;
for(;;) {
/* Wait a maximum of 10ms for either bit 0 or bit 1 to be set within
the event group. Not clear the bits before exiting. */
event_bits = xEventGroupWaitBits(
event_group, /* The event group being tested. */
EVENT_DISPLAY_INIT | EVENT_DISPLAY_GRAPH, /* The bits within the event group to wait for. */
pdFALSE, /* Bit should not be cleared before returning. */
pdFALSE, /* Don't wait for both bits, either bit will do. */
ticks_to_wait);/* Wait a maximum of 10ms for either bit to be set. */
if((event_bits & EVENT_DISPLAY_INIT) ||
(event_bits & EVENT_DISPLAY_GRAPH)) {
oled1_set_led_state(&oled1, OLED1_LED1_ID, true);
// Compute new noise sample and value of current graph sample
graph_noise = (graph_noise * 173) + 1;
current_value = ((uint16_t)graph_noise + current_value) / 2;
xSemaphoreTake(display_mutex, portMAX_DELAY);
// Scale graph value so it fits within the canvas
y = CANVAS_GRAPH_Y_OFFSET
+ ((uint16_t)CANVAS_HEIGHT * current_value) / 256;
// Clear previous graph point..
gfx_mono_draw_vertical_line(x, CANVAS_GRAPH_Y_OFFSET, CANVAS_HEIGHT,
GFX_PIXEL_CLR);
// ..and draw a continuous graph using lines
if (x == 0) {
gfx_mono_draw_pixel(x, y, GFX_PIXEL_SET);
} else {
gfx_mono_draw_line(x - 1, old_y, x, y, GFX_PIXEL_SET);
}
xSemaphoreGive(display_mutex);
old_y = y;
if (++x >= CANVAS_WIDTH) {
x = 0;
}
oled1_set_led_state(&oled1, OLED1_LED1_ID, false);
}
vTaskDelay(GRAPH_TASK_DELAY);
}
}
示例12: MPU_xEventGroupWaitBits
EventBits_t MPU_xEventGroupWaitBits( EventGroupHandle_t xEventGroup, const EventBits_t uxBitsToWaitFor, const BaseType_t xClearOnExit, const BaseType_t xWaitForAllBits, TickType_t xTicksToWait )
{
EventBits_t xReturn;
BaseType_t xRunningPrivileged = xPortRaisePrivilege();
xReturn = xEventGroupWaitBits( xEventGroup, uxBitsToWaitFor, xClearOnExit, xWaitForAllBits, xTicksToWait );
vPortResetPrivilege( xRunningPrivileged );
return xReturn;
}
示例13: scan_task
static void scan_task(void *pvParameters)
{
while(1) {
xEventGroupWaitBits(wifi_event_group, SCAN_DONE_BIT, false, true, portMAX_DELAY);
ESP_LOGI(TAG, "WIFI scan doen");
xEventGroupClearBits(wifi_event_group, SCAN_DONE_BIT);
uint16_t apCount = 0;
esp_wifi_scan_get_ap_num(&apCount);
printf("Number of access points found: %d\n", apCount);
if (apCount == 0) {
ESP_LOGI(TAG, "Nothing AP found");
return;
}
wifi_ap_record_t *list = (wifi_ap_record_t *)malloc(sizeof(wifi_ap_record_t) * apCount);
ESP_ERROR_CHECK(esp_wifi_scan_get_ap_records(&apCount, list));
int i;
printf("======================================================================\n");
printf(" SSID | RSSI | AUTH \n");
printf("======================================================================\n");
for (i=0; i<apCount; i++) {
char *authmode;
switch(list[i].authmode) {
case WIFI_AUTH_OPEN:
authmode = "WIFI_AUTH_OPEN";
break;
case WIFI_AUTH_WEP:
authmode = "WIFI_AUTH_WEP";
break;
case WIFI_AUTH_WPA_PSK:
authmode = "WIFI_AUTH_WPA_PSK";
break;
case WIFI_AUTH_WPA2_PSK:
authmode = "WIFI_AUTH_WPA2_PSK";
break;
case WIFI_AUTH_WPA_WPA2_PSK:
authmode = "WIFI_AUTH_WPA_WPA2_PSK";
break;
default:
authmode = "Unknown";
break;
}
printf("%26.26s | % 4d | %22.22s\n",list[i].ssid, list[i].rssi, authmode);
}
free(list);
printf("\n\n");
// scan again
vTaskDelay(2000 / portTICK_PERIOD_MS);
//The true parameter cause the function to block until the scan is done.
ESP_ERROR_CHECK(esp_wifi_scan_start(&scanConf, true));
}
}
示例14: about_task
/**
* \brief About task
*
* This task prints a short text about the demo, with a simple zooming
* animation.
*
* \param params Parameters for the task. (Not used.)
*/
static void about_task(void *params)
{
char c;
gfx_coord_t x, y;
uint8_t i, shift;
EventBits_t event_bits;
const TickType_t ticks_to_wait = 10 / portTICK_PERIOD_MS;
const uint8_t max_shift = 8;
shift = 1;
for (;;) {
/* Wait a maximum of 10ms for either bit 3 to be set within
the event group. Not clear the bits before exiting. */
event_bits = xEventGroupWaitBits(
event_group, /* The event group being tested. */
EVENT_DISPLAY_ABOUT, /* The bits within the event group to wait for. */
pdFALSE, /* Bit should not be cleared before returning. */
pdFALSE, /* Don't wait for both bits, either bit will do. */
ticks_to_wait);/* Wait a maximum of 10ms for either bit to be set. */
if(event_bits & EVENT_DISPLAY_ABOUT) {
oled1_set_led_state(&oled1, OLED1_LED2_ID, true);
xSemaphoreTake(display_mutex, portMAX_DELAY);
// Print the about text in an expanding area
for (i = 0; i < (sizeof(about_text) - 1); i++) {
c = about_text[i];
x = (((i % TERMINAL_COLUMNS) * SYSFONT_WIDTH) * shift
+ (CANVAS_WIDTH / 2) * (max_shift - shift))
/ max_shift;
y = (((i / TERMINAL_COLUMNS) * SYSFONT_HEIGHT) * shift
+ (CANVAS_HEIGHT / 2) * (max_shift - shift))
/ max_shift;
gfx_mono_draw_char(c, x, y, &sysfont);
}
xSemaphoreGive(display_mutex);
oled1_set_led_state(&oled1, OLED1_LED2_ID, false);
// Repeat task until we're displaying the text in full size
if (shift < max_shift) {
shift++;
vTaskDelay(ABOUT_TASK_DELAY);
} else {
shift = 0;
xEventGroupClearBits(event_group, EVENT_DISPLAY_ABOUT);
}
}
}
}
示例15: prvCDCGetChar
static void prvCDCGetChar( void )
{
const TickType_t xTransferCompleteDelay = pdMS_TO_TICKS( 750UL );
if( ulBytesAvailable == 0 ) {
/* Wait for a transfer to complete. */
xEventGroupWaitBits( xCDCEventBits,
cmdRX_COMPLETE_BIT, /* The bit to wait for. */
pdTRUE, /* Clear the bit before exiting the function. */
pdFALSE, /* Only need to wait for one bit anyway. */
xTransferCompleteDelay ); /* The maximum time to wait for the event. */
}
}