📄 sysserial.c
字号:
/* sysSerial.c - CSB337 BSP serial device initialization */
/* Copyright 1984-2004 Wind River Systems, Inc. */
/*
modification history
--------------------
01a,14sep04,pdr written
*/
/*
DESCRIPTION
This file contains the board-specific routines for serial channel
initialization.
*/
#include "vxWorks.h"
#include "config.h"
#include "intLib.h"
#include "iv.h"
#include "sysLib.h"
#include "at91Sio.h"
#include "at91Sio.c"
/* defines */
/* device initialisation structure */
typedef struct
{
UINT32 vector;
UINT32 * baseAdrs;
UINT intLevel;
BOOL isUsart;
} AT91_CHAN_PARAMS;
/* Local data structures */
LOCAL AT91_CHAN_PARAMS devParas[] =
{
{0 , (UINT32 *) AT91C_BASE_DBGU, SP_DBGU_ID, FALSE }, /* first is the DBGU unit */
{INT_VEC_SERIAL_1, (UINT32 *) AT91C_BASE_US1 , INT_LVL_SERIAL_1, TRUE } /* the other are USART */
};
LOCAL AT91_SIO_CHAN at91SioChan[N_AT91_USART_CHANNELS];
/*
* Array of pointers to all serial channels configured in system.
* See sioChanGet(). It is this array that maps channel pointers
* to standard device names. The first entry will become "/tyCo/0",
* the second "/tyCo/1", and so forth.
*/
SIO_CHAN * sysSioChans [] =
{
&at91SioChan[0].sio, /* /tyCo/0 */
&at91SioChan[1].sio /* /tyCo/1 */
};
/******************************************************************************
*
* sysSerialHwInit - initialize the BSP serial devices to a quiescent state
*
* This routine initializes the BSP serial device descriptors and puts the
* devices in a quiescent state. It is called from sysHwInit() with
* interrupts locked.
*
* RETURNS: N/A
*
* SEE ALSO: sysHwInit()
*/
void sysSerialHwInit (void)
{
int i;
for (i = 0; i < N_AT91_USART_CHANNELS; i++)
{
at91SioChan[i].regs = devParas[i].baseAdrs;
at91SioChan[i].baudRate = CONSOLE_BAUD_RATE;
at91SioChan[i].xtal = CSB337_MCLK_SPEED;
at91SioChan[i].level = devParas[i].intLevel;
at91SioChan[i].isUsart = devParas[i].isUsart;
/* Set USART to be clocked from MCKI */
if (devParas[i].isUsart)
{
AT91_USART_REG_WRITE (&at91SioChan[i], AT91_US_MR, 0);
}
/*
* Initialise driver functions, getTxChar, putRcvChar and channelMode
* and otherwise initialise UART
*/
at91SioDevInit(&at91SioChan[i]);
}
}
/******************************************************************************
*
* sysSerialHwInit2 - connect BSP serial device interrupts
*
* This routine connects the BSP serial device interrupts. It is called from
* sysHwInit2().
*
* Serial device interrupts cannot be connected in sysSerialHwInit() because
* the kernel memory allocator is not initialized at that point and
* intConnect() calls malloc().
*
* This is where most device driver modules get called and devices are created.
*
* RETURNS: N/A
*
* SEE ALSO: sysHwInit2()
*/
void sysSerialHwInit2 (void)
{
int i;
for (i = 0; i < N_AT91_USART_CHANNELS; i++)
{
/*
* Perform second init stage (safe buffer allocation)
*/
at91SioDevInit2(&at91SioChan[i]);
/*
* We would like to check the return value from this and log a message
* if it failed. However, logLib has not been initialised yet, so we
* cannot log a message, so there's little point in checking it.
*/
/* connect and enable interrupts */
if (devParas[i].isUsart)
{
(void) intConnect (INUM_TO_IVEC(devParas[i].vector), at91SioInt, (int) &at91SioChan[i]);
intEnable (devParas[i].intLevel);
}
else
{
sysPeripheralIntConnect(devParas[i].intLevel, at91SioInt, (int) &at91SioChan[i]);
sysPeripheralIntEnable(devParas[i].intLevel);
}
}
}
/******************************************************************************
*
* sysSerialChanGet - get the SIO_CHAN device associated with a serial channel
*
* This routine returns a pointer to the SIO_CHAN device associated
* with a specified serial channel. It is called by usrRoot() to obtain
* pointers when creating the system serial devices, `/tyCo/x'. It
* is also used by the WDB agent to locate its serial channel.
*
* RETURNS: A pointer to the SIO_CHAN structure for the channel, or ERROR
* if the channel is invalid.
*/
SIO_CHAN * sysSerialChanGet
(
int channel /* serial channel */
)
{
if (channel < 0 || channel >= NELEMENTS(sysSioChans))
{
return (SIO_CHAN *) ERROR;
}
return sysSioChans[channel];
}
/******************************************************************************
*
* sysSerialReset - reset the sio devices to a quiet state
*
* Reset all devices to prevent them from generating interrupts.
*
* This is called from sysToMonitor() to shutdown the system gracefully
* before transferring control to the boot ROM.
*
* RETURNS: N/A.
*/
void sysSerialReset (void)
{
int i;
/* disable interrupts */
for (i = 0; i < N_AT91_USART_CHANNELS; i++)
{
intDisable (devParas[i].intLevel);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -