Example #1
0
void
on_timer_tick(uint _1, uint _2)
{
	counter += 1;
	counter &= 0xFF;
	
	if (counter <= (*led_value)) {
		spin1_led_control(LED_ON(BLINK_LED));
	} else {
		spin1_led_control(LED_OFF(BLINK_LED));
	}
}
/**
 * A function which will store a copy of the results in SDRAM, overwriting the
 * original configuration.
 *
 * Note that this is currently implemented the slow way using memcpy rather than
 * DMA to simplify programing as the penalty for the one-off copy is not too
 * significant.
 */
void
store_results(void)
{
	// Turn on LED until results written
	if (leadAp)
		spin1_led_control(LED_ON(BLINK_LED));
	
	// Copy source results back.
	config_source_t *config_sources_sdram_addr = (config_source_t *)( ((uint)CONFIG_ROOT_SDRAM_ADDR(spin1_get_core_id()))
	                                                                  + sizeof(config_root_t)
	                                                                )
	                                           ;
	spin1_memcpy( config_sources_sdram_addr
	            , &config_sources
	            , sizeof(config_source_t) * config_root.num_sources
	            );
	
	// Copy sink results back.
	config_sink_t *config_sinks_sdram_addr = (config_sink_t *)( ((uint)CONFIG_ROOT_SDRAM_ADDR(spin1_get_core_id()))
	                                                            + sizeof(config_root_t)
	                                                            + sizeof(config_source_t) * config_root.num_sources
	                                                          )
	                                         ;
	spin1_memcpy( config_sinks_sdram_addr
	            , &config_sinks
	            , sizeof(config_sink_t) * config_root.num_sinks
	            );
	
	// Record router counters
	config_root.result_forwarded_packets = rtr_unbuf[FWD_CNTR_CNT];
	config_root.result_dropped_packets   = rtr_unbuf[DRP_CNTR_CNT];
	
	// Copy root config results back last so that the completion_state is only
	// updated when most of the data is coppied back.
	config_root_t *config_root_sdram_addr = CONFIG_ROOT_SDRAM_ADDR(spin1_get_core_id());
	spin1_memcpy(config_root_sdram_addr, &config_root, sizeof(config_root_t));
	
	// Note that routes are not copied back because they aren't changed.
	
	io_printf( IO_BUF, "Stored results back into 0x%08x.\n"
	         , (uint)config_root_sdram_addr
	         );
	
	// Turn off LED on completion.
	if (leadAp)
		spin1_led_control(LED_OFF(BLINK_LED));
}
Example #3
0
/****f* simple.c/flip_led
*
* SUMMARY
*  This function is used as a callback for timer tick events.
*  It inverts the state of LED 1 and sends packets.
*
* SYNOPSIS
*  void flip_led (uint ticks, uint null)
*
* INPUTS
*   uint ticks: simulation time (in ticks) - provided by the RTS
*   uint null: padding - all callbacks must have two uint arguments!
*
* SOURCE
*/
void flip_led (uint ticks, uint null)
{
  /* flip led 1 */
  /* Only 1 core should flip leds! */
  if ((get_ncores(NUMBER_OF_CHIPS, core_map) == 1) || (coreID == 1))
  {
    spin1_led_control(LED_INV (1));
  }

  /* trigger user event to send packets */
  if (spin1_trigger_user_event(ticks, NULL) == FAILURE)
  {
    ufailed++;
  }

  /* stop if desired number of ticks reached */
  if (ticks >= TOTAL_TICKS) spin1_stop();
}
/**
 * Traffic generation and experiment management.
 */
void
on_timer_tick(uint _1, uint _2)
{
	// Experiment management
	if (simulation_warmup && simulation_ticks == 0) {
		// Start of warmup
		io_printf(IO_BUF, "Warmup starting...\n");
	}
	
	// Start of warmup, start of experiment
	if (simulation_warmup && simulation_ticks >= config_root.warmup_duration) {
		simulation_ticks = 0u;
		simulation_warmup = false;
		io_printf(IO_BUF, "Warmup ended, starting main experiment...\n");
		
		// Reset and enable counters
		if (leadAp)
			rtr_unbuf[RTR_DGEN] |=  (FWD_CNTR_BIT | DRP_CNTR_BIT)
			                     | ((FWD_CNTR_BIT | DRP_CNTR_BIT)<<16)
			                     ;
	}
	
	// End of experiment
	if (!simulation_warmup && simulation_ticks >= config_root.duration) {
		// Disable counters
		if (leadAp)
			rtr_unbuf[RTR_DGEN] &= ~(FWD_CNTR_BIT | DRP_CNTR_BIT);
		
		if (config_root.completion_state != COMPLETION_STATE_FAILIURE)
			config_root.completion_state = COMPLETION_STATE_SUCCESS;
		
		spin1_stop();
		return;
	}
	
	simulation_ticks ++;
	
	// Show current status using LEDs
	if (leadAp) {
		// Drive with 1/16% brightness in warmup
		if (simulation_warmup)
			spin1_led_control((simulation_ticks%16 == 0) ? LED_ON(BLINK_LED) : LED_OFF(BLINK_LED));
		else
			spin1_led_control(LED_ON(BLINK_LED));
	}
	
	
	// Generate traffic
	for (int i = 0; i < config_root.num_sources; i++) {
		switch (config_sources[i].temporal_dist) {
			case TEMPORAL_DIST_BERNOULLI:
				if (((float)rand() / (float)RAND_MAX) < config_sources[i].temporal_dist_data.bernoulli_packet_prob) {
					generate_packet(i);
				}
				break;
			
			default:
				// Unrecognised temporal distribution do nothing...
				io_printf(IO_BUF, "Unrecognised traffic distribution '%d' for source with key 0x%08x.\n"
				         , config_sources[i].temporal_dist
				         , config_sources[i].routing_key
				         );
				config_root.completion_state = COMPLETION_STATE_FAILIURE;
				break;
		}
	}
}