Difference between revisions of "Concept of meta"

From Ethersex_Wiki
Jump to: navigation, search
m (framework for the file meta.c)
(meta.h / meta_header_magic.m4)
Line 51: Line 51:
 
Contains the structures  
 
Contains the structures  
 
* uip_udp_connection_state and  
 
* uip_udp_connection_state and  
* uuip_tcp_conenction state  
+
* uip_tcp_conenction state  
which can be extenede with the macros
+
which can be extended with the macros
 
* state_udp
 
* state_udp
 
* state_tcp
 
* state_tcp
  
Why you should do that? - Dig into the network stuff! - I don't know at the moment.
+
If a module wants to save a network relevant state as part of it's functionality, it has to be part of the connection_state structure.
 +
Since it is a union, I think, it is neccessary for passing the structure to the network functions.
 +
 
 +
I.e. the module dyndns puts the dyndns connection state structure there.
 +
 
 +
But look into the details by yourself - if you like.
 +
 
  
 
=== Macro state_header ===
 
=== Macro state_header ===

Revision as of 19:42, 17 May 2012

Intro

With meta information in each module the main program is set up depending on the configuration. At the end there will be a short example of such meta information.

If you continue to read, you should understand this concept: M4 - very short intro (Deutsch)#divert

Also have a look at the files explained while reading - that will help.

meta.c / meta_magic.m4

The creation of this file is mainly controlled by the file "meta_magic.m4".

What is in the file meta_magic.m4?

framework for the file meta.c

The framework consists of several divert sections, in which code of the used modules is injected.

Only the idea of the injection is explained with the first injection point.

The second section starts with "divert(initearly_divert)dnl" and contains the function "ethersex_meta_init", but the final closing brace of the function is missing. So if you define further divert sections with the index "initearly_divert", then it will be in the output before the closing brace and so part of "ethersex_meta_init".

Therefore later in in the file some macros are defined - in this case it is named "initearly".

This macros and some others are all defined the same way:

define(`initearly',`dnl
divert(initearly_divert) $1 ();
divert(-1)')

So if the meta macro initearly(<module-initearly-functionname>) is used, the module initearly function will be called from the function ethersex_meta_init, because the function call will be in the output directly after the section.

The closing brace of the function is part of the next section "divert(net_init_divert)".

structure of meta.c

meta.c itself contains several functions, which are called at important points in the firmware:

  • ethersex_meta_init
    is called in the startup before the pins are initialized
  • ethersex_meta_startup
    is called before the main loop starts
  • ethersex_meta_mainloop
    is called in the main loop - injected functions should do only short processings or reset the watchdog by thereselfs ...
  • periodic_process
    is the last function called in ethersex_meta_mainloop - after all the injected modules function
    does some network and console reading (ECMD support and other) - at the momenet I don't know the backgrounds of this operations.
    further operations can be injected here - a counter incremented on each call can be used to delay the injected code ...

meta.h / meta_header_magic.m4

Contains the structures

  • uip_udp_connection_state and
  • uip_tcp_conenction state

which can be extended with the macros

  • state_udp
  • state_tcp

If a module wants to save a network relevant state as part of it's functionality, it has to be part of the connection_state structure. Since it is a union, I think, it is neccessary for passing the structure to the network functions.

I.e. the module dyndns puts the dyndns connection state structure there.

But look into the details by yourself - if you like.


Macro state_header

By use if this macro it is possible to include additional ".h" files into meta.h.

Usage:

 state_header(<path_and_filename>)

Expands to

 #include "<path_and_filename>"

Examlpe meta section

From tanklevel.c

  -- Ethersex META --
 header(services/tanklevel/tanklevel.h)
 init(tanklevel_init)
 timer(1, tanklevel_periodic())
  • header
    • include file for meta.c
  • init
    • Aufruf von tanklevel_init() in meta_init
  • timer
    • Aufruf von tanklevel_periodic() bei jedem Durchlauf der main_loop

Closing

After all this explained I want to mention that some modules are not only in that structured way integrated into the project. There are also direct compiler directives for them in the framework itself ... this looks like needed "hacks".