usart rx working, some cleaning

This commit is contained in:
2016-03-16 18:31:25 +01:00
parent 5867713380
commit bb386fcbbc
17 changed files with 400 additions and 173 deletions
+2 -1
View File
@@ -28,7 +28,8 @@ XTENSA_TOOLS_ROOT ?=
# base directory of the ESP8266 SDK package, absolute
# Only used for the non-FreeRTOS build
SDK_BASE ?= /opt/Espressif/ESP8266_SDK
SDK_BASE ?= ../esp_iot_sdk_v1.5.2
#opt/Espressif/ESP8266_SDK
# Base directory of the ESP8266 FreeRTOS SDK package, absolute
# Only used for the FreeRTOS build
+8 -5
View File
@@ -9,6 +9,7 @@ int strcasecmp(const char *a, const char *b);
#ifndef FREERTOS
#include <eagle_soc.h>
#include <ets_sys.h>
#include <os_type.h>
//Missing function prototypes in include folders. Gcc will warn on these if we don't define 'em anywhere.
//MOST OF THESE ARE GUESSED! but they seem to swork and shut up the compiler.
typedef struct espconn espconn;
@@ -33,7 +34,9 @@ void ets_timer_arm_new(os_timer_t *a, int b, int c, int isMstimer);
void ets_timer_disarm(os_timer_t *a);
void ets_timer_setfn(os_timer_t *t, ETSTimerFunc *fn, void *parg);
void ets_update_cpu_frequency(int freqmhz);
int os_printf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
int os_snprintf(char *str, size_t size, const char *format, ...) __attribute__ ((format (printf, 3, 4)));
int os_printf_plus(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
void uart_div_modify(int no, unsigned int freq);
@@ -64,11 +67,11 @@ void pvPortFree(void *ptr, const char *file, int line);
#ifdef PIN_FUNC_SELECT
#undef PIN_FUNC_SELECT
#define PIN_FUNC_SELECT(PIN_NAME, FUNC) do { \
WRITE_PERI_REG(PIN_NAME, \
(READ_PERI_REG(PIN_NAME) \
& (~(PERIPHS_IO_MUX_FUNC<<PERIPHS_IO_MUX_FUNC_S))) \
|( (((FUNC&BIT2)<<2)|(FUNC&0x3))<<PERIPHS_IO_MUX_FUNC_S) ); \
} while (0)
WRITE_PERI_REG(PIN_NAME, \
(READ_PERI_REG(PIN_NAME) \
& (~(PERIPHS_IO_MUX_FUNC<<PERIPHS_IO_MUX_FUNC_S))) \
|( (((FUNC&BIT2)<<2)|(FUNC&0x3))<<PERIPHS_IO_MUX_FUNC_S) ); \
} while (0)
#endif
#endif
+19 -19
View File
@@ -1,16 +1,16 @@
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
* this notice you can do whatever you want with this stuff. If we meet some day,
* and you think this stuff is worth it, you can buy me a beer in return.
* Jeroen Domburg <jeroen@spritesmods.com> wrote this file. As long as you retain
* this notice you can do whatever you want with this stuff. If we meet some day,
* and you think this stuff is worth it, you can buy me a beer in return.
* ----------------------------------------------------------------------------
*/
/*
This is a 'captive portal' DNS server: it basically replies with a fixed IP (in this case:
the one of the SoftAP interface of this ESP module) for any and all DNS queries. This can
the one of the SoftAP interface of this ESP module) for any and all DNS queries. This can
be used to send mobile phones, tablets etc which connect to the ESP in AP mode directly to
the internal webserver.
*/
@@ -95,17 +95,17 @@ typedef struct __attribute__ ((packed)) {
//Function to put unaligned 16-bit network values
static void ICACHE_FLASH_ATTR setn16(void *pp, int16_t n) {
char *p=pp;
*p++=(n>>8);
*p++=(n&0xff);
*p++=(char)(n>>8);
*p++=(char)(n&0xff);
}
//Function to put unaligned 32-bit network values
static void ICACHE_FLASH_ATTR setn32(void *pp, int32_t n) {
char *p=pp;
*p++=(n>>24)&0xff;
*p++=(n>>16)&0xff;
*p++=(n>>8)&0xff;
*p++=(n&0xff);
*p++=(char)((n>>24)&0xff);
*p++=(char)((n>>16)&0xff);
*p++=(char)((n>>8)&0xff);
*p++=(char)(n&0xff);
}
static uint16_t ICACHE_FLASH_ATTR my_ntohs(uint16_t *in) {
@@ -114,7 +114,7 @@ static uint16_t ICACHE_FLASH_ATTR my_ntohs(uint16_t *in) {
}
//Parses a label into a C-string containing a dotted
//Parses a label into a C-string containing a dotted
//Returns pointer to start of next fields in packet
static char* ICACHE_FLASH_ATTR labelToStr(char *packet, char *labelPtr, int packetSz, char *res, int resMaxLen) {
int i, j, k;
@@ -153,7 +153,7 @@ static char ICACHE_FLASH_ATTR *strToLabel(char *str, char *label, int maxLen) {
char *p=label+1; //ptr to next label byte to be written
while (1) {
if (*str=='.' || *str==0) {
*len=((p-len)-1); //write len of label bit
*len=(char)((p-len)-1); //write len of label bit
len=p; //pos of len for next part
p++; //data ptr is one past len
if (*str==0) break; //done
@@ -183,7 +183,7 @@ static void ICACHE_FLASH_ATTR captdnsRecv(struct sockaddr_in *premote_addr, char
DnsHeader *hdr=(DnsHeader*)p;
DnsHeader *rhdr=(DnsHeader*)&reply[0];
p+=sizeof(DnsHeader);
// httpd_printf("DNS packet: id 0x%X flags 0x%X rcode 0x%X qcnt %d ancnt %d nscount %d arcount %d len %d\n",
// httpd_printf("DNS packet: id 0x%X flags 0x%X rcode 0x%X qcnt %d ancnt %d nscount %d arcount %d len %d\n",
// my_ntohs(&hdr->id), hdr->flags, hdr->rcode, my_ntohs(&hdr->qdcount), my_ntohs(&hdr->ancount), my_ntohs(&hdr->nscount), my_ntohs(&hdr->arcount), length);
//Some sanity checks:
if (length>DNS_LEN) return; //Packet is longer than DNS implementation allows
@@ -276,14 +276,14 @@ static void captdnsTask(void *pvParameters) {
socklen_t fromlen;
struct ip_info ipconfig;
char udp_msg[DNS_LEN];
memset(&ipconfig, 0, sizeof(ipconfig));
memset(&server_addr, 0, sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_family = AF_INET;
server_addr.sin_addr.s_addr = INADDR_ANY;
server_addr.sin_port = htons(53);
server_addr.sin_len = sizeof(server_addr);
do {
sockFd=socket(AF_INET, SOCK_DGRAM, 0);
if (sockFd==-1) {
@@ -291,7 +291,7 @@ static void captdnsTask(void *pvParameters) {
vTaskDelay(1000/portTICK_RATE_MS);
}
} while (sockFd==-1);
do {
ret=bind(sockFd, (struct sockaddr *)&server_addr, sizeof(server_addr));
if (ret!=0) {
@@ -307,7 +307,7 @@ static void captdnsTask(void *pvParameters) {
ret=recvfrom(sockFd, (u8 *)udp_msg, DNS_LEN, 0,(struct sockaddr *)&from,(socklen_t *)&fromlen);
if (ret>0) captdnsRecv(&from,udp_msg,ret);
}
close(sockFd);
vTaskDelete(NULL);
}
@@ -328,4 +328,4 @@ void ICACHE_FLASH_ATTR captdnsInit(void) {
espconn_create(&conn);
}
#endif
#endif