📄 uart_example.c
字号:
/***********************************************************************
* $Workfile: uart_example.c $
* $Revision: 1.2 $
* $Author: WellsK $
* $Date: Oct 01 2003 12:03:58 $
*
* Project: Interrupt driven UART driver example
*
* Description:
* A Interrupt driven UART driver example.
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh7a404/bsps/sdk7a404/examples/uart_int/uart_example.c-arc $
*
* Rev 1.2 Oct 01 2003 12:03:58 WellsK
* Added logic to get TTB address from register CP15 TTB.
*
* Rev 1.1 Sep 18 2003 09:25:20 WellsK
* Updated example for MMU and VIC driver changes.
*
* Rev 1.0 Jul 01 2003 12:02:58 WellsK
* Initial revision.
*
*
***********************************************************************
* SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
* OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
* AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES,
* SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
*
* SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY
* FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A
* SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
* FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
*
* COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
* CAMAS, WA
**********************************************************************/
#include "abl_types.h"
#include "abl_irq_fiq.h"
#include "abl_arm922t_cp15_driver.h"
#include "lh7a404_vic_driver.h"
#include "lh7a404_uart_driver.h"
/* UART device handle */
STATIC INT_32 uartdev;
CHAR menu1[] = "Hello world\n\r";
CHAR menu2[] = "This is string 2\n\r";
CHAR menu3[] = "This is string 3\n\r";
CHAR menu4[] = "This is string 4\n\r";
CHAR menu5[] = "This is string 5\n\r";
/* Print a menu */
void print_menu(void)
{
uart_write_ring(uartdev, menu1, sizeof(menu1));
uart_write_ring(uartdev, menu2, sizeof(menu2));
uart_write_ring(uartdev, menu3, sizeof(menu3));
uart_write_ring(uartdev, menu4, sizeof(menu4));
uart_write_ring(uartdev, menu5, sizeof(menu5));
}
/***********************************************************************
*
* Function: c_entry
*
* Purpose: UART example code with interrupts
*
* Processing:
* Sends out a 'simulated' menu to UART 2 at 115K-N-8-1. Press the
* 'r' key to display the menu again. Press ESC to end the example.
* Any other key is simply wrapped back around to the terminal.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Always returns 1
*
* Notes: None
*
**********************************************************************/
int c_entry(void)
{
CHAR buffer[10];
INT_32 len, idx;
BOOL_32 exitflag = FALSE;
/* Disable interrupts in ARM core */
disable_irq_fiq();
/* Set virtual address of MMU table (needed for VIC driver
functions) */
cp15_set_vmmu_addr((UNS_32 *) cp15_get_ttb());
/* Initialize interrupt system */
vic_initialize(0xC0000000);
/* Install standard IRQ dispatcher at ARM IRQ vector */
vic_install_arm_handler(IRQ_VEC, (PFV) vic_arm_irq_dispatcher);
/* Install VIC1 and VIC2 handlers */
vic_install_arm_handler(VIC1_IRQ_VEC, (PFV) vic1_irq_dispatcher);
vic_install_arm_handler(VIC2_IRQ_VEC, (PFV) vic2_irq_dispatcher);
/* Install UART handler in the VIC dispatcher */
vic_install_handler(VIC_UART2INTR, VIC_IRQ, (PFV) uart2_isr);
/* Open UART 2 */
if ((uartdev = uart_open(UART2, 0)) == 0x00000000)
{
return 0;
}
/* Set UART 2 to 115.2K-N-8-1 */
uart_ioctl(uartdev, UART_SET_BAUD_RATE, BPS_115200);
uart_ioctl(uartdev, UART_SET_PARITY, UART_PARITY_NONE);
uart_ioctl(uartdev, UART_SET_DATA_BITS, 8);
uart_ioctl(uartdev, UART_SET_STOP_BITS, 1);
/* Enable UART 2 receive and receive timeout interrupts */
uart_ioctl(uartdev, UART_ENABLE_INTS,
(UART_INTR_RI | UART_INTR_RTI));
/* Enable UART interrupt in the interrupt controller */
vic_int_enable(VIC_UART2INTR, TRUE);
/* Enable IRQ interrupts in the ARM core */
enable_irq();
/* Print a menu */
print_menu();
/* Read some data from the buffer */
while (exitflag == FALSE)
{
len = 0;
while (len == 0)
{
len = uart_read_ring(uartdev, buffer, sizeof(buffer));
}
/* Got some data */
idx = 0;
while (idx < len)
{
if (buffer[idx] == 27)
{
/* ESC key, set exit flag */
exitflag = TRUE;
}
else if (buffer[idx] == 'r')
{
print_menu();
}
else
{
/* Echo it back */
uart_write_ring(uartdev, &buffer[idx], 1);
}
idx++;
}
}
/* Close UART */
uart_close(uartdev);
/* Disable UART interrupt in the interrupt controller */
vic_int_enable(VIC_UART2INTR, FALSE);
/* Disable ARM core IRQ interrupts */
disable_fiq();
return 1;
}
#ifndef __GNUC__
/* With ARM and GHS toolsets, the entry point is main() - this will
allow the linker to generate wrapper code to setup stacks, allocate
heap area, and initialize and copy code and data segments. For GNU
toolsets, the entry point is through __start() in the crt0_gnu.asm
file, and that startup code will setup stacks and data */
int main(void)
{
return c_entry();
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -