void init_sli(void) { VexControl vcon; std::set_terminate(__gnu_cxx::__verbose_terminate_handler); vexInitHeap(); LibVEX_default_VexControl(&vcon); vcon.iropt_level = 0; vcon.iropt_unroll_thresh = 0; vcon.guest_chase_thresh = 0; //vcon.guest_max_insns = 1; LibVEX_Init(failure_exit, log_bytes, 0, 0, &vcon); signal(SIGUSR1, handle_sigusr1); initialise_timers(); initialise_profiling(); on_exit(exitfunc, NULL); }
// // // Main procedure // // int main(int argc, char **argv) { int shutdown = 0; // Shutdown flag struct timer_list timers; // Timers int payload_len; // length of payload returned struct payload_pkt app_data; // App payload data char node_name[HOSTNAME_LEN]; // Node name parse_options(argc, argv); // Parse command line parameters debug(DEBUG_ESSENTIAL, "Mesh starting in mode: %d\n", operating_mode); initialise_network(sizeof(struct payload_pkt),notify_link_up, notify_link_down); // Initialise the network details with callbacks initialise_timers(&timers); // and set all timers switch (operating_mode) { case OPMODE_MASTER: // Only Master nodes are responsible for broadcasting add_timer(TIMER_BROADCAST, 5); // Set to refresh network in y seconds break; case OPMODE_SLAVE: // add_timer(TIMER_APPLICATION, 15); // Set to refresh network in y seconds // now done when link comes up break; } add_timer(TIMER_STATS, timeto1hour()); // Report Network Efficiency stats hourly while (!shutdown) { // While NOT shutdown wait_on_network_timers(&timers); // Wait for message or timer expiory if (check_network_msg()) { // If a message is available handle_network_msg(&node_name[0], (char *)&app_data, &payload_len); // handle the network message handle_app_msg(&app_data, payload_len); // handle application specific messages } switch (check_timers(&timers)) { // check which timer has expired case TIMER_BROADCAST: // On Broadcast timer broadcast_network(); // send out broadcast message to contact other nodes add_timer(TIMER_BROADCAST, 20); // and set to broadcast again in y seconds break; case TIMER_PING: if (check_live_nodes()) { // On Ping check the network add_timer(TIMER_REPLY, 2); // Expire replies if not received within x secoonds add_timer(TIMER_PING, 20); // and set to Ping again in y seconds } break; case TIMER_REPLY: expire_live_nodes(); // Expire other nodes where reply has timed out break; case TIMER_STATS: report_network_stats(); // Report network efficiency stats hourly add_timer(TIMER_STATS, timeto1hour()); // Set to refresh network in 1 hour break; case TIMER_PAYLOAD_ACK: timeout_payload(); break; case TIMER_APPLICATION: handle_app_timer(); // Handle the timer for the App break; default: break; } DEBUG_FUNCTION( DEBUG_DETAIL, display_live_network()); DEBUG_FUNCTION( DEBUG_DETAIL, display_timers(&timers)); } debug(DEBUG_ESSENTIAL, "Mesh node shut down\n"); return 0; }