Chat freely about anything...

User avatar
By RogerClark
#4458 Hi guys,

I've been trying to understand the structure of an esp8266 build, but I can't find any documentation about the core setup

It doesn't look like there is a main() in any of the "app" code ? I presume that this must be linked from the SDK and that it calls user_init() ?

Also I'm unclear about why there is a folder called driver , I can see that people put code in there to communicate with the UART etc, but I'm not sure why code needs to be put in that folder, or if it needs to be there at all

I've read the latest SDK document 0.9.2 and I can't see any mention of user_init() or drivers

Is there another document that describes an overview of the structure and hierarchy, build and run process ?

Another thing I'm unclear of is why the code is usually split into 2 blocks, I presume this is a code block and a data (text) block, but unless you want to keep replacing the code and not replacing the text this seems pointless

And I see in some things the app is split into even more blocks e.g. the web server I think is in 3 blocks

Can someone let me know where the documentation is that describes why this is done etc.

Thanks

Roger
User avatar
By ni9e
#4616 I am wondering the same thing.

The 'IoT_Demo' project that's included with the SDK has this structure, but other projects have only some of the folders.

Code: Select alllol@satan:~/git/esp8266/esp_iot_sdk_v0.9.3/examples/IoT_Demo$ ls
driver  include  json  lwip  Makefile  ssl  upgrade  user


If someone with a bit of insight could give us directions on how to get started with this, I would be grateful.
User avatar
By RogerClark
#4623 As far as I can tell the use of the directories can't be a specific requirement.

They just contain .c files which are compiled to .o files which are all linked together. i.e the .o files in the driver folder are not linked separately to the ones in the user folder.

e.g there only appears to be one entry for the linker in the Makefile I'm using

$(Q) $(LD) -L$(SDK_LIBDIR) $(LD_SCRIPT) $(LDFLAGS) -Wl,--start-group $(LIBS) $(APP_AR) -Wl,--end-group -o $@


Re: user_init()

I think we have to assume that the SDK contains main() and that sometime after startup, that it calls user_init(), which is the equivalent to main, except that you must return as soon as possible and run all code via timers and other callbacks. i.e event driven model.

There are 2 other bits of code that look interesting

static void ICACHE_FLASH_ATTR procTask(os_event_t *events)
{
}

and
#define procTaskPrio 0

void ICACHE_FLASH_ATTR user_init(void)
{
...
...
...
system_os_post(procTaskPrio, 0, 0 );
}

The docs for this read

3.2.12. system_os_post
Function: Send a message to the task
Function definition:
void system_os_post (uint8 prio, os_signal_t sig, os_param_t par)
Input parameters: uint8 prio -- task priorities, and the priority of establishing correspondence
os_signal_t sig -- message type
os_param_t par-- message parameters


But I'm not precisely sure what that means. it appears to be sending a message to the system of priority 0, the other two parameters 0 as well

I've no idea how the SDK knows that it needs to call procTask(), as this function name doesnt seem to be referenced in the e.g. blinky. i.e nothing is setting procTask() as a callback

So this would seem to imply that only one of these functions should exist and it is always run by the system, but perhaps if system_os_post(procTaskPrio, 0, 0 ); is not called, then procTask(); doesnt get called.

Obviously someone must know how this works, as there are various bits of code kicking around the web, but perhaps they contain a load of redundant code, e.g. perhaps procTask() is not required if you don't want to handle events ??

Shame no one seems to know anything about this, on this forum, perhaps there is a better forum for this device ?
User avatar
By igrr
#4626 system_os_post sends a message to a task with a given priority. to start the task, you call system_os_task passing a function pointer and a priority. for each priority there is a single task, so system_os_post can uniquely identify the task by priority.

searching this forum would give you some references: http://www.esp8266.com/viewtopic.php?f=5&t=418&p=1790&hilit=system_os_post#p1790

reading existing code, e.g. Sprite_tm's webserver, or Necromant's firmware, or my AT firmware, could also help you.