📄 intc_example6.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_example6.c
*
* @path $(CSLPATH)\example\c64xplus\intc\intc_example6\src
*
* @desc Example of INTC
*
* ============================================================================
* @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.
* Some additional CSL APIs are tested here compared to intc_example5.
* 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 and Disables exceptions
* 7. Again restores the exceptions
* 8. Intializes and opens the timer module
* 9. Sets up the timer modules
* 10. starts the timers
* 11. Wait for exceptions to occur
* 12. 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_example6.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 <cslr_chip.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;
volatile Int failed = 0;
extern cregister volatile Uint32 CSR;
extern cregister volatile Uint32 TSR;
extern cregister volatile Uint32 EFR;
/* Intc Variable declarations */
CSL_IntcContext context;
CSL_IntcEventHandlerRecord Record[3];
CSL_IntcEventHandlerRecord EventHandler[30];
/* ============================================================================
*
* @func main
*
* @desc
* This is the main routine,which invokes the example
* ============================================================================
*/
void main()
{
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 and Disables exceptions
* 7. Again restores the exceptions
* 8. Intializes and opens the timer module
* 9. Sets up the timer modules
* 10. starts the timers
* 11. Wait for exceptions to occur
* 12. print the result
* 13. 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;
Uint32 loadValue = 100;
Uint32 prevState;
volatile Uint16 delay;
/* 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;
}
/* Enabling Global interrupts */
status = CSL_intcGlobalEnable(&state);
if (status != CSL_SOK) {
printf ("Intc global enable failed\n");
return;
}
/* Global Exceptions enable */
status = CSL_intcGlobalExcepEnable ();
if (status != CSL_SOK) {
printf ("Intc global exceptions enable failed\n");
return;
}
/* Global External Exceptions enable */
status = CSL_intcGlobalExtExcepEnable ();
if (status != CSL_SOK) {
printf ("Intc global external exceptions enable failed\n");
return;
}
/* Disabling Global interrupts */
status = CSL_intcGlobalDisable(&state);
if (status != CSL_SOK) {
printf ("Intc global disable failed\n");
return;
}
/* Restore Global interrupts */
status = CSL_intcGlobalRestore(state);
if (status != CSL_SOK) {
printf ("Intc global restore failed\n");
return;
}
/* Check for all interrupt are enable are not */
if (CSL_FEXT(CSR,CHIP_CSR_GIE) != CSL_CHIP_CSR_GIE_ENABLE)
failed++;
/* 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;
}
/* Enable timer Exceptions */
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;
}
/* Disable timer Exceptions */
status = CSL_intcExcepAllDisable (CSL_INTC_EXCEP_0TO31,
(1 << (CSL_INTC_EVENTID_TINTLO6))
|(1 << (CSL_INTC_EVENTID_TINTLO7)),
&prevState);
if (status != CSL_SOK) {
printf("Intc disabling timer exceptions failed\n");
return;
}
/* Restore timer Exceptions */
status = CSL_intcExcepAllRestore(CSL_INTC_EXCEP_0TO31,prevState);
if (status != CSL_SOK) {
printf("Intc restore timer exceptions failed\n");
return;
}
/* Disabling these exceptions for a while */
if (((CSL_IntcRegsOvly)CSL_INTC_0_REGS)->EXPMASK[CSL_INTC_EXCEP_0TO31] != prevState)
failed++;
/* Check leftover Exception routines */
if (CSL_FEXT(TSR,CHIP_TSR_GEE) != CSL_CHIP_TSR_GEE_ENABLE)
failed ++;
/* Initialize GP timer CSL module */
CSL_tmrInit(NULL);
/* Open timer 6 and Timer 7 */
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 the timer */
CSL_tmrHwSetup(hTmr6, &hwSetup6);
CSL_tmrHwSetup(hTmr7, &hwSetup7);
/* Load the timer6 period register */
CSL_tmrHwControl(hTmr6, CSL_TMR_CMD_LOAD_PRDLO, (void *)&loadValue);
/* Load the timer7 period register */
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);
if( failed > 0)
printf("Intc Example test case failed \n");
/* 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 ();
* =============================================================================
*/
volatile Uint32 temp;
#pragma NMI_INTERRUPT(NMI_handler);
void NMI_handler()
{
Uint32 excepStatus1;
Uint32 rcvExcep0to31;
Uint32 evtMask;
Int evtId;
/* Get the exception status */
CSL_intcExcepAllStatus(CSL_INTC_EXCEP_0TO31,&excepStatus1);
temp = EFR;
while (excepStatus1) {
rcvExcep0to31 = excepStatus1;
CSL_intcExcepAllClear(CSL_INTC_EXCEP_0TO31,excepStatus1);
evtMask = (1 << (4));
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 + -