Skip to content

Instantly share code, notes, and snippets.

@blippy
Created June 25, 2019 07:58
Show Gist options
  • Save blippy/c13cab82842192f2d886516bbf0835fa to your computer and use it in GitHub Desktop.
Save blippy/c13cab82842192f2d886516bbf0835fa to your computer and use it in GitHub Desktop.
ESP32 RTOS "does not compute"
/* Blink Example
This example code is in the Public Domain (or CC0 licensed, at your option.)
Unless required by applicable law or agreed to in writing, this
software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
CONDITIONS OF ANY KIND, either express or implied.
*/
#include <stdio.h>
#include <string.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "driver/gpio.h"
#include "sdkconfig.h"
//#include "linenoise/linenoise.h"
//#include <fio.h>
//#include <serial.h>
#include <driver/dac.h>
//#include <esp-common/include/esp_timer.h>
#include <esp_timer.h>
#include <esp_task_wdt.h>
#include "track.h"
/* Can run 'make menuconfig' to choose the GPIO to blink,
or you can edit the following line and set a number here.
*/
//#define BLINK_GPIO CONFIG_BLINK_GPIO
#define BLINK_GPIO 2
char line[100];
char* out = "mcarter\n";
char buf[100];
void vInput(void* params)
{
//line = linenoise($");
size_t count;
for(;;) {
//count = fio_read(0, line, sizeof(line));
//sprintf(buf, "length= %d", strlen(line));
count = 0;
while(1) {
int c = getc(stdin);
vTaskDelay(100 / portTICK_PERIOD_MS);
if(c==EOF) continue;
buf[count] = c;
putc(c, stdout);
if(c == '\n' || count == 98) { buf[count] = 0; break; }
count++;
}
fgets(buf, 99, stdin);
printf("You said: %s\n", buf);
//vTaskDelay(1000);
//fio_write(1, buff, strlen(buf));
}
}
//hw_time_t* timer = NULL;
volatile int8_t hit;
static void timcb(void* arg)
{
hit = 1;
}
void vWhite(void* param)
{
int idx =0;
//TickType_t xLastWakeTime = xTaskGetTickCount();
//const TickType_t xFreq = 10;
//double v = 0;
for(;;) {
taskYIELD();
esp_task_wdt_reset();
if(!hit) continue;
hit = 0;
//vTaskDelayUntil(&xLastWakeTime, xFreq);
//delayMicroseconds(2);
//int v = rand() % 255;
dac_output_voltage(DAC_CHANNEL_1, track_raw[idx++]);
if(idx>= track_raw_len) idx = 0;
//v =
}
}
void vIdle1(void* param)
{
for(;;) {
esp_task_wdt_reset();
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}
void vBlink(void* param)
{
while(1) {
//dacWrite(25, 12);
/*
static char mystring[100];
//fgets(mystring, 100, stdin);
char * line = linenoise("$");
if(line == NULL) continue;
printf("length = %d\n", st
rlen(line));
*/
/* Blink off (output low) */
//printf("Turning off the LED\n");
gpio_set_level(BLINK_GPIO, 0);
vTaskDelay(1000 / portTICK_PERIOD_MS);
/* Blink on (output high) */
//printf("Turning on the LED\n");
gpio_set_level(BLINK_GPIO, 1);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
}
void app_main()
{
/* Configure the IOMUX register for pad BLINK_GPIO (some pads are
muxed to GPIO on reset already, but some default to other
functions and need to be switched to GPIO. Consult the
Technical Reference for a list of pads and their default
functions.)
*/
gpio_pad_select_gpio(BLINK_GPIO);
/* Set the GPIO as a push/pull output */
gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
dac_output_enable(DAC_CHANNEL_1);
const esp_timer_create_args_t timargs = {
.callback = &timcb,
.name = "marksperiodic"
};
esp_timer_handle_t every;
esp_timer_create(&timargs, &every);
esp_timer_start_periodic(every, 125);
//Serial.begin(115200);
TaskHandle_t hnd = NULL;
TaskHandle_t hnd1 = NULL;
TaskHandle_t hnd2 = NULL;
TaskHandle_t hnd3 = NULL;
esp_task_wdt_init(3, false);
esp_task_wdt_add(xTaskGetIdleTaskHandleForCPU(1));
//BaseType_t inp = xTaskCreate(vInput, "vInput", 10000, (void*) 1, tskIDLE_PRIORITY, &hnd);
xTaskCreatePinnedToCore(vInput, "vInput", 10000, (void*) 1, configMAX_PRIORITIES/4,&hnd, 0);
xTaskCreatePinnedToCore(vWhite, "vWhite", 10000, (void*) 1, configMAX_PRIORITIES/2, &hnd1, 1);
xTaskCreatePinnedToCore(vBlink, "vBlink", 10000, (void*) 1, configMAX_PRIORITIES/8, &hnd2, 0);
xTaskCreatePinnedToCore(vIdle1, "vIdle1", 10000, (void*) 1, tskIDLE_PRIORITY, &hnd3, 1);
while(1){
vTaskDelay(100000 / portTICK_PERIOD_MS);
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment