Hello I'm a new mqx user, and i'm working with the MCF52259DEMO Board. I'm looking for some help, with the interruption of the PIT1.
I' need to do a virtual clock (just a simple counter with a variable), but this clock must to be very exact.
So my idea is to make constant interruption with the PIT1 module.
The problem is that I never obtain an interuption, so the code have some kind of problem.
I wrote this code (is very simple), so I'm going to post this:
//////this is just the main//////////
TASK_TEMPLATE_STRUCT MQX_template_list[] =
{
/* Task number, Entry point, Stack, Pri, String, Auto? */
{MAIN_TASK, Main_task, 5000, 4, "main", MQX_AUTO_START_TASK,0L,0},
{0, 0, 0, 0, 0,0,0L,0}
};
extern void dtim3_isr(void);
//////////////////////////////////////////////
// Clck counter //
//////////////////////////////////////////////
static unsigned long int clock;
static unsigned int Pit_counter;
//////////////////////////////////////////////////
// Global Register pointer //
//////////////////////////////////////////////////
VMCF5225_STRUCT_PTR reg_ptr;
/*****************************************************************/
/*****************************************************************/
/*ISR*-----------------------------------------------------------
*
* ISR Name : dtim3_isr
* Comments :
*END*-----------------------------------------------------------*/
__declspec(interrupt) void dtim3_isr(void)
{
//Set the PIT interrupt flag
reg_ptr->PIT[1].PCSR=reg_ptr->PIT[1].PCSR;
//
reg_ptr->PIT[1].PMR=Pit_counter;
/////////////////////////////////////////////////
//Actualizo el Contador
if(clock==1000)
{
clock=0;
reg_ptr->GPIO.PORTTC=reg_ptr->GPIO.PORTTC^0x01;
}
else
{
clock++;
reg_ptr->GPIO.PORTTA = reg_ptr->GPIO.PORTTA^0x01;
}
}
/*****************************************************************/
/*****************************************************************/
/*TASK*-----------------------------------------------------
*
* Task Name : Main_task
* Comments :
* This task prints " Hello World "
*
*END*-----------------------------------------------------*/
void Main_task(uint_32 initial_data)
{
//////////////////////////////////////////////////////////////
// Voy a Configurar el IOC0 y el DTIM0 (LED0) like output //
//////////////////////////////////////////////////////////////
//First IOC0
reg_ptr->GPIO.PTAPAR = 0x00;
reg_ptr->GPIO.DDRTA = 0x0F;
reg_ptr->GPIO.PORTTA = 0x00;
//Next Led
reg_ptr->GPIO.PTCPAR = 0x00;
reg_ptr->GPIO.DDRTC = 0x0F;
reg_ptr->GPIO.PORTTC = 0x00;
//////////////////////////////////////////////////////////////
//PIT1 Init
reg_ptr->PIT[1].PCSR=(reg_ptr->PIT[0].PCSR)
reg_ptr->PIT[1].PMR=reg_ptr->PIT[0].PMR;
Pit_counter=reg_ptr->PIT[0].PMR;
//Finally Install the PIT1
if (_int_install_isr(BSP_PIT1_INT_VECTOR,dtim3_isr, NULL) == NULL)
{
printf("\n PIT1 instalation fail \n");
} */
//Init global clock
clock=0;
while(1)
{
printf("\nTick count =%d\n", clock);
_time_delay_ticks(200);
}
}
Please could some body tell me what is the problem?
Thank you for your help, now I have the program running well
Note that your ISR is MQX's kernel ISR, which runs already in interurpt context- so you ISR shoule be __declspec(interrupt) void dtim3_isr(void) only if you are replacing vector in interrupt table. MQX ISR has prototype:
void isr(uint_32 value);
Hi AF_Ariel,
You had not initialized the reg_ptr correctly. Also the IMRH bit mask for PIT0 needed to be cleared and lastly the ICR[56] for PIT1 need initialization.
I added you code to my isr.c file that I've hacked up for other test but you should be able to pull out your stuff easily enough.
I've attached my isr.c file.
Happy New Year,
David