Esempio n. 1
0
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;
}
Esempio n. 2
0
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);
    }
}
Esempio n. 3
0
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 );
}
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_);
}
Esempio n. 5
0
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); 
  }
}
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;
		}
	}
}
Esempio n. 7
0
File: i2c.c Progetto: cocobot/mcual
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;
}
Esempio n. 8
0
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 );
}
Esempio n. 9
0
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");
        }
    }
}
Esempio n. 10
0
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 );
	}
}
Esempio n. 11
0
static void wait_for_ip()
{
    uint32_t bits = IPV4_GOTIP_BIT | IPV6_GOTIP_BIT ;

    ESP_LOGI(TAG, "Waiting for AP connection...");
    xEventGroupWaitBits(wifi_event_group, bits, false, true, portMAX_DELAY);
    ESP_LOGI(TAG, "Connected to AP");
}
/**
 * \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);
	}
}
Esempio n. 13
0
/*FUNCTION**********************************************************************
 *
 * Function Name : OSA_EventWait
 * Description   : This function checks the event's status, if it meets the wait
 * condition, return osaStatus_Success, otherwise, timeout will be used for
 * wait. The parameter timeout indicates how long should wait in milliseconds.
 * Pass osaWaitForever_c to wait indefinitely, pass 0 will return the value
 * osaStatus_Timeout immediately if wait condition is not met. The event flags
 * will be cleared if the event is auto clear mode. Flags that wakeup waiting
 * task could be obtained from the parameter setFlags.
 * This function returns osaStatus_Success if wait condition is met, returns
 * osaStatus_Timeout if wait condition is not met within the specified
 * 'timeout', returns osaStatus_Error if any errors occur during waiting.
 *
 *END**************************************************************************/
osaStatus_t OSA_EventWait(osaEventId_t eventId, osaEventFlags_t flagsToWait, bool_t waitAll, uint32_t millisec, osaEventFlags_t *pSetFlags)
{
#if osNumberOfEvents  
  osEventStruct_t* pEventStruct; 
  BaseType_t clearMode;
  uint32_t timeoutTicks;
  event_flags_t flagsSave;
  if(osObjectIsAllocated(&osEventInfo, eventId) == FALSE)
  {
    return osaStatus_Error;
  }
  
  /* Clean FreeRTOS cotrol flags */
  flagsToWait = flagsToWait & 0x00FFFFFF;
  
  pEventStruct = (osEventStruct_t*)eventId;  
  if(pEventStruct->event.eventHandler == NULL)
  {
    return osaStatus_Error;
  }
  
  /* Convert timeout from millisecond to tick. */
  if (millisec == osaWaitForever_c)
  {
    timeoutTicks = portMAX_DELAY;
  }
  else
  {
    timeoutTicks = millisec/portTICK_PERIOD_MS;
  }
  
  clearMode = (pEventStruct->event.autoClear) ? pdTRUE: pdFALSE;
  
  flagsSave = xEventGroupWaitBits(pEventStruct->event.eventHandler,(event_flags_t)flagsToWait,clearMode,(BaseType_t)waitAll,timeoutTicks);
  
  flagsSave &= (event_flags_t)flagsToWait;
  if(pSetFlags)
  {
    *pSetFlags = (osaEventFlags_t)flagsSave;
  }
  
  if (flagsSave)
  {
    return osaStatus_Success;
  }
  else
  {
    return osaStatus_Timeout;
  }
#else
  (void)eventId;
  (void)flagsToWait;  
  (void)waitAll;  
  (void)millisec;  
  (void)pSetFlags;  
  return osaStatus_Error;
#endif  
}
Esempio n. 14
0
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;
}
Esempio n. 15
0
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));
	}


}
Esempio n. 16
0
int WiFiGenericClass::waitStatusBits(int bits, uint32_t timeout_ms){
    if(!_network_event_group){
        return 0;
    }
    return xEventGroupWaitBits(
        _network_event_group,    // The event group being tested.
        bits,  // The bits within the event group to wait for.
        pdFALSE,         // BIT_0 and BIT_4 should be cleared before returning.
        pdTRUE,        // Don't wait for both bits, either bit will do.
        timeout_ms / portTICK_PERIOD_MS ) & bits; // Wait a maximum of 100ms for either bit to be set.
}
/**
 * \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);
			}
		}
	}
}
Esempio n. 18
0
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. */
    }
}
Esempio n. 19
0
int meca_fish_is_catch(void)
{
  xEventGroupClearBits(busy, 0xFF);

  next_state = MECA_FISH_CHECK;

  xEventGroupWaitBits(busy, 0xFF, pdFALSE, pdFALSE, portMAX_DELAY); 

#ifdef AUSBEE_SIM
  return ((rand() % 3) == 0);
#else
  return ir_value > 300;
#endif
}
Esempio n. 20
0
static portTASK_FUNCTION( vnRFTask, pvParameters )
{
TickType_t xRate, xLastTime;
BaseType_t	Event_Status = 0;

	/* The parameters are not used. */
	( void ) pvParameters;

	nRF_SPI_IO_Init();
	xRate = 10;

	/* We need to initialise xLastFlashTime prior to the first call to 
	vTaskDelayUntil(). */
	xLastTime = xTaskGetTickCount();

	for(;;)
	{
		if (xEventGruop == NULL)
		{
			xEventGruop = xEventGroupCreate();
			continue;
		}

		Event_Status = xEventGroupWaitBits(xEventGruop, Key_State_Down, pdTRUE, pdFALSE, (TickType_t)1000);
		if (Event_Status & Key_State_Down)
		{
			nRF_Buf.datatype = DataType_Key;
			nRF_Buf.data[0] = Get_Key_Status();
		}

		if (Event_Status&Key_State_Down)
		{
			if (nRF_Start_Tx() == nRF_TX_OK)
			{
				BSP_LED_Toggle(LED2);
				if (nRF_Start_Rx() == nRF_RX_OK)
				{
					BSP_LED_Toggle(LED3);
				}
			}
			Event_Status = 0;
		}
		
		memset(&nRF_Buf, 0, sizeof(nRF_Tx_DataType));
		//vTaskDelayUntil( &xLastTime, xRate );
	}
} /*lint !e715 !e818 !e830 Function definition must be standard for task creation. */
Esempio n. 21
0
void smartconfig_example_task(void * parm)
{
    EventBits_t uxBits;
    ESP_ERROR_CHECK( esp_smartconfig_set_type(SC_TYPE_ESPTOUCH) );
    ESP_ERROR_CHECK( esp_smartconfig_start(sc_callback) );
    while (1) {
        uxBits = xEventGroupWaitBits(wifi_event_group, CONNECTED_BIT | ESPTOUCH_DONE_BIT, true, false, portMAX_DELAY); 
        if(uxBits & CONNECTED_BIT) {
            ESP_LOGI(TAG, "WiFi Connected to ap");
        }
        if(uxBits & ESPTOUCH_DONE_BIT) {
            ESP_LOGI(TAG, "smartconfig over");
            esp_smartconfig_stop();
            vTaskDelete(NULL);
        }
    }
}
void dispatch_queue::dispatch_thread_handler(void)
{
	BaseType_t status = xSemaphoreTakeRecursive(mutex_, portMAX_DELAY);
	assert(status == pdTRUE && "Failed to lock mutex!");

	do {
		//after wait, we own the lock
		if(!quit_ && q_.size())
		{
			auto op = std::move(q_.front());
			q_.pop();

			//unlock now that we're done messing with the queue
			status = xSemaphoreGiveRecursive(mutex_);
			assert(status == pdTRUE && "Failed to unlock mutex!");

			op();

			status = xSemaphoreTakeRecursive(mutex_, portMAX_DELAY);
			assert(status == pdTRUE && "Failed to lock mutex!");
		}
		else if(!quit_)
		{
			status = xSemaphoreGiveRecursive(mutex_);
			assert(status == pdTRUE && "Failed to unlock mutex!");

			// Wait for new work - clear flags on exit
			xEventGroupWaitBits(notify_flags_, DISPATCH_WAKE_EVT, pdTRUE, pdFALSE, portMAX_DELAY);

			status = xSemaphoreTakeRecursive(mutex_, portMAX_DELAY);
			assert(status == pdTRUE && "Failed to lock mutex!");
		}
	} while (!quit_);

	// We were holding the mutex after we woke up
	status = xSemaphoreGiveRecursive(mutex_);
	assert(status == pdTRUE && "Failed to unlock mutex!");

	// Set a signal to indicate a thread exited
	status = xEventGroupSetBits(notify_flags_, DISPATCH_EXIT_EVT);
	assert(status == pdTRUE && "Failed to set event flags!");

	// Delete the current thread
	vTaskDelete(NULL);
}
Esempio n. 23
0
static void prvCDCSend( const char *pcData, size_t xDataLength )
{
    const TickType_t xTransferCompleteDelay = pdMS_TO_TICKS( 500UL );

    ( void ) pcData;
    ( void ) xDataLength;

    if( xDataLength > 0 ) {
        if( CDCDSerialDriver_Write( ( void * ) pcData, xDataLength, ( TransferCallback ) prvCDCDataTransmittedCallback, 0 ) == USBD_STATUS_SUCCESS ) {
            /* Wait for the transfer to complete. */
            xEventGroupWaitBits(	xCDCEventBits,
                                    cmdTX_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. */
        }
    }
}
Esempio n. 24
0
void main_loop(void* arg)
{
    (void)arg;

    // timeout of 500ms
    const TickType_t xTicksToWait = 500 / portTICK_PERIOD_MS;
    while(1) {

        EventBits_t uxBits = xEventGroupWaitBits(g_pot_event_group, (POT_PORT1_BIT | POT_PORT2_BIT), pdTRUE, pdFALSE, xTicksToWait);
//        xEventGroupClearBits(g_pot_event_group, (POT_PORT1_BIT | POT_PORT2_BIT));

        // if not timeout, change the state
        if (uxBits != 0) {

//            gpio_set_level(GPIO_NUM_5, 0);

//            gpio_set_level(GPIO_NUM_21, 1);
//            ets_delay_us(50);
            gpio_set_level(GPIO_NUM_21, 0);

            ets_delay_us(223);
            ets_delay_us(g_joy_state.joy1_potx);

            gpio_set_level(GPIO_NUM_21, 1);
//            gpio_set_level(GPIO_NUM_5, 1);

//            ets_delay_us(50);

//            gpio_set_level(GPIO_NUM_21, 0);

//            gpio_set_level(GPIO_NUM_5, 0);


//            const TickType_t xDelay = 100 / portTICK_PERIOD_MS;
//            vTaskDelay(xDelay);
        } else {
            // timeout
            gpio_set_level(GPIO_NUM_21, 0);
        }

//        taskYIELD();
    }
}
Esempio n. 25
0
void meca_fish_walk(int wait)
{
  if(wait)
  {
    xEventGroupClearBits(busy, 0xFF);
  }

  if(current_state == MECA_FISH_WALK)
  {
    wait = 0;
  }

  next_state = MECA_FISH_WALK;

  if(wait)
  {
    xEventGroupWaitBits(busy, 0xFF, pdFALSE, pdFALSE, portMAX_DELAY); 
  }
}
Esempio n. 26
0
int flag_event_wait(flag_event_t *event){
#if defined(OS_FREERTOS)
	EventBits_t uxBits;
	uxBits = xEventGroupWaitBits(*event,
			((uint32_t)1) << 0,
			pdTRUE,
			pdFALSE,
			portMAX_DELAY);
	if(uxBits & (((uint32_t)1) << 0))
		return 1;
	return 0;
#elif defined(OS_UCOS)
	OS_ERR err;
	OS_FLAGS flags;
	flags = OSFlagPend(event, 1, 0, OS_OPT_PEND_FLAG_SET_ANY, 0, &err);
	if((err == OS_ERR_NONE) && (flags & ((OS_FLAGS)1) == 1)) return 1;
	return 0;
#endif
}
Esempio n. 27
0
void meca_fish_prepare(int wait)
{
  if(wait)
  {
    xEventGroupClearBits(busy, 0xFF);
  }

  if(current_state == MECA_FISH_PREPARE)
  {
    wait = 0;
  }

  next_state = MECA_FISH_PREPARE;

  if(wait)
  {
    xEventGroupWaitBits(busy, 0xFF, pdFALSE, pdFALSE, portMAX_DELAY); 
  }
}
Esempio n. 28
0
void meca_fish_swim_right(int wait)
{
  if(wait)
  {
    xEventGroupClearBits(busy, 0xFF);
  }

  if(current_state == MECA_FISH_SWIM_RIGHT)
  {
    wait = 0;
  }

  next_state = MECA_FISH_SWIM_RIGHT;

  if(wait)
  {
    xEventGroupWaitBits(busy, 0xFF, pdFALSE, pdFALSE, portMAX_DELAY); 
  }
}
Esempio n. 29
0
/**
  * @brief 软件触发中断,进入中断发送数据
  * @param  None
  * retval   None
  */
uint8_t nRF_Start_Tx(void)
{
	BaseType_t uxBits;
	const TickType_t xTicksToWait = 5;		// Time Out 3ms
	uint8_t RetValue = 0;
	
	// Entry TX Mode to Send Data
	nRF_TX_Mode();
	
	/*!< Select the nRF: Chip Select low */
	nRF_CSN_LOW();
	
	nRF_SPI_IO_WriteReg(nRF_FLUSH_TX, 0x00);

	nRF_SPI_IO_WriteData(nRF_WR_TX_PLOAD, (uint8_t *)&nRF_Buf, nRF_TX_PLOAD_WIDTH);
	
	/*!< Deselect the nRF: Start Send */
	nRF_CSN_HIGH();

	uxBits = xEventGroupWaitBits(xEventGruop, nRF_State_TX_OK|nRF_State_TX_MAX, pdTRUE, pdFALSE, xTicksToWait);
	if (uxBits & nRF_State_TX_OK)
	{
		nRF_RX_Mode();
		RetValue = nRF_TX_OK;
	}
	else if ( uxBits & nRF_State_TX_MAX)
	{
		nRF_CSN_LOW();
		nRF_SPI_IO_WriteReg(nRF_FLUSH_TX, 0xFF);
		nRF_CSN_HIGH();
		RetValue = nRF_MAX_TX;
	}
	else
	{
		nRF_CSN_LOW();
		nRF_SPI_IO_WriteReg(nRF_FLUSH_TX, 0xFF);
		nRF_CSN_HIGH();
		RetValue = nRF_TIMEOUT;
	}
	
	return RetValue;
}
Esempio n. 30
0
/// Wait for one or more Signal Flags to become signaled for the current \b RUNNING thread.
/// \param[in]     signals       wait until all specified signal flags set or 0 for any single signal flag.
/// \param[in]     millisec      timeout value or 0 in case of no time-out.
/// \return event flag information or error code.
/// \note MUST REMAIN UNCHANGED: \b osSignalWait shall be consistent in every CMSIS-RTOS.
osEvent osSignalWait (int32_t signals, uint32_t millisec)
{
    TaskHandle_t thread_id;
    EventGroupHandle_t event_handle;
    EventBits_t uxBits=0x80000000;
    osEvent   ret;
    uint32_t wait_ticks;

    if (signals & (0xFFFFFFFF << osFeature_Signals)) {
        ret.status = osErrorValue;
        ret.value.signals = 0;
        return ret;
    }
    
    thread_id = xTaskGetCurrentTaskHandle();
    event_handle = find_signal_by_thread(thread_id);
    if (event_handle) {
        if (signals == 0) {
            // if signals is 0, then wait any signal
            signals = (1 << osFeature_Signals) - 1;
        }

        wait_ticks = millisec_to_ticks(millisec);
        uxBits = xEventGroupWaitBits(
                        event_handle,   /* The event group being tested. */
                        signals, /* The bits within the event group to wait for. */
                        pdTRUE,        /* the signals should be cleared before returning. */
                        pdFALSE,       /* Don't wait for both bits, either bit will do. */
                        wait_ticks );/* Wait for either bit to be set. */
        if (uxBits == 0) {
            ret.status = millisec ? osEventTimeout : osOK;
            ret.value.signals = 0;
        }
        else {
            ret.status = osEventSignal;
            ret.value.signals = uxBits;
        }
    }
    
    return ret;
}