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

📄 lh7a400_evbutil.c

📁 sharp的arm920t 7A400的评估板附带光盘Sharp KEVLH7A400 v0.3b Welcome to the SHARP KEV7A400 Evaluation board
💻 C
字号:
/**********************************************************************
 * $Workfile:   LH7A400_evbutil.c  $
 * $Revision:   1.0  $
 * $Author:   WellsK  $
 * $Date:   Sep 23 2002 13:52:02  $
 *
 * Project: ARM Processor Specific Modules - LH7A400
 *
 * Description:
 *    ARM LH7A400 EVB utility routines
 *
 * Local Includes:
 *      #include "LH7A400_evb.h"
 *      #include "LH7A400_evbutil.h"
 *
 * Revision History:
 * $Log:   //smaicnt2/pvcs/VM/CDROM/archives/KEV7A400/Software/Startup_lite/LH7A400_evbutil.c-arc  $
 * 
 *    Rev 1.0   Sep 23 2002 13:52:02   WellsK
 * Initial revision.
 * 
 *    Rev 1.0   Sep 14 2002 11:38:06   WellsK
 * Initial revision.
 * 
 *    Rev 1.12   Aug 20 2002 16:07:32   BarnettH
 * Changed delay_timer to only use available timer, and to return error
 * if all timers are in use.
 * 
 *    Rev 1.11   Jun 20 2002 11:52:36   MaysR
 * Moved functions "LH7A400_clk_set" and "LH7A400_get_hclk"
 * to the clock and state controller driver (LH7A400_CSC_driver.*)
 * 
 *    Rev 1.10   Jun 13 2002 19:12:10   BarnettH
 * Eliminated all CLKIDX references; added LH7A400_clkset_default global.  Changed to single CLKSET_XXX_XXX_XXX reference to eliminate necessity of coherency among clockset codes and across assembly and C language files.
 * Cleaned up formatting, banners, and comments.
 * 
 *    Rev 1.9   Jun 05 2002 11:27:44   MaysR
 * Added 3 additional clock indexes:
 * 175/87/22, 184/92/23, 190/96/24.
 * 
 *    Rev 1.8   Jun 05 2002 10:56:06   BarnettH
 * Changed name of toggle_led to LH7A400_evb_toggle_led
 * Changed name of set_led to LH7A400_evb_set_led, and revised associated LED's.
 * Changed name of LH7A400_init_iocon to LH7A400_init_muxdpins.
 * 
 *    Rev 1.7   May 21 2002 20:07:44   BarnettH
 * Changed the _NF back, and changed MMU_CONTROL_IA to ASYNCH.
 * 
 *    Rev 1.6   May 21 2002 19:24:48   BarnettH
 * Changed all MMU_CONTROL_NF to MMU_CONTROL_ASYNCH
 * 
 *    Rev 1.5   May 21 2002 17:23:44   MaysR
 * Corrected bit mapping for switch to Sync/Async mode.
 * 
 * Added clock defines for 184/92/46 & 19/0/96/48.
 * 
 * Fixed function "toggle_led". (might consider removing this)
 * 
 *    Rev 1.4   Apr 11 2002 16:48:00   BarnettH
 * Changed function names to standard
 * Removed tabs
 * Cleaned up formatting.
 * 
 *    Rev 1.3   Dec 06 2001 11:11:38   MaysR
 * Changed clock set routines to conform with Alpheus2 spec, section 2.17.1.3, dated 8/7/01, when switching between Sync mode and Fastbus mode.
 *
 *    Rev 1.2   Nov 14 2001 16:13:48   MaysR
 * Added clock settings up to 200-100-50.  Added code to change to Sync clock mode for asymetrical clock rate settings.
 *
 * Added new routine to get current value of HCLK.  Used by LH7A400_meminit.c
 *
 *    Rev 1.1   Sep 28 2001 16:33:40   BarnettH
 * Customized set_led() for LH7A400
 * (New clocks still need to be added.)
 *
 *    Rev 1.0   Sep 18 2001 18:05:42   BarnettH
 * Initial revision.
 *
 ***********************************************************************
 * 
 *  Copyright (c) 2002 Sharp Microelectronics of the Americas
 *
 *  All rights reserved
 *
 *  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.
 *
 **********************************************************************/

#include "LH7A400_evb.h"
#include "LH7A400_evbutil.h"

/***********************************************************************
 *
 * Function: INT_32 LH7A400_delay_timer_msecs (UNS_32 msecs)
 *
 * Purpose:
 *      To provide a specialized non-interrupt driven timer to 
 *      provide milliseconds of delay depending on argument.
 *
 * Processing:
 *      Find a timer not in use; if none available, return error
 *      Load timer with valid downcount value < 32768
 *      Enable 2KHz timer
 *      Wait until timer underflows
 *      Return
 *
 * Parameters: msecs - milliseconds of delay wanted
 *
 * Outputs: None.
 *
 * Returns: None.
 *
 * Notes: 
 *    (1) Assumes 2 clocks per millisecond (2KHz clocked timer)
 *    (2) Max delay limited to 16.383 seconds (16,383 msecs)
 *    (3) TIMER3 count frequency is too high to use for this function,
 *        so only TIMER1 and TIMER2 are examined.
 *
 **********************************************************************/

INT_32 LH7A400_delay_timer_msecs (UNS_32 msecs)
{
    TIMERREGS * timer = TIMER1;

    if (timer->control & TIMER_CTRL_ENABLE)
    {
        // TIMER1 is in use, use TIMER2
        timer = TIMER2;
        if (timer->control & TIMER_CTRL_ENABLE)
        {
            // TIMER2 is in use, no timers available
            return (_ERROR);
        }
    }

    /* At 2 KHz, ~2 counts per millisecond */
    timer->load = ((msecs << 1) & 0x7FFF);
    /* enable free running timer1 2KHz */
    timer->control = TIMER_CTRL_ENABLE | TIMER_CTRL_FREERUN |
                            TIMER_CTRL_2K;
    /* delay until timer is finished */
    /* check > 32767) indicating rollover */
    while(!(timer->value & _BIT(15)))
        ;
    /* disable timer */
    timer->control = TIMER_CTRL_DISABLE;
    return (_NO_ERROR);
}

/**********************************************************************
 *
 * Function: void LH7A400_evb_toggle_led (INT_32 id)
 *
 * Author: barnetth
 *
 * Purpose:
 *      To toggle EVB LED D16 or D17 as desired
 *
 * Processing:
 *      Set the IOCON UARTMux register for the appropriate GPIOA[3:4]
 *      Set Data Direction for the pin
 *      Toggle the Data for the pin
 *      Return
 *
 * Parameters:
 *      INT_32 id - the bit for LED_D9 or LED_D10
 *      See LH7A400_evb.h
 *
 * Outputs: LED D9 or D10 illuminates or extinguishes.
 *
 * Returns: None
 *
 * Notes:
 *    (1) This function is used by the startup routine.
 *    (2) This function pre-empts any use of UART1.
 *
 **********************************************************************/

void LH7A400_evb_toggle_led (INT_32 id)
{
    LH7A400_evb_set_led (id, LED_TOGGLE);
}

/**********************************************************************
 *
 * Function: void LH7A400_evb_set_led (INT_32 id, INT_32 state)
 *
 * Author: barnetth
 *
 * Purpose:
 *      To toggle EVB LED D16 or D17 as desired
 *
 * Processing:
 *      Check the argument, return if bad
 *      Set the IOCON UARTMux register for the appropriate GPIOA[3:4]
 *      Set Data Direction for the pin(s)
 *      Set or toggle the Data for the pin as required.
 *      Return
 *
 * Parameters:
 *      INT_32 id - LED_D16, LED_D17, or (LED_D16 | LED_D17)
 *      INT_32 state - {LED_ON | LED_OFF | LED_TOGGLE}
 *      See LH7A400_evb.h
 *
 * Outputs: LED D16 or D17 illuminates, extinguishes, or changes state.
 *
 * Returns: None
 *
 * Notes:
 *    (1) This function pre-empts any use of UART3.
 *
 **********************************************************************/

void LH7A400_evb_set_led (INT_32 id, INT_32 state)
{
    switch (id)
    {
        case LED_D16:
        case LED_D17:
        case LED_D16 | LED_D17:
            break;

        default:
            return; /* bad argument */
            break;
    }

    /* Ensure Data Direction for desired LED is correct */
    GPIO->pbddr |= id;
    switch (state)
    {
        case LED_ON:
            GPIO->pbdr &= ~id;
            break;

        case LED_OFF:
            GPIO->pbdr |= id;
            break;

        case LED_TOGGLE:
        default:
            /* Toggle the bit */
            GPIO->pbdr ^= id;
            break;
    }
}

/**********************************************************************
 *
 * Function: void LH7A400_init_muxdpins (void)
 *
 * Author: barnetth
 *
 * Purpose:
 *      To initialize required multiplexed pins 
 *
 * Processing:
 *      Self-explanatory
 *
 * Parameters: None
 *
 * Outputs:  None
 *
 * Returns:  None
 *
 * Notes:
 *    (1)
 *
 **********************************************************************/

void LH7A400_init_muxdpins (void)
{
    /* IOCON->memmux = MEMMUX_PIOE_NOMUX; */ /* Example */ 
}

/**********************************************************************
 *
 * Function:
 *      UNS_32 LH7A400_Enable_Exception (UNS_32 interrupt)
 *      UNS_32 LH7A400_Disable_Exception (UNS_32 interrupt)
 *
 * Author: barnetth
 *
 * Purpose:
 *      To enable and disable IRQ and FIQ interrupts in the CPSR.
 *
 * Processing:
 *      Check for valid argument, return _ERROR if invalid
 *      Set or clear the appropriate bits in the CPSR
 *      Return CPSR value
 *
 * Parameters:
 *      UNS_32 interrupt -
 *          CORE_IRQ
 *          CORE_FIQ
 *          CORE_IRQ | CORE_FIQ
 *      See LH7A400map.h
 *
 * Outputs: Enables
 *
 * Returns:
 *      Value of CPSR after change
 *      _ERROR if invalid argument
 *
 * Notes:
 *    (1)
 *
 **********************************************************************/

UNS_32 LH7A400_Enable_Exception (UNS_32 interrupt)
{
    UNS_32 tmp;
    /* Only IRQ bit and FIQ bit are valid */
    if (interrupt & 0xFFFFFF3F)
        return (_ERROR);  /* error */

    __asm
    {
        MRS tmp, CPSR
        BIC tmp,tmp,interrupt
        MSR CPSR_cf, tmp
    }
    return (tmp);
}

UNS_32 LH7A400_Disable_Exception (UNS_32 interrupt)
{
    UNS_32 tmp;
    /* Only IRQ bit and FIQ bit are valid */
    if (interrupt & 0xFFFFFF3F)
        return (-1);  /* error */

    __asm
    {
        MRS tmp, CPSR
        ORR tmp, tmp, interrupt
        MSR CPSR_cf, tmp
    }
    return (tmp);
}

⌨️ 快捷键说明

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