Сигнальный МП Motorola DSP56002 (1086189), страница 41
Текст из файла (страница 41)
This exampleNOP;does not trap errors so thisNOP;interrupt is not used.;*************************************************;SCI TRANSMIT INTERRUPT VECTOR*Freescale Semiconductor, Inc...ORGP:$0016;*************************************************ORGP:$0018;Load the SCI TX interrupt vectorsJSRTX;Transmit next byte in bufferNOP;*************************************************;INITIALIZE THE SCI PORT*;*************************************************ORGP:STARTORI#$03,MRMOVEP#$C000,X:IPRMOVEP#$0BE6,X:SCRMOVEP#$0000,X:SCCRMOVEP#>$03,X:PCC;Start the program at location $40;Mask interrupts temporarily;Set interrupt priority to 2;Disable TX, enable RX interrupts;Enable transmitter and receiver,;Wired-OR mode, Rec.
wakeup;mode,11-bit multidrop (1 start,;8 data,1 data type, 1 stop);Use internal TX, RX clocks;625K BPS at 40 MHz;Select pins TXD and RXD for SCI;**************************************************;INITIALIZE INTERRUPTS, REGISTERS, ETC.*;**************************************************MOVEP#$0,X:BCRMOVE#TX_BUFF,R0MOVE#TX_BUFF,R1MOVE#RX_BUFF,R2MOVE#RX_BUFF,R3MOVE#>$41,R5;No wait states;Load start pointer of transmit buffer;Load end pointer of transmit buffer;Load start pointer of receive buffer;Load end pointer of receive buffer;Init data register... R5 contains;the data that will be sent in this;example; it is initialized to an ASCII A.Figure 6-34 Multidrop Transmit Receive Example (Sheet 2 of 4)MOTOROLAPORT CFor More Information On This Product,Go to: www.freescale.com6 - 65Freescale Semiconductor, Inc.SERIAL COMMUNICATION INTERFACE (SCI)Freescale Semiconductor, Inc...MOVEMOVEMOVEMOVEMOVEMOVEMOVEMOVEP#B_SIZE,M0#B_SIZE,M1#B_SIZE,M2#B_SIZE,M3#>$1,N0#>$1,N1#0,N2X:SRX,X:(R0);Load transmit buffer size;Load transmit buffer size;Load receive buffer size;Load receive buffer size;Load receive address;Load first slave address;Load a constant (0) into N2;Clear receive register;**************************************************;MAIN PROGRAM*;**************************************************ANDI#$FC,MRMOVE(R1)+LOOPSND_BUFSENDMOVEMOVEMOVECMPJEQMOVER1,A(R1)R0,BA,BSND_BUFR5,X:(R1)+MOVEMOVE(R5)+(R1)+JMPJSRJMPLOOPWAKE_UPSEND;Re-enable interrupts;Temporarily increment the tail pointer;Build a packet;Check to see if the TX buffer is full;(fix tail pointer now that we’ve used it);by comparing the head and tail pointers;of the circular transmit buffer.;if equal, transmit completed packet;if not, put next character in;transmit buffer and;increment the pointers.;Temporarily increment the tail;pointer to test buffer again;Wake up proper slave and send packet;and allow interrupts to drain;the transmit buffer.Figure 6-34 Multidrop Transmit Receive Example (Sheet 3 of 4)6 - 66PORT CFor More Information On This Product,Go to: www.freescale.comMOTOROLAFreescale Semiconductor, Inc.SERIAL COMMUNICATION INTERFACE (SCI)Freescale Semiconductor, Inc...;*******************************************************************************************; SUBROUTINE TO READ SCI AND STORE IN BUFFER USING A LONG INTERRUPT*;*******************************************************************************************RXJCLR#7,X:$FFF1,RX_DATA;Check if this is address or data.MOVEPX:SRX,A;Compare the received addressMOVEN1,B;with the slave address.CMPA,BJEQEND_RX;If address OK, use interrupts to Rx;packetBSET#6,X:$FFF0;if not, go back to sleepJMPEND_RX;and return to previous program.RX_DATA MOVEPX:SRX,X:(R3)+;Put data in buffer,MOVEN2,X:RX_MTY;and clear the Rx buffer empty flagEND_RXRTI;Return to previous program;*******************************************************************************************;SUBROUTINE TO WRITE BUFFER TO SCI USING A LONG INTERRUPT*;*******************************************************************************************TXMOVEPX:(R0)+,X:STX;Transmit a byte and increment the;pointerMOVER0,A;Check to see if the TX buffer is;emptyMOVER1,BCMPA,BJNEEND_TX;If not, return to mainMOVE#$000001,X0;If it is, set the TX buffer empty flagMOVEX0,X:TX_MTYBCLR#12,X:SCR;disable transmit interrupts, andEND_TXRTI;return to main;*******************************************************************************************;SUBROUTINE TO WAKE UP THE ADDRESSED SLAVE*;*******************************************************************************************WAKE_UP MOVEPN1,X:STXA;Transmit slave address using STXA;not STXBSET#12,X:SCR;Enable transmit interrupts to send;packetAWAKERTIEND;End of example.Figure 6-34 Multidrop Transmit/Receive Example (Sheet 4 of 4)MOTOROLAPORT CFor More Information On This Product,Go to: www.freescale.com6 - 67Freescale Semiconductor, Inc.Freescale Semiconductor, Inc...SERIAL COMMUNICATION INTERFACE (SCI)6.3.9SCI TimerThe SCI clock determines the data transmission rate and can also be used to establish a periodicinterrupt that can act as an event timer or be used in any other timing function.
Figure 6-35 illustrates how the SCI timer is programmed. Bits CD11–CD0, SCP, and STIR in the SCCR work together to determine the time base. The crystal oscillator fosc is first divided by 2 and then dividedby the number CD11–CD0 in the SCCR. The oscillator is then divided by 1 (if SCP=0) or eight(if SCP=1). This output is used as is if STIR = 1 or, if STIR = 0, it is divided by 2 and then by 16before being used. If TMIE in the SCR = 1 when the periodic timeout occurs, the SCI timer interrupt is recognized and pending. The SCI timer interrupt is automatically cleared when the interrupt is serviced. This interrupt will occur every time the periodic timer times out.
If only the timerfunction is being used (i.e., PC0, PC1, and PC2 pins have been programmed as GPIO pins), thetransmit interrupts should be turned off (TIE=0). Under individual reset, TDRE will remain set andthe timer will continuously generate interrupts.Figure 6-35 shows that an external clock can be used for SCI receive and/or transmit, whichfrees the SCI timer to be programmed for a different interrupt rate. In addition, both the SCI timerinterrupt and the SCI can use the internal time base if the SCI receiver and/or transmitter requirethe same clock period as the SCI timer.The program in Figure 6-36 configures the SCI to interrupt the DSP at fixed intervals. The program starts by setting equates for convenience and clarity and then points the reset vector to thestart of the program. The SCI timer interrupt vector location contains “move (R0)+”, incrementingthe contents of R0, which serves as an elapsed time counter.The timer initialization consists of enabling the SCI timer interrupt, setting the SCI baud ratecounters for the desired interrupt rate, setting the interrupt mask, enabling the interrupt, and thenenabling the SCI state machine.6 - 68PORT CFor More Information On This Product,Go to: www.freescale.comMOTOROLAFreescale Semiconductor, Inc.SERIAL COMMUNICATION INTERFACE (SCI)SCI CONTROL REGISTER (SCCR)(READ/WRITE)X:$FFF21514131211109876543210TCMRCMSCPCODCD11CD10CD9CD8CD7CD6CD5CD4CD3CD2CD1CD010PRESCALERIF SCP = 1, THEN DIVIDE BY 8IF SCP = 0, THEN DIVIDE BY 1Freescale Semiconductor, Inc...DIVIDEBY 2DIVIDE BY 1TO 4096DIVIDEBY 2foscSCKPOUTPUT DIVIDERIF SYNC, THEN DIVIDE BY 2IF ASYNC THEN:COD = 1, DIVIDE BY 1COD = 0, DIVIDE BY 16CODINTERNALSCLKSCKPEXTERNALRCMTCMTCMTRANSMIT CONTROLIF ASYNC, THEN DIVIDE BY 16IF SYNC THEN:MASTER, DIVIDE BY 2SLAVE, DIVIDE BY 1CLOCKPERIODIC TIMERDIVIDE BY 161TRANSMIT CLOCKCLOCK0RECEIVE CONTROLIF ASYNC, THEN DIVIDE BY 16IF SYNC THEN:MASTER, DIVIDE BY 2SLAVE, DIVIDE BY 11RECEIVE CLOCK0SCI CONTROL REGISTER (SCR)(READ/WRITE)X:$FFF015141312111098001TIERIEILIETERESCKPSTIRTMIE7WOMS6543RWUWAKESBK02WDS2 WDS1 WDS0SSFTD1.
WHEN PERIODIC TIMEOUT OCCURS AND TMIE = 1 IN SCR, THEN AN SCI TIMER EXCEPTION IS TAKEN.INTERRUPTVECTORTABLEP:$001CSCI TIMERINTERRUPTSERVICEROUTINE(FAST OR LONG)SCI TIMER2. PENDING TIMER INTERRUPT IS AUTOMATICALLY CLEARED WHEN INTERRUPT IS SERVICED.Figure 6-35 SCI Timer OperationMOTOROLAPORT CFor More Information On This Product,Go to: www.freescale.com6 - 69Freescale Semiconductor, Inc.SERIAL COMMUNICATION INTERFACE (SCI);*******************************************************************************************;TIMER USING SCI TIMER INTERRUPT*;*******************************************************************************************Freescale Semiconductor, Inc...;*************************************************;SCI and other EQUATES*;*************************************************STARTEQU$0040;Start of programSCREQU$FFF0;SCI control registerSCCREQU$FFF2;SCI clock control registerIPREQU$FFFF;Interrupt priority register;*************************************************;RESET VECTOR*;*************************************************ORGP:$0000JMPSTART;*************************************************;SCI TIMER INTERRUPT VECTOR*;*************************************************ORGP:$001C;Load the SCI timer interrupt vectorsMOVE(R0)+;Increment the timer interrupt counterNOP;This timer routine is implemented;as a fast interrupt;*************************************************;INITIALIZE THE SCI PORT*;*************************************************ORGP:START;Start the program at location $40MOVE#0,R0;Initialize the timer interrupt counterMOVEP#$2000,X:SCR ;Select the timer interruptMOVEP#$013F,X:SCCR;Set the interrupt rate at 1 ms;(arbitrarily chosen);Interrupts/second =;fosc/(64×(7(SCP)-+1)×(CD+1));Note that this is the same equation;as for SCI async baud rateFigure 6-36 SCI Timer Example (Sheet 1 of 2)6 - 70PORT CFor More Information On This Product,Go to: www.freescale.comMOTOROLAFreescale Semiconductor, Inc.SERIAL COMMUNICATION INTERFACE (SCI)ENDMOVEP#$C000,X:IPRANDI#$FC,MRJMPENDFreescale Semiconductor, Inc...END;For 1 ms, SCP=0,;CD=0001 0011 1111.;Set the interrupt priority level–;application specific.;Enable interrupts, set MR bits I1 and;I0=0;Normally something more useful;would be put here.;End of example.Figure 6-36 SCI Timer Example (Sheet 2 of 2)6.3.10Bootstrap Loading Through the SCI (Operating Mode 6)When the DSP comes out of reset, it looks at the MODC, MODB, and MODA pins andsets the corresponding mode bits in the OMR.