sbmp cleaning, sbmp now works ok

master
Ondřej Hruška 8 years ago
parent 5f14fdf1e9
commit e3b96fd2f9
  1. 6
      Makefile
  2. 1
      esp_meas.pro
  3. 24
      esp_meas.pro.user
  4. 3
      libesphttpd/include/esp8266.h
  5. 8
      sbmp/crc32.c
  6. 2
      sbmp/sbmp.h
  7. 10
      sbmp/sbmp_checksum.c
  8. 2
      sbmp/sbmp_config.h
  9. 6
      sbmp/sbmp_datagram.c
  10. 36
      sbmp/sbmp_frame.c
  11. 6
      sbmp/sbmp_logging.c
  12. 4
      sbmp/sbmp_logging.h
  13. 44
      sbmp/sbmp_session.c
  14. 22
      user/datalink.c
  15. 4
      user/datalink.h
  16. 18
      user/io.c
  17. 26
      user/serial.c
  18. 4
      user/uart_driver.c
  19. 12
      user/user_main.c

@ -39,7 +39,7 @@ USE_OPENSDK?=yes
#Esptool.py path and port #Esptool.py path and port
ESPTOOL ?= esptool.py ESPTOOL ?= esptool.py
ESPPORT ?= /dev/ttyUSB0 ESPPORT ?= /dev/ttyUSBblack
#ESPDELAY indicates seconds to wait between flashing the two binary images #ESPDELAY indicates seconds to wait between flashing the two binary images
ESPDELAY ?= 3 ESPDELAY ?= 3
ESPBAUD ?= 115200 ESPBAUD ?= 115200
@ -62,10 +62,10 @@ LIBS += esphttpd
# compiler flags using during compilation of source files # compiler flags using during compilation of source files
CFLAGS = -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \ CFLAGS = -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \
-nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH \ -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH \
-Wno-address -Wno-address -ffunction-sections
# linker flags used to generate the main object file # linker flags used to generate the main object file
LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static LDFLAGS = -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static -Wl,--gc-sections
# various paths from the SDK used in this project # various paths from the SDK used in this project

@ -46,7 +46,6 @@ SOURCES += \
sbmp/sbmp_checksum.c \ sbmp/sbmp_checksum.c \
sbmp/sbmp_datagram.c \ sbmp/sbmp_datagram.c \
sbmp/sbmp_frame.c \ sbmp/sbmp_frame.c \
sbmp/sbmp_logging.c \
sbmp/sbmp_session.c \ sbmp/sbmp_session.c \
user/datalink.c \ user/datalink.c \
user/serial.c user/serial.c

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 3.6.0, 2016-03-16T13:58:05. --> <!-- Written by QtCreator 3.6.0, 2016-03-17T11:48:45. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>
@ -65,7 +65,7 @@
<value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value> <value type="int" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
<value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">1</value> <value type="int" key="ProjectExplorer.Target.ActiveRunConfiguration">1</value>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/ondra/devel/esp/projects/esphttpd</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/ondra/BP/code/esp-firmware</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@ -106,9 +106,7 @@
</valuemap> </valuemap>
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value> <value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value> <value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"> <valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
<value type="QString">PATH=/usr/lib/qt/bin:/usr/bin:/home/ondra/GNUstep/Tools:/usr/local/sbin:/usr/local/bin:/usr/bin:/opt/android-sdk/platform-tools:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/ondra/bin:/home/ondra/devel/esp/sdk/esp-open-sdk/xtensa-lx106-elf/bin/</value>
</valuelist>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Debug</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4BuildConfiguration</value>
@ -116,7 +114,7 @@
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap> </valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.1">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/ondra/devel/esp/projects/build-esphttpd-Desktop-Release</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/ondra/BP/code/build-esp_meas-Desktop-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@ -176,7 +174,7 @@
<value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value> <value type="bool" key="Qt4ProjectManager.Qt4BuildConfiguration.UseShadowBuild">true</value>
</valuemap> </valuemap>
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2"> <valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.2">
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/ondra/devel/esp/projects/build-esphttpd-Desktop-Profile</value> <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/ondra/BP/code/build-esp_meas-Desktop-Profile</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0"> <valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value> <value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
@ -291,12 +289,12 @@
</valuelist> </valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value> <value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">esphttpd</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">esp_meas</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/ondra/devel/esp/projects/esphttpd/esphttpd.pro</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">Qt4ProjectManager.Qt4RunConfiguration:/home/ondra/BP/code/esp-firmware/esp_meas.pro</value>
<value type="bool" key="QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath">true</value> <value type="bool" key="QmakeProjectManager.QmakeRunConfiguration.UseLibrarySearchPath">true</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.CommandLineArguments"></value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">esphttpd.pro</value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.ProFile">esp_meas.pro</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value> <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseDyldImageSuffix">false</value>
<value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value> <value type="bool" key="Qt4ProjectManager.Qt4RunConfiguration.UseTerminal">true</value>
<value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value> <value type="QString" key="Qt4ProjectManager.Qt4RunConfiguration.UserWorkingDirectory"></value>
@ -348,10 +346,10 @@
</valuelist> </valuelist>
<value type="int" key="PE.EnvironmentAspect.Base">2</value> <value type="int" key="PE.EnvironmentAspect.Base">2</value>
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/> <valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Arguments">flash -j 4</value> <value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Arguments">flash</value>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable">/bin/make</value> <value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.Executable">/usr/bin/make</value>
<value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory">%{buildDir}</value> <value type="QString" key="ProjectExplorer.CustomExecutableRunConfiguration.WorkingDirectory">%{buildDir}</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Run /bin/make</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Run /usr/bin/make</value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName"></value>
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value> <value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
<value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value> <value type="uint" key="RunConfiguration.QmlDebugServerPort">3768</value>

@ -22,6 +22,9 @@
#include <upgrade.h> #include <upgrade.h>
#endif #endif
#define FLASH_FN ICACHE_FLASH_ATTR
#include "platform.h" #include "platform.h"
#include "espmissingincludes.h" #include "espmissingincludes.h"
#include "esp_sdk_ver.h"

@ -115,22 +115,22 @@ static uint32_t ICACHE_RODATA_ATTR STORE_ATTR crc_32_tab[] = { /* CRC polynomial
#define UPDC32(octet, crc) (crc_32_tab[((crc) ^ ((uint8_t)octet)) & 0xff] ^ ((crc) >> 8)) #define UPDC32(octet, crc) (crc_32_tab[((crc) ^ ((uint8_t)octet)) & 0xff] ^ ((crc) >> 8))
uint32_t crc32_begin(void) uint32_t FLASH_FN crc32_begin(void)
{ {
return 0xFFFFFFFF; return 0xFFFFFFFF;
} }
uint32_t crc32_update(uint32_t crc_scratch, uint8_t ch) uint32_t FLASH_FN crc32_update(uint32_t crc_scratch, uint8_t ch)
{ {
return UPDC32(ch, crc_scratch); return UPDC32(ch, crc_scratch);
} }
uint32_t crc32_end(uint32_t crc_scratch) uint32_t FLASH_FN crc32_end(uint32_t crc_scratch)
{ {
return ~crc_scratch; return ~crc_scratch;
} }
uint32_t crc32buf(uint8_t *buf, size_t len) uint32_t FLASH_FN crc32buf(uint8_t *buf, size_t len)
{ {
uint32_t scratch = crc32_begin(); uint32_t scratch = crc32_begin();

@ -8,6 +8,8 @@
* #include in your application code. * #include in your application code.
*/ */
#define SBMP_VER "1.3"
#include "sbmp_config.h" #include "sbmp_config.h"
// Common utils & the frame parser // Common utils & the frame parser

@ -11,7 +11,7 @@
/** Get nr of bytes in a checksum */ /** Get nr of bytes in a checksum */
uint8_t chksum_length(SBMP_CksumType cksum_type) uint8_t FLASH_FN chksum_length(SBMP_CksumType cksum_type)
{ {
switch (cksum_type) { switch (cksum_type) {
case SBMP_CKSUM_CRC32: return 4; case SBMP_CKSUM_CRC32: return 4;
@ -23,7 +23,7 @@ uint8_t chksum_length(SBMP_CksumType cksum_type)
} }
/** Start calculating a checksum */ /** Start calculating a checksum */
void cksum_begin(SBMP_CksumType type, uint32_t *scratch) void FLASH_FN cksum_begin(SBMP_CksumType type, uint32_t *scratch)
{ {
switch (type) { switch (type) {
@ -43,7 +43,7 @@ void cksum_begin(SBMP_CksumType type, uint32_t *scratch)
} }
/** Update the checksum calculation with an incoming byte */ /** Update the checksum calculation with an incoming byte */
void cksum_update(SBMP_CksumType type, uint32_t *scratch, uint8_t byte) void FLASH_FN cksum_update(SBMP_CksumType type, uint32_t *scratch, uint8_t byte)
{ {
switch (type) { switch (type) {
@ -63,7 +63,7 @@ void cksum_update(SBMP_CksumType type, uint32_t *scratch, uint8_t byte)
} }
/** Stop the checksum calculation, get the result */ /** Stop the checksum calculation, get the result */
void cksum_end(SBMP_CksumType type, uint32_t *scratch) void FLASH_FN cksum_end(SBMP_CksumType type, uint32_t *scratch)
{ {
switch (type) { switch (type) {
@ -83,7 +83,7 @@ void cksum_end(SBMP_CksumType type, uint32_t *scratch)
} }
/** Check if the calculated checksum matches the received one */ /** Check if the calculated checksum matches the received one */
bool cksum_verify(SBMP_CksumType type, uint32_t *scratch, uint32_t received_cksum) bool FLASH_FN cksum_verify(SBMP_CksumType type, uint32_t *scratch, uint32_t received_cksum)
{ {
cksum_end(type, scratch); cksum_end(type, scratch);

@ -44,7 +44,7 @@
* If handshake is used, the peer will detect that CRC32 is not * If handshake is used, the peer will detect that CRC32 is not
* supported here, and should start using XOR. * supported here, and should start using XOR.
*/ */
#define SBMP_HAS_CRC32 0 #define SBMP_HAS_CRC32 1
#endif #endif
/* ------------------------------------- */ /* ------------------------------------- */

@ -4,7 +4,7 @@
#include "sbmp_logging.h" #include "sbmp_logging.h"
#include "sbmp_datagram.h" #include "sbmp_datagram.h"
SBMP_Datagram *sbmp_dg_parse(SBMP_Datagram *dg, const uint8_t *payload, uint16_t length) SBMP_Datagram FLASH_FN *sbmp_dg_parse(SBMP_Datagram *dg, const uint8_t *payload, uint16_t length)
{ {
if (length < 3) { if (length < 3) {
sbmp_error("Can't parse datagram, payload too short."); sbmp_error("Can't parse datagram, payload too short.");
@ -34,7 +34,7 @@ SBMP_Datagram *sbmp_dg_parse(SBMP_Datagram *dg, const uint8_t *payload, uint16_t
/** Start a datagram transmission */ /** Start a datagram transmission */
bool sbmp_dg_start(SBMP_FrmInst *frm, SBMP_CksumType cksum_type, uint16_t session, SBMP_DgType type, uint16_t length) bool FLASH_FN sbmp_dg_start(SBMP_FrmInst *frm, SBMP_CksumType cksum_type, uint16_t session, SBMP_DgType type, uint16_t length)
{ {
if (length > (0xFFFF - 3)) { if (length > (0xFFFF - 3)) {
sbmp_error("Can't send a datagram, payload too long."); sbmp_error("Can't send a datagram, payload too long.");
@ -57,7 +57,7 @@ bool sbmp_dg_start(SBMP_FrmInst *frm, SBMP_CksumType cksum_type, uint16_t sessio
/** Send a whole datagram in one go */ /** Send a whole datagram in one go */
bool sbmp_dg_send(SBMP_FrmInst *frm, SBMP_CksumType cksum_type, SBMP_Datagram *dg) bool FLASH_FN sbmp_dg_send(SBMP_FrmInst *frm, SBMP_CksumType cksum_type, SBMP_Datagram *dg)
{ {
if (! sbmp_dg_start(frm, cksum_type, dg->session, dg->type, dg->length)) { if (! sbmp_dg_start(frm, cksum_type, dg->session, dg->type, dg->length)) {
sbmp_error("Failed to start datagram."); sbmp_error("Failed to start datagram.");

@ -12,7 +12,7 @@ static void call_frame_rx_callback(SBMP_FrmInst *frm);
/** Allocate the state struct & init all fields */ /** Allocate the state struct & init all fields */
SBMP_FrmInst *sbmp_frm_init( SBMP_FrmInst FLASH_FN *sbmp_frm_init(
SBMP_FrmInst *frm, SBMP_FrmInst *frm,
uint8_t *buffer, uint8_t *buffer,
uint16_t buffer_size, uint16_t buffer_size,
@ -58,39 +58,39 @@ SBMP_FrmInst *sbmp_frm_init(
} }
/** Reset the internal state */ /** Reset the internal state */
void sbmp_frm_reset(SBMP_FrmInst *frm) void FLASH_FN sbmp_frm_reset(SBMP_FrmInst *frm)
{ {
sbmp_frm_reset_rx(frm); sbmp_frm_reset_rx(frm);
sbmp_frm_reset_tx(frm); sbmp_frm_reset_tx(frm);
} }
/** Enable or disable Rx */ /** Enable or disable Rx */
void sbmp_frm_enable_rx(SBMP_FrmInst *frm, bool enable) void FLASH_FN sbmp_frm_enable_rx(SBMP_FrmInst *frm, bool enable)
{ {
frm->rx_enabled = enable; frm->rx_enabled = enable;
} }
/** Enable or disable Tx */ /** Enable or disable Tx */
void sbmp_frm_enable_tx(SBMP_FrmInst *frm, bool enable) void FLASH_FN sbmp_frm_enable_tx(SBMP_FrmInst *frm, bool enable)
{ {
frm->tx_enabled = enable; frm->tx_enabled = enable;
} }
/** Enable or disable both Rx and Tx */ /** Enable or disable both Rx and Tx */
void sbmp_frm_enable(SBMP_FrmInst *frm, bool enable) void FLASH_FN sbmp_frm_enable(SBMP_FrmInst *frm, bool enable)
{ {
sbmp_frm_enable_rx(frm, enable); sbmp_frm_enable_rx(frm, enable);
sbmp_frm_enable_tx(frm, enable); sbmp_frm_enable_tx(frm, enable);
} }
/** Set user token */ /** Set user token */
void sbmp_frm_set_user_token(SBMP_FrmInst *frm, void *token) void FLASH_FN sbmp_frm_set_user_token(SBMP_FrmInst *frm, void *token)
{ {
frm->user_token = token; frm->user_token = token;
} }
/** Reset the receiver state */ /** Reset the receiver state */
void sbmp_frm_reset_rx(SBMP_FrmInst *frm) void FLASH_FN sbmp_frm_reset_rx(SBMP_FrmInst *frm)
{ {
frm->rx_buffer_i = 0; frm->rx_buffer_i = 0;
frm->rx_length = 0; frm->rx_length = 0;
@ -104,7 +104,7 @@ void sbmp_frm_reset_rx(SBMP_FrmInst *frm)
} }
/** Reset the transmitter state */ /** Reset the transmitter state */
void sbmp_frm_reset_tx(SBMP_FrmInst *frm) void FLASH_FN sbmp_frm_reset_tx(SBMP_FrmInst *frm)
{ {
frm->tx_status = FRM_STATE_IDLE; frm->tx_status = FRM_STATE_IDLE;
frm->tx_remain = 0; frm->tx_remain = 0;
@ -114,21 +114,21 @@ void sbmp_frm_reset_tx(SBMP_FrmInst *frm)
} }
/** Update a header XOR */ /** Update a header XOR */
static inline static inline FLASH_FN
void hdrxor_update(SBMP_FrmInst *frm, uint8_t rxbyte) void hdrxor_update(SBMP_FrmInst *frm, uint8_t rxbyte)
{ {
frm->rx_hdr_xor ^= rxbyte; frm->rx_hdr_xor ^= rxbyte;
} }
/** Check header xor against received value */ /** Check header xor against received value */
static inline static inline FLASH_FN
bool hdrxor_verify(SBMP_FrmInst *frm, uint8_t rx_xor) bool hdrxor_verify(SBMP_FrmInst *frm, uint8_t rx_xor)
{ {
return frm->rx_hdr_xor == rx_xor; return frm->rx_hdr_xor == rx_xor;
} }
/** Append a byte to the rx buffer */ /** Append a byte to the rx buffer */
static inline static inline FLASH_FN
void append_rx_byte(SBMP_FrmInst *frm, uint8_t b) void append_rx_byte(SBMP_FrmInst *frm, uint8_t b)
{ {
frm->rx_buffer[frm->rx_buffer_i++] = b; frm->rx_buffer[frm->rx_buffer_i++] = b;
@ -136,7 +136,7 @@ void append_rx_byte(SBMP_FrmInst *frm, uint8_t b)
/** Set n-th byte (0 = LSM) to a value */ /** Set n-th byte (0 = LSM) to a value */
static inline static inline
void set_byte(uint32_t *acc, uint8_t pos, uint8_t byte) void FLASH_FN set_byte(uint32_t *acc, uint8_t pos, uint8_t byte)
{ {
*acc |= (uint32_t)(byte << (pos * 8)); *acc |= (uint32_t)(byte << (pos * 8));
} }
@ -145,7 +145,7 @@ void set_byte(uint32_t *acc, uint8_t pos, uint8_t byte)
* Call the message handler with the payload. * Call the message handler with the payload.
* *
*/ */
static void call_frame_rx_callback(SBMP_FrmInst *frm) static void FLASH_FN call_frame_rx_callback(SBMP_FrmInst *frm)
{ {
if (frm->rx_handler == NULL) { if (frm->rx_handler == NULL) {
sbmp_error("frame_handler is null!"); sbmp_error("frame_handler is null!");
@ -165,7 +165,7 @@ static void call_frame_rx_callback(SBMP_FrmInst *frm)
* @param rxbyte * @param rxbyte
* @return status * @return status
*/ */
SBMP_RxStatus sbmp_frm_receive(SBMP_FrmInst *frm, uint8_t rxbyte) SBMP_RxStatus FLASH_FN sbmp_frm_receive(SBMP_FrmInst *frm, uint8_t rxbyte)
{ {
if (! frm->rx_enabled) { if (! frm->rx_enabled) {
return SBMP_RX_DISABLED; return SBMP_RX_DISABLED;
@ -303,7 +303,7 @@ SBMP_RxStatus sbmp_frm_receive(SBMP_FrmInst *frm, uint8_t rxbyte)
} }
/** Send a frame header */ /** Send a frame header */
bool sbmp_frm_start(SBMP_FrmInst *frm, SBMP_CksumType cksum_type, uint16_t length) bool FLASH_FN sbmp_frm_start(SBMP_FrmInst *frm, SBMP_CksumType cksum_type, uint16_t length)
{ {
if (! frm->tx_enabled) { if (! frm->tx_enabled) {
sbmp_error("Can't tx, not enabled."); sbmp_error("Can't tx, not enabled.");
@ -356,7 +356,7 @@ bool sbmp_frm_start(SBMP_FrmInst *frm, SBMP_CksumType cksum_type, uint16_t lengt
} }
/** End frame and enter idle mode */ /** End frame and enter idle mode */
static void end_frame(SBMP_FrmInst *frm) static void FLASH_FN end_frame(SBMP_FrmInst *frm)
{ {
if (!frm->tx_enabled) { if (!frm->tx_enabled) {
sbmp_error("Can't tx, not enabled."); sbmp_error("Can't tx, not enabled.");
@ -387,7 +387,7 @@ static void end_frame(SBMP_FrmInst *frm)
} }
/** Send a byte in the currently open frame */ /** Send a byte in the currently open frame */
bool sbmp_frm_send_byte(SBMP_FrmInst *frm, uint8_t byte) bool FLASH_FN sbmp_frm_send_byte(SBMP_FrmInst *frm, uint8_t byte)
{ {
if (!frm->tx_enabled) { if (!frm->tx_enabled) {
sbmp_error("Can't tx, not enabled."); sbmp_error("Can't tx, not enabled.");
@ -410,7 +410,7 @@ bool sbmp_frm_send_byte(SBMP_FrmInst *frm, uint8_t byte)
} }
/** Send a buffer in the currently open frame */ /** Send a buffer in the currently open frame */
uint16_t sbmp_frm_send_buffer(SBMP_FrmInst *frm, const uint8_t *buffer, uint16_t length) uint16_t FLASH_FN sbmp_frm_send_buffer(SBMP_FrmInst *frm, const uint8_t *buffer, uint16_t length)
{ {
if (! frm->tx_enabled) { if (! frm->tx_enabled) {
sbmp_error("Can't tx, not enabled."); sbmp_error("Can't tx, not enabled.");

@ -1,6 +0,0 @@
#include <stdarg.h>
#include "esp8266.h"
#include "sbmp_config.h"
#include "sbmp_logging.h"

@ -9,7 +9,7 @@
*/ */
// do-nothing definitions // do-nothing definitions
#define sbmp_error(fmt, ...) os_printf("\x1b[31;1mSBMP][E] " #fmt "\x1b[0m\r\n", ##__VA_ARGS__) #define sbmp_error(fmt, ...) os_printf("\x1b[31;1mSBMP][E] "fmt"\x1b[0m\r\n", ##__VA_ARGS__)
#define sbmp_info(fmt, ...) os_printf("\x1b[32;1m[SBMP][i] " #fmt "\x1b[0m\r\n", ##__VA_ARGS__) #define sbmp_info(fmt, ...) os_printf("\x1b[32;1m[SBMP][i] "fmt"\x1b[0m\r\n", ##__VA_ARGS__)
#endif /* SBMP_COMMON_H */ #endif /* SBMP_COMMON_H */

@ -18,7 +18,7 @@ static void handle_hsk_datagram(SBMP_Endpoint *ep, SBMP_Datagram *dg);
/** Rx handler that is assigned to the framing layer */ /** Rx handler that is assigned to the framing layer */
static void ep_rx_handler(uint8_t *buf, uint16_t len, void *token) static void FLASH_FN ep_rx_handler(uint8_t *buf, uint16_t len, void *token)
{ {
// endpoint pointer is stored in the user token // endpoint pointer is stored in the user token
SBMP_Endpoint *ep = (SBMP_Endpoint *)token; SBMP_Endpoint *ep = (SBMP_Endpoint *)token;
@ -39,7 +39,7 @@ static void ep_rx_handler(uint8_t *buf, uint16_t len, void *token)
* @param buffer_size : Rx buffer length * @param buffer_size : Rx buffer length
* @return the endpoint struct pointer (allocated if ep was NULL) * @return the endpoint struct pointer (allocated if ep was NULL)
*/ */
SBMP_Endpoint *sbmp_ep_init( SBMP_Endpoint FLASH_FN *sbmp_ep_init(
SBMP_Endpoint *ep, SBMP_Endpoint *ep,
uint8_t *buffer, uint8_t *buffer,
uint16_t buffer_size, uint16_t buffer_size,
@ -85,7 +85,7 @@ SBMP_Endpoint *sbmp_ep_init(
* *
* @param ep : Endpoint * @param ep : Endpoint
*/ */
void sbmp_ep_reset(SBMP_Endpoint *ep) void FLASH_FN sbmp_ep_reset(SBMP_Endpoint *ep)
{ {
ep->next_session = 0; ep->next_session = 0;
ep->origin = 0; ep->origin = 0;
@ -103,19 +103,19 @@ void sbmp_ep_reset(SBMP_Endpoint *ep)
// --- Customizing settings --- // --- Customizing settings ---
/** Set session number (good to randomize before first message) */ /** Set session number (good to randomize before first message) */
void sbmp_ep_seed_session(SBMP_Endpoint *ep, uint16_t sesn) void FLASH_FN sbmp_ep_seed_session(SBMP_Endpoint *ep, uint16_t sesn)
{ {
ep->next_session = sesn & 0x7FFF; ep->next_session = sesn & 0x7FFF;
} }
/** Set the origin bit (bypass handshake) */ /** Set the origin bit (bypass handshake) */
void sbmp_ep_set_origin(SBMP_Endpoint *endp, bool bit) void FLASH_FN sbmp_ep_set_origin(SBMP_Endpoint *endp, bool bit)
{ {
endp->origin = bit; endp->origin = bit;
} }
/** Set the preferred checksum. */ /** Set the preferred checksum. */
void sbmp_ep_set_preferred_cksum(SBMP_Endpoint *endp, SBMP_CksumType cksum_type) void FLASH_FN sbmp_ep_set_preferred_cksum(SBMP_Endpoint *endp, SBMP_CksumType cksum_type)
{ {
if (cksum_type == SBMP_CKSUM_CRC32 && !SBMP_HAS_CRC32) { if (cksum_type == SBMP_CKSUM_CRC32 && !SBMP_HAS_CRC32) {
sbmp_error("CRC32 not avail, using XOR instead."); sbmp_error("CRC32 not avail, using XOR instead.");
@ -127,19 +127,19 @@ void sbmp_ep_set_preferred_cksum(SBMP_Endpoint *endp, SBMP_CksumType cksum_type)
/** Enable or disable RX in the FrmInst backing this Endpoint */ /** Enable or disable RX in the FrmInst backing this Endpoint */
void sbmp_ep_enable_rx(SBMP_Endpoint *ep, bool enable_rx) void FLASH_FN sbmp_ep_enable_rx(SBMP_Endpoint *ep, bool enable_rx)
{ {
sbmp_frm_enable_rx(&ep->frm, enable_rx); sbmp_frm_enable_rx(&ep->frm, enable_rx);
} }
/** Enable or disable TX in the FrmInst backing this Endpoint */ /** Enable or disable TX in the FrmInst backing this Endpoint */
void sbmp_ep_enable_tx(SBMP_Endpoint *ep, bool enable_tx) void FLASH_FN sbmp_ep_enable_tx(SBMP_Endpoint *ep, bool enable_tx)
{ {
sbmp_frm_enable_tx(&ep->frm, enable_tx); sbmp_frm_enable_tx(&ep->frm, enable_tx);
} }
/** Enable or disable Rx & TX in the FrmInst backing this Endpoint */ /** Enable or disable Rx & TX in the FrmInst backing this Endpoint */
void sbmp_ep_enable(SBMP_Endpoint *ep, bool enable) void FLASH_FN sbmp_ep_enable(SBMP_Endpoint *ep, bool enable)
{ {
sbmp_frm_enable(&ep->frm, enable); sbmp_frm_enable(&ep->frm, enable);
} }
@ -147,7 +147,7 @@ void sbmp_ep_enable(SBMP_Endpoint *ep, bool enable)
// --- // ---
/** Get a new session number */ /** Get a new session number */
static uint16_t next_session(SBMP_Endpoint *ep) static uint16_t FLASH_FN next_session(SBMP_Endpoint *ep)
{ {
uint16_t sesn = ep->next_session; uint16_t sesn = ep->next_session;
@ -163,7 +163,7 @@ static uint16_t next_session(SBMP_Endpoint *ep)
// --- Header/body send funcs --- // --- Header/body send funcs ---
/** Start a message as a reply */ /** Start a message as a reply */
bool sbmp_ep_start_response(SBMP_Endpoint *ep, SBMP_DgType type, uint16_t length, uint16_t sesn) bool FLASH_FN sbmp_ep_start_response(SBMP_Endpoint *ep, SBMP_DgType type, uint16_t length, uint16_t sesn)
{ {
uint16_t peer_accepts = ep->peer_buffer_size - DATAGRA_HEADER_LEN; uint16_t peer_accepts = ep->peer_buffer_size - DATAGRA_HEADER_LEN;
@ -176,7 +176,7 @@ bool sbmp_ep_start_response(SBMP_Endpoint *ep, SBMP_DgType type, uint16_t length
} }
/** Start a message in a new session */ /** Start a message in a new session */
bool sbmp_ep_start_session(SBMP_Endpoint *ep, SBMP_DgType type, uint16_t length, uint16_t *sesn_ptr) bool FLASH_FN sbmp_ep_start_session(SBMP_Endpoint *ep, SBMP_DgType type, uint16_t length, uint16_t *sesn_ptr)
{ {
uint16_t sn = next_session(ep); uint16_t sn = next_session(ep);
@ -189,19 +189,19 @@ bool sbmp_ep_start_session(SBMP_Endpoint *ep, SBMP_DgType type, uint16_t length,
} }
/** Send one byte in the current message */ /** Send one byte in the current message */
bool sbmp_ep_send_byte(SBMP_Endpoint *ep, uint8_t byte) bool FLASH_FN sbmp_ep_send_byte(SBMP_Endpoint *ep, uint8_t byte)
{ {
return sbmp_frm_send_byte(&ep->frm, byte); return sbmp_frm_send_byte(&ep->frm, byte);
} }
/** Send a data buffer (or a part) in the current message */ /** Send a data buffer (or a part) in the current message */
uint16_t sbmp_ep_send_buffer(SBMP_Endpoint *ep, const uint8_t *buffer, uint16_t length) uint16_t FLASH_FN sbmp_ep_send_buffer(SBMP_Endpoint *ep, const uint8_t *buffer, uint16_t length)
{ {
return sbmp_frm_send_buffer(&ep->frm, buffer, length); return sbmp_frm_send_buffer(&ep->frm, buffer, length);
} }
/** Rx, pass to framing layer */ /** Rx, pass to framing layer */
SBMP_RxStatus sbmp_ep_receive(SBMP_Endpoint *ep, uint8_t byte) SBMP_RxStatus FLASH_FN sbmp_ep_receive(SBMP_Endpoint *ep, uint8_t byte)
{ {
return sbmp_frm_receive(&ep->frm, byte); return sbmp_frm_receive(&ep->frm, byte);
} }
@ -210,7 +210,7 @@ SBMP_RxStatus sbmp_ep_receive(SBMP_Endpoint *ep, uint8_t byte)
// --- All-in-one send funcs --- // --- All-in-one send funcs ---
/** Send a message in a session. */ /** Send a message in a session. */
bool sbmp_ep_send_response( bool FLASH_FN sbmp_ep_send_response(
SBMP_Endpoint *ep, SBMP_Endpoint *ep,
SBMP_DgType type, SBMP_DgType type,
const uint8_t *buffer, const uint8_t *buffer,
@ -230,7 +230,7 @@ bool sbmp_ep_send_response(
} }
/** Send message in a new session */ /** Send message in a new session */
bool sbmp_ep_send_message( bool FLASH_FN sbmp_ep_send_message(
SBMP_Endpoint *ep, SBMP_Endpoint *ep,
SBMP_DgType type, SBMP_DgType type,
const uint8_t *buffer, const uint8_t *buffer,
@ -267,7 +267,7 @@ bool sbmp_ep_send_message(
* *
* The buffer is long HSK_PAYLOAD_LEN bytes * The buffer is long HSK_PAYLOAD_LEN bytes
*/ */
static void populate_hsk_buf(SBMP_Endpoint *ep, uint8_t* buf) static void FLASH_FN populate_hsk_buf(SBMP_Endpoint *ep, uint8_t* buf)
{ {
// [ pref_crc 1B | buf_size 2B ] // [ pref_crc 1B | buf_size 2B ]
@ -277,7 +277,7 @@ static void populate_hsk_buf(SBMP_Endpoint *ep, uint8_t* buf)
} }
/** Parse peer info from received handhsake dg payload */ /** Parse peer info from received handhsake dg payload */
static void parse_peer_hsk_buf(SBMP_Endpoint *ep, const uint8_t* buf) static void FLASH_FN parse_peer_hsk_buf(SBMP_Endpoint *ep, const uint8_t* buf)
{ {
ep->peer_pref_cksum = buf[0]; ep->peer_pref_cksum = buf[0];
ep->peer_buffer_size = (uint16_t)(buf[1] | (buf[2] << 8)); ep->peer_buffer_size = (uint16_t)(buf[1] | (buf[2] << 8));
@ -297,7 +297,7 @@ static void parse_peer_hsk_buf(SBMP_Endpoint *ep, const uint8_t* buf)
* @brief Start a handshake (origin bit arbitration) * @brief Start a handshake (origin bit arbitration)
* @param ep : Endpoint state * @param ep : Endpoint state
*/ */
bool sbmp_ep_start_handshake(SBMP_Endpoint *ep) bool FLASH_FN sbmp_ep_start_handshake(SBMP_Endpoint *ep)
{ {
if (ep->hsk_state == SBMP_HSK_AWAIT_REPLY) { if (ep->hsk_state == SBMP_HSK_AWAIT_REPLY) {
// busy now // busy now
@ -322,7 +322,7 @@ bool sbmp_ep_start_handshake(SBMP_Endpoint *ep)
} }
/** Get hsk state */ /** Get hsk state */
SBMP_HandshakeStatus sbmp_ep_handshake_status(SBMP_Endpoint *ep) SBMP_HandshakeStatus FLASH_FN sbmp_ep_handshake_status(SBMP_Endpoint *ep)
{ {
return ep->hsk_state; return ep->hsk_state;
} }
@ -335,7 +335,7 @@ SBMP_HandshakeStatus sbmp_ep_handshake_status(SBMP_Endpoint *ep)
* @param ep : endpoint * @param ep : endpoint
* @param dg : datagram * @param dg : datagram
*/ */
static void handle_hsk_datagram(SBMP_Endpoint *ep, SBMP_Datagram *dg) static void FLASH_FN handle_hsk_datagram(SBMP_Endpoint *ep, SBMP_Datagram *dg)
{ {
bool hsk_start = (dg->type == SBMP_DG_HSK_START); bool hsk_start = (dg->type == SBMP_DG_HSK_START);
bool hsk_accept = (dg->type == SBMP_DG_HSK_ACCEPT); bool hsk_accept = (dg->type == SBMP_DG_HSK_ACCEPT);

@ -4,24 +4,34 @@
#include "datalink.h" #include "datalink.h"
static SBMP_Endpoint *ep;
/** func used for sending bytes by SBMP */ /** 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."); sbmp_info("Datagram received.");
} }
void datalink_receive(uint8_t byte)
static SBMP_Endpoint *ep; {
sbmp_ep_receive(ep, byte);
}
/** Datalink */ /** Datalink */
void datalinkInit(void) void FLASH_FN datalinkInit(void)
{ {
ep = sbmp_ep_init(NULL, NULL, 256, dg_handler, u0_putc); ep = sbmp_ep_init(NULL, NULL, 256, dg_handler, u0_putc);
sbmp_ep_enable(ep, true);
os_printf("SBMP started on UART0\n");
} }

@ -1,6 +1,10 @@
#ifndef DATALINK_H #ifndef DATALINK_H
#define DATALINK_H #define DATALINK_H
#include <esp8266.h>
void datalinkInit(void); void datalinkInit(void);
void datalink_receive(uint8_t byte);
#endif // DATALINK_H #endif // DATALINK_H

@ -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; static int resetCnt=0;
if (!GPIO_INPUT_GET(BTNGPIO)) { if (!GPIO_INPUT_GET(BTNGPIO)) {
resetCnt++; 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_GPIO2_U, FUNC_GPIO2);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0);
gpio_output_set(0, 0, 0/*(1<<LEDGPIO)*/, (1<<BTNGPIO)); gpio_output_set(0, 0, 0/*(1<<LEDGPIO)*/, (1<<BTNGPIO));
os_timer_disarm(&resetBtntimer);
os_timer_setfn(&resetBtntimer, resetBtnTimerCb, NULL); if (GPIO_INPUT_GET(BTNGPIO) == 0) {
os_timer_arm(&resetBtntimer, 500, 1); // 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");
}
} }

@ -11,7 +11,7 @@
#include <esp8266.h> #include <esp8266.h>
#include "uart_driver.h" #include "uart_driver.h"
#include "datalink.h"
static void uart0_rx_intr_handler(void *para); 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]; static os_event_t uart_recvTaskQueue[uart_recvTaskQueueLen];
/** Clear the fifos */ /** Clear the fifos */
void ICACHE_FLASH_ATTR void FLASH_FN clear_rxtx(int uart_no)
clear_rxtx(int uart_no)
{ {
SET_PERI_REG_MASK(UART_CONF0(uart_no), UART_RXFIFO_RST | UART_TXFIFO_RST); 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); 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 * @brief Configure UART 115200-8-N-1
* @param uart_no * @param uart_no
*/ */
static void ICACHE_FLASH_ATTR static void FLASH_FN my_uart_init(UARTn uart_no)
my_uart_init(UARTn uart_no)
{ {
UART_SetParity(uart_no, PARITY_NONE); UART_SetParity(uart_no, PARITY_NONE);
UART_SetStopBits(uart_no, ONE_STOP_BIT); UART_SetStopBits(uart_no, ONE_STOP_BIT);
@ -49,7 +45,7 @@ my_uart_init(UARTn uart_no)
/** Configure basic UART func and pins */ /** Configure basic UART func and pins */
static void conf_uart_pins(void) static void FLASH_FN conf_uart_pins(void)
{ {
// U0TXD // U0TXD
PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0TXD_U, FUNC_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 */ /** Configure Rx on UART0 */
static void conf_uart_receiver(void) static void FLASH_FN conf_uart_receiver(void)
{ {
// //
// Start the Rx reading task // Start the Rx reading task
@ -98,8 +94,7 @@ static void conf_uart_receiver(void)
} }
void ICACHE_FLASH_ATTR void FLASH_FN serialInit()
serialInit()
{ {
conf_uart_pins(); conf_uart_pins();
conf_uart_receiver(); 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) #define UART_GetRxFifoCount(uart_no) ((READ_PERI_REG(UART_STATUS((uart_no))) >> UART_RXFIFO_CNT_S) & UART_RXFIFO_CNT)
static void ICACHE_FLASH_ATTR static void FLASH_FN uart_recvTask(os_event_t *events)
uart_recvTask(os_event_t *events)
{ {
if (events->sig == 0) { if (events->sig == 0) {
uint8 fifo_len = UART_GetRxFifoCount(UART0); uint8 fifo_len = UART_GetRxFifoCount(UART0);
@ -137,7 +131,9 @@ uart_recvTask(os_event_t *events)
// read from the FIFO & print back // read from the FIFO & print back
for (uint8 idx = 0; idx < fifo_len; idx++) { for (uint8 idx = 0; idx < fifo_len; idx++) {
uint8 d_tmp = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF; 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 // clear irq flags
@ -160,6 +156,8 @@ uart_recvTask(os_event_t *events)
static void static void
uart0_rx_intr_handler(void *para) uart0_rx_intr_handler(void *para)
{ {
(void)para;
uint32_t status_reg = READ_PERI_REG(UART_INT_ST(UART0)); uint32_t status_reg = READ_PERI_REG(UART_INT_ST(UART0));
if (status_reg & UART_FRM_ERR_INT_ST) { if (status_reg & UART_FRM_ERR_INT_ST) {

@ -154,9 +154,9 @@ void ICACHE_FLASH_ATTR
UART_SetPrintPort(UARTn uart_no) UART_SetPrintPort(UARTn uart_no)
{ {
if (uart_no == UART0) { if (uart_no == UART0) {
os_install_putc1(u0_putc_crlf); os_install_putc1((void *)u0_putc_crlf);
} else { } else {
os_install_putc1(u1_putc_crlf); os_install_putc1((void *)u1_putc_crlf);
} }
} }

@ -26,6 +26,8 @@
#include "datalink.h" #include "datalink.h"
#include "uart_driver.h" #include "uart_driver.h"
#include "sbmp.h"
/** /**
* @brief BasicAuth name/password checking function. * @brief BasicAuth name/password checking function.
@ -42,7 +44,7 @@
* @param passLen : password buffer size * @param passLen : password buffer size
* @return 0 to end, 1 if more users are available. * @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)connData;
(void)userLen; (void)userLen;
@ -122,6 +124,8 @@ static HttpdBuiltInUrl builtInUrls[] = {
// UART_WriteBuffer(0, (uint8_t*)t, strlen(t), 1000); // 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. * 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 // set up the debuging output
serialInit(); 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 // reset button etc
ioInit(); ioInit();

Loading…
Cancel
Save