Timer and interrupt

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Timer and interrupt

3,688 Views
eitanm
Contributor I

 

Hi, the following will be the first of possibly many questions I'm going to post here,

Sorry in advance for the noob nature of those questions. If there is a good documentation (other then the reference manual) feel free to kindly point me there.

I'm attempting to make my first steps with the Tower K60, I'm working with uvision\Keil IDE (so no CodeWarrior, and no MQX), all I have is a working Blinky sample..

 

1. How do I configure the interrupt vector table? I went through ARM's CMSIS NVIC interface, I could not find how-to install a function pointer to be execute on an interrupt event.

 2. How do I set a simple timer (I guess PIT ?) to trigger my interrupt handler.

 

Thanks,

Eitan.

0 Kudos
3 Replies

1,433 Views
mjbcswitzerland
Specialist V

Hi

 

Assuming interrup vectors in RAM:

 

The Cortex M4 core's vector table offset needs to be configured, eg.

 

VECTOR_TABLE_OFFSET_REG   = (RAM_START_ADDRESS);                     // position the vector table at the bottom of RAM

 

The interrupt needs to be entered into the table and the Cortex NVIC registers configured with the interrupt's priority and enabled, eg.

 

// Function used to enter processor interrupts
//
static void fnEnterInterrupt(int iInterruptID, unsigned char ucPriority, void (*InterruptFunc)(void))
{
    unsigned long *ptrIntSet = IRQ0_31_SER_ADD;
    unsigned char *ptrPriority = IRQ0_3_PRIORITY_REGISTER_ADD;
    VECTOR_TABLE *ptrVect;
    void ( **processor_ints )( void );

    ptrVect = (VECTOR_TABLE *)(RAM_START_ADDRESS);
    processor_ints = (void (**)(void))&ptrVect->processor_interrupts;
    processor_ints += iInterruptID;
    *processor_ints = InterruptFunc;

    ptrIntSet += (iInterruptID/32);
    *ptrIntSet = (0x01 << (iInterruptID%32));                            // enable the interrupt

    ptrPriority += iInterruptID;
    *ptrPriority = ucPriority;                                           // define the interrupt's priority
}

 

Usually the Cortex M4's SYSTICK is used as tick timer (this leaves PITs free for other functions).

 

However, to configure a PIT0 interrupt the following can be done:

1) Enable clocks to the PIT0 module [SIM_SCG6 |= (SIM_SCGC6_PIT);]

2) Enter the PIT handler [fnEnterInterrupt(irq_PIT0_ID, PIT_int_priority, _PIT0_Interrupt);]

3) Configure and start the PIT0 (see data sheet)

4) Handle the interrupt, eg:

 


static __interrupt void _PIT0_Interrupt(void)
{
    PIT_TFLG0 = PIT_TFLG_TIF;                                            // clear pending interrupts

   ... other stuff
}

 

There are various additional developer's tips in the following document - see the appendix: http://www.utasker.com/docs/KINETIS/uTaskerV1.4_Kinetis_demo.pdf

 

Regards

 

Mark

 

 

0 Kudos

1,433 Views
eitanm
Contributor I

Hi,

 

Thanks for your help!

I'm not sure how to integrate the code you've posted into my environment.

I'm using uVision 4 IDE,  the only include file I have is "MK60N512MD100.h", it's a basic CMSIS style interface to the K60  that was created by Freescale. None of your defines are recognized in this header and I'm not

 sure how to proceed.

 

Thanks,

Eitan.

 

 

 

0 Kudos

1,434 Views
mjbcswitzerland
Specialist V

Eitan

 

I have attached the header file that the above code uses - you can look up the defines there and exchange for the defines in your file if you want.

 

Additional project defines for the chip type used are (with 512k FLASH):

 

    #define SIZE_OF_FLASH       (512*1024)                               // 512k FLASH
    #define SIZE_OF_RAM         (128 * 1024)                             // 128k SRAM

 

 

Alternatively you can get the complete project (including uVision project) from the uTasker web site (http://www.uTasker.com) - this allows simulation of the Kinetis device, including simulation of the interrupt mechanisms, thus simplifying first steps as well as complete projects.

 

Regards

 

Mark

 

0 Kudos