void c_main (void) { uint coreID = spin1_get_core_id(); uint chipID = spin1_get_chip_id(); if(chipID == 0 && coreID == 1) { io_printf (IO_STD, "Hello world! (via SDP)\n"); io_printf (IO_BUF, "Hello world! (via the terminal)\n"); if(spin_devin_init() == 0) { io_printf(IO_BUF, "Error: could not connect to the SpiNNaker!\n"); } spin_devin_send_motor(2000 << 16 | 2000); uint cam = spin_devin_get_camera(); io_printf(IO_BUF, "camera: %08x\n", cam); spin1_set_timer_tick(10000); spin1_callback_on(TIMER_TICK, upd, 0); spin_devin_dispose(); } spin1_start(); }
/****f* simple.c/c_main * * SUMMARY * This function is called at application start-up. * It is used to register event callbacks and begin the simulation. * * SYNOPSIS * int c_main() * * SOURCE */ void c_main() { io_printf (IO_STD, ">> simple\n"); /* get this core's IDs */ coreID = spin1_get_core_id(); chipID = spin1_get_chip_id(); /* TODO: Works on 4-chip board only! */ /* set the core map for the simulation */ if (NUMBER_OF_CHIPS > 0) core_map[0] = CORE_MAP_00; if (NUMBER_OF_CHIPS > 1) core_map[1] = CORE_MAP_01; if (NUMBER_OF_CHIPS > 2) core_map[2] = CORE_MAP_10; if (NUMBER_OF_CHIPS > 3) core_map[3] = CORE_MAP_11; spin1_set_core_map(NUMBER_OF_CHIPS, core_map); /* set timer tick value (in microseconds) */ spin1_set_timer_tick(TIMER_TICK_PERIOD); /* register callbacks */ spin1_callback_on(MC_PACKET_RECEIVED, count_packets, -1); spin1_callback_on(DMA_TRANSFER_DONE, check_memcopy, 0); spin1_callback_on(USER_EVENT, send_packets, 2); spin1_callback_on(TIMER_TICK, flip_led, 3); /* initialize application */ app_init(); /* go */ spin1_start(); /* report results */ app_done(); }
void flush_output_spikes() { if(spike_output->arg1) { spike_output->srce_addr = spin1_get_chip_id(); spike_output->arg2 = spin1_get_simulation_time(); spike_output->length = 24 + spike_output->arg1 * 4; spin1_send_sdp_msg(spike_output, 1); // Timeout on transmission at 1ms /* io_printf(IO_STD, "sending spikes out\n");*/ spike_output->arg1 = 0; spike_output->cmd_rc = 0x100; } }
void timer_callback(uint key, uint payload) { chipID = spin1_get_chip_id(); coreID = spin1_get_core_id(); uint newID; uint newKey; if (nIterations == 1 && chipID == 0 && coreID == 1) { io_printf(IO_STD, "Switching to Spomnibot project\n"); spin1_send_mc_packet(0x111007F1, 2, 1); } if (nIterations == 2 && chipID == 0 && coreID == 1) { spin1_send_mc_packet(0x111002b7, 0, 1); io_printf(IO_STD, "Beep!\n"); } if (nIterations == 10 && chipID == 0 && coreID == 1) { spin1_send_mc_packet(0x111002c3, 10, 1); // 10Hz io_printf(IO_STD, "Setting up sensor streaming\n"); spin1_send_mc_packet(0x111002c2, 1<<4|1 , 1); // bump + compass } if (nIterations == 50 && chipID == 0 && coreID == 1) { spin1_send_mc_packet(0x111002a0, 0x30, 1); //driving forward io_printf(IO_STD, "driving forward\n"); } if (nIterations == 200 && chipID == 0 && coreID == 1) { spin1_send_mc_packet(0x111002a7, 0x00, 1); //stop all io_printf(IO_STD, "stopping now\n"); } if (chipID == 0 && coreID == 1) { io_printf(IO_STD, "iteration %d\n", nIterations); nIterations++; } //updateNeurons(); }
// The idea is to set a communication system whose purpose // is to exchange data from a virtual master node (situated // at core 0, chip 0) and all the other cores situated on all // the other chips. From master node to other nodes we use multicast // messages, whereas from a node to master node we use sdp messages. void c_main (void) { // simulation initialization coreID = spin1_get_core_id(); chipID = spin1_get_chip_id(); if(chipID == 0 && coreID == 1) { io_printf(IO_BUF,"CoreID is %u, ChipID is %u\n",coreID, chipID); spin1_set_timer_tick(TICK_TIME); // end of simulation initialization spin1_callback_on(TIMER_TICK, update, 1); spin_devin_init(); } spin1_start(); }
void send_sync_sdp(void) { sdp_msg_t sync_pkt; sync_pkt.tag = 1; sync_pkt.dest_port = PORT_ETH; sync_pkt.dest_addr = 0; sync_pkt.flags = 0x07; sync_pkt.srce_port = 3 << 5 | app_data.virtual_core_id; sync_pkt.srce_addr = spin1_get_chip_id(); sync_pkt.cmd_rc = 0; sync_pkt.arg1 = 0; sync_pkt.arg2 = spin1_get_simulation_time(); sync_pkt.arg3 = 0; sync_pkt.data[0] = 0; sync_pkt.data[1] = 0; sync_pkt.length = 26; io_printf(IO_STD, "sending sync spike\n"); spin1_send_sdp_msg (&sync_pkt, 1); }
/* sending an mc packet to the application monitoring processor */ void send_special_mc_packet(unsigned short population_id, unsigned short instruction_code, int value) { uint key = spin1_get_chip_id() << 16 | 1 << 15 | // spike/no spike spin1_get_core_id()-1 << 11 | 1 << 10 | // system/application population_id << 4 | instruction_code; /* io_printf(IO_STD, "key: %8x x: %u y: %u s: %u core_id : %u a: %u popid : %u ic : %u\n", */ /* key,*/ /* (key >> 24) & 0xFF,*/ /* (key >> 16) & 0xFF, */ /* (key >> 15) & 0x1,*/ /* (key >> 11) & 0xF, */ /* (key >> 10) & 0x1, // system/application*/ /* (key >> 4) & 0x3F, */ /* (key & 0xF)); */ spin1_send_mc_packet(key, value, 1); }
void send_out_value(int arg1, int arg2, int arg3, int out_value) { sdp_msg_t sdp_value_packet; int * ptr = (int *)&(sdp_value_packet.data[0]); //io_printf (IO_STD, "sending packet\n"); sdp_value_packet.tag = 1; sdp_value_packet.dest_port = PORT_ETH; sdp_value_packet.dest_addr = 0; sdp_value_packet.flags = 0x07; sdp_value_packet.srce_port = 4 << 5 | app_data.virtual_core_id; sdp_value_packet.srce_addr = spin1_get_chip_id();; *ptr = out_value; sdp_value_packet.length = 28; sdp_value_packet.cmd_rc = 257; sdp_value_packet.arg1 = arg1; sdp_value_packet.arg2 = arg2; sdp_value_packet.arg3 = arg3; spin1_send_sdp_msg (&sdp_value_packet, 1); /* io_printf(IO_STD, "sending vakue %d\n", out_value);*/ sdp_value_packet.arg1 = 0; }
void c_main (void) { io_printf (IO_STD, "Starting communication test.\n"); // get this core's ID coreID = spin1_get_core_id(); chipID = spin1_get_chip_id(); // get this chip's coordinates for core map my_x = chipID >> 8; my_y = chipID & 0xff; my_chip = (my_x * NUMBER_OF_YCHIPS) + my_y; // operate only if in core map! if ((core_map[my_x][my_y] & (1 << coreID)) == 0) { io_printf (IO_STD, "Stopping comm. (Not in core map)\n"); return; } // set the core map for the simulation spin1_application_core_map(NUMBER_OF_XCHIPS, NUMBER_OF_YCHIPS, core_map); spin1_set_timer_tick (TIMER_TICK_PERIOD); // register callbacks spin1_callback_on (MC_PACKET_RECEIVED, receive_data, 0); spin1_callback_on (TIMER_TICK, update, 0); spin1_callback_on (SDP_PACKET_RX, host_data, 0); // Initialize routing tables routing_table_init (); // Initialize SDP message buffer sdp_init (); // go spin1_start(); }
void c_main (void) { int chipIDs[] = {0, 1, 256, 257}; chipID = spin1_get_chip_id(); coreID = spin1_get_core_id(); spikeNumber = 0; //io_printf(IO_STD, "Simulation starting on (chip: %d, core: %d)...\n", chipID, coreID); // Set the number of chips in the simulation //spin1_set_core_map(64, (uint *)(0x74220000)); // set the core map for the simulation //spin1_application_core_map(2, 2, core_map); //spin1_set_core_map(4, (uint *)(core_map)); // initialise routing entries // set a MC routing table entry to send my packets back to me if (chipID == 0 && coreID == 1) { /* ------------------------------------------------------------------- */ /* initialise routing entries */ /* ------------------------------------------------------------------- */ /* set a MC routing table entry to send my packets back to me */ io_printf(IO_STD, "Setting routing table on (chip: %d, core: %d)...\n", chipID, coreID); uint e = rtr_alloc (1); if (e == 0) rt_error (RTE_ABORT); rtr_mc_set (e, // entry 0x11100001, // key 0xFFFF0001, // mask SOUTH_WEST ); e = rtr_alloc (1); if (e == 0) rt_error (RTE_ABORT); rtr_mc_set (e, // entry 0x11100000, // key 0xFFFF0001, // mask SOUTH_WEST ); e = rtr_alloc (1); if (e == 0) rt_error (RTE_ABORT); rtr_mc_set (e, 0x80000000 | 9 << 7 | 0 << 2, 0x80000000 | 15 << 7 | 31 << 2, CORE(2) // core 2 handles bump sensor ); e = rtr_alloc (1); if (e == 0) rt_error (RTE_ABORT); rtr_mc_set (e, 0x80000000 | 9 << 7 | 4 << 2 | 2, 0x80000000 | 15 << 7 | 31 << 2 | 3, CORE(3) // core 3 handles compass sensor ); e = rtr_alloc (1); if (e == 0) rt_error (RTE_ABORT); rtr_mc_set (e, 0x80000000 , //| 9 << 7 | 0 << 2, 0x80000000 , //| 15 << 7 | 0 << 2, CORE(4) // core 4 logs data ); } // Call hardware and simulation configuration functions spin1_set_timer_tick(TIME_STEP_MICROSEC); if (chipID == 0 && coreID == 1) //core1 handles time-based stuff { spin1_callback_on(TIMER_TICK, timer_callback, TIMER_PRIORITY); } if (chipID == 0 && coreID == 2) { spin1_callback_on(MCPL_PACKET_RECEIVED, bump_received, MC_PACKET_EVENT_PRIORITY); } if (chipID == 0 && coreID == 3) { spin1_callback_on(MC_PACKET_RECEIVED, enable_packet_received, MC_PACKET_EVENT_PRIORITY); } if (chipID == 0 && coreID == 4) { // Register callbacks spin1_callback_on(MC_PACKET_RECEIVED, multiCastPacketReceived_callback, MC_PACKET_EVENT_PRIORITY); spin1_callback_on(MCPL_PACKET_RECEIVED, multiCastPacketReceived_with_payload_callback, MC_PACKET_EVENT_PRIORITY); } // transfer control to the run-time kernel //if (chipID == 0 && coreID == 1) { spin1_start(0); } }
void synaptic_event(void *dma_copy, uint row_size) { uint time = spin1_get_simulation_time()*1000 + spin1_get_us_since_last_tick(); char evt_connected = 0; #ifdef DEBUG io_printf(IO_STD, "Inside synaptic_event\n"); io_printf(IO_STD, "Received event at time %u ms\n", time); #endif synaptic_row_t *synaptic_row = (synaptic_row_t *) dma_copy; neuron_t *neuron = (neuron_t *) population->neuron; for(uint i = 0; i < row_size; i++) { synaptic_word_t decoded_word; decode_synaptic_word (synaptic_row->synapses[i], &decoded_word); #ifdef DEBUG io_printf(IO_STD, "Type %d, weight %d, index %d, arrival %d, synapses: %08x, synaptic word: %08x\n", decoded_word.synapse_type, decoded_word.weight, decoded_word.index, time, (int) &synaptic_row->synapses[i], synaptic_row->synapses[i]); #endif // Process only if the weight is non-zero if (decoded_word.weight == 0) { #ifdef DEBUG io_printf(IO_STD, "Non connected pre-neuron, dropping\n", time); #endif continue; } evt_connected = 1; // Drop the event if the queue is full if (!spike_ring->ring_empty && spike_ring->ring_start == spike_ring->ring_end) { missed_events++; } else { spike_ring->ring[spike_ring->ring_end].ts = time + delay_us; spike_ring->ring[spike_ring->ring_end].key = spin1_get_chip_id() << 16 | app_data.virtual_core_id << 11 | population->id | decoded_word.index; spike_ring->ring_end = (spike_ring->ring_end+1) % SPIKE_QUEUE_SIZE; if (spike_ring->ring_empty) { #ifdef DEBUG io_printf(IO_STD, "Scheduling an event in %u us.\n", delay_us); #endif schedule_trigger_timer2(send_spike_callback, delay_us); } spike_ring->ring_empty = 0; } } #ifdef DEBUG io_printf(IO_STD, "Received event at time %u ms\n", time); io_printf(IO_STD, "Ring state :\n"); io_printf(IO_STD, "\tstart : %u\n", spike_ring->ring_start); io_printf(IO_STD, "\tend : %u\n", spike_ring->ring_end); io_printf(IO_STD, "\tempty : %d\n", spike_ring->ring_empty); io_printf(IO_STD, "\tring addr : 0x%x\n", spike_ring->ring); #endif if (evt_connected) { events_received++; } }
void c_main (void) { // simulation initialization coreID = spin1_get_core_id(); chipID = spin1_get_chip_id(); spin1_set_timer_tick(TICK_TIME); // the intrachip communication is totally independent from a // chip to another. chips do not interfere with each other (good point) if(chipID == 0) { // 0, 0 // in this chip, we test master to nodes, then nodes to master // results: performance is good // from master to nodes spin1_set_mc_table_entry(0x6, ERROR_MSG, 0xFFFFFFFF, ALL_NODES_MASTER_CHIP); // froms nodes to master spin1_set_mc_table_entry(0x7, UPD_MSG, 0xFFFFFFFF, MASTER_CORE); if(coreID == 1) { // master core // events setting spin1_callback_on(MC_PACKET_RECEIVED,eventMaster_chip0,0); spin1_callback_on(TIMER_TICK, update_chip0, 0); } else { // nodes // events setting spin1_callback_on(MC_PACKET_RECEIVED,eventNode_chip0,0); } } else if(chipID == 1) { // 0, 1 // in this chip, we test parallel message sending (core 1 to 2, core 3 to 4 and core 5 to 6, independently) // results: performance good spin1_set_mc_table_entry(0x2, 0x2, 0xFFFFFFFF, CORE(2)); spin1_set_mc_table_entry(0x4, 0x4, 0xFFFFFFFF, CORE(4)); spin1_set_mc_table_entry(0x6, 0x6, 0xFFFFFFFF, CORE(6)); if(coreID == 3 | coreID == 1 | coreID == 5) { // sending cores spin1_callback_on(TIMER_TICK, update_chip1, -2); } else { // receiving cores spin1_callback_on(MC_PACKET_RECEIVED,eventRec_chip1,-1); } } else if(chipID == 256) { // 1, 0 // ... } else if(chipID == 257) { // 1, 1 // ... } // Note that calling io_printf in the functions slows down a lot the system. // Therefore tests should be performed without calling this function // (or calling it not so often) spin1_start(); }