📄 board.c
字号:
/*****************************************************************************
* Copyright (C) ARM Limited 1998. All rights reserved.
* Copyright (C) Hynix Semiconductor Limited 2002. All rights reserved.
*****************************************************************************/
/*****************************************************************************
*
* This file contains Hynix HMS39C7092 platform specfic C code.
*
*****************************************************************************/
#include "uhal.h"
#include "errno.h"
extern U32 uHALiv_MemorySize;
/* structure definitions */
typedef struct UARTReg
{
#ifdef BIG_ENDIAN
volatile unsigned char _BEpad[3];
#endif
volatile unsigned char rhrthr;
volatile unsigned char _pad0[3];
volatile unsigned char ier;
volatile unsigned char _pad1[3];
volatile unsigned char isrfcr;
volatile unsigned char _pad2[3];
volatile unsigned char lcr;
volatile unsigned char _pad3[3];
volatile unsigned char mcr;
volatile unsigned char _pad4[3];
volatile unsigned char lsr;
volatile unsigned char _pad5[3];
volatile unsigned char msr;
volatile unsigned char _pad6[3];
volatile unsigned char spr;
volatile unsigned char _pad7[3];
volatile unsigned char clkcr;
volatile unsigned char _pad8[3];
volatile unsigned char clkdr;
} UARTReg;
/* Set the LED(s) to given value (or mask), eg GREEN_LED_0 */
unsigned int uHALir_SetLEDs(unsigned int value) {
/* Return the number of LEDs in the system */
return (uHAL_NUM_OF_LEDS) ;
}
/* Set the state of the specified LED, the LED number passed is not
the bit number but the LED number. */
int uHALr_WriteLED(unsigned int number, unsigned int state) {
if(state) {
*(volatile unsigned int *)P7DR |= 0x20;
}
else {
*(volatile unsigned int *)P7DR &=~0x20;
}
return (OK);
}
/*
* PID IRQ register definitions.
*/
/*
* Update the register on the target which masks the irq passed to the PID IC.
* This routine is target-specific. Turn the interrupt source off.
*/
void uHALir_MaskIrq(unsigned int irq) {
*(volatile unsigned int *)(ICBase+IC_IMR)|= (1 << irq);
*(volatile unsigned int *)(ICBase+IC_ISCR) = (1 << irq);
}
/*
* Update the register on the target which masks the irq passed to the PID IC.
* This routine is target-specific. Turn the interrupt source on.
*/
void uHALir_UnmaskIrq(unsigned int irq) {
*(volatile unsigned int *)(ICBase+IC_IMR)&=~(1 << irq) ;
*(volatile unsigned int *)(ICBase+IC_ISCR) = (1 << irq);
}
/*============================================================================
*
* routine: getPlatformId()
*
* parameters: void
*
* description: this routine will return the current platform ID
*
* calls: none
*
* returns: platform ID
*
*/
void uHALr_GetPlatformInfo(pInfoType p) {
uHALr_memset ((char *)p, 0, sizeof(infoType));
p->memType = 0;
p->memSize = uHALiv_MemorySize;
p->cpuId = uHALir_CpuIdRead();
p->platformId = PLATFORM_ID;
return;
}
/*============================================================================
*
* routine: uHALir_PciHost()
*
* parameters: void
*
* description: This routine determines if the target is PCI Host.
*
* calls: none
*
* returns: FALSE if not PCI Host
*
*/
unsigned int uHALr_PciHost(void) {
return (FALSE) ;
}
/* Set up the system's timers */
static void uHALir_PlatformInitTimers(void) {
}
#define TIMERN(x) ((x)*0x20)
/* This routine stops the specified timer hardware. */
void uHALir_PlatformDisableTimer(unsigned int timer) {
int temp;
timer--;
*(volatile unsigned int *)(TIMERBase + TIMER_TSTARTR)&= ~(0x01<<(timer));
temp = *(volatile unsigned int *)(TIMERBase + TIMERN(timer) + TIMER_TSR0);
}
/* This routine starts the specified timer hardware. */
void uHALir_PlatformEnableTimer(unsigned int timer) {
int temp;
struct uHALis_Timer *action ;
extern struct uHALis_Timer uHALiv_TimerStatus[];
action = &uHALiv_TimerStatus[timer] ;
uHALir_PlatformDisableTimer(timer);
timer--;
*(volatile unsigned int *)(TIMERBase + TIMERN(timer) + TIMER_GRA0) = 2062500/action->period;
*(volatile unsigned int *)(TIMERBase + TIMERN(timer) + TIMER_TCR0) = 0xBA ;
*(volatile unsigned int *)(TIMERBase + TIMERN(timer) + TIMER_TIER0) = 0x01 ;
*(volatile unsigned int *)(TIMERBase + TIMER_TSTARTR)|= (0x01<<(timer));
temp = *(volatile unsigned int *)(TIMERBase + TIMERN(timer) + TIMER_TSR0);
}
/*============================================================================
*
* routine: uHALir_PlatformInit()
*
* parameters: void
*
* description: this routine does platform specific system initialization.
*
* calls: none
*
* returns: void
*
*/
void uHALir_PlatformInit(void) {
/* Debug - write to LEDs */
uHALir_SetLEDs(ALL_LEDS) ;
/* Initialize the timers */
uHALir_PlatformInitTimers() ;
/* re-init the com port */
uHALr_ResetPort() ;
/* Thunderbirds are go.. */
/* Initialize HMS39C7092 Interrupt Controller */
*(volatile unsigned int *)(ICBase + IC_IMR) = ~0;
*(volatile unsigned int *)(ICBase + IC_FMR) = ~0;
*(volatile unsigned int *)(ICBase + IC_GMR) = 0xfff00000;
*(volatile unsigned int *)(ICBase + IC_TMR) = 0x000fc000;
*(volatile unsigned int *)(ICBase + IC_TPR) = 0x000fc000;
*(volatile unsigned int *)(ICBase + IC_IDR) = 0;
/* Initialize HMS39C7092 Port 7.5 */
*(volatile unsigned int *)P7DDR &=~0x20;
}
/*
* the Interrupt Enable register is write-only, so we use the
* scratch register to keep track of currently enabled Ints
*/
#define IER_set(u, f) ((u)->ier = ((u)->spr |= (f)))
#define IER_clr(u, f) ((u)->ier = ((u)->spr &= (~(f))))
#define IER_reset(u) ((u)->ier = ((u)->spr = 0));
int UART_InitPort(UARTReg *port, unsigned int baudRate)
{
/*
* Interrupt Enable Register - all interrupts off
*/
IER_reset(port);
/*
* FIFO Control Register - FIFO enabled, but Rx and Tx
* FIFOs empty; RxRDY and TxRDY mode 1; FIFO interrupt
* trigger level = 4.
*/
port->isrfcr = 0x4f;
/*
* Line Control Register is initialised in UART_set_params.
*
* Modem Control Register - DTR* and RTS* outputs high; INT
* pin tri-stated; Rx and Tx "disabled" by setting chip in
* loopback mode.
*/
port->mcr = 0x10;
/*
* wait for current transmits to finish
*/
while ((port->lsr & LSRTxEmpty) == 0)
/* do nothing */
;
/*
* Enable divisor latch via the Line Control Register, and
* set the baud rates
*/
port->clkcr = 0x01;
port->clkdr = 0x02;
port->lcr = 0x80;
port->rhrthr = (unsigned char)(baudRate & 0xff);
port->ier = (unsigned char)((baudRate >> 8) & 0xff);
/*
* OK, set the operational values for the LCR: 8-bit words,
* 1 stop bit, no parity
*/
port->lcr = 0x03;
/*
* take the chip out of loopback, and enable interrupts; DTR* and
* RTS* outputs are forced low.
*/
port->mcr = 0x0b;
return 0;
}
/* Initialise the serial port
* NOTE: HOST_COMPORT and OS_COMPORT must be defined (see platform.[sh])
*
* uHALr_ResetPort() is aliased to be
* uHALir_InitSerial(OS_COMPORT, DEFAULT_OS_BAUD)
*/
void uHALir_InitSerial(unsigned int port, unsigned int baudRate)
{
#ifndef STANDALONE
/* If running under a debugger, don't re-initialise its comport. */
if (HOST_COMPORT != OS_COMPORT)
#endif
{
UART_InitPort((UARTReg *)port, baudRate) ;
}
}
int UART_SSerialGetChar(UARTReg *port) {
/* Wait for a byte */
while((port->lsr & LSRRxData) == 0);
return((int) port->rhrthr);
}
void UART_SSerialPutChar(UARTReg *port, U8 ch) {
/* Wait until FIFO has space */
while((port->lsr & LSRTxHoldEmpty) == 0);
port->rhrthr = ch;
}
/*============================================================================
*
* routine: uHALir_prePlatformInit()
*
* parameters: void
*
* description: this routine does platform specific system initialization.
*
* calls: none
*
* returns: void
*
*/
void uHALir_prePlatformInit(void) {
*(volatile int*)MEMCR|= 0x01;
*(volatile int*)BCR0 = 0x002;
*(volatile int*)P1MR=0x00;
*(volatile int*)P2MR=0x00;
*(volatile int*)P3MR=0x00;
*(volatile int*)P4MR=0x00;
*(volatile int*)P5MR=0x00;
*(volatile int*)P6MR=0x00;
*(volatile int*)P8MR=0x00;
}
int uHALir_ReadCPUIdFromBoard(void)
{
return 0x0f0f0f0f;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -