Compiling Embedded C Code : Initialization

Initialization

The following is a sequence of initialization actions required for I/O mapping:

Initialize all card description elements. At this stage, the pin_array field is set so correspondence between card elements and their pin arrays is established.
For every module, initialize report elements that belong to the module. At the same moment, the corresponding element of the pin array is set to be a pointer to the current report element. The pin arrays are completely initialized. The card_p field of the report element is also initialized. The cross-referenced data structure is built.

The following portions of r2main.c and m1.c illustrate these points:

r2main.c:
void lo_init()
{
init_card_desc(&card_card_1_desc,
card_generic_driver, card_generic_init,
“card_1",pins_card_1_desc);
init_card_desc(&card_card_2_desc,
card_generic_driver,card_generic_init,
“card_2",pins_card_2_desc);
memset(pins_card_1_desc,0,2*sizeof(report_link));
memset(pins_card_2_desc,0,2*sizeof(report_link));
m1_init();
dbg_init();
(*card_card_1_desc.card_init)(&card_card_1_desc);
(*card_card_2_desc.card_init)(&card_card_2_desc);
}
m1.c:
int X_IN1;
report_elem rep_X_IN1;
int X_IN2;
report_elem rep_X_IN2;
int X_OUT1;
report_elem rep_X_OUT1;
int X_OUT2;
report_elem rep_X_OUT2;
...
void m1_init()
{
init_int(&X_IN1,0);
init_report(&rep_X_IN1,"A2:X_IN1","",&X_IN1,
el_enumer,0,trace_f,FALSE,&card_card_1_desc,
"0x0012","1",2,input_mapf,NULL,NULL,FALSE,FALSE);
init_int(&X_IN2,0);
init_report(&rep_X_IN2,"A2:X_IN2","",&X_IN2,
el_enumer,0,NULL,FALSE,&card_card_2_desc,
"0x0012","1",2,input_mapf,NULL,NULL,FALSE,FALSE);
init_int(&X_OUT1,0);
init_report(&rep_X_OUT1,"A2:X_OUT1","",&X_OUT1,
el_enumer,0,trace_f,FALSE,
&card_card_1_desc,"0x0013","2",1,NULL,
NULL,output_mapf,FALSE,FALSE);
init_int(&X_OUT2,0);
init_report(&rep_X_OUT2,"A2:X_OUT2","",&X_OUT2,
el_enumer,0,NULL,FALSE,&card_card_2_desc,
"0x0013","2", 1,NULL,NULL,output_mapf,
FALSE,FALSE);
init_activity(&A1,activ,FALSE,0,0,0,0,0,"A1",FALSE);
}