예제 #1
0
/******************************************************************
*  Function: alt_video_display_allocate_buffers
*
*  Purpose: Allocates memory for both the frame buffers and the 
*           descriptor chains.
* 
*           If ALT_VIDEO_DISPLAY_USE_HEAP is specified for either
*           the buffer_location or descriptor_location, the memory
*           is allocated from the heap. Otherwise, buffer_location and 
*           descriptor_locaiton are presumed to contain the base address 
*           of memory sufficient to hold the requested number of descriptors
*           and video frames. This memory space may be quite large.
* 
*  Returns:  0 - Success
*           -1 - Error allocating memory
******************************************************************/
int alt_video_display_allocate_buffers( alt_video_display* display,
                                       int bytes_per_frame,
                                       int buffer_location,
                                       int descriptor_location,
                                       int num_buffers )
{
  int i, ret_code = 0;
  
  /* Allocate our frame buffers and descriptor buffers */
  for( i = 0; i < num_buffers; i++ ) {
    display->buffer_ptrs[i] = 
      (alt_video_frame*) malloc( sizeof( alt_video_frame ));
      
    if(display->buffer_ptrs[i] == NULL) {
      ret_code = -1;
    }
    
    if( buffer_location == ALT_VIDEO_DISPLAY_USE_HEAP ) {
      display->buffer_ptrs[i]->buffer = 
        (void*) alt_uncached_malloc(( bytes_per_frame ));
        
      if( display->buffer_ptrs[i]->buffer == NULL )
        ret_code = -1;
    }
    else {
      display->buffer_ptrs[i]->buffer = (void*)alt_remap_uncached(
        (void*)(buffer_location + (i * bytes_per_frame)), bytes_per_frame);
    }
    
    if( descriptor_location == ALT_VIDEO_DISPLAY_USE_HEAP ) {
      /*
       * The SGDMA controller requires all descriptors to be aligned to
       * the size of an SGDMA descriptor (32 bytes).  Use memalign() to 
       * get properly aligned address.
       */
      display->buffer_ptrs[i]->desc_base = (alt_sgdma_descriptor*)
        memalign( 32, alt_video_display_get_descriptor_span( display ) );
      
      if( display->buffer_ptrs[i]->desc_base == NULL ) {
        ret_code = -1;
      }
    }
    else {
      display->buffer_ptrs[i]->desc_base = 
        (alt_sgdma_descriptor*)((void*)descriptor_location + 
          (i * alt_video_display_get_descriptor_span( display )));
    } 
  }
 
  return ret_code;
}
예제 #2
0
int spu_init(alt_u32 dev_pcm)			// 初期化 
{
	int i;

	if (dev_pcm == 0) {
		IOWR(g_dev_spu, spu_reg_status, spu_mute_enable);
		IOWR(g_dev_spu, spu_reg_setup, 0);

		if (p_g_wavbuff != NULL) alt_uncached_free(p_g_wavbuff);
		g_dev_spu = 0;

		return 0;
	}

	p_g_wavbuff = (alt_u16 *)alt_uncached_malloc(nd_WAVBUFF_SIZE);
	if (p_g_wavbuff == NULL) return -1;

	g_dev_spu = dev_pcm;

//	IOWR(dev_pcm, spu_reg_status, spu_mute_enable);
	IOWR(dev_pcm, spu_reg_setup, 0);

	for(i=1 ; i<=spudef_slotmax ; i++) {
		IOWR(dev_pcm, spu_reg_slotstatus(i), spu_keyoff);
		IOWR(dev_pcm, spu_reg_volume_l(i), 0);
		IOWR(dev_pcm, spu_reg_volume_r(i), 0);
	}

	IOWR(dev_pcm, spu_reg_setup, spudef_slotmax);
	IOWR(dev_pcm, spu_reg_status, 0);
	IOWR(dev_pcm, spu_reg_aclink, 0x04000);
	IOWR(dev_pcm, spu_reg_aclink, 0x14000);

	IOWR(dev_pcm, spu_reg_sync, 1);
	while( (IORD(dev_pcm, spu_reg_sync) & spu_syncbusy_bitmask) ) {}

	return 0;
}
예제 #3
0
파일: file_test.c 프로젝트: osafune/ulexite
int main(void)
{
	alt_u16 *pFrameBuffer;

	// システム初期化 

	IOWR(LED_7SEG_BASE, 0, ~0x71733d77);	// FPGAと表示する 
	IOWR(BLCON_BASE, 0, (0<<8));			// バックライトOFF

	systeminit();


	// ファイルシステム初期化 

	mmcfs_setup();


	// VGA初期化 

	nd_GsVgaInit();

	pFrameBuffer = (alt_u16 *)alt_uncached_malloc(na_VRAM_size);
	if (pFrameBuffer == NULL) {
		printf("[!] Framebuffer assignment failed.\n");
		return -1;
	}

	nd_GsVgaSetBuffer((nd_u32)pFrameBuffer);
	nd_GsEglPage((nd_u32)pFrameBuffer,(nd_u32)pFrameBuffer,0);

	nd_color(nd_COLORGRAY, 0, 256);
	nd_boxfill(0, 0, window_xmax, window_ymax);

	nd_color(nd_COLORWHITE, 0, 256);
	nd_line(0,0, 0,window_ymax);
	nd_color(nd_COLORRED, 0, 256);
	nd_line(window_xmax,0, window_xmax,window_ymax);
	nd_color(nd_COLORLIGHTGREEN, 0, 256);
	nd_line(0,0, window_xmax,0);
	nd_color(nd_COLORBLUE, 0, 256);
	nd_line(0,window_ymax, window_xmax,window_ymax);

	nd_GsVgaScanOn();
	IOWR(BLCON_BASE, 0, (1<<8)|0);		// バックライトON、輝度最大 


	// 画像を展開 

	loadbmp("mmcfs:/de0/test.bmp",pFrameBuffer);

	printf("done.\n");
	while(1) {}


	// 終了処理 

	nd_GsVgaScanOff();
	alt_uncached_free(pFrameBuffer);


	return 0;
}
//------------------------------------------------------------------------------
UINT8* openmac_uncachedMalloc(UINT size_p)
{
    return (UINT8*)alt_uncached_malloc(size_p);
}
예제 #5
0
static int MemDMATest(unsigned int memory_base, unsigned int nBytes)
{
  int rc;
  int ret_code = 0;
  int pattern, offset;
  alt_dma_txchan txchan;
  alt_dma_rxchan rxchan;
  void* data_written;
  void* data_read;
  
  /* Get a couple buffers for the test */
  data_written = (void*)alt_uncached_malloc(0x1000);
  data_read = (void*)alt_uncached_malloc(0x1000);
  
  
  /* Fill write buffer with known values */
  for (pattern = 1, offset = 0; offset < sizeof(data_written); pattern++, offset+=4)
  {
    IOWR_32DIRECT((int)data_written, offset, pattern);
  }

  /* Create the transmit channel */
  if ((txchan = alt_dma_txchan_open("/dev/dma")) == NULL)
  {
    printf ("Failed to open transmit channel\n");
    exit (1);
  }
  
  /* Create the receive channel */
  if ((rxchan = alt_dma_rxchan_open("/dev/dma")) == NULL)
  {
    printf ("Failed to open receive channel\n");
    exit (1);
  }
  
  for(offset = memory_base; offset < (memory_base + nBytes); offset += 0x1000)
  {
    /* Use DMA to transfer from write buffer to memory under test */
    /* Post the transmit request */
    if ((rc = alt_dma_txchan_send (txchan, data_written, 0x1000, NULL, NULL)) < 0)
    {
      printf ("Failed to post transmit request, reason = %i\n", rc);
      exit (1);
    }

    /* Post the receive request */
    if ((rc = alt_dma_rxchan_prepare (rxchan, (void*)offset, 0x1000, dma_done, NULL)) < 0)
    {
      printf ("Failed to post read request, reason = %i\n", rc);
      exit (1);
    }
  
    /* Wait for transfer to complete */
    while (!rx_done);
    rx_done = 0;
    
    /* Clear the read buffer before we fill it */
    memset(data_read, 0, 0x1000);
    
    /* Use DMA to read data back into read buffer from memory under test */
    /* Post the transmit request */
    if ((rc = alt_dma_txchan_send (txchan, (void*)offset, 0x1000, NULL, NULL)) < 0)
    {
      printf ("Failed to post transmit request, reason = %i\n", rc);
      exit (1);
    }

    /* Post the receive request */
    if ((rc = alt_dma_rxchan_prepare (rxchan, data_read, 0x1000, dma_done, NULL)) < 0)
    {
      printf ("Failed to post read request, reason = %i\n", rc);
      exit (1);
    }

    /* Wait for transfer to complete */
    while (!rx_done);
    rx_done = 0;
    
    if (memcmp(data_written, data_read, 0x1000))
    {
      ret_code = offset;
      break;
    }
  }
  alt_uncached_free(data_written);
  alt_uncached_free(data_read);
  return ret_code;
}
//------------------------------------------------------------------------------
void* openmac_uncachedMalloc(size_t size_p)
{
    return (void*)alt_uncached_malloc(size_p);
}