CC3200 FS refactoring and basic Mongoose example

Moved filesystem-related code out of SJS and into common.
Made it possible to have one, both or no filesystems enabled.
FailFS is now SimpleLinkFS, SLFS (ahem).

Example just serves a "Hello, world!" index page for now.

PUBLISHED_FROM=0e98ee4b8d95782c10791522c42eae5a7ba314f9
This commit is contained in:
Deomid Ryabkov 2016-03-21 19:05:28 +00:00 committed by rojer
parent 012f241005
commit 4f9627c612
9 changed files with 441 additions and 3 deletions

27
examples/CC3200/Makefile Normal file
View File

@ -0,0 +1,27 @@
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/smartjs/platforms/cc3200/firmware/smartjs.bin \
"
debug:
docker run --rm -it --privileged -v $(SRC_DIR):/src $(SDK) \
/bin/bash -c "cd /src/smartjs/platforms/cc3200 && tools/gdb.sh"

View File

@ -0,0 +1,132 @@
# -*- mode: makefile -*-
# This file is executed inside Docker build container.
# It can be used without container too if SDK_PATH and V7_PATH are configured.
PLATFORM = CC3200
SDK_PATH ?= /cc3200-sdk
REPO_PATH ?= ../../..
COMMON_PATH ?= $(REPO_PATH)/common
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) \
${SDK_PATH} \
${SDK_PATH}/inc \
${SDK_PATH}/driverlib \
${SDK_PATH}/oslib \
${SDK_PATH}/simplelink \
${SDK_PATH}/simplelink/include \
${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 \
${COMMON_PATH}/platforms/cc3200 \
MONGOOSE_FEATURES = \
-DMG_CC3200 \
-DMG_DISABLE_DIRECTORY_LISTING \
-DMG_DISABLE_JSON_RPC \
-DMG_DISABLE_COAP \
-DMG_DISABLE_SYNC_RESOLVER \
-DMG_DISABLE_SOCKETPAIR \
-DMG_DISABLE_DAV \
-DMG_DISABLE_CGI \
-DMG_DISABLE_SSI \
-DMG_ENABLE_HTTP_STREAMING_MULTIPART \
-DMG_MAX_HTTP_HEADERS=20 \
-DMG_MAX_HTTP_REQUEST_SIZE=1024 \
-DMG_MAX_PATH=40 \
-DMG_MAX_HTTP_SEND_MBUF=1024 \
-DMG_NO_BSD_SOCKETS
SDK_FLAGS = -DTARGET_IS_CC3200 -DUSE_FREERTOS -DSL_PLATFORM_MULTI_THREADED
DISABLED_SDK_WARNINGS = -Wno-missing-braces -Wno-strict-aliasing -Wno-parentheses -Wno-unused-variable
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} ${SYS_CONFIG_C} ${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}"
@$(COMMON_PATH)/tools/fw_meta.py gen_build_info \
--json_output=$(BUILD_INFO_JSON)
@cp -v $(SLFS_FILES) out/
@$(COMMON_PATH)/tools/fw_meta.py create_manifest \
--name=$(PROG) --platform=$(PLATFORM) \
--build_info=$(BUILD_INFO_JSON) \
--output=$(FW_MANIFEST) \
--src_dir=$(FW_DIR) \
sys_mcuimg.bin:src=$(notdir $(FW_BIN)) \
$(foreach f,$(SLFS_FILES), $(notdir $(f)):src=$(notdir $(f)))
@echo " ZIP $@"
@$(COMMON_PATH)/tools/fw_meta.py create_fw \
--manifest=$(FW_MANIFEST) \
--src_dir=$(FW_DIR) \
--output=$@
APP_OBJS = $(OBJDIR)/main.o \
${OBJDIR}/cc3200_fs.o ${OBJDIR}/cc3200_fs_slfs.o ${OBJDIR}/cc3200_libc.o \
${OBJDIR}/cc3200_socket.o \
${OBJDIR}/mongoose.o \
${OBJDIR}/startup_gcc.o \
${OBJDIR}/timers.o ${OBJDIR}/list.o ${OBJDIR}/queue.o ${OBJDIR}/tasks.o ${OBJDIR}/port.o ${OBJDIR}/heap_3.o ${OBJDIR}/osi_freertos.o \
${OBJDIR}/socket.o ${OBJDIR}/wlan.o ${OBJDIR}/driver.o ${OBJDIR}/device.o ${OBJDIR}/netapp.o ${OBJDIR}/netcfg.o ${OBJDIR}/cc_pal.o ${OBJDIR}/fs.o \
${OBJDIR}/cpu.o ${OBJDIR}/i2c.o ${OBJDIR}/interrupt.o ${OBJDIR}/pin.o ${OBJDIR}/prcm.o ${OBJDIR}/spi.o ${OBJDIR}/uart.o ${OBJDIR}/udma.o ${OBJDIR}/utils.o
${FW_ELF}: ${APP_OBJS}
SCATTERgcc_${PROG} = ${PROG}.ld
ENTRY_${PROG} = ResetISR
# Target specific warning inhibitions
build/wlan.o: CFLAGS += $(DISABLED_SDK_WARNINGS)
build/driver.o: CFLAGS += $(DISABLED_SDK_WARNINGS)
build/fs.o: CFLAGS += $(DISABLED_SDK_WARNINGS)
build/spi.o: CFLAGS += $(DISABLED_SDK_WARNINGS)
build/prcm.o: CFLAGS += $(DISABLED_SDK_WARNINGS)
build/spiffs_hydrogen.o: CFLAGS += -Wno-unused-function

View File

@ -0,0 +1,93 @@
/*****************************************************************************
* app.ld
*
* GCC Linker script for SmartJS. 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 for cc3200 ES 1.33 device onward */
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 = .;
}
}

173
examples/CC3200/main.c Normal file
View File

@ -0,0 +1,173 @@
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#include <malloc.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
/* Driverlib includes */
#include "hw_types.h"
#include "hw_ints.h"
#include "hw_memmap.h"
#include "interrupt.h"
#include "pin.h"
#include "prcm.h"
#include "rom.h"
#include "rom_map.h"
#include "uart.h"
#include "utils.h"
#include "simplelink.h"
#include "device.h"
#include "oslib/osi.h"
#include <mongoose.h>
#define CONSOLE_BAUD_RATE 115200
#define CONSOLE_UART UARTA0_BASE
#define CONSOLE_UART_PERIPH PRCM_UARTA0
#define WIFI_SSID "YourWiFi"
#define WIFI_PASS "YourPassword"
struct sj_event {
int type;
void *data;
};
OsiMsgQ_t s_v7_q;
struct mg_mgr mg_mgr;
void SimpleLinkWlanEventHandler(SlWlanEvent_t *e) {
if (e->Event == SL_WLAN_CONNECT_EVENT) {
LOG(LL_INFO, ("WiFi: connected"));
} else {
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: %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)));
}
}
static void ev_handler(struct mg_connection *nc, int ev, void *p) {
LOG(LL_DEBUG, ("Ev: %d", ev));
if (ev == MG_EV_HTTP_REQUEST) {
struct mg_serve_http_opts opts;
memset(&opts, 0, sizeof(opts));
opts.document_root = ".";
mg_serve_http(nc, (struct http_message *) p, opts);
}
}
static void mg_task(void *arg) {
LOG(LL_INFO, ("Hello, world!"));
osi_MsgQCreate(&s_v7_q, "V7", sizeof(struct sj_event), 32 /* len */);
sl_Start(NULL, NULL, NULL);
if (strlen(WIFI_SSID) > 0) {
int ret;
SlSecParams_t sp;
sl_WlanSetMode(ROLE_STA);
sl_Stop(0);
sl_Start(NULL, NULL, NULL);
sl_WlanDisconnect();
LOG(LL_INFO, ("WiFi: connecting to %s", WIFI_SSID));
sp.Key = (_i8 *) WIFI_PASS;
sp.KeyLen = strlen(WIFI_PASS);
sp.Type = sp.KeyLen ? SL_SEC_TYPE_WPA : SL_SEC_TYPE_OPEN;
ret = sl_WlanConnect((const _i8 *) WIFI_SSID, strlen(WIFI_SSID), 0, &sp, 0);
if (ret != 0) {
LOG(LL_ERROR, ("WlanConnect error: %d\n", ret));
}
} else {
LOG(LL_INFO, ("Not connecting to WiFi."));
sl_Start(NULL, NULL, NULL);
}
/* We don't need TI's web server. */
sl_NetAppStop(SL_NET_APP_HTTP_SERVER_ID);
mg_mgr_init(&mg_mgr, NULL);
const char *err = "";
struct mg_bind_opts opts;
memset(&opts, 0, sizeof(opts));
opts.error_string = &err;
struct mg_connection *nc = mg_bind(&mg_mgr, "80", ev_handler);
if (nc != NULL) {
mg_set_protocol_http_websocket(nc);
} else {
LOG(LL_ERROR, ("Failed to create listener: %s", err));
}
while (1) {
struct sj_event e;
mg_mgr_poll(&mg_mgr, 0);
if (osi_MsgQRead(&s_v7_q, &e, 1000) != OSI_OK) continue;
}
}
/* Int vector table, defined in startup_gcc.c */
extern void (*const g_pfnVectors[])(void);
int main() {
MAP_IntVTableBaseSet((unsigned long) &g_pfnVectors[0]);
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, _IONBF, 0);
setvbuf(stderr, NULL, _IONBF, 0);
//cs_log_set_level(LL_INFO);
cs_log_set_level(LL_VERBOSE_DEBUG);
VStartSimpleLinkSpawnTask(8);
osi_TaskCreate(mg_task, (const signed char *) "mg", 8192, NULL, 3, NULL);
osi_start();
return 0;
}
/* These are FreeRTOS hooks for various life situations. */
void vApplicationMallocFailedHook() {
}
void vApplicationIdleHook() {
}
void vApplicationStackOverflowHook(OsiTaskHandle *th, signed char *tn) {
}
void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *e,
SlHttpServerResponse_t *resp) {
}
void SimpleLinkSockEventHandler(SlSockEvent_t *e) {
}

View File

@ -0,0 +1 @@
docker.cesanta.com:5000/cc3200-build:1.1.0-r7

View File

@ -0,0 +1,7 @@
<!DOCTYPE HTML>
<html>
<head></head>
<body>
<h1>Hello, world!</h1>
</body>
</html>

View File

@ -3,7 +3,7 @@
# `wildcard ./*/` works in both linux and linux/wine, while `wildcard */` enumerates nothing under wine
SUBDIRS = $(sort $(dir $(wildcard ./*/)))
SUBDIRS:=$(filter-out ./, $(SUBDIRS))
SUBDIRS:=$(filter-out ./ ./CC3200/, $(SUBDIRS))
ifeq ($(OS), Windows_NT)
SUBDIRS:=$(filter-out ./load_balancer/ ./netcat/ ./raspberry_pi_mjpeg_led/ ./captive_dns_server/, $(SUBDIRS))

View File

@ -5865,7 +5865,12 @@ static void mg_http_send_file2(struct mg_connection *nc, const char *path,
snprintf(range, sizeof(range), "Content-Range: bytes %" INT64_FMT
"-%" INT64_FMT "/%" INT64_FMT "\r\n",
r1, r1 + cl - 1, (int64_t) st->st_size);
#if _FILE_OFFSET_BITS == 64 || _POSIX_C_SOURCE >= 200112L || \
_XOPEN_SOURCE >= 600
fseeko(pd->file.fp, r1, SEEK_SET);
#else
fseek(pd->file.fp, r1, SEEK_SET);
#endif
}
}

View File

@ -561,7 +561,7 @@ int gettimeofday(struct timeval *t, void *tz);
long int random(void);
#ifdef CC3200_ENABLE_SPIFFS
#ifdef CC3200_FS_SPIFFS
#include <common/spiffs/spiffs.h>
typedef struct {
@ -575,7 +575,7 @@ typedef struct {
DIR *opendir(const char *dir_name);
int closedir(DIR *dir);
struct dirent *readdir(DIR *dir);
#endif
#endif /* CC3200_FS_SPIFFS */
#endif /* CS_PLATFORM == CS_P_CC3200 */
#endif /* CS_COMMON_PLATFORMS_PLATFORM_CC3200_H_ */