yvesds wrote on Friday, October 20, 2017:
Hi,
I’ve been adapting a example, and i must say it came to work:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "sdkconfig.h"
#include "esp_system.h"
#include "esp_heap_alloc_caps.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/heap_regions.h"
#define outputCore 1
#define logicCore 0
xQueueHandle demo_queue;
void tx_task1(void *arg) {
uint32_t txpos=0;
uint32_t myCore = xPortGetCoreID();
printf("TX1 from Core : %u\n",myCore);
while (1) {
if(xQueueSendToBack(demo_queue,&txpos,1000/portTICK_RATE_MS)!=pdTRUE) {
printf("tx_task1 can not transfer %d\n",txpos);
}
vTaskDelay(7000 / portTICK_RATE_MS); // delay 7s
txpos++;
}
}
void tx_task2(void *arg) {
uint32_t txpos=0;
uint32_t myCore = xPortGetCoreID();
printf("TX2 from Core :%u\n",myCore);
while (1) {
if(xQueueSendToBack(demo_queue,&txpos,1000/portTICK_RATE_MS)!=pdTRUE) {
printf("tx_task2 can not transfer %d\n",txpos);
}
vTaskDelay(10000 / portTICK_RATE_MS); // delay 10s
txpos++;
}
}
void rx_task(void *arg) {
uint32_t rxpos;
uint32_t myCore = xPortGetCoreID();
printf("This is the receiving Task : rx_task\n");
while (1) {
printf("rx_task queue yield");
if(xQueueReceive(demo_queue,&rxpos,60000/portTICK_RATE_MS)!=pdTRUE) { // max wait 60s
printf("nothing received!\n");
} else {
printf("rx_task received a value %d\n",rxpos);
printf("Active core : %u\n",myCore);
}
if (uxQueueMessagesWaiting(demo_queue)==0) { // no message? take a break
printf("nothing to do, take a nap :-)\n");
vTaskDelay(15000 / portTICK_RATE_MS); // delay 15s
}
}
}
void app_main() {
printf("constructing & starting ESP32 tasks\n");
printf("free DRAM %u IRAM %u\n",esp_get_free_heap_size(),xPortGetFreeHeapSizeTagged(MALLOC_CAP_32BIT));
demo_queue = xQueueCreate(10, sizeof(uint32_t));
printf("free DRAM %u IRAM %u\n",esp_get_free_heap_size(),xPortGetFreeHeapSizeTagged(MALLOC_CAP_32BIT));
printf("created three tasks\n");
xTaskCreatePinnedToCore(tx_task1, "tx_task1", CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE, NULL, 5, NULL,logicCore);
xTaskCreatePinnedToCore(tx_task2, "tx_task2", CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE, NULL, 5, NULL,logicCore);
xTaskCreatePinnedToCore(rx_task, "rx_task", CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE, NULL, 5, NULL,outputCore);
printf("end of main\n");
}
i have the following question now :
can i create a ISR task and let that be pinned to a core?
the goal is to trap a signal from a button by interrupt, and do some output on the other core…
ah, i have a additional question : in arduino we have something like millis() or micros() who return a timestamp from since the Mcu started after a (re-)boot - is there a similar function in IDF?
Grtz,
Yves