/* The example of esp-free-rtos
*
* This sample code is in the public domain.
*/
#include <stdlib.h>
#include <string.h>
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "message_buffer.h"
#include "task.h"
#include "esp8266.h"
void task1(void *pvParameters)
{
TickType_t nowTick;
nowTick = xTaskGetTickCount();
printf("[%s:%d]
Start\n",pcTaskGetName(0),nowTick);
MessageBufferHandle_t *buffer =
(MessageBufferHandle_t *)pvParameters;
size_t xBytesSent;
char pcStringToSend[30];
while(1) {
// delay 1000mSec
vTaskDelay(1000 /
portTICK_PERIOD_MS);
nowTick =
xTaskGetTickCount();
sprintf(pcStringToSend,"nowTick=%d",nowTick);
xBytesSent =
xMessageBufferSend( *buffer,
( void * ) pcStringToSend,
strlen( pcStringToSend ),
0 );
printf("[%s:%d]
xBytesSent=%d\n",pcTaskGetName(0),nowTick,xBytesSent);
}
}
void task2(void *pvParameters)
{
TickType_t nowTick;
nowTick = xTaskGetTickCount();
printf("[%s:%d]
Start\n",pcTaskGetName(0),nowTick);
MessageBufferHandle_t *buffer =
(MessageBufferHandle_t *)pvParameters;
size_t xBytesReceived;
char ucRxData[ 100 ];
//const TickType_t xBlockTime =
pdMS_TO_TICKS( 2000 );
while(1) {
vTaskDelay(2000 /
portTICK_PERIOD_MS);
while(1) {
xBytesReceived
= xMessageBufferReceive( *buffer,
( void * ) ucRxData,
sizeof( ucRxData ),
0 );
nowTick =
xTaskGetTickCount();
printf("[%s:%d]
xBytesReceived=%d\n",pcTaskGetName(0),nowTick,xBytesReceived);
if
(xBytesReceived != 0) {
ucRxData[xBytesReceived] = 0;
printf("[%s:%d]
ucRxData=[%s]\n",pcTaskGetName(0),nowTick,ucRxData);
} else {
break;
}
}
}
}
static MessageBufferHandle_t xMessageBuffer;
void user_init(void)
{
uart_set_baud(0, 115200);
printf("SDK version:%s\n",
sdk_system_get_sdk_version());
printf("pcTaskGetName=%s\n",pcTaskGetName(0));
//MessageBufferHandle_t xMessageBuffer;
const size_t xMessageBufferSizeBytes =
100;
/* Create a message buffer that can
hold 100 bytes. The memory used to hold
both the message buffer structure and
the data in the message buffer is
allocated dynamically. */
xMessageBuffer = xMessageBufferCreate(
xMessageBufferSizeBytes );
if( xMessageBuffer == NULL ) {
/* There was not
enough heap memory space available to create the
message buffer. */
printf("%s: Unable to
create MessageBuffer ...\n", __FUNCTION__);
}
else
{
/* The message buffer
was created successfully and can now be used. */
printf("%s: Success
to create MessageBuffer ...\n", __FUNCTION__);
xTaskCreate(task1,
"task1", 256, &xMessageBuffer, 2, NULL);
xTaskCreate(task2,
"task2", 256, &xMessageBuffer, 2, NULL);
}
} |