⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 board.c

📁 ucos下的driver的抽象层, 有了这一层porting将更容易
💻 C
字号:
/*****************************************************************************
 * Copyright (C) ARM Limited 1998. All rights reserved. 
 *****************************************************************************/
/*****************************************************************************
 *
 * This file contains PID platform specfic C code.
 *
 *****************************************************************************/

#include	"uhal.h" 
#include        "errno.h"
#include        "mmu_h.h"

extern U32 uHALiv_MemorySize;

/* structure definitions */
typedef struct ST16C552Reg
{
#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;
} ST16C552Reg;

/* 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) {
	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_IRQEnableClear) = (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_IRQEnableSet) = (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) {
}

/* This routine stops the specified timer hardware. */
void uHALir_PlatformDisableTimer(unsigned int timer) {
  *(volatile unsigned int *)(TIMERBase + TIMER_CONTROL) = 0x0;
}

/* This routine starts the specified timer hardware. */
void uHALir_PlatformEnableTimer(unsigned int timer) {
  struct uHALis_Timer *action ;
  extern struct uHALis_Timer uHALiv_TimerStatus[];
  action = &uHALiv_TimerStatus[timer] ;
  uHALir_PlatformDisableTimer(timer);
  *(volatile unsigned int *)(TIMERBase + TIMER_LOAD) = action->period;
  *(volatile unsigned int *)(TIMERBase + TIMER_CONTROL) = 0xC4 ;
}

/*============================================================================
 *
 *  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) ;

#ifdef STANDALONE
	/* Turn on MMU & caches by default */
	uHALr_InitMMU(EnableMMU | IC_ON | DC_ON ) ;
#endif
	/* Initialize the timers */
	uHALir_PlatformInitTimers() ;

	/* re-init the com port */
	uHALr_ResetPort() ;

	/* Thunderbirds are go.. */
}

/*
 * 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 st16c552_InitPort(ST16C552Reg *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 st16c552_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->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
      {
	st16c552_InitPort((ST16C552Reg *)port, baudRate) ;
      }
}

int st16c552_SSerialGetChar(ST16C552Reg *port) {
   /* Wait for a byte */
   while((port->lsr & LSRRxData) == 0);

   return((int) port->rhrthr);
}

void st16c552_SSerialPutChar(ST16C552Reg *port, U8 ch) {
   /* Wait until FIFO has space */
   while((port->lsr & LSRTxHoldEmpty) == 0);

   port->rhrthr = ch;
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -