📄 lh7a400_evb_cpld_driver.c
字号:
/**********************************************************************
* $Workfile: LH7A400_EVB_CPLD_driver.c $
* $Revision: 1.18 $
* $Author: MaysR $
* $Date: Aug 20 2002 10:09:42 $
*
* Project: LH7A400
*
* Description:
* LH7A400 EVB CPLD device driver
*
* See LH7A400 EVB CPLD description document for definition of
* the CPLD registers
*
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/CHIPS/archives/LH7A400/CPLD/Drivers/LH7A400_EVB_CPLD_driver.c-arc $
*
* Rev 1.18 Aug 20 2002 10:09:42 MaysR
* Added parameter to init functions to allow soft init.
*
* Rev 1.17 Aug 14 2002 18:45:04 MaysR
* Changed function names for LCD control functions to correctly
* reflect what the functions do.
*
* Cosmetic changes to meet coding standard.
*
* Rev 1.16 Aug 09 2002 11:02:02 MaysR
* Updated interrupt installer to include call to SMA_core_irq().
*
* Rev 1.15 Jul 09 2002 16:32:08 MaysR
* Corrected errors in parameter usage for arguments
* passed to interrupt handler functions.
* Corrected error in external interrupt clear function.
* Added new typedef for push button interrupts.
* Changed case of typdefs to comply with coding standard
*
* Rev 1.14 Jun 20 2002 14:00:28 MaysR
* Removed commented code from file.
*
* Rev 1.13 Jun 20 2002 13:26:44 MaysR
* Changed all function names to comply with coding standard
*
* Rev 1.12 Jun 19 2002 17:07:52 BarnettH
* Changed INTC_GPIO1INTR to INTC_GPIO1INTR_BIT
*
* Rev 1.11 Jun 13 2002 16:31:16 MaysR
* Added Sharp legal disclaimer
*
* Rev 1.10 Jun 13 2002 15:45:02 MaysR
* Changed defined name for interrupt number.
*
* Rev 1.9 Jun 10 2002 10:22:58 MaysR
* Corrected logic error in null handler function.
*
* Rev 1.8 Jun 06 2002 14:03:06 MaysR
* Removed compiler warning generated by dispatcher code.
*
* Rev 1.7 Jun 05 2002 20:28:14 MaysR
* Added interrupt handler for all CPLD interrupt sources, using
* priority handler.
*
* Enhanced pld_init function to initiallize all devices.
*
* Added pld_setup to initialize and install irq handler.
*
* Rev 1.6 Jan 09 2002 09:38:16 KovitzP
* Moved local defines to LH7A400_evb.h
*
* Rev 1.5 Dec 03 2001 11:13:36 MaysR
* Corrected logic for usage of 26.8V supply settiing. Missed this
* during last change.
*
* Rev 1.4 Dec 03 2001 10:41:00 MaysR
* Corrected logic problem for 26.8V supply on/off state.
*
* Rev 1.3 Nov 30 2001 10:00:10 WellsK
* Corrected pld_get_pb function.
*
* Rev 1.2 Nov 20 2001 18:56:08 SuryanG
* Added function headers and description.
* Added 22 new interface functions.
* Added two new exported type definitions.
* Moved to CPLD directory.
*
* Rev 1.1 Nov 08 2001 18:14:58 SuryanG
* No code change. Added file banner.
*
* Rev 1.0 Nov 07 2001 19:00:24 SuryanG
* Initial revision.
*
* SHARP MICROELECTRONICS OF THE AMERICAS MAKES NO REPRESENTATION
* OR WARRANTIES WITH RESPECT TO THE PERFORMANCE OF THIS SOFTWARE,
* AND SPECIFICALLY DISCLAIMS ANY RESPONSIBILITY FOR ANY DAMAGES,
* SPECIAL OR CONSEQUENTIAL, CONNECTED WITH THE USE OF THIS SOFTWARE.
*
* SHARP MICROELECTRONICS OF THE AMERICAS PROVIDES THIS SOFTWARE SOLELY
* FOR THE PURPOSE OF SOFTWARE DEVELOPMENT INCORPORATING THE USE OF A
* SHARP MICROCONTROLLER OR SYSTEM-ON-CHIP PRODUCT. USE OF THIS SOURCE
* FILE IMPLIES ACCEPTANCE OF THESE CONDITIONS.
*
* COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
* CAMAS, WA
*********************************************************************/
#include "LH7A400_evb.h"
#include "LH7A400_EVB_CPLD_driver.h"
#include "LH7A400_int_driver.h"
#include "LH7A400_gpio_driver.h"
#include "SMA_priority_driver.h"
#include "SMA_coreutils.h"
static void (*handlers[CPLD_INT_NSOURCES + 1])(void);
static void LH7A400_pld_null_handler(void);
static void LH7A400_pld_irq_dispatcher(void);
static INT_8 priorities[CPLD_INT_NSOURCES + 1];
static INT_8 priority_encode0[_BIT(8)];
static INT_8 priority_encode1[_BIT(CPLD_INT_NSOURCES - 8)];
static UNS_16 cpld_int_status;
static PRIORITY_DATA CPLD_prio =
{
CPLD_INT_NSOURCES,
priorities,
priority_encode0,
priority_encode1,
0,
0,
handlers
};
static UNS_8 initialized = 0;
static UNS_8 int_init = 0;
static UNS_8 ext_int_mask;
static UNS_8 pb_int_mask;
static UNS_8 io_brd_ctl;
/**********************************************************************
* Function: LH7A400_pld_init
*
* Purpose:
* initialize the LH7A400 CPLD, including the SMC to access
* the CPLD, and all devices controlled by the CPLD.
*
* Processing:
* initialize static memory controller bank 2 configuration
* register to access 16-bit wide memory, highest wait-state
* setting. Disable all interrupts and initialize shadow mask
* registers. Initialize the I/O power control devices.
*
* Parameters: None
*
* Outputs: None
*
* Returns: Nothing
**********************************************************************/
void LH7A400_pld_init(INIT_MODE_T force)
{
if (!(initialized) || force)
{
SMC->bcr2 = SMC_BCR2_INIT;
ext_int_mask = 0;
CPLD->extsettings.wr_ext_int_mask = ext_int_mask;
pb_int_mask = 0;
CPLD->status.intmask.wr_pb_int_mask = pb_int_mask;
cpld_int_status = 0;
io_brd_ctl = 0;
LH7A400_pld_mmc_disable_pwr();
LH7A400_pld_eth_sleep();
LH7A400_pld_i2s_disable_pwr();
LH7A400_pld_ac97_disable_pwr();
LH7A400_pld_pc_card_pwr_disable(1);
LH7A400_pld_pc_card_pwr_disable(2);
initialized = 1;
}
}
/**********************************************************************
*
* Function: LH7A400_pld_irq_setup
*
* Purpose:
* Install the dispatcher for the CPLD interrupt request.
*
* Processing:
* Initialize the CPLD_prio structure,
* configure the GPIO pin for interrupt mode,
* install the CPLD interrupt handler into the system dispatcher.
*
* Parameters:
* priority: the priority of the CPLD interrupt.
*
* Outputs: nothing
*
* Returns: results from installer (see LH7A400_int_driver.c)
*
* Notes: Initializes the CPLD input interrupt handler before installing
* the CPLD interrupt into the dispatcher.
*
**********************************************************************/
INT_8 LH7A400_pld_irq_setup(INT_8 priority, INIT_MODE_T force)
{
CORE_INT_STATE irq_state;
INT_8 ret;
if (!(int_init) || force)
{
irq_state = SMA_core_irq(DISABLE_INT);
int_init_irq_handler(0);
priority_init_driver(&CPLD_prio, LH7A400_pld_null_handler);
gpio_port_f_bit_is_interrupt(LH7A400_EVB_CPLD_INT);
gpio_interrupt_edge_triggered(LH7A400_EVB_CPLD_INT);
gpio_interrupt_active_low(LH7A400_EVB_CPLD_INT);
gpio_interrupt_debounce_enable(LH7A400_EVB_CPLD_INT);
ret = int_install_irq_handler(INTC_GPIO1INTR_BIT,
priority,
LH7A400_pld_irq_dispatcher);
int_enable_interrupt(INTC_GPIO1INTR_BIT);
SMA_core_irq(irq_state);
int_init = 1;
return ret;
}
return priority;
}
/**********************************************************************
*
* Function: LH7A400_pld_install_int_handler
*
* Purpose:
* Install an interrupt handler function that will be called by the
* INT2 handler function
*
* Processing:
* Use priority_driver functions
*
* Parameters:
* source: The interrupt source can be one of:
*
* CPLD_ETH_INT_PRIO
* CPLD_CF_IDE_INT_PRIO
* CPLD_MMC_CD_INT_PRIO
* CPLD_RI2_INT_PRIO
* CPLD_SW3_INT_PRIO
* CPLD_PB_SW10_PRIO
* CPLD_PB_SW11_PRIO
* CPLD_PB_SW12_PRIO
* CPLD_PB_SW13_PRIO
* CPLD_PB_SW14_PRIO
* CPLD_PB_SW15_PRIO
* CPLD_PB_SW16_PRIO
* CPLD_PB_SW17_PRIO
*
* priority: The priority number for the source.
* 0 <= priority < CPLD_INT_NSOURCES
* hp: A pointer to the handler function.
*
* Outputs: Arrays in the prio structure set up for the handler
*
* Returns:
* priority if successful, CPLD_INT_NSOURCES if not.
*
* Notes: None
*
**********************************************************************/
INT_8 LH7A400_pld_install_int_handler(INT_8 source,
INT_8 priority,
void (*hp)(void))
{
return priority_install_handler(&CPLD_prio,
source,
priority,
hp,
LH7A400_pld_null_handler);
}
/**********************************************************************
*
* Function: LH7A400_pld_remove_int_handler
*
* Purpose:
* Install an interrupt handler function that will be called by the
* INT2 handler function
*
* Processing:
* Use priority_driver functions
*
* Parameters:
* Source number of handler to remove
*
* Outputs: None
*
* Returns:
* priority if successful, CPLD_INT_NSOURCES if not.
*
* Notes: None
*
**********************************************************************/
INT_8 LH7A400_pld_remove_int_handler(INT_8 source)
{
return priority_remove_handler(&CPLD_prio,
priority_get_priority(&CPLD_prio,
source),
LH7A400_pld_null_handler);
}
/**********************************************************************
*
* Function: LH7A400_pld_null_handler
*
* Purpose:
* Disable the interrupt source if it is unhandled.
*
* Processing:
* This function is called by the CPLD interrupt handler if the
* CPLD function has an active, unmasked, unhandled interrupt. It
* disables the unhandled interrupt.
*
* Parameters: none
*
* Outputs: nothing
*
* Returns: nothing
*
* Notes: Button presses are not latched. If they are not handled in
* time, we could get here with cpld_int_status == 0. If so, just
* clear the processor interrupt and return.
*
**********************************************************************/
static void LH7A400_pld_null_handler(void)
{
if (cpld_int_status & CPLD_MMC_CD_INT_BIT)
LH7A400_pld_disable_ext_int(NMMC_CD);
if (cpld_int_status & CPLD_RI2_INT_BIT)
LH7A400_pld_disable_ext_int(NRI2);
if (cpld_int_status & CPLD_CF_IDE_INT_BIT)
LH7A400_pld_disable_ext_int(IDE_CF);
if (cpld_int_status & CPLD_ETH_INT_BIT)
LH7A400_pld_disable_ext_int(ETH_INT);
if (cpld_int_status & CPLD_SW3_INT_BIT)
LH7A400_pld_disable_ext_int(SW3_INT);
if (cpld_int_status & (CPLD_PB_SW10_INT_BIT))
LH7A400_pld_disable_pb_int(PB_SW10);
if (cpld_int_status & CPLD_PB_SW11_INT_BIT)
LH7A400_pld_disable_pb_int(PB_SW11);
if (cpld_int_status & CPLD_PB_SW12_INT_BIT)
LH7A400_pld_disable_pb_int(PB_SW12);
if (cpld_int_status & CPLD_PB_SW13_INT_BIT)
LH7A400_pld_disable_pb_int(PB_SW13);
if (cpld_int_status & CPLD_PB_SW14_INT_BIT)
LH7A400_pld_disable_pb_int(PB_SW14);
if (cpld_int_status & CPLD_PB_SW15_INT_BIT)
LH7A400_pld_disable_pb_int(PB_SW15);
if (cpld_int_status & CPLD_PB_SW16_INT_BIT)
LH7A400_pld_disable_pb_int(PB_SW16);
if (cpld_int_status & CPLD_PB_SW17_INT_BIT)
LH7A400_pld_disable_pb_int(PB_SW17);
if (cpld_int_status == 0)
gpio_interrupt_clear(LH7A400_EVB_CPLD_INT);
}
/***********************************************************************
*
* Function: LH7A400_pld_irq_dispatcher
*
* Purpose:
* When the CPLD asserts its interrupt line, parse the masked status
* bits from the misc_stat register and branch to the handler for the
* highest priority source that is asserting the interrupt line.
*
* Processing:
* See the priority driver.
*
* Parameters: none
*
* Outputs: nothing
*
* Returns: nothing
*
* Notes: None
*
**********************************************************************/
static void LH7A400_pld_irq_dispatcher(void)
{
MAKE_DISPATCHER16((cpld_int_status = (UNS_16)
((CPLD->rd_pb_keys & pb_int_mask) |
((CPLD->latched_ints & ext_int_mask) << 8))),
handlers,
priority_encode)
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -