Difference between revisions of "Custom Interrupts - ARM"

From Flowcode Help
Jump to navigationJump to search
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
<font style="color:#FF0000"> '''Target ARM Processor ( AT91SAM7S128 )'''
  
 +
'''(Note: For other ARM devices you may have to refer to the device datasheet to obtain the correct code)''' </font>
  
  
<span style="color:#FF0000"> '''Target AVR Processor''' ( ATMEGA8, 16, 32 ) </span>
+
The official device datasheet is an invaluable source of information when dealing with custom interrupts, as are two header files,lib_AT91SAM7S128.h and AT91SAM7S128.h, which provide functions and definitions. These files are applicable to all the devices in the AT91SAM7S range.
  
<span style="color:#FF0000"> '''(Note: For other AVR devices you may have to refer to the device datasheet to obtain the correct code)''' </span>
+
The header files can be found in the \Tools\ Global folder of the Flowcode installation. These files must not be modified!
  
  
'''USART receive'''
+
'''Enable Code:'''
  
 +
This command enables the receive interrupt of USART1.
  
The Flowcode RS232 component can be used to set the Baud rate and configure the mode of operation, and the ReceiveRS232Char function can be used in the handler macro to read the data (clearing the interrupt).
 
  
 +
<span style="color:#000080">AT91F_US_EnableIt(AT91C_BASE_US1,AT91C_US_RXRDY);</span>
  
Enable code:
 
  
<span style="color:#000080"> UCSRB |= ((1 << RXCIE) | (1 << RXEN)); // enable USART receiver and receive interrupts </span>
+
[[File:Gen_Custom_Interrupts_ARM_US1.png|right]]
 +
'''AT91F_US_EnableIt()'''
  
 +
This library function can be used to enable any of the interrupts generated by a USART. AT91SAM7S16 and 32 devices have only one USART, the other devices in the range have two. The function writes to the interrupt enable register of the designated USART.
  
Disable code:
 
  
<span style="color:#000080"> UCSRB &= ~(1 << RXCIE); // disable USART receive interrupts </span>
+
''There is an AT91F_US_DisableIt() function that can be used in the same way in the Disable Code section to disable the interrupt.''
  
  
Handler code:
+
'''AT91C_BASE_US1'''
  
<font style="color:#000080"> ISR(USART_RXC_vect) // USART receive vector
+
This is the system definition of the base address of the registers associated with USART1
  
{
 
 
FCM_%n(); // call selected macro
 
 
} </font>
 
  
 +
'''AT91C_US_RXRDY'''
  
'''<img>'''
+
This is the system definition of the RXRDY (Receive Ready) bit in a USART interrupt enable register.
  
  
'''Analogue comparator'''
+
'''Disable Code:'''
  
 +
<span style="color:#000080">AT91F_US_EnableIt(AT91C_BASE_US1,AT91C_US_RXRDY);</span>
  
Enable code:
 
  
<font style="color:#000080"> SFIOR &= ~(1 << ACME); // disable multiplexer input
+
'''Handler Code:'''
  
ACSR |= (1 << ACIE); // enable comparator interrupts - interrupt when comparator output toggles </font>
+
This code section checks the identity of the peripheral device generating the interrupt and the interrupt event being generated. The Flowcode Custom Interrupt system receives two parameters when an interrupt is generated:
  
 +
Peripheral device identity number (periphID)
  
Disable code:
+
Active interrupt flags (IFlags)
  
<span style="color:#000080"> ACSR &= ~(1 << ACIE); // disable comparator interrupts </span>
 
  
 +
Active interrupt flags are those that have been both enabled and triggered.
  
Handler code:
 
  
<font style="color:#000080"> ISR(ANA_COMP_vect) // analogue comparator interrupt vector
+
<font style="color:#000080">if ( (periphID == AT91C_ID_US1) && (IFlags & AT91C_US_RXRDY) )
  
 
{
 
{
  
FCM_%n(); // call selected macro
+
FCM_%n(); / Call Flowcode Macro
  
} </font>
+
}</font>
  
  
The state of the comparator input can be read into a Flowcode variable 'compstate' with the following C code line:
 
  
  
<span style="color:#000080"> FCV_COMPSTATE = ACSR & (1 << ACO); </span>
+
'''FCM_%n():'''
  
 +
This is converted into the name of the macro selected in the 'Will call macro' box of the interrupt properties panel.
  
'''<img>'''
 
  
 +
'''periphID:'''
  
'''Timer1 rollover'''
+
This parameter is the system identification number of the peripheral device generating the interrupt. The following peripheral devices are supported by Flowcode as custom interrupts;
  
  
Enable code:
+
''AT91C_ID_PIOA'' - Parallel IO Controller
  
<font style="color:#000080"> TCCR1B = 0x45; // positive edge trigger with no noise canceler, prescaler = /1024
+
''AT91C_ID_ADC'' - Analog-to-Digital Converter
  
TIMSK |= (1 << TICIE1); // enable input capture interrupts </font>
+
''AT91C_ID_SPI'' - Serial Peripheral Interface
  
 +
''AT91C_ID_US0'' - USART 0
  
Disable code:
+
''AT91C_ID_US1'' - USART 1
  
<span style="color:#000080"> TIMSK &= ~(1 << TICIE1); // disable input capture interrupts </span>
+
''AT91C_ID_TWI'' - Two-Wire Interface
  
 +
''AT91C_ID_PWMC'' - PWM Controller
  
Handler code:
+
''AT91C_ID_TC0'' - Timer Counter 0
  
<font style="color:#000080"> ISR(TIMER1_CAPT_vect) // input capture vector
+
''AT91C_ID_TC1'' - Timer Counter 1
  
{
+
''AT91C_ID_TC2'' - Timer Counter 2
  
FCM_%n(); // call selected macro
 
 
}</font>
 
  
  
The captured 16-bit count value can be read into a Flowcode variable 'captval' with the following C code line:
+
'''IFlags:'''
  
 +
This parameter contains all the interrupt flags that are being generated by the peripheral device and have been previously enabled.
  
<span style="color:#000080"> FCV_CAPTVAL = ICR1; </span>
 
  
** captval must be declared as an integer variable **
+
'''AT91C_US_RXRDY:'''
  
'''<img>'''
+
In addition to being the definition of the interrupt enable flag, this also acts as the definition of the interrupt request flag.

Latest revision as of 12:11, 3 July 2019

Target ARM Processor ( AT91SAM7S128 )

(Note: For other ARM devices you may have to refer to the device datasheet to obtain the correct code)


The official device datasheet is an invaluable source of information when dealing with custom interrupts, as are two header files,lib_AT91SAM7S128.h and AT91SAM7S128.h, which provide functions and definitions. These files are applicable to all the devices in the AT91SAM7S range.

The header files can be found in the \Tools\ Global folder of the Flowcode installation. These files must not be modified!


Enable Code:

This command enables the receive interrupt of USART1.


AT91F_US_EnableIt(AT91C_BASE_US1,AT91C_US_RXRDY);


Gen Custom Interrupts ARM US1.png

AT91F_US_EnableIt()

This library function can be used to enable any of the interrupts generated by a USART. AT91SAM7S16 and 32 devices have only one USART, the other devices in the range have two. The function writes to the interrupt enable register of the designated USART.


There is an AT91F_US_DisableIt() function that can be used in the same way in the Disable Code section to disable the interrupt.


AT91C_BASE_US1

This is the system definition of the base address of the registers associated with USART1


AT91C_US_RXRDY

This is the system definition of the RXRDY (Receive Ready) bit in a USART interrupt enable register.


Disable Code:

AT91F_US_EnableIt(AT91C_BASE_US1,AT91C_US_RXRDY);


Handler Code:

This code section checks the identity of the peripheral device generating the interrupt and the interrupt event being generated. The Flowcode Custom Interrupt system receives two parameters when an interrupt is generated:

Peripheral device identity number (periphID)

Active interrupt flags (IFlags)


Active interrupt flags are those that have been both enabled and triggered.


if ( (periphID == AT91C_ID_US1) && (IFlags & AT91C_US_RXRDY) )

{

FCM_%n(); / Call Flowcode Macro

}



FCM_%n():

This is converted into the name of the macro selected in the 'Will call macro' box of the interrupt properties panel.


periphID:

This parameter is the system identification number of the peripheral device generating the interrupt. The following peripheral devices are supported by Flowcode as custom interrupts;


AT91C_ID_PIOA - Parallel IO Controller

AT91C_ID_ADC - Analog-to-Digital Converter

AT91C_ID_SPI - Serial Peripheral Interface

AT91C_ID_US0 - USART 0

AT91C_ID_US1 - USART 1

AT91C_ID_TWI - Two-Wire Interface

AT91C_ID_PWMC - PWM Controller

AT91C_ID_TC0 - Timer Counter 0

AT91C_ID_TC1 - Timer Counter 1

AT91C_ID_TC2 - Timer Counter 2


IFlags:

This parameter contains all the interrupt flags that are being generated by the peripheral device and have been previously enabled.


AT91C_US_RXRDY:

In addition to being the definition of the interrupt enable flag, this also acts as the definition of the interrupt request flag.