📄 main.c
字号:
/* main.c
*
* Motorola Coldfire MCF5307 port to MicroC/OS-II
*
* Ross Berteig
* Cheshire Engineering Corp
* 650 Sierra Madre Villa, Suite 201
* Pasadena CA 91107
* +1-626-351-5493 +1-626-351-8645 FAX
* Ross@CheshireEng.com, www.CheshireEng.com
*
* Copyright (C) 1998 Cheshire Engineering Corporation.
* Based on a port to uCOS version 1.x by David Fiddes.
* Portions Copyright (C) 1997 David Fiddes, D.J.Fiddes@hw.ac.uk
* Anything that no longer works is probably not his fault.
*
* This module provides the C main entry point and general
* initialization of the Arnewsh SBC5307 Evaluation Board.
*
* Builds with the Diab Data C compiler, tested under SDS SingleStep.
* Should work as S-record download into dBUG also, but will be
* harder to prove to work.
*/
#include "includes.h" /* uCOS definitions */
#include <stdio.h>
#include <string.h>
/* EarlyInit
*
* Place for hardware and other intialization to be done
* after C runtime initializations, but before MicroC/OS-II
* is started.
*
* Notice that this assumes that some other piece of system code
* has already made the SDRAM work. This could either be the
* dBUG monitor, a configuration file for SingleStep, or a
* custom boot loader.
*/
void EarlyInit()
{
register MCF5307_IMM *imm = &__MBAR;
// Mask out all interrupts
imm->sim.IMR = ~0;
// Set parallel port as 2 bytes of useful bits, all outputs
imm->sim.PAR = 0xffff;
imm->parallel_port.PADDR = 0xffff;
imm->parallel_port.PADAT = 0;
// magic settings needed for 5307 to correctly stack exceptions.
// Without this setting, 0x00000000 is occasionally used as the
// return address in the exception frame, causing bad things to
// happen.
imm->sim.MPARK = MCF5307_SIM_MPARK_EARBCTRL | MCF5307_SIM_MPARK_SHOWDATA;
// Set Chip Select system to match dBUG monitor and linker config
//
// This must be done so that the uC/OS kernel, when downloaded and
// run from SingleStep, will be able to count on the correct PC
// value in stacked exception frames. Setting up CS0 here is sufficient.
// So is setting MPARK to include EARBCTRL|SHOWDATA as shown later.
// CS0: 1 Mb at 0xffe00000 - 0xffefffff, WS=3, AA=1, PS=16bit, no bursts
imm->cs.CSAR0 = 0xFFE0;
imm->cs.CSMR0 = 0x000F0001;
imm->cs.CSCR0 = 0x0D80;
// CS1: unused, V=0
imm->cs.CSAR1 = 0x0080; // 0xffff
imm->cs.CSMR1 = 0x00000000; // 0x00000001
imm->cs.CSCR1 = 0x0100;
// CS2 - CS7 are 2 Mb each, based at 0xfe400000.
imm->cs.CSBAR = 0xFE;
imm->cs.CSMR2 = 0x00000001; // CS2: Valid, 32bit, AA=1, WS=0
imm->cs.CSCR2 = 0x0140;
imm->cs.CSMR3 = 0x00000015; // CS3: Valid, 16bit, AA=1, SC, UC
imm->cs.CSCR3 = 0x0080;
imm->cs.CSMR4 = 0x00000001; // CS4: Valid, 16bit, AA=1, SC, UC
imm->cs.CSCR4 = 0x0080;
imm->cs.CSMR5 = 0x0000001f; // 0x0000001F;
imm->cs.CSCR5 = 0x0100;
imm->cs.CSMR6 = 0x0000001f;
imm->cs.CSCR6 = 0x0100;
imm->cs.CSMR7 = 0x0000001f;
imm->cs.CSCR7 = 0x0100;
// Interrupt controls to match dBUG
imm->sim.AVCR = 0xFF;
imm->sim.ICR0 = 0x9E;
imm->sim.ICR1 = 0x97;
imm->sim.ICR2 = 0x95;
imm->sim.ICR3 = 0x8C;
imm->sim.ICR4 = 0x8E;
imm->sim.ICR5 = 0x8D;
imm->sim.ICR6 = 0x88;
imm->sim.ICR7 = 0x89;
imm->sim.ICR8 = 0x8A;
imm->sim.ICR9 = 0x8B;
imm->sim.ICR10 = 0x84;
imm->sim.ICR11 = 0x86;
}
/* HookOSVectors()
*
* Set the vectors required for uC/OS operation.
*/
void HookOSVectors()
{
ADDRESS *vect = (ADDRESS *)0x00000000;
// Hook required vectors:
vect[14] = (ADDRESS)&CPUFormatError; /* Format Error Exception */
vect[24+5] = (ADDRESS)&OSTickISR; /* AutoVector 5 - Timer tick */
vect[32+14] = (ADDRESS)&OSCtxSw; /* Trap 14 - Do a context switch */
}
/* StartTicking
*
* Setup and release the TIMER1 as a periodic interrupt source.
* We need a heartbeat for the uC/OS task scheduler to use for
* task preemption. This should have a 10 ms period to match the
* declaration of OS_TICKS_PER_SEC in OS_CFG.h.
*
* The frequency is 100Hz = BCLK / (1 or 16) / prescale / reference
* = 45 MHz / 1 / 45 / 10000
*/
void StartTicking()
{
register MCF5307_IMM *imm = &__MBAR;
// disable timer1 interrupts
imm->sim.IMR |= MCF5307_SIM_IMR_TIMER1;
// reset the timer
imm->timer.TMR1 = MCF5307_TIMER_TMR_RST; // enable
imm->timer.TMR1 = 0x0000; // reset
// setup timer
imm->timer.TMR1 = MCF5307_TIMER_TMR_RST; // enable
imm->timer.TMR1 = MCF5307_TIMER_TMR_PS(45) | // Prescale
MCF5307_TIMER_TMR_CE_NONE | // No capture
MCF5307_TIMER_TMR_ORI | // Output Ref Int enable
MCF5307_TIMER_TMR_FRR | // Free run restart
MCF5307_TIMER_TMR_CLK_STOP | // Stopped clock
MCF5307_TIMER_TMR_RST; // Enabled
imm->timer.TCN1 = 0; // zero count
imm->timer.TRR1 = 10000; // 10 msec period
// start timer
imm->timer.TMR1 |= MCF5307_TIMER_TMR_CLK_MSCLK;
//enable timer1 interrupts
imm->sim.ICR1 = MCF5307_SIM_ICR_AVEC |
MCF5307_SIM_ICR_IL(5) |
0x0003; //MCF5307_SIM_ICR_HI2
imm->sim.IMR &= ~MCF5307_SIM_IMR_TIMER1;
}
/* StartupTask
*
* Task function for system startup task created in main(). Its
* primary duty is to enable the tick interrupt so that the task
* scheduler will get its heartbeats. This must be done after at least
* one task is created and running (e.g. this task) to eliminate a
* race condition in the kernel.
*/
void StartupTask(void *data)
{
extern void StartupMain(void);
OS_ENTER_CRITICAL();
StartTicking();
OS_EXIT_CRITICAL();
StartupMain();
OSTaskDel(OS_PRIO_SELF);
}
/* main
*
* Where everything starts.
*
* Called out of Diab's crt0.s. We assume that we are running
* from downloaded code in the eval board. This means that basic
* hardware services such as the DRAM are present and initialized.
* We will call a pro-forma hardware initialization routine to setup
* our timer tick and any other services we need not supplied by the
* dBUG initialization.
*/
void main()
{
OS_STK StartupTaskStack[1024];
memset(StartupTaskStack, 0x55, sizeof(StartupTaskStack));
EarlyInit();
HookOSVectors();
OSInit();
OSTaskCreate(StartupTask,
(void *)0,
&StartupTaskStack[1023],
OS_LOWEST_PRIO - 4);
OSStart();
/*
* Can't get here, but plug the possible leak with another
* HALT instruction just in case.
*/
asm (" HALT ");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -