Exemplo n.º 1
0
void mrf24j40_setup_io() {

        #ifndef __PIC32MX__	
	        make_input(mrf24j40_int_port, mrf24j40_int_pin);
	        set_pin(mrf24j40_cs_port, mrf24j40_cs_pin);	// keep high
	        make_output(mrf24j40_cs_port, mrf24j40_cs_pin);
        #endif	
        #ifdef __PIC32MX__
        	SPI_init();			// init SPI default (2 on PIC32-PINGUINO)
        						// only called here for test
        						// will be called later in main32.c
        	#ifndef PIC32_PINGUINO_220
				//pinmode(13,OUTPUT); // CLK
				//pinmode(11,OUTPUT); // SDO
				//pinmode(12,INPUT);	// SDI				
				ZIGRESETOUT;		// macro for RESET
				ZIGCSOUT;			// macro for CS
				ZIGINTIN;			// interrupt (not yet implemented)
        	#else
				ZIGRESETOUT;		// macro for RESET
				ZIGCSOUT;			// macro for CS
			#endif
        	ZIGRESET=0;
        	ZIGCS=1;
        	ZIGRESET=1;
        	Delayms(100);
		#endif        	
}
Exemplo n.º 2
0
void make_output(int pin) {
    // Reset 3-bit configuration bits to 0b000
    make_input(pin);

    // 32-bit block containing pin
    volatile unsigned *block = gpio + (pin / 10);

    // Pin's location in block
    int loc = (pin % 10) * 3;

    // 0b001 is the 3-bit number to make pin an output
   *block |=  (0b001 << loc);  
}
Exemplo n.º 3
0
 tensor_t model_t::make_input(const image_t& image, const rect_t& region) const
 {
         return make_input(image, region.left(), region.top());
 }
Exemplo n.º 4
0
 const tensor_t& model_t::output(const image_t& image, coord_t x, coord_t y) const
 {
         return output(make_input(image, x, y));
 }
Exemplo n.º 5
0
void ht1632_set_pixel(uns8 x, uns8 y, uns8 colour) {

uns8 common, panel, led_in_panel, inverted_x, out, mem_addr, bit_in_mem_addr, count, data;

	// first calculate memory address
	
	// y location on panels is top left based
	
	common = 15 - y;
	
/* Previous calculations:
	panel = x / 8;	// which panel of the three is it that we need to change?
	led_in_panel = x - (panel * 8); 
	inverted_x = 7 - led_in_panel;
	out = panel * 8 + led_in_panel; //inverted_x;
	mem_addr = out * 4 + common / 4;
*/
	bit_in_mem_addr = common & 0b00000011;
	

	mem_addr = x * 4 + common / 4;


	clear_pin(ht1632_cs1_port, ht1632_cs1_pin);

	// send WR command

	// send 1
	set_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);
	
	// send 0
	clear_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);

	// send 1
	set_pin  (ht1632_data_port, ht1632_data_pin);
	// pulse wr
	clear_pin(ht1632_wr_port, ht1632_wr_pin);
	set_pin  (ht1632_wr_port, ht1632_wr_pin);

	// write mem addr, bits 6 -> 0
	for(count = 0 ; count < 7 ; count++) {
		if (test_bit(mem_addr, 6)) {
			set_pin(ht1632_data_port, ht1632_data_pin);
		} else { 
			clear_pin(ht1632_data_port, ht1632_data_pin);
		}

		//change_pin_var(ht1632_data_port, ht1632_data_pin, test_bit(mem_addr, 6));
		// pulse rd
		clear_pin(ht1632_wr_port, ht1632_wr_pin);
		set_pin  (ht1632_wr_port, ht1632_wr_pin);

		// shift mem addr along
		mem_addr = mem_addr << 1;
	}

	// Retrieve 4 bits
	// read clocked out on falling edge of RD
	
	make_input(ht1632_data_port, ht1632_data_pin);

	for(count = 0 ; count < 4 ; count++) {
		// pulse rd
		clear_pin(ht1632_rd_port, ht1632_rd_pin);

		data = data >> 1;
		data.3 = test_pin(ht1632_data_port, ht1632_data_pin);

		set_pin  (ht1632_rd_port, ht1632_rd_pin);

	}

	make_output(ht1632_data_port, ht1632_data_pin);

	// now we have the data, we need to change the bit
	if (colour) {
		set_bit(data, bit_in_mem_addr);
	} else {
		clear_bit(data, bit_in_mem_addr);
	}	
	
	// Now write it back out again
	
	// write data, bits 0 -> 3 (different from mem addr format)
	for(count = 0 ; count < 4 ; count++) {
		//change_pin_var(ht1632_data_port, ht1632_data_pin, test_bit(data, 0));
		if (test_bit(data, 0)) {
			set_pin(ht1632_data_port, ht1632_data_pin);
		} else { 
			clear_pin(ht1632_data_port, ht1632_data_pin);
		}

		// pulse wr
		clear_pin(ht1632_wr_port, ht1632_wr_pin);
		set_pin  (ht1632_wr_port, ht1632_wr_pin);
		// shift data along
		data = data >> 1;
	}
	
	
	// reset CS
	// don't think this is necessary
//	set_pin(ht1632_cs1_port, ht1632_cs1_pin);
//	clear_pin(ht1632_cs1_port, ht1632_cs1_pin);
	set_pin  (ht1632_cs1_port, ht1632_cs1_pin);
	
	
}
Exemplo n.º 6
0
/*
 * The primary compute function for the bucket sort
 * Executes the sum of NUM_ITERATIONS + BURN_IN iterations, as defined in params.h
 * Only iterations after the BURN_IN iterations are timed
 * Only the final iteration calls the verification function
 */
static int bucket_sort(void)
{
  int err = 0;

  init_timers(NUM_ITERATIONS);

#ifdef PERMUTE
  create_permutation_array();
#endif

  for(uint64_t i = 0; i < (NUM_ITERATIONS + BURN_IN); ++i)
  {

    // Reset timers after burn in 
    if(i == BURN_IN){ init_timers(NUM_ITERATIONS); } 

    SHMEM_BARRIER_AT_START;

    timer_start(&timers[TIMER_TOTAL]);

    KEY_TYPE * my_keys = make_input();

    int * local_bucket_sizes = count_local_bucket_sizes(my_keys);

    int * send_offsets;
    int * local_bucket_offsets = compute_local_bucket_offsets(local_bucket_sizes,
                                                                   &send_offsets);

    KEY_TYPE * my_local_bucketed_keys =  bucketize_local_keys(my_keys, local_bucket_offsets);

    KEY_TYPE * my_bucket_keys = exchange_keys(send_offsets, 
                                              local_bucket_sizes,
                                              my_local_bucketed_keys);

    my_bucket_size = receive_offset;

    int * my_local_key_counts = count_local_keys(my_bucket_keys);

    SHMEM_BARRIER_AT_END;

    timer_stop(&timers[TIMER_TOTAL]);

    // Only the last iteration is verified
    if(i == NUM_ITERATIONS) { 
      err = verify_results(my_local_key_counts, my_bucket_keys);
    }

    // Reset receive_offset used in exchange_keys
    receive_offset = 0;

    free(my_local_bucketed_keys);
    free(my_keys);
    free(local_bucket_sizes);
    free(local_bucket_offsets);
    free(send_offsets);
    free(my_local_key_counts);

    shmem_barrier_all();
  }

  return err;
}