Forum Discussion
Altera_Forum
Honored Contributor
19 years agohttp://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/sad.gif
Hi Banx, Thanx for your code. I've compared it to mine and it is essentially the same. I've even gone as far as re-writing my code the same as yours and trying it. The result remains the same. As soon as I enable the TRDY interrupt, the code breaks. It just doesn't make sense!!! Just out of interest, I don't quite follow how the statement tx_in_index_0 &= txb_size_mask; works. I realise that you only use two pointers for your ring buffer. What do you determine by the statement??? (Please excuse my apparent stupidity!!!) I just use another variable as a counter. I suppose it boils down to being the same. Out of interest, my current functions are: // ============================================================void uart_placechar(unsigned int uartnumber, unsigned char datacharacter)
{
while (uart[uartnumber].tx_counter == uart_tx_ringbuffer_size);
uart[uartnumber].tx_ringbuffer[uart[uartnumber].tx_wr_index] = datacharacter;
uart[uartnumber].tx_wr_index++;
if (uart[uartnumber].tx_wr_index == uart_tx_ringbuffer_size)
uart[uartnumber].tx_wr_index = 0;
// enable the tx (thr) interrupt
iowr_altera_avalon_uart_control(uart_base_address_lookup(uartnumber), (iord_altera_avalon_uart_control(uart_base_address_lookup(uartnumber)) | altera_avalon_uart_control_trdy_msk));
} // void uart_placechar(unsigned int uartnumber, unsigned char datacharacter)
// ============================================================
void uart25_isr(void* context, alt_u32 id)
{
unsigned char datacharacter;
unsigned int status,
uart_base_address,
uartnumber;
uartnumber = 25;
uart_base_address = uart_base_address_lookup(uartnumber);
status = iord_altera_avalon_uart_status(uart_base_address);
status &= (altera_avalon_uart_status_rrdy_msk | altera_avalon_uart_status_trdy_msk);
// clear any error flags and clear interrupt
iowr_altera_avalon_uart_status(uart_base_address, 0);
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// rx part
if (status & altera_avalon_uart_status_rrdy_msk)
{
datacharacter = iord_altera_avalon_uart_rxdata(uart_base_address);
if ((status & (altera_avalon_uart_status_fe_msk | altera_avalon_uart_status_pe_msk | altera_avalon_uart_status_roe_msk)) == 0)
{
uart[uartnumber].rx_ringbuffer[uart[uartnumber].rx_wr_index] = datacharacter;
if (++uart[uartnumber].rx_wr_index == uart_rx_ringbuffer_size)
uart[uartnumber].rx_wr_index = 0;
if (++uart[uartnumber].rx_counter == uart_rx_ringbuffer_size)
{
uart[uartnumber].rx_counter = 0;
uart[uartnumber].rx_buffer_overflow++;
} // if (++uart[uartnumber].rx_counter == uart_rx_ring_buffer_size)
} // if ((status & (altera_avalon_uart_status_fe_msk | altera_avalon_uart_status_pe_msk | altera_avalon_uart_status_roe_msk)) == 0)
} // if (status & altera_avalon_uart_status_rrdy_msk)
// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
// tx part
if (status & altera_avalon_uart_status_trdy_msk)
{
if (uart[uartnumber].tx_counter == 0)
{
iowr_altera_avalon_uart_control(uart_base_address, (iord_altera_avalon_uart_control(uart_base_address) | ~altera_avalon_uart_control_trdy_msk));
} // if (uart[uartnumber].tx_rd_index == uart[uartnumber].tx_wr_index)
else
{
iowr_altera_avalon_uart_txdata(uart_base_address, uart[uartnumber].tx_ringbuffer[uart[uartnumber].tx_rd_index]);
uart[uartnumber].tx_counter--;
uart[uartnumber].tx_rd_index++;
if (uart[uartnumber].tx_rd_index == uart_tx_ringbuffer_size)
uart[uartnumber].tx_rd_index = 0;
} // else
} // if (status & altera_avalon_uart_status_trdy_msk)
} // void uart25_isr(void* context, alt_u32 id) Note: The function UART_Base_Address_Lookup(UARTNumber) just returns the base for the current UART. (In this way I can use the same code for all my UARTs, barring the ISRs, those are uniquely named but the body of the function remains the same. The only way I differentiate is by the "hardcoded" variable UARTNumber) Also, I tried to se if my other UARTs are doing the same and they all are. Regards, Tyrone