Move mg_task to SimpleLink platform code

It'll be used for MSP432 as well

PUBLISHED_FROM=cb5dcda4cc5d9edc6dea71540d51ab00e252186e
This commit is contained in:
Deomid Ryabkov 2016-04-11 19:46:31 +02:00 committed by rojer
parent 76364af243
commit c8b09c2238
8 changed files with 91 additions and 95 deletions

View File

@ -7,6 +7,9 @@ PORT ?= auto
MAKEFLAGS += w MAKEFLAGS += w
all clean: all clean:
rm -rf ccs/*/Debug
rm -rf ccs/*/Release
rm -rf ccs/*/.launches
docker run --rm -i -v $(SRC_DIR):/src $(SDK) \ docker run --rm -i -v $(SRC_DIR):/src $(SDK) \
/bin/bash -c "\ /bin/bash -c "\
make -C /src/mongoose mongoose.c mongoose.h && \ make -C /src/mongoose mongoose.c mongoose.h && \

View File

@ -93,7 +93,7 @@ VPATH += $(SDK_PATH)/driverlib $(SDK_PATH)/example/common $(SDK_PATH)/oslib \
$(SDK_PATH)/third_party/FreeRTOS/source/portable/GCC/ARM_CM4 \ $(SDK_PATH)/third_party/FreeRTOS/source/portable/GCC/ARM_CM4 \
$(SDK_PATH)/third_party/FreeRTOS/source/portable/MemMang \ $(SDK_PATH)/third_party/FreeRTOS/source/portable/MemMang \
APP_SRCS = main.c bm222.c data.c mongoose.c mg_task.c tmp006.c wifi.c $(SDK_SRCS) 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))) APP_OBJS = $(addprefix $(OBJDIR)/,$(patsubst %.c,%.o,$(APP_SRCS)))
$(FW_ELF): $(APP_OBJS) $(FW_ELF): $(APP_OBJS)

View File

@ -25,16 +25,6 @@
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature> <nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures> </natures>
<linkedResources> <linkedResources>
<link>
<name>mg_task.c</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/mg_task.c</locationURI>
</link>
<link>
<name>mg_task.h</name>
<type>1</type>
<locationURI>PARENT-2-PROJECT_LOC/mg_task.h</locationURI>
</link>
<link> <link>
<name>mongoose.c</name> <name>mongoose.c</name>
<type>1</type> <type>1</type>

View File

@ -31,7 +31,6 @@
#include "data.h" #include "data.h"
#include "mongoose.h" #include "mongoose.h"
#include "mg_task.h"
#include "wifi.h" #include "wifi.h"
/* Set up an AP or connect to existing WiFi network. */ /* Set up an AP or connect to existing WiFi network. */
@ -52,8 +51,6 @@
#define BM222_ADDR 0x18 #define BM222_ADDR 0x18
#define TMP006_ADDR 0x41 #define TMP006_ADDR 0x41
extern int cc3200_fs_init();
static struct mg_str upload_fname(struct mg_connection *nc, static struct mg_str upload_fname(struct mg_connection *nc,
struct mg_str fname) { struct mg_str fname) {
struct mg_str lfn; struct mg_str lfn;
@ -124,7 +121,9 @@ static void mg_init(struct mg_mgr *mgr) {
data_init_sensors(TMP006_ADDR, BM222_ADDR); data_init_sensors(TMP006_ADDR, BM222_ADDR);
cc3200_fs_init(); sl_fs_init();
sl_Start(NULL, NULL, NULL);
#if defined(WIFI_STA_SSID) #if defined(WIFI_STA_SSID)
if (!wifi_setup_sta(WIFI_STA_SSID, WIFI_STA_PASS)) { if (!wifi_setup_sta(WIFI_STA_SSID, WIFI_STA_PASS)) {

View File

@ -1,46 +0,0 @@
#include "mg_task.h"
enum mg_q_msg_type {
MG_Q_MSG_CB,
};
struct mg_q_msg {
enum mg_q_msg_type type;
void (*cb)(struct mg_mgr *mgr, void *arg);
void *arg;
};
static OsiMsgQ_t s_mg_q;
static void mg_task(void *arg);
bool mg_start_task(int priority, int stack_size, mg_init_cb mg_init) {
if (osi_MsgQCreate(&s_mg_q, "MG", sizeof(struct mg_q_msg), 16) != OSI_OK) {
return false;
}
if (osi_TaskCreate(mg_task, (const signed char *) "MG", stack_size,
(void *) mg_init, priority, NULL) != OSI_OK) {
return false;
}
return true;
}
static void mg_task(void *arg) {
struct mg_mgr mgr;
mg_init_cb mg_init = (mg_init_cb) arg;
sl_Start(NULL, NULL, NULL);
mg_mgr_init(&mgr, NULL);
mg_init(&mgr);
while (1) {
struct mg_q_msg msg;
mg_mgr_poll(&mgr, 1);
if (osi_MsgQRead(&s_mg_q, &msg, 1) != OSI_OK) continue;
switch (msg.type) {
case MG_Q_MSG_CB: {
msg.cb(&mgr, msg.arg);
}
}
}
}
void mg_run_in_task(void (*cb)(struct mg_mgr *mgr, void *arg), void *cb_arg) {
struct mg_q_msg msg = {MG_Q_MSG_CB, cb, cb_arg};
osi_MsgQWrite(&s_mg_q, &msg, OSI_NO_WAIT);
}

View File

@ -1,20 +0,0 @@
/*
* Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved
*/
#ifndef CS_MONGOOSE_EXAMPLES_CC3200_MG_TASK_H_
#define CS_MONGOOSE_EXAMPLES_CC3200_MG_TASK_H_
#include <stdbool.h>
#include <stdlib.h>
#include <oslib/osi.h>
#include "mongoose.h"
typedef void (*mg_init_cb)(struct mg_mgr *mgr);
bool mg_start_task(int priority, int stack_size, mg_init_cb mg_init);
void mg_run_in_task(void (*cb)(struct mg_mgr *mgr, void *arg), void *cb_arg);
#endif /* CS_MONGOOSE_EXAMPLES_CC3200_MG_TASK_H_ */

View File

@ -10153,10 +10153,13 @@ int _isatty(int fd) {
#if CS_PLATFORM == CS_P_MSP432 #if CS_PLATFORM == CS_P_MSP432
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Clock.h>
int gettimeofday(struct timeval *tp, void *tzp) { int gettimeofday(struct timeval *tp, void *tzp) {
/* FIXME */ uint32_t ticks = Clock_getTicks();
tp->tv_sec = 42; tp->tv_sec = ticks / 1000;
tp->tv_usec = 123; tp->tv_usec = (ticks % 1000) * 1000;
return 0; return 0;
} }
@ -10173,8 +10176,8 @@ long int random(void) {
* All rights reserved * All rights reserved
*/ */
#ifndef CS_SMARTJS_PLATFORMS_SIMPLELINK_SL_FS_SLFS_H_ #ifndef CS_COMMON_PLATFORMS_SIMPLELINK_SL_FS_SLFS_H_
#define CS_SMARTJS_PLATFORMS_SIMPLELINK_SL_FS_SLFS_H_ #define CS_COMMON_PLATFORMS_SIMPLELINK_SL_FS_SLFS_H_
#if defined(MG_FS_SLFS) #if defined(MG_FS_SLFS)
@ -10199,7 +10202,7 @@ int fs_slfs_rename(const char *from, const char *to);
#endif /* defined(MG_FS_SLFS) */ #endif /* defined(MG_FS_SLFS) */
#endif /* CS_SMARTJS_PLATFORMS_SIMPLELINK_SL_FS_SLFS_H_ */ #endif /* CS_COMMON_PLATFORMS_SIMPLELINK_SL_FS_SLFS_H_ */
#ifdef MG_MODULE_LINES #ifdef MG_MODULE_LINES
#line 1 "./src/../../common/platforms/simplelink/sl_fs_slfs.c" #line 1 "./src/../../common/platforms/simplelink/sl_fs_slfs.c"
#endif #endif
@ -10273,7 +10276,7 @@ int fs_slfs_open(const char *pathname, int flags, mode_t mode) {
struct sl_fd_info *fi = &s_sl_fds[fd]; struct sl_fd_info *fi = &s_sl_fds[fd];
_u32 am = 0; _u32 am = 0;
fi->size = -1; fi->size = (size_t) -1;
if (pathname[0] == '/') pathname++; if (pathname[0] == '/') pathname++;
int rw = (flags & 3); int rw = (flags & 3);
if (rw == O_RDONLY) { if (rw == O_RDONLY) {
@ -10322,7 +10325,7 @@ ssize_t fs_slfs_read(int fd, void *buf, size_t count) {
if (fi->fh <= 0) return set_errno(EBADF); if (fi->fh <= 0) return set_errno(EBADF);
/* Simulate EOF. sl_FsRead @ file_size return SL_FS_ERR_OFFSET_OUT_OF_RANGE. /* Simulate EOF. sl_FsRead @ file_size return SL_FS_ERR_OFFSET_OUT_OF_RANGE.
*/ */
if (fi->size >= 0 && fi->pos == fi->size) return 0; if (fi->pos == fi->size) return 0;
_i32 r = sl_FsRead(fi->fh, fi->pos, buf, count); _i32 r = sl_FsRead(fi->fh, fi->pos, buf, count);
DBG(("sl_FsRead(%d, %d, %d) = %d", (int) fi->fh, (int) fi->pos, (int) count, DBG(("sl_FsRead(%d, %d, %d) = %d", (int) fi->fh, (int) fi->pos, (int) count,
(int) r)); (int) r));
@ -10636,7 +10639,7 @@ ssize_t _read(int fd, void *buf, size_t count) {
ssize_t _write(int fd, const void *buf, size_t count) { ssize_t _write(int fd, const void *buf, size_t count) {
int r = -1; int r = -1;
size_t i; size_t i = 0;
switch (fd_type(fd)) { switch (fd_type(fd)) {
case FD_INVALID: case FD_INVALID:
r = set_errno(EBADF); r = set_errno(EBADF);
@ -10652,6 +10655,8 @@ ssize_t _write(int fd, const void *buf, size_t count) {
if (c == '\n') MAP_UARTCharPut(CONSOLE_UART, '\r'); if (c == '\n') MAP_UARTCharPut(CONSOLE_UART, '\r');
MAP_UARTCharPut(CONSOLE_UART, c); MAP_UARTCharPut(CONSOLE_UART, c);
} }
#else
(void) i;
#endif #endif
r = count; r = count;
break; break;
@ -10745,7 +10750,7 @@ int mkdir(const char *path, mode_t mode) {
} }
#endif #endif
int cc3200_fs_init() { int sl_fs_init() {
int ret = 1; int ret = 1;
#ifdef __TI_COMPILER_VERSION__ #ifdef __TI_COMPILER_VERSION__
#ifdef MG_FS_SLFS #ifdef MG_FS_SLFS
@ -10811,4 +10816,58 @@ int inet_pton(int af, const char *src, void *dst) {
return 1; return 1;
} }
#endif /* MG_SOCKET_SIMPLELINK */ #endif /* CS_COMMON_PLATFORMS_SIMPLELINK_SL_SOCKET_C_ */
#ifdef MG_MODULE_LINES
#line 1 "./src/../../common/platforms/simplelink/sl_mg_task.c"
#endif
#if defined(MG_SOCKET_SIMPLELINK)
/* Amalgamated: #include "mg_task.h" */
#include <oslib/osi.h>
enum mg_q_msg_type {
MG_Q_MSG_CB,
};
struct mg_q_msg {
enum mg_q_msg_type type;
void (*cb)(struct mg_mgr *mgr, void *arg);
void *arg;
};
static OsiMsgQ_t s_mg_q;
static void mg_task(void *arg);
bool mg_start_task(int priority, int stack_size, mg_init_cb mg_init) {
if (osi_MsgQCreate(&s_mg_q, "MG", sizeof(struct mg_q_msg), 16) != OSI_OK) {
return false;
}
if (osi_TaskCreate(mg_task, (const signed char *) "MG", stack_size,
(void *) mg_init, priority, NULL) != OSI_OK) {
return false;
}
return true;
}
static void mg_task(void *arg) {
struct mg_mgr mgr;
mg_init_cb mg_init = (mg_init_cb) arg;
mg_mgr_init(&mgr, NULL);
mg_init(&mgr);
while (1) {
struct mg_q_msg msg;
mg_mgr_poll(&mgr, 1);
if (osi_MsgQRead(&s_mg_q, &msg, 1) != OSI_OK) continue;
switch (msg.type) {
case MG_Q_MSG_CB: {
msg.cb(&mgr, msg.arg);
}
}
}
}
void mg_run_in_task(void (*cb)(struct mg_mgr *mgr, void *arg), void *cb_arg) {
struct mg_q_msg msg = {MG_Q_MSG_CB, cb, cb_arg};
osi_MsgQWrite(&s_mg_q, &msg, OSI_NO_WAIT);
}
#endif /* defined(MG_SOCKET_SIMPLELINK) */

View File

@ -621,12 +621,14 @@ int _stat(const char *pathname, struct stat *st);
* All rights reserved * All rights reserved
*/ */
#ifndef CS_SMARTJS_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_ #ifndef CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_
#define CS_SMARTJS_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_ #define CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_
/* If simplelink.h is already included, all bets are off. */ /* If simplelink.h is already included, all bets are off. */
#if defined(MG_SOCKET_SIMPLELINK) && !defined(__SIMPLELINK_H__) #if defined(MG_SOCKET_SIMPLELINK) && !defined(__SIMPLELINK_H__)
#include <stdbool.h>
#ifndef __TI_COMPILER_VERSION__ #ifndef __TI_COMPILER_VERSION__
#undef __CONCAT #undef __CONCAT
#undef FD_CLR #undef FD_CLR
@ -711,9 +713,18 @@ const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
char *inet_ntoa(struct in_addr in); char *inet_ntoa(struct in_addr in);
int inet_pton(int af, const char *src, void *dst); int inet_pton(int af, const char *src, void *dst);
struct mg_mgr;
typedef void (*mg_init_cb)(struct mg_mgr *mgr);
bool mg_start_task(int priority, int stack_size, mg_init_cb mg_init);
void mg_run_in_task(void (*cb)(struct mg_mgr *mgr, void *arg), void *cb_arg);
int sl_fs_init();
#endif /* defined(MG_SOCKET_SIMPLELINK) && !defined(__SIMPLELINK_H__) */ #endif /* defined(MG_SOCKET_SIMPLELINK) && !defined(__SIMPLELINK_H__) */
#endif /* CS_SMARTJS_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_ */ #endif /* CS_COMMON_PLATFORMS_SIMPLELINK_CS_SIMPLELINK_H_ */
/* /*
* Copyright (c) 2014-2016 Cesanta Software Limited * Copyright (c) 2014-2016 Cesanta Software Limited
* All rights reserved * All rights reserved