static void run_usart_test(const struct test_case *test)
{
	static uint8_t rx_buffer[RX_BUFFER_SIZE];
	uint32_t received;
	unsigned portBASE_TYPE string_index;

	string_index = 0;

	for (;;) {
		memset(rx_buffer, 0x00, sizeof(rx_buffer));

		received = freertos_usart_serial_read_packet(freertos_usart,
				rx_buffer,
				strlen((const char *) echo_strings[string_index]),
				portMAX_DELAY);

		test_assert_true(test, received ==
				strlen((const char *) echo_strings[string_index]),
				"Test1: received size does not match!");
		test_assert_true(test,
				strcmp((const char *) rx_buffer,
				(const char *) echo_strings[string_index]) == 0,
				"Test2: unexpected string value!");

		/* Expect the next string the next time around. */
		string_index++;
		if (string_index >= (sizeof(echo_strings) / sizeof(uint8_t *))) {
			break;
		}
	}
}
Beispiel #2
0
static void usart_echo_rx_task(void *pvParameters)
{
	freertos_usart_if usart_port;
	static uint8_t rx_buffer[RX_BUFFER_SIZE];
	uint32_t received;
	unsigned portBASE_TYPE string_index;

	/* The (already open) USART port is passed in as the task parameter. */
	usart_port = (freertos_usart_if)pvParameters;

	string_index = 0;

	for (;;) {
		memset(rx_buffer, 0x00, sizeof(rx_buffer));

		received = freertos_usart_serial_read_packet(usart_port, rx_buffer,
				strlen((const char *) echo_strings[string_index]),
				portMAX_DELAY);

		/* Ensure the string received is that expected. */
		configASSERT(received == strlen((const char *) echo_strings[string_index]));
		configASSERT(strcmp((const char *) rx_buffer, (const char *) echo_strings[string_index]) == 0);

		/* Increment a loop counter as an indication that this task is still
		actually receiving strings. */
		rx_task_loops++;

		/* Expect the next string the next time around. */
		string_index++;
		if (string_index >= (sizeof(echo_strings) / sizeof(uint8_t *))) {
			string_index = 0;
		}
	}
}