EmbeddedRelated.com
Forums

AT91 USART Interrupt Source Code GCC

Started by jannethgil July 11, 2005
Hi

Does anybody has an simple example on using usart interrupts using
the
GCC compiler for an AT91 ARM7 microcontroller?.

I just need to get started.

Any links, sugestions or source code will be appreciated

Thanks :)


Just a snippet from a current project:

#define BUFFER_SIZE 256

#ifdef MD_USE_USART0
mdByte
com0_recBuffer[BUFFER_SIZE],
com0_sendBuffer[BUFFER_SIZE];
mdBuffer
com0_ReceiveBuffer,
com0_SendBuffer;
const AT91PS_USART
com0 = AT91C_BASE_US0;
mdBool
ser_bTransmission = false; void usart0_irq_handler()
{
mdUInt32
status;

status = com0->US_CSR;
status &= com0->US_IMR;

if (status & AT91C_US_TXRDY)
{
if (com0_SendBuffer.pos == com0_SendBuffer.len)
{
com0->US_IDR = AT91C_US_TXRDY;

ser_bTransmission = false;
}
else
{
com0->US_THR = com0_SendBuffer.buf[com0_SendBuffer.pos++];

if (com0_SendBuffer.pos >= com0_SendBuffer.size)
com0_SendBuffer.pos = 0;
}
}

if (status & AT91C_US_RXRDY)
{
if (com0_ReceiveBuffer.len >= com0_ReceiveBuffer.size)
com0_ReceiveBuffer.len = 0;

com0_ReceiveBuffer.buf[com0_ReceiveBuffer.len++] = com0->US_RHR;
}

com0->US_CR = AT91C_US_RSTSTA;
AT91C_BASE_AIC->AIC_EOICR = 0;
} void usart0_init()
{
AT91F_US0_CfgPMC();
AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA,
((mdUInt32) AT91C_PA5_RXD0) |
((mdUInt32) AT91C_PA6_TXD0),
0
);

AT91F_US_Configure(com0, TARGET_MCK, AT91C_US_ASYNC_MODE, USART0_BAUDRATE,
0);

com0->US_CR = AT91C_US_RXEN | AT91C_US_TXEN;

com0->US_IER = AT91C_US_RXRDY;

__md_ulDummy = com0->US_RHR;

AT91F_AIC_ConfigureIt(AT91C_BASE_AIC,
AT91C_ID_US0,
USART0_INTERRUPT_LEVEL,
AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE,
usart0_irq_handler
);
AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_US0);

com0_ReceiveBuffer.size = BUFFER_SIZE;
com0_ReceiveBuffer.pos = 0;
com0_ReceiveBuffer.len = 0;
com0_ReceiveBuffer.buf = com0_recBuffer;

com0_SendBuffer.size = BUFFER_SIZE;
com0_SendBuffer.pos = 0;
com0_SendBuffer.len = 0;
com0_SendBuffer.buf = com0_sendBuffer;
} void usart0_send(const mdByte *buf, mdUInt32 len)
{
mdUInt32
i;

if (len > BUFFER_SIZE)
len = BUFFER_SIZE;

for (i = 0; i < len; i++)
{
if (com0_SendBuffer.len >= com0_SendBuffer.size)
com0_SendBuffer.len = 0;
com0_SendBuffer.buf[com0_SendBuffer.len++] = buf[i];
}

ser_bTransmission = true;

com0->US_IER = AT91C_US_TXRDY | AT91C_US_RXRDY;
} mdUInt32 usart0_received()
{
mdUInt32
len;

if (com0_ReceiveBuffer.pos <= com0_ReceiveBuffer.len)
len = com0_ReceiveBuffer.len - com0_ReceiveBuffer.pos;
else
len = com0_ReceiveBuffer.size - com0_ReceiveBuffer.pos +
com0_ReceiveBuffer.len;

return len;
} void usart0_get(mdByte *dest, mdUInt32 len)
{
while (len--)
{
if (com0_ReceiveBuffer.pos >= com0_ReceiveBuffer.size)
com0_ReceiveBuffer.pos = 0;

*dest++ = com0_ReceiveBuffer.buf[com0_ReceiveBuffer.pos++];
}
} void usart0_clear()
{
com0_ReceiveBuffer.len = 0;
com0_ReceiveBuffer.pos = 0;
com0_SendBuffer.len = 0;
com0_SendBuffer.pos = 0;
} --
Mike On Tuesday 12 July 2005 01:08, jannethgil wrote:
> Hi
>
> Does anybody has an simple example on using usart interrupts using
> the
> GCC compiler for an AT91 ARM7 microcontroller?.
>
> I just need to get started.
>
> Any links, sugestions or source code will be appreciated
>
> Thanks :) >
>
> YAHOO! GROUPS LINKS >



Thank You Very Much :) --- In AT91SAM7@AT91..., "jannethgil" <jannethgil@y...> wrote:
> Hi
>
> Does anybody has an simple example on using usart interrupts using
> the
> GCC compiler for an AT91 ARM7 microcontroller?.
>
> I just need to get started.
>
> Any links, sugestions or source code will be appreciated
>
> Thanks :)