diff options
author | root <root@lamia.panaceas.james.local> | 2015-07-21 09:38:46 +0100 |
---|---|---|
committer | root <root@lamia.panaceas.james.local> | 2015-07-21 09:38:46 +0100 |
commit | 16debdbce7a5d92167207c17f18406c6905eb9b5 (patch) | |
tree | bf08771141439e0ce99565b642858143a9d74b2b | |
parent | 93a2ecba4bbb929129bbf8ff426b0829278b23d6 (diff) | |
download | polycom-16debdbce7a5d92167207c17f18406c6905eb9b5.tar.gz polycom-16debdbce7a5d92167207c17f18406c6905eb9b5.tar.bz2 polycom-16debdbce7a5d92167207c17f18406c6905eb9b5.zip |
udp
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | polycom_xmit/Makefile | 2 | ||||
-rw-r--r-- | polycom_xmit/gpio.c | 105 | ||||
-rw-r--r-- | polycom_xmit/main.c | 3 | ||||
-rw-r--r-- | polycom_xmit/msg.c | 33 | ||||
-rw-r--r-- | polycom_xmit/project.h | 2 | ||||
-rw-r--r-- | polycom_xmit/prototypes.h | 5 | ||||
-rw-r--r-- | polycom_xmit/webserver.c | 3 |
8 files changed, 150 insertions, 4 deletions
@@ -6,6 +6,7 @@ iot/ *.0 *.1 *.2 +*~ polycom_xmit/user0/ polycom_xmit/user1/ polycom_xmit/user2/ diff --git a/polycom_xmit/Makefile b/polycom_xmit/Makefile index 28166d1..3e2aae5 100644 --- a/polycom_xmit/Makefile +++ b/polycom_xmit/Makefile @@ -25,7 +25,7 @@ PROG0=${PROG}.0 PROG1=${PROG}.1 PROG2=${PROG}.2 -SRC=main.c webserver.c util.c reset.c wifi.c uart.c upgrade.c gpio.c +SRC=main.c webserver.c util.c reset.c wifi.c uart.c upgrade.c gpio.c msg.c UART_BAUD=115200 diff --git a/polycom_xmit/gpio.c b/polycom_xmit/gpio.c index 394f794..8a595ac 100644 --- a/polycom_xmit/gpio.c +++ b/polycom_xmit/gpio.c @@ -1,5 +1,77 @@ #include "project.h" + + +static struct gpio +{ + int id; + uint32_t pin; + uint32_t func; + uint32_t bit; +} gpios[] = +{ + { + 0, PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0, BIT0}, + { + 2, PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2, BIT2}, + { + 12, PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12, BIT12}, + { + 13, PERIPHS_IO_MUX_MTCK_U, FUNC_GPIO13, BIT13}, + { + 14, PERIPHS_IO_MUX_MTMS_U, FUNC_GPIO14, BIT14}, + { + 15, PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15, BIT15} +}; + +#define N_GPIOS (sizeof(gpios)/sizeof(gpios[0])) + +static os_timer_t gpio_timer; +static os_timer_t gpio_intr_timer; + + +void ICACHE_FLASH_ATTR +gpio_dispatch (void) +{ + uint32_t v = gpio_input_get (); + msg_send (v); +} + + +static void ICACHE_FLASH_ATTR +gpio_intr_timer_cb (void *arg) +{ + gpio_dispatch (); +} + + +static void ICACHE_FLASH_ATTR +gpio_timer_cb (void *arg) +{ + gpio_dispatch (); +} + + +/* Docs say you can't call os_timer_arm in an interrupt, yet the examples do */ + +static void +gpio_intr_handler (void *arg) +{ + int i; + uint32 status = GPIO_REG_READ (GPIO_STATUS_ADDRESS); + + +/* Clear any interrupts */ + for (i = 0; i < N_GPIOS; ++i) + if (status & gpios[i].bit) + GPIO_REG_WRITE (GPIO_STATUS_W1TC_ADDRESS, status & gpios[i].bit); + +/*Arm the timer*/ + os_timer_disarm (&gpio_intr_timer); + os_timer_setfn (&gpio_intr_timer, gpio_intr_timer_cb, NULL); + os_timer_arm (&gpio_intr_timer, 5, 0); +} + void ICACHE_FLASH_ATTR gpio_page (struct espconn *conn) { @@ -48,11 +120,40 @@ gpio_page (struct espconn *conn) + + + void ICACHE_FLASH_ATTR -gpio_init(void) +gpio_init (void) { + int i; + ETS_GPIO_INTR_DISABLE (); + ETS_GPIO_INTR_ATTACH (gpio_intr_handler, NULL); -} + for (i = 0; i < N_GPIOS; ++i) + { + PIN_FUNC_SELECT (gpios[i].pin, gpios[i].func); + PIN_PULLUP_EN (gpios[i].pin); + +/* disable drivers */ + gpio_output_set (0, 0, 0, gpios[i].bit); + + gpio_register_set (GPIO_PIN_ADDR (gpios[i].id), + GPIO_PIN_INT_TYPE_SET (GPIO_PIN_INTR_DISABLE) | + GPIO_PIN_PAD_DRIVER_SET (GPIO_PAD_DRIVER_DISABLE) | + GPIO_PIN_SOURCE_SET (GPIO_AS_PIN_SOURCE)); + GPIO_REG_WRITE (GPIO_STATUS_W1TC_ADDRESS, gpios[i].bit); + + gpio_pin_intr_state_set (GPIO_ID_PIN (gpios[i].id), + GPIO_PIN_INTR_ANYEDGE); + } + + ETS_GPIO_INTR_ENABLE (); + + os_timer_disarm (&gpio_timer); + os_timer_setfn (&gpio_timer, (os_timer_func_t *) gpio_timer_cb, NULL); + os_timer_arm (&gpio_timer, 10000, 1); +} diff --git a/polycom_xmit/main.c b/polycom_xmit/main.c index 2588ded..d7bc0bf 100644 --- a/polycom_xmit/main.c +++ b/polycom_xmit/main.c @@ -16,7 +16,8 @@ user_init (void) reset_init (); wifi_init (); - gpio_init(); + msg_init (); + gpio_init (); diff --git a/polycom_xmit/msg.c b/polycom_xmit/msg.c new file mode 100644 index 0000000..92931e4 --- /dev/null +++ b/polycom_xmit/msg.c @@ -0,0 +1,33 @@ +#include "project.h" + +static struct espconn udp; + + +void ICACHE_FLASH_ATTR +msg_send (uint32_t v) +{ + char buf[32]; + size_t len; + + len = os_sprintf (buf, "%x\r\n", v); + + udp.proto.udp->remote_port = 29153; + + udp.proto.udp->remote_ip[0] = 255; + udp.proto.udp->remote_ip[1] = 255; + udp.proto.udp->remote_ip[2] = 255; + udp.proto.udp->remote_ip[3] = 255; + + espconn_sent (&udp, buf, len); +} + + + +void ICACHE_FLASH_ATTR +msg_init (void) +{ + udp.type = ESPCONN_UDP; + udp.proto.udp = (esp_udp *) os_zalloc (sizeof (esp_udp)); + udp.proto.udp->local_port = 29153; + espconn_create (&udp); +} diff --git a/polycom_xmit/project.h b/polycom_xmit/project.h index f010b12..08b275a 100644 --- a/polycom_xmit/project.h +++ b/polycom_xmit/project.h @@ -18,6 +18,8 @@ #include <user_interface.h>
#include <espconn.h>
#include <upgrade.h>
+#include <gpio.h>
+#include <eagle_soc.h>
#include "uart_register.h"
diff --git a/polycom_xmit/prototypes.h b/polycom_xmit/prototypes.h index 64df8a2..0aa91dd 100644 --- a/polycom_xmit/prototypes.h +++ b/polycom_xmit/prototypes.h @@ -18,4 +18,9 @@ void uart_init(void); /* upgrade.c */ void upgrade(void); /* gpio.c */ +void gpio_dispatch(void); void gpio_page(struct espconn *conn); +void gpio_init(void); +/* msg.c */ +void msg_send(uint32_t v); +void msg_init(void); diff --git a/polycom_xmit/webserver.c b/polycom_xmit/webserver.c index 40be484..d7d6c92 100644 --- a/polycom_xmit/webserver.c +++ b/polycom_xmit/webserver.c @@ -353,6 +353,9 @@ webserver_req (struct espconn *conn, http_state * s) 0); } + + espconn_disconnect (conn); + } |