/* ********************************************************************************************************* * uC/OS-View * * (c) Copyright 2004, Micrium, Inc., Weston, FL * All Rights Reserved * * Altera * Nios II ********************************************************************************************************* */ #include /*$PAGE*/ /* ********************************************************************************************************* * EXIT uC/OS-View * * Description: This function is not used in this port. ********************************************************************************************************* */ void OSView_Exit (void) { } /* ********************************************************************************************************* * Obtain CPU name * * Description: This routine allows the OSView application to display the name of the processor. ********************************************************************************************************* */ void OSView_GetCPUName (char *s) { OS_StrCopy(s, "Altera - Nios II"); } /* ********************************************************************************************************* * Obtain Interrupt Stack Base * * Description: This function simply returns a zero because the Nios II processor does not have a * seperate interrupt stack. * Returns : 0 ********************************************************************************************************* */ INT32U OSView_GetIntStkBase (void) { return ((INT32U)0); /* There is no seperate interrupt stack */ } /* ********************************************************************************************************* * Obtain Interrupt Stack Size * * Description: This function simply returns a zero because the Nios II processor does not have a * seperate interrupt stack. * Returns : 0 ********************************************************************************************************* */ INT32U OSView_GetIntStkSize (void) { return ((INT32U)0); /* There is no seperate interrupt stack */ } /*$PAGE*/ /* ********************************************************************************************************* * INITIALIZE uC/OS-View COM PORT * * Description: Initialize the hardware required for OS-View. A timer is setup to run continuously * (it will not cause an interrupt when it overflows) with the maximum period. The UART * is initialized to cause an interrupt when data is being received or when the transmit * buffer is empty. ********************************************************************************************************* */ void OSView_InitTarget (INT32U baud_rate) { INT16U isr_status; INT16U period_low; INT16U period_high; period_low = 0xFFFF; period_high = 0xFFFF; /* Use the maximum period for the 32-bit timer */ baud_rate = baud_rate; /* Baud rate is set by the hardware configuration */ /* Set the timer's period */ IOWR_ALTERA_AVALON_TIMER_PERIODL(HIGH_RES_TIMER_BASE, period_low); IOWR_ALTERA_AVALON_TIMER_PERIODH(HIGH_RES_TIMER_BASE, period_high); /* Start the timer running continuously */ IOWR_ALTERA_AVALON_TIMER_CONTROL(HIGH_RES_TIMER_BASE, ALTERA_AVALON_TIMER_CONTROL_CONT_MSK | ALTERA_AVALON_TIMER_CONTROL_START_MSK ); /* Register the UART interrupt handler */ isr_status = alt_irq_register (UART1_IRQ, (void *)0, OSView_RxTxISRHandler); /* Setup receive and transmit interrupts for the UART */ IOWR_ALTERA_AVALON_UART_CONTROL(UART1_BASE, ALTERA_AVALON_UART_CONTROL_TMT_MSK | ALTERA_AVALON_UART_CONTROL_RRDY_MSK); } /*$PAGE*/ /* ********************************************************************************************************* * Disable Rx Interrupts * * Description: This routine disables the UART's receive interrupts ********************************************************************************************************* */ void OSView_RxIntDis (void) { INT16U status; status = IORD_ALTERA_AVALON_UART_CONTROL(UART1_BASE); /* Get the current UART interrupt status */ status &= ~ALTERA_AVALON_UART_CONTROL_RRDY_MSK; /* and disable receive interrupts */ IOWR_ALTERA_AVALON_UART_CONTROL(UART1_BASE, status); } /* ********************************************************************************************************* * Enable Rx Interrupts * * Description: This routine enables receive interrupts for the UART ********************************************************************************************************* */ void OSView_RxIntEn (void) { INT16U status; status = IORD_ALTERA_AVALON_UART_CONTROL(UART1_BASE); /* Get the current UART interrupt status */ status |= ALTERA_AVALON_UART_CONTROL_RRDY_MSK; /* and enable receive interrupts */ IOWR_ALTERA_AVALON_UART_CONTROL(UART1_BASE, status); } /* ********************************************************************************************************* * Rx Communication handler for uC/OS-View * * Description: This routine is not used because the UART produces a single interrupt for receives * and transmits ********************************************************************************************************* */ void OSView_RxISRHandler (void) { } /* ********************************************************************************************************* * Rx/Tx Communication handler for uC/OS-View * * Description: This function is registered with the HAL as the interrupt handler for the UART. * The UART can cause an interrupt if it is receiving data, or if the transmit buffer * is empty. This function checks to see which of those conditions has occurs and * calls the appropriate processor independent code. ********************************************************************************************************* */ void OSView_RxTxISRHandler (void* context, alt_u32 id) { INT8U uart_chr; INT16U uart_status; /* Prevent compliler warning by doing something with the arguments */ context = context; id = id; /* See if a receive or transmit interrupt has occured */ uart_status = IORD_ALTERA_AVALON_UART_STATUS(UART1_BASE); if ((uart_status & ALTERA_AVALON_UART_STATUS_RRDY_MSK) != 0) { /* A receive interrupt has occured */ /* Get the received data and pass it to the processor independent code */ uart_chr = IORD_ALTERA_AVALON_UART_RXDATA(UART1_BASE); OSView_RxHandler(uart_chr); IOWR_ALTERA_AVALON_UART_STATUS(UART1_BASE, 0); /* Acknowledge the interrupt */ } if ((uart_status & ALTERA_AVALON_UART_STATUS_TMT_MSK) != 0) { /* A transmit interrupt has occured */ OSView_TxHandler(); /* Call the processor independent code */ IOWR_ALTERA_AVALON_UART_STATUS(UART1_BASE, 0); /* Acknowledge the interrupt */ } } /*$PAGE*/ /* ********************************************************************************************************* * Update 32-bit cycles counter * * Description: This function is empty because the Nios II has a 32-bit timer, so no time variable * needs to be updated. ********************************************************************************************************* */ void OSView_TickHook (void) { } /* ********************************************************************************************************* * Get time [cycles] * * Description: This routine returns a complement of the 32-bit timer's value, since the timer * counts down and an increasing cycle count is needed. * * Returns : A 32-bit representation of time. ********************************************************************************************************* */ INT32U OSView_TimeGetCycles (void) { INT32U snap_low; INT32U snap_high; INT32U snap; /* Cause the timer to copy its current value to its snapl and snaph registers */ IOWR_ALTERA_AVALON_TIMER_SNAPL(HIGH_RES_TIMER_BASE, 0); /* Read the snapshot of the timer */ snap_low = IORD_ALTERA_AVALON_TIMER_SNAPL(HIGH_RES_TIMER_BASE); snap_high = IORD_ALTERA_AVALON_TIMER_SNAPH(HIGH_RES_TIMER_BASE); snap = (snap_high << 16) + snap_low; snap = ~snap; /* Invert the timer value to simulate a count up timer */ return (snap); } /*$PAGE*/ /* ********************************************************************************************************* * Transmit a Character * * Description: Send 1 character to COM Port ********************************************************************************************************* */ void OSView_Tx1 (INT8U c) { IOWR_ALTERA_AVALON_UART_TXDATA(UART1_BASE, c); /* Transmit the given character */ } /* ********************************************************************************************************* * Disable Tx Interrupts * * Description: This routine disables the UART's transmit interrupts ********************************************************************************************************* */ void OSView_TxIntDis (void) { INT16U status; status = IORD_ALTERA_AVALON_UART_CONTROL(UART1_BASE); /* Get the current UART interrupt status */ status &= ~ALTERA_AVALON_UART_CONTROL_TMT_MSK; /* and disable transmit interrupts */ IOWR_ALTERA_AVALON_UART_CONTROL(UART1_BASE, status); } /* ********************************************************************************************************* * Enable Tx Interrupts * * Description: This routine enables transmit interrupts for the UART ********************************************************************************************************* */ void OSView_TxIntEn (void) { INT16U status; status = IORD_ALTERA_AVALON_UART_CONTROL(UART1_BASE); /* Get the current UART interrupt status */ status |= ALTERA_AVALON_UART_CONTROL_TMT_MSK; /* and enable transmit interrupts */ IOWR_ALTERA_AVALON_UART_CONTROL(UART1_BASE, status); } /* ********************************************************************************************************* * Tx Communication handler for uC/OS-View * * Description: This routine is not used because the UART produces a single interrupt for receives and * transmits ********************************************************************************************************* */ void OSView_TxISRHandler (void) { }