|
|
|
// Some comments about author
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
|
|
|
|
#include "Periphery.h"
|
|
|
|
#include "System/SystemContol.h"
|
|
|
|
|
|
|
|
#include "DSP28335/SCIB.h"
|
|
|
|
#include "DSP28335/SCIBase.h"
|
|
|
|
|
|
|
|
|
|
|
|
//Functions declarations
|
|
|
|
void idle_loop(void);
|
|
|
|
|
|
|
|
interrupt void cpu_timer0_isr(void);
|
|
|
|
interrupt void cpu_timer1_isr(void);
|
|
|
|
interrupt void cana_isr(void);
|
|
|
|
|
|
|
|
Periphery periphery;
|
|
|
|
|
|
|
|
volatile uint16_t infCounter = 0;
|
|
|
|
volatile uint16_t canISRcounter = 0;
|
|
|
|
volatile uint16_t canBoxISRcounter = 0;
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
|
|
|
ServiceDog();
|
|
|
|
DisableDog();
|
|
|
|
|
|
|
|
InitSysCtrl();
|
|
|
|
|
|
|
|
DINT;
|
|
|
|
|
|
|
|
InitPieCtrl();
|
|
|
|
|
|
|
|
IER = 0x0000;
|
|
|
|
IFR = 0x0000;
|
|
|
|
|
|
|
|
InitPieVectTable();
|
|
|
|
|
|
|
|
EALLOW;
|
|
|
|
PieVectTable.TINT0 = &cpu_timer0_isr;
|
|
|
|
PieVectTable.XINT13 = &cpu_timer1_isr;
|
|
|
|
PieVectTable.ECAN0INTA = &cana_isr;
|
|
|
|
PieVectTable.ECAN1INTA = &cana_box_isr;
|
|
|
|
EDIS;
|
|
|
|
|
|
|
|
MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
|
|
|
|
|
|
|
|
InitCpuTimers();
|
|
|
|
ConfigCpuTimer(&CpuTimer0, 150, 1000); // 1ms
|
|
|
|
ConfigCpuTimer(&CpuTimer1, 150, 5000); // 5ms
|
|
|
|
|
|
|
|
IER |= M_INT1; // Enable CPU Interrupt 1
|
|
|
|
IER |= M_INT9; // Enable CPU Interrupt 9
|
|
|
|
IER |= M_INT13; // Enable CPU Interrupt 13
|
|
|
|
|
|
|
|
PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
|
|
|
|
PieCtrlRegs.PIEIER9.bit.INTx5 = 1; // from 5 to 8
|
|
|
|
PieCtrlRegs.PIEIER9.bit.INTx6 = 1;
|
|
|
|
|
|
|
|
periphery.config();
|
|
|
|
periphery.updateVersionFPGA();
|
|
|
|
periphery.getModbusConfiguration();
|
|
|
|
SYSCTRL::initModbusTable(periphery);
|
|
|
|
|
|
|
|
// Enable global Interrupts and higher priority real-time debug events:
|
|
|
|
EINT; // Enable Global interrupt INTM
|
|
|
|
ERTM; // Enable Global realtime interrupt DBGM
|
|
|
|
|
|
|
|
|
|
|
|
CpuTimer0.RegsAddr->TCR.bit.TSS = 0;
|
|
|
|
CpuTimer1.RegsAddr->TCR.bit.TSS = 0;
|
|
|
|
|
|
|
|
idle_loop();
|
|
|
|
//
|
|
|
|
}//end main()
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
void idle_loop()
|
|
|
|
{
|
|
|
|
while (true)
|
|
|
|
{
|
|
|
|
infCounter++;
|
|
|
|
periphery.receiveModbusParameters();
|
|
|
|
|
|
|
|
periphery.modbusRTU.execute();
|
|
|
|
periphery.receiveCpuModbusData();
|
|
|
|
|
|
|
|
}//end while
|
|
|
|
|
|
|
|
}//end idle_loop()
|
|
|
|
|
|
|
|
|
|
|
|
interrupt void cpu_timer0_isr(void)
|
|
|
|
{
|
|
|
|
periphery.processDigitalOutput();
|
|
|
|
periphery.sendModbusDataToCPU();
|
|
|
|
|
|
|
|
PieCtrlRegs.PIEACK.all |= PIEACK_GROUP1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interrupt void cpu_timer1_isr(){
|
|
|
|
CpuTimer1.InterruptCount++;
|
|
|
|
|
|
|
|
periphery.processDigitalInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
interrupt void cana_isr(void){
|
|
|
|
canISRcounter++;
|
|
|
|
|
|
|
|
periphery.canSystemInterruptHandle();
|
|
|
|
|
|
|
|
PieCtrlRegs.PIEACK.all |= PIEACK_GROUP9;
|
|
|
|
}
|