void hTimer(uint tick, uint Unused) { if(tick==1) { io_printf(IO_STD, "Collecting all workers ID\n"); spin1_schedule_callback(pingWorkers, 0,0,PRIORITY_PROCESSING); } // after 3 ticks, all workers should have reported else if(tick==3) { io_printf(IO_STD, "Total workers: %d\n", workers.tAvailable); for(int i=0; i<workers.tAvailable; i++) { io_printf(IO_STD, "worker-%d is core-%d\n", i, workers.wID[i]); } } else if(tick==5) { io_printf(IO_STD, "Distributing workload...\n"); // send worker's block ID, except to leadAp uint check, key, payload; for(uint i=1; i<workers.tAvailable; i++) { key = workers.wID[i]; payload = workers.tAvailable << 16; payload += i; check = spin1_send_mc_packet(key, payload, WITH_PAYLOAD); if(check==SUCCESS) io_printf(IO_BUF, "Sending id-%d to core-%d\n", payload, key); else io_printf(IO_BUF, "Fail sending id-%d to core-%d\n", payload, key); } io_printf(IO_STD, "Ready for image...\n"); spin1_callback_off(TIMER_TICK); } }
void compass_received(uint key, uint payload) { io_printf(IO_STD, "this was a compass message: %08x,%08x \n", key, payload); if ( abs(heading - payload) > 100000) { spin1_send_mc_packet(0x111002a0,0x40,1); // slowly forwards io_printf(IO_STD, "Go forwards again.\n"); spin1_send_mc_packet(0x111002a2,0,1); // no roll spin1_callback_off(MCPL_PACKET_RECEIVED); // deregister my callback heading = -1; //reset heading } }