[En-Nut-Discussion] NutOS Dbgu Interrupt

András Szemző szemzo.andras at gmail.com
Wed Jan 20 14:06:51 CET 2010


hi,

if you would like to use your own DBGU functions instead of ethernut driver, you can do something like:

int At91UsartDbguInit(unsigned int baud)
{

    /*
     * Register receive and transmit interrupts.
     */
    if (NutRegisterSysIrqHandler(&SIG_UART_DBGU, At91UsartDbguInterrupt, 0)) {
        return -1;
    }

    outr(PMC_PCER, _BV(SYSC_ID));

    /* Disable GPIO on UART tx/rx pins. */
    outr(PIOA_PDR, _BV(27) | _BV(28));
    /* Reset UART. */
    outr(DBGU_CR, US_RSTRX | US_RSTTX | US_RXDIS | US_TXDIS);
    /* Disable all UART interrupts. */
    outr(DBGU_IDR, 0xFFFFFFFF);
    /* Set UART baud rate generator register. */
    outr(DBGU_BRGR, (NutGetCpuClock() / (8 * (baud)) + 1) / 2);
    /* Set UART mode to 8 data bits, no parity and 1 stop bit. */
    outr(DBGU_MR, US_CHMODE_NORMAL | US_PAR_NO);

   At91UsartDbguEnable();

    return 0;
}

static void At91UsartDbguEnable(void)
{

    /* Enable UART receiver and transmitter. */
    outr(DBGU_CR, US_RXEN | US_TXEN);
	
    /* Enable UART receiver interrupts. */
    outr(DBGU_IER, US_RXRDY);

    NutSysIrqEnable(&SIG_UART_DBGU);
}

static void At91UsartDbguInterrupt(void *arg)
{
    ureg_t csr = inr(DBGU_SR);

    if (csr & US_RXRDY) {
        At91UsartDbguRxReady();
    }
/*    if (csr & US_TXRDY) {
        At91UsartTxReady();
    }
*/
}


static void At91UsartDbguRxReady(void) 
{
	unsigned char data;
	unsigned char tmphead;

	/* Read the received data */
	data = inb(DBGU_RHR);               
	/* Calculate buffer index */
	tmphead = ( USARTDBGU_RxHead + 1 ) & USARTDBGU_RX_BUFFER_MASK;
	USARTDBGU_RxHead = tmphead;      /* Store new index */
	/* ERROR! Receive buffer overflow */
	//if ( tmphead == USART_RxTail ) { }
	USARTDBGU_RxBuf[tmphead] = data; /* Store received data in buffer */	
}


Regards,
Andras




On Jan 20, 2010, at 1:07 PM, kafka85 wrote:

> Hi,
> 
> I'm using Nut/OS 4.8.5. I'm trying to create my own routine on DBGU receive interrupt. Can you guide me how to do that?
> 
> I succesfully created timer interrupt as follows:
> 
> void InitApiTimer(void) {
> 	compare_value = local_ZBTO;
> 	outr(AIC_IECR, _BV(TC1_ID));
> 	outr(PMC_PCER, _BV(TC1_ID));
> 	outr(TC1_CCR, TC_CLKDIS);
> 	outr(TC1_IDR, 0xFFFFFFFF);
> 	inr(TC1_SR);
> 	outr(TC1_CMR, TC_CLKS_MCK32);
> 	outr(TC1_RC, local_ZBTO);
> 	outr(TC1_CCR, TC_CLKEN);
> 	outr(TC1_IER, TC_CPCS);
> 	NutRegisterIrqHandler(&sig_TC1, ApiTimerIntr, 0);
> 	NutIrqSetPriority(&sig_TC1, 7);
> 	NutIrqEnable(&sig_TC1);
> 	outr(TC1_CCR, TC_SWTRG);
> }
> 
> My DBGU setup routine is as follows:
> 
> void debug_init(AT91PS_DBGU paramDbgu, AT91PS_PIO paramPio, uint32_t pinMask,
> 		uint8_t periph, uint32_t baud) {
> 
> 	pDbgu = paramDbgu;
> 	paramPio->PIO_PDR = pinMask;
> 	if (periph == 0) {
> 		paramPio->PIO_ASR = pinMask;
> 	} else {
> 		paramPio->PIO_BSR = pinMask;
> 	}
> 	pDbgu->DBGU_CR = AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS
> 			| AT91C_US_TXDIS;
> 	pDbgu->DBGU_MR = AT91C_US_PAR_NONE | AT91C_US_CHRL_8_BITS;
> 	pDbgu->DBGU_BRGR = AT91F_US_Baudrate(MCK, baud);
> 
> 	//enable interrupt source
> 	//pDbgu->DBGU_IER = AT91C_US_RXRDY;
> 
> 	pDbgu->DBGU_CR = AT91C_US_RXEN | AT91C_US_TXEN;
> }
> 
> 
> I'd like to create my own DBGU interrupt routine in the same manner as my timer interrupt.
> _______________________________________________
> http://lists.egnite.de/mailman/listinfo/en-nut-discussion




More information about the En-Nut-Discussion mailing list