Commit 7cc7df8c authored by Sergey Lyubka's avatar Sergey Lyubka Committed by GitHub

Merge pull request #778 from cesanta/remove_examples

Remove examples
parents e81f8373 551f393d
SDK ?= $(shell cat sdk.version)
SRC_DIR ?= $(realpath ../../..)
PORT ?= auto
.PHONY: all clean
MAKEFLAGS += w
all clean:
docker run --rm -i -v $(SRC_DIR):/src $(SDK) \
/bin/bash -c "\
make -C /src/mongoose mongoose.c mongoose.h && \
make -C /src/mongoose/examples/CC3200 -f Makefile.build $@ -$(MAKEFLAGS) \
"
ifeq ("$(PORT)", "auto")
PORT = $(shell ls -1 /dev/ttyUSB* | tail -n 1)
endif
flash:
docker run --rm -it --privileged -v $(SRC_DIR):/src $(SDK) /bin/bash -c "\
cd /usr/local/bin; \
./cc3200prog $(PORT) /src/fw/platforms/cc3200/firmware/fw.bin \
"
debug:
docker run --rm -it --privileged -v $(SRC_DIR):/src $(SDK) \
/bin/bash -c "cd /src/fw/platforms/cc3200 && tools/gdb.sh"
# -*- mode: makefile -*-
# This file is executed inside Docker build container.
# It can be used without container too if SDK_PATH is configured.
PLATFORM = CC3200
SDK_PATH ?= /cc3200-sdk
REPO_PATH ?= ../../..
BUILD_DIR ?= ./.build
FW_DIR ?= ./out
SLFS_PATH ?= ./slfs
BINDIR = $(FW_DIR)
OBJDIR = $(BUILD_DIR)
include $(SDK_PATH)/tools/gcc_scripts/makedefs
.PHONY: all clean flash
PROG = cc3200_example
IPATH = . ../.. $(REPO_PATH)
VPATH = ../..
MONGOOSE_FEATURES = -DMG_ENABLE_SSL -DMG_ENABLE_HTTP_STREAMING_MULTIPART
SDK_FLAGS = -DUSE_FREERTOS -DSL_PLATFORM_MULTI_THREADED
# -DTARGET_IS_CC3200 would reduce code size by using functions in ROM
# but then the code won't work on pre-release chips (XCC3200HZ).
CFLAGS += -Os -Wall -Werror \
$(SDK_FLAGS) -DCS_PLATFORM=4 -DCC3200_FS_SLFS \
$(MONGOOSE_FEATURES) $(CFLAGS_EXTRA)
FW_ELF = $(FW_DIR)/$(PROG).axf
FW_BIN = $(FW_DIR)/$(PROG).bin
FW_MANIFEST = $(FW_DIR)/manifest.json
FW_ZIP = $(FW_DIR)/firmware.zip
BUILD_INFO_JSON = $(OBJDIR)/build_info.json
SLFS_FILES = $(wildcard $(SLFS_PATH)/*)
.PHONY: all clean flash
all: $(OBJDIR) $(FW_DIR) $(FW_ZIP)
clean:
@rm -rf $(OBJDIR) $(wildcard *~)
@rm -rf $(FW_DIR) $(wildcard *~)
$(OBJDIR):
@echo " MKDIR $@"
@mkdir -p $(OBJDIR) $(FS_BUILD_DIR)
$(FW_DIR):
@echo " MKDIR $@"
@mkdir -p $(FW_DIR)
$(FW_ZIP): $(FW_ELF) $(FW_BIN) $(SLFS_FILES)
@echo " Code size: $(shell ls -l $(FW_BIN) | awk '{print $$5}')"
@echo " GEN $(FW_MANIFEST)"
@fw_meta gen_build_info \
--json_output=$(BUILD_INFO_JSON)
@cp -v $(SLFS_FILES) out/
@cp $(CC3200_SP_FILE)* $(FW_DIR)
@fw_meta create_manifest \
--name=$(PROG) --platform=$(PLATFORM) \
--build_info=$(BUILD_INFO_JSON) \
--output=$(FW_MANIFEST) \
--src_dir=$(FW_DIR) \
/sys/servicepack.ucf:type=slfile,src=$(CC3200_SP_FILE),falloc=60416,sign=$(notdir $(CC3200_SP_FILE)).sign \
$(notdir $(CC3200_SP_FILE)).sign:type=signature,src=$(CC3200_SP_FILE).sign \
/sys/mcuimg.bin:type=app,src=$(notdir $(FW_BIN)) \
$(foreach f,$(SLFS_FILES), $(notdir $(f)):type=slfile,src=$(notdir $(f)))
@echo " ZIP $@"
@fw_meta create_fw \
--manifest=$(FW_MANIFEST) \
--src_dir=$(FW_DIR) \
--output=$@
FREERTOS_SRCS = timers.c list.c queue.c tasks.c port.c heap_3.c osi_freertos.c
DRIVER_SRCS = cpu.c gpio.c gpio_if.c i2c.c i2c_if.c interrupt.c pin.c prcm.c spi.c uart.c udma.c utils.c
SL_SRCS = socket.c wlan.c driver.c device.c netapp.c netcfg.c network_common.c cc_pal.c fs.c
SDK_SRCS = startup_gcc.c $(FREERTOS_SRCS) $(DRIVER_SRCS) $(SL_SRCS)
IPATH += $(SDK_PATH) $(SDK_PATH)/inc $(SDK_PATH)/driverlib \
$(SDK_PATH)/example/common $(SDK_PATH)/oslib \
$(SDK_PATH)/simplelink $(SDK_PATH)/simplelink/include \
$(SDK_PATH)/simplelink_extlib/provisioninglib \
$(SDK_PATH)/third_party/FreeRTOS/source \
$(SDK_PATH)/third_party/FreeRTOS/source/include \
$(SDK_PATH)/third_party/FreeRTOS/source/portable/GCC/ARM_CM4
VPATH += $(SDK_PATH)/driverlib $(SDK_PATH)/example/common $(SDK_PATH)/oslib \
$(SDK_PATH)/simplelink $(SDK_PATH)/simplelink/source \
$(SDK_PATH)/third_party/FreeRTOS/source \
$(SDK_PATH)/third_party/FreeRTOS/source/portable/GCC/ARM_CM4 \
$(SDK_PATH)/third_party/FreeRTOS/source/portable/MemMang \
APP_SRCS = main.c bm222.c data.c mongoose.c tmp006.c wifi.c $(SDK_SRCS)
APP_OBJS = $(addprefix $(OBJDIR)/,$(patsubst %.c,%.o,$(APP_SRCS)))
$(FW_ELF): $(APP_OBJS)
SCATTERgcc_$(PROG) = $(PROG).ld
ENTRY_$(PROG) = ResetISR
# Disable certain warnings on SDK sources, we have no control over them anyway.
SDK_OBJS = $(addprefix $(OBJDIR)/,$(patsubst %.c,%.o,$(SDK_SRCS)))
$(SDK_OBJS): CFLAGS += -include mongoose.h -Wno-missing-braces -Wno-strict-aliasing -Wno-parentheses -Wno-unused-variable
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#include "bm222.h"
#include "mongoose.h"
#include "cs_dbg.h"
#include "i2c_if.h"
#define BM222_REG_FIFO_STATUS 0x0e
#define BM222_REG_PMU_BW 0x10
#define BM222_PMU_BW_7_81_HZ 0x8
#define BM222_PMU_BW_31_25_HZ 0xA
#define BM222_PMU_BW_62_5_HZ 0xB
#define BM222_PMU_BW_125_HZ 0xC
#define BM222_REG_BGW_SOFTRESET 0x14
#define BM222_DO_SOFT_RESET 0xB6
#define BM222_REG_FIFO_CONFIG_1 0x3e
#define BM222_FIFO_MODE_FIFO 0x40
#define BM222_FIFO_DATA_ALL 0
#define BM222_REG_FIFO_DATA 0x3f
struct bm222_ctx *bm222_init(uint8_t addr) {
struct bm222_ctx *ctx = (struct bm222_ctx *) calloc(1, sizeof(*ctx));
if (ctx == NULL) return NULL;
ctx->addr = addr;
{
unsigned char val[2] = {BM222_REG_BGW_SOFTRESET, BM222_DO_SOFT_RESET};
if (I2C_IF_Write(addr, val, 2, 1) != 0) goto out_err;
osi_Sleep(2 /* ms */); /* t_w,up1 = 1.8 ms */
}
if (!bm222_fifo_init(ctx)) return false;
{
unsigned char val[2] = {BM222_REG_PMU_BW, BM222_PMU_BW_125_HZ};
if (I2C_IF_Write(addr, val, 2, 1) != 0) goto out_err;
}
return ctx;
out_err:
free(ctx);
return NULL;
}
bool bm222_fifo_init(struct bm222_ctx *ctx) {
unsigned char val[2] = {BM222_REG_FIFO_CONFIG_1,
BM222_FIFO_MODE_FIFO | BM222_FIFO_DATA_ALL};
return (I2C_IF_Write(ctx->addr, val, 2, 1) == 0);
}
bool bm222_get_data(struct bm222_ctx *ctx) {
unsigned char reg = BM222_REG_FIFO_STATUS;
unsigned char val;
if (I2C_IF_ReadFrom(ctx->addr, &reg, 1, &val, 1) < 0) return false;
unsigned char len = (val & 0x7f);
unsigned char overflow = (val & 0x80 ? 1 : 0);
LOG(LL_DEBUG, ("FIFO len: %d (ovf? %d)", len, overflow));
reg = BM222_REG_FIFO_DATA;
int8_t fifo[32 * 6], *v = fifo;
if (I2C_IF_ReadFrom(ctx->addr, &reg, 1, (unsigned char *) fifo, len * 6) <
0) {
return false;
}
double now = mg_time();
/* Of potentially multiple samples, pick one with maximum difference. */
int32_t max_d = 0;
bool sampled = false;
struct bm222_sample *ls = ctx->data + ctx->last_index, *s = NULL;
if (ls->ts == 0) {
/* The very first sample. */
ls->ts = now;
ls->x = v[1];
ls->y = v[3];
ls->z = v[5];
v += 6;
len--;
sampled = true;
s = ls;
}
for (; len > 0; v += 6, len--) {
int32_t dx = ((int32_t) v[1]) - ((int32_t) ls->x);
int32_t dy = ((int32_t) v[3]) - ((int32_t) ls->y);
int32_t dz = ((int32_t) v[5]) - ((int32_t) ls->z);
int32_t d = dx * dx + dy * dy + dz * dz;
if ((d > 2 && d > max_d) || (!sampled && now - ls->ts > 1.0)) {
if (!sampled) {
ctx->last_index = (ctx->last_index + 1) % BM222_NUM_SAMPLES;
s = ctx->data + ctx->last_index;
sampled = true;
}
s->ts = now;
s->x = v[1];
s->y = v[3];
s->z = v[5];
if (d > max_d) max_d = d;
LOG(LL_VERBOSE_DEBUG, ("dx %d dy %d dz %d d %d", dx, dy, dz, d));
}
}
return (overflow ? bm222_fifo_init(ctx) : true); /* Clear the ovf flag. */
}
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_MONGOOSE_EXAMPLES_CC3200_BM222_H_
#define CS_MONGOOSE_EXAMPLES_CC3200_BM222_H_
#include <inttypes.h>
#include <stdbool.h>
#define BM222_NUM_SAMPLES 64
struct bm222_ctx {
uint8_t addr;
struct bm222_sample {
double ts;
int8_t x;
int8_t y;
int8_t z;
} data[BM222_NUM_SAMPLES];
int last_index;
};
struct bm222_ctx *bm222_init(uint8_t addr);
bool bm222_fifo_init(struct bm222_ctx *ctx);
bool bm222_get_data(struct bm222_ctx *ctx);
#endif /* CS_MONGOOSE_EXAMPLES_CC3200_BM222_H_ */
/*****************************************************************************
* app.ld
*
* GCC Linker script for Mongoose OS. Based on TI's example "blinky.ld".
*
* Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************/
HEAP_SIZE = 0xB000;
MEMORY
{
/* SRAM size of 240KB (0x3C000) for cc3200 ES 1.33 device onward,
* 176KB (0x2C000) for XCC3200HZ (pre-release device). */
SRAM (rwx) : ORIGIN = 0x20004000, LENGTH = 0x3C000
}
SECTIONS
{
.text :
{
_text = .;
KEEP(*(.intvecs))
*(.text*)
*(.rodata*)
*(.ARM.extab* .gnu.linkonce.armextab.*)
. = ALIGN(8);
_etext = .;
} > SRAM
.ARM : {
__exidx_start = .;
*(.ARM.exidx*)
__exidx_end = .;
} > SRAM
__init_data = .;
.data : AT(__init_data)
{
_data = .;
*(.data*)
. = ALIGN (8);
_edata = .;
} > SRAM
.bss :
{
_bss = .;
*(.bss*)
*(COMMON)
_ebss = .;
} > SRAM
.heap :
{
_heap = .;
. = . + HEAP_SIZE;
. = ALIGN(8);
_eheap = .;
}
}
<?xml version="1.0" encoding="UTF-8" ?>
<?ccsproject version="1.0"?>
<projectOptions>
<deviceVariant value="Cortex M.CC3200"/>
<deviceFamily value="TMS470"/>
<deviceEndianness value="little"/>
<codegenToolVersion value="5.2.7"/>
<isElfFormat value="true"/>
<connection value="common/targetdb/connections/Stellaris_ICDI_Connection.xml"/>
<linkerCommandFile value="cc3200v1p32.cmd"/>
<rts value="libc.a"/>
<createSlaveProjects value=""/>
<templateProperties value="id=com.ti.common.project.core.emptyProjectWithMainTemplate,"/>
<isTargetManual value="false"/>
</projectOptions>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MG_hello</name>
<comment></comment>
<projects>
<project>Mongoose</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.ti.ccstudio.core.ccsNature</nature>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<linkedResources>
<link>
<name>gpio_if.c</name>
<type>1</type>
<locationURI>CC3200_SDK_ROOT/example/common/gpio_if.c</locationURI>
</link>
<link>
<name>network_common.c</name>
<type>1</type>
<locationURI>CC3200_SDK_ROOT/example/common/network_common.c</locationURI>
</link>
<link>
<name>startup_ccs.c</name>
<type>1</type>
<locationURI>CC3200_SDK_ROOT/example/common/startup_ccs.c</locationURI>
</link>
<link>
<name>wifi.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/wifi.c</locationURI>
</link>
<link>
<name>wifi.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/wifi.h</locationURI>
</link>
</linkedResources>
<variableList>
<variable>
<name>CC3200_SDK_ROOT</name>
<value>$%7BTI_PRODUCTS_DIR%7D/CC3200SDK_1.2.0/cc3200-sdk</value>
</variable>
</variableList>
</projectDescription>
//*****************************************************************************
// cc3200v1p32.cmd
//
// CCS linker configuration file for cc3200 ES 1.32.
//
// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//*****************************************************************************
--retain=g_pfnVectors
//*****************************************************************************
// The following command line options are set as part of the CCS project.
// If you are building using the command line, or for some reason want to
// define them here, you can uncomment and modify these lines as needed.
// If you are using CCS for building, it is probably better to make any such
// modifications in your CCS project and leave this file alone.
//*****************************************************************************
//*****************************************************************************
// The starting address of the application. Normally the interrupt vectors
// must be located at the beginning of the application.
//*****************************************************************************
#define RAM_BASE 0x20004000
/* System memory map */
MEMORY
{
/* Application uses internal RAM for program and data */
SRAM_CODE (RWX) : origin = 0x20004000, length = 0x20000
SRAM_DATA (RWX) : origin = 0x20024000, length = 0x1C000
}
/* Section allocation in memory */
SECTIONS
{
.intvecs: > RAM_BASE
.init_array : > SRAM_CODE
.vtable : > SRAM_CODE
.text : > SRAM_CODE
.const : > SRAM_CODE
.cinit : > SRAM_CODE
.pinit : > SRAM_CODE
.data : > SRAM_DATA
.bss : > SRAM_DATA
.sysmem : > SRAM_DATA
.stack : > SRAM_DATA(HIGH)
}
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
/* Set up an AP or connect to existing WiFi network. */
#define WIFI_AP_SSID "Mongoose"
#define WIFI_AP_PASS ""
#define WIFI_AP_CHAN 6
// #define WIFI_STA_SSID "YourWiFi"
// #define WIFI_STA_PASS "YourPass"
#define MGOS_TASK_PRIORITY 3
#define MG_TASK_STACK_SIZE 8192
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inc/hw_types.h>
#include <inc/hw_ints.h>
#include <inc/hw_memmap.h>
#include <driverlib/gpio.h>
#include <driverlib/interrupt.h>
#include <driverlib/pin.h>
#include <driverlib/prcm.h>
#include <driverlib/rom.h>
#include <driverlib/rom_map.h>
#include <example/common/gpio_if.h>
/* Mongoose.h brings in SimpleLink support. Do not include simplelink.h. */
#include <mongoose.h>
#include <simplelink/include/device.h>
#include "cs_dbg.h"
#include "wifi.h"
void fs_slfs_set_new_file_size(const char *name, size_t size);
static const char *upload_form =
"\
<h1>Upload file</h1> \
<form action='/upload' method='POST' enctype='multipart/form-data'> \
<input type='file' name='file'> \
<input type='submit' value='Upload'> \
</form>";
static struct mg_str upload_fname(struct mg_connection *nc,
struct mg_str fname) {
struct mg_str lfn;
char *fn = malloc(fname.len + 4);
memcpy(fn, "SL:", 3);
memcpy(fn + 3, fname.p, fname.len);
fn[3 + fname.len] = '\0';
if (nc->user_data != NULL) {
intptr_t cl = (intptr_t) nc->user_data;
if (cl >= 0) {
fs_slfs_set_new_file_size(fn + 3, cl);
}
}
lfn.len = fname.len + 4;
lfn.p = fn;
return lfn;
}
void mg_ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
LOG(LL_DEBUG, ("%p ev %d", nc, ev));
switch (ev) {
case MG_EV_ACCEPT: {
char addr[32];
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
LOG(LL_INFO, ("Connection %p from %s", nc, addr));
break;
}
case MG_EV_HTTP_REQUEST: {
char addr[32];
struct http_message *hm = (struct http_message *) ev_data;
cs_stat_t st;
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
LOG(LL_INFO,
("HTTP request from %s: %.*s %.*s", addr, (int) hm->method.len,
hm->method.p, (int) hm->uri.len, hm->uri.p));
if (mg_vcmp(&hm->uri, "/upload") == 0 ||
(mg_vcmp(&hm->uri, "/") == 0 && mg_stat("SL:index.html", &st) != 0)) {
mg_send(nc, upload_form, strlen(upload_form));
nc->flags |= MG_F_SEND_AND_CLOSE;
break;
}
struct mg_serve_http_opts opts;
memset(&opts, 0, sizeof(opts));
opts.document_root = "SL:";
mg_serve_http(nc, hm, opts);
break;
}
case MG_EV_CLOSE: {
LOG(LL_INFO, ("Connection %p closed", nc));
break;
}
/* SimpleLink FS requires pre-declaring max file size. We use Content-Length
* for that purpose - it will not exactly match file size, but is guaranteed
* to exceed it and should be close enough. */
case MG_EV_HTTP_MULTIPART_REQUEST: {
struct http_message *hm = (struct http_message *) ev_data;
struct mg_str *cl_header = mg_get_http_header(hm, "Content-Length");
intptr_t cl = -1;
if (cl_header != NULL && cl_header->len < 20) {
char buf[20];
memcpy(buf, cl_header->p, cl_header->len);
buf[cl_header->len] = '\0';
cl = atoi(buf);
if (cl < 0) cl = -1;
}
nc->user_data = (void *) cl;
break;
}
case MG_EV_HTTP_PART_BEGIN:
case MG_EV_HTTP_PART_DATA:
case MG_EV_HTTP_PART_END: {
struct mg_http_multipart_part *mp =
(struct mg_http_multipart_part *) ev_data;
if (ev == MG_EV_HTTP_PART_BEGIN) {
LOG(LL_INFO, ("Begin file upload: %s", mp->file_name));
} else if (ev == MG_EV_HTTP_PART_END) {
LOG(LL_INFO, ("End file upload: %s", mp->file_name));
}
mg_file_upload_handler(nc, ev, ev_data, upload_fname);
}
}
}
static void mg_init(struct mg_mgr *mgr) {
LOG(LL_INFO, ("MG task running"));
stop_nwp(); /* See function description in wifi.c */
LOG(LL_INFO, ("Starting NWP..."));
int role = sl_Start(0, 0, 0);
if (role < 0) {
LOG(LL_ERROR, ("Failed to start NWP"));
return;
}
LOG(LL_INFO, ("NWP started"));
sl_fs_init();
#if defined(WIFI_STA_SSID)
if (!wifi_setup_sta(WIFI_STA_SSID, WIFI_STA_PASS)) {
LOG(LL_ERROR, ("Error setting up WiFi station"));
}
#elif defined(WIFI_AP_SSID)
if (!wifi_setup_ap(WIFI_AP_SSID, WIFI_AP_PASS, WIFI_AP_CHAN)) {
LOG(LL_ERROR, ("Error setting up WiFi AP"));
}
#else
#error WiFi not configured
#endif
/* We don't need SimpleLink's web server. */
sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID);
const char *err = "";
struct mg_bind_opts opts;
memset(&opts, 0, sizeof(opts));
opts.error_string = &err;
struct mg_connection *nc = mg_bind(mgr, "80", mg_ev_handler);
if (nc != NULL) {
mg_set_protocol_http_websocket(nc);
} else {
LOG(LL_ERROR, ("Failed to create listener: %s", err));
}
}
#ifndef USE_TIRTOS
/* Int vector table, defined in startup_gcc.c */
extern void (*const g_pfnVectors[])(void);
#endif
int main(void) {
#ifndef USE_TIRTOS
MAP_IntVTableBaseSet((unsigned long) &g_pfnVectors[0]);
#endif
MAP_IntEnable(FAULT_SYSTICK);
MAP_IntMasterEnable();
PRCMCC3200MCUInit();
setvbuf(stdout, NULL, _IOLBF, 0);
setvbuf(stderr, NULL, _IOLBF, 0);
cs_log_set_level(LL_INFO);
cs_log_set_file(stdout);
LOG(LL_INFO, ("Hello, world!"));
/* Set up the red LED. Note that amber and green cannot be used as they share
* pins with I2C. */
MAP_PRCMPeripheralClkEnable(PRCM_GPIOA1, PRCM_RUN_MODE_CLK);
MAP_PinTypeGPIO(PIN_64, PIN_MODE_0, false);
MAP_GPIODirModeSet(GPIOA1_BASE, 0x2, GPIO_DIR_MODE_OUT);
GPIO_IF_LedConfigure(LED1);
GPIO_IF_LedOn(MCU_RED_LED_GPIO);
if (VStartSimpleLinkSpawnTask(8) != 0) {
LOG(LL_ERROR, ("Failed to create SL task"));
}
if (!mg_start_task(MGOS_TASK_PRIORITY, MG_TASK_STACK_SIZE, mg_init)) {
LOG(LL_ERROR, ("Failed to create MG task"));
}
osi_start();
return 0;
}
/* These are FreeRTOS hooks for various life situations. */
void vApplicationMallocFailedHook(void) {
}
void vApplicationIdleHook(void) {
}
void vApplicationStackOverflowHook(OsiTaskHandle *th, signed char *tn) {
}
void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *e,
SlHttpServerResponse_t *resp) {
}
void SimpleLinkSockEventHandler(SlSockEvent_t *e) {
}
void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *e) {
LOG(LL_ERROR, ("status %d sender %d", e->EventData.deviceEvent.status,
e->EventData.deviceEvent.sender));
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<configurations XML_version="1.2" id="configurations_0">
<configuration XML_version="1.2" id="configuration_0">
<instance XML_version="1.2" desc="Stellaris In-Circuit Debug Interface" href="connections/Stellaris_ICDI_Connection.xml" id="Stellaris In-Circuit Debug Interface" xml="Stellaris_ICDI_Connection.xml" xmlpath="connections"/>
<connection XML_version="1.2" id="Stellaris In-Circuit Debug Interface">
<instance XML_version="1.2" href="drivers/cc3200_cs_icepick.xml" id="drivers" xml="cc3200_cs_icepick.xml" xmlpath="drivers"/>
<instance XML_version="1.2" href="drivers/stellaris_cs_dap.xml" id="drivers" xml="stellaris_cs_dap.xml" xmlpath="drivers"/>
<instance XML_version="1.2" href="drivers/cc3200_cortex_m4.xml" id="drivers" xml="cc3200_cortex_m4.xml" xmlpath="drivers"/>
<platform XML_version="1.2" id="platform_0">
<instance XML_version="1.2" desc="CC3200" href="devices/CC3200.xml" id="CC3200" xml="CC3200.xml" xmlpath="devices"/>
</platform>
</connection>
</configuration>
</configurations>
The 'targetConfigs' folder contains target-configuration (.ccxml) files, automatically generated based
on the device and connection settings specified in your project on the Properties > General page.
Please note that in automatic target-configuration management, changes to the project's device and/or
connection settings will either modify an existing or generate a new target-configuration file. Thus,
if you manually edit these auto-generated files, you may need to re-apply your changes. Alternatively,
you may create your own target-configuration file for this project and manage it manually. You can
always switch back to automatic target-configuration management by checking the "Manage the project's
target-configuration automatically" checkbox on the project's Properties > General page.
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" ?>
<?ccsproject version="1.0"?>
<projectOptions>
<deviceVariant value="Cortex M.CC3200"/>
<deviceFamily value="TMS470"/>
<deviceEndianness value="little"/>
<codegenToolVersion value="5.2.7"/>
<isElfFormat value="true"/>
<connection value="common/targetdb/connections/Stellaris_ICDI_Connection.xml"/>
<linkerCommandFile value="cc3200v1p32.cmd"/>
<rts value="libc.a"/>
<createSlaveProjects value=""/>
<templateProperties value="id=com.ti.common.project.core.emptyProjectWithMainTemplate,"/>
<isTargetManual value="false"/>
</projectOptions>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MG_sensor_demo</name>
<comment></comment>
<projects>
<project>Mongoose</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.ti.ccstudio.core.ccsNature</nature>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<linkedResources>
<link>
<name>bm222.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/bm222.c</locationURI>
</link>
<link>
<name>bm222.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/bm222.h</locationURI>
</link>
<link>
<name>data.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/data.c</locationURI>
</link>
<link>
<name>data.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/data.h</locationURI>
</link>
<link>
<name>gpio_if.c</name>
<type>1</type>
<locationURI>CC3200_SDK_ROOT/example/common/gpio_if.c</locationURI>
</link>
<link>
<name>i2c_if.c</name>
<type>1</type>
<locationURI>CC3200_SDK_ROOT/example/common/i2c_if.c</locationURI>
</link>
<link>
<name>main.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/main.c</locationURI>
</link>
<link>
<name>network_common.c</name>
<type>1</type>
<locationURI>CC3200_SDK_ROOT/example/common/network_common.c</locationURI>
</link>
<link>
<name>startup_ccs.c</name>
<type>1</type>
<locationURI>CC3200_SDK_ROOT/example/common/startup_ccs.c</locationURI>
</link>
<link>
<name>tmp006.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/tmp006.c</locationURI>
</link>
<link>
<name>tmp006.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/tmp006.h</locationURI>
</link>
<link>
<name>wifi.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/wifi.c</locationURI>
</link>
<link>
<name>wifi.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/wifi.h</locationURI>
</link>
</linkedResources>
<variableList>
<variable>
<name>CC3200_SDK_ROOT</name>
<value>$%7BTI_PRODUCTS_DIR%7D/CC3200SDK_1.2.0/cc3200-sdk</value>
</variable>
</variableList>
</projectDescription>
//*****************************************************************************
// cc3200v1p32.cmd
//
// CCS linker configuration file for cc3200 ES 1.32.
//
// Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/
//
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions
// are met:
//
// Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the
// distribution.
//
// Neither the name of Texas Instruments Incorporated nor the names of
// its contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
//*****************************************************************************
--retain=g_pfnVectors
//*****************************************************************************
// The following command line options are set as part of the CCS project.
// If you are building using the command line, or for some reason want to
// define them here, you can uncomment and modify these lines as needed.
// If you are using CCS for building, it is probably better to make any such
// modifications in your CCS project and leave this file alone.
//*****************************************************************************
//*****************************************************************************
// The starting address of the application. Normally the interrupt vectors
// must be located at the beginning of the application.
//*****************************************************************************
#define RAM_BASE 0x20004000
/* System memory map */
MEMORY
{
/* Application uses internal RAM for program and data */
SRAM_CODE (RWX) : origin = 0x20004000, length = 0x20000
SRAM_DATA (RWX) : origin = 0x20024000, length = 0x1C000
}
/* Section allocation in memory */
SECTIONS
{
.intvecs: > RAM_BASE
.init_array : > SRAM_CODE
.vtable : > SRAM_CODE
.text : > SRAM_CODE
.const : > SRAM_CODE
.cinit : > SRAM_CODE
.pinit : > SRAM_CODE
.data : > SRAM_DATA
.bss : > SRAM_DATA
.sysmem : > SRAM_DATA
.stack : > SRAM_DATA(HIGH)
}
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<configurations XML_version="1.2" id="configurations_0">
<configuration XML_version="1.2" id="configuration_0">
<instance XML_version="1.2" desc="Stellaris In-Circuit Debug Interface" href="connections/Stellaris_ICDI_Connection.xml" id="Stellaris In-Circuit Debug Interface" xml="Stellaris_ICDI_Connection.xml" xmlpath="connections"/>
<connection XML_version="1.2" id="Stellaris In-Circuit Debug Interface">
<instance XML_version="1.2" href="drivers/cc3200_cs_icepick.xml" id="drivers" xml="cc3200_cs_icepick.xml" xmlpath="drivers"/>
<instance XML_version="1.2" href="drivers/stellaris_cs_dap.xml" id="drivers" xml="stellaris_cs_dap.xml" xmlpath="drivers"/>
<instance XML_version="1.2" href="drivers/cc3200_cortex_m4.xml" id="drivers" xml="cc3200_cortex_m4.xml" xmlpath="drivers"/>
<platform XML_version="1.2" id="platform_0">
<instance XML_version="1.2" desc="CC3200" href="devices/CC3200.xml" id="CC3200" xml="CC3200.xml" xmlpath="devices"/>
</platform>
</connection>
</configuration>
</configurations>
The 'targetConfigs' folder contains target-configuration (.ccxml) files, automatically generated based
on the device and connection settings specified in your project on the Properties > General page.
Please note that in automatic target-configuration management, changes to the project's device and/or
connection settings will either modify an existing or generate a new target-configuration file. Thus,
if you manually edit these auto-generated files, you may need to re-apply your changes. Alternatively,
you may create your own target-configuration file for this project and manage it manually. You can
always switch back to automatic target-configuration management by checking the "Manage the project's
target-configuration automatically" checkbox on the project's Properties > General page.
\ No newline at end of file
clean:
rm -rf */Debug */Release */.launches */.settings */.xdchelp */src
<?xml version="1.0" encoding="UTF-8" ?>
<?ccsproject version="1.0"?>
<projectOptions>
<deviceVariant value="Cortex M.CC3200"/>
<deviceFamily value="TMS470"/>
<deviceEndianness value="little"/>
<codegenToolVersion value="5.2.7"/>
<isElfFormat value="true"/>
<connection value="common/targetdb/connections/Stellaris_ICDI_Connection.xml"/>
<createSlaveProjects value=""/>
<templateProperties value="id=com.ti.common.project.core.emptyProjectWithMainTemplate,"/>
<isTargetManual value="false"/>
</projectOptions>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Mongoose</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>com.ti.ccstudio.core.ccsNature</nature>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
<linkedResources>
<link>
<name>mongoose.c</name>
<type>1</type>
<locationURI>PARENT-4-PROJECT_LOC/mongoose.c</locationURI>
</link>
<link>
<name>mongoose.h</name>
<type>1</type>
<locationURI>PARENT-4-PROJECT_LOC/mongoose.h</locationURI>
</link>
</linkedResources>
<variableList>
<variable>
<name>CC3200_SDK_ROOT</name>
<value>$%7BTI_PRODUCTS_DIR%7D/CC3200SDK_1.2.0/cc3200-sdk</value>
</variable>
</variableList>
</projectDescription>
# Code Composer Studio example projects
To run them you will need:
- [CC3200-LAUNCHXL](http://www.ti.com/tool/cc3200-launchxl) dev board.
- [CC3200SDK 1.2.0](http://www.ti.com/tool/cc3200sdk) installed in `TI_PRODUCTS_DIR/CC3200SDK_1.2.0` (typically `C:\ti\CC3200SDK_1.2.0` on Windows, `/home/USER/ti/CC3200SDK_1.2.0` on Linux).
- The latest CC3200SDK-SERVICEPACK should also be installed and flashed to the device
- Code Composer Studio 6 IDE
- Mongoose source code. Either clone the [Git repo](https://github.com/cesanta/mongoose.git) or download the [ZIP archive](https://github.com/cesanta/mongoose/archive/master.zip).
## Mongoose - The library project
This project produces `Mongoose.lib` - a static library meant to be used by other projects.
Feel free to use it as a dependency for your own projects or just copy `mongoose.c` and `mongoose.h`.
Note that by default a lot of features are enabled, including file serving (which we use in our examples).
You can trim a lot of fat by turning various build options off.
A minimal HTTP serving configuration is about 25 K (compiled for ARM® Cortex®M4 with GCC 4.9 with size optimization on).
## MG_hello - A simple demo
MG_hello project is a simple web server that serves files from the SimpleLink file system and allows them to be uploaded.
This project depends on the Mongoose library project, make sure you import them both.
When importing, ensure the “copy project to workspace” checkbox is *unchecked*, otherwise file references will be broken.
When built and run on the device, by default, the example will set up a Wi-Fi network called “Mongoose” (no password).
Assuming everything works, you should see the following output in CIO:
```
main Hello, world!
mg_init MG task running
mg_init Starting NWP...
mg_init NWP started
wifi_setup_ap WiFi: AP Mongoose configured
```
Note: If the demo does not proceed past “Starting NWP…”, please reset the board (possibly related to [this](https://e2e.ti.com/support/wireless_connectivity/simplelink_wifi_cc31xx_cc32xx/f/968/p/499123/1806610#1806610) and our [workaround](https://github.com/cesanta/mongoose/commit/848c884fff80de03051344e230392a68d4b51b84) is not always effective).
And after connecting to Wi-Fi network Mongoose, the following page on http://192.168.4.1/:
<img src="upload_form.png" width="364" height="239">
Pick a small file (say favicon.ico) and upload.
You should get “Ok, favicon.ico - 16958 bytes.” and it will be served back to you ([link](http://192.168.4.1/)).
If you upload index.html, it will be served instead of the form (but the form will be accessible at [/upload](http://192.168.4.1/upload)).
## MG_sensor_demo - A more elaborate demo project
This demo shows the use of [timers](https://docs.cesanta.com/mongoose/latest/#/c-api/net.h/mg_set_timer/) and serving a WebSocket data stream to (potentially) multiple subscribers.
Data from the on-board temperature sensors and accelerometer is streamed to any clients connected over WebSocket, which allows building of responsive, near-real time dashboards.
The main [event handler function](https://github.com/cesanta/mongoose/blob/master/examples/CC3200/main.c#L81) in main.c does everything MG_hello’s function does, but also handles the websocket connection event - when `MG_EV_WEBSOCKET_HANDSHAKE_DONE` arrives, it switches the event handler to a different one - data_conn_handler (defined [here](https://github.com/cesanta/mongoose/blob/master/examples/CC3200/data.c#L144) in data.c). Doing this is not required, but it keeps the code modular and function size manageable.
Data acquisition is performed at regular intervals by a timer. Mongoose timers are not very accurate (remember - everything is executed in single thread), but good enough for this case.The timer is first set [in mg_init()](https://github.com/cesanta/mongoose/blob/master/examples/CC3200/main.c#L200), and the `MG_EV_TIMER` event is handled [in the main handler](https://github.com/cesanta/mongoose/blob/master/examples/CC3200/main.c#L123). Mongoose timers must be re-armed manually.
To try this demo from Code Composer Studio IDE, follow the steps above for MG_hello. Same as for MG_hello, you will only see an upload for initially. Please upload `main.js` and `index.html` from the [slfs directory](https://github.com/cesanta/mongoose/tree/master/examples/CC3200/slfs) and reload the page. You should see something like this:
<img src="sensor_demo.png" width="770" height="856">
[This short video](https://youtu.be/T0aFUKIBZxk) shows the demo in action.
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_COMMON_CS_DBG_H_
#define CS_COMMON_CS_DBG_H_
#if CS_ENABLE_STDIO
#include <stdio.h>
#endif
#ifndef CS_ENABLE_DEBUG
#define CS_ENABLE_DEBUG 0
#endif
#ifndef CS_LOG_ENABLE_TS_DIFF
#define CS_LOG_ENABLE_TS_DIFF 0
#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
enum cs_log_level {
LL_NONE = -1,
LL_ERROR = 0,
LL_WARN = 1,
LL_INFO = 2,
LL_DEBUG = 3,
LL_VERBOSE_DEBUG = 4,
_LL_MIN = -2,
_LL_MAX = 5,
};
void cs_log_set_level(enum cs_log_level level);
#if CS_ENABLE_STDIO
void cs_log_set_file(FILE *file);
extern enum cs_log_level cs_log_level;
void cs_log_print_prefix(const char *func);
void cs_log_printf(const char *fmt, ...);
#define LOG(l, x) \
if (cs_log_level >= l) { \
cs_log_print_prefix(__func__); \
cs_log_printf x; \
}
#ifndef CS_NDEBUG
#define DBG(x) \
if (cs_log_level >= LL_VERBOSE_DEBUG) { \
cs_log_print_prefix(__func__); \
cs_log_printf x; \
}
#else /* NDEBUG */
#define DBG(x)
#endif
#else /* CS_ENABLE_STDIO */
#define LOG(l, x)
#define DBG(x)
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* CS_COMMON_CS_DBG_H_ */
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#include "data.h"
#include <stdio.h>
#include <stdlib.h>
#include "gpio_if.h"
#include "bm222.h"
#include "tmp006.h"
#include "cs_dbg.h"
struct temp_data {
double ts;
double volt;
double temp;
};
struct conn_state {
struct temp_data td;
double last_sent_td;
unsigned char led;
double last_sent_led;
double last_sent_acc;
};
static int s_tmp006_addr;
static struct temp_data s_temp_data;
static struct bm222_ctx *s_accel_ctx;
void data_init_sensors(int tmp006_addr, int bm222_addr) {
s_tmp006_addr = tmp006_addr;
if (!tmp006_init(tmp006_addr, TMP006_CONV_2, false)) {
LOG(LL_ERROR, ("Failed to init temperature sensor"));
} else {
LOG(LL_INFO, ("Temperature sensor initialized"));
}
s_accel_ctx = bm222_init(bm222_addr);
if (s_accel_ctx == NULL) {
LOG(LL_ERROR, ("Failed to init accelerometer"));
} else {
LOG(LL_INFO, ("Accelerometer initialized"));
}
}
void data_collect(void) {
double volt = tmp006_read_sensor_voltage(s_tmp006_addr);
double temp = tmp006_read_die_temp(s_tmp006_addr);
if (volt != TMP006_INVALID_READING && temp != TMP006_INVALID_READING) {
s_temp_data.temp = temp;
s_temp_data.volt = volt;
s_temp_data.ts = mg_time();
LOG(LL_DEBUG, ("V = %lf mV, T = %lf C", volt, temp));
}
bm222_get_data(s_accel_ctx);
}
static void send_temp(struct mg_connection *nc, const struct temp_data *td) {
if (td->ts == 0) return;
mg_printf_websocket_frame(nc, WEBSOCKET_OP_TEXT,
"{\"t\": 0, \"ts\": %lf, \"sv\": %lf, \"dt\": %lf}",
td->ts, td->volt, td->temp);
}
static void send_led(struct mg_connection *nc, double ts, unsigned char led) {
if (ts == 0) return;
mg_printf_websocket_frame(nc, WEBSOCKET_OP_TEXT,
"{\"t\": 1, \"ts\": %lf, \"v\": %d}", ts, led);
}
static void send_acc_sample(struct mg_connection *nc,
const struct bm222_sample *s) {
if (s->ts == 0) return;
mg_printf_websocket_frame(
nc, WEBSOCKET_OP_TEXT,
"{\"t\": 2, \"ts\": %lf, \"x\": %d, \"y\": %d, \"z\": %d}", s->ts, s->x,
s->y, s->z);
}
static double send_acc_data_since(struct mg_connection *nc,
const struct bm222_ctx *ctx, double since) {
int i = (ctx->last_index + 1) % BM222_NUM_SAMPLES, n = BM222_NUM_SAMPLES;
double last_sent_ts = 0;
for (; n > 0; i = (i + 1) % BM222_NUM_SAMPLES, n--) {
const struct bm222_sample *s = ctx->data + i;
if (s->ts <= since) continue;
send_acc_sample(nc, s);
last_sent_ts = s->ts;
}
return last_sent_ts;
}
static void process_command(struct mg_connection *nc, unsigned char *data,
size_t len) {
// TODO(lsm): use proper JSON parser
int cmd, val;
if (sscanf((char *) data, "{\"t\":%d,\"v\":%d}", &cmd, &val) != 2) {
LOG(LL_ERROR, ("Invalid request: %.*s", (int) len, data));
return;
}
if (cmd == 1) {
switch (val) {
case '0': {
GPIO_IF_LedOff(MCU_RED_LED_GPIO);
break;
}
case '1': {
GPIO_IF_LedOn(MCU_RED_LED_GPIO);
break;
}
case '2': {
GPIO_IF_LedToggle(MCU_RED_LED_GPIO);
break;
}
default: {
LOG(LL_ERROR, ("Invalid value: %.*s", (int) len, data));
return;
}
}
} else {
LOG(LL_ERROR, ("Unknown command: %.*s", (int) len, data));
return;
}
}
void data_conn_handler(struct mg_connection *nc, int ev, void *ev_data) {
struct conn_state *cs = (struct conn_state *) nc->user_data;
if (cs == NULL) {
cs = (struct conn_state *) calloc(1, sizeof(*cs));
nc->user_data = cs;
}
switch (ev) {
case MG_EV_POLL:
case MG_EV_TIMER: {
const double now = mg_time();
const unsigned char led = GPIO_IF_LedStatus(MCU_RED_LED_GPIO);
/* Send if there was a change or repeat last data every second. */
if (s_temp_data.volt != cs->td.volt || s_temp_data.temp != cs->td.temp ||
now > cs->last_sent_td + 1.0) {
memcpy(&cs->td, &s_temp_data, sizeof(cs->td));
send_temp(nc, &cs->td);
cs->last_sent_td = now;
}
if (led != cs->led || now > cs->last_sent_led + 1.0) {
send_led(nc, now, led);
cs->led = led;
cs->last_sent_led = now;
}
if (s_accel_ctx != NULL) {
const struct bm222_sample *ls =
s_accel_ctx->data + s_accel_ctx->last_index;
if (cs->last_sent_acc == 0) {
send_acc_sample(nc, ls);
cs->last_sent_acc = ls->ts;
} else {
double last_sent_ts =
send_acc_data_since(nc, s_accel_ctx, cs->last_sent_acc);
if (last_sent_ts > 0) cs->last_sent_acc = last_sent_ts;
}
}
nc->ev_timer_time = now + 0.05;
break;
}
case MG_EV_WEBSOCKET_FRAME: {
struct websocket_message *wm = (struct websocket_message *) ev_data;
process_command(nc, wm->data, wm->size);
break;
}
case MG_EV_CLOSE: {
LOG(LL_INFO, ("%p closed", nc));
free(cs);
break;
}
}
}
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_MONGOOSE_EXAMPLES_CC3200_DATA_H_
#define CS_MONGOOSE_EXAMPLES_CC3200_DATA_H_
#include "mongoose.h"
void data_collect(void);
void data_init_sensors(int tmp006_addr, int bm222_addr);
void data_conn_handler(struct mg_connection *nc, int ev, void *p);
#endif /* CS_MONGOOSE_EXAMPLES_CC3200_DATA_H_ */
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inc/hw_types.h>
#include <inc/hw_ints.h>
#include <inc/hw_memmap.h>
#include <driverlib/gpio.h>
#include <driverlib/interrupt.h>
#include <driverlib/pin.h>
#include <driverlib/prcm.h>
#include <driverlib/rom.h>
#include <driverlib/rom_map.h>
#include <driverlib/uart.h>
#include <driverlib/utils.h>
#include <example/common/gpio_if.h>
#include <example/common/i2c_if.h>
/* Mongoose.h brings in SimpleLink support. Do not include simplelink.h. */
#include <mongoose.h>
#include "cs_dbg.h"
#include <simplelink/include/device.h>
#include "data.h"
#include "wifi.h"
/* Set up an AP or connect to existing WiFi network. */
#define WIFI_AP_SSID "Mongoose"
#define WIFI_AP_PASS ""
#define WIFI_AP_CHAN 6
// #define WIFI_STA_SSID "YourWiFi"
// #define WIFI_STA_PASS "YourPass"
#define DATA_COLLECTION_INTERVAL_MS 20
#define CONSOLE_BAUD_RATE 115200
#define CONSOLE_UART UARTA0_BASE
#define CONSOLE_UART_PERIPH PRCM_UARTA0
#define MGOS_TASK_PRIORITY 3
#define MG_TASK_STACK_SIZE 8192
#define BM222_ADDR 0x18
#define TMP006_ADDR 0x41
void fs_slfs_set_new_file_size(const char *name, size_t size);
static const char *upload_form =
"\
<h1>Upload file</h1> \
<form action='/upload' method='POST' enctype='multipart/form-data'> \
<input type='file' name='file'> \
<input type='submit' value='Upload'> \
</form>";
static struct mg_str upload_fname(struct mg_connection *nc,
struct mg_str fname) {
struct mg_str lfn;
char *fn = malloc(fname.len + 4);
memcpy(fn, "SL:", 3);
memcpy(fn + 3, fname.p, fname.len);
fn[3 + fname.len] = '\0';
if (nc->user_data != NULL) {
intptr_t cl = (intptr_t) nc->user_data;
if (cl >= 0) {
fs_slfs_set_new_file_size(fn + 3, cl);
}
}
lfn.len = fname.len + 4;
lfn.p = fn;
return lfn;
}
static void mg_ev_handler(struct mg_connection *nc, int ev, void *ev_data) {
switch (ev) {
case MG_EV_ACCEPT: {
char addr[32];
mg_conn_addr_to_str(nc, addr, sizeof(addr), MG_SOCK_STRINGIFY_REMOTE |
MG_SOCK_STRINGIFY_IP |
MG_SOCK_STRINGIFY_PORT);
LOG(LL_INFO, ("%p conn from %s", nc, addr));
break;
}
case MG_EV_HTTP_REQUEST: {
char addr[32];
struct http_message *hm = (struct http_message *) ev_data;
cs_stat_t st;
mg_conn_addr_to_str(nc, addr, sizeof(addr), MG_SOCK_STRINGIFY_REMOTE |
MG_SOCK_STRINGIFY_IP |
MG_SOCK_STRINGIFY_PORT);
LOG(LL_INFO,
("HTTP request from %s: %.*s %.*s", addr, (int) hm->method.len,
hm->method.p, (int) hm->uri.len, hm->uri.p));
if (mg_vcmp(&hm->uri, "/upload") == 0 ||
(mg_vcmp(&hm->uri, "/") == 0 && mg_stat("SL:index.html", &st) != 0)) {
mg_send(nc, upload_form, strlen(upload_form));
nc->flags |= MG_F_SEND_AND_CLOSE;
break;
}
struct mg_serve_http_opts opts;
memset(&opts, 0, sizeof(opts));
opts.document_root = "SL:";
mg_serve_http(nc, hm, opts);
break;
}
case MG_EV_CLOSE: {
LOG(LL_INFO, ("%p closed", nc));
break;
}
case MG_EV_WEBSOCKET_HANDSHAKE_DONE: {
LOG(LL_INFO, ("%p switching to data mode", nc));
nc->handler = data_conn_handler;
nc->ev_timer_time = mg_time(); /* Immediately */
break;
}
case MG_EV_TIMER: {
data_collect();
nc->ev_timer_time = mg_time() + (DATA_COLLECTION_INTERVAL_MS * 0.001);
break;
}
/* SimpleLink FS requires pre-declaring max file size. We use Content-Length
* for that purpose - it will not exactly match file size, but is guaranteed
* to exceed it and should be close enough. */
case MG_EV_HTTP_MULTIPART_REQUEST: {
struct http_message *hm = (struct http_message *) ev_data;
struct mg_str *cl_header = mg_get_http_header(hm, "Content-Length");
intptr_t cl = -1;
if (cl_header != NULL && cl_header->len < 20) {
char buf[20];
memcpy(buf, cl_header->p, cl_header->len);
buf[cl_header->len] = '\0';
cl = atoi(buf);
if (cl < 0) cl = -1;
}
nc->user_data = (void *) cl;
break;
}
case MG_EV_HTTP_PART_BEGIN:
case MG_EV_HTTP_PART_DATA:
case MG_EV_HTTP_PART_END: {
struct mg_http_multipart_part *mp =
(struct mg_http_multipart_part *) ev_data;
if (ev == MG_EV_HTTP_PART_BEGIN) {
LOG(LL_INFO, ("Begin file upload: %s", mp->file_name));
} else if (ev == MG_EV_HTTP_PART_END) {
LOG(LL_INFO, ("End file upload: %s", mp->file_name));
}
mg_file_upload_handler(nc, ev, ev_data, upload_fname);
}
}
}
static void mg_init(struct mg_mgr *mgr) {
LOG(LL_INFO, ("MG task running"));
stop_nwp(); /* See function description in wifi.c */
LOG(LL_INFO, ("Starting NWP..."));
int role = sl_Start(0, 0, 0);
if (role < 0) {
LOG(LL_ERROR, ("Failed to start NWP"));
return;
}
{
SlVersionFull ver;
unsigned char opt = SL_DEVICE_GENERAL_VERSION;
unsigned char len = sizeof(ver);
memset(&ver, 0, sizeof(ver));
sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &opt, &len,
(unsigned char *) (&ver));
LOG(LL_INFO, ("NWP v%d.%d.%d.%d started, host v%d.%d.%d.%d",
ver.NwpVersion[0], ver.NwpVersion[1], ver.NwpVersion[2],
ver.NwpVersion[3], SL_MAJOR_VERSION_NUM, SL_MINOR_VERSION_NUM,
SL_VERSION_NUM, SL_SUB_VERSION_NUM));
}
GPIO_IF_LedToggle(MCU_RED_LED_GPIO);
data_init_sensors(TMP006_ADDR, BM222_ADDR);
sl_fs_init();
#if defined(WIFI_STA_SSID)
if (!wifi_setup_sta(WIFI_STA_SSID, WIFI_STA_PASS)) {
LOG(LL_ERROR, ("Error setting up WiFi station"));
}
#elif defined(WIFI_AP_SSID)
if (!wifi_setup_ap(WIFI_AP_SSID, WIFI_AP_PASS, WIFI_AP_CHAN)) {
LOG(LL_ERROR, ("Error setting up WiFi AP"));
}
#else
#error WiFi not configured
#endif
/* We don't need SimpleLink's web server. */
sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID);
const char *err = "";
struct mg_bind_opts opts;
memset(&opts, 0, sizeof(opts));
opts.error_string = &err;
struct mg_connection *nc = mg_bind_opt(mgr, "80", mg_ev_handler, opts);
if (nc != NULL) {
mg_set_protocol_http_websocket(nc);
nc->ev_timer_time = mg_time(); /* Start data collection */
} else {
LOG(LL_ERROR, ("Failed to create listener: %s", err));
}
}
#ifndef USE_TIRTOS
/* Int vector table, defined in startup_gcc.c */
extern void (*const g_pfnVectors[])(void);
#endif
int main(void) {
#ifndef USE_TIRTOS
MAP_IntVTableBaseSet((unsigned long) &g_pfnVectors[0]);
#endif
MAP_IntEnable(FAULT_SYSTICK);
MAP_IntMasterEnable();
PRCMCC3200MCUInit();
/* Console UART init. */
MAP_PRCMPeripheralClkEnable(CONSOLE_UART_PERIPH, PRCM_RUN_MODE_CLK);
MAP_PinTypeUART(PIN_55, PIN_MODE_3); /* PIN_55 -> UART0_TX */
MAP_PinTypeUART(PIN_57, PIN_MODE_3); /* PIN_57 -> UART0_RX */
MAP_UARTConfigSetExpClk(
CONSOLE_UART, MAP_PRCMPeripheralClockGet(CONSOLE_UART_PERIPH),
CONSOLE_BAUD_RATE,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
MAP_UARTFIFOLevelSet(CONSOLE_UART, UART_FIFO_TX1_8, UART_FIFO_RX4_8);
MAP_UARTFIFOEnable(CONSOLE_UART);
setvbuf(stdout, NULL, _IOLBF, 0);
setvbuf(stderr, NULL, _IOLBF, 0);
cs_log_set_level(LL_INFO);
cs_log_set_file(stdout);
LOG(LL_INFO, ("Hello, world!"));
MAP_PinTypeI2C(PIN_01, PIN_MODE_1); /* SDA */
MAP_PinTypeI2C(PIN_02, PIN_MODE_1); /* SCL */
I2C_IF_Open(I2C_MASTER_MODE_FST);
/* Set up the red LED. Note that amber and green cannot be used as they share
* pins with I2C. */
MAP_PRCMPeripheralClkEnable(PRCM_GPIOA1, PRCM_RUN_MODE_CLK);
MAP_PinTypeGPIO(PIN_64, PIN_MODE_0, false);
MAP_GPIODirModeSet(GPIOA1_BASE, 0x2, GPIO_DIR_MODE_OUT);
GPIO_IF_LedConfigure(LED1);
GPIO_IF_LedOn(MCU_RED_LED_GPIO);
if (VStartSimpleLinkSpawnTask(8) != 0) {
LOG(LL_ERROR, ("Failed to create SL task"));
}
if (!mg_start_task(MGOS_TASK_PRIORITY, MG_TASK_STACK_SIZE, mg_init)) {
LOG(LL_ERROR, ("Failed to create MG task"));
}
osi_start();
return 0;
}
/* These are FreeRTOS hooks for various life situations. */
void vApplicationMallocFailedHook(void) {
}
void vApplicationIdleHook(void) {
}
void vApplicationStackOverflowHook(OsiTaskHandle *th, signed char *tn) {
}
void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *e,
SlHttpServerResponse_t *resp) {
}
void SimpleLinkSockEventHandler(SlSockEvent_t *e) {
}
void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *e) {
LOG(LL_ERROR, ("status %d sender %d", e->EventData.deviceEvent.status,
e->EventData.deviceEvent.sender));
}
docker.cesanta.com/cc3200-build:1.2.0-r8
l<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>CC3200 Mongoose sensor demo</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="text/javascript" src="main.js"></script>
<style>
* {
outline: none;
box-sizing: border-box;
}
body {
background: #7cf;
color: #555;
margin: 0;
padding: 0;
font: 16px/1.4 Helvetica, Arial, sans-serif;
}
div.content {
width: 800px;
margin: 1em auto;
padding: 2em;
background-color: #fff;
border-radius: 1em;
}
a:link, a:visited {
color: #69c;
text-decoration: none;
}
#graphs {
margin-top: 1em;
}
.graph {
min-height: 12em;
border: 0px solid #ccc;
position: relative;
margin: 0;
padding-right: 5px;
width: 100%;
display: inline-block;
}
.graph_title {
position: absolute;
top: 0.5em; left: 1em;
color: #ccc;
font-weight: bold;
z-index: 999;
}
button { font-size: 100%; }
</style>
</head>
<body>
<div class="content">
<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEYAAABECAYAAAA85kOPAAAWc0lEQVR42u1bCXxU1dUPiAKCpUqxlYqKYmttq1W6fLbWtVXR2vpVsbQfS5pltrfct81kI2TYioKoiBtFFAHZFAVUrCwiFMQKik0IW1YgBBKEBJIQssyc73/ezIRJMkCA4Jev+n7en8Pkvjf3/u85//M/594XF/f19fX19fWfcqU4HL1cuv5dlyvUNE27TNf17l95YLzeFKHq+nuq0N9TVO19oemLTNMc9JUGZdCgQV3TMjLfBSgkNMNu+NygGVaW3+/v8h81WUyoszs19eK29LUscQNAyHG5pYDbIxM3WRF1iqK96PMlXHSq+wcPHnyex+Pp2eFBcVnWpYqmJWi6Oc1U1YGn6i/L2kOSLMoASPA4MFoAbQl45pJT3N7ZMLy/A7CTFEX5jX+w/4IOB0hCQsJFqqrer2r6LKz4XrhEQNeN9+SEhL4t+4I/voWJ3IT+d3tk8ZJHUmoioHCTZJXbDkXosiSJ22RZvi4WGeMZt8OytghhsIVl67o5Gv1+7HA4zu8wwGBA9+jC/EyW1cbwxEhRRYNheuckhF2CgZBVMUFV9cWq0D6RhZYHa6mMtpZIA1j1sqLuwzNyFU1fi/tew31CMozvhZ91rSyLj0HWdPz3tKOqpi2VdP2HHQYYhNibVc3IgbU0myD+fVRR1fdgQfN1wyrEv6vxfSODgclHQIjZ3BKeEerDfRtUYRwyTCsHAEyXJHUlntX0DG4MEixniS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xaFtW6AUtKdxCfRvQoKP0jVDVu1puh9gvX6ja05GNtg5xGYb3T4Zh7eaJRb1PwEnmOhmKWNH125HU+eFOS1klo0H8aYchxupjbezZR8NktRZ9DjIIiHSf4N5ZsB5J0rSb7ZPqKv/tuPoOv4H7Bu9FdxhgvParM3oqzP9jPiwNgiSup6hRL4wykfKBZsjx28Abw3j7Apaxwi2rdS1dD6RdAtKeCveQPYr2CIMhSWm9o5/FySu/N8C7pgwSgHtT0bQ/dri3allAYSI/R5uCwa7g87anugd9JLhfRfO3aO33kZZprtgHH5vuBVCapj8NS13DO4m4rozryBe/c81h86SnB47v+dyP1S6NBgZR6xi+e36YZZ2yZJGWltYH/PbD/7iX1/l8ChK73EjECr99W4MobbXn6zP/7y4o2QtT0tJfs2s6qoZIo+1GuP7Uso4f/PnKXl5v+k9YzEHq3w1yvhvZ8C913X/JVx4Ydhnmo0g7QZrw9dURrv8FCph3BenigLsAAAAASUVORK5CYII=
" style="float:right; height: 50px; border-radius: 3px;">
<h1>Mongoose on CC3200 LaunchPad</h1>
<p>
This web page demonstrates how Mongoose embedded networking library can be
used to implement real-time data exchange. Here, a TI CC3200 board pushes
JSON-encoded WebSocket frames to the connected browser, which in turn
graphs the data. Also, the browser can send commands to the device wrapped
into a WebSocket frame to turn an LED on/off.
</p>
<button id="on_off_button">Switch LED off</button>
<div id="graphs"></div>
</div>
</body>
</html>
This source diff could not be displayed because it is too large. You can view the blob instead.
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#include "tmp006.h"
#include "mongoose.h"
#include "i2c_if.h"
#define TMP006_REG_SENSOR_VOLTAGE 0x00
#define TMP006_REG_DIE_TEMP 0x01
#define TMP006_REG_CONFIG 0x02
bool tmp006_init(uint8_t addr, enum tmp006_conversion_rate conv_rate,
bool drdy_en) {
unsigned char val[3] = {TMP006_REG_CONFIG, 0x80, 0};
/* Reset first */
if (I2C_IF_Write(addr, val, 3, 1) != 0) return false;
val[1] = 0x70 | (conv_rate << 1) | drdy_en;
return (I2C_IF_Write(addr, val, 3, 1) == 0);
}
double tmp006_read_sensor_voltage(uint8_t addr) {
unsigned char reg = TMP006_REG_SENSOR_VOLTAGE;
unsigned char val[2] = {0, 0};
int status = I2C_IF_ReadFrom(addr, &reg, 1, val, 2);
if (status < 0) return -1000;
int voltage = (val[0] << 8) | val[1];
if (val[0] & 0x80) voltage = -((1 << 16) - voltage);
return voltage * 0.00015625;
}
double tmp006_read_die_temp(uint8_t addr) {
unsigned char reg = TMP006_REG_DIE_TEMP;
unsigned char val[2] = {0, 0};
int status = I2C_IF_ReadFrom(addr, &reg, 1, val, 2);
if (status < 0) return -1000;
int temp = (val[0] << 6) | (val[1] >> 2);
if (val[0] & 0x80) temp = -((1 << 14) - temp);
return temp / 32.0;
}
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_MONGOOSE_EXAMPLES_CC3200_TMP006_H_
#define CS_MONGOOSE_EXAMPLES_CC3200_TMP006_H_
#include <inttypes.h>
#include <stdbool.h>
enum tmp006_conversion_rate {
TMP006_CONV_4 = 0,
TMP006_CONV_2,
TMP006_CONV_1,
TMP006_CONV_1_2,
TMP006_CONV_1_4,
};
bool tmp006_init(uint8_t addr, enum tmp006_conversion_rate conv_rate,
bool drdy_en);
double tmp006_read_sensor_voltage(uint8_t addr);
double tmp006_read_die_temp(uint8_t addr);
#define TMP006_INVALID_READING (-1000.0)
#endif /* CS_MONGOOSE_EXAMPLES_CC3200_TMP006_H_ */
#include "wifi.h"
#include "mongoose.h"
#include <simplelink/cc_pal.h>
#include <simplelink/include/wlan.h>
#include <inc/hw_types.h>
#include <driverlib/gpio.h>
#include <driverlib/utils.h>
#include <example/common/gpio_if.h>
#include "cs_dbg.h"
void SimpleLinkWlanEventHandler(SlWlanEvent_t *e) {
switch (e->Event) {
case SL_WLAN_CONNECT_EVENT:
LOG(LL_INFO, ("WiFi: connected, getting IP"));
break;
case SL_WLAN_STA_CONNECTED_EVENT:
LOG(LL_INFO, ("WiFi: station connected"));
break;
case SL_WLAN_STA_DISCONNECTED_EVENT:
LOG(LL_INFO, ("WiFi: station disconnected"));
break;
default:
LOG(LL_INFO, ("WiFi: event %d", e->Event));
}
}
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *e) {
if (e->Event == SL_NETAPP_IPV4_IPACQUIRED_EVENT) {
SlIpV4AcquiredAsync_t *ed = &e->EventData.ipAcquiredV4;
LOG(LL_INFO, ("IP acquired: %lu.%lu.%lu.%lu", SL_IPV4_BYTE(ed->ip, 3),
SL_IPV4_BYTE(ed->ip, 2), SL_IPV4_BYTE(ed->ip, 1),
SL_IPV4_BYTE(ed->ip, 0)));
GPIO_IF_LedToggle(MCU_RED_LED_GPIO);
} else if (e->Event == SL_NETAPP_IP_LEASED_EVENT) {
LOG(LL_INFO, ("IP leased"));
} else {
LOG(LL_INFO, ("NetApp event %d", e->Event));
}
}
bool wifi_setup_ap(const char *ssid, const char *pass, int channel) {
uint8_t v;
if (sl_WlanSetMode(ROLE_AP) != 0) {
return false;
}
if (sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SSID, strlen(ssid),
(const uint8_t *) ssid) != 0) {
return false;
}
v = strlen(pass) > 0 ? SL_SEC_TYPE_WPA : SL_SEC_TYPE_OPEN;
if (sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_SECURITY_TYPE, 1, &v) != 0) {
return false;
}
if (v == SL_SEC_TYPE_WPA &&
sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_PASSWORD, strlen(pass),
(const uint8_t *) pass) != 0) {
return false;
}
v = channel;
if (sl_WlanSet(SL_WLAN_CFG_AP_ID, WLAN_AP_OPT_CHANNEL, 1, &v) != 0) {
return false;
}
sl_NetAppStop(SL_NET_APP_DHCP_SERVER_ID);
{
SlNetCfgIpV4Args_t ipcfg;
memset(&ipcfg, 0, sizeof(ipcfg));
if (!inet_pton(AF_INET, "192.168.4.1", &ipcfg.ipV4) ||
!inet_pton(AF_INET, "255.255.255.0", &ipcfg.ipV4Mask) ||
/* This means "disable". 0.0.0.0 won't do. */
!inet_pton(AF_INET, "255.255.255.255", &ipcfg.ipV4DnsServer) ||
/* We'd like to disable gateway too, but DHCP server refuses to start.
*/
!inet_pton(AF_INET, "192.168.4.1", &ipcfg.ipV4Gateway) ||
sl_NetCfgSet(SL_IPV4_AP_P2P_GO_STATIC_ENABLE, IPCONFIG_MODE_ENABLE_IPV4,
sizeof(ipcfg), (uint8_t *) &ipcfg) != 0) {
return false;
}
}
{
SlNetAppDhcpServerBasicOpt_t dhcpcfg;
memset(&dhcpcfg, 0, sizeof(dhcpcfg));
dhcpcfg.lease_time = 900;
if (!inet_pton(AF_INET, "192.168.4.20", &dhcpcfg.ipv4_addr_start) ||
!inet_pton(AF_INET, "192.168.4.200", &dhcpcfg.ipv4_addr_last) ||
sl_NetAppSet(SL_NET_APP_DHCP_SERVER_ID, NETAPP_SET_DHCP_SRV_BASIC_OPT,
sizeof(dhcpcfg), (uint8_t *) &dhcpcfg) != 0) {
return false;
}
}
sl_Stop(0);
sl_Start(NULL, NULL, NULL);
if (sl_NetAppStart(SL_NET_APP_DHCP_SERVER_ID) != 0) {
LOG(LL_ERROR, ("DHCP server failed to start"));
return false;
}
LOG(LL_INFO, ("WiFi: AP %s configured, IP 192.168.4.1", ssid));
return true;
}
bool wifi_setup_sta(const char *ssid, const char *pass) {
SlSecParams_t sp;
LOG(LL_INFO, ("WiFi: connecting to %s", ssid));
if (sl_WlanSetMode(ROLE_STA) != 0) return false;
sl_Stop(0);
sl_Start(NULL, NULL, NULL);
sl_WlanDisconnect();
sp.Key = (_i8 *) pass;
sp.KeyLen = strlen(pass);
sp.Type = sp.KeyLen ? SL_SEC_TYPE_WPA : SL_SEC_TYPE_OPEN;
if (sl_WlanConnect((const _i8 *) ssid, strlen(ssid), 0, &sp, 0) != 0) {
return false;
}
return true;
}
/*
* In SDK 1.2.0 TI decided to stop resetting NWP before sl_Start, which in
* practice means that sl_start will hang on subsequent runs after the first.
*
* See this post for details and suggested solution:
* https://e2e.ti.com/support/wireless_connectivity/simplelink_wifi_cc31xx_cc32xx/f/968/p/499123/1806610#1806610
*
* However, since they don't provide OS_debug variant of simplelink.a and
* adding another project dependency will complicate our demo even more,
* we just take the required bit of code.
*
* This is a copy-paste of NwpPowerOnPreamble from cc_pal.c.
*/
void stop_nwp(void) {
#define MAX_RETRY_COUNT 1000
unsigned int sl_stop_ind, apps_int_sts_raw, nwp_lpds_wake_cfg;
unsigned int retry_count;
/* Perform the sl_stop equivalent to ensure network services
are turned off if active */
HWREG(0x400F70B8) = 1; /* APPs to NWP interrupt */
UtilsDelay(800000 / 5);
retry_count = 0;
nwp_lpds_wake_cfg = HWREG(0x4402D404);
sl_stop_ind = HWREG(0x4402E16C);
if ((nwp_lpds_wake_cfg != 0x20) && /* Check for NWP POR condition */
!(sl_stop_ind & 0x2)) /* Check if sl_stop was executed */
{
/* Loop until APPs->NWP interrupt is cleared or timeout */
while (retry_count < MAX_RETRY_COUNT) {
apps_int_sts_raw = HWREG(0x400F70C0);
if (apps_int_sts_raw & 0x1) {
UtilsDelay(800000 / 5);
retry_count++;
} else {
break;
}
}
}
HWREG(0x400F70B0) = 1; /* Clear APPs to NWP interrupt */
UtilsDelay(800000 / 5);
/* Stop the networking services */
NwpPowerOff();
}
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_MONGOOSE_EXAMPLES_CC3200_WIFI_H_
#define CS_MONGOOSE_EXAMPLES_CC3200_WIFI_H_
#include <stdbool.h>
bool wifi_setup_ap(const char *ssid, const char *pass, int channel);
bool wifi_setup_sta(const char *ssid, const char *pass);
void stop_nwp(void);
#endif /* CS_MONGOOSE_EXAMPLES_CC3200_WIFI_H_ */
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of object file images to be generated ()
# GEN_BINS - list of binaries to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
TARGET = eagle
#FLAVOR = release
FLAVOR = debug
EXTRA_CCFLAGS += -Wall -Werror -DRTOS_SDK
ifndef PDIR # {
GEN_IMAGES= eagle.app.v6.out
GEN_BINS= eagle.app.v6.bin
SPECIAL_MKTARGETS=$(APP_MKTARGETS)
SUBDIRS=user
endif # } PDIR
LDDIR = $(SDK_PATH)/ld
CCFLAGS += -Os -Wno-undef
TARGET_LDFLAGS = \
-nostdlib \
-Wl,-EL \
--longcalls \
--text-section-literals
ifeq ($(FLAVOR),debug)
TARGET_LDFLAGS += -g -O2
endif
ifeq ($(FLAVOR),release)
TARGET_LDFLAGS += -g -O0
endif
COMPONENTS_eagle.app.v6 = \
user/libuser.a
LINKFLAGS_eagle.app.v6 = \
-L$(SDK_PATH)/lib \
-Wl,--gc-sections \
-nostdlib \
-T$(LD_FILE) \
-Wl,--no-check-sections \
-u call_user_start \
-Wl,-static \
-Wl,--start-group \
-lcirom \
-lgcc \
-lhal \
-lphy \
-lpp \
-lnet80211 \
-lwpa \
-lcrypto \
-lmain \
-lfreertos \
-llwip \
$(DEP_LIBS_eagle.app.v6) \
-Wl,--end-group
DEPENDS_eagle.app.v6 = \
$(LD_FILE) \
$(LDDIR)/eagle.rom.addr.v6.ld
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
#UNIVERSAL_TARGET_DEFINES = \
# Other potential configuration flags include:
# -DTXRX_TXBUF_DEBUG
# -DTXRX_RXBUF_DEBUG
# -DWLAN_CONFIG_CCX
CONFIGURATION_DEFINES = -DICACHE_FLASH
DEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES)
DDEFINES += \
$(UNIVERSAL_TARGET_DEFINES) \
$(CONFIGURATION_DEFINES)
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
INCLUDES := $(INCLUDES) -I $(PDIR)include
sinclude $(SDK_PATH)/Makefile
.PHONY: FORCE
FORCE:
This is a Mongoose "Hello, world" that can be compiled under ESP8266 RTOS SDK.
It sets up an AP (SSID `Mongoose`) and serves a "hello world" page on http://192.168.4.1/
Most of the the boilerplate comes from [project_template](https://github.com/espressif/ESP8266_RTOS_SDK/tree/master/examples/project_template) (@ [3ca6af5](https://github.com/espressif/ESP8266_RTOS_SDK/tree/3ca6af5da68678d809b34c7cd98bee71e0235039/examples/project_template)) with minimal changes.
To build with no changes to the SDK, you will need a module with 1MB (8Mb) flash or more.
Compile (for NodeMCU 1.0):
```
$ export SDK_PATH=/path/to/ESP8266_RTOS_SDK
$ export BIN_PATH=./bin
$ make clean; make BOOT=none APP=0 SPI_SPEED=40 SPI_MODE=dio SPI_SIZE_MAP=0
```
Flash (using [esptool](https://github.com/themadinventor/esptool)):
```
$ esptool.py --port /dev/ttyUSB0 --baud 230400 \
write_flash --flash_mode=qio --flash_size=4m \
0x00000 ${BIN_PATH}/eagle.flash.bin \
0x20000 ${BIN_PATH}/eagle.irom0text.bin \
0x7e000 ${SDK_PATH}/bin/esp_init_data_default.bin
```
#!/bin/bash
docker run \
--rm -i -v $(realpath ${PWD}/../..):/src \
--entrypoint=/bin/bash $(cat sdk.version) -l -c -x '
export SDK_PATH=/opt/Espressif/ESP8266_SDK;
export BIN_PATH=./bin;
cd /src/examples/ESP8266_RTOS &&
mkdir -p ./bin && make clean &&
make BOOT=none APP=0 SPI_SPEED=40 SPI_MODE=qio SPI_SIZE_MAP=0'
#!/bin/bash
:<<!
******NOTICE******
MUST set SDK_PATH & BIN_PATH firstly!!!
example:
export SDK_PATH=~/ESP8266_RTOS_SDK
export BIN_PATH=~/esp8266_bin
!
echo "gen_misc.sh version 20150911"
echo ""
if [ $SDK_PATH ]; then
echo "SDK_PATH:"
echo "$SDK_PATH"
echo ""
else
echo "ERROR: Please export SDK_PATH in gen_misc.sh firstly, exit!!!"
exit
fi
if [ $BIN_PATH ]; then
echo "BIN_PATH:"
echo "$BIN_PATH"
echo ""
else
echo "ERROR: Please export BIN_PATH in gen_misc.sh firstly, exit!!!"
exit
fi
echo "Please check SDK_PATH & BIN_PATH, enter (Y/y) to continue:"
read input
if [[ $input != Y ]] && [[ $input != y ]]; then
exit
fi
echo ""
echo "Please follow below steps(1-5) to generate specific bin(s):"
echo "STEP 1: use boot_v1.2+ by default"
boot=new
echo "boot mode: $boot"
echo ""
echo "STEP 2: choose bin generate(0=eagle.flash.bin+eagle.irom0text.bin, 1=user1.bin, 2=user2.bin)"
echo "enter (0/1/2, default 0):"
read input
if [ -z "$input" ]; then
if [ $boot != none ]; then
boot=none
echo "ignore boot"
fi
app=0
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
elif [ $input == 1 ]; then
if [ $boot == none ]; then
app=0
echo "choose no boot before"
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
else
app=1
echo "generate bin: user1.bin"
fi
elif [ $input == 2 ]; then
if [ $boot == none ]; then
app=0
echo "choose no boot before"
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
else
app=2
echo "generate bin: user2.bin"
fi
else
if [ $boot != none ]; then
boot=none
echo "ignore boot"
fi
app=0
echo "generate bin: eagle.flash.bin+eagle.irom0text.bin"
fi
echo ""
echo "STEP 3: choose spi speed(0=20MHz, 1=26.7MHz, 2=40MHz, 3=80MHz)"
echo "enter (0/1/2/3, default 2):"
read input
if [ -z "$input" ]; then
spi_speed=40
elif [ $input == 0 ]; then
spi_speed=20
elif [ $input == 1 ]; then
spi_speed=26.7
elif [ $input == 3 ]; then
spi_speed=80
else
spi_speed=40
fi
echo "spi speed: $spi_speed MHz"
echo ""
echo "STEP 4: choose spi mode(0=QIO, 1=QOUT, 2=DIO, 3=DOUT)"
echo "enter (0/1/2/3, default 0):"
read input
if [ -z "$input" ]; then
spi_mode=QIO
elif [ $input == 1 ]; then
spi_mode=QOUT
elif [ $input == 2 ]; then
spi_mode=DIO
elif [ $input == 3 ]; then
spi_mode=DOUT
else
spi_mode=QIO
fi
echo "spi mode: $spi_mode"
echo ""
echo "STEP 5: choose spi size and map"
echo " 0= 512KB( 256KB+ 256KB)"
echo " 2=1024KB( 512KB+ 512KB)"
echo " 3=2048KB( 512KB+ 512KB)"
echo " 4=4096KB( 512KB+ 512KB)"
echo " 5=2048KB(1024KB+1024KB)"
echo " 6=4096KB(1024KB+1024KB)"
echo "enter (0/2/3/4/5/6, default 0):"
read input
if [ -z "$input" ]; then
spi_size_map=0
echo "spi size: 512KB"
echo "spi ota map: 256KB + 256KB"
elif [ $input == 2 ]; then
spi_size_map=2
echo "spi size: 1024KB"
echo "spi ota map: 512KB + 512KB"
elif [ $input == 3 ]; then
spi_size_map=3
echo "spi size: 2048KB"
echo "spi ota map: 512KB + 512KB"
elif [ $input == 4 ]; then
spi_size_map=4
echo "spi size: 4096KB"
echo "spi ota map: 512KB + 512KB"
elif [ $input == 5 ]; then
spi_size_map=5
echo "spi size: 2048KB"
echo "spi ota map: 1024KB + 1024KB"
elif [ $input == 6 ]; then
spi_size_map=6
echo "spi size: 4096KB"
echo "spi ota map: 1024KB + 1024KB"
else
spi_size_map=0
echo "spi size: 512KB"
echo "spi ota map: 256KB + 256KB"
fi
echo ""
echo "start..."
echo ""
make clean
make BOOT=$boot APP=$app SPI_SPEED=$spi_speed SPI_MODE=$spi_mode SPI_SIZE_MAP=$spi_size_map
This is a simple project template.
sample_lib is an example for multi-level folder Makefile, notice the folder structure and each Makefile, you can get the clue.
HOWTO:
1. Copy this folder to anywhere.
Example:
Copy to ~/workspace/project_template
You can rename this folder as you like.
2. Export SDK_PATH and BIN_PATH.
Example:
Your SDK path is ~/esp_iot_rtos_sdk, and want generate bin at ~/esp8266_bin.
Do follow steps:
1>. export SDK_PATH=~/esp_iot_rtos_sdk
2>. export BIN_PATH=~/esp8266_bin
SDK and project are seperate, you can update SDK without change your project.
3. Enter project_template folder, run ./gen_misc.sh, and follow the tips and steps.
Compile Options:
(1) COMPILE
Possible value: xcc
Default value:
If not set, use gcc by default.
(2) BOOT
Possible value: none/old/new
none: no need boot
old: use boot_v1.1
new: use boot_v1.2
Default value: new
(3) APP
Possible value: 0/1/2
0: original mode, generate eagle.app.v6.flash.bin and eagle.app.v6.irom0text.bin
1: generate user1
2: generate user2
Default value: 0
(3) SPI_SPEED
Possible value: 20/26.7/40/80
Default value: 40
(4) SPI_MODE
Possible value: QIO/QOUT/DIO/DOUT
Default value: QIO
(4) SPI_SIZE_MAP
Possible value: 0/2/3/4/5/6
Default value: 0
For example:
make COMPILE=gcc BOOT=new APP=1 SPI_SPEED=40 SPI_MODE=QIO SPI_SIZE_MAP=0
docker.cesanta.com/esp8266-build-rtos:1.4.0-r2
#############################################################
# Required variables for each makefile
# Discard this section from all parent makefiles
# Expected variables (with automatic defaults):
# CSRCS (all "C" files in the dir)
# SUBDIRS (all subdirs with a Makefile)
# GEN_LIBS - list of libs to be generated ()
# GEN_IMAGES - list of images to be generated ()
# COMPONENTS_xxx - a list of libs/objs in the form
# subdir/lib to be extracted and rolled up into
# a generated lib/image xxx.a ()
#
ifndef PDIR
GEN_LIBS = libuser.a
endif
#############################################################
# Configuration i.e. compile options etc.
# Target specific stuff (defines etc.) goes in here!
# Generally values applying to a tree are captured in the
# makefile at its root level - these are then overridden
# for a subtree within the makefile rooted therein
#
DEFINES +=
#############################################################
# Recursion Magic - Don't touch this!!
#
# Each subtree potentially has an include directory
# corresponding to the common APIs applicable to modules
# rooted at that subtree. Accordingly, the INCLUDE PATH
# of a module can only contain the include directories up
# its parent path, and not its siblings
#
# Required for each makefile to inherit from the parent
#
INCLUDES += -I ./
PDIR := ../$(PDIR)
sinclude $(PDIR)Makefile
/*
* Copyright (c) 2015 Cesanta Software Limited
* All rights reserved
*/
#include <ctype.h>
#include <sys/time.h>
#include <stdint.h>
#include <math.h>
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "esp_common.h"
/* Makes fprintf(stdout) and stderr work. */
_ssize_t _write_r(struct _reent *r, int fd, void *buf, size_t len) {
if (fd == 1 || fd == 2) {
size_t i;
for (i = 0; i < len; i++) {
os_putc(((char *) buf)[i]);
}
return len;
}
return -1;
}
/*
* You'll need to implement _open_r and friends if you want file operations. See
* https://github.com/cesanta/mongoose-os/blob/master/fw/platforms/esp8266/user/esp_fs.c
* for SPIFFS-based implementation.
*/
void abort(void) __attribute__((no_instrument_function));
void abort(void) {
/* cause an unaligned access exception, that will drop you into gdb */
*(int *) 1 = 1;
while (1)
; /* avoid gcc warning because stdlib abort() has noreturn attribute */
}
void _exit(int status) {
abort();
}
/*
* This will prevent counter wrap if time is read regularly.
* At least Mongoose poll queries time, so we're covered.
*/
int _gettimeofday_r(struct _reent *r, struct timeval *tp, void *tzp) {
static uint32_t prev_time = 0;
static uint32_t num_overflows = 0;
uint32_t time = system_get_time();
uint64_t time64 = time;
if (prev_time > 0 && time < prev_time) num_overflows++;
time64 += (((uint64_t) num_overflows) * (1ULL << 32));
tp->tv_sec = time64 / 1000000ULL;
tp->tv_usec = time64 % 1000000ULL;
prev_time = time;
return 0;
(void) r;
(void) tzp;
}
../../../mongoose.c
\ No newline at end of file
../../../mongoose.h
\ No newline at end of file
/*
* Copyright (c) 2015 Cesanta Software Limited
* All rights reserved
*/
#include "esp_common.h"
#include "mongoose.h"
#define AP_SSID "Mongoose"
#define AP_PASS "Mongoose"
#define AP_CHAN 9
#define MG_LISTEN_ADDR "80"
#define MG_TASK_STACK_SIZE 4096
#define MGOS_TASK_PRIORITY 1
void uart_div_modify(int uart_no, unsigned int freq);
void ev_handler(struct mg_connection *nc, int ev, void *p) {
static const char *reply_fmt =
"HTTP/1.0 200 OK\r\n"
"Connection: close\r\n"
"Content-Type: text/plain\r\n"
"\r\n"
"Hello %s\n";
switch (ev) {
case MG_EV_ACCEPT: {
char addr[32];
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
printf("Connection %p from %s\n", nc, addr);
break;
}
case MG_EV_HTTP_REQUEST: {
char addr[32];
struct http_message *hm = (struct http_message *) p;
mg_sock_addr_to_str(&nc->sa, addr, sizeof(addr),
MG_SOCK_STRINGIFY_IP | MG_SOCK_STRINGIFY_PORT);
printf("HTTP request from %s: %.*s %.*s\n", addr, (int) hm->method.len,
hm->method.p, (int) hm->uri.len, hm->uri.p);
mg_printf(nc, reply_fmt, addr);
nc->flags |= MG_F_SEND_AND_CLOSE;
break;
}
case MG_EV_CLOSE: {
printf("Connection %p closed\n", nc);
break;
}
}
}
void setup_ap(void) {
int off = 0;
struct ip_info info;
struct softap_config cfg;
wifi_set_opmode_current(SOFTAP_MODE);
memset(&cfg, 0, sizeof(cfg));
strcpy((char *) cfg.ssid, AP_SSID);
strcpy((char *) cfg.password, AP_PASS);
cfg.ssid_len = strlen((const char *) cfg.ssid);
cfg.authmode =
strlen((const char *) cfg.password) ? AUTH_WPA2_PSK : AUTH_OPEN;
cfg.channel = AP_CHAN;
cfg.ssid_hidden = 0;
cfg.max_connection = 10;
cfg.beacon_interval = 100; /* ms */
printf("Setting up AP '%s' on channel %d\n", cfg.ssid, cfg.channel);
wifi_softap_set_config_current(&cfg);
wifi_softap_dhcps_stop();
wifi_softap_set_dhcps_offer_option(OFFER_ROUTER, &off);
wifi_softap_dhcps_start();
wifi_get_ip_info(SOFTAP_IF, &info);
printf("WiFi AP: SSID %s, channel %d, IP " IPSTR "\n", cfg.ssid, cfg.channel,
IP2STR(&info.ip));
}
static void mg_task(void *arg) {
struct mg_mgr mgr;
struct mg_connection *nc;
printf("SDK version: %s\n", system_get_sdk_version());
setup_ap();
mg_mgr_init(&mgr, NULL);
nc = mg_bind(&mgr, MG_LISTEN_ADDR, ev_handler);
if (nc == NULL) {
printf("Error setting up listener!\n");
return;
}
mg_set_protocol_http_websocket(nc);
while (1) {
mg_mgr_poll(&mgr, 1000);
}
}
xTaskHandle s_mg_task_handle;
void user_init(void) {
uart_div_modify(0, UART_CLK_FREQ / 115200);
xTaskCreate(mg_task, (const signed char *) "mongoose", MG_TASK_STACK_SIZE,
NULL, MGOS_TASK_PRIORITY, &s_mg_task_handle);
}
<?xml version="1.0" encoding="UTF-8" ?>
<?ccsproject version="1.0"?>
<projectOptions>
<deviceVariant value="MSP432P401R"/>
<deviceFamily value="MSP432"/>
<deviceEndianness value="little"/>
<codegenToolVersion value="5.2.8"/>
<isElfFormat value="true"/>
<rts value="libc.a"/>
<createSlaveProjects value=""/>
<origin value="/home/rojer/cesanta/ti/tirtos_msp43x_2_16_00_08/resources/msp_exp432P401RLaunchpad/networkExamples/tiNetworkExamples/wiFiExamples/com_ti_rtsc_tirtosmsp430_example_101.projectspec"/>
<templateProperties value="id=com_ti_rtsc_tirtosmsp430_example_101.projectspec.tcpEchoCC3X00_MSP_EXP432P401R_TI_MSP432P401R,type=rtsc,products=com.ti.rtsc.TIRTOSmsp430,xdcToolsVersion=3_32_00_06_core,target=ti.targets.arm.elf.M4F,platform=ti.platforms.msp432:MSP432P401R,buildProfile=release,isHybrid=true,configuroOptions= --compileOptions &quot;${COMPILER_FLAGS} &quot;,"/>
<connection value="common/targetdb/connections/TIXDS110_Connection.xml"/>
<isTargetManual value="false"/>
</projectOptions>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>MSP432_MG_hello</name>
<comment></comment>
<projects>
<project>MSP432_Mongoose</project>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.rtsc.xdctools.buildDefinitions.XDC.xdcNature</nature>
<nature>com.ti.ccstudio.core.ccsNature</nature>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
/* clang-format off */
/*
* Copyright (c) 2015, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef CS_MONGOOSE_EXAMPLES_MSP432_CCS_MG_HELLO_BOARD_H_
#define CS_MONGOOSE_EXAMPLES_MSP432_CCS_MG_HELLO_BOARD_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "MSP_EXP432P401R.h"
#define Board_initGeneral MSP_EXP432P401R_initGeneral
#define Board_initGPIO MSP_EXP432P401R_initGPIO
#define Board_initI2C MSP_EXP432P401R_initI2C
#define Board_initPWM MSP_EXP432P401R_initPWM
#define Board_initSDSPI MSP_EXP432P401R_initSDSPI
#define Board_initSPI MSP_EXP432P401R_initSPI
#define Board_initUART MSP_EXP432P401R_initUART
#define Board_initWatchdog MSP_EXP432P401R_initWatchdog
#define Board_initWiFi MSP_EXP432P401R_initWiFi
#define Board_LED_ON MSP_EXP432P401R_LED_ON
#define Board_LED_OFF MSP_EXP432P401R_LED_OFF
#define Board_BUTTON0 MSP_EXP432P401R_S1
#define Board_BUTTON1 MSP_EXP432P401R_S2
#define Board_LED0 MSP_EXP432P401R_LED1
#define Board_LED1 MSP_EXP432P401R_LED_RED
#define Board_LED2 MSP_EXP432P401R_LED_RED
/*
* MSP_EXP432P401R_LED_GREEN & MSP_EXP432P401R_LED_BLUE are used for
* PWM examples. Uncomment the following lines if you would like to control
* the LEDs with the GPIO driver.
*/
//#define Board_LED2 MSP_EXP432P401R_LED_GREEN
//#define Board_LED3 MSP_EXP432P401R_LED_BLUE
#define Board_I2C0 MSP_EXP432P401R_I2CB0
#define Board_I2C_TMP MSP_EXP432P401R_I2CB0
#define Board_I2C_NFC MSP_EXP432P401R_I2CB0
#define Board_I2C_TPL0401 MSP_EXP432P401R_I2CB0
#define Board_PWM0 MSP_EXP432P401R_PWM_TA1_1
#define Board_PWM1 MSP_EXP432P401R_PWM_TA1_2
#define Board_SDSPI0 MSP_EXP432P401R_SDSPIB0
#define Board_SPI0 MSP_EXP432P401R_SPIB0
#define Board_SPI1 MSP_EXP432P401R_SPIB2
#define Board_UART0 MSP_EXP432P401R_UARTA0
#define Board_UART1 MSP_EXP432P401R_UARTA2
#define Board_WATCHDOG0 MSP_EXP432P401R_WATCHDOG
#define Board_WIFI MSP_EXP432P401R_WIFI
#define Board_WIFI_SPI MSP_EXP432P401R_SPIB0
/* Board specific I2C addresses */
#define Board_TMP006_ADDR (0x40)
#define Board_RF430CL330_ADDR (0x28)
#define Board_TPL0401_ADDR (0x40)
#ifdef __cplusplus
}
#endif
#endif /* CS_MONGOOSE_EXAMPLES_MSP432_CCS_MG_HELLO_BOARD_H_ */
This diff is collapsed.
/*
* Copyright (c) 2015-2016, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* ======== MSP_EXP432P401R.cmd ========
* Define the memory block start/length for the MSP_EXP432P401R M4
*/
MEMORY
{
MAIN (RX) : origin = 0x00000000, length = 0x00040000
INFO (RX) : origin = 0x00200000, length = 0x00004000
SRAM_CODE (RWX): origin = 0x01000000, length = 0x00010000
SRAM_DATA (RW) : origin = 0x20000000, length = 0x00010000
}
/* Section allocation in memory */
SECTIONS
{
.text : > MAIN
.const : > MAIN
.cinit : > MAIN
.pinit : > MAIN
.data : > SRAM_DATA
.bss : > SRAM_DATA
.sysmem : > SRAM_DATA
.stack : > SRAM_DATA (HIGH)
}
/* Symbolic definition of the WDTCTL register for RTS */
WDTCTL_SYM = 0x4000480C;
This diff is collapsed.
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_COMMON_CS_DBG_H_
#define CS_COMMON_CS_DBG_H_
#if CS_ENABLE_STDIO
#include <stdio.h>
#endif
#ifndef CS_ENABLE_DEBUG
#define CS_ENABLE_DEBUG 0
#endif
#ifndef CS_LOG_ENABLE_TS_DIFF
#define CS_LOG_ENABLE_TS_DIFF 0
#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
enum cs_log_level {
LL_NONE = -1,
LL_ERROR = 0,
LL_WARN = 1,
LL_INFO = 2,
LL_DEBUG = 3,
LL_VERBOSE_DEBUG = 4,
_LL_MIN = -2,
_LL_MAX = 5,
};
void cs_log_set_level(enum cs_log_level level);
#if CS_ENABLE_STDIO
void cs_log_set_file(FILE *file);
extern enum cs_log_level cs_log_level;
void cs_log_print_prefix(const char *func);
void cs_log_printf(const char *fmt, ...);
#define LOG(l, x) \
if (cs_log_level >= l) { \
cs_log_print_prefix(__func__); \
cs_log_printf x; \
}
#ifndef CS_NDEBUG
#define DBG(x) \
if (cs_log_level >= LL_VERBOSE_DEBUG) { \
cs_log_print_prefix(__func__); \
cs_log_printf x; \
}
#else /* NDEBUG */
#define DBG(x)
#endif
#else /* CS_ENABLE_STDIO */
#define LOG(l, x)
#define DBG(x)
#endif
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* CS_COMMON_CS_DBG_H_ */
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
var BIOS = xdc.useModule('ti.sysbios.BIOS');
clean:
rm -rf */Debug */Release */.config */.launches */.settings */.xdchelp */src
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Please download the [LPCOpen QSB SDK](https://www.embeddedartists.com/sites/default/files/support/qsb/lpc4088/lpcopen_2_10_lpcxpresso_arm_university_4088qsb.zip) and unpack it into this directory.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment