⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex1l.c

📁 ucos 在F2812上的移置,内含三个任务,可以在F2812上跑起来,通过测试,在片外SRAM中运行,完整的工程
💻 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 	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], 3);
    OSStart();                                             /* Start multitasking                       */
}

/*$PAGE*/
/*
*********************************************************************************************************
*                                              STARTUP TASK
*********************************************************************************************************
*/
void TaskStart (void *data)
{
    data = data;                                           
    
    InitCpuTimers();

    EALLOW;	
	IER |= M_INT1;										//使能中断组1
    PieVectTable.USER11 = &OSCtxSw;						//当应用程序自动放弃CPU权利时,调用
	PieCtrlRegs.PIEIER1.bit.INTx7 = 1;					//使能定时器T0  
	PieVectTable.TINT0 = &OSTickISR;					//周期设度中断
	EDIS;           
    
    
    ConfigCpuTimer(&CpuTimer0, 120, 10000);				// 120MHz CPU Freq, 10ms  Period 
    OSTaskCreate(Task, (void *)0, (void *)&TaskStk[0][0], 10);
    OSTaskCreate(Task1, (void *)0, (void *)&TaskStk[1][0], 12);
    StartCpuTimer0();    
    EINT;  
	ERTM;    
    
    for (;;)  {    
  
    	*(unsigned int *)0x4c00 |= 0x1;     
        OSTimeDly(25);
        *(unsigned int *)0x4c00 &= (unsigned int)(0XFE);     
        OSTimeDly(25);  
    
       }

        
    
}
/*$PAGE*/
/*
*********************************************************************************************************
*                                                  TASKS
*********************************************************************************************************
*/
void Task1(void *data)
{

    for (;;) {      

      *(unsigned int *)0x4c00 |= 0x2;     
      OSTimeDly(50);
      *(unsigned int *)0x4c00 &= (unsigned int)(0XFD);      
      OSTimeDly(50);  
      
    }
}


void Task (void *data)
{

    //UBYTE err;


    for (;;) {      

     *(unsigned int *)0x4c00 |= 0x4;     
     OSTimeDly(100);
    *(unsigned int *)0x4c00 &= (unsigned int)(0XFB);    
     OSTimeDly(100);  
      
    }
}



// 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;
}




⌨️ 快捷键说明

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