📄 tcof.c
字号:
/*********************************************************************
* Filename: TCOF.c
*
* Description: This code checks the functionality of the TCOFn bit.
*
* CAN bit timing registers are configured for 1 Mbps. After a while, the
* MSB of the TSC would become 1, which would set TCOFn bit and assert
* a CAN interrupt.
*
* Last update: 12/25/2002
*********************************************************************/
#include "DSP28_Device.h"
// Variable declarations
int int0count = 0; // Counter to track the # of level 0 interrupts
int int1count = 0; // Counter to track the # of level 1 interrupts
long i;
void InitECan(void);
// Prototype statements for functions found within this file.
interrupt void eCAN0INT_ISR(void);
interrupt void eCAN1INT_ISR(void);
/* Create a shadow register structure for the CAN control registers. This is
needed, since, only 32-bit access is allowed to these registers. 16-bit access
to these registers could potentially corrupt the register contents. This is
especially true while writing to a bit (or group of bits) among bits 16 - 31 */
struct ECAN_REGS ECanaShadow;
main()
{
/* Initialize the CAN module */
InitECan();
/* Initialize PIE vector table To a Known State: */
// The PIE vector table is initialized with pointers to shell "Interrupt
// Service Routines (ISR)". The shell routines are found in DSP28_DefaultIsr.c.
// Insert user specific ISR code in the appropriate shell ISR routine in
// the DSP28_DefaultIsr.c file.
// InitPieVectTable(); // uncomment this line if the shell ISR routines are needed
// This function is found in DSP28_PieVect.c. It populates the PIE vector table
// with pointers to the shell ISR functions found in DSP28_DefaultIsr.c. This
// function is not useful in this code because the user-specific ISR is present
// in this file itself. The shell ISR routine in the DSP28_DefaultIsr.c file is
// not used. If the shell ISR routines are needed, uncomment this line and add
// DSP28_PieVect.c & DSP28_DefaultIsr.c files to the project
/* Disable and clear all CPU interrupts: */
DINT;
IER = 0x0000;
IFR = 0x0000;
/* Initialize Pie Control Registers To Default State */
InitPieCtrl(); // This function is found in the DSP28_PieCtrl.c file.
/* Initialize the Time Stamp Counter (TSC) */
ECanaRegs.CANTSC = 0x7FF00000;
/* Configure CAN interrupts */
ECanaShadow.CANGIM.all = 0;
ECanaShadow.CANGIM.bit.TCOM = 1; // Enable "Timer counter overflow" int
ECanaShadow.CANGIM.bit.GIL = 0; // GIL value determines ECAN(0/1)INT
ECanaShadow.CANGIM.bit.I0EN = 1; // Enable the int line chosen by GIL
ECanaShadow.CANGIM.bit.I1EN = 1; // Enable the int line chosen by GIL
ECanaRegs.CANGIM.all = ECanaShadow.CANGIM.all;
/* Reassign ISRs. i.e. reassign the PIE vector for ECAN0INTA_ISR and ECAN0INTA_ISR
to point to a different ISR than the shell routine found in DSP28_DefaultIsr.c.
This is done if the user does not want to use the shell ISR routine but instead
wants to embed the ISR in this file itself. */
PieVectTable.ECAN0INTA = &eCAN0INT_ISR;
PieVectTable.ECAN1INTA = &eCAN1INT_ISR;
/* Configure PIE interrupts */
PieCtrlRegs.PIECRTL.bit.ENPIE = 1; // Enable vector fetching from PIE block
PieCtrlRegs.PIEACK.bit.ACK9 = 1; // Enables PIE to drive a pulse into the CPU
// The 'TCOM' interrupt can be asserted in either of the eCAN interrupt lines
// Comment out the unwanted line...
PieCtrlRegs.PIEIER9.bit.INTx5 = 1; // Enable INTx.5 of INT9 (eCAN0INT)
PieCtrlRegs.PIEIER9.bit.INTx6 = 1; // Enable INTx.6 of INT9 (eCAN1INT)
/* Configure system interrupts */
IER |= 0x0100; // Enable INT9 of CPU
EINT; // Global enable of interrupts
while(1) {}
}
/* --------------------------------------------------- */
/* ISR for PIE INT9.5 */
/* Connected to HECC0-INTA eCAN */
/* ----------------------------------------------------*/
interrupt void eCAN0INT_ISR(void) // eCAN
{
asm (" NOP");
// Clear TCOIF0 flag bit..
ECanaShadow.CANGIF0.all = ECanaRegs.CANGIF0.all;
ECanaShadow.CANGIF0.bit.TCOF0 = 1;
ECanaRegs.CANGIF0.all = ECanaShadow.CANGIF0.all;
int0count++; // Interrupt counter
// Re-enable core interrupts and CAN int from PIE module
PieCtrlRegs.PIEACK.bit.ACK9 = 1; // Enables PIE to drive a pulse into the CPU
IER |= 0x0100; // Enable INT9
EINT;
return;
}
/* --------------------------------------------------- */
/* ISR for PIE INT9.6 */
/* Connected to HECC1-INTA eCAN */
/* ----------------------------------------------------*/
interrupt void eCAN1INT_ISR(void) // eCAN
{
asm (" NOP");
// Clear TCOIF1 flag bit..
ECanaShadow.CANGIF1.all = ECanaRegs.CANGIF1.all;
ECanaShadow.CANGIF1.bit.TCOF1 = 1;
ECanaRegs.CANGIF1.all = ECanaShadow.CANGIF1.all;
int1count++; // Interrupt counter
// Re-enable core interrupts and CAN int from PIE module
PieCtrlRegs.PIEACK.bit.ACK9 = 1; // Enables PIE to drive a pulse into the CPU
IER |= 0x0100; // Enable INT9
EINT;
return;
}
/*
The TSC is a free-running counter and is independant of transmission/reception.
The mailboxes need not be enabled for the counter to run.
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -