Hi
How to configure GPIO interrupt and test on Keystone I devices - C6678 ?
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi
How to configure GPIO interrupt and test on Keystone I devices - C6678 ?
How to configure GPIO interrupt and test on Keystone I devices - C6678 ?
Pre-requisites:
1. Download and install "PROCESSOR-SDK-RTOS-C667x 06_03_00_106"
from https://software-dl.ti.com/processor-sdk-rtos/esd/C667x/latest/index_FDS.html
( Please install the SDK in the recommended path: C:\ti\)
2. Download and install CCS 9.3 , https://www.ti.com/tool/download/CCSTUDIO/9.3.0.00012
( Please install in the recommended path: C:\ti\)
3. Please download this document and have a look.
2502.Configuring Interrupts K1.pdf
https://www.ti.com/lit/ug/sprugv1/sprugv1.pdf
Steps:
1. Create an empty project using CCS.
2. Include the files, GPIO_Interrupt_sample.c and test_lnk.cmd to the project.
Download the files
1.GPIO_Interrupt_sample.c
#include "ti/csl/csl_chip.h" #include "ti/csl/csl_chipAux.h" #include "ti/csl/src/intc/csl_intc.h" #include "ti/csl/csl_gpio.h" #include "ti/csl/csl_gpioAux.h" #include <ti/csl/csl_tsc.h> // check the path where the csl_tsc.h is located. Accordingly include the path of the file. #include <stdio.h> CSL_IntcContext intcContext; CSL_IntcEventHandlerRecord EventHandler[30]; CSL_IntcObj intcObj; CSL_IntcHandle hTest; CSL_IntcGlobalEnableState state; CSL_IntcEventHandlerRecord EventRecord; CSL_IntcParam vectId; CSL_GpioHandle hGpio; volatile int a = 0; extern cregister volatile unsigned int TSCL; extern cregister volatile unsigned int TSCH; /*Throughput calculation initialization */ uint64_t volatile StartTime = 0; uint64_t volatile EndTime = 0; uint64_t volatile Total_cycle_ticks = 0; /*Throughput calculation initialization Ends */ uint32_t utilReadTime32 () { uint32_t low = 0; low = TSCL; return low; } interrupt void intIsr() { a = 1; } uint64_t utilReadTime64 () { uint32_t low = 0; uint32_t high = 0; low = TSCL; high = TSCH; return (_itoll(high,low)); } int main(void) { int pinNum = 0; int bankNum = 0; TSCH = 0; TSCL = 0; /* Enable the time stamp counter. */ CSL_tscEnable(); /************************************************ *************** INTC Configuration ************* ************************************************/ printf ("Debug: GEM-INTC Configuration...\n"); /* INTC module initialization */ intcContext.eventhandlerRecord = EventHandler; intcContext.numEvtEntries = 10; if (CSL_intcInit(&intcContext) != CSL_SOK) { printf("Error: GEM-INTC initialization failed\n"); return 0; } /* Enable NMIs */ if (CSL_intcGlobalNmiEnable() != CSL_SOK) { printf("Error: GEM-INTC global NMI enable failed\n"); return 0; } /* Enable global interrupts */ if (CSL_intcGlobalEnable(&state) != CSL_SOK) { printf ("Error: GEM-INTC global enable failed\n"); return 0; } /* Open the INTC Module for Vector ID: 4 and Event ID: 90 (GPIO_n in C6678)*/ vectId = CSL_INTC_VECTID_4; hTest = CSL_intcOpen (&intcObj, 90, &vectId , NULL); if (hTest == NULL) { printf("Error: GEM-INTC Open failed\n"); return 0; } /* Register an call-back handler which is invoked when the event occurs. */ EventRecord.handler = &intIsr; EventRecord.arg = 0; if (CSL_intcPlugEventHandler(hTest,&EventRecord) != CSL_SOK) { printf("Error: GEM-INTC Plug event handler failed\n"); return 0; } /* Enabling the events. */ if (CSL_intcHwControl(hTest,CSL_INTC_CMD_EVTENABLE, NULL) != CSL_SOK) { printf("Error: GEM-INTC CSL_INTC_CMD_EVTENABLE command failed\n"); return 0; } printf ("Debug: GEM-INTC Configuration Completed\n"); // 1. Init Flag a = 0; printf("a = %d\n",a); // 2. Trigger GPIO_0 in Core0 pinNum = 0; bankNum = 0; // Open the CSL GPIO Module 0 hGpio = CSL_GPIO_open (0); // Set GPIO pin number 0 as an output pin CSL_GPIO_setPinDirOutput (hGpio, pinNum); #if 0 // Set interrupt detection on GPIO pin 0 to rising edge CSL_GPIO_setRisingEdgeDetect (hGpio, pinNum); #else // Set interrupt detection on GPIO pin 0 to rising edge CSL_GPIO_setFallingEdgeDetect (hGpio, pinNum); #endif // Enable GPIO per bank interrupt for bank zero CSL_GPIO_bankInterruptEnable (hGpio, bankNum); #if 0 // Toggle GPIO_0 pin to trigger GPIO interrupt CSL_GPIO_clearOutputData (hGpio, pinNum); //GPIO_0=0 CSL_GPIO_setOutputData (hGpio, pinNum); //GPIO_0=1 #else // Toggle GPIO_0 pin to trigger GPIO interrupt CSL_GPIO_setOutputData (hGpio, pinNum); //GPIO_0=1 CSL_GPIO_clearOutputData (hGpio, pinNum); //GPIO_0=0 StartTime = utilReadTime64(); #endif // 3. Wait for entering into ISR while(a!=1){} EndTime = utilReadTime64(); printf("a = %d\n",a); printf("GPIO interrupt occurs\n"); Total_cycle_ticks = EndTime - StartTime; printf("Started at cpu cycle = %llu cycles \n", StartTime); printf("Ended at cpcu cycle = %llu cyclces \n", EndTime); printf("Total_cpu_cycle = %llu cycles\n", Total_cycle_ticks); return 0; }
2. test_lnk.cmd
-c -heap 0x2000 -stack 0x2000 /* Memory Map 1 - the default */ MEMORY { L1D: o = 00f00000h l = 00007FFFh L1P: o = 00e00000h l = 00007FFFh L2: o = 00800000h l = 0007FFFFh } SECTIONS { .csl_vect > L2 .text > L2 .stack > L2 .bss > L2 .cinit > L2 .cio > L2 .const > L2 .data > L2 .switch > L2 .sysmem > L2 .far > L2 .testMem > L2 .fardata > L2 .neardata > L2 .rodata > L2 }
3. Do the necessary compiler and linker options appropriately.
3.1. Add the CSL path, "C:\ti\pdk_c667x_2_0_16\packages" in the C6000 compiler --> Include options
3.2. Add the CSL library paths in the C6000 Linker --> Include Library files.
4. Build the project
================
5. How to load and run the sample code.
===============================
5. Observe the outputs like below.
Regards
Shankari G