diff --git a/Makefile b/Makefile index 6f4eaf9..02ff857 100644 --- a/Makefile +++ b/Makefile @@ -39,7 +39,7 @@ USE_OPENSDK?=yes #Esptool.py path and port ESPTOOL ?= esptool.py -ESPPORT ?= /dev/ttyUSB0 +ESPPORT ?= /dev/ttyUSBblack #ESPDELAY indicates seconds to wait between flashing the two binary images ESPDELAY ?= 3 ESPBAUD ?= 115200 @@ -62,10 +62,10 @@ LIBS += esphttpd # compiler flags using during compilation of source files CFLAGS = -Os -ggdb -std=gnu99 -Werror -Wpointer-arith -Wundef -Wall -Wl,-EL -fno-inline-functions \ -nostdlib -mlongcalls -mtext-section-literals -D__ets__ -DICACHE_FLASH \ - -Wno-address + -Wno-address -ffunction-sections # 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 diff --git a/esphttpd.pro b/esp_meas.pro similarity index 99% rename from esphttpd.pro rename to esp_meas.pro index 361d074..177537b 100644 --- a/esphttpd.pro +++ b/esp_meas.pro @@ -46,7 +46,6 @@ SOURCES += \ sbmp/sbmp_checksum.c \ sbmp/sbmp_datagram.c \ sbmp/sbmp_frame.c \ - sbmp/sbmp_logging.c \ sbmp/sbmp_session.c \ user/datalink.c \ user/serial.c diff --git a/esphttpd.pro.user b/esp_meas.pro.user similarity index 96% rename from esphttpd.pro.user rename to esp_meas.pro.user index 63c03e4..7f17dff 100644 --- a/esphttpd.pro.user +++ b/esp_meas.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -65,7 +65,7 @@ 0 1 - /home/ondra/devel/esp/projects/esphttpd + /home/ondra/BP/code/esp-firmware true @@ -106,9 +106,7 @@ 2 false - - 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/ - + Debug Qt4ProjectManager.Qt4BuildConfiguration @@ -116,7 +114,7 @@ true - /home/ondra/devel/esp/projects/build-esphttpd-Desktop-Release + /home/ondra/BP/code/build-esp_meas-Desktop-Release true @@ -176,7 +174,7 @@ true - /home/ondra/devel/esp/projects/build-esphttpd-Desktop-Profile + /home/ondra/BP/code/build-esp_meas-Desktop-Profile true @@ -291,12 +289,12 @@ 2 - esphttpd + esp_meas - Qt4ProjectManager.Qt4RunConfiguration:/home/ondra/devel/esp/projects/esphttpd/esphttpd.pro + Qt4ProjectManager.Qt4RunConfiguration:/home/ondra/BP/code/esp-firmware/esp_meas.pro true - esphttpd.pro + esp_meas.pro false true @@ -348,10 +346,10 @@ 2 - flash -j 4 - /bin/make + flash + /usr/bin/make %{buildDir} - Run /bin/make + Run /usr/bin/make ProjectExplorer.CustomExecutableRunConfiguration 3768 diff --git a/libesphttpd/include/esp8266.h b/libesphttpd/include/esp8266.h index 98d03ab..57d28c2 100644 --- a/libesphttpd/include/esp8266.h +++ b/libesphttpd/include/esp8266.h @@ -22,6 +22,9 @@ #include #endif +#define FLASH_FN ICACHE_FLASH_ATTR + #include "platform.h" #include "espmissingincludes.h" +#include "esp_sdk_ver.h" diff --git a/sbmp/crc32.c b/sbmp/crc32.c index 49bae49..55c9c8e 100644 --- a/sbmp/crc32.c +++ b/sbmp/crc32.c @@ -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)) -uint32_t crc32_begin(void) +uint32_t FLASH_FN crc32_begin(void) { 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); } -uint32_t crc32_end(uint32_t crc_scratch) +uint32_t FLASH_FN crc32_end(uint32_t 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(); diff --git a/sbmp/sbmp.h b/sbmp/sbmp.h index f3f24f5..dd2de61 100644 --- a/sbmp/sbmp.h +++ b/sbmp/sbmp.h @@ -8,6 +8,8 @@ * #include in your application code. */ +#define SBMP_VER "1.3" + #include "sbmp_config.h" // Common utils & the frame parser diff --git a/sbmp/sbmp_checksum.c b/sbmp/sbmp_checksum.c index 463d6da..8ceb4ee 100644 --- a/sbmp/sbmp_checksum.c +++ b/sbmp/sbmp_checksum.c @@ -11,7 +11,7 @@ /** 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) { case SBMP_CKSUM_CRC32: return 4; @@ -23,7 +23,7 @@ uint8_t chksum_length(SBMP_CksumType cksum_type) } /** 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) { @@ -43,7 +43,7 @@ void cksum_begin(SBMP_CksumType type, uint32_t *scratch) } /** 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) { @@ -63,7 +63,7 @@ void cksum_update(SBMP_CksumType type, uint32_t *scratch, uint8_t byte) } /** 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) { @@ -83,7 +83,7 @@ void cksum_end(SBMP_CksumType type, uint32_t *scratch) } /** 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); diff --git a/sbmp/sbmp_config.h b/sbmp/sbmp_config.h index 6a932dd..01dbc74 100644 --- a/sbmp/sbmp_config.h +++ b/sbmp/sbmp_config.h @@ -44,7 +44,7 @@ * If handshake is used, the peer will detect that CRC32 is not * supported here, and should start using XOR. */ -#define SBMP_HAS_CRC32 0 +#define SBMP_HAS_CRC32 1 #endif /* ------------------------------------- */ diff --git a/sbmp/sbmp_datagram.c b/sbmp/sbmp_datagram.c index 1849624..09a48e6 100644 --- a/sbmp/sbmp_datagram.c +++ b/sbmp/sbmp_datagram.c @@ -4,7 +4,7 @@ #include "sbmp_logging.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) { 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 */ -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)) { 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 */ -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)) { sbmp_error("Failed to start datagram."); diff --git a/sbmp/sbmp_frame.c b/sbmp/sbmp_frame.c index 4e8ff22..79103a4 100644 --- a/sbmp/sbmp_frame.c +++ b/sbmp/sbmp_frame.c @@ -12,7 +12,7 @@ static void call_frame_rx_callback(SBMP_FrmInst *frm); /** Allocate the state struct & init all fields */ -SBMP_FrmInst *sbmp_frm_init( +SBMP_FrmInst FLASH_FN *sbmp_frm_init( SBMP_FrmInst *frm, uint8_t *buffer, uint16_t buffer_size, @@ -58,39 +58,39 @@ SBMP_FrmInst *sbmp_frm_init( } /** 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_tx(frm); } /** 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; } /** 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; } /** 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_tx(frm, enable); } /** 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; } /** 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_length = 0; @@ -104,7 +104,7 @@ void sbmp_frm_reset_rx(SBMP_FrmInst *frm) } /** 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_remain = 0; @@ -114,21 +114,21 @@ void sbmp_frm_reset_tx(SBMP_FrmInst *frm) } /** Update a header XOR */ -static inline +static inline FLASH_FN void hdrxor_update(SBMP_FrmInst *frm, uint8_t rxbyte) { frm->rx_hdr_xor ^= rxbyte; } /** Check header xor against received value */ -static inline +static inline FLASH_FN bool hdrxor_verify(SBMP_FrmInst *frm, uint8_t rx_xor) { return frm->rx_hdr_xor == rx_xor; } /** Append a byte to the rx buffer */ -static inline +static inline FLASH_FN void append_rx_byte(SBMP_FrmInst *frm, uint8_t 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 */ 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)); } @@ -145,7 +145,7 @@ void set_byte(uint32_t *acc, uint8_t pos, uint8_t byte) * 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) { sbmp_error("frame_handler is null!"); @@ -165,7 +165,7 @@ static void call_frame_rx_callback(SBMP_FrmInst *frm) * @param rxbyte * @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) { return SBMP_RX_DISABLED; @@ -303,7 +303,7 @@ SBMP_RxStatus sbmp_frm_receive(SBMP_FrmInst *frm, uint8_t rxbyte) } /** 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) { 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 */ -static void end_frame(SBMP_FrmInst *frm) +static void FLASH_FN end_frame(SBMP_FrmInst *frm) { if (!frm->tx_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 */ -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) { 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 */ -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) { sbmp_error("Can't tx, not enabled."); diff --git a/sbmp/sbmp_logging.c b/sbmp/sbmp_logging.c deleted file mode 100644 index 1599252..0000000 --- a/sbmp/sbmp_logging.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -#include "esp8266.h" - -#include "sbmp_config.h" -#include "sbmp_logging.h" diff --git a/sbmp/sbmp_logging.h b/sbmp/sbmp_logging.h index e6ad08b..9cf4406 100644 --- a/sbmp/sbmp_logging.h +++ b/sbmp/sbmp_logging.h @@ -9,7 +9,7 @@ */ // do-nothing definitions -#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_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__) #endif /* SBMP_COMMON_H */ diff --git a/sbmp/sbmp_session.c b/sbmp/sbmp_session.c index 75dc246..5fa16ec 100644 --- a/sbmp/sbmp_session.c +++ b/sbmp/sbmp_session.c @@ -18,7 +18,7 @@ static void handle_hsk_datagram(SBMP_Endpoint *ep, SBMP_Datagram *dg); /** 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 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 * @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, uint8_t *buffer, uint16_t buffer_size, @@ -85,7 +85,7 @@ SBMP_Endpoint *sbmp_ep_init( * * @param ep : Endpoint */ -void sbmp_ep_reset(SBMP_Endpoint *ep) +void FLASH_FN sbmp_ep_reset(SBMP_Endpoint *ep) { ep->next_session = 0; ep->origin = 0; @@ -103,19 +103,19 @@ void sbmp_ep_reset(SBMP_Endpoint *ep) // --- Customizing settings --- /** 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; } /** 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; } /** 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) { 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 */ -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); } /** 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); } /** 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); } @@ -147,7 +147,7 @@ void sbmp_ep_enable(SBMP_Endpoint *ep, bool enable) // --- /** 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; @@ -163,7 +163,7 @@ static uint16_t next_session(SBMP_Endpoint *ep) // --- Header/body send funcs --- /** 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; @@ -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 */ -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); @@ -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 */ -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); } /** 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); } /** 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); } @@ -210,7 +210,7 @@ SBMP_RxStatus sbmp_ep_receive(SBMP_Endpoint *ep, uint8_t byte) // --- All-in-one send funcs --- /** Send a message in a session. */ -bool sbmp_ep_send_response( +bool FLASH_FN sbmp_ep_send_response( SBMP_Endpoint *ep, SBMP_DgType type, const uint8_t *buffer, @@ -230,7 +230,7 @@ bool sbmp_ep_send_response( } /** Send message in a new session */ -bool sbmp_ep_send_message( +bool FLASH_FN sbmp_ep_send_message( SBMP_Endpoint *ep, SBMP_DgType type, const uint8_t *buffer, @@ -267,7 +267,7 @@ bool sbmp_ep_send_message( * * 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 ] @@ -277,7 +277,7 @@ static void populate_hsk_buf(SBMP_Endpoint *ep, uint8_t* buf) } /** 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_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) * @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) { // busy now @@ -322,7 +322,7 @@ bool sbmp_ep_start_handshake(SBMP_Endpoint *ep) } /** 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; } @@ -335,7 +335,7 @@ SBMP_HandshakeStatus sbmp_ep_handshake_status(SBMP_Endpoint *ep) * @param ep : endpoint * @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_accept = (dg->type == SBMP_DG_HSK_ACCEPT); diff --git a/user/datalink.c b/user/datalink.c index 6220856..066cd6c 100644 --- a/user/datalink.c +++ b/user/datalink.c @@ -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"); } diff --git a/user/datalink.h b/user/datalink.h index 8d1b412..84c7bcf 100644 --- a/user/datalink.h +++ b/user/datalink.h @@ -1,6 +1,10 @@ #ifndef DATALINK_H #define DATALINK_H +#include + void datalinkInit(void); +void datalink_receive(uint8_t byte); + #endif // DATALINK_H diff --git a/user/io.c b/user/io.c index 2e766b4..fae680c 100644 --- a/user/io.c +++ b/user/io.c @@ -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< #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) { diff --git a/user/uart_driver.c b/user/uart_driver.c index 96f3d09..041b6a0 100644 --- a/user/uart_driver.c +++ b/user/uart_driver.c @@ -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); } } diff --git a/user/user_main.c b/user/user_main.c index 298ae53..52459f8 100644 --- a/user/user_main.c +++ b/user/user_main.c @@ -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();