2014-12-22 12:35:05 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Copyright 2013-2014 Espressif Systems (Wuxi)
|
|
|
|
*
|
|
|
|
* FileName: user_main.c
|
|
|
|
*
|
|
|
|
* Description: entry file of user application
|
|
|
|
*
|
|
|
|
* Modification history:
|
|
|
|
* 2014/1/1, v1.0 create this file.
|
|
|
|
*******************************************************************************/
|
|
|
|
#include "lua.h"
|
|
|
|
#include "platform.h"
|
2016-05-26 10:36:20 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2015-04-02 18:51:02 +02:00
|
|
|
#include "flash_fs.h"
|
2016-03-24 00:06:09 +01:00
|
|
|
#include "flash_api.h"
|
2014-12-22 12:35:05 +01:00
|
|
|
#include "user_interface.h"
|
2015-06-25 07:32:21 +02:00
|
|
|
#include "user_modules.h"
|
2016-05-26 10:36:20 +02:00
|
|
|
#include "rom.h"
|
2014-12-22 12:35:05 +01:00
|
|
|
|
|
|
|
#include "ets_sys.h"
|
|
|
|
#include "driver/uart.h"
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
#include "task/task.h"
|
2016-05-26 10:31:09 +02:00
|
|
|
#include "sections.h"
|
2014-12-22 12:35:05 +01:00
|
|
|
#include "mem.h"
|
2016-05-30 09:56:33 +02:00
|
|
|
#include "freertos/task.h"
|
2014-12-22 12:35:05 +01:00
|
|
|
|
2015-06-25 07:32:21 +02:00
|
|
|
#ifdef LUA_USE_MODULES_RTCTIME
|
|
|
|
#include "rtc/rtctime.h"
|
|
|
|
#endif
|
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
#define SIG_LUA 0
|
2015-10-08 04:33:15 +02:00
|
|
|
#define SIG_UARTINPUT 1
|
2015-11-12 02:57:07 +01:00
|
|
|
|
2016-05-26 10:36:20 +02:00
|
|
|
extern void call_user_start (void);
|
|
|
|
|
2015-11-12 02:57:07 +01:00
|
|
|
|
2015-06-23 07:38:52 +02:00
|
|
|
/* Note: the trampoline *must* be explicitly put into the .text segment, since
|
|
|
|
* by the time it is invoked the irom has not yet been mapped. This naturally
|
|
|
|
* also goes for anything the trampoline itself calls.
|
|
|
|
*/
|
2015-07-06 05:45:35 +02:00
|
|
|
void TEXT_SECTION_ATTR user_start_trampoline (void)
|
2015-06-23 07:38:52 +02:00
|
|
|
{
|
2015-06-25 07:32:21 +02:00
|
|
|
#ifdef LUA_USE_MODULES_RTCTIME
|
|
|
|
// Note: Keep this as close to call_user_start() as possible, since it
|
|
|
|
// is where the cpu clock actually gets bumped to 80MHz.
|
2015-07-06 05:45:35 +02:00
|
|
|
rtctime_early_startup ();
|
2015-06-25 07:32:21 +02:00
|
|
|
#endif
|
2015-11-12 02:57:07 +01:00
|
|
|
|
2016-05-26 07:47:33 +02:00
|
|
|
/* The first thing call_user_start() does is switch the interrupt vector
|
|
|
|
* base, which enables our 8/16bit load handler. */
|
2015-06-23 07:38:52 +02:00
|
|
|
call_user_start ();
|
|
|
|
}
|
|
|
|
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
// +================== New task interface ==================+
|
2016-05-24 10:07:27 +02:00
|
|
|
static void start_lua(task_param_t param, task_prio_t prio) {
|
2016-05-31 05:56:47 +02:00
|
|
|
(void)param;
|
2016-05-24 10:07:27 +02:00
|
|
|
(void)prio;
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
char* lua_argv[] = { (char *)"lua", (char *)"-i", NULL };
|
|
|
|
NODE_DBG("Task task_lua started.\n");
|
|
|
|
lua_main( 2, lua_argv );
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
|
|
|
|
2016-05-24 10:07:27 +02:00
|
|
|
static void handle_input(task_param_t flag, task_prio_t priority) {
|
|
|
|
(void)priority;
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
lua_handle_input (flag);
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
|
|
|
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
static task_handle_t input_sig;
|
2014-12-22 12:35:05 +01:00
|
|
|
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
task_handle_t user_get_input_sig(void) {
|
|
|
|
return input_sig;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool user_process_input(bool force) {
|
|
|
|
return task_post_low(input_sig, force);
|
|
|
|
}
|
2014-12-30 19:47:44 +01:00
|
|
|
|
2015-01-23 06:25:54 +01:00
|
|
|
void nodemcu_init(void)
|
2014-12-22 12:35:05 +01:00
|
|
|
{
|
|
|
|
NODE_ERR("\n");
|
2015-10-30 04:25:02 +01:00
|
|
|
// Initialize platform first for lua modules.
|
2014-12-22 12:35:05 +01:00
|
|
|
if( platform_init() != PLATFORM_OK )
|
|
|
|
{
|
|
|
|
// This should never happen
|
|
|
|
NODE_DBG("Can not init platform for modules.\n");
|
|
|
|
return;
|
|
|
|
}
|
2015-03-15 22:40:43 +01:00
|
|
|
|
|
|
|
#if defined(FLASH_SAFE_API)
|
|
|
|
if( flash_safe_get_size_byte() != flash_rom_get_size_byte()) {
|
|
|
|
NODE_ERR("Self adjust flash size.\n");
|
|
|
|
// Fit hardware real flash size.
|
|
|
|
flash_rom_set_size_byte(flash_safe_get_size_byte());
|
2015-11-12 02:57:07 +01:00
|
|
|
|
2015-04-02 18:51:02 +02:00
|
|
|
if( !fs_format() )
|
|
|
|
{
|
|
|
|
NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" );
|
|
|
|
NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" );
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
NODE_ERR( "format done.\n" );
|
|
|
|
}
|
|
|
|
fs_unmount(); // mounted by format.
|
2015-03-15 22:40:43 +01:00
|
|
|
|
2016-05-18 21:45:15 +02:00
|
|
|
// Reboot to get SDK to use (or write) init data at new location
|
2015-11-12 02:57:07 +01:00
|
|
|
system_restart ();
|
2016-05-18 21:45:15 +02:00
|
|
|
|
|
|
|
// Don't post the start_lua task, we're about to reboot...
|
|
|
|
return;
|
2015-01-05 16:57:07 +01:00
|
|
|
}
|
2016-05-18 21:45:15 +02:00
|
|
|
#endif // defined(FLASH_SAFE_API)
|
2015-01-05 16:57:07 +01:00
|
|
|
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
#if defined ( BUILD_SPIFFS )
|
2015-04-02 18:51:02 +02:00
|
|
|
fs_mount();
|
2014-12-22 12:35:05 +01:00
|
|
|
// test_spiffs();
|
|
|
|
#endif
|
|
|
|
|
2016-05-31 05:56:47 +02:00
|
|
|
task_post_low(task_get_id(start_lua), 0);
|
2014-12-22 12:35:05 +01:00
|
|
|
}
|
2015-01-23 06:25:54 +01:00
|
|
|
|
2016-05-30 09:56:33 +02:00
|
|
|
|
|
|
|
static void nodemcu_main (void *param)
|
|
|
|
{
|
|
|
|
(void)param;
|
|
|
|
|
|
|
|
nodemcu_init ();
|
|
|
|
|
|
|
|
task_pump_messages ();
|
|
|
|
__builtin_unreachable ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-23 06:25:54 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* FunctionName : user_init
|
|
|
|
* Description : entry of user application, init user function here
|
|
|
|
* Parameters : none
|
|
|
|
* Returns : none
|
|
|
|
*******************************************************************************/
|
|
|
|
void user_init(void)
|
|
|
|
{
|
2015-07-06 05:45:35 +02:00
|
|
|
#ifdef LUA_USE_MODULES_RTCTIME
|
|
|
|
rtctime_late_startup ();
|
|
|
|
#endif
|
2015-01-23 06:25:54 +01:00
|
|
|
|
2015-10-30 04:25:02 +01:00
|
|
|
UartBautRate br = BIT_RATE_DEFAULT;
|
|
|
|
|
Add New Tasking I/F and rework GPIO, UART, etc to support it
As with the last commit this rolls up the follwowing, but include the various
review comments on the PR.
- **Documentation changes**. I've added the taks FAQ as a stub new Extension
developer FAQ, and split the old FAQ into a Lua Developer FAQ and a Hardware
FAQ.
- **Tasking I/F**. New `app/task/Makefile`, `app/task/task.c`,
`app/include/task/task.h` and `app/Makefile` as per previous commit. Cascade
changes to `app/driver/uart.c`, `app/include/driver/uart.h`,
`app/user/user_main.c` and `app/modules/node.c`
- **GPIO Rework** to `app/modules/gpio.c` and `pin_map.[hc]`, `platform.[hc]`
in `app/platform`
- **Other Optimisations** Move the `platform_*_exists()` from
`app/platform/common.c` to static inline declarations in `platform.h` as
this generates faster, smaller code. Move lgc.a routines out of iram0.
2016-02-17 18:13:17 +01:00
|
|
|
input_sig = task_get_id(handle_input);
|
|
|
|
uart_init (br, br, input_sig);
|
2015-10-30 04:25:02 +01:00
|
|
|
|
2016-03-20 17:54:16 +01:00
|
|
|
#ifndef NODE_DEBUG
|
2015-01-23 06:25:54 +01:00
|
|
|
system_set_os_print(0);
|
2016-03-20 17:54:16 +01:00
|
|
|
#endif
|
2015-10-08 05:14:51 +02:00
|
|
|
|
2016-05-30 09:56:33 +02:00
|
|
|
// FIXME! Max supported RTOS stack size is 512 words (2k bytes), but
|
|
|
|
// NodeMCU currently uses more than that. The game is on to find these
|
|
|
|
// culprits, but this gcc doesn't do the -fstack-usage option :(
|
|
|
|
xTaskCreate (
|
|
|
|
nodemcu_main, "nodemcu", 600, 0, configTIMER_TASK_PRIORITY +1, NULL);
|
2015-01-23 06:25:54 +01:00
|
|
|
}
|