📄 os_viewc.c
字号:
/*
*********************************************************************************************************
* uC/OS-View
*
* (c) Copyright 2002, Micrium, Inc., WESTON, FL
* All Rights Reserved
*
* LPC2XXX ARM CPU
*
* Filename : OS_VIEWc.C
* Programmer : ZLB
*********************************************************************************************************
*/
#include "includes.h"
#include "OS_VIEWC.H"
#include "OS_VIEW.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
#define BSP_DEBUG 0
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
static INT32U OSView_TmrCntsPrev;
/*
*********************************************************************************************************
* LOCAL PROTOTYPES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* Get the CPU Clock Frequency
*
* Description: This function reads CPU registers to determine the CPU clock frequency of the chip.
*********************************************************************************************************
*/
INT32U BSP_CPU_ClkFreq (void)
{
INT32U msel;
INT32U cpu_clk_freq;
msel = (INT32U)(PLLCFG & 0x1F);
cpu_clk_freq = CPU_OSC_FREQ * (msel + 1);
return (cpu_clk_freq);
}
INT32U BSP_CPU_ClkFreqPeripheral (void)
{
INT32U msel;
INT32U vpbdiv;
INT32U cpu_clk_freq;
INT32U cpu_peripheral_clk_freq;
msel = (INT32U)(PLLCFG & 0x1F);
cpu_clk_freq = CPU_OSC_FREQ * (msel + 1);
vpbdiv = (INT32U)(VPBDIV & 0x03);
switch (vpbdiv) {
case 0:
cpu_peripheral_clk_freq = cpu_clk_freq / 4;
break;
case 1:
cpu_peripheral_clk_freq = cpu_clk_freq;
break;
case 2:
cpu_peripheral_clk_freq = cpu_clk_freq / 2;
break;
default:
cpu_peripheral_clk_freq = cpu_clk_freq / 4;
break;
}
return (cpu_peripheral_clk_freq);
}
#if 0
INT32U Tmr_ReloadCnts;
void Tmr_TickISR_Handler (void)
{
T0IR = 0xFF; /* Clear timer #0 interrupt */
/* Reload 'relative' to current interrupt time */
#if BSP_DEBUG == 0
T0MR0 += Tmr_ReloadCnts;
#endif
VICVectAddr = 0;
OSTimeTick(); /* Call uC/OS-II's OSTimeTick() */
}
static void Tmr_TickInit (void)
{
INT32U peripheral_clk_freq;
/* VIC TIMER #0 Initialization */
VICIntSelect &= ~(1 << VIC_TIMER0); /* Enable interrupts */
VICVectAddr2 = (INT32U)Tmr_TickISR_Handler; /* Set the vector address */
VICVectCntl2 = 0x20 | VIC_TIMER0; /* Enable vectored interrupts */
VICIntEnable = (1 << VIC_TIMER0); /* Enable Interrupts */
peripheral_clk_freq = BSP_CPU_ClkFreqPeripheral();
Tmr_ReloadCnts = peripheral_clk_freq / OS_TICKS_PER_SEC;
T0TCR = 0; /* Disable timer 0. */
T0PC = 0; /* Prescaler is set to no division. */
#if BSP_DEBUG == 0
T0MR0 = T0TC + Tmr_ReloadCnts;
T0MCR = 1; /* Interrupt on MR0 (match register 0). */
#else
T0MR0 = Tmr_ReloadCnts;
T0MCR = 3; /* Interrupt on MR0 (reset TC) */
#endif
T0CCR = 0; /* Capture is disabled. */
T0EMR = 0; /* No external match output. */
T0TCR = 1; /* Enable timer 0 */
}
#endif
void OSView_Exit (void)
{
OSView_RxIntDis();
OSView_TxIntDis();
}
/*
*********************************************************************************************************
* Obtain CPU name
*********************************************************************************************************
*/
void OSView_GetCPUName (char *s)
{
INT8U cpu_clk_freq;
cpu_clk_freq = (INT8U)(BSP_CPU_ClkFreq() / 1000000L);
(void)OS_StrCopy((INT8U *)s, "Philips LPC2148 (xx MHz)");
s[17] = cpu_clk_freq / 10 + '0';
s[18] = 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 */
}
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_0
void Uart0SetBps(INT32U bps)
{
INT16U Fdiv;
U0LCR = 0x80; // 允许访问分频因子寄存器
Fdiv = (Fpclk / 16) / bps; // 设置波特率
U0DLM = Fdiv / 256;
U0DLL = Fdiv % 256;
U0LCR = 0x03; // 禁止访问分频因子寄存器
}
void InitUart0(INT32U bps)
{
PINSEL0 = (PINSEL0 & 0xfffffff0) | 0x05; // 选择管脚为UART0
Uart0SetBps(bps); // 且设置为8,1,n
U0IER = 0x05; // 允许接收和发送中断
U0FCR = 0x87; // 初始化FIFO Rx 8 Char EnFIFO
//U0MCR = 0x00;
}
#endif
#if OS_VIEW_COMM_SEL == OS_VIEW_UART_1
void Uart1SetBps(INT32U bps)
{
uint16 Fdiv;
U1LCR = 0x80; /* 允许访问分频因子寄存器 */
Fdiv = (Fpclk / 16) / bps; /* 设置波特率 */
U1DLM = Fdiv / 256;
U1DLL = Fdiv % 256;
U1LCR = 0x03; /* 禁止访问分频因子寄存器 */
}
void InitUart1(INT32U bps)
{
PINSEL0 = (PINSEL0 & 0xfff0ffff) | 0x00050000; /* 选择管脚为UART1 ,允许txd rxd ri*/
Uart1SetBps(bps);
U1IER = 0x05;
U1FCR = 0x87; /* 初始化FIFO */
U1MCR = 0x00;
}
#endif
/*$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.
*********************************************************************************************************
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -