tsoftuart: add a softare timer base UART driver, and example.
This commit is contained in:
parent
05da9151ee
commit
5ab0d05768
8 changed files with 349 additions and 0 deletions
1
examples/tsoftuart/.gitignore
vendored
Normal file
1
examples/tsoftuart/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
!local.mk
|
7
examples/tsoftuart/FreeRTOSConfig.h
Normal file
7
examples/tsoftuart/FreeRTOSConfig.h
Normal file
|
@ -0,0 +1,7 @@
|
|||
#define configUSE_TRACE_FACILITY 1
|
||||
#define configGENERATE_RUN_TIME_STATS 1
|
||||
#define portGET_RUN_TIME_COUNTER_VALUE() (RTC.COUNTER)
|
||||
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() {}
|
||||
|
||||
/* Use the defaults for everything else */
|
||||
#include_next<FreeRTOSConfig.h>
|
13
examples/tsoftuart/Makefile
Normal file
13
examples/tsoftuart/Makefile
Normal file
|
@ -0,0 +1,13 @@
|
|||
# Makefile for tsfotuart example
|
||||
PROGRAM=tsoftuart
|
||||
EXTRA_COMPONENTS=extras/dhcpserver extras/wificfg extras/mactimer extras/tsoftuart
|
||||
|
||||
# For the mDNS responder included with lwip:
|
||||
EXTRA_CFLAGS += -DLWIP_MDNS_RESPONDER=1 -DLWIP_NUM_NETIF_CLIENT_DATA=1 -DLWIP_NETIF_EXT_STATUS_CALLBACK=1
|
||||
|
||||
# Avoid writing the wifi state to flash when using wificfg.
|
||||
EXTRA_CFLAGS += -DWIFI_PARAM_SAVE=0
|
||||
|
||||
EXTRA_CFLAGS += -DWIFICFG_CLIENT_TASK=1 -DWIFICFG_IRAM_TEST=1
|
||||
|
||||
include ../../common.mk
|
1
examples/tsoftuart/local.mk
Normal file
1
examples/tsoftuart/local.mk
Normal file
|
@ -0,0 +1 @@
|
|||
FLASH_SIZE ?= 32
|
75
examples/tsoftuart/tsoftuart.c
Normal file
75
examples/tsoftuart/tsoftuart.c
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
* Example timer based software UART drive.
|
||||
*
|
||||
* Copyright (C) 2019 OurAirQuality.org
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0, January 2004 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
* http://www.apache.org/licenses/
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT
|
||||
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS WITH THE SOFTWARE.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#include <espressif/esp_common.h>
|
||||
#include <espressif/user_interface.h>
|
||||
#include <esp/uart.h>
|
||||
#include <FreeRTOS.h>
|
||||
#include <task.h>
|
||||
|
||||
#include "lwip/sockets.h"
|
||||
|
||||
#include "wificfg/wificfg.h"
|
||||
#include "tsoftuart/tsoftuart.h"
|
||||
|
||||
static void tsoftuart_task(void *pvParameters)
|
||||
{
|
||||
/* Initialize the UART Tx. */
|
||||
uint32_t tx_pin = *(uint32_t *)pvParameters;
|
||||
struct tsoftuart *uart = tsoftuart_init(tx_pin, 9600);
|
||||
|
||||
for (;;) {
|
||||
/* Reset the timing error records. */
|
||||
uart->output_queue_error_low = 0;
|
||||
uart->output_queue_error_high = 0;
|
||||
|
||||
char str[] = "Hello 0123456789 abcdefghijklmnopqrstuvwxyz\r\n";
|
||||
for (size_t i = 0; i < strlen(str); i++) {
|
||||
tsoftuart_putc(uart, str[i]);
|
||||
}
|
||||
|
||||
/* Check the timing error. */
|
||||
if (uart->output_queue_error_high > 2 || uart->output_queue_error_low < -2) {
|
||||
tsoftuart_write(uart, "X\r\n", 3);
|
||||
}
|
||||
|
||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||
}
|
||||
}
|
||||
|
||||
void user_init(void)
|
||||
{
|
||||
uart_set_baud(0, 115200);
|
||||
printf("SDK version:%s\n", sdk_system_get_sdk_version());
|
||||
|
||||
wificfg_init(80, NULL);
|
||||
|
||||
/* Start two tasks writing to different pins. */
|
||||
|
||||
static uint32_t tx_pin1 = 1;
|
||||
xTaskCreate(&tsoftuart_task, "tsoftuart1", 256, &tx_pin1, 1, NULL);
|
||||
|
||||
static uint32_t tx_pin2 = 2;
|
||||
xTaskCreate(&tsoftuart_task, "tsoftuart2", 256, &tx_pin2, 1, NULL);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue