hi,
i’m trying to receive string from computer then transmit to another device by using freertos. when i start on proteus, i only see one message although i’m sending different things. here is my code and screenshot:
int main()
{
uart_start();
uart_sendstr(uart0, "hello, i'm a transmitter\n\r");
if ( xSerialSemaphore == NULL ) // Check to confirm that the Serial Semaphore has not already been created.
{
xSerialSemaphore = xSemaphoreCreateMutex(); // Create a mutex semaphore we will use to manage the Serial Port
if ( ( xSerialSemaphore ) != NULL )
xSemaphoreGive( ( xSerialSemaphore ) ); // Make the Serial Port available for use, by "Giving" the Semaphore.
}
queue = xQueueCreate(10, sizeof(char));
if (queue == NULL) {
uart_sendstr(uart0, "Queue can not be created");
}
xTaskCreate(
TaskRead
, "Receive" // A name just for humans
, 128 // This stack size can be checked & adjusted by reading the Stack Highwater
, NULL
, 1 // Priority, with 1 being the highest, and 4 being the lowest.
, NULL );
xTaskCreate(
TaskTransmit
, "Transmit"
, 128 // Stack size
, NULL
, 2 // Priority
, NULL );
vTaskStartScheduler();
/* while(1)
{
uart_sendstr(uart0, uart_getstring(uart1, 1));
_delay_ms(100);
}*/
}
void loop()
{
// put your main code here, to run repeatedly:
}
void TaskRead(void *pvParameters)
{
while(1)
{
char* receive;
if ( xSemaphoreTake( xSerialSemaphore, ( TickType_t ) 5 ) == pdTRUE )
{
receive = uart_getstring(uart1, 10);
xQueueSend(queue, &receive, portMAX_DELAY);
xSemaphoreGive( xSerialSemaphore ); // Now free or "Give" the Serial Port for others.
}
vTaskDelay(1);
}
}
void TaskTransmit(void *pvParameters)
{
char* received;
while(1){
if (xSemaphoreTake (xSerialSemaphore, (TickType_t)5) == pdTRUE)
{
if(xQueueReceive(queue, &received, portMAX_DELAY) == pdPASS)
{
uart_sendstr(uart1, received);
}
xSemaphoreGive(xSerialSemaphore);
}
vTaskDelay(1);
}
}