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

📄 os_lh79524.c

📁 ucos在编译环境ads中arm移植代码
💻 C
字号:
/**********************************************************************
 * $Workfile:   os_lh79524.c  $
 * $Revision:   1.0  $
 * $Author:   LiJ  $
 * $Date:   Oct 20 2004 14:11:12  $
 *
 * Project: LH79524
 *
 * Description:
 * 	  Auxiliary Operating System routines for uC/OS-II port
 * 	  to LH79524 Platform
 *
 *
 * Revision History:
 * $Log:   //smaicnt2/pvcs/VM/sharpmcu/archives/sharpmcu/software/csps/lh79524/ports/ucosii/os_lh79524.c-arc  $
 * 
 *    Rev 1.0   Oct 20 2004 14:11:12   LiJ
 * 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 PURPucosiiE 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) 2004 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
 *	CAMAS, WA
 *********************************************************************/

#include "includes.h"
#include "os_lh79524.h"

#define TIMER_USED      2       /* Either 1 or 2 */
#define IRQ_PRIORITY    14      /* Priority from 0 to 15, 0 is the highest */
/**********************************************************************
*
* Function: Install_IRQ_Handler ()
*
* Purpose:
*	To install the timer interrupt handler for ARM interrupt vector 0x18
*
* Processing:
*	Installs IRQ Handler entry address in Exception jump table for
*	 "Load pc" method of branching to IRQ Handler.
*	Calls Install_Handler () with pointer to IRQ vector 0x18
*		and pointer to jump table address
*
* Parameters: 
*    unsigned int, location of IRQ Handler entry point
*
* Outputs:  None.
*
* Returns:	unsigned int, old contents of IRQ vector
*
* Notes:
*    ARM Architecture specific
*
**********************************************************************/

static void Install_IRQ_Handler (int priority, unsigned int handler_addr)
{

    unsigned int source; /* timer location in the vector source table */

    /* Write a ldr pc,[pc, #-0xff0] instruction to direct vector 
       address 0x18. This is required by IRQ handler */
    *(volatile unsigned int *)(0x18) = 0xe51ffff0;
    

    switch (TIMER_USED)
    {
        case 1:
            source = TIMER1_LH79524_VIC_SOURCE; /* timer channel in vector source table */
            break;
        case 2:
            source = TIMER2_LH79524_VIC_SOURCE; /* timer channel in vector source table */
            break;
        default:
            source = TIMER2_LH79524_VIC_SOURCE; /* timer channel in vector source table */
            break;
    }
    
    if (priority > 15) priority = 15;
    if (priority < 0) priority = 0;
    
    /* disable the interrupt for the source first */
    *(volatile unsigned int *)VICIntEnableClear = (0x1 << source);
    
    /* clear the interrupt vector address */
    *(volatile unsigned int *)VICVectorAddr = 0x0;

    /* clear the control register for the source */
    *(volatile unsigned int *)VICVectorCntl(priority) = 0x0;

    /* set the source to be IRQ */
    *(volatile unsigned int *)VICIntSelect &= ~(0x1 << source); 
     
    /* set the source to the VIC entry */
    *(volatile unsigned int *)VICVectorCntl(priority) = (0x20 | source);
    
    *(volatile unsigned int *)VICVectAddr(priority) = handler_addr;

    /* enable the interrupt for the source last */   
    *(volatile unsigned int *)VICIntEnable |= (0x1 << source);

}


/**********************************************************************
*
* Function: InstallTimer ()
*
* Purpose:
*	To initialize the OS ticker.
*
* Processing:
*
* Parameters: 
*    int - ticks per second
*
* Outputs:  None.
*
* Returns:	void
*
* Notes: 
*    Timer is only 1 or 2 
*
**********************************************************************/

static void InstallTimer (int ticks_per_sec)
{
    unsigned int pclk;
    unsigned int tmp1;
    TIMER_REGS_T * timer_used;
    
    if(TIMER_USED == 1)
    {
        timer_used = TIMER1;
    }
    else
    {
        timer_used = TIMER2;
    }

    /* Get the system clock from crystal value */    
    tmp1 = *(volatile unsigned int *)(RCPC_SYSPLLCTL);
    pclk = CRYSTAL_FREQ*(tmp1&0x3f)/((tmp1>>6)&0x3f);
    pclk = pclk / (*(volatile unsigned int *)(RCPC_SYSCLKPRE) * 2);
    
    /* Clear the control, clear the counter */
    timer_used->ctrl = 0x1;
    
    /* Set the control, div = pclk/128 */
    timer_used->ctrl |= _BIT(3) | _BIT(4);
    
    /* Set the only cmp0 int enable */
    timer_used->int_ctrl = _BIT(1);
    
    /* Set the cmp0 value */
    timer_used->cmp0 = pclk/128/ticks_per_sec;
    
    /* Clear the cmp0 interruption */
    timer_used->status |= _BIT(1);
    
    /* Start the timer */
    timer_used->ctrl |= _BIT(1);
    
}



/**********************************************************************
*
* Function: C_IRQHandler ()
*
*
* Purpose:
*	IRQ handler function called from os_cpu_a.s
*
* Processing:
*    Do the other chip related IRQ handler function
*
* Parameters:  None.
*
* Outputs:  None.
*
* Returns:	void
*
* Notes: When interruption happens, MCU will jump to UCOS_IRQHandler
*       defined in os_cpu_a.s, then UCOS_IRQHandler will call function
*       C_IRQHandler defined here and then back to uCOSII handling
*
**********************************************************************/

void C_IRQHandler (void)
{
    TIMER_REGS_T * timer_used;
    
    if(TIMER_USED == 1)
    {
        timer_used = TIMER1;
    }
    else
    {
        timer_used = TIMER2;
    }

    /* Stop the timer */
    timer_used->ctrl &= ~_BIT(1);
    
    /* Clear the counter */
    timer_used->ctrl |= _BIT(0);
    
    /* Clear the cmp0 interruption */
    timer_used->status |= _BIT(1);
    
    /* clear the interrupt vector address */
    *(volatile unsigned int *)VICVectorAddr = 0x0;

    /* Start the timer */
    timer_used->ctrl |= _BIT(1);
    
    OSTimeTick();

}



/**********************************************************************
*
* Function: MCU_start_ticker ()
*
* Author: barnetth
*
* Purpose:
*	To install the IRQ handler for all IRQ interrupt sources (of which
*	the OS time tick is one) and initialize and start the OS time tick
*	on Counter/Timer 0.
*
* Processing:
*    Install IRQ Handler
*    Call Ticker Initalize function
*    Reset Ticker to clear pending interrupts, if any
*
* Parameters: 
*    int - ticks per second
*
* Outputs:  None.
*
* Returns:	void
*
* Notes: 
*    (1) Must be called only once in the first (highest priority) task
*    to start.
*    (2) OS timer uses Counter/Timer 0 dedicated to timer tick.
*    (3) LH79531 EVB (Rainbow) specific.
*
*
**********************************************************************/
void MCU_start_ticker (int ticks_per_sec)
{
#if OS_CRITICAL_METHOD == 3                      /* Allocate storage for CPU status register           */
    OS_CPU_SR  cpu_sr;
    
    cpu_sr = 0;                                  /* Prevent compiler warning                           */
#endif    

	OS_ENTER_CRITICAL ();
	Install_IRQ_Handler (IRQ_PRIORITY, (unsigned int) UCOS_IRQHandler);
	/* Initialize ticker */ 
	InstallTimer(ticks_per_sec);
	OS_EXIT_CRITICAL ();
}

⌨️ 快捷键说明

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