📄 intc_example5.c
字号:
/* ===========================================================================
* Copyright (c) Texas Instruments Inc 2002, 2003, 2004, 2005
*
* Use of this software is controlled by the terms and conditions found in the
* license agreement under which this software has been supplied.
* ==========================================================================
*/
/** ===========================================================================
* @file Intc_example5.c
*
* @path $(CSLPATH)\example\c64xplus\intc\intc_example5\src
*
* @desc Example of INTC
*
* ============================================================================
* @n Target Platform: TCI6486 VDB
* ============================================================================
* @n <b> Example Description </b>
* @n This example demonstrating usage of the exception handling. Timer 6,7
* are treated as exceptions and they are cleared accordingly
* This example,
* 1. Intializes Intc module and the CPU vector table, dispatcher
* 2. Enables the external exceptions
* 3. Hook up the NMI Isr
* 4. Opens a handle for the Timer 6 and Timer 7 Event as an
* exception event
* 5. Plugs timers event handler
* 6. Enabls timers exception
* 7. Intializes and opens the timer module
* 8. Sets up the timer modules
* 9. starts the timers
* 10. Wait for exceptions to occur
* 11. print the result
*
* =============================================================================
*
* <b> Procedure to run the example </b>
* @verbatim
* 1. Configure the CCS setup to work with the emulator being used
* 2. Please refer CCS manual for setup configuration and loading
* proper GEL file
* 3. Launch CCS window
* 4. Open project Intc_example5.pjt
* 5. Build the project and load the .out file of the project.
*
* @endverbatim
*
*/
/* ============================================================================
* Revision History
* ===============
* 2-July-2004 Ruchika Kharwar File Created.
*
* 14-Nov-2005 ds changed to support timer CSL
*
* ============================================================================
*/
#include <csl_intc.h>
#include <csl_intcAux.h>
#include <csl_tmr.h>
#include <soc.h>
#include <stdio.h>
/* Forward declarations */
void eventTimer6Handler(void *handle);
void eventTimer7Handler(void *handle);
void NMI_handler();
void intc_example (void);
/* Global variables declarations */
volatile Int timer6Cnt = 0;
volatile Int timer7Cnt = 0;
volatile Int passed = 0;
Uint32 excepStatus1;
/* Intc Variable declarations */
CSL_IntcEventHandlerRecord EventHandler[30];
CSL_IntcContext context;
CSL_IntcEventHandlerRecord Record[3];
/* ============================================================================
*
* @func main
*
* @desc
* This is the main routine,which invokes the example
* ============================================================================
*/
void main (void)
{
printf ("Demonstrating the exception handling \n");
/* Invoke example */
intc_example ();
return;
}
/*
* =============================================================================
* @func intc_example
*
* @arg None
*
* @desc
* Demonstrating usage of the exception handling. Timer 6,7 are treated
* as exceptions and they are cleared accordingly
* It implements following steps
* 1. Intializes Intc module and the CPU vector table, dispatcher
* 2. Enables the external exceptions
* 3. Hook up the NMI Isr
* 4. Opens a handle for the Timer6 and Timer7 Event as an
* exception event
* 5. Plugs timers event handler
* 6. Enabls timers exception
* 7. Intializes and opens the timer module
* 8. Sets up the timer modules
* 9. starts the timers
* 10. Wait for exceptions to occur
* 11. print the result
* 12. Close intc and timer module
*
* @return
* None
*
* @eg
* intc_example ();
* =============================================================================
*/
void intc_example (void)
{
CSL_IntcObj intcTimerObj6;
CSL_IntcObj intcTimerObj7;
CSL_IntcHandle hIntcTimer6;
CSL_IntcHandle hIntcTimer7;
CSL_IntcGlobalEnableState state;
CSL_IntcEventHandlerRecord eventRecord;
CSL_IntcParam vectId;
CSL_TmrHandle hTmr6;
CSL_TmrHandle hTmr7;
CSL_TmrObj tmrObj6;
CSL_TmrObj tmrObj7;
CSL_Status status;
CSL_TmrHwSetup hwSetup6 = CSL_TMR_HWSETUP_DEFAULTS;
CSL_TmrHwSetup hwSetup7 = CSL_TMR_HWSETUP_DEFAULTS;
CSL_TmrEnamode TimeCountMode = CSL_TMR_ENAMODE_ENABLE;
volatile Uint32 delay;
Uint32 LoadValue = 100;
/* Init the Interrupt Controller
* Initializes the CPU vector table, dispatcher
*/
context.numEvtEntries = 3;
context.eventhandlerRecord = Record;
status = CSL_intcInit(&context);
if (status != CSL_SOK) {
printf("Intc initialization failed\n");
return;
}
/* Enable NMIs */
status = CSL_intcGlobalNmiEnable();
if (status != CSL_SOK) {
printf("Intc global NMI enable failed\n");
return;
}
/* Enable Global Interrupts */
status = CSL_intcGlobalEnable(&state);
if (status != CSL_SOK) {
printf ("Intc global enable failed\n");
return;
}
/* Enable global exceptions */
status = CSL_intcGlobalExcepEnable ();
if (status != CSL_SOK) {
printf ("Intc global exceptions enable failed\n");
return;
}
/* Enable external exceptions */
status = CSL_intcGlobalExtExcepEnable ();
if (status != CSL_SOK) {
printf ("Intc global external exceptions enable failed\n");
return;
}
/* Hook up the NMI Isr */
status = CSL_intcHookIsr(CSL_INTC_VECTID_NMI,NMI_handler);
if (status != CSL_SOK) {
printf ("Intc hook up NMI Isr failed\n");
return;
}
/* Opening a handle for the Timer 6 Event as an exception event */
vectId = CSL_INTC_VECTID_EXCEP;
hIntcTimer6 = CSL_intcOpen (&intcTimerObj6, CSL_INTC_EVENTID_TINTLO6,
&vectId , NULL);
if (hIntcTimer6 == NULL) {
printf("Intc open failed for timer6 event \n");
return;
}
/* Plug timer6 event handler */
eventRecord.handler = &eventTimer6Handler;
eventRecord.arg = hIntcTimer6;
status = CSL_intcPlugEventHandler(hIntcTimer6,&eventRecord);
if (status != CSL_SOK) {
printf("Intc plug event handler for timer6 event failed\n");
return;
}
/* Opening a handle for the Timer 7 Event as an exception event */
vectId = CSL_INTC_VECTID_EXCEP;
hIntcTimer7 = CSL_intcOpen (&intcTimerObj7, CSL_INTC_EVENTID_TINTLO7,
&vectId , NULL);
if (hIntcTimer7 == NULL) {
printf("Intc open failed for timer7 event\n");
return;
}
/* Plug timer7 event handler */
eventRecord.handler = &eventTimer7Handler;
eventRecord.arg = hIntcTimer7;
status = CSL_intcPlugEventHandler(hIntcTimer7,&eventRecord);
if (status != CSL_SOK) {
printf("Intc plug event handler for timer7 event failed\n");
return;
}
/* Enabling timers exception */
status = CSL_intcExcepAllEnable (CSL_INTC_EXCEP_0TO31,
(1 << (CSL_INTC_EVENTID_TINTLO6))
|(1 << (CSL_INTC_EVENTID_TINTLO7)), NULL);
if (status != CSL_SOK) {
printf("Intc enabling timer exceptions failed\n");
return;
}
/* Initialize GP timer CSL module */
CSL_tmrInit(NULL);
/* Open the timer6 and timer7 */
hTmr6 = CSL_tmrOpen(&tmrObj6, CSL_TMR_6, NULL, &status);
hTmr7 = CSL_tmrOpen(&tmrObj7, CSL_TMR_7, NULL, &status);
/* Stop the GP Timer */
status = CSL_tmrHwControl(hTmr6, CSL_TMR_CMD_RESET_TIMLO, NULL);
/* Stop the GP Timer */
status = CSL_tmrHwControl(hTmr7, CSL_TMR_CMD_RESET_TIMLO, NULL);
/* Set the timer mode to unchained dual mode */
hwSetup6.tmrTimerMode = CSL_TMR_TIMMODE_DUAL_UNCHAINED;
/* Set the timer mode to unchained dual mode */
hwSetup7.tmrTimerMode = CSL_TMR_TIMMODE_DUAL_UNCHAINED;
/* Setup timers */
CSL_tmrHwSetup(hTmr6, &hwSetup6);
CSL_tmrHwSetup(hTmr7, &hwSetup7);
/* Load the period register of timer6 */
CSL_tmrHwControl(hTmr6, CSL_TMR_CMD_LOAD_PRDLO, (void *)&LoadValue);
/* Load the period register of timer7 */
CSL_tmrHwControl(hTmr7, CSL_TMR_CMD_LOAD_PRDLO, (void *)&LoadValue);
/* Start the timer6 with one shot*/
CSL_tmrHwControl(hTmr6, CSL_TMR_CMD_START_TIMLO, (void *)&TimeCountMode);
/* Start the timer7 with one shot*/
CSL_tmrHwControl(hTmr7, CSL_TMR_CMD_START_TIMLO, (void *)&TimeCountMode);
/* Waits for exception to generate */
while (!passed);
/* Wait for some time */
for (delay = 0; delay < 1000; delay++);
/* Stop the GP Timer */
status = CSL_tmrHwControl(hTmr6, CSL_TMR_CMD_RESET_TIMLO, NULL);
/* Stop the GP Timer */
status = CSL_tmrHwControl(hTmr7, CSL_TMR_CMD_RESET_TIMLO, NULL);
CSL_tmrClose (hTmr6);
CSL_tmrClose (hTmr7);
/* Close Intc CSL */
CSL_intcClose(hIntcTimer6);
/* Close Intc CSL */
CSL_intcClose(hIntcTimer7);
printf ("Demonstrating the exception handling Done\n");
}
/*
* =============================================================================
* @func NMI_handler
*
* @desc
* This is the interrupt exception handler
*
* @arg
* None
*
*
* @eg
* NMI_handler ();
* =============================================================================
*/
#pragma NMI_INTERRUPT(NMI_handler);
void NMI_handler (void)
{
Uint32 excepStatus1;
Uint32 rcvExcep0to31;
Uint32 evtMask;
Int evtId;
/* Get the exception status */
CSL_intcExcepAllStatus(CSL_INTC_EXCEP_0TO31,&excepStatus1);
while (excepStatus1) {
rcvExcep0to31 = excepStatus1;
CSL_intcExcepAllClear(CSL_INTC_EXCEP_0TO31,excepStatus1);
evtMask = 16;
evtId = 4;
do {
if (rcvExcep0to31 & evtMask) {
CSL_intcInvokeEventHandle(evtId);
rcvExcep0to31 &= ~evtMask;
}
evtMask = evtMask << 1;
evtId++;
} while (rcvExcep0to31);
CSL_intcExcepAllStatus(CSL_INTC_EXCEP_0TO31,&excepStatus1);
}
CSL_intcExcepAllDisable(CSL_INTC_EXCEP_0TO31,(1 << (CSL_INTC_EVENTID_TINTLO6))
|(1 << (CSL_INTC_EVENTID_TINTLO7)) ,NULL);
passed++;
}
/*
* =============================================================================
* @func eventTimer6Handler
*
* @desc
* This is the interrupt handler for timer 6
*
* @arg
* None
*
*
* @eg
* eventTimer6Handler ();
* =============================================================================
*/
void eventTimer6Handler (
void *handle
)
{
timer6Cnt++;
}
/*
* =============================================================================
* @func eventTimer7Handler
*
* @desc
* This is the interrupt handler for timer 7
*
* @arg
* None
*
*
* @eg
* eventTimer7Handler ();
* =============================================================================
*/
void eventTimer7Handler (
void *handle
)
{
timer7Cnt++;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -