Demo starter application to connect WiGo to NSP and expose on-board sensors
Dependencies: NVIC_set_all_priorities cc3000_hostdriver_mbedsocket mbed nsdl_lib TEMT6200 TSI Wi-Go_eCompass_Lib_V3 WiGo_BattCharger
This is the mbed project for the IoT World Hackathon event, June 17th and 18th in Palo Also.
The setup instructions for participants are at the Setup page of this wiki:
Revision 16:d6812604cf92, committed 2014-06-18
- Comitter:
- sam_grove
- Date:
- Wed Jun 18 03:29:01 2014 +0000
- Parent:
- 15:6a0acd1c2e00
- Child:
- 17:b4cdafc4241d
- Commit message:
- Changed comport to 9600 baud (default for nearly all terminals); Moved UDPSocket and Endpoint to main (extern in nsdl); Added heap checking and hard fault handler; Don't register the Magnetometer
Changed in this revision
--- a/main.cpp Tue Jun 17 11:05:13 2014 +0000 +++ b/main.cpp Wed Jun 18 03:29:01 2014 +0000 @@ -16,6 +16,7 @@ #include "mbed.h" #include "cc3000.h" #include "main.h" +#include "UDPSocket.h" #include "TCPSocketConnection.h" #include "TCPSocketServer.h" #include "nsdl_support.h" @@ -57,6 +58,21 @@ TCPSocketConnection socket; +UDPSocket server; +Endpoint nsp; + +#define MEM_VALID(x) \ + int s##x=0;\ + int *h##x = new int [1];\ + std::printf("[stack]0x%08x\t[heap]0x%08x\t[memory avail]%d bytes \tLine: %d %s\r\n", &s##x, h##x, &s##x-h##x, __LINE__, __FILE__);\ + if (h##x > &s##x)\ + printf("collision\n");\ + else\ + delete [] h##x;\ + __nop() + +extern "C" void HardFault_Handler(void){MEM_VALID(0); printf("hard faulted - doh!\r\n"); while(1);} + Serial pc(USBTX, USBRX); // Slide sensor @@ -450,7 +466,7 @@ // Unlock I2C bus if blocked by a device I2C_busreset(); - pc.baud(115200); +// pc.baud(115200); // set current to 500mA since we're turning on the Wi-Fi Batt.init(CHRG_500MA); @@ -575,7 +591,7 @@ printf("\r\nAttempting SSID Connection. \r\n"); if (wifi.connect() == -1) { - printf("Failed to connect. Please verify connection details and try again. \r\n"); + error("Failed to connect. Please verify connection details and try again. \r\n"); } else { printf("Connected - IP address: %s \r\n",wifi.getIPAddress()); }
--- a/nsdl_run.cpp Tue Jun 17 11:05:13 2014 +0000 +++ b/nsdl_run.cpp Wed Jun 18 03:29:01 2014 +0000 @@ -67,8 +67,8 @@ // **************************************************************************** // NSP initialization -UDPSocket server; -Endpoint nsp; +extern UDPSocket server; +extern Endpoint nsp; static void nsp_init() { @@ -113,10 +113,10 @@ create_battery_resource(resource_ptr); create_light_resource(resource_ptr); create_temp_resource(resource_ptr); -// create_alt_resource(resource_ptr); + create_alt_resource(resource_ptr); create_slider_resource(resource_ptr); create_accel_resource(resource_ptr); - create_magnet_resource(resource_ptr); +// create_magnet_resource(resource_ptr); create_rgbled_resource(resource_ptr); /* Register with NSP */
--- a/nsdl_support.cpp Tue Jun 17 11:05:13 2014 +0000 +++ b/nsdl_support.cpp Wed Jun 18 03:29:01 2014 +0000 @@ -9,6 +9,17 @@ #include "UDPSocket.h" #include "Endpoint.h" +/* __heapvalid((__heapprt)fprintf,stdout, 1);\*/ +#define MEM_VALID(x) \ + int s##x=0;\ + int *h##x = new int [1];\ + std::printf("[stack]0x%08x\t[heap]0x%08x\t[memory avail]%d bytes \tLine: %d %s\r\n", &s##x, h##x, &s##x-h##x, __LINE__, __FILE__);\ + if (h##x > &s##x)\ + printf("collision\n");\ + else\ + delete [] h##x;\ + __nop() + extern Serial pc; extern cc3000 wifi; extern Endpoint nsp; @@ -25,12 +36,17 @@ void *nsdl_alloc(uint16_t size) { - return malloc(size); + void *buf = malloc(size); + printf("alloc\r\n"); + MEM_VALID(0); + return buf; } void nsdl_free(void* ptr_to_free) { free(ptr_to_free); + printf("de-alloc\r\n"); + MEM_VALID(0); } /*