Is there any more info on setting and using device hardware Interrupts? I am trying to work out how to make my own interrupts handler routines for various hardware (timers, USART, ETC)..
My current project involves reading 4 bytes of serial data (USART) and based on those 4 bytes, play a sound. I have the sound play from an SD card working, with a timer1 interrupt setting the Audio output data rate. Since this application cant miss any serial commands i need to implement a high priority ISR to capture the USART serial data, even when a sound is being played. The serial data is always 4 bytes long and is generated at random times..
I see there is already an USART ISRRX module but i'm not sure its entirely suitable, and besides i'd really like to learn more about how SF handles Interrupts.
My plan is to store the 4 bytes of serial data in an long word array, setup as a circular buffer, probably 32 long words long. The ISR should read the 4 bytes into the array position (0) and then increment the array element pointer, ready for the next 4 bytes. I could then buffer up to 32 commands to play sounds.
In order to prevent data loss from the main program reading the long word elements at the same time as the ISR may be writing it, i plan to have an equal length Boolean flag array which is set to true only after the 4 bytes serial data are written into the buffer array.
The main program loop then checks each boolean flag array and if true (data in the buffer at that position) then branch off to process that serial command and play the sound required. Once complete that boolean flag is set back to zero and the data will be simply overwritten the next time the ISR gets to that element.
Something like this..
Code: Select all
Dim My_Array(32) as LongWord=0
Dim My_flag(32) as Boolean=false
Dim My_pointer as Byte=0
Dim Counter as byte
Interrupt onRX()
//Context save here
//Clear Int flag
My_array(My_pointer)=USART.ReadLongWord
My_Flag(My_pointer)=true
Inc(My_pointer)
IF My_Pointer=31 then
My_Pointer=0
end if
//context restore.
End Interrupt
Start:
Do
For counter = 0 to 31
If My_flag(Counter)=true then
//Call subroutine to process serial command
//My_Flag(Counter)=False
end if
Next
Until forever.
I just need to work out how to setup and configure the Interrupt handler etc but i am quite lost on how to achieve this. Is there a guide?
Cheers
Lee