📄 ex1l.c
字号:
/*
*********************************************************************************************************
* uC/OS-II
* The Real-Time Kernel
*
* (c) Copyright 1992-1998, Jean J. Labrosse, Plantation, FL
* All Rights Reserved
*
* V2.00
*
* EXAMPLE #1
*********************************************************************************************************
*/
#include "includes.h"
#include "DSP28_Device.h"
#include "DSP28_Globalprototypes.h"
#include "os_globalstack.h"
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
extern OS_STK TaskStartStk[TASK_STK_SIZE];
extern OS_STK TaskStk[N_TASKS][TASK_STK_SIZE]; /* Tasks stacks */
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void Task(void *data); /* Function prototypes of tasks */
void Task1(void *data);
void TaskStart(void *data); /* Function prototypes of Startup task */
extern void OSTickISR();
void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period);
void InitCpuTimers(void);
struct CPUTIMER_VARS CpuTimer0;
void funcall(int i);
void testasm(int i ,int j,int k);
void OSTickISR();
void OSCtxSw();
/*$PAGE*/
/*
*********************************************************************************************************
* MAIN
*********************************************************************************************************
*/
void main (void)
{
DINT;
EALLOW; // This is needed to write to EALLOW protected registers
InitSysCtrl();
InitPieVectTable();
InitPieCtrl();
EDIS;
OSInit(); /* Initialize uC/OS-II */
OSTaskCreate(TaskStart, (void *)0, (void *)&TaskStartStk[0], 0);
OSStart(); /* Start multitasking */
}
/*$PAGE*/
/*
*********************************************************************************************************
* STARTUP TASK
*********************************************************************************************************
*/
void TaskStart (void *data)
{
UBYTE i;
data = data; /* Prevent compiler warning */
InitCpuTimers();
EALLOW; // This is needed to write to EALLOW protected registers
// Enable CPU INT1 which is connected to CPU-Timer 0:
IER |= M_INT1;
// Enable TINT0 in the PIE: Group 1 interrupt 7
PieVectTable.USER11 = &OSCtxSw;
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
PieVectTable.TINT0 = &OSTickISR;
EDIS; // This is needed to disable write to EALLOW protected registers
ConfigCpuTimer(&CpuTimer0, 100, 1000000); // 100MHz CPU Freq, 1 second Period (in uSeconds)
OSTaskCreate(Task, (void *)0, (void *)&TaskStk[0][0], 10);
OSTaskCreate(Task1, (void *)0, (void *)&TaskStk[1][0], 12);
StartCpuTimer0();
EINT;
ERTM;
for (;;) {
i = 3;
i = 3 +4;
OSTimeDly(1);
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* TASKS
*********************************************************************************************************
*/
void Task1(void *data)
{
UBYTE x1;
for (;;) {
x1 = 3;
OSTimeDly(6);
}
}
void Task (void *data)
{
UBYTE x;
UBYTE y;
UBYTE err;
for (;;) {
x = 3;
y = 4;
x = y;
y = x ;
OSTimeDly(4);
}
}
void funcall(int i)
{
i = i;
}
void testasm(int i ,int j,int k)
{
i = i;
j = j;
k = k;
/*
int j;
OSTCBHighRdy->OSTCBStkPtr[15] = 12;
OSTCBHighRdy->OSTCBStkPtr[3] = 4;
j = OSTCBHighRdy->OSTCBStkPtr[15];
*/
}
void SaveSetting()
{
//OSTCBHighRdy->OSTCBStkPtr[0] = 4;
//OSTCBHighRdy->OSTCBStkPtr[1] = 8;
//OSTCBHighRdy->OSTCBStkPtr[2] = 9;
OSIntNesting++;
}
// CpuTimer 1 and CpuTimer2 are reserved for DSP BIOS & other RTOS
//struct CPUTIMER_VARS CpuTimer1;
//struct CPUTIMER_VARS CpuTimer2;
//---------------------------------------------------------------------------
// InitCpuTimers:
//---------------------------------------------------------------------------
// This function initializes all three CPU timers to a known state.
//
void InitCpuTimers(void)
{
// CPU Timer 0
// Initialize address pointers to respective timer registers:
CpuTimer0.RegsAddr = &CpuTimer0Regs;
// Initialize timer period to maximum:
CpuTimer0Regs.PRD.all = 0xFFFFFFFF;
// Initialize pre-scale counter to divide by 1 (SYSCLKOUT):
CpuTimer0Regs.TPR.all = 0;
CpuTimer0Regs.TPRH.all = 0;
// Make sure timer is stopped:
CpuTimer0Regs.TCR.bit.TSS = 1;
// Reload all counter register with period value:
CpuTimer0Regs.TCR.bit.TRB = 1;
// Reset interrupt counters:
CpuTimer0.InterruptCount = 0;
// CpuTimer 1 and CpuTimer2 are reserved for DSP BIOS & other RTOS
// Do not use these two timers if you ever plan on integrating
// DSP-BIOS or another realtime OS.
//
// For this reason, the code to manipulate these two timers is
// commented out and not used in these examples.
// Initialize address pointers to respective timer registers:
// CpuTimer1.RegsAddr = &CpuTimer1Regs;
// CpuTimer2.RegsAddr = &CpuTimer2Regs;
// Initialize timer period to maximum:
// CpuTimer1Regs.PRD.all = 0xFFFFFFFF;
// CpuTimer2Regs.PRD.all = 0xFFFFFFFF;
// Make sure timers are stopped:
// CpuTimer1Regs.TCR.bit.TSS = 1;
// CpuTimer2Regs.TCR.bit.TSS = 1;
// Reload all counter register with period value:
// CpuTimer1Regs.TCR.bit.TRB = 1;
// CpuTimer2Regs.TCR.bit.TRB = 1;
// Reset interrupt counters:
// CpuTimer1.InterruptCount = 0;
// CpuTimer2.InterruptCount = 0;
}
//---------------------------------------------------------------------------
// ConfigCpuTimer:
//---------------------------------------------------------------------------
// This function initializes the selected timer to the period specified
// by the "Freq" and "Period" parameters. The "Freq" is entered as "MHz"
// and the period in "uSeconds". The timer is held in the stopped state
// after configuration.
//
void ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period)
{
Uint32 temp;
// Initialize timer period:
Timer->CPUFreqInMHz = Freq;
Timer->PeriodInUSec = Period;
//temp = (long) (Freq * Period);
temp = 100000000;
Timer->RegsAddr->PRD.all = temp;
// Set pre-scale counter to divide by 1 (SYSCLKOUT):
Timer->RegsAddr->TPR.all = 0;
Timer->RegsAddr->TPRH.all = 0;
// Initialize timer control register:
Timer->RegsAddr->TCR.bit.POL = 0; // 0 = Pulse Low
Timer->RegsAddr->TCR.bit.TOG = 0; // 0 = No Toggle, POL bit defines action
Timer->RegsAddr->TCR.bit.TSS = 1; // 1 = Stop timer, 0 = Start/Restart Timer
Timer->RegsAddr->TCR.bit.TRB = 1; // 1 = reload timer
Timer->RegsAddr->TCR.bit.FRCEN = 0; // Force output enable (not used)
Timer->RegsAddr->TCR.bit.PWIDTH = 7; // 7+1 = 8 SYSCLKOUT cycle pulse width
Timer->RegsAddr->TCR.bit.SOFT = 1;
Timer->RegsAddr->TCR.bit.FREE = 1; // Timer Free Run
Timer->RegsAddr->TCR.bit.TIE = 1; // 0 = Disable/ 1 = Enable Timer Interrupt
// Reset interrupt counter:
Timer->InterruptCount = 0;
}
void test()
{
//PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
int *p;
//p = OSTCBHighRdy->OSTCBStkPtr;
OSTCBCur->OSTCBStkPtr = p;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -