Modem interrupt service sample code, A n 9 3 – Silicon Laboratories SI2493/57/34/15/04 User Manual
Page 300

A N 9 3
300
Rev. 1.3
Modem Interrupt Service Sample Code
The following is the C code for the modem ISR. Also refer to "Figure 76. Parallel- or SPI-Port Interrupt-Service
Flowchart" for more explanations. Please contact Silicon Labs to obtain a complete C8051F12xx project bundle.
// Macros for modem ISR readability
#define RXFInterrupt ( modem_status & SiRXF )
#define TXEInterrupt ( modem_status & ( SiTXE & modem_control ) )
#define TimerInterrupt ( !( modem_status & SiREM ) && !RXFInterrupt && !rxf_processed )
#define U70Interrupt ( modem_status & ( SiINT & ( modem_status >> 1 ) ) )
#define RTSIsSet ( modem_status & SiRTSb )
#define ClearRTS ( modem_control &= ~SiRTSb )
#define ClearRXF ( modem_control &= ~SiRXF )
#define ClearTXE ( modem_control &= ~SiTXE )
#define ClearINTM ( modem_control &= ~SiINTM )
#define rxBufferSize gModemToUARTBufferSize
#define ReadModemStatus modem_status = readModem( HIR1 )
#define readModemByte pushByteToUART( readModem( HIR0 ) )
//-----------------------------------------------------------------------------
// Interrupt service routine
//-----------------------------------------------------------------------------
// modemInterrupt()
//-----------------------------------------------------------------------------
// Invoked whenever the modem issues an interrupt: this is meant as reference
// code for parallel-port/SPI interrupt service.
//
// Parameters: None
// Return value: None
//-----------------------------------------------------------------------------
void modemInterrupt( void ) interrupt 2
{
char modem_status;
char modem_control; // Modem control before writing (written only if modifed)
char control_update = 0; // Tracks whether control register was modified, needs updating
char rxf_processed = 0;
int BytesSent;
int BytesReceived = 0;
char SFRPAGE_SAVE;
EA = 0; // Disable global interrupt
EA = 0; // Dummy operation required by MCU, as per MCU data sheet
SFRPAGE_SAVE = SFRPAGE; // Save Current SFR page
ReadModemStatus; // Read HIR1 to get current status
// Set default write value. Always write the RXF and TXE bits to 1 by default
// to avoid inadvertently clearing those interrupts
modem_control = modem_status | SiTXE | SiRXF;
// Clear the RTS bit if it's set. The part comes out of reset with RTS set.
// RTS will have no effect unless the modem gets the AT\Q3 command.
// If RTS isn't needed this code can be removed.
if ( RTSIsSet )
{
ClearRTS; // Clear the RTSb so data enters FIFO
control_update = 1;