edb7xxx_misc.c

来自「eCos操作系统源码」· C语言 代码 · 共 581 行 · 第 1/2 页

C
581
字号
    KBDEOI, // CYGNUM_HAL_INTERRUPT_KBDINT     17    0,      // CYGNUM_HAL_INTERRUPT_SS2RX      18    0,      // CYGNUM_HAL_INTERRUPT_SS2TX      19    0,      // CYGNUM_HAL_INTERRUPT_UTXINT2    20    0,      // CYGNUM_HAL_INTERRUPT_URXINT2    21#if defined(__EDB7211)    0,      // CYGNUM_HAL_INTERRUPT_MCPINT     22#endif#if defined(__EDB7209)    0,      // CYGNUM_HAL_INTERRUPT_I2SINT     22#endif#if defined(__EDB7312)    0,      // CYGNUM_HAL_INTERRUPT_DAIINT     22#endif};static struct regmap {    int        first_int, last_int;    cyg_uint32 stat_reg, mask_reg;} hal_interrupt_status_regmap[] = {    { CYGNUM_HAL_INTERRUPT_EXTFIQ, CYGNUM_HAL_INTERRUPT_MCINT,   INTSR1, INTMR1},#if defined(__EDB7211)    { CYGNUM_HAL_INTERRUPT_MCPINT, CYGNUM_HAL_INTERRUPT_MCPINT,  INTSR3, INTMR3},#endif#if defined(__EDB7209)    { CYGNUM_HAL_INTERRUPT_I2SINT, CYGNUM_HAL_INTERRUPT_I2SINT,  INTSR3, INTMR3},#endif#if defined(__EDB7312)    { CYGNUM_HAL_INTERRUPT_DAIINT, CYGNUM_HAL_INTERRUPT_DAIINT,  INTSR3, INTMR3},#endif    { CYGNUM_HAL_INTERRUPT_CSINT,  CYGNUM_HAL_INTERRUPT_SSEOTI,  INTSR1, INTMR1},    { CYGNUM_HAL_INTERRUPT_KBDINT, CYGNUM_HAL_INTERRUPT_URXINT2, INTSR2, INTMR2},    { 0, 0, 0, 0 }};#ifdef CYGHWR_HAL_ARM_EDB7XXX_BATLOW// This ISR is called when the battery low interrupt occursint cyg_hal_batlow_isr(cyg_vector_t vector, cyg_addrword_t data, HAL_SavedRegisters *regs){    diag_printf("Battery low\n");    cyg_drv_interrupt_mask(CYGNUM_HAL_INTERRUPT_BLINT);    // Presumably, one would leave this masked until the battery changed    cyg_drv_interrupt_acknowledge(CYGNUM_HAL_INTERRUPT_BLINT);    return 0;  // No need to run DSR}#endif//// Early stage hardware initialization//   Some initialization has already been done before we get here.  For now// just set up the interrupt environment.void hal_hardware_init(void){    volatile cyg_uint32 *icr;    int vector;        // Clear and initialize instruction cache    HAL_ICACHE_INVALIDATE_ALL();    HAL_ICACHE_ENABLE();    // Any hardware/platform initialization that needs to be done.    *(volatile cyg_uint32 *)INTMR1 = 0;    *(volatile cyg_uint32 *)INTMR2 = 0;#if !defined(__CL7111)    *(volatile cyg_uint32 *)INTMR3 = 0;#endif#if !defined(__CL7111) && !defined(__EDB7312)    *(volatile cyg_uint8 *)SYSCON3 = SYSCON3_CLKCTL(CPU_CLOCK);#endif#if 0    diag_printf("IMR1: %04x, IMR2: %04x\n",                *(volatile cyg_uint32 *)INTMR1,                *(volatile cyg_uint32 *)INTMR2);    diag_printf("Memcfg1: %08x, Memcfg2: %08x, DRAM refresh: %08x\n",                 *(volatile cyg_uint32 *)MEMCFG1,                *(volatile cyg_uint32 *)MEMCFG2,                *(volatile cyg_uint8 *)DRFPR);#endif#define MEMCFG_BUS_WIDTH(n)   (n<<0)#define MEMCFG_BUS_WIDTH_32   (0<<0)#define MEMCFG_BUS_WIDTH_16   (1<<0)#define MEMCFG_BUS_WIDTH_8    (2<<0)#define MEMCFG_WAIT_STATES(n) (n<<2)     // 0 is max, 15 min#define MEMCFG_SQAEN          (1<<6)#define MEMCFG_CLKENB         (1<<7)// These need to be checked/improved#define CS0_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(3) | MEMCFG_SQAEN#define CS1_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(4)#define CS2_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(0)#define CS3_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(0)#define CS4_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(0)#define CS5_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(0)#define CS6_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(0)#define CS7_CONFIG MEMCFG_BUS_WIDTH_32 | MEMCFG_WAIT_STATES(0)#if defined(__EDB7209)    *(volatile cyg_uint32 *)MEMCFG1 =         (CS0_CONFIG << 0) |       // FLASH rom        (CS1_CONFIG << 8) |       // NAND flash        (CS2_CONFIG << 16) |      // Ethernet        (CS3_CONFIG << 24);       // Parallel printer, keyboard, touch panel    *(volatile cyg_uint32 *)MEMCFG2 =         (CS4_CONFIG << 0) |       // USB        (CS5_CONFIG << 8) |       // Expansion        (CS6_CONFIG << 16) |      // Local SRAM        (CS7_CONFIG << 24);       // Boot ROM    // This value came from Cirrus, but doesn't match the recommendations above?    *(volatile cyg_uint32 *)MEMCFG1 = 0x3C001814;    // Set up GPIO lines    *(volatile cyg_uint8 *)PADDR   = 0x00;  // Keyboard data 0-7 input    *(volatile cyg_uint8 *)PBDDR   = 0xFA;  // 0 - I/O on J22                                            // 1 - RTS on UART1                                            // 2 - Ring on UART1                                            // 3 - SSI header, Pin 13                                            // 4 - NAND Command Latch Enable                                            // 5 - NAND Address Latch Enable                                            // 6 - On-board NAND Select (active low)                                            // 7 - SmartMedia Card Enable (active low)    *(volatile cyg_uint8 *)PBDR    = 0xC0;  // Everything off    *(volatile cyg_uint8 *)PDDDR   = 0x40;  // 0 - Diagnostic LED control                                            // 1 - Enable DC-DC converter for LCD                                            // 2 - Enable LCD                                            // 3 - ENable LCD Backlight                                            // 4 - CS4342 I2C Data                                            // 5 - CS4342 I2C Clock                                            // 6 - SmartMedia Presence indicator                                            // 7 - I/O on J22    *(volatile cyg_uint8 *)PDDR    = 0x00;  // Everything off    *(volatile cyg_uint8 *)PEDDR   = 0x05;  // 0 - Codec or ADC/DAC                                            // 1 - I/O on JP38 (0 when inserted)                                            // 2 - Enable touch panel    *(volatile cyg_uint8 *)PEDR    = 0x01;  // Enable audio (not CODEC)    // Initialize system control    *(volatile cyg_uint32 *)SYSCON2 = SYSCON2_KBWEN;#endif#if defined(__EDB7312)    *(volatile cyg_uint32 *)MEMCFG1 = 0x1F101710;    *(volatile cyg_uint32 *)MEMCFG2 = 0x00001F93;    // Set up GPIO lines    *(volatile cyg_uint8 *)PADDR   = 0x00;  // Keyboard data 0-7 input    *(volatile cyg_uint8 *)PBDDR   = 0xF2;    *(volatile cyg_uint8 *)PDDDR   = 0x2F;    *(volatile cyg_uint8 *)PDDDR   = 0x10;  // Directions are inverted!    *(volatile cyg_uint8 *)PDDR    = 0x00;  // Everything off    *(volatile cyg_uint8 *)PEDDR   = 0x01;    // Initialize system control    *(volatile cyg_uint32 *)SYSCON1 = 0x00040100;    *(volatile cyg_uint32 *)SYSCON2 = 0x00000102;#ifdef CPU_CLOCK_90MHZ    // We must slow down the RAM timings compared to default by adding    // wait states or it does not work.    // Slow them all down to Random=5, Seq=3 waitstates by replacing    // that field throughout the default value copied from above:    *(volatile cyg_uint32 *)MEMCFG1 = (0x1F101710 & ~0x3c3c3c3c) | 0x0c0c0c0c;    *(volatile cyg_uint32 *)MEMCFG2 = (0x00001F93 & ~0x00003c3c) | 0x00000c0c;#endif // CPU_CLOCK_90MHZ    *(volatile cyg_uint32 *)SYSCON3 = 0x00000208 | SYSCON3_CLKCTL(CPU_CLOCK);#ifdef CPU_CLOCK_90MHZ    // Let the clock change settle before hitting the PLL multiplier    // register to change up by a further 22.5%    asm volatile( "nop;nop;nop;nop;nop;nop;nop;nop;");    *(volatile cyg_uint32 *)EP7312_PLL_MR = EP7312_PLL_MR_FOR_90MHz;    asm volatile( "nop;nop;nop;nop;nop;nop;nop;nop;");#endif // CPU_CLOCK_90MHZ#endif    // Reset all interrupt masks (disable all interrupt sources)    for (vector = CYGNUM_HAL_ISR_MIN;  vector < CYGNUM_HAL_ISR_COUNT;  vector++) {        icr = (volatile cyg_uint32 *)hal_interrupt_clear_map[vector];        if (icr) *icr = 0;  // Just a write clears the latch    }#ifndef __EDB7312    // Turn on the DIAG LED to let the world know the board is alive    *(volatile unsigned char *)LEDFLSH = LEDFLSH_ENABLE|LEDFLSH_DUTY(16)|LEDFLSH_PERIOD(1);#endif#ifdef CYGHWR_HAL_ARM_EDB7XXX_BATLOW    cyg_drv_interrupt_create(CYGNUM_HAL_INTERRUPT_BLINT,                             99,                     // Priority - what goes here?                             0,                      //  Data item passed to interrupt handler                             cyg_hal_batlow_isr,                             0,                             &batlow_interrupt_handle,                             &batlow_interrupt);    cyg_drv_interrupt_attach(batlow_interrupt_handle);    cyg_drv_interrupt_unmask(CYGNUM_HAL_INTERRUPT_BLINT);#endif    // Initialize real-time clock (for delays, etc, even if kernel doesn't use it)    hal_clock_initialize(CYGNUM_HAL_RTC_PERIOD);    // Set up eCos/ROM interfaces    hal_if_init();#ifdef CYGSEM_EDB7XXX_LCD_COMM    // Initialize I/O channel    lcd_comm_init();#endif}//// This routine is called to respond to a hardware interrupt (IRQ).  It// should interrogate the hardware and return the IRQ vector number.// This code is a little convoluted to keep it general while still avoiding// reading the hardware a lot, since the interrupt status is split across// three separate registers.int hal_spurious_ints;int hal_IRQ_handler(void){    struct regmap *map = hal_interrupt_status_regmap;    cyg_uint32 stat;    int vector;    while (map->first_int) {        stat = *(volatile cyg_uint32 *)map->stat_reg & *(volatile cyg_uint32 *)map->mask_reg;        for (vector = map->first_int;  vector <= map->last_int;  vector++) {            if (stat & hal_interrupt_bitmap[vector]) return vector;        }        map++;  // Next interrupt status register    }    hal_spurious_ints++;    return CYGNUM_HAL_INTERRUPT_NONE; // This shouldn't happen!}//// Interrupt control//void hal_interrupt_mask(int vector){    volatile cyg_uint32 *imr;    imr = (volatile cyg_uint32 *)hal_interrupt_mask_regmap[vector];    *imr &= ~hal_interrupt_bitmap[vector];}void hal_interrupt_unmask(int vector){    volatile cyg_uint32 *imr;    imr = (volatile cyg_uint32 *)hal_interrupt_mask_regmap[vector];    *imr |= hal_interrupt_bitmap[vector];}void hal_interrupt_acknowledge(int vector){    // Some interrupt sources have a register for this.    volatile cyg_uint8 *icr;    icr = (volatile cyg_uint8 *)hal_interrupt_clear_map[vector];    if (icr) {        *icr = 0;  // Any data clears interrupt    }}void hal_interrupt_configure(int vector, int level, int up){    // No interrupts are configurable on this hardware}void hal_interrupt_set_level(int vector, int level){    // No interrupts are configurable on this hardware}#define _CYGHWR_LAYOUT_ONLY#include <cyg/hal/hal_platform_setup.h>unsigned long_edb7xxx_physical_address(unsigned long addr){    unsigned long res;    if (addr < DRAM_LA_END) {        res = addr + DRAM_PA;    } else {        res = addr | 0xC0000000;    }    return res;}/*------------------------------------------------------------------------*/// EOF hal_misc.c

⌨️ 快捷键说明

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