Intel® Quartus® Prime Software
Intel® Quartus® Prime Design Software, Design Entry, Synthesis, Simulation, Verification, Timing Analysis, System Design (Platform Designer, formerly Qsys)
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Using UART FD

Chloé_Russell
Beginner
2,127 Views

Hello,

 

This is my first use of Software drivers. I'm working with the Quartus standard version 16.0.

 

when I used the "altera_avalon_uart_write" and "altera_avalon_uart_read" functions, things go right.. but when trying to use FD (altera_avalon_uart_write_fd and altera_avalon_uart_read_fd) , the parameter SP points to a false base address although the file has been correctly opened, it returns a valid value (!=NULL).

 

my code is :

 

int main()

{

 altera_avalon_uart_state* sp_UART_0;

  altera_avalon_uart_state* sp_UART_1;

 

  sp_UART_0->base = UART_0_BASE;

  sp_UART_1->base = UART_1_BASE;

 

  char tx_buffer[8] = "BITBANG";

  char rx_buffer[8];

 

   alt_fd* fp_uart_1;

   alt_fd* fp_uart_0;

 

   fp_uart_1= open ("/dev/uart_1", O_RDWR); //Open file for reading and writing

   fp_uart_0= open ("/dev/uart_0",O_RDWR); //Open file for reading and writing

 

   printf("call init uart\n");

   altera_avalon_uart_init(sp_UART_1, UART_1_IRQ_INTERRUPT_CONTROLLER_ID,UART_1_IRQ);

   altera_avalon_uart_init(sp_UART_0, UART_0_IRQ_INTERRUPT_CONTROLLER_ID,UART_0_IRQ);

 

   int wr = altera_avalon_uart_write_fd (fp_uart_1,tx_buffer,sizeof(tx_buffer)) ;

   printf("wr = %d\n",wr);

   alt_busy_sleep(1000000); / delay 1us /// 1 s

 

   int rd = altera_avalon_uart_read_fd (fp_uart_0,rx_buffer,sizeof(tx_buffer)) ;

   alt_busy_sleep(1000000); / delay 1us /// 1 s

   printf(" rd = %d\n",rd);

 

   printf("rx_buffer = '%s'\n\n",rx_buffer);

 

   printf("sp_UART_0 base = 0x%08X \n", sp_UART_0->base);

   printf("sp_UART_0 ctrl = 0x%08X \n", sp_UART_0->ctrl);

   printf("sp_UART_0 tx_buf = '%s' \n", sp_UART_0->tx_buf);

   printf("sp_UART_0 rx_buf = '%s' \n\n\n", sp_UART_0->rx_buf);

 

   printf("sp_UART_1 base = 0x%08X \n", sp_UART_1->base);

   printf("sp_UART_1 ctrl = 0x%08X \n", sp_UART_1->ctrl);

   printf("sp_UART_1 tx_buf = '%s' \n", sp_UART_1->tx_buf);

   printf("sp_UART_1 rx_buf = '%s' \n\n", sp_UART_1->rx_buf);

 

   printf(" rx_buffer = %s\n",rx_buffer);

 

  altera_avalon_uart_close (fp_uart_1) ;

  altera_avalon_uart_close (fp_uart_0) ;

 

  free(fp_uart_1);

  free(fp_uart_0);

 

 return 0;

}

 

 

I'm not sure if I'm missing or using things wrong, any help would be much appreciated. Thank you in advance

 

0 Kudos
0 Replies
Reply