Difference between revisions of "Custom Interrupts - ARM"

From Flowcode Help
Jump to navigationJump to search
Line 2: Line 2:
  
  
<font style="color:#FF0000"> '''Target AVR Processor''' ( ATMEGA8, 16, 32 )
+
<font style="color:#FF0000"> '''Target ARM Processor ( AT91SAM7S128 )'''
  
'''(Note: For other AVR devices you may have to refer to the device datasheet to obtain the correct code)''' </font>
+
(Note: For other ARM devices you may have to refer to the device datasheet to obtain the correct code)''' </font>
  
  
'''USART receive'''
+
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!
  
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).
 
  
 +
'''<img>'''
  
Enable code:
 
  
<span style="color:#000080"> UCSRB |= ((1 << RXCIE) | (1 << RXEN)); // enable USART receiver and receive interrupts </span>
+
'''Enable Code:'''
  
 +
This command enables the receive interrupt of USART1.
  
Disable code:
 
  
<span style="color:#000080"> UCSRB &= ~(1 << RXCIE); // disable USART receive interrupts </span>
+
AT91F_US_EnableIt(AT91C_BASE_US1,AT91C_US_RXRDY);
  
  
Handler code:
+
'''AT91F_US_EnableIt()'''
  
<font style="color:#000080"> ISR(USART_RXC_vect) // USART receive vector
+
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.
  
{
 
  
FCM_%n(); // call selected macro
+
''There is an AT91F_US_DisableIt() function that can be used in the same way in the Disable Code section to disable the interrupt.''
 +
 
  
} </font>
+
'''AT91C_BASE_US1'''
  
 +
This is the system definition of the base address of the registers associated with USART1
  
'''<img>'''
 
  
 +
'''AT91C_US_RXRDY'''
  
'''Analogue comparator'''
+
This is the system definition of the RXRDY (Receive Ready) bit in a USART interrupt enable register.
  
  
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
+
if((periphID == AT91C_ID_US1) && (IFlags & AT91C_US_RXRDY))
  
 
{
 
{
  
FCM_%n(); // call selected macro
+
    FCM_%n();
 
 
} </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():'''
  
 +
Thisis 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
 +
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
  
<font style="color:#000080"> TCCR1B = 0x45; // positive edge trigger with no noise canceler, prescaler = /1024
 
  
TIMSK |= (1 << TICIE1); // enable input capture interrupts </font>
+
'''IFlags:'''
  
 +
This parameter contains all the interrupt flags that are being generated by the peripheral device and have been previously enabled.
  
Disable code:
 
  
<span style="color:#000080"> TIMSK &= ~(1 << TICIE1); // disable input capture interrupts </span>
 
  
 +
'''AT91C_US_RXRDY:'''
  
Handler code:
+
In addition to being the definition of the interrupt enable flag, this also acts as the definition of the interrupt request flag.
 
 
<font style="color:#000080"> ISR(TIMER1_CAPT_vect) // input capture vector
 
 
 
{
 
 
 
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:
 
 
 
 
 
<span style="color:#000080"> FCV_CAPTVAL = ICR1; </span>
 
 
 
** captval must be declared as an integer variable **
 
 
 
'''<img>'''
 

Revision as of 10:31, 16 May 2013


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!


<img>


Enable Code:

This command enables the receive interrupt of USART1.


AT91F_US_EnableIt(AT91C_BASE_US1,AT91C_US_RXRDY);


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.


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();

}


FCM_%n():

Thisis 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.