コード例 #1
0
ファイル: GHCreateEffects.c プロジェクト: blue-brick/dgn-1
//Tremolo(panner) effect has its parameters precalculated here in software.
//The user only takes care of choosing the depth and rate of the trembling,
//whereas the hardware receives calculated slope parameters.
static void tremoloSendParams() {
	float slope, diff, best_diff;
	float actualRate;
	unsigned int a, b, j, k, depth;
	if (_tremoloDepth < 0 || _tremoloRate < 0) return;

	//The actual, ideal slope
	slope = 2 * _tremoloDepth*((1<<16)-1)*_tremoloRate / 48000;

	best_diff = infinityf();

	//The hardware receives the slope of the trembling in the form of a
	//rational number a/b.

	//We find the closest approximation of the actual slope.
	for (k = 1; k<16; k++) {
		j = (int)roundf(slope*k);
		if (j < 1) j = 1;
		if (j > 15) j = 15;
		diff = fabsf( ((float)a/b) - slope);
		if (diff < best_diff) {
			a = j;
			b = k;
			best_diff = diff;
		}
	}

	depth = (int)floorf(_tremoloDepth * ((1<<16)-1));

	IOWR_16DIRECT(PIO_TREMOLO_STEREO_DEPTH_BASE, 0, depth);
	IOWR_16DIRECT(PIO_TREMOLO_STEREO_SWEEP_A_BASE, 0, a);
	IOWR_16DIRECT(PIO_TREMOLO_STEREO_SWEEP_B_BASE, 0, b);
}
コード例 #2
0
ファイル: object_spawner.c プロジェクト: karfair/doge
void game_start(master* m, bmp* bg, char* level_to_read, char* bg_music) {
	p_shift = 0;
	first_platform = true;
	inc = 0;
	//background drawing
	clear_loc(pixel_buffer,0,0,319,239,bg);
	alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer);
	while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer));
	clear_loc(pixel_buffer,0,0,319,239,bg);
	alt_up_pixel_buffer_dma_swap_buffers(pixel_buffer);
	while (alt_up_pixel_buffer_dma_check_swap_buffers_status(pixel_buffer));



	m->ab->wav = init_read_wav(bg_music); //reads wav file into buffer
	fill_buffer(m->ab);

	sd_read_level(level_to_read, m->l);
	object_spawn_init(m);
	init_char_update(m);

	//start timer
	IOWR_16DIRECT(TIMER_0_BASE, 4, 0x5); //start timer

	//enable audio interrupt
	alt_up_audio_enable_write_interrupt(m->ab->audio_dev);

	//enable character interrupt
	IOWR_16DIRECT(TIMER_2_BASE, 4, 0x5);

	//enable object spawning interrupt
	IOWR_16DIRECT(TIMER_1_BASE, 4, 0x5);
}
コード例 #3
0
void initAnimate(struct Cursor* cursor) {
	int timer = 3000000;
	IOWR_16DIRECT(TIMESTAMP_BASE, 8, timer & 0xFFFF);
	IOWR_16DIRECT(TIMESTAMP_BASE, 12, timer >> 16);
	IOWR_16DIRECT(TIMESTAMP_BASE, 4, 0x07);
	alt_irq_register(TIMESTAMP_IRQ, cursor, (void*)animate_ISR);
}
コード例 #4
0
ファイル: audio.c プロジェクト: RedTn/niosmusic
//Stops hardware timer
void stop_timer()
{
	printf("Stopping Timer\n");
	alt_irq_disable(TIMER_0_IRQ);
	IOWR_16DIRECT(TIMER_0_BASE, 4, 11);
	IOWR_16DIRECT(TIMER_0_BASE, 0, 0);
}
コード例 #5
0
ファイル: program.c プロジェクト: kkumt93/DE1_SoC_Project
int main()
{ 
  printf("Hello from Nios II!\n");
  IOWR_16DIRECT(0x4003020,0,0x1);
  unsigned int i;
  unsigned int data[640];
  /* Event loop never exits. */
  for(i=0;i<640;i++){
	  IOWR_16DIRECT(SDRAM_BASE,i*2,i);
  }

//  IOWR_16DIRECT(0x4003020,0,0x2);
//  for(i=0;i<640;i++){
//	  printf("%x\n",IORD_16DIRECT(SDRAM_BASE,i*5));
//	  data[i] = IORD_16DIRECT(SDRAM_BASE,i*2);
//  }

//  printf("%x\n",data[500]);


  while (1){
	  IOWR_16DIRECT(0x4003020,0,0x0);
  }

  return 0;
}
コード例 #6
0
void initAudioBuffer() {
	int timer = 3000000;
	IOWR_16DIRECT(AUDIOBUFFERPROCESS_BASE, 8, timer & 0xFFFF);
	IOWR_16DIRECT(AUDIOBUFFERPROCESS_BASE, 12, timer >> 16);
	IOWR_16DIRECT(AUDIOBUFFERPROCESS_BASE, 4, 0x08);
	alt_irq_register(AUDIOBUFFERPROCESS_IRQ, NULL, (void*)mix_ISR);

}
コード例 #7
0
/** Switch the palette loaded in the palette shifter. Takes an int* to the palette
 * definition, and the length of that colour palette. */
void switchPalette(unsigned int* palette, int length){

	int i = 0;
	for (i = 0; i < length; i++){
		IOWR_16DIRECT(COLOUR_PALETTE_SHIFTER_0_BASE, 2*i, 0x0000);
		IOWR_16DIRECT(COLOUR_PALETTE_SHIFTER_0_BASE, 2*i, palette[i]);
	}


}
コード例 #8
0
ファイル: object_spawner.c プロジェクト: karfair/doge
void game_reset(master* m) {
	alt_up_audio_disable_write_interrupt(m->ab->audio_dev);
	IOWR_16DIRECT(TIMER_0_BASE, 4, 1 << 3);
	IOWR_16DIRECT(TIMER_1_BASE, 4, 1 << 3);
	IOWR_16DIRECT(TIMER_2_BASE, 4, 1 << 3);


	sd_fclose(m->ab->wav);
	reset_audio_buffer(m->ab);
	alt_up_audio_reset_audio_core(m->ab->audio_dev);
}
コード例 #9
0
ファイル: hello.c プロジェクト: gb88/KNN_Accelerator_Thesis
void recv_short(alt_u16* buffer, alt_u16 len)
{
	alt_u16 i = 0;
	while(IORD_16DIRECT(USBFIFOCTRL_0_BASE,0x0002)& 0x0001);
	IOWR_16DIRECT(USBFIFOCTRL_0_BASE,0x0006,0x0002);
	for (i = 0; i<len;i++)
	{
		IOWR_16DIRECT(USBFIFOCTRL_0_BASE,0x0004,(unsigned int) 0x0002);
		while(IORD_16DIRECT(USBFIFOCTRL_0_BASE,0x0002)& 0x0001);
		buffer[i] = IORD_16DIRECT(USBFIFOCTRL_0_BASE,0x0000);
	}
}
コード例 #10
0
ファイル: main.c プロジェクト: karfair/doge
void handle_timer_interrupts(){ //Interrupt for when hardware timer counts to zero
	int i; for( i = 0 ;  i < OBJECT_SIZE ;i++ ) {
		update_object(&co,i);
		update_object(&box,i);
		update_object(&spikes, i);
		update_object(&box_3 , i);
		update_object(&box_1, i );
	}
	update_object(&flag,0);//update winning flag

	IOWR_16DIRECT(TIMER_0_BASE,0,0); //needed to show that interrupt finished executing
	IOWR_16DIRECT(TIMER_0_BASE,4,0x5); //restarts the hardware timer before exiting the isr
	return;
}
コード例 #11
0
ファイル: checkpoint.c プロジェクト: maximegregoire/vlsi
int main()
{
	int readdata = 0;
	int offset = 0;
	int toggle = 0;

	while (offset < 200)
	{
		IOWR_16DIRECT(NEW_SDRAM_CONTROLLER_0_BASE, offset * LINE_PITCH, toggle);

		readdata = IORD_16DIRECT(NEW_SDRAM_CONTROLLER_0_BASE, offset * LINE_PITCH);

		offset++;

		if (toggle == 0)
		{
			toggle = 1;
		}
		else
		{
			toggle = 0;
		}
	}
	return 0;
}
コード例 #12
0
int alt_up_pixel_buffer_draw(alt_up_pixel_buffer_dev *pixel_buffer, unsigned int color, unsigned int x, unsigned int y)
/* This function draws a pixel to the back buffer.
 */
{
	// boundary check
	if (x >= pixel_buffer->x_resolution || y >= pixel_buffer->y_resolution )
		return -1;

	unsigned int addr = 0;
	/* Check the mode VGA Pixel Buffer is using. */
	if (pixel_buffer->addressing_mode == ALT_UP_PIXEL_BUFFER_XY_ADDRESS_MODE) {
		/* For X-Y addressing mode, the address format is | unused | Y | X |. So shift bits for coordinates X and Y into their respective locations. */
		addr |= ((x & pixel_buffer->x_coord_mask) << pixel_buffer->x_coord_offset);
		addr |= ((y & pixel_buffer->y_coord_mask) << pixel_buffer->y_coord_offset);
	} else {
		/* In a consecutive addressing mode, the pixels are stored in consecutive memory locations. So the address of a pixel at (x,y) can be computed as
		 * (y*x_resolution + x).*/
		addr += ((x & pixel_buffer->x_coord_mask) << pixel_buffer->x_coord_offset);
		addr += (((y & pixel_buffer->y_coord_mask) * pixel_buffer->x_resolution) << pixel_buffer->x_coord_offset);
	}
	/* Now, depending on the color depth, write the pixel color to the specified memory location. */
	if (pixel_buffer->color_mode == ALT_UP_8BIT_COLOR_MODE) {
		IOWR_8DIRECT(pixel_buffer->back_buffer_start_address, addr, color);
	} else if (pixel_buffer->color_mode == ALT_UP_16BIT_COLOR_MODE) {
		IOWR_16DIRECT(pixel_buffer->back_buffer_start_address, addr, color);
	} else {
		IOWR_32DIRECT(pixel_buffer->back_buffer_start_address, addr, color);
	}

	return 0;
}
コード例 #13
0
ファイル: audio.c プロジェクト: RedTn/niosmusic
//Timer interrupt function
void timer_isr(void * context, alt_u32 irq_id)
{
	/*
	unsigned int buffer;

	buffer = (unsigned int)alt_up_rs232_get_used_space_in_read_FIFO;
	while(buffer > 0) {
		alt_up_rs232_read_data(uart, &data, &parity);
		fifo_isr++;

		if (fifo_isr > 128)
					printf("Fifo overflow\n");
		else
			fifo_buffer[fifo_isr] = data;

			buffer--;
	}
	 */
	unsigned int space = (unsigned int)alt_up_rs232_get_used_space_in_read_FIFO;
	if (space > 0)
		rs_flag = true;
	else
		rs_flag = false;

	IOWR_16DIRECT(TIMER_0_BASE, 0, 0);
}
コード例 #14
0
int main()
{

	/* Event loop never exits. */

	int i;

	for(i=0;i<1282;i++){
		IOWR_16DIRECT(AVALON_MM_CAMERA_CONTROLLER_0_BASE,i*2,i);
	}

	IOWR_16DIRECT(AVALON_MM_CAMERA_CONTROLLER_0_BASE,1283*2,0xffff);


	while (1);

	return 0;
}
コード例 #15
0
void sd_card_start_read_sector(int index)
{

	/* Multiply sector offset by sector size to get the address. Sector size is 512. Also,
	 * the SD card reads data in 512 byte chunks, so the address must be a multiple of 512. */
	IOWR_32DIRECT(command_argument_register, 0, (sectors[index] + fat_partition_offset_in_512_byte_sectors)*512);
	IOWR_16DIRECT(command_register, 0, CMD_READ_BLOCK);
	current_sector_index = sectors[index]+fat_partition_offset_in_512_byte_sectors;
}
コード例 #16
0
ファイル: audio.c プロジェクト: RedTn/niosmusic
//Initialize hardware-only timer
void init_timer(double period)
{
	int timer_period,status,control,tp_low,tp_high;
	bool irq,repeat;
	alt_irq_register(TIMER_0_IRQ, NULL, &timer_isr);
	timer_period = period * 50000000;
	IOWR_16DIRECT(TIMER_0_BASE, 8, timer_period & 0xFFFF);
	IOWR_16DIRECT(TIMER_0_BASE, 12, timer_period >> 16);

	tp_low = IORD_16DIRECT(TIMER_0_BASE, 8);
	tp_high = IORD_16DIRECT(TIMER_0_BASE, 12);

	//	printf("Period: %x%x\n", tp_high,tp_low);

	double dec = ((tp_high << 16) + tp_low) / 50000;

	printf("Period (decimal): %lf milliseconds\n", dec);

	//printf("Stopping Timer\n");
	status = IORD_16DIRECT(TIMER_0_BASE, 0);
	//printf("Status: %x\n", status);
	if (status & 0x2) {
		printf("Timer stopped\n");
		IOWR_16DIRECT(TIMER_0_BASE, 4, 1 << 3);
	}
	if (status & 0x1) {
		printf("Reset TO\n");
		IOWR_16DIRECT(TIMER_0_BASE, 0, 0);
	}

	control = IORD_16DIRECT(TIMER_0_BASE, 4);
	//printf("Control: %x\n", control);
	irq = (control & 0x1);
	repeat = (control & 0x2) >> 1;
	if ((!irq) || (!repeat)){
		IOWR_16DIRECT(TIMER_0_BASE, 4, 3);
	}

	control = IORD_16DIRECT(TIMER_0_BASE, 4);
	//printf("New control: %x\n", control);

}
コード例 #17
0
ファイル: main.c プロジェクト: lechienv/ProgSandbot
int main()
{
Clr_BUFFER_FLAG();

 alt_video_display Display;
 TOUCH_HANDLE *pTouch;

 printf("Hi There !\n");

 // Write 0x3C on LED[6:0] through the dedicated custom IP
 IOWR(LED_CTRL_BASE, 0x0, 0x3C);

 // TOUCH INITIALIZATION
 pTouch = Touch_Init(LT24_TOUCH_SPI_BASE,  LT24_TOUCH_PENIRQ_N_BASE, LT24_TOUCH_PENIRQ_N_IRQ);
 if (!pTouch){
	 printf("Failed to init touch\r\n");
 }else{
	 printf("Init touch successfully\r\n");
 }

 // LCD INITIALIZATION
 LCD_Init();

 // Pattern example
 //LCD_Pattern_Horizon();
 // Sleep 3s
 //usleep(3*1000*1000);

 Set_BUFFER_FLAG();

 unsigned int X, Y;
 unsigned int posTamper =0;
 while(1){
	 if(Touch_GetXY(pTouch, &X, &Y)){
		 //printf("X: %d Y: %d\n",X,Y);
		 LCD_WR_DATA(Y);
		 LCD_WR_REG(X);
		 //we can modify the character (the image become progressively red when we touch it), we might do the same for the background
		 IOWR_16DIRECT(PIC_MEM_BASE,posTamper,0xF800);
		 posTamper++;
	 }
 }

 // Painter demo
 /*Clr_BUFFER_FLAG();
 Display.interlace = 0;
 Display.bytes_per_pixel = 2;
 Display.color_depth = 16;
 Display.height = SCREEN_HEIGHT;
 Display.width = SCREEN_WIDTH;
 GUI(&Display, pTouch);*/

 return 0;
}
コード例 #18
0
void helper_plot_pixel(register unsigned int buffer_start, register int line_size, register int x, register int y, register int color, register int mode)
/* This is a helper function that draws a pixel at a given location. Note that no boundary checks are made,
 * so drawing off-screen may cause unpredictable side effects. */
{
	if (mode == 0)
		IOWR_8DIRECT(buffer_start, line_size*y+x, color);
	else if (mode == 1)
		IOWR_16DIRECT(buffer_start, (line_size*y+x) << 1, color);
	else
		IOWR_32DIRECT(buffer_start, (line_size*y+x) << 2, color);
}
コード例 #19
0
ファイル: animations.c プロジェクト: scolin22/fxgame
int draw_pixel_fast(alt_up_pixel_buffer_dma_dev *pixel_buffer,
        unsigned int color, unsigned int x, unsigned int y) {
    unsigned int addr = 0;

    addr |= ((x & pixel_buffer->x_coord_mask) << pixel_buffer->x_coord_offset);
    addr |= ((y & pixel_buffer->y_coord_mask) << pixel_buffer->y_coord_offset);

    IOWR_16DIRECT(pixel_buffer->back_buffer_start_address, addr, color);

    return 0;
}
コード例 #20
0
ファイル: audio.c プロジェクト: RedTn/niosmusic
//Starts hardware timer
void start_timer()
{
	printf("Starting Timer\n");
	alt_irq_enable(TIMER_0_IRQ);
	IOWR_16DIRECT(TIMER_0_BASE, 4, 7);

	/*
	 int control;
	control = IORD_16DIRECT(TIMER_0_BASE, 4);
	printf("New control (2): %x\n", control);
	 */
}
コード例 #21
0
/******************************************************************
*  Function: alt_video_display_register_written_buffer
*
*  Purpose: Registers the buffer pointed to by buffer_being_written
*           as being finished and ready for display.
*
*  Returns: 0 - Everything is groovy.
*           1 - buffer_being_written is now equal to buffer_being_displayed
*                 - It would be a good idea to wait for buffer_being_displayed 
*                   to increment before writing to buffer_being_written.
*
******************************************************************/
int alt_video_display_register_written_buffer( alt_video_display* display )
{
  int ret_code, prev_frame_index;
  alt_sgdma_descriptor *desc_prev_frame_tail;
  alt_sgdma_descriptor *desc_being_registered_head, *desc_being_registered_tail;

  /* 
   * Prepare relevant SGDMA descriptors in the frame being registered:
   *  - Set the new frame's head-descriptor transfer count to 0
   *  - Ensure that the new frame descriptor chain loops (tail points to head)
   *  - Point the previous frame at the new one to "break" its loop
   */
  desc_being_registered_head = 
    display->buffer_ptrs[display->buffer_being_written]->desc_base;
  desc_being_registered_tail = desc_being_registered_head + 
    (display->descriptors_per_frame - 1);
      
  IOWR_16DIRECT(
    (alt_u32)(&desc_being_registered_head->actual_bytes_transferred), 
    0, (alt_u16) 0x0);
  IOWR_32DIRECT((alt_u32)(&desc_being_registered_tail->next), 0, 
    (alt_u32)(desc_being_registered_head)); 
 
  /* Find the tail of the descriptor chain in the last frame registered */
  prev_frame_index = (display->buffer_being_written - 1);

  if(prev_frame_index < 0) {
    prev_frame_index = (display->num_frame_buffers - 1);
  }

  desc_prev_frame_tail = display->buffer_ptrs[prev_frame_index]->desc_base;
  desc_prev_frame_tail += (display->descriptors_per_frame - 1);
       
  IOWR_32DIRECT((alt_u32)(&desc_prev_frame_tail->next), 0, 
    (alt_u32)(desc_being_registered_head));
  
  /* 
   * Update frame_being_written index. Note: The new index may *not* be 
   * safe to write to; alt_video_display_buffer_is_available() must be 
   * called to verify this).
   */
  display->buffer_being_written = 
    ( display->buffer_being_written + 1 ) % display->num_frame_buffers;

  if( display->buffer_being_written == display->buffer_being_displayed ) {
    ret_code = 1;
  }
  else {
    ret_code = 0;
  }
  
  return(ret_code);
}
コード例 #22
0
ファイル: object_spawner.c プロジェクト: karfair/doge
void object_spawn_init(master *mstr){

	//init timer1 and interrupt


	//set base values
	init_obj(mstr->o);
	init_obj(mstr->co);
	init_obj(mstr->spikes);
	init_obj(mstr->box_3);
	init_obj(mstr->box_1);
	init_obj(mstr->flag);

	IOWR_16DIRECT(TIMER_1_BASE, 8, mstr->l->wait_time[mstr->l->obj_index] & 0xFFFF); //writes the period to the hardware timer
	IOWR_16DIRECT(TIMER_1_BASE, 12, mstr->l->wait_time[mstr->l->obj_index] >> 16);
	IOWR_16DIRECT(TIMER_1_BASE, 4, 1 << 3); //stop timer

	alt_irq_register(TIMER_1_IRQ,mstr,(void*)object_spawn_interrupt);//registers function to a specific IRQ

	//IOWR_16DIRECT(TIMER_1_BASE, 4, 0x5);	//starts timer with interrupt

	return;
}
コード例 #23
0
/* This funcion draws a pixel to the background buffer, and assumes:
 * 1. Your pixel buffer DMA is set to CONSECUTIVE
 * 2. The resolution is 320x240
 * 3. x and y are within the screen (0,0)->(319, 239)
 * 4. You are using 16-bit color
 *
 * DO NOT USE THIS FUNCTION IF ANY OF THE ABOVE ARE NOT GUARANATEED, OR YOU
 * MAY WRITE TO INVALID MEMORY LOCATIONS, CRASHING YOUR PROGRAM, OR
 * CAUSING UNEXPECTED BEHAVIOR.
 */
int draw_pixel_fast(alt_up_pixel_buffer_dma_dev *pixel_buffer,
		unsigned int color, unsigned int x, unsigned int y, int backbuffer) {
	unsigned int bufferAddr;
	if (backbuffer == 1)
		bufferAddr = pixel_buffer->back_buffer_start_address;
	else
		bufferAddr = pixel_buffer->buffer_start_address;

	unsigned int addr;

	addr = ((x & pixel_buffer->x_coord_mask) << 1);
	addr += (((y & pixel_buffer->y_coord_mask) * 320) << 1);

	IOWR_16DIRECT(bufferAddr, addr, color);

	return 0;
}
コード例 #24
0
ファイル: hello.c プロジェクト: gb88/KNN_Accelerator_Thesis
void send_short(alt_u16* buffer, alt_u16 len)
{
	alt_u16 i = 0;
	for(i = 0; i < len-1; i++)
	{
		IOWR_16DIRECT(USBFIFOCTRL_0_BASE,0x0006,0x0003);
		while(IORD_16DIRECT(USBFIFOCTRL_0_BASE,0x0002)& 0x0001);
		IOWR_16DIRECT(USBFIFOCTRL_0_BASE,0x0000,(unsigned int) buffer[i]);
		IOWR_16DIRECT(USBFIFOCTRL_0_BASE,0x0004,(unsigned int) 0x0001);
	}
	IOWR_16DIRECT(USBFIFOCTRL_0_BASE,0x0006,0x0003);
	while(IORD_16DIRECT(USBFIFOCTRL_0_BASE,0x0002)& 0x0001);
	IOWR_16DIRECT(USBFIFOCTRL_0_BASE,0x0000,(unsigned int) buffer[len-1]);
	IOWR_16DIRECT(USBFIFOCTRL_0_BASE,0x0004,(unsigned int) 0x0005);
}
コード例 #25
0
ファイル: memtest_small.c プロジェクト: caudipublius/peridot
/******************************************************************
*  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);
}
コード例 #26
0
ファイル: timer.c プロジェクト: cilver/LaserSharknado
// Test code from lab
void timer_test(void) {
	int freq;
	int cycles;
	float duration;
	int ticks_start;
	int ticks_end;
	int ticks_per_s;
	int ticks_duration;
	int timer_period;
	int status;
	int done;

	printf("Timers\n");
	printf(" Sys Clock Timer\n");
	ticks_per_s = alt_ticks_per_second();
	printf("Tick Freq: %d\n", ticks_per_s);
	printf(" Recording starting ticks\n");
	ticks_start = alt_nticks();
	printf(" Sleeping for 5 seconds\n");
	usleep(5000000);
	printf(" Recording ending ticks\n");
	ticks_end = alt_nticks();
	ticks_duration = ticks_end -ticks_start;
	duration = (float) ticks_duration / (float) ticks_per_s;
	printf(" The program slept for %d ticks (%f seconds)\n\n", ticks_duration,
	duration);

	printf(" Timestamp Timer\n");
	freq = alt_timestamp_freq();
	printf(" CPU Freq: %d\n", freq);
	printf(" Resetting Timestamp timer\n");
	alt_timestamp_start();
	printf(" ...Timing the print of this statement...\n");
	cycles = alt_timestamp();
	duration = (float) cycles / (float) freq;
	printf(" It took %d cycles (%f seconds) to print the statement\n\n",
	cycles, duration);

	printf(" Hardware-Only Timer\n");
	printf(" Setting timer period to 5 seconds.\n");
	timer_period = 5 * CLOCK_FREQ;
	// Setting the period registers must be done in 2 steps as they are only 16 bits wide
	IOWR_16DIRECT(MY_HW_ONLY_TIMER_BASE, 8, timer_period & 0xFFFF); // less significant word
	IOWR_16DIRECT(MY_HW_ONLY_TIMER_BASE,12, timer_period >> 16); // more significant word
	printf(" Stopping Timer\n");
	status = IORD_16DIRECT(MY_HW_ONLY_TIMER_BASE, 0); // read status registers
	// Write the control registers
	if(status & 0x2) {
		IOWR_16DIRECT(MY_HW_ONLY_TIMER_BASE, 4, 1 << 3); // stop the timer if it was started
	}
	printf(" Starting Timer\n");
	IOWR_16DIRECT(MY_HW_ONLY_TIMER_BASE, 4, 1 << 2); // start the timer

	printf("  Waiting for timer to expire...\n");
	done = 0;
	while(! done) {
		status = IORD_16DIRECT(MY_HW_ONLY_TIMER_BASE, 0); // read status registers
		done = status & 0x1;
	}
	printf(" 5 seconds timer is done\n");
}
コード例 #27
0
ファイル: timer.c プロジェクト: cilver/LaserSharknado
void startHardwareTimer(void)
{
	IOWR_16DIRECT(MY_HW_ONLY_TIMER_BASE, 4, 1 << 2);
}
コード例 #28
0
void alt_up_pixel_buffer_draw_vline(alt_up_pixel_buffer_dev *pixel_buffer, int x, int y0, int y1, int color, int backbuffer)
/* This method draws a vertical line. This method is faster than using the line method because we know the direction of the line. */

{
	register unsigned int addr;
	register unsigned int limit_x = pixel_buffer->x_resolution;
	register unsigned int limit_y = pixel_buffer->y_resolution;
	register unsigned int temp;
	register unsigned int line_x = x;
	register unsigned int t_y = y0;
	register unsigned int b_y = y1;
	register unsigned int local_color = color;
	
	/* Check coordinates */
	if (t_y > b_y)
	{
		temp = t_y;
		t_y = b_y;
		b_y = temp;
	}
	if ((line_x >= limit_x) || (t_y >= limit_y) || (line_x < 0) || (b_y < 0))
	{
		/* Drawing outside of the window, so don't bother. */
		return;
	}
	/* Clip the box and draw only within the confines of the screen. */
	if (t_y < 0)
	{
		t_y = 0;
	}
	if (b_y >= limit_y)
	{
		b_y = limit_y - 1;
	}

	/* Set up the address to start clearing from and the screen boundaries. */
	if (backbuffer == 1)
		addr = pixel_buffer->back_buffer_start_address;
	else
		addr = pixel_buffer->buffer_start_address;

	/* Draw the vertical line using one of the addressing modes. */
	if (pixel_buffer->addressing_mode == ALT_UP_PIXEL_BUFFER_XY_ADDRESS_MODE) {
		/* Draw a vertical line of a given color on the screen using the XY addressing mode. */
		register unsigned int y;
		register unsigned int offset_y;
		offset_y = pixel_buffer->y_coord_offset;
		addr = addr + (t_y << offset_y);
		
		/* This portion of the code is purposefully replicated. This is because having a text for
		 * the mode would unnecessarily slow down the drawing of a box. */
		if (pixel_buffer->color_mode == ALT_UP_8BIT_COLOR_MODE) {
			for (y = t_y; y <= b_y; y++)
			{
				IOWR_8DIRECT(addr, line_x, local_color);
				addr = addr + (1 << offset_y);
			}
		} else if (pixel_buffer->color_mode == ALT_UP_16BIT_COLOR_MODE) {
			for (y = t_y; y <= b_y; y++)
			{
				IOWR_16DIRECT(addr, line_x << 1, local_color);
				addr = addr + (1 << offset_y);
			}
		}
		else
		{
			for (y = t_y; y <= b_y; y++)
			{
				IOWR_32DIRECT(addr, line_x << 2, local_color);
				addr = addr + (1 << offset_y);
			}
		}
	} else {
		/* Draw a vertical line of a given color on the screen using the linear addressing mode. */
		register unsigned int y;
		/* This portion of the code is purposefully replicated. This is because having a text for
		 * the mode would unnecessarily slow down the drawing of a box. */
		if (pixel_buffer->color_mode == ALT_UP_8BIT_COLOR_MODE) {
			addr = addr + t_y * limit_x;
			for (y = t_y; y <= b_y; y++)
			{
				IOWR_8DIRECT(addr, line_x, local_color);
				addr = addr + limit_x;
			}
		} else if (pixel_buffer->color_mode == ALT_UP_16BIT_COLOR_MODE) {
			limit_x = limit_x << 1;
			addr = addr + t_y * limit_x;
			for (y = t_y; y <= b_y; y++)
			{
				IOWR_16DIRECT(addr, line_x << 1, local_color);
				addr = addr + limit_x;
			}
		}
		else
		{
			limit_x = limit_x << 2;
			addr = addr + t_y * limit_x;
			for (y = t_y; y <= b_y; y++)
			{
				IOWR_32DIRECT(addr, line_x << 2, local_color);
				addr = addr + limit_x;
			}
		}
	}
}
コード例 #29
0
ファイル: object_spawner.c プロジェクト: karfair/doge
void object_spawn_interrupt( void* context ){
	//printf("entered interrupt\n");
	IOWR_16DIRECT(TIMER_1_BASE,0,0); //needed to show that interrupt finished executing

	master *mstr_spwn = (master*)context;

	if(highlighted_level == 3){
		object* o = mstr_spwn->o;
		object* coin = mstr_spwn->co;

		int i, index = 0;
		//if # of objects in obj struct is OBJECT_SIZE or over, program finds and index with an invalid value and replaces that
		if(o->size >= OBJECT_SIZE){
			for(i = 0; i<OBJECT_SIZE; i++){
				//printf("%i ", o->temp_length[i]);
				if(o->temp_length[i]==-1) {
					index = i;
					o->temp_length[i] = 0;
					break;
				}
			}
		}
		else
			index = o->size;

		int temp5;
		if(first_platform == true){
			temp5 = 20000000;
			first_platform = false;
			o->color[index] = -1;
			o->y[index] = 220;
			o->length[index] = 80;
			o->height[index] = 13;
			o->x[index] = 319;
			prev_y = 220;
		}else{
			temp5 = 0;
			inc += 500000;
			temp5 -= inc;
			o->color[index] = rand() % 2 ;
			int temp = rand() % 101 - 50;
			prev_y += temp;
			if( prev_y > 225 ) prev_y = 225;
			if( prev_y < 125 ) prev_y = 125;
			o->y[index] = prev_y;
			o->length[index] = rand()%20 + 40;
			o->height[index] = 13;
			o->x[index] = 319;
		}

		//increment # of objects and level index
		//printf("count: %i y:%i l:%i h:%i x:%i\n", count++,o->y[index],o->length[index],o->height[index],o->x[index]);

		o->size++;


		//if # of objects in obj struct is OBJECT_SIZE or over, program finds and index with an invalid value and replaces that
		if(coin->size >= OBJECT_SIZE){
			for(i = 0; i<OBJECT_SIZE; i++){
				//printf("%i ", o->temp_length[i]);
				if(coin->temp_length[i]==-1) {
					index = i;
					coin->temp_length[i] = 0;
					break;
				}
			}
		}
		else
			index = coin->size;

		coin->y[index] = prev_y-14;
		coin->length[index] = 10;
		coin->height[index] = 14;
		coin->x[index] = 319;

		coin->size++;

		temp5 += (40000000 + rand() % 20000000);
		 //writes the period to the hardware timer
		IOWR_16DIRECT(TIMER_1_BASE, 8, temp5 & 0xFFFF);
		IOWR_16DIRECT(TIMER_1_BASE, 12, temp5 >> 16);

		IOWR_16DIRECT(TIMER_1_BASE,4,0x5); //restarts the hardware timer before exiting the isr
		return;
	}
コード例 #30
0
ファイル: HEX.c プロジェクト: Limro/IHA
void printBCDon7Seg(int bcd)
{
	// Update HEX-LEDs
	IOWR_16DIRECT(MM_BUS_SEVEN_SEG_FOUR_DIGIT_0_BASE, 2, BCDto7Seg(bcd));
}