sbmp cleaning, sbmp now works ok

This commit is contained in:
2016-03-17 12:01:46 +01:00
parent 5f14fdf1e9
commit e3b96fd2f9
19 changed files with 132 additions and 106 deletions
+16 -6
View File
@@ -4,24 +4,34 @@
#include "datalink.h"
static SBMP_Endpoint *ep;
/** func used for sending bytes by SBMP */
static void u0_putc(uint8_t c)
static void FLASH_FN u0_putc(uint8_t c)
{
UART_WriteCharCRLF(UART0, c, 0);
UART_WriteChar(UART0, c, 0);
}
static void dg_handler(SBMP_Datagram *dg)
static void FLASH_FN dg_handler(SBMP_Datagram *dg)
{
sbmp_info("Datagram received.");
}
static SBMP_Endpoint *ep;
void datalink_receive(uint8_t byte)
{
sbmp_ep_receive(ep, byte);
}
/** Datalink */
void datalinkInit(void)
void FLASH_FN datalinkInit(void)
{
ep = sbmp_ep_init(NULL, NULL, 256, dg_handler, u0_putc);
sbmp_ep_enable(ep, true);
os_printf("SBMP started on UART0\n");
}
+4
View File
@@ -1,6 +1,10 @@
#ifndef DATALINK_H
#define DATALINK_H
#include <esp8266.h>
void datalinkInit(void);
void datalink_receive(uint8_t byte);
#endif // DATALINK_H
+13 -5
View File
@@ -31,7 +31,7 @@ static ETSTimer resetBtntimer;
// }
//}
static void ICACHE_FLASH_ATTR resetBtnTimerCb(void *arg) {
static void FLASH_FN resetBtnTimerCb(void *arg) {
static int resetCnt=0;
if (!GPIO_INPUT_GET(BTNGPIO)) {
resetCnt++;
@@ -46,12 +46,20 @@ static void ICACHE_FLASH_ATTR resetBtnTimerCb(void *arg) {
}
}
void ioInit() {
void FLASH_FN ioInit() {
// PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);
gpio_output_set(0, 0, 0/*(1<<LEDGPIO)*/, (1<<BTNGPIO));
os_timer_disarm(&resetBtntimer);
os_timer_setfn(&resetBtntimer, resetBtnTimerCb, NULL);
os_timer_arm(&resetBtntimer, 500, 1);
if (GPIO_INPUT_GET(BTNGPIO) == 0) {
// starting "in BOOT mode" - do not install the AP reset timer
os_printf("GPIO0 stuck low - AP reset button disabled.\n");
} else {
os_timer_disarm(&resetBtntimer);
os_timer_setfn(&resetBtntimer, resetBtnTimerCb, NULL);
os_timer_arm(&resetBtntimer, 500, 1);
os_printf("Note: Hold GPIO0 low for reset to AP mode.\n");
}
}
+12 -14
View File
@@ -11,7 +11,7 @@
#include <esp8266.h>
#include "uart_driver.h"
#include "datalink.h"
static void uart0_rx_intr_handler(void *para);
@@ -22,11 +22,8 @@ static void uart_recvTask(os_event_t *events);
static os_event_t uart_recvTaskQueue[uart_recvTaskQueueLen];
/** Clear the fifos */
void ICACHE_FLASH_ATTR
clear_rxtx(int uart_no)
void FLASH_FN clear_rxtx(int uart_no)
{
SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
CLEAR_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST);
@@ -37,8 +34,7 @@ clear_rxtx(int uart_no)
* @brief Configure UART 115200-8-N-1
* @param uart_no
*/
static void ICACHE_FLASH_ATTR
my_uart_init(UARTn uart_no)
static void FLASH_FN my_uart_init(UARTn uart_no)
{
UART_SetParity(uart_no, PARITY_NONE);
UART_SetStopBits(uart_no, ONE_STOP_BIT);
@@ -49,7 +45,7 @@ my_uart_init(UARTn uart_no)
/** Configure basic UART func and pins */
static void conf_uart_pins(void)
static void FLASH_FN conf_uart_pins(void)
{
// U0TXD
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_U0TXD);
@@ -70,7 +66,7 @@ static void conf_uart_pins(void)
}
/** Configure Rx on UART0 */
static void conf_uart_receiver(void)
static void FLASH_FN conf_uart_receiver(void)
{
//
// Start the Rx reading task
@@ -98,8 +94,7 @@ static void conf_uart_receiver(void)
}
void ICACHE_FLASH_ATTR
serialInit()
void FLASH_FN serialInit()
{
conf_uart_pins();
conf_uart_receiver();
@@ -128,8 +123,7 @@ void uart_rx_intr_enable(uint8 uart_no)
#define UART_GetRxFifoCount(uart_no) ((READ_PERI_REG(UART_STATUS((uart_no))) >> UART_RXFIFO_CNT_S) & UART_RXFIFO_CNT)
static void ICACHE_FLASH_ATTR
uart_recvTask(os_event_t *events)
static void FLASH_FN uart_recvTask(os_event_t *events)
{
if (events->sig == 0) {
uint8 fifo_len = UART_GetRxFifoCount(UART0);
@@ -137,7 +131,9 @@ uart_recvTask(os_event_t *events)
// read from the FIFO & print back
for (uint8 idx = 0; idx < fifo_len; idx++) {
uint8 d_tmp = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF;
UART_WriteChar(UART0, d_tmp, 0);
//UART_WriteChar(UART0, d_tmp, 0);
datalink_receive(d_tmp);
}
// clear irq flags
@@ -160,6 +156,8 @@ uart_recvTask(os_event_t *events)
static void
uart0_rx_intr_handler(void *para)
{
(void)para;
uint32_t status_reg = READ_PERI_REG(UART_INT_ST(UART0));
if (status_reg & UART_FRM_ERR_INT_ST) {
+2 -2
View File
@@ -154,9 +154,9 @@ void ICACHE_FLASH_ATTR
UART_SetPrintPort(UARTn uart_no)
{
if (uart_no == UART0) {
os_install_putc1(u0_putc_crlf);
os_install_putc1((void *)u0_putc_crlf);
} else {
os_install_putc1(u1_putc_crlf);
os_install_putc1((void *)u1_putc_crlf);
}
}
+11 -1
View File
@@ -26,6 +26,8 @@
#include "datalink.h"
#include "uart_driver.h"
#include "sbmp.h"
/**
* @brief BasicAuth name/password checking function.
@@ -42,7 +44,7 @@
* @param passLen : password buffer size
* @return 0 to end, 1 if more users are available.
*/
int myPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen)
int FLASH_FN myPassFn(HttpdConnData *connData, int no, char *user, int userLen, char *pass, int passLen)
{
(void)connData;
(void)userLen;
@@ -122,6 +124,8 @@ static HttpdBuiltInUrl builtInUrls[] = {
// UART_WriteBuffer(0, (uint8_t*)t, strlen(t), 1000);
//}
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
/**
* Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done.
@@ -131,6 +135,12 @@ void user_init(void)
// set up the debuging output
serialInit();
os_printf("\n\x1b[32;1mESP8266 starting, "
"HTTPD v."HTTPDVER", "
"SBMP v."SBMP_VER", "
"IoT SDK v." STR(ESP_SDK_VERSION)
"\x1b[0m\n");
// reset button etc
ioInit();