uart.c
上传用户:fy98168
上传日期:2015-06-26
资源大小:13771k
文件大小:5k
- #ifdef REPORT_TO_CONSOLE
- #include <stdio.h>
- #endif
- #include <string.h>
- #include "stdevice.h"
- #include "stsys.h"
- #include "stpio.h"
- #include "stuart.h"
- #include "stcommon.h"
- #include "gendef.h"
- #include "section.h"
- #include "uart.h"
- #include "pio.h"
- #define UART_END_OF_LIST 0xff
- static U8 InitList[] = { KB_UART_DATA_DEV, KB_UART_SC0_DEV, UART_END_OF_LIST };
- ST_DeviceName_t UART_DeviceName[] = {"UART0","UART1"};
- STUART_Handle_t UART_Handle[KB_UART_DEVICES];
- ST_ClockInfo_t ST_ClockInfo;
- extern ST_DeviceName_t PIO_DeviceName[];
- static ST_ErrorCode_t uart_init(int Instance);
- static ST_ErrorCode_t uart_init(int Instance)
- {
- ST_ErrorCode_t ST_ErrorCode = ST_NO_ERROR;
- STUART_InitParams_t STUART_InitParams;
- STUART_Params_t STUART_Params;
- /* Common Init Parameters */
- (void) ST_GetClockInfo(&ST_ClockInfo);
- STUART_InitParams.DriverPartition = SystemPartition;
- STUART_InitParams.ClockFrequency = ST_ClockInfo.CommsBlock;
- STUART_InitParams.SwFIFOEnable = TRUE;
- STUART_InitParams.FIFOLength = 256;
- STUART_InitParams.RXD.PortName[0] = ' ';
- STUART_InitParams.TXD.PortName[0] = ' ';
- STUART_InitParams.RTS.PortName[0] = ' ';
- STUART_InitParams.CTS.PortName[0] = ' ';
- #ifdef REPORT_TO_CONSOLE
- Print("STUART_Setup(%s/", UART_DeviceName[Instance] );
- #endif
- switch(Instance)
- {
- case KB_UART_DATA_DEV:
- #ifdef REPORT_TO_CONSOLE
- Print("KB_UART_DATA_DEV)=");
- #endif
- /* set default values */
- STUART_Params.RxMode.BaudRate = 115200;
- STUART_Params.RxMode.DataBits = STUART_8BITS_NO_PARITY;
- STUART_Params.RxMode.StopBits = STUART_STOP_1_0;
- STUART_Params.RxMode.FlowControl = STUART_NO_FLOW_CONTROL;
- STUART_Params.RxMode.TermString = NULL;
- STUART_Params.RxMode.TimeOut = 1; /* As short as possible */
- STUART_Params.RxMode.NotifyFunction = NULL; /* No callback */
- STUART_Params.TxMode.BaudRate = 115200;
- STUART_Params.TxMode.DataBits = STUART_8BITS_NO_PARITY;
- STUART_Params.TxMode.StopBits = STUART_STOP_1_0;
- STUART_Params.TxMode.FlowControl = STUART_NO_FLOW_CONTROL;
- STUART_Params.TxMode.TermString = NULL;
- STUART_Params.TxMode.TimeOut = 0; /* No time-out */
- STUART_Params.TxMode.NotifyFunction = NULL; /* No callback */
- STUART_Params.SmartCardModeEnabled = FALSE;
- STUART_Params.GuardTime = 0;
- STUART_Params.NACKSignalDisabled = FALSE;
- STUART_Params.HWFifoDisabled = FALSE;
- /* Initialize DATA Uart */
- STUART_InitParams.UARTType = KB_UART_ASC_DEVICE_TYPE;
- STUART_InitParams.DefaultParams = &STUART_Params;
- STUART_InitParams.BaseAddress = (U32 *)KB_UART_DATA_BASE_ADDRESS;
- STUART_InitParams.InterruptNumber = KB_UART_DATA_INTERRUPT;
- STUART_InitParams.InterruptLevel = KB_UART_DATA_INTERRUPT_LEVEL;
- STUART_InitParams.RXD.BitMask = KB_UART_DATA_RXD_BIT;
- STUART_InitParams.TXD.BitMask = KB_UART_DATA_TXD_BIT;
- strcpy(STUART_InitParams.RXD.PortName, PIO_DeviceName[KB_UART_DATA_RXD_DEV]);
- strcpy(STUART_InitParams.TXD.PortName, PIO_DeviceName[KB_UART_DATA_TXD_DEV]);
- STUART_InitParams.RTS.BitMask = 0;
- STUART_InitParams.CTS.BitMask = 0;
- strcpy(STUART_InitParams.RTS.PortName, "");
- strcpy(STUART_InitParams.CTS.PortName, "");
- break;
- case KB_UART_SC0_DEV: /* Initialize SMARTCARD0 Uart*/
- #ifdef REPORT_TO_CONSOLE
- Print("KB_UART_SC0_DEV)=");
- #endif
- STUART_InitParams.UARTType = STUART_ISO7816;
- STUART_InitParams.DefaultParams = NULL;
- STUART_InitParams.BaseAddress = (U32 *)KB_UART_SC0_BASE_ADDRESS;
- STUART_InitParams.InterruptNumber = KB_UART_SC0_INTERRUPT;
- STUART_InitParams.InterruptLevel = KB_UART_SC0_INTERRUPT_LEVEL;
- /* Smart card IO is only one pio, so TX and RX is same */
- STUART_InitParams.RXD.BitMask = KB_UART_SC0_TXD_BIT;
- STUART_InitParams.TXD.BitMask = KB_UART_SC0_TXD_BIT;
- strcpy(STUART_InitParams.RXD.PortName, PIO_DeviceName[KB_UART_SC0_TXD_DEV]);
- strcpy(STUART_InitParams.TXD.PortName, PIO_DeviceName[KB_UART_SC0_TXD_DEV]);
- STUART_InitParams.RTS.BitMask = 0;
- STUART_InitParams.RTS.PortName[0] = 0;
- STUART_InitParams.CTS.BitMask = 0;
- STUART_InitParams.CTS.PortName[0] = 0;
- break;
- default:
- break;
- }
- ST_ErrorCode = STUART_Init(UART_DeviceName[Instance], &STUART_InitParams);
- #ifdef REPORT_TO_CONSOLE
- if (ST_ErrorCode != ST_NO_ERROR)
- Print("STUART_Init Errorn");
- else
- Print("%sn", STUART_GetRevision() );
- #endif
- return (ST_ErrorCode);
- }
- ST_ErrorCode_t KB_UartSetup(void)
- {
- ST_ErrorCode_t ST_ErrorCode = ST_NO_ERROR;
- U8 Index;
- for ( Index = 0; InitList[Index] != UART_END_OF_LIST; Index++ )
- {
- ST_ErrorCode |= uart_init(InitList[Index]);
- }
-
- return ( ST_ErrorCode );
- }
- /* EOF */