📄 frmwrk.c
字号:
/**************************************************************************
* *
* PROJECT : ARM port for uC/OS-II *
* *
* MODULE : FRMWRK.c *
* *
* AUTHOR : Michael Anburaj *
* URL : http://geocities.com/michaelanburaj/ *
* EMAIL: michaelanburaj@hotmail.com *
* *
* SPONSORS : Thanks to Martin Li (mli00@yahoo.com) & Don Williams *
* (donw@clearblu.net) for sponsoring hardware. *
* *
* PROCESSOR : LPC2xxx (32 bit ARM7TDMI-S RISC core from Philips) *
* *
* TOOL-CHAIN : SDT 2.51, ADS 1.2 or GCC *
* *
* DESCRIPTION : *
* This is the Framework module. Creates an operating infrastructure. *
* *
**************************************************************************/
#include "frmwrk_cfg.h"
#include "includes.h"
#include "frmwrk.h"
#include "halt.h"
#include "consol.h"
#include <stdarg.h>
#include <stdio.h>
/* ********************************************************************* */
/* Global definitions */
/* ********************************************************************* */
/* File local definitions */
/* ********************************************************************* */
/* Local functions */
/*
*********************************************************************************************
* __vLogo
*
* Description: This routine display the Logo on the CONSOL port.
*
* Arguments : none.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
static void __vLogo(void)
{
SEND_STR("\n\nUCOS_FRAMEWORK Ver "__mVer" for "__mProcessor" :"__mDate"\n"
"Built using "
#if defined (ADS)
"ADS"
#elif defined (SDT)
"SDT"
#elif defined (GCC)
"GCC"
#else
"Unknown Tool-chain"
#endif
" on "__DATE__" <"__TIME__">\n"
"Endian: "
#ifdef EB
"BIG"
#else
"LITTLE"
#endif
"\n"
"Processor operating state: "
#if defined (THUMB_INTERWORK)
"ARM-THUMB"
#else
"ARM"
#endif
"\n"
"Task start state: "
#ifdef THUMB_TASKS
"THUMB"
#else
"ARM"
#endif
"\n");
SEND_STR("CONSOL: COM");
SEND_NUM(10, 1, False, ' ', __nConsolPort);
SEND_STR(", ");
SEND_NUM(10, 6, False, ' ', __nConsolBaud);
SEND_STR("bps, 8Bit, NP\n");
SEND_STR("CPU Clk: ");
SEND_NUM(10, 4, False, ' ', CCLK/1000000);
SEND_STR("MHz MMU: "
"N/A"
" Cache: "
"N/A"
" Write Buf: "
"N/A"
"\n");
SEND_STR("FLASH_SADDR:");
SEND_NUM(16, 8, False, '0', FLASH_SADDR);
SEND_STR("h SRAM_SADDR:");
SEND_NUM(16, 8, False, '0', SRAM_SADDR);
SEND_STR("h SRAM_EADDR:");
SEND_NUM(16, 8, False, '0', SRAM_EADDR);
SEND_STR("h\nSFR_BADDR :");
SEND_NUM(16, 8, False, '0', SFR_BADDR);
SEND_STR("h ISR_BADDR :");
SEND_NUM(16, 8, False, '0', ISR_BADDR);
SEND_STR("h\n");
SEND_STR("Free RAM: ");
SEND_NUM(16, 8, False, '0', C_wRTMem);
SEND_STR("h ~ ");
SEND_NUM(16, 8, False, '0', C_wRTMemLimit);
SEND_STR("h\n");
SEND_STR("Developed by "__mAuthor"\n\n");
}
/*
*********************************************************************************************
* __vT0Interrupt
*
* Description: This routine clears the pending WDT interrupt & calls the OS tick handler.
*
* Arguments : none.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
static void __vT0Interrupt()
{
rT0IR = BIT_IR_MR0;
OSTimeTick();
}
#ifndef RAM_IMAGE
/*
*********************************************************************************************
* __vPortInit
*
* Description: This routine sets the default GPIO condition.
*
* Arguments : none.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
static void __vPortInit(void)
{
#if (INCLUDE_CONSOL1)
//**** PINSEL0
//Ports : P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P0.8 P0.9 P0.10 P0.11 P0.12 P0.13 P0.14 P0.15
//Signal : TxD0 RxD0 IO IO IO IO IO IO TxD1 RxD1 IO IO IO IO IO IO
//Func : UART0 ----------- NC ------------------ UART1 LED3 LED4 LED5 SW2 SW3 SW4
//Binary : 01 01 00 00 00 00 00 00 01 01 00 00 00 00 00 00
rPINSEL0 = 0x00050005;
#else
//**** PINSEL0
//Ports : P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P0.8 P0.9 P0.10 P0.11 P0.12 P0.13 P0.14 P0.15
//Signal : TxD0 RxD0 IO IO IO IO IO IO IO IO IO IO IO IO IO IO
//Func : UART0 ----------- NC ------------------ LED1 LED2 LED3 LED4 LED5 SW2 SW3 SW4
//Binary : 01 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00
rPINSEL0 = 0x00000005;
#endif
//**** PINSEL1
//Ports : P0.16 P0.17 P0.18 P0.19 P0.20 P0.21 P0.22 P0.23 P0.24 P0.25 P0.26 P0.27 P0.28 P0.29 P0.30 P0.31
//Signal : IO IO IO IO IO IO IO IO IO IO IO IO IO IO IO IO
//Func : --------------------------------------------- NC ---------------------------------------------
//Binary : 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
rPINSEL1 = 0x00000000;
//**** IO
//Ports : P0.0 P0.1 P0.2 P0.3 P0.4 P0.5 P0.6 P0.7 P0.8 P0.9 P0.10 P0.11 P0.12 P0.13 P0.14 P0.15
//Dir : OP OP OP OP OP OP OP OP OP OP OP IP IP IP
//Binary : 0 0 1 1 1 1 1 1 1 1 1 1 1 0 0 0
//Logic : L L L L L L H H H H H
//SetMsk : 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0
//ClrMsk : 0 0 1 1 1 1 1 1 0 0 0 0 0 0 0 0
//
//Ports : P0.16 P0.17 P0.18 P0.19 P0.20 P0.21 P0.22 P0.23 P0.24 P0.25 P0.26 P0.27 P0.28 P0.29 P0.30 P0.31
//Dir : OP OP OP OP OP OP OP OP OP OP
//Binary : 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
//Logic : L L L L L L L L L L
//SetMsk : 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
//ClrMsk : 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
#if defined (LPC2104) || defined (LPC2105) || defined (LPC2106)
rIOSET = 0x00001f00; // Turn On all LEDs
rIOCLR = 0xffc000fc; // clear the ZEROs output
rIODIR = 0xffc01ffc; // set the output bit direction
#else
rIOSET0 = 0x00001f00; // Turn On all LEDs
rIOCLR0 = 0xffc000fc; // clear the ZEROs output
rIODIR0 = 0xffc01ffc; // set the output bit direction
#endif
}
/*
*********************************************************************************************
* __vLowLevelInit
*
* Description: This routine starts up the PLL then sets up the GPIO pins before
* waiting for the PLL to lock. It finally engages the PLL.
*
* Arguments : none.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
static void __vLowLevelInit(void)
{
// set PLL multiplier & divisor.
// values computed in lpc210x.h
rPLLCFG = (VAL_PLLCFG_MSEL | VAL_PLLCFG_PSEL);
// enable PLL
rPLLCON = BIT_PLLCON_PLLE;
rPLLFEED = 0xAA; // Make it happen. These two updates
rPLLFEED = 0x55; // MUST occur in sequence.
__vPortInit();
// wait for PLL lock
while (!(rPLLSTAT & BIT_PLLSTAT_LOCK))
continue;
// enable & connect PLL
rPLLCON = (BIT_PLLCON_PLLE | BIT_PLLCON_PLLC);
rPLLFEED = 0xAA; // Make it happen. These two updates
rPLLFEED = 0x55; // MUST occur in sequence.
// setup & enable the MAM
rMAMTIM = VAL_MAMTIM_CYCLES;
rMAMCR = VAL_MAMCR_FULL;
// set the peripheral bus speed
rVPBDIV = VAL_VPBDIV; // set the peripheral bus clock speed
}
#endif
/* ********************************************************************* */
/* Global functions */
/*
*********************************************************************************************
* C_IRQHandler
*
* Description: This routine is the IRQ handler. Dispatches all peripheral interrupts.
*
* Arguments : none.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void C_IRQHandler(void)
{
U32 wIrqStatus, wInt;
wIrqStatus = rVICIRQStatus;
for (wInt = MIN_INT_NUM; wInt <= MAX_INT_NUM; wInt++)
{
if (wIrqStatus & (1<<wInt))
{
((void(*)(void))(*((U32 *)(aISR_WDT+(wInt<<2)))))();
}
}
}
/*
*********************************************************************************************
* FRMWRK_vStartTicker
*
* Description: This routine starts Timer1 (TC1) in the Prescale mode for OS Tick.
*
* Arguments : wTicksPerSec - Time ticks per second.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
#define T0_DIV 3
void FRMWRK_vStartTicker(U32 wTicksPerSec)
{
#if OS_CRITICAL_METHOD == 3 /* Allocate storage for CPU status register */
OS_CPU_SR cpu_sr;
#endif
OS_ENTER_CRITICAL();
// setup Timer 1 to count forever
rT0TCR = BIT_TCR_RESET; // reset & disable timer 0
rT0PR = T0_DIV-1; // set the prescale divider
rT0MR0 = (PCLK/T0_DIV)/wTicksPerSec;// set the match register 0
rT0MCR = (BIT_MCR_MR0_I|BIT_MCR_MR0_R);
rT0CCR = 0; // disable compare registers
rT0EMR = 0; // disable external match register
pISR_TIMER0 = (U32)__vT0Interrupt;
INT_ENABLE(IRQ, BIT_TIMER0);
rT0TCR = BIT_TCR_ENABLE; // enable timer 0
OS_EXIT_CRITICAL();
}
/*
*********************************************************************************************
* FRMWRK_vRamTest
*
* Description: This routine is used do RAM test.
*
* Arguments : pbID - Test identification string.
* wSAddr - RAM starting address.
* wEAddr - RAM end address.
*
* Return : none.
*
* Note(s) : Do not test the following areas using this routine:
* 1. Stack
* 2. Software vector table
* 3. C Variables (RW & ZI)
*********************************************************************************************
*/
void FRMWRK_vRamTest(U8 *pbID,U32 wSAddr,U32 wEAddr)
{
U32 wI,wJ;
U8 bError=0;
SEND_CHAR('\n');
SEND_STR((char *)pbID);
SEND_CHAR('(');
SEND_NUM(16, 8, False, '0', wSAddr);
SEND_STR("h-");
SEND_NUM(16, 8, False, '0', wEAddr);
SEND_STR("h):WR");
for(wI=wSAddr;wI<wEAddr;wI+=4)
{
*((volatile unsigned *)wI)=wI;
}
SEND_STR("\b\bRD");
for(wI=wSAddr;wI<wEAddr;wI+=4)
{
wJ=*((volatile unsigned *)wI);
if(wJ!=wI)bError=1;
}
SEND_STR((bError==0)? "\b\bO.K.\n": "\b\bFAIL\n");
}
/*
*********************************************************************************************
* C_vMain
*
* Description: This is the main C entry function.
*
* Arguments : none.
*
* Return : none.
*
* Note(s) :
*********************************************************************************************
*/
void C_vMain(void)
{
#ifndef RAM_IMAGE
__vLowLevelInit();
#endif
HALT_vInitARMModeHandlers();
pISR_IRQ = (U32)UCOS_IRQHandler;
#if (INCLUDE_CONSOL == 1)
CONSOL_Init(UART_BAUD(__nConsolBaud), __nConsolFifoEn);
#endif
__vLogo();
APP_vMain();
SEND_STR("APP has ended...\n");
}
#if (INCLUDE_CONSOL == 1) & (CONSOL_VARARG == 1)
/*
*********************************************************************************************
* printf
*
* Description: This is a stdio.h function.
*
* Arguments : .
*
* Return : Returns 0.
*
* Note(s) :
*********************************************************************************************
*/
int printf(const char *pbFmt,...)
{
va_list pArg;
char abString[256];
va_start(pArg,pbFmt);
vsprintf(abString,pbFmt,pArg);
SEND_STR(abString);
va_end(pArg);
return 0;
}
#endif /* (INCLUDE_CONSOL == 1) & (CONSOL_VARARG == 1) */
/* ********************************************************************* */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -