/* -------------------------------------------------------------------- * DUPLICATE THE GRAPH */ tg tg_dup(tg graph) { tg g2; int node; task_list arcs=NULL; int elements, count; int resource; /* 1. INITIALIZE THE NEW GRAPH */ g2 = tg_init(tg_resnum(graph)); /* 2. FOR ALL NODES ON THE OLD ONE */ for (node = 0; node <= tg_maxid(graph); node ++ ) { /* 2.1. ... THAT EXISTS ... */ if (!tg_id(graph, node)) continue; /* 2.2. CREATE NODE */ tg_add_node(g2, node); /* 2.3. COPY INFORMATION */ for (resource = 0; resource < tg_resnum(graph); resource ++ ) { tg_set_resource(g2, node, resource, tg_get_resource(graph, node, resource)); } /* 2.4. CREATE ARCS FOR SUCCESORS */ elements = tg_succ_num(graph, node); arcs = (task_list) malloc( sizeof(tg_task) * elements); if ( arcs == NULL ) { Asystem_error("tg_dup", "Not enough memory", "arcs"); } memcpy(arcs,tg_succ(graph,node), sizeof(tg_task)*elements ); for (count = 0; count < elements; count ++ ) { /* 2.4.1. IF SUCCESOR DOES NOT EXIST YET, CREATE */ if (!tg_id(g2, arcs[count])) tg_add_node(g2, arcs[count]); /* 2.4.2. ADD ARC */ tg_add_arc(g2, node, arcs[count]); } free(arcs); arcs=NULL; } /* 3. SET ROOT */ tg_set_root(g2, tg_root(graph)); /* 4. RETURN THE NEW GRAPH */ return g2; }
int main(void) { // There are a lot of dependencies in the order of these inits. // Don't change the ordering unless you understand this. // Inits can assume that all memory has been zeroed by either // a hardware reset or a watchdog timer reset. cli(); // system and drivers sys_init(); // system hardware setup - must be first rtc_init(); // real time counter xio_init(); // xmega io subsystem sig_init(); // signal flags st_init(); // stepper subsystem - must precede gpio_init() gpio_init(); // switches and parallel IO pwm_init(); // pulse width modulation drivers - must follow gpio_init() // application structures tg_init(STD_INPUT); // tinyg controller (controller.c) - must be first app init; reqs xio_init() cfg_init(); // config records from eeprom - must be next app init mp_init(); // motion planning subsystem cm_init(); // canonical machine - must follow cfg_init() sp_init(); // spindle PWM and variables // now bring up the interupts and get started PMIC_SetVectorLocationToApplication(); // as opposed to boot ROM PMIC_EnableHighLevel(); // all levels are used, so don't bother to abstract them PMIC_EnableMediumLevel(); PMIC_EnableLowLevel(); sei(); // enable global interrupts rpt_print_system_ready_message();// (LAST) announce system is ready _unit_tests(); // run any unit tests that are enabled tg_canned_startup(); // run any pre-loaded commands while (true) { // if (tg.network == NET_MASTER) { // tg_repeater(); // } else if (tg.network == NET_SLAVE) { // tg_receiver(); // } else { tg_controller(); // NET_STANDALONE // } } }
void tg_system_reset(void) { cli(); // These inits are order dependent: _tg_debug_init(); // (0) inits for the debug system sys_init(); // (1) system hardware setup xio_init(); // (2) xmega io subsystem tg_init(STD_INPUT); // (3) tinyg controller (arg is std devices) sig_init(); // (4) signal flags rtc_init(); // (5) real time counter st_init(); // (6) stepper subsystem (must run before gp_init()) gpio_init(); // (7) switches and parallel IO PMIC_EnableMediumLevel();// enable TX interrupts for init reporting sei(); // enable global interrupts cfg_init(); // (8) get config record from eeprom (reqs xio) tg_announce(); // print version string }
/* -------------------------------------------------------------------- * READ THE GRAPH STRUCTURE FROM A TEXT FILE */ tg tg_read(FILE *fp) { tg graph; tg_task tid; int tasknum, resnum, i; int succnum, succ, t; double rvalue; char comments[256]; task_list list=NULL; int elements; int check; /* SKIP INITIAL COMMENTS BEGINING WITH # */ check = fscanf(fp, "%[#]", comments); while(check==1) { fscanf(fp, "%[^\n]", comments); fscanf(fp, "\n"); check = fscanf(fp, "%[#]", comments); } /* 1. READ NUMBER OF TASK AND RESOURCES */ tasknum=-1; check = fscanf(fp, "T:%d\n", &tasknum); CheckError(check==1 && tasknum>0, "reading graph file: Number of tasks"); check = fscanf(fp, "R:%d\n", &resnum); CheckError(check==1 && resnum>=0, "reading graph file: Number of resources"); /* 2. INITIALIZE GRAPH WITH NUMBER OF RESOURCES */ graph = tg_init(resnum); /* 3. READ TASKS */ for (t = 0; t < tasknum; t++) { /* 3.1. READ NUMBER OF TASK */ check = fscanf(fp,"t%d:",&tid); CheckError(check==1 && tid>=0, "reading graph file: Reading a task number"); /* 3.2. CREATE TASK IF IT DOES NOT EXIST */ if (!tg_id(graph, tid)) tg_add_node(graph, tid); /* 3.3. RESOURCES */ for ( i = 0; i < resnum; i++) { check = fscanf(fp,"%lf",&rvalue); CheckError(check==1 && rvalue>=0.0, "reading graph file: Reading task resource values"); tg_set_resource(graph, tid, i, rvalue); } /* 3.4. NUMBER OF SUCCESORS */ check = fscanf(fp,"%[ ]s%d:",comments,&succnum); CheckError(check==2 && succnum>=0.0, "reading graph file: Reading the number of successors of a task"); /* 3.5. SUCCESORS */ for ( i = 0; i < succnum; i++) { check = fscanf(fp,"%d",&succ); CheckError(check==1 && succ>=0, "reading graph file: Reading the successors of a task"); if (!tg_id(graph, succ)) { tg_add_node(graph, succ); } tg_add_arc(graph, tid, succ); } /* 3.6. END ON LINE */ fscanf(fp,"%[ \n]", comments); } /* 4. DETECT ROOT */ elements = tg_pred_grade(graph, 0, &list); if (elements == 1) tg_set_root(graph, list[0]); free(list); list = NULL; /* 5. RETURN THE NEW GRAPH */ return graph; }