sdk7a400_simple_startup.c

来自「Sharp LH7A400 BSP平台无关部分的代码,有很高的参考价值,尤其是系」· C语言 代码 · 共 184 行

C
184
字号
/***********************************************************************
 * $Workfile:   sdk7a400_simple_startup.c  $
 * $Revision:   1.1  $
 * $Author:   WellsK  $
 * $Date:   Sep 10 2003 12:14:44  $
 *
 * Project: SDK7A400 simple startup example
 *
 * Description:
 *     This file contains a simple startup code example that will
 *     generate a 'heartbeat' indicator on several LEDs.
 *
 * Revision History:
 * $Log:   //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh7a400/bsps/sdk7a400/startup/examples/simple/sdk7a400_simple_startup.c-arc  $
 * 
 *    Rev 1.1   Sep 10 2003 12:14:44   WellsK
 * Added support for virtual MMU table location. Added default
 * vector for int_initialize(). Updated the background comment.
 * Added the TIMER_MSEC macro value.
 * 
 *    Rev 1.0   Jun 20 2003 09:26:14   WellsK
 * 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 "abl_types.h"
#include "abl_arm922t_cp15_driver.h"
#include "abl_irq_fiq.h"
#include "lh7a400_int_driver.h"
#include "lh7a400_timer_driver.h"
#include "sdk7a400_cpld_driver.h"

/* Timer device handle */
INT_32 timer1dev;

/* Timer count value */
volatile UNS_32 t1count;

/***********************************************************************
 *
 * Function: timer1_user_interrupt
 *
 * Purpose: Timer 1 interrupt handler
 *
 * Processing:
 *     Clear the timer interrupt and increment the interrupt count.
 *     Perform some basic LED toggling logic based on the interrupt
 *     count.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void timer1_user_interrupt(void)
{
    static BOOL_32 gpio_led_state = FALSE;
    static BOOL_32 status_led_state = FALSE;

    /* Clear the interrupt and increment count */
    timer_ioctl(timer1dev, TIMER_INT_CLEAR, 0);
    t1count++;

    switch (t1count)
    {
        case 3:
        /* Turn on first LED */
        gpio_led_state = TRUE;
        break;

        case 5:
        /* Turn on second LED */
        status_led_state = TRUE;
        break;

        case 8:
        /* Turn off first LED */
        gpio_led_state = FALSE;
        break;

        case 13:
        /* Turn off second LED */
        status_led_state = FALSE;

        default:
            if (t1count >= 13)
            {
                t1count = 0;
            }
            break;
    }

    cpld_enable_led(LED_GPIO, gpio_led_state);
    cpld_enable_led(LED_STATUS, status_led_state);
}

/***********************************************************************
 *
 * Function: c_entry
 *
 * Purpose: Application entry point from the startup code
 *
 * Processing:
 *     Clear t1count and disable IRQ and FIQ interrupts in the ARM core.
 *     Initialize the interrupt driver with a call to int_initialize.
 *     Install the IRQ dispatcher at the ARM vector address with a call
 *     to int_install_handler. Install the timer interrupt handler in
 *     the IRQ dispatcher with a call to int_install_irq_handler.
 *     Initialize timer 1 for a periodic 100mS underflow and enable the
 *     timer 1 interrupt in the interrupt controller. Enable interrupts
 *     in the ARM core. Wait in a endless loop as the timer 1 interrupt
 *     will handle the blinking of the LEDs.
 *
 * Parameters: None
 *
 * Outputs: None
 *
 * Returns: Nothing
 *
 * Notes: None
 *
 **********************************************************************/
void c_entry(void)
{
    /* Set virtual address of MMU table (needed for VIC driver
       functions) */
    cp15_set_vmmu_addr((UNS_32 *)
        (0xC1C00000 + (0xCD3E0000- 0xCD000000)));

    /* Clear initial state of interrupt count */
    t1count = 0;

    /* Disable interrupts in ARM core */
    disable_irq_fiq();

    /* Initialize interrupt system */
    int_initialize(0xFFFFFFFF);

    /* Install standard IRQ dispatcher at ARM IRQ vector */
    int_install_handler(IRQ_VEC, (PFV) irq_dispatcher);

    /* Install timers handler in the IRQ dispatcher */
    int_install_irq_handler(INT_TC1UINTR, (PFV) timer1_user_interrupt);

    /* Open timer 1 */
    timer1dev = timer_open(TIMER1, 0);

    /* Setup timer 1 for a 10Hz tick */
    timer_ioctl(timer1dev, TIMER_SET_USECS, (100 * TIMER_MSEC));

    /* Enable timer (starts counting) */
    timer_ioctl(timer1dev, TIMER_ENABLE, 1);

    /* Clear any latched timer 1 interrupts */
    timer_ioctl(timer1dev, TIMER_INT_CLEAR, 0);

    /* Enable timer 1 interrupts in the interrupt controller */
    int_enable(INT_TC1UINTR);

    /* Enable IRQ interrupts in the ARM core */
    enable_irq();

    /* Loop forever and let interrupts toggle the LEDs */
    while (1);
}

⌨️ 快捷键说明

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