Netcruzer Library API  V2.03
 All Data Structures Files Functions Variables Typedefs Enumerations Macros Groups Pages
nz_interrupt.h File Reference

Code for using and configuring Interrupts. More...

#include "nz_ioPorts.h"

Go to the source code of this file.

Macros

#define USE_AND_OR
 
#define CHANGE_INT_ON   INT_ENABLE
 
#define CHANGE_INT_OFF   INT_DISABLE
 
#define CHANGE_INT_PRI_7   INT_PRI_7
 
#define CHANGE_INT_PRI_6   INT_PRI_6
 
#define CHANGE_INT_PRI_5   INT_PRI_5
 
#define CHANGE_INT_PRI_4   INT_PRI_4
 
#define CHANGE_INT_PRI_3   INT_PRI_3
 
#define CHANGE_INT_PRI_2   INT_PRI_2
 
#define CHANGE_INT_PRI_1   INT_PRI_1
 
#define CHANGE_INT_PRI_0   INT_PRI_0
 
#define NZ_INT_DIS_PUSH()
 
#define NZ_INT_EN_POP()
 
#define NZ_INT_DIS_SAVE(save_to)
 
#define NZ_INT_EN_SAVE(save_to)
 
#define NZ_INT_DISABLE_FIBERS()   NZOS_INT_KERNEL_DISABLE()
 
#define NZ_INT_ENABLE_FIBERS()   NZOS_INT_KERNEL_ENABLE()
 
#define NZ_INT_DISABLE_P07()   __builtin_disi(0x3FFF)
 
#define NZ_INT_ENABLE_P07()   __builtin_disi(0)
 
#define NZ_BUILTIN_DISI(val)   __builtin_disi(val)
 
#define NZ_SET_AND_SAVE_CPU_IPL(ipl, lvl)   SET_AND_SAVE_CPU_IPL(ipl,lvl)
 
#define NZ_RESTORE_CPU_IPL(ipl)   RESTORE_CPU_IPL(ipl)
 
#define intOnChangeConfig(conf)   ConfigIntCN(conf)
 
#define intOnChangeEnablePort(portID)   portSetBitadr(portGetCNIE(portID))
 
#define intOnChangeDisablePort(portID)   portClearBitadr(portGetCNIE(portID))
 
#define intOnChangeClearIF()   InputChange_Clear_Intr_Status_Bit
 

Detailed Description

Code for using and configuring Interrupts.

Author
Modtronix Engineering
Compiler:
MPLAB XC16

Description

Code for using and configuring Interrupts

Configuration

The following defines are used to configure this module, and should be placed in projdefs.h. Note that all items marked [-DEFAULT-] are defaults, and do not have to be placed in projdefs.h if they contain desired configuration! For details, see Project Configuration.

// *********************************************************************
// ---------------------- ioPorts Configuration ------------------------
// *********************************************************************

Software License Agreement

The software supplied herewith is owned by Modtronix Engineering, and is protected under applicable copyright laws. The software supplied herewith is intended and supplied to you, the Company customer, for use solely and exclusively on products manufactured by Modtronix Engineering. The code may be modified and can be used free of charge for commercial and non commercial applications. All rights are reserved. Any use in violation of the foregoing restrictions may subject the user to criminal sanctions under applicable laws, as well as to civil liability for the breach of the terms and conditions of this license.

THIS SOFTWARE IS PROVIDED IN AN 'AS IS' CONDITION. NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.

File History

2013-11-20, David H. (DH):

  • Initial version

Macro Definition Documentation

#define intOnChangeClearIF ( )    InputChange_Clear_Intr_Status_Bit
Function:
void intOnChangeClearIF(void)

Clear "Interrupt on Change" interrupt flag

Examples:
rotary_encoder/main.c, and sensor_dht11_dht22/main.c.
#define intOnChangeConfig (   conf)    ConfigIntCN(conf)
Function:
void intOnChangeConfig(BYTE portID)

Configure and Enable "Interrupt on Change". For example:

//Interrupt on change ISR
void __attribute__((interrupt,no_auto_psv)) _CNInterrupt(void) {
intOnChangeClearIF(); //Clear "interrupt on change" IF (interrupt flag)
//Do something....
}
//Configure the interrupt on change for ports 7 and 8 (old port names X7 and X8)
enableIntOnChange(CHANGE_INT_ON|CHANGE_INT_PRI_6); //Enable Interrupt on chagne at Int Priority level 4
intOnChangeClearIF(); //Clear "interrupt on change" IF (interrupt flag)
enableIntOnChange(7); //Enable "interrupt on change" for Port 7
enableIntOnChange(8); //Enable "interrupt on change" for Port 8
Parameters
confAn OR'ed combination of:
  • CHANGE_INT_ON - Enable Interrupt on Change
  • CHANGE_INT_OFF - Enable Interrupt on Change
  • CHANGE_INT_PRI_n - Where n is Interrupt priority 0-7. 0 is the lowest.
Examples:
rotary_encoder/main.c, and sensor_dht11_dht22/main.c.
#define intOnChangeDisablePort (   portID)    portClearBitadr(portGetCNIE(portID))
Function:
void intOnChangeDisablePort(BYTE portID)

Disable "Interrupt on Change" for the given IO Port (port of SBC).

Pre-Condition:
Interrupts on change must have already been configured with intOnChangeConfig() function.
Parameters
portIDThe "Port ID" of the requested port. Is a number from 0 to 41, also known as the "Netcruzer Port Name".
#define intOnChangeEnablePort (   portID)    portSetBitadr(portGetCNIE(portID))
Function:
void intOnChangeEnablePort(BYTE portID)

Enables "Interrupt on Change" for the given IO Port (port of SBC).

Pre-Condition:
Interrupts on change must have already been configured with intOnChangeConfig() function.
Parameters
portIDThe "Port ID" of the requested port. Is a number from 0 to 41, also known as the "Netcruzer Port Name".
Examples:
rotary_encoder/main.c, and sensor_dht11_dht22/main.c.
#define NZ_BUILTIN_DISI (   val)    __builtin_disi(val)

Disable interrupt for given number of instruction cycles

#define NZ_INT_DIS_PUSH ( )
Value:
asm volatile ("push SR \n disi #3 \n mov #0xE0, W0 \n ior SR" \
: /* no outputs */ \
: /* no inputs */ \
: "w0")
#define NZ_INT_DIS_SAVE (   save_to)
Value:
asm volatile ("disi #5 \n mov SR, W0 \n mov W0, %0 \n mov #0xE0, W0 \n ior SR" \
: "=g" (save_to) /* Outputs */ \
: /* no inputs */ \
: "w0")
#define NZ_INT_DISABLE_FIBERS ( )    NZOS_INT_KERNEL_DISABLE()

Disable fibers

#define NZ_INT_DISABLE_P07 ( )    __builtin_disi(0x3FFF)

Disable All Interrupt level, excluding level 7. For TMR1 and TMR2 interrupts (maybe more), if this method is used to disable interrupt, the IF is NOT set while interrupts are disabled!!!! Using NZ_SET_AND_SAVE_CPU_IPL to disabled interrupts does NOT disable these IF from getting set!

#define NZ_INT_EN_POP ( )
Value:
/* Allow 2 instructions for push and pop! Compiler does not always use PUSH and POP! */ \
asm volatile ("disi #2 \n pop %0" \
: "+r" (SR) /* Outputs */ \
: /* no inputs */)
#define NZ_INT_EN_SAVE (   save_to)
Value:
asm volatile ("disi #3 \n mov %1, W0 \n mov W0, %0" \
: "+r" (SR) /* Outputs */ \
: "g" (save_to) /* Inputs */ \
: "w0")
#define NZ_INT_ENABLE_FIBERS ( )    NZOS_INT_KERNEL_ENABLE()

Disable fibers

#define NZ_INT_ENABLE_P07 ( )    __builtin_disi(0)

Enable All Interrupt levels

#define NZ_RESTORE_CPU_IPL (   ipl)    RESTORE_CPU_IPL(ipl)

Restore CPU IPL to given level.

#define NZ_SET_AND_SAVE_CPU_IPL (   ipl,
  lvl 
)    SET_AND_SAVE_CPU_IPL(ipl,lvl)

Set CPU IPL to new level, and save current level to given var. All interrupts equal to AND lower than given level will be disabled.