Roberto Mattos

MCF5282 - problem with PIT (?) or exception vector (?) & monitoring registers

Discussion created by Roberto Mattos on Jan 9, 2009
Latest reply on Jan 13, 2009 by Roberto Mattos

I am trying to make the CF generate a “RTC” that I can use for multi-purpose functions.

 

I thought about using one of the PIT for incrementing a counter.

I created a structure with multiple counter entities:

 

typedef struct

{

  uint16 ledCounter;

  uint32 secondsCounter;

  uint16 systemCounter;

} RTcounters;

 

and an Update procedure

void updateRTcounters( void )

{

  static uint16 count = 0;

 

  g_RTcounters.systemCounter++;

  g_RTcounters.ledCounter++;

    

  count++;

 

  if( count >= ONE_SECOND_CONSTANT)

  {

    g_RTcounters.secondsCounter++;

    count = 0;

  }

 

}

 

where the ONE_SECOND_CONSTANT and g_RTcounters are as follows:

 

#define ONE_SECOND_CONSTANT   4000   /* 4000 * 250us = 1s. */

RTcounters g_RTcounters;

 

That would update all counters every time this PIT0 count reaches zero, when I reload it to my constant and start over (forever).

My PIT initialization is as follows:

 

/******************************

 * Timer 0: Ticks every 250us *

 ******************************/

void pit_init_0()

{

  /* Timer setup for continuous interrupts every 250us. */

 

  MCF_PIT0_PCSR = 0x021E; /* RES=0, PRE=2 (64MHz/8 = 8MHz = 125ns), RES=0, DOZE=0

                                                                                                                                                                       HALT=0, OVW=1, PIE=1, PIF=1, RLD=1, EN=0. */

  MCF_PIT0_PMR = 1999;    /* 125ns * 2000 = 250us. */

  MCF_PIT0_PCSR |= MCF_PIT_PCSR_EN; /* Enable. */

}

 

Using this idea I can implement for example a toggle for an LED using one of the counters (ledCounter) in the following procedure (LED would be located on PORT E, with option for another one in PORT TD):

void flashDebugLed2( void )

{

  if (g_RTcounters.ledCounter >= 4000)

  {

    //Toggle LED 2

    MCF5282_GPIO_PORTE ^= 0x01;

    MCF5282_GPIO_PORTTD ^= 0x01;

    g_RTcounters.ledCounter = 0;

  }

}

 

So in the initialization of the system routine I unmasked this particular interruption

void __initialize_system(void)

{

  MCF_INTC0_IMRL = 0xFFFFFFFF;  /* int 1-31 masked. */

 

  MCF_INTC0_IMRH = 0xFF7FFFFF;  /* int 55 active, all other masked. */

 

  /* Other peripherals. */ 

  MCF_INTC0_ICR55 = 0x34;    /* Level 6, priority 4  - PIT0. */

 

}

 

Then in my exception.c I added the following code:

/********************************************************************/

__declspec(interrupt) void irq_handler (void)
{
 printf("irq_handler\n");
 /* empty */
}

/********************************************************************/

__interrupt__
void pit0_handler (void)
{
 //Clear IRQ
 MCF_PIT0_PCSR |= MCF_PIT_PCSR_PIF;
 
 //Update all periodic counters
  updateRTcounters();
   
}

and finally, I changed on my vector table the call from:

  asm_exception_handler,           /* 119 (0x___) Reserved                   */
to:

   pit0_handler,              /* 119 (0x___) Reserved                   */

 

And I monitor my count variable and it is not incrementing, so my routine updateRTcounters is never called. So, I cannot say if my PIT is not working or if my expection implementation is not properly set.

 

I tried to look at the registers, but my register windows (view-> registers) only shows values for the general purpose registers, EMAC Registers and supervisor registers. All other registers appears as unavailable or  write only (when this is the case). So, I cannot see the contents of the register while I am debugging, even the register details gives me Debugger Error 104100 (unless I am missing something stupid).

 

 

I am using MCF5282 on its evaluation board, CodeWarrior Development Studio 5.9.0 and I need HELP!

Outcomes