PicGIM 0.5 documentation    
Copyright (C) 2002, 2013 - [AsYntote-SkyMatrix] gKript.org    
Generated on Sun Apr 26 2015 11:03:34 with DoxyGen 1.8.8    
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Events ( Interrupts )
Interrupts.png

PicGIM is able to handle events of PIC18F easily and fully automatically
We have chosen for this milestone, the first, to support interrupts without the management of priority.
To do this pg_event_init() sets to 0 IPEN bit of the RCON register. IPEN: Interrupt Priority Enable

Warning
If you choose to use the automatic handler YOU MUST NOT modify any register directly related to the hardware interrupt management.
Todo:
In the next milestone [1.0] the interrupts module will support high and low priority.



Module configuration


In order to use this module, it must be enabled and configured in:

Attention
For software reference, please read the documentation about pgim_event.h .
This is not a file defined as public and therefore it would not be edited.
We suggest that you edit this file only if necessary and only if you know what you are doing.




Module enabling


#define PGIM_EVENTS PG_DISABLE

This define enables or disables the module.
It must be:

  • PG_ENABLE : Interrupts module enabled.
  • PG_DISABLE : Interrupts module disabled.

References

Automatic Interrupts Handler


#define PG_EVENT_AUTO_HANDLER PG_ENABLE

These defines enable or disable the Automatic Interrupts Handler.
They must be:

  • PG_ENABLE : Automatic Interrupts Handler enabled.
  • PG_DISABLE : Automatic Interrupts Handler disabled. So you must code your own handler. In this case, the automatic handler will not be compiled.

By default is set to PG_ENABLE.

References

Note
If you disable the automatic handler the interrupts will no longer be managed by PicGIM until you create your own manager in pg_event_user_handler() .
Attention
Please note that in any case PicGIM will put my_isr() function in the interrupt vector.
So upon receipt of an interrupt will be call my_isr() which will call the pg_event_occurred() that deals of calling the correct handler and to clean the bit of the event.
You can see in the picture below  ↓
If you want to completely manage the interrupts in autonomy is necessary to disable completely the module.
See also
         Module enabling



External interupts


#define PG_EVENT_SET_INT0 PG_DISABLE
#define PG_EVENT_SET_INT1 PG_DISABLE
#define PG_EVENT_SET_INT2 PG_DISABLE
#define PG_EVENT_SET_RB0 PG_DISABLE

These defines enable or disable each external interrupts event.
They must be:

  • PG_ENABLE : enhanced mode enabled.
  • PG_DISABLE : enhanced mode disabled.

References

Internal Interrupts


#define PG_EVENT_SET_TMR0 PG_DISABLE
#define PG_EVENT_SET_TMR1 PG_DISABLE
#define PG_EVENT_SET_TMR2 PG_DISABLE
#define PG_EVENT_SET_AD PG_DISABLE
#define PG_EVENT_SET_USARTRC PG_DISABLE
#define PG_EVENT_SET_USARTTX PG_DISABLE
#define PG_EVENT_SET_SSP PG_DISABLE
#define PG_EVENT_SET_CCP1 PG_DISABLE
#define PG_EVENT_SET_CCP2 PG_DISABLE
#define PG_EVENT_SET_OSCF PG_DISABLE
#define PG_EVENT_SET_CM PG_DISABLE
#define PG_EVENT_SET_EE PG_DISABLE
#define PG_EVENT_SET_BCL PG_DISABLE

These defines enable or disable each internal interrupts event.
They must be:

  • PG_ENABLE : enhanced mode enabled.
  • PG_DISABLE : enhanced mode disabled.

References

Functions


After it has been enabled and configured the module you can refer to this set of functions to use it.


Private functions

Note
With "private" we mean a function that should not be used by the user in its code.
In this documentation the private functions are marked as Deprecate.
PicGIM internally uses these functions to properly manage the module.
Of course you are always free to use them if you think they are useful.
Note
If you choose the user interrupts handler the private function pg_event_clear_bit() will be considered public.



Public functions

  • pg_event_set() : This is the function to enable or disable one single interrupt events.
  • pg_event_user_handler() : This is the call for the user interrupts handler. The code for this function must be placed in the relative function in pgim_interrupt_callbacks.c
Note
The pg_event_user_handler() function is necessary only if you do not want to use the automatic handler.
Attention
Please note that in any case PicGIM will put my_isr() function in the interrupt vector.
So upon receipt of an interrupt will be call my_isr() which will call the pg_event_occurred() that deals of calling the correct handler and to clean the bit of the event.
If you want to completely manage the interrupts in autonomy is necessary to disable completely the module.
See also
Module enabling



How to use the interrupts callback routines


Introduction

After set the events you need to write the code to do what you wish for every single event.
If, for example, it was necessary to use timer 0 to blink one LED through the events will be necessary to attack the event given by the timer 0 to our callback function.
It is done in this way.

void led_blink( void ) {
...
}
void main( void ) {
...
...
}


A code example

Here is a simple example of how to use the module in your code.

Warning
In order to compile this example, the module must be enabled and properly configured.

This is the code for main.c :

#include "picgim_main.h"
#define MY_LED L_B3
#define MY_LED_TRIS T_B3
void led_blink( void ) {
pg_pin_toggle( MY_LED );
}
void main( void ) {
pg_pin_mode( MY_LED_TRIS , PG_OUT );
pg_timer_set_freq( PG_TIMER_0 , 1 , PG_HZ );
pg_timer_start( PG_TIMER_0 );
}

...and one LED will blink.