os_viewc.c

来自「称植到lpc2124上的UCOS2.85版 是本人初学移植和ARM的成果 可」· C语言 代码 · 共 272 行

C
272
字号
/*
*********************************************************************************************************
*                                           uC/OS-View
*
*                            (c) Copyright 2002, Micrium, Inc., WESTON, FL
*                                       All Rights Reserved
*
*                                     LPC2XXX ARM CPU
*
* Filename   : OS_VIEWc.C
* Programmer : ZLB
*********************************************************************************************************
*/

#include "..\AVR\target.h"
/*
*********************************************************************************************************
*                                               CONSTANTS
*********************************************************************************************************
*/

#define  BIT0                         0x01       /* Bit masks                                          */
#define  BIT1                         0x02
#define  BIT2                         0x04
#define  BIT3                         0x08
#define  BIT4                         0x10
#define  BIT5                         0x20
#define  BIT6                         0x40
#define  BIT7                         0x80

/*
*********************************************************************************************************
*                                           Obtain CPU name
*********************************************************************************************************
*/

void  OSView_GetCPUName (char *s)
{
    INT8U  cpu_clk_freq;

    cpu_clk_freq = (INT8U)(Fcclk / 1000000L);
    (void)OS_StrCopy((INT8U *)s, "AT91SAM7S64 (xx MHz)");
    s[13] = cpu_clk_freq / 10 + '0';
    s[14] = cpu_clk_freq % 10 + '0'; 
}

/*
*********************************************************************************************************
*                                  Obtain Interrupt Stack information
*********************************************************************************************************
*/

INT32U  OSView_GetIntStkBase (void)
{
    return (0);										  /* We are not using an ISR stack                 */
}


INT32U  OSView_GetIntStkSize (void)
{
    return (0);										  /* We are not using an ISR stack                 */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                    INITIALIZE uC/OS-View COM PORT
*
* Description: Initialize the hardware required for the OS to run. This will work on any target hardware,
*              but may have to be tailored a little for:
*                  Interrupt vectors
*                  Time measurement timer
*                  Communications port
*                  etc.
*
* Note(s)    : 1) Timer #2 is used to measure task execution time.
*********************************************************************************************************
*/

INT8U Init_Debug( INT32U baudrate )
{
    DWORD Fdiv;

	extern void OSView_RxTxISRHandler(void);

    PINSEL0 = 0x00050005;       /* Enable RxD1 and TxD1, RxD0 and TxD0 */

    U0LCR = 0x83;               /* 8 bits, no Parity, 1 Stop bit    */
    Fdiv = ( Fpclk / 16 ) / baudrate ;	/*baud rate */
    U0DLM = Fdiv / 256;							
    U0DLL = Fdiv % 256;	
    U0LCR = 0x03;               /* DLAB = 0                         */
    U0FCR = 0x07;	           	/* Enable and reset TX and RX FIFO. */

    if ( install_irq(3, UART0_INT, (void *)OSView_RxTxISRHandler ) == FALSE )
    {
	     return (FALSE);
    }
    return (TRUE);
}


void  OSView_InitTarget (void)
{
	Init_Debug(OS_VIEW_BAUDRATE); 
    OSView_TxIntEn ();
	U0IER |= IER_RBR | IER_RLS;
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                           Get time [cycles]
*
* Description: This routine is required for task execution time measurement.  This function needs to
*              return time as accurately as possible and in a 32-bit variable.
*
*              On the PC, the cycles counter is actually updated by the tick ISR (see OSView_TickHook()).
*              Because of this, this function only needs to return the value of the global counter
*              OSView_CyclesCtr.
*
* Returns    : A 32-bit representation of time.
*********************************************************************************************************
*/

INT32U  OSView_TimeGetCycles (void)
{
    INT32U     cycles;

    cycles = OSView_CyclesCtr;
    return (cycles);
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                      Communication for uC/OS-View
*
* Description: Send 1 character to COM Port
*
* Note(s)    : 1) Assumes UART #0
*********************************************************************************************************
*/

void  OSView_Tx1 (INT8U c)
{
	  /*while ( !(UART0TxEmpty & 0x01) );THRE status, contain valid data */			
	  U0THR = c;
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                       Disable Tx Interrupts
*********************************************************************************************************
*/

void  OSView_TxIntDis (void)
{
    #if 1
#if OS_CRITICAL_METHOD == 3                                              /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr;
#endif

    OS_ENTER_CRITICAL();
    U0IER &= ~IER_THRE ;	 
    OS_EXIT_CRITICAL();
    #endif
}

/*
*********************************************************************************************************
*                                       Enable Tx Interrupts
*********************************************************************************************************
*/

void  OSView_TxIntEn (void)
{
    #if 1
#if OS_CRITICAL_METHOD == 3                 /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr;
#endif

    OS_ENTER_CRITICAL();
    U0IER |= IER_THRE ;	      /* Enable UART0 interrupt */
    OS_EXIT_CRITICAL();
    #endif
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                Tx Communication handler for uC/OS-View
*                       (NOT USED for PC since OSView_RxTxHandler() handles this)
*********************************************************************************************************
*/
void OSView_RxTxISR_Exception(void)  
{ 
#if OS_CRITICAL_METHOD == 3                 /* Allocate storage for CPU status register */
    OS_CPU_SR  cpu_sr;
#endif


    INT8U IIRValue, LSRValue;
    INT8U Dummy;
	volatile INT8U temp;

    OS_ENTER_CRITICAL();

    IIRValue = U0IIR;
    
    IIRValue >>= 1;			    /* skip pending bit in IIR */
    IIRValue &= 0x07;			/* check bit 1~3, interrupt identification */
    if ( IIRValue == IIR_RLS )  /* Receive Line Status */
    {
	    LSRValue = U0LSR;
	    /* Receive Line Status */
	    if ( LSRValue & (LSR_OE|LSR_PE|LSR_FE|LSR_RXFE|LSR_BI) )
	   {
	      /* There are errors or break interrupt */
	      /* Read LSR will clear the interrupt */
	      Dummy = U0RBR;		/* Dummy read on RX to clear 
					             interrupt, then bail out */
	      OS_ENTER_CRITICAL();
	      VICVectAddr = 0;		/* Acknowledge Interrupt */
	      return;
	   }
	   if ( LSRValue & LSR_RDR )	/* Receive Data Ready */			
	   {
	      /* If no error on RLS, normal ready, save into the data buffer. */
	      /* Note: read RBR will clear the interrupt */
	      OSView_RxCtr++;
          temp = U0RBR;                                          //Read A Char        
          OSView_RxHandler(temp);
	    }
    }
    else if ( IIRValue == IIR_RDA )	/* Receive Data Available */
    {
	    /* Receive Data Available */
	      OSView_RxCtr++;
          temp = U0RBR;                                          //Read A Char        
          OSView_RxHandler(temp);
    }
    else if ( IIRValue == IIR_CTI )	/* Character timeout indicator */
    {
	     /* Character Time-out indicator */
	             ;		/* Bit 9 as the CTI error */
    }
    else if ( IIRValue == IIR_THRE )	/* THRE, transmit holding register empty */
    {
	      /* THRE interrupt */
	      LSRValue = U0LSR;		   /* Check status in the LSR to see if
					                  valid data in U0THR or not */
         if ( LSRValue & LSR_THRE )
	     {
	            OSView_TxCtr++;
                OSView_TxHandler(); 
	     }
	     else
       	{
	           ;
	     }
    }
    
    OS_ENTER_CRITICAL();
    VICVectAddr = 0;		/* Acknowledge Interrupt */
}




⌨️ 快捷键说明

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