Esempio n. 1
0
int main(void) {
	int i=0, x, y, j, value = 0;
	unsigned char* shared;
	int dim = 40*40*3;
     	while(1){
		for (i = 8; i <= 16; i=i+4){ 
			generate_p3(i, i, 7*i);
//			 Just to see that the task compiles correctly 
			IOWR_ALTERA_AVALON_PIO_DATA(LEDS_GREEN_BASE, value++);

			shared = (unsigned char*) SHARED_ONCHIP_BASE + 4 * (3 + dim);
			while(IORD_32DIRECT(shared, 0) > 0) {}
				//delay
	
			//Read from cpu4 and print to hex
			x = IORD_32DIRECT(shared++, 0)%40;
			y = IORD_32DIRECT(shared++, 0)%40;
			shared++;
			for(i = 0; i < y; i++){
				for(j = 0; j < x; j++){
					printf("%c", (unsigned char)IORD_32DIRECT(shared++, 0));
				 }
				printf("\n");
			}
			shared = (unsigned char*) SHARED_ONCHIP_BASE ;
			while(IORD_32DIRECT(shared, 0) != 0) {}
				//delay
		}

	}

  return 0;
}
Esempio n. 2
0
/**
 * Odczytanie odszyfrowanych danych
 */
void deciph_3des_read ( unsigned int *cdata1, unsigned int *cdata2)
{
	(*cdata1) = IORD_32DIRECT(A_3DESDECRYPT_0_BASE,0x00000040); //Odczytanie pierwszej polowy danych
	(*cdata2) = IORD_32DIRECT(A_3DESDECRYPT_0_BASE,0x00000044); //Odczytanie drugiej polowy danych


}
int main(void){

	//IOWR_32DIRECT(0x00800000, OFFSET*i, 1); //Direccion base de la memoria, desplazamiento y dato a escribir
	//IORD_32DIRECT(0x00000000, 0); //Direccion base de la memoria y desplazamiento (lectura)
	int pruebas=200;
	alt_u32 time1;
	alt_u32 time2;
	alt_u32 time3;
	alt_u32 time4;
	alt_u32 time5;
	alt_u32 time6;
	int i=0, j=0;
	alt_u8 OFFSET=sizeof(int);
	alt_u8 DESPI=0, DESPJ=0;

	if (alt_timestamp_start() < 0)
	{
		printf ("No timestamp device available\n");
	}
	else
	{
		time1 = alt_timestamp();
		//Podemos hacerlo asi o con puntero
		for(i=0; i<pruebas; i++){ //SRAM
			IOWR_32DIRECT(0x01000000, DESPI, 1); //Direccion base de la memoria, desplazamiento y dato a escribir
			DESPI+=OFFSET;
		}

		time2 = alt_timestamp();
		for(j=0; j<pruebas; j++){ //SDRAM
			IOWR_32DIRECT(0x00100000, DESPJ, 1); //Direccion base de la memoria, desplazamiento y dato a escribir
			DESPJ+=OFFSET;
		}
		time3 = alt_timestamp();
		DESPI=0;
		DESPJ=0;

		printf ("time in write SDRAM = %u ticks\n", (unsigned int) (time2 - time1));
		printf ("time in write SRAM = %u ticks\n", (unsigned int) (time3 - time2));

		//LECTURA
		time4 = alt_timestamp();
		for(i=0; i<pruebas; i++){
			IORD_32DIRECT(0x01000000, DESPI); //Direccion base de la memoria, desplazamiento y dato a escribir
			DESPI+=OFFSET;
		}

		time5 = alt_timestamp();
		for(j=0; j<pruebas; j++){
			IORD_32DIRECT(0x00100000, DESPJ); //Direccion base de la memoria, desplazamiento y dato a escribir
			DESPJ+=OFFSET;
		}
		time6 = alt_timestamp();
		printf ("time in read SDRAM = %u ticks\n", (unsigned int) (time5 - time4));
		printf ("time in read SRAM = %u ticks\n", (unsigned int) (time6 - time5));
	}

	return 0;
}
Esempio n. 4
0
char dump_memory()
{
	int i;
	char buf[20] = {'\0'};
	for (i = 0; i<(DATA_MEMORY_SIZE_VALUE); i+=8)
	{
		memset(buf,'\0',sizeof(buf));
		raw_sprintf(buf,"%08x%08x\n", IORD_32DIRECT(DATA_MEMORY_BASE, (i+4)), IORD_32DIRECT(DATA_MEMORY_BASE, i));
		putstr_uart0(buf);
		// Give enough time for sd-card storage
		usleep(14*1000);
	}
	return 1;
}
Esempio n. 5
0
/******************************************************************
*  Function: MemTestAddressBus
*
*  Purpose: Tests that the address bus is connected with no 
*           stuck-at's, shorts, or open circuits.
*
******************************************************************/
static int MemTestAddressBus(unsigned int memory_base, unsigned int nBytes)
{
  unsigned int address_mask = (nBytes - 1);
  unsigned int offset;
  unsigned int test_offset;

  unsigned int pattern     = 0xAAAAAAAA;
  unsigned int antipattern  = 0x55555555;

  unsigned int ret_code = 0x0;

  /* Write the default pattern at each of the power-of-two offsets. */
  for (offset = sizeof(unsigned int); (offset & address_mask) != 0; offset <<= 1)
  {
    IOWR_32DIRECT(memory_base, offset, pattern);
  }

  /* Check for address bits stuck high. */
  test_offset = 0;
  IOWR_32DIRECT(memory_base, test_offset, antipattern);
  for (offset = sizeof(unsigned int); (offset & address_mask) != 0; offset <<= 1)
  {
     if (IORD_32DIRECT(memory_base, offset) != pattern)
     {
        ret_code = (memory_base+offset);
        break;
     }
  }

  /* Check for address bits stuck low or shorted. */
  IOWR_32DIRECT(memory_base, test_offset, pattern);
  for (test_offset = sizeof(unsigned int); (test_offset & address_mask) != 0; test_offset <<= 1)
  {
    if (!ret_code)
    {
      IOWR_32DIRECT(memory_base, test_offset, antipattern);
      for (offset = sizeof(unsigned int); (offset & address_mask) != 0; offset <<= 1)
      {
        if ((IORD_32DIRECT(memory_base, offset) != pattern) && (offset != test_offset))
        {
          ret_code = (memory_base + test_offset);
          break;
        }
      }
      IOWR_32DIRECT(memory_base, test_offset, pattern);
    }
  }

  return ret_code;
}
int alt_up_pixel_buffer_change_back_buffer_address(alt_up_pixel_buffer_dev *pixel_buffer, unsigned int new_address)
/* This function changes the memory address for the back buffer. */
{
	IOWR_32DIRECT(pixel_buffer->base, 4, new_address);
	pixel_buffer->back_buffer_start_address = IORD_32DIRECT(pixel_buffer->base, 4);
	return 0;
}
Esempio n. 7
0
/*
 * Read a stream of bytes for a file (in the position start_byte_in_file), to a length of read_length, on an SD card.
 * @param buf	: Pointer to buffer to start writing to.
 * @param count	: Number of bytes to read from SD card.
 * @return: On success, returns number of bytes read.
 * 			If at end of file, returns -1.
 * 			On error, returns -2.
 */
int sd_read(void* buf, int count) {
	int bytes_read = 0;

	if (count <= 0) { return 0; }
	if (sd_card_curr_read_sector >= sd_card_sectors_num) { return -1; }

	while (sd_card_curr_read_sector < sd_card_sectors_num){
		sd_card_start_read_sector(sd_card_curr_read_sector);
		if(!sd_card_wait_read_sector()){
			printf("Cannot read %d-th sector\n", sd_card_curr_read_sector);
			return -2;
		}

		//move sector to file buffer 32bits at a time
		for(int j = sd_card_start_byte_in_sector; j < 512; j+=4){
			*((uint32_t*)(buf+j-sd_card_start_byte_in_sector)) = IORD_32DIRECT(buffer_memory, j);
			bytes_read += 4;
			if (bytes_read >= count) {
				sd_card_start_byte_in_sector = j + 4;
				return bytes_read;
			}
		}
		buf+= (512 - sd_card_start_byte_in_sector);

		sd_card_curr_read_sector++;
		sd_card_start_byte_in_sector = 0;
	}
	return bytes_read;
}
Esempio n. 8
0
int main()
{
	alt_up_pixel_buffer_dma_dev* pixel_buffer;
	pixel_buffer = alt_up_pixel_buffer_dma_open_dev("/dev/video_pixel_buffer_dma_0");
	if (pixel_buffer == 0) {
		printf("error initializing pixel buffer (check name in alt_up_pixel_buffer_dma_open_dev)\n");
	}
	alt_up_pixel_buffer_dma_change_back_buffer_address(pixel_buffer, PIXEL_BUFFER_BASE);
	alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer);
	while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer));
	alt_up_pixel_buffer_dma_clear_screen(pixel_buffer, 0);

	int hw = 0;
	if (hw) {
           IOWR_32DIRECT(drawer_base,0,10); // Set x1
           IOWR_32DIRECT(drawer_base,4,20); // Set y1
           IOWR_32DIRECT(drawer_base,8,50); // Set x2
           IOWR_32DIRECT(drawer_base,12,60); // Set y2
           IOWR_32DIRECT(drawer_base,16,0xFFFF);  // Set colour
           IOWR_32DIRECT(drawer_base,20,1);  // Start drawing
           while(IORD_32DIRECT(drawer_base,20)==0); // wait until done
 	} else {
           alt_up_pixel_buffer_dma_draw_box(pixel_buffer, 10,20,50,60,0xFFFF,0);
 	}
    return 0;
}
Esempio n. 9
0
void generate_p3(unsigned char size_x, unsigned char size_y, unsigned char max_color) 
{
  unsigned char* shared;


	unsigned char bar_color[8][3] = {
		{255, 255, 255}, // White
		{255, 255, 0  }, // Yellow
		{0  , 255, 255}, // Cyan
		{0  , 255, 0  }, // Green
      		{255, 0  , 255}, // Magenta
      		{255, 0  , 0  }, // Red
		{0,   0  , 255}, // Blue
      		{0,   0  ,   0}, // Black
	 };

	int x, y;
	shared = (unsigned char*) SHARED_ONCHIP_BASE;
	printf("Waiting for %d\n", shared);
	while(IORD_32DIRECT(shared, 0) != 0) {}
		//delay
	shared++;
	IOWR_32DIRECT(shared++, 0, size_y);
	IOWR_32DIRECT(shared++, 0, max_color);
  	for (y = 0; y < size_y; y++){
		 for (x = 0; x < size_x; x++){
			unsigned char color;
			color = y / (size_y / 8);
			IOWR_32DIRECT(shared++, 0, bar_color[color][0]);
			IOWR_32DIRECT(shared++, 0, bar_color[color][1]);
			IOWR_32DIRECT(shared++, 0, bar_color[color][2]);
		}
	}
	IOWR_32DIRECT(SHARED_ONCHIP_BASE, 0, size_x);
}
int alt_up_pixel_buffer_check_swap_buffers_status(alt_up_pixel_buffer_dev *pixel_buffer)
/* This function checks if the buffer swap has occured. Since the buffer swap only happens after an entire screen is drawn,
 * it is important to wait for this function to return 0 before proceeding to draw on either buffer. When both front and the back buffers
 * have the same address calling the alt_up_pixel_buffer_swap_buffers(...) function and then waiting for this function to return 0, causes your program to
 * wait for the screen to refresh. */
{
	return (IORD_32DIRECT(pixel_buffer->base, 12) & 0x1);
}
Esempio n. 11
0
/*
 * get_board_mac_addr
 *
 * Read the MAC address in a board specific way
 *
 */
error_t get_board_mac_addr(unsigned char mac_addr[6])
{
  error_t error = 0;
  alt_u32 signature;

  /* Get the flash sector with the MAC address. */
  error = FindLastFlashSectorOffset(&last_flash_sector_offset);
  if (!error)
    last_flash_sector = CFI_FLASH_BASE + last_flash_sector_offset;
  else
    printf ("Could not locate flash sector with MAC address.\n");

/* This last_flash_sector region of flash is examined to see if 
 * valid network settings are present, indicated by a signature of 0x00005afe at 
 * the first address of the last flash sector.  This hex value is chosen as the 
 * signature since it looks like the english word "SAFE", meaning that it is 
 * safe to use these network address values.  
*/
  ///*
  if (!error)
  {
    signature = IORD_32DIRECT(last_flash_sector, 0);
    if (signature != 0x00005afe)
    {
      error = generate_and_store_mac_addr();
    }
  }
  //*/
//    mac_addr[0] = 0x00;
//    mac_addr[1] = 0x07;
//    mac_addr[2] = 0xed;
//    mac_addr[3] = 0x12;
//    mac_addr[4] = 0x8f;
//    mac_addr[5] = 0xff;
  if (!error)
  {
    mac_addr[0] = IORD_8DIRECT(last_flash_sector, 4);
    mac_addr[1] = IORD_8DIRECT(last_flash_sector, 5);
    mac_addr[2] = IORD_8DIRECT(last_flash_sector, 6);
    mac_addr[3] = IORD_8DIRECT(last_flash_sector, 7);
    mac_addr[4] = IORD_8DIRECT(last_flash_sector, 8);
    mac_addr[5] = IORD_8DIRECT(last_flash_sector, 9);
    
    printf("Your Ethernet MAC address is %02x:%02x:%02x:%02x:%02x:%02x\n", 
            mac_addr[0],
            mac_addr[1],
            mac_addr[2],
            mac_addr[3],
            mac_addr[4],
            mac_addr[5]);

  }

  return error;
}
Esempio n. 12
0
/******************************************************************
*  Function: MemTestDevice
*
*  Purpose: Tests that every bit in the memory device within the 
*           specified address range can store both a '1' and a '0'.
*
******************************************************************/
static int MemTestDevice(unsigned int memory_base, unsigned int nBytes)
{
  unsigned int offset;
  unsigned int pattern;
  unsigned int antipattern;
  unsigned int ret_code = 0x0;

  /* Fill memory with a known pattern. */
  for (pattern = 1, offset = 0; offset < nBytes; pattern++, offset+=4)
  {
    IOWR_32DIRECT(memory_base, offset, pattern);
  }

  printf(" .");

  /* Check each location and invert it for the second pass. */
  for (pattern = 1, offset = 0; offset < nBytes; pattern++, offset+=4)
  {
    if (IORD_32DIRECT(memory_base, offset) != pattern)
    {
      ret_code = (memory_base + offset);
      break;
    }
    antipattern = ~pattern;
    IOWR_32DIRECT(memory_base, offset, antipattern);
  }

  printf(" .");

  /* Check each location for the inverted pattern and zero it. */
  for (pattern = 1, offset = 0; offset < nBytes; pattern++, offset+=4)
  {
    antipattern = ~pattern;
    if (IORD_32DIRECT(memory_base, offset) != antipattern)
    {
      ret_code = (memory_base + offset);
      break;
    }
    IOWR_32DIRECT(memory_base, offset, 0x0);
  }
  return ret_code;
}
Esempio n. 13
0
static void interruptServiceRoutine()
{
	int readdata;
	int update_gfstart = 0;

	// Reset SOFISTS and EOFISTS
	readdata = IORD_32DIRECT(REGFILE_FINAL_0_BASE, GINT);
	SET_BIT(readdata, 1);
	SET_BIT(readdata, 3);
	IOWR_32DIRECT(REGFILE_FINAL_0_BASE, GINT, readdata);

	// Set SHHT and Grab controls
	readdata = IORD_32DIRECT(REGFILE_FINAL_0_BASE, GCTRL);
	if (CHECK_BIT(readdata, 5))
	{
		CLEAR_BIT(readdata, 5);
		update_gfstart = 1;
	}
	else
	{
		SET_BIT(readdata, 5);
	}

	// Set the SHHT
	SET_BIT(readdata, 0);
	// Write the control register
	IOWR_32DIRECT(REGFILE_FINAL_0_BASE, GCTRL, readdata);

	// Update GFSTART to new line location
	readdata = IORD_32DIRECT(REGFILE_FINAL_0_BASE, GFSTART);

	if (update_gfstart == 1)
	{
		readdata += GFSTART_increment - 1;
	}
	else
	{
		readdata += 1;
	}
	IOWR_32DIRECT(REGFILE_FINAL_0_BASE, GFSTART, readdata);
}
Esempio n. 14
0
/*
 * Get system console GUI soft button state from debug memory
 */
void debug_get_buttons(int offset, int num_buttons, int *buttons)
{
    int i;
    int val;
    unsigned int base_address = IO_IN_BUTTONS_BASE + offset;
    *buttons = 0;
    for (i=0;i<num_buttons;i++) {
        val = IORD_32DIRECT(base_address,i*4);
        *buttons = *buttons | ((val != 0) << i);
        IOWR_32DIRECT(base_address, i*4, 0);    //reset button value
    }
}
Esempio n. 15
0
short readSliders(int channel){
	short adcValues = IORD_32DIRECT(ADC, 0);
	short firstChannel = (adcValues & 0x00FF);
	short secondChannel = (adcValues &0x00FF00) >> 8;
	short error = 0;
	if( channel == 1 ){
		return (firstChannel/25)*10;
	} else if( channel == 2 ) {
		return (secondChannel/25)*10;
	}
	return error;
}
Esempio n. 16
0
File: Main.c Progetto: IceyP/DECA
void HandleClassSpecificControlRequests(volatile __CONTROL_REQUEST_STATUS *PCtrlReqStatus,
										volatile unsigned int base, char stage)
{
    if(PCtrlReqStatus->PUsbCtrlReq->bmRequestType.RequestType == 0x01)
    {
        //if Class specific request is there
    
        //printf("Class Req\n");
        if(     (PCtrlReqStatus->PUsbCtrlReq->bRequest == 0xFE)                &&
            (PCtrlReqStatus->PUsbCtrlReq->bmRequestType.Direction == 1)    &&
            (PCtrlReqStatus->PUsbCtrlReq->bmRequestType.RequestType == 1)  &&
            (PCtrlReqStatus->PUsbCtrlReq->wIndex.Value == 0)               &&
            (PCtrlReqStatus->PUsbCtrlReq->wValue.Value == 0)               &&
            (PCtrlReqStatus->PUsbCtrlReq->wLength == 1)         )
        {
            //printf("GetMaxLUN\n");
            PCtrlReqStatus->sizeOfDataStageData = 1;
            PCtrlReqStatus->PDataStageData = &DataToBeSent;
        }
        else if(    (PCtrlReqStatus->PUsbCtrlReq->bRequest == 0xFF)                   &&
                    (PCtrlReqStatus->PUsbCtrlReq->bmRequestType.Direction == 0)       &&
                    (PCtrlReqStatus->PUsbCtrlReq->bmRequestType.RequestType == 1)     &&
                    (PCtrlReqStatus->PUsbCtrlReq->wIndex.Value == 0)                  &&
                    (PCtrlReqStatus->PUsbCtrlReq->wValue.Value == 0)                  &&
                    (PCtrlReqStatus->PUsbCtrlReq->wLength == 0))
        {
            int csr = IORD_32DIRECT(base, 0x50);
            IOWR_32DIRECT(base, 0x50, csr | 0x00800000);
			csr = IORD_32DIRECT(base, 0x60);
            IOWR_32DIRECT(base, 0x60, csr | 0x00800000);
        }
        else
        {
//            printf("Bad control request\n");
            int csr = IORD_32DIRECT(base, 0x40);
            IOWR_32DIRECT(base, 0x40, csr | 0x00800000);
        }
    }
}
Esempio n. 17
0
void shuffle_with_accelerator(volatile long* array, int size)
{
    // Set Start address and array size
    IOWR_32DIRECT(ACCELERATOR_0_BASE, 0x0, (long ) array);
    IOWR_32DIRECT(ACCELERATOR_0_BASE, 0x4, ARRAY_SIZE);

    // Start
    IOWR_32DIRECT(ACCELERATOR_0_BASE, 0x8, 1);

    // Wait for Done
    while (IORD_32DIRECT(ACCELERATOR_0_BASE, 0xC) != 1) {
        alt_putstr("Waiting for accelerator\n");
    }

}
Esempio n. 18
0
void draw(int x1, int y1, int x2, int y2, int colour) {
	IOWR_32DIRECT(drawer_base, 0, x1);
	// Set x1
	IOWR_32DIRECT(drawer_base, 4, y1);
	// Set y1
	IOWR_32DIRECT(drawer_base, 8, x2);
	// Set x2
	IOWR_32DIRECT(drawer_base, 12, y2);
	// Set y2
	IOWR_32DIRECT(drawer_base, 16, colour);
	// Set colour
	IOWR_32DIRECT(drawer_base, 20, 1);
	// Start drawing
	while (IORD_32DIRECT(drawer_base,20) == 0)
		; // wait until done
}
Esempio n. 19
0
/*
* get_board_mac_addr
*
* Read the MAC address in a board specific way
*
*/
error_t get_board_mac_addr(unsigned char mac_addr[6])
{
    error_t error = 0;
    alt_u32 signature;
#if 0
    /* Get the flash sector with the MAC address. */
    error = FindLastFlashSectorOffset(&last_flash_sector_offset);
    if (!error)
        last_flash_sector = EXT_FLASH_BASE + last_flash_sector_offset;

    /* This last_flash_sector region of flash is examined to see if 
     * valid network settings are present, indicated by a signature of 0x00005afe at 
     * the first address of the last flash sector.  This hex value is chosen as the 
     * signature since it looks like the english word "SAFE", meaning that it is 
     * safe to use these network address values.  
    */
    if (!error)
    {
        signature = IORD_32DIRECT(last_flash_sector, 0);
        if (signature != 0x00005afe)
        {
          error = generate_and_store_mac_addr();
        }
    }
#endif  
    if (!error)
    {
  	/* Hard code MAC address here $$ */
    mac_addr[0] = 0x00;
    mac_addr[1] = 0x15;
    mac_addr[2] = 0x17;
    mac_addr[3] = 0x26;
    mac_addr[4] = 0x63;
    mac_addr[5] = 0xf9;
    
        printf("Your Ethernet MAC address is %02x:%02x:%02x:%02x:%02x:%02x\n", 
            mac_addr[0],
            mac_addr[1],
            mac_addr[2],
            mac_addr[3],
            mac_addr[4],
            mac_addr[5]);
    
    }
    
    return error;
}
Esempio n. 20
0
int main(int i, char ** pp, char ** ppp)
{
	  int REG_ADDR;
	  volatile int readData;

	  // Read address 0
	  REG_ADDR = 0;
	  int counter = 0;
	  while (1)
	  {
	  readData = IORD_32DIRECT(REG_0_BASE, REG_ADDR);
	  IOWR_32DIRECT(REG_0_BASE, REG_ADDR + 8, counter + readData);
	  counter++;
	  }

	  return 0;
}
//------------------------------------------------------------------------------
UINT32 openmac_timerGetTimeValue(UINT timer_p)
{
    UINT offset;

    switch (timer_p)
    {
        case HWTIMER_SYNC:
            offset = OPENMAC_TIMER_OFFSET_TIME_VAL;
            break;

        case HWTIMER_EXT_SYNC:
        default:
            return 0;
    }

    return IORD_32DIRECT(OPENMAC_TIMER_BASE, offset);
}
Esempio n. 22
0
/*
* get_board_mac_addr
*
* Read the MAC address in a board specific way
*
*/
error_t get_board_mac_addr(unsigned char mac_addr[6])
{
  error_t error = 0;

  alt_u32 signature;
  alt_u32 mac_addr_ptr = EXT_FLASH_BASE + ETHERNET_OPTION_BITS;
  
/* This last_flash_sector region of flash is examined to see if 
 * valid network settings are present, indicated by a signature of 0x00005afe at 
 * the first address of the last flash sector.  This hex value is chosen as the 
 * signature since it looks like the english word "SAFE", meaning that it is 
 * safe to use these network address values.  
*/

  /* Get the flash sector with the MAC address. */
  signature = IORD_32DIRECT(mac_addr_ptr, 0);
    
  if (signature != 0x00005afe)
  {
    error = generate_and_store_mac_addr();
  }
  
  if (!error)
  {
    mac_addr[0] = IORD_8DIRECT(mac_addr_ptr, 4);
    mac_addr[1] = IORD_8DIRECT(mac_addr_ptr, 5);
    mac_addr[2] = IORD_8DIRECT(mac_addr_ptr, 6);
    mac_addr[3] = IORD_8DIRECT(mac_addr_ptr, 7);
    mac_addr[4] = IORD_8DIRECT(mac_addr_ptr, 8);
    mac_addr[5] = IORD_8DIRECT(mac_addr_ptr, 9);
    
    printf("Your Ethernet MAC address is %02x:%02x:%02x:%02x:%02x:%02x\n", 
            mac_addr[0],
            mac_addr[1],
            mac_addr[2],
            mac_addr[3],
            mac_addr[4],
            mac_addr[5]);

  }

  return error;
}
Esempio n. 23
0
/******************************************************************
*  Function: MemTestDataBus
*
*  Purpose: Tests that the data bus is connected with no 
*           stuck-at's, shorts, or open circuits.
*
******************************************************************/
static int MemTestDataBus(unsigned int address)
{
  unsigned int pattern;
  unsigned int ret_code = 0x0;

  /* Perform a walking 1's test at the given address. */
  for (pattern = 1; pattern != 0; pattern <<= 1)
  {
    /* Write the test pattern. */
    IOWR_32DIRECT(address, 0, pattern);

    /* Read it back (immediately is okay for this test). */
    if (IORD_32DIRECT(address, 0) != pattern)
    {
      ret_code = pattern;
      break;
    }
  }
  return ret_code;
}
Esempio n. 24
0
/******************************************************************
*  Function: FlashCheckIfBlockErased
*
*  Purpose: Checks the specified flash block to see if it is 
*           completely erased (all 0xFFFFFFFF).
*
******************************************************************/
static int FlashCheckIfBlockErased(void* base, int block, flash_region* regions)
{
  int i;
  int ret_code = 0x0;
 
  /* Check for blocks that are all 0xFFFFFFFF */
  for(i = 0; i < regions->block_size; i += 4)
  {
    if(IORD_32DIRECT((int)base + (regions->offset), (block * regions->block_size) + i) != 0xFFFFFFFF)
      break;
  }
 
  /* Block is erased if we indexed through all block locations */
  if(i == regions->block_size)
    ret_code = 1;
  else
    ret_code = 0;
 
  return ret_code;
}
Esempio n. 25
0
static void demo_mandelbrot(void)
{
	static const float args[][6] = {
		{-2.4f, -1.2f, 1.28f, 0.64f, 0.0f, 0.0f},
		{-0.843333f, -0.111628f, 0.042667f, 0.021333f, 0.0f, 0.0f},
		{-0.775333f, -0.111628f, 0.0042667f, 0.0021333f, 0.0f, 0.0f},
	};

	lcd_write(0x50, 0);
	lcd_write(0x51, LCD_WIDTH-1);
	lcd_write(0x52, 0);
	lcd_write(0x53, LCD_HEIGHT-1);
	lcd_write(0x03, 0x1028);

	int i = 0;
	do
	{
		lcd_write(0x21, 0);
		lcd_write(0x20, 0);
		lcd_write_address(0x22);

		alt_u32 *params = (alt_u32*)args[i];
		IOWR_32DIRECT(MB_FLOAT_BASE, 0*4, params[0]);
		IOWR_32DIRECT(MB_FLOAT_BASE, 1*4, params[1]);
		IOWR_32DIRECT(MB_FLOAT_BASE, 2*4, params[2]);
		IOWR_32DIRECT(MB_FLOAT_BASE, 3*4, params[3]);
		IOWR_32DIRECT(MB_FLOAT_BASE, 4*4, params[4]);
		IOWR_32DIRECT(MB_FLOAT_BASE, 5*4, params[5]);

		IOWR_32DIRECT(MB_FLOAT_BASE, 7*4, 0x0);
		while(IORD_32DIRECT(MB_FLOAT_BASE, 7*4) & 1);

		mdelay(2000);
		if(++i >= (sizeof(args) / sizeof(*args))) i = 0;
	}
	while(DEMO_MODE() == DEMO_MANDELBROT);

	lcd_write(0x03, LCD_ENTRYMODE);
}
Esempio n. 26
0
/**
 * alt_adc_word_read
 *
 * Reading from sample store core (RAM) in word addressing
 *
 *slot |  address_ofset    |  ADC1 sample data   |   ADC0 sample data
 *     | (word addressing) |  MS2B(31-16)        |   LS2B(15-0 bits)
 *--------------------------------------------------------------------
 * 0   |     0             |   xxxx xxxx xxxx    |   xxxx xxxx xxxx    
 * 1   |     4             |   xxxx xxxx xxxx    |   xxxx xxxx xxxx 
 * Arguments:
 * - sample_store_base: Base address of sample store core
 * - *dest_ptr: destination buffer  
 * - len: size of reading in 32 bits.
 *
 * Returns:
 * 0 -> success
 * -EINVAL -> Invalid arguments
**/
int alt_adc_word_read (alt_u32 sample_store_base, alt_u32* dest_ptr, alt_u32 len)
{
    alt_u32 word = 0;
    alt_u32 word_length = len;
    alt_u32* dest_buf = dest_ptr;
    alt_u32 base = sample_store_base;
     
    /* return -EINVAL if invalid arguments passed into function */
    if(NULL == dest_buf)
    {
    	return -EINVAL;
    }

    for(word = 0; word < word_length; word++)
    {
       *dest_buf = IORD_32DIRECT((base + (word * 4)),0);

       dest_buf++;
    }

    return 0;

}
Esempio n. 27
0
int main()
{
	unsigned int row, col;
	unsigned int i = 0;
	unsigned int j = 0;
	pixbuf_t *pixbuf;

	graphics_init();
	pixbuf = graphics_get_final_buffer();

	alt_putstr("Restoring default palette\n");
	switch_palette(&palette_332);

	graphics_clear_screen();

	// Draw to edges of screen
	graphics_draw_rectangle(pixbuf, 0, 0, 640-1, 480-1, 0xE0);
	graphics_draw_rectangle(pixbuf, 1, 1, 640-2, 480-2, 0xFF);
	ALT_CI_CI_FRAME_DONE_0;

	// Draw the colors at the top of the screen
	for (i = 0; i < sizeof(color_array); i++)
	{
		graphics_draw_rectangle(pixbuf, i, 0, i, 0, color_array[i]);
	}

	// Cycle through a pattern
	for (i = 0; i < 256; i++)
	{
		graphics_draw_rectangle(pixbuf, 300, 50, 301, 127, color_array[i % sizeof(color_array)]);
		graphics_draw_rectangle(pixbuf, 201, 111, 400, 230, color_array[(i+4) % sizeof(color_array)]);
		graphics_draw_rectangle(pixbuf, 100, 200, 500, 430, color_array[(i+8) % sizeof(color_array)]);
		ALT_CI_CI_FRAME_DONE_0;
		for (j = 0; j < 10000; j++)
		{
			// Do nothing
		}
	}

	graphics_clear_screen();

	// Draw a geometric pattern in the most inefficient way possible...
	for (row = 0; row < 480; row++)
	{
		for (col = 0; col < 640; col++)
		{
			if (row == col) {
				graphics_draw_rectangle(pixbuf, col, row, col, row, 0xFF);
			}
			if (row == col - 160) {
				graphics_draw_rectangle(pixbuf, col, row, col, row, 0xFF);
			}
			if (480 - row - 1 == col) {
				graphics_draw_rectangle(pixbuf, col, row, col, row, 0xFF);
			}
			if (480 - row - 1 == col - 160) {
				graphics_draw_rectangle(pixbuf, col, row, col, row, 0xFF);
			}
		}
	}
	ALT_CI_CI_FRAME_DONE_0;
	for ( i = 0; i < 100000; i++)
	{
		//wait for a while
	}
	graphics_clear_screen();
	int genesis_value;
	while(1)
	{
		genesis_value = IORD_32DIRECT(GENESIS_0_BASE, 0);
		if ((genesis_value)& (1 << 4)){
			graphics_draw_rectangle(pixbuf, 100, 100, 150, 150, 0x1A);
			  }
		else
			graphics_draw_rectangle(pixbuf, 100, 100, 150, 150, 0x0);
			  if ((genesis_value)& (1 << 5)){
				  graphics_draw_rectangle(pixbuf, 200, 200, 250, 250, 0xE0);
			  }
			  else
				  graphics_draw_rectangle(pixbuf, 200, 200, 250, 250, 0x0);
			  if ((genesis_value)& (1 << 6)){
				  graphics_draw_rectangle(pixbuf, 300, 300, 350, 350, 0x03);
			  }
			  else
				  graphics_draw_rectangle(pixbuf, 300, 300, 350, 350, 0x0);

			  ALT_CI_CI_FRAME_DONE_0;
		// Do nothing
	}

	return 0;
}
Esempio n. 28
0
//
// Low level read fiunction for Biss interface
//
unsigned int Biss_Read(unsigned int base_addr, unsigned int reg) {
	return IORD_32DIRECT(base_addr, reg);
}
Esempio n. 29
0
/******************************************************************
*  Function: MemTest8_16BitAccess
*
*  Purpose: Tests that the memory at the specified base address
*           can be read and written in both byte and half-word 
*           modes.
*
******************************************************************/
static int MemTest8_16BitAccess(unsigned int memory_base)
{
  int ret_code = 0x0;

  /* Write 4 bytes */
  IOWR_8DIRECT(memory_base, 0, 0x0A);
  IOWR_8DIRECT(memory_base, 1, 0x05);
  IOWR_8DIRECT(memory_base, 2, 0xA0);
  IOWR_8DIRECT(memory_base, 3, 0x50);

  /* Read it back as one word */
  if(IORD_32DIRECT(memory_base, 0) != 0x50A0050A)
  {
    ret_code = memory_base;
  }

  /* Read it back as two half-words */
  if (!ret_code)
  {
    if ((IORD_16DIRECT(memory_base, 2) != 0x50A0) ||
        (IORD_16DIRECT(memory_base, 0) != 0x050A))
    {
      ret_code = memory_base;
    }
  }

  /* Read it back as 4 bytes */
  if (!ret_code)
  {
    if ((IORD_8DIRECT(memory_base, 3) != 0x50) ||
        (IORD_8DIRECT(memory_base, 2) != 0xA0) ||
        (IORD_8DIRECT(memory_base, 1) != 0x05) ||
        (IORD_8DIRECT(memory_base, 0) != 0x0A))
    {
    ret_code = memory_base;
    }
  }

  /* Write 2 half-words */
  if (!ret_code)
  {
    IOWR_16DIRECT(memory_base, 0, 0x50A0);
    IOWR_16DIRECT(memory_base, 2, 0x050A);

    /* Read it back as one word */
    if(IORD_32DIRECT(memory_base, 0) != 0x050A50A0)
    {
      ret_code = memory_base;
    }
  }

  /* Read it back as two half-words */
  if (!ret_code)
  {
    if ((IORD_16DIRECT(memory_base, 2) != 0x050A) ||
        (IORD_16DIRECT(memory_base, 0) != 0x50A0))
    {
      ret_code = memory_base;
    }
  }

  /* Read it back as 4 bytes */
  if (!ret_code)
  {
    if ((IORD_8DIRECT(memory_base, 3) != 0x05) ||
        (IORD_8DIRECT(memory_base, 2) != 0x0A) ||
        (IORD_8DIRECT(memory_base, 1) != 0x50) ||
        (IORD_8DIRECT(memory_base, 0) != 0xA0))
    {
      ret_code = memory_base;
    }
  }

  return(ret_code);
}
Esempio n. 30
0
int main()
{

	IOWR_RAM_DATA(NIOSINTERFACE_1_0_BASE, 0, 0);
	int dir = 0;
	int posX = doubleToInt(21.5), posY = doubleToInt(11.5);  //x and y start position
 // int posX = 22, posY = 11;  //x and y start position
  int x =0;

  int p, q;


  IOSKYWR_RAM_DATA(SKYGEN_0_BASE, 262143, 0x0000);

  for(p = 0; p < 480; p++){
	  for(q = 0; q < 512; q++)
	  {

		  IOSKYWR_RAM_DATA(SKYGEN_0_BASE, p*512+q, (sky[p*1024+q*2+1]<<8) + (sky[p*1024+q*2]));

	  }
  }

  IOSKYWR_RAM_DATA(SKYGEN_0_BASE, 262143, 0x000F);
  double sine_temp;
  double cosine_temp;

	for(x = 0; x < lookupLength ; x++)
	{
			//calculate ray position and direction

		sine_temp = sin(x*RAD + HALF_RAD);
		cosine_temp = cos(x*RAD + HALF_RAD);

		dirsine[x] = doubleToInt(sin(x*RAD));
		dircosine[x] = doubleToInt(cos(x*RAD));
		sine[x] = doubleToInt(sine_temp);
		cosine[x] = doubleToInt(cosine_temp);
	}


  int angle;
  int fish_angle;
  int move;

  int rayDirX;
  int rayDirY;
  int count_step;

  int k;
  int k2;
  int forward = 0;
  int backward = 0;
  int left = 0;
  int right = 0;
  //char key[] = { 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d',
//		  'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d', 'd','d','d','d','d','d','d','d','d','d','d','d','d','d','d','d'};

  unsigned char code = 0;
  //char key[] = {'d'};
  k2 = 0;
  //start the main loop
  //for (k2 = 0; k2 < sizeof(key); k2++)

  int hardwareData = 0;

  while(1)
  {

	  code = 0;

		//while (!IORD_8DIRECT(DE2_PS2_0_BASE, 0)) ; /* Poll the status */

//		code = IORD_8DIRECT(DE2_PS2_0_BASE, 0);

//		if (code)


	//printf("%c, %x, %d\n", code, code, code);

		/* Get received byte */

	  //code = 'k';

	  //hardwareData = IORD_RAM_DATA(NIOSINTERFACE_1_0_BASE, 1);
	  //printf("%d\n", hardwareData >> 4);

	  code = IORD_8DIRECT(DE2_PS2_1_BASE, 1);

	  switch(code)
	  {
	  	  case 'u':
	  		  forward = 1;
	  		  backward = 0;
	  		  break;
	  	  case 'r':
	  		  forward = 0;
	  		  backward = 1;
	  		  break;
	  	  case 't':
	  		  right = 1;
	  		  left = 0;
	  		  break;
	  	  case 'k':
	  		  left = 1;
	  		  right = 0;
	  		  break;
	  	  case 'U':
	  		  forward = 0;
	  		  break;
	  	  case 'R':
	  		  backward = 0;
	  		  break;
	  	  case 'T':
	  		  right = 0;
	  		  break;
	  	  case 'K':
	  		  left = 0;
	  		  break;

	  	  case ')':
	  		forward = 0;
	  		backward = 0;
	  		right = 0;
	  		left = 0;
	  		break;

	  }

     x = 0;
    for(k = -halfScreenWidth; k < halfScreenWidth; k++)
    {
        angle = dir + k;

        if ( angle < 0)
                angle += lookupLength;

        if (angle >= lookupLength)
                angle -= lookupLength;

        fish_angle = k;

        if ( fish_angle < 0)
            fish_angle += lookupLength;

        if (fish_angle >= lookupLength)
             fish_angle -= lookupLength;


      //calculate ray position and direction
      //double cameraX = 2*x/double(w)-1; //x-coordinate in camera space
      rayDirX = cosine[angle]>>extensionFactor;
      rayDirY = sine[angle]>>extensionFactor;
      count_step = cosine[fish_angle]>>extensionFactor;

      //using a happy medium between 1/32 and 1/64 ray extension increment
//      rayDirX = (cosine[angle]>>6)+(cosine[angle]>>7);
//      rayDirY = (sine[angle]>>6) +(sine[angle]>>7);
//      count_step = (cosine[fish_angle]>>6) +(cosine[fish_angle]>>7);


 //     hardwareData = IORD_32DIRECT(NIOSINTERFACE_1_0_BASE, 1);
    //  printf("%d\n", hardwareData);
     DrawAccelerate(angle, posX, posY, count_step, rayDirX, rayDirY, x);
     IOWR_RAM_DATA(NIOSINTERFACE_1_0_BASE, 0, 0);

     hardwareData = IORD_32DIRECT(NIOSINTERFACE_1_0_BASE, 1);

	 while (!(hardwareData & 1)){
		 hardwareData = IORD_32DIRECT(NIOSINTERFACE_1_0_BASE, 1);
	  }


      //IOWR_RAM_DATA(NIOSINTERFACE_1_0_BASE, 0, 0);

      IOWR_RAM_DATA(NIOSINTERFACE_1_0_BASE, 0, 0xFFFFFFFF);



//	  printf("out of loop\n");
	  //IOWR_RAM_DATA(NIOSINTERFACE_0_BASE, 0, 0);

//	  int rayPosX = posX;
//	  int rayPosY = posY;
//	  int count = 0;
//      int mapX;
//      int mapY;
//
//      //what direction to step in x or y-direction (either +1 or -1)
//      int stepX;
//      int stepY;
//
//      int hit = 0; //was there a wall hit?
//      unsigned int side = 0; //was a NS or a EW wall hit?
//
//      //calculate step and initial sideDist
//      if (rayDirX < 0)
//         stepX = -1;
//      else
//         stepX = 1;
//
//      if (rayDirY < 0)
//         stepY = -1;
//      else
//         stepY = 1;
//
//
//      while ( worldMap[rayPosX>>posShift][rayPosY>>posShift] == 0)
//      {
//        count += count_step;
//
//        //jump to next map square, OR in x-direction, OR in y-direction
//        rayPosX += rayDirX;
//        rayPosY += rayDirY;
//
//        //Check if ray has hit a wall
//      }
//
//      hit = 1;
//      ////////////////////////////////////////////////////////////////////////
//      /////LOOOP BACK CODE FOR SMOOTHER EDGES AND FASTER SPEEDS///////////////
//
//      count_step = count_step>>4;
//      rayDirX = rayDirX>>4;
//      rayDirY = rayDirY>>4;
//
//      while(hit == 1)
//      {
//
//        count -= count_step;
//
//        //jump to next map square, OR in x-direction, OR in y-direction
//        rayPosX -= rayDirX;
//        rayPosY -= rayDirY;
//
//        //Check if ray has hit a wall
//        if (worldMap[rayPosX>>posShift][rayPosY>>posShift] == 0) hit = 0;
//
//      }
//
//      count += count_step;
//      rayPosX += rayDirX;
//      rayPosY += rayDirY;
//
//      ////////////////////////////////////////////////////////////////////////
//      ////////////////////////////////////////////////////////////////////////
//
//      mapX = ((rayPosX>>posShift)  + ((1 - stepX)>>1))<<posShift;
//      mapY = ((rayPosY>>posShift)  + ((1 - stepY)>>1))<<posShift;
//
//      //Calculate distance of perpendicular ray (oblique distance will give fisheye effect!)
//      if ( absVal(mapX - rayPosX) <  absVal(mapY - rayPosY) )
//          side  = 1;
//
//
//      //Calculate height of line to draw on screen
//      //int lineHeight = abs( (screenHeight<<posShift) /count);
//      int lineHeight = (screenHeight<<posShift) /count;
//      //printf("lineHeight= %d", lineHeight);
////      if (lineHeight >= screenHeight){
////    	  lineHeight = 0x1FF;
////    	  //printf(" lineHeight= %d", lineHeight);
////      }
//      //printf("\n");
//
//      //calculate lowest and highest pixel to fill in current stripe
//      int drawStart = (-lineHeight >> 1) + (screenHeight >> 1);
//      if(drawStart < 0) drawStart = 0;
//      int drawEnd = (lineHeight >> 1) + (screenHeight >> 1);
//      if(drawEnd >= screenHeight) drawEnd = screenHeight - 1;
//
//      /////////////////////////////////////////////////
//      ////texturing calculations
//      /////////////////////////////////////////////////
//	   unsigned int texNum = worldMap[rayPosX>>posShift][rayPosY>>posShift] - 1; //1 subtracted from it so that texture 0 can      be used!
//
//	   //calculate value of wallX
//	   int wallX; //where exactly the wall was hit
//
//	   if (side == 0) wallX = rayPosX;
//	   else           wallX = rayPosY;
//
//
//	   wallX -= (wallX>>posShift)<<posShift;
//
//	   //x coordinate on the texture
//	   unsigned int texX = (wallX * texWidth)>>posShift;
//	   if(side == 1 && rayDirX > 0) texX = texWidth - texX - 1;
//	   if(side == 0 && rayDirY < 0) texX = texWidth - texX - 1;
//
//	   unsigned int invLineHeight = (texHeight << 16)/lineHeight;
//	   int line_minus_h = lineHeight - screenHeight;
//
//
//
//	   DrawTexture(x, texX, drawStart, drawEnd, side, texNum, invLineHeight , line_minus_h);

//       unsigned int color;
//      switch(worldMap[rayPosX>>posShift][rayPosY>>posShift])
//      {
//        case 1:  color = RED_8BIT;  break; //red
//        case 2:  color = GREEN_8BIT;  break; //green
//        case 3:  color = BLUE_8BIT;   break; //blue
//        case 4:  color = WHITE_8BIT;  break; //white
//        default: color = YELLOW_8BIT; break; //yellow
//      }

      //draw the pixels of the stripe as a vertical line
      //DrawColumn(x, color, drawStart, drawEnd, side);
      //DrawColumn(x, color, lineHeight, side);
      //verLine(x, drawStart, drawEnd, color);

      x++;
    }



    //move forward if no wall in front of you
    if (forward == 1)
    {
        move = dircosine[dir]>>4;
        if(worldMap[(posX + move)>>posShift][posY>>posShift] == 0)
                posX += move;

        move = dirsine[dir]>>4;
        if(worldMap[posX>>posShift][(posY+move)>>posShift] == 0)
                posY += move;
    }
    //move backwards if no wall behind you
    if (backward == 1)
    {
        move = dircosine[dir]>>4;
        if(worldMap[(posX - move)>>posShift][posY>>posShift] == 0)
                posX -= move;

        move = dirsine[dir]>>4;
        if(worldMap[posX>>posShift][(posY - move)>>posShift] == 0)
                posY -= move;
    }