📄 main.c
字号:
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
#include "..\OS\28335cpu\includes.h"
#include "F28335_example.h" // Main include file
// Determine when the shift to right justify the data takes place
// Only one of these should be defined as 1.
// The other two should be defined as 0.
#define POST_SHIFT 0 // Shift results after the entire sample table is full
#define INLINE_SHIFT 1 // Shift results as the data is taken from the results regsiter
#define NO_SHIFT 0 // Do not shift the results
// ADC start parameters
#if (CPU_FRQ_150MHZ) // Default - 150 MHz SYSCLKOUT
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz
#endif
#define ADC_CKPS 0x0 // ADC module clock = HSPCLK/1 = 25.5MHz/(1) = 25.0 MHz
#define ADC_SHCLK 0x1 // S/H width in ADC module periods = 2 ADC cycle
#define AVG 1000 // Average sample limit
#define ZOFFSET 0x00 // Average Zero offset
#define BUF_SIZE 360 // Sample buffer size
/*
*********************************************************************************************************
* CONSTANTS
*********************************************************************************************************
*/
#define TASK_STK_SIZE 30
#define N_TASKS 2
OS_STK TaskStartStk[TASK_STK_SIZE];
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 Task2(void *data);
void OSTickISR();
/*$PAGE*/
/*
*********************************************************************************************************
* MAIN
*********************************************************************************************************
*/
interrupt void ISRTimer0(void);
interrupt void ISRTimer1(void);
interrupt void ISRTimer2(void);
//--- Global Variables
Uint16 AdcBuf[ADC_BUF_LEN]; // ADC data buffer allocation
Uint32 PwmDuty; // Measured PWM duty cycle
Uint32 PwmPeriod; // Measured PWM period
void main(void)
{
//--- CPU Initialization
InitSysCtrl(); // Initialize the CPU
InitWatchdog(); // Initialize the Watchdog Timer
InitGpio(); // Initialize the shared GPIO pins
InitXintf(); // Initialize the external memory interface
//#ifdef EXAMPLE_FLASH // EXAMPLE_FLASH, if defined, is in CCS project options
//--- Copy all Flash sections that need to run from RAM (use memcpy() from RTS library)
// Section secureRamFuncs contains user defined code that runs from CSM secured RAM
// memcpy( &secureRamFuncs_runstart,
// &secureRamFuncs_loadstart,
// &secureRamFuncs_loadend - &secureRamFuncs_loadstart);
//--- Initialize the Flash and OTP
// InitFlash(); // Initialize the Flash
//#endif
DINT;
// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl(); // Initialize and enable the PIE
InitPieVectTable();
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TINT0 = &OSTickISR;//ISRTimer0;//
PieVectTable.USER11 = &OSCtxSw;//任务切换模拟中断 用指令asm(" TRAP #30")来调用实现
EDIS; // This is needed to disable write to EALLOW protected registers
// Step 4. Initialize the Device Peripheral. This function can be
// found in DSP2833x_CpuTimers.c
InitCpuTimers(); // For this example, only initialize the Cpu Timers
// Configure CPU-Timer 0, 1, and 2 to interrupt every second:
// 150MHz CPU Freq, 1 second Period (in uSeconds)
ConfigCpuTimer(&CpuTimer0, 150, 1000);//初始化为1MS中断一次 作为OS时钟
// Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
// which is connected to CPU-Timer 1, and CPU int 14, which is connected
// to CPU-Timer 2:
IER |= M_INT1;
// Enable TINT0 in the PIE: Group 1 interrupt 7
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
// Timer 1 connected to int13 by yang
XIntruptRegs.XNMICR.bit.SELECT= 0;
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
OSInit(); /* Initialize uC/OS-II */
OSTaskCreate(Task, (void *)0, (void *)&TaskStk[0][0], 1);
OSTaskCreate(Task1, (void *)0, (void *)&TaskStk[1][0], 2);
OSStart();
while(1){
}
}
/*
*********************************************************************************************************
* TASKS
*********************************************************************************************************
*/
int cnt=0;
int x=0;
int k=0;
void Task1(void *data)
{
while(1) {
OSTimeDly(500);
cnt++;
x=x+cnt*20;
}
}
void Task (void *data)
{
StartCpuTimer0();
OSTaskCreate(Task2, (void *)0, (void *)&TaskStk[2][0], 3);
// OSStatInit();
while(1) {
OSTimeDly(100);
x++;
}
}
void Task2(void *data)
{
while(1) {
OSTimeDly(1000);
k++;
x=x/k;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -