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.

Proper way to write/add an ISR to my code?

Hi Folks,


I'm trying to figure out how to add an eCAP interrupt to my code and I'm having a bit of a problem.  Here is my eCAP setup code (located in the HAL.C):

void HAL_setupeCAP(HAL_Handle handle)
{
  HAL_Obj   *obj = (HAL_Obj *)handle;

  CAP_setModeCap(obj->capHandle);						// set mode to CAP
  CAP_clearInt(obj->capHandle,CAP_Int_Type_CEVT4);		// clear the CEVT1 int
  CAP_disableSyncIn(obj->capHandle);
  CAP_setCapEvtPolarity(obj->capHandle,CAP_Event_1,CAP_Polarity_Rising);
  CAP_setCapEvtPolarity(obj->capHandle,CAP_Event_2,CAP_Polarity_Falling);
  CAP_setCapEvtPolarity(obj->capHandle,CAP_Event_3,CAP_Polarity_Rising);
  CAP_setCapEvtPolarity(obj->capHandle,CAP_Event_4,CAP_Polarity_Falling);
  CAP_setCapEvtReset(obj->capHandle,CAP_Event_1,CAP_Reset_Enable);
  CAP_setCapEvtReset(obj->capHandle,CAP_Event_2,CAP_Reset_Enable);
  CAP_setCapEvtReset(obj->capHandle,CAP_Event_3,CAP_Reset_Enable);
  CAP_setCapEvtReset(obj->capHandle,CAP_Event_4,CAP_Reset_Enable);

//  CAP_setCapContinuous(obj->capHandle);
  CAP_setCapOneShot(obj->capHandle);
  CAP_setRunMode(obj->capHandle);
  CAP_setStopWrap(obj->capHandle,CAP_Stop_Wrap_CEVT4);
  CAP_enableCaptureLoad(obj->capHandle);
  CAP_enableInt(obj->capHandle,CAP_Int_Type_CEVT4);
  CAP_enableTimestampCounter(obj->capHandle);

  // enable eCAP interrupt
  PIE_enableInt(obj->pieHandle, PIE_GroupNumber_4, PIE_InterruptSource_ECAP1);

  // enable CPU interrupt
  CPU_enableInt(obj->cpuHandle, CPU_IntNumber_4);

  return;
}  // end of HAL_setupCAP() function

My ISR (in my main.c file) is:

interrupt void ecapISR(void)
{
	DutyOnTime1 = CAP_getCap2(halHandle->capHandle);
	// toggle status LED
	  if(gLEDcnt++ > (uint_least32_t)(USER_ISR_FREQ_Hz / LED_BLINK_FREQ_Hz))
	  {
	    HAL_toggleLed(halHandle,(GPIO_Number_e)HAL_Gpio_LED2);
	    gLEDcnt = 0;
	  }
	CAP_rearm(halHandle->capHandle);
	CAP_clearInt(halHandle->capHandle, CAP_Int_Type_CEVT4);
	PIE_clearInt(halHandle->pieHandle, PIE_GroupNumber_4);
	return;
}

In the HAL_init() I"ve put this:

obj->capHandle = CAP_init((void *)CAP1_BASE_ADDR,sizeof(CAP_Obj));

In the Hal_obj.h file I"ve added:

CAP_Handle    capHandle;

In the Hal.h globals section I've added:

extern interrupt void ecapISR(void);

And in the Hal.h vector table setup I've added:

static inline void HAL_initIntVectorTable(HAL_Handle handle)
 {
  HAL_Obj *obj = (HAL_Obj *)handle;
  PIE_Obj *pie = (PIE_Obj *)obj->pieHandle;


  ENABLE_PROTECTED_REGISTER_WRITE_MODE;

  pie->ADCINT1 = &mainISR;

  pie->ECAP1_INT = &ecapISR;

  DISABLE_PROTECTED_REGISTER_WRITE_MODE;

  return;
 } // end of HAL_initIntVectorTable() function

Is there anything else I need to do or have I totally screwed this up?

Thanks,

Richard