Freescale 9S12 系列单片机应用笔记(SCI)3
- if(pbuf->RingBufTxOutPtr==&pbuf->if(pbuf->RingBufTxOutPtr==&pbuf->RingBufTx[SCI_TX_BUF_SIZE]){/*WrapOUTpointer*/
- pbuf->RingBufTxOutPtr=&pbuf->RingBufTx[0];
- }
- (void)OSSemPost(pbuf->RingBufTxSem);/*Indicatethatcharacterwillbesent*/
- *err=SCI_NO_ERR;
- return(c);/*Charactersarestillavailable*/
- }else{
- *err=SCI_TX_EMPTY;
- return(NUL);/*Bufferisempty*/
- }
- }
- voidSCI0_ISR_Handler(void)
- {
- charstatus;
- chardata;
- unsignedcharerr;
- status=SCI0SR1;
if(status&0x0F)//0x1F=00011111,ifstatusisnotReceiveDataRegFullFlag
- {
- //Seeifwehavesomekindoferror
- //Clearinterrupt(donothingaboutit!)
- data=SCI0DRL;
- }
- elseif(status&0x20)//ReceiveDataRegFullFlag
- {
- data=SCI0DRL;
- SCIPutRxChar(SCI0,data);//Insertreceivedcharacterintobuffer
- }
- elseif(status&0x80)
- {
- data=SCIGetTxChar(SCI0,&err);//Getnextcharactertosend.
- if(err==SCI_TX_EMPTY)
- {//Dowehaveanymorecharacterstosend?
- //No,DisableTxinterrupts
- SCIDisTxInt(SCI0);
- }
- else
- {
- SCI0DRL=data;//Yes,Sendcharacter
- }
- }
- }
- voidSCI1_ISR_Handler(void)
- {
- charstatus;
- chardata;
- unsignedcharerr;
- status=SCI1SR1;
if(status&0x0F)//0x1F=00011111,ifstatusisnotReceiveDataRegFullFlag
- {
- //Seeifwehavesomekindoferror
- //Clearinterrupt(donothingaboutit!)
- data=SCI1DRL;
- }
- elseif(status&0x20)//ReceiveDataRegFullFlag
- {
- data=SCI1DRL;
- SCIPutRxChar(SCI1,data);//Insertreceivedcharacterintobuffer
- }
- elseif(status&0x80)
- {
- data=SCIGetTxChar(SCI1,&err);//Getnextcharactertosend.
- if(err==SCI_TX_EMPTY)
- {//Dowehaveanymorecharacterstosend?
- //No,DisableTxinterrupts
- SCIDisTxInt(SCI1);
- }
- else
- {
- SCI1DRL=data;//Yes,Sendcharacter
- }
- }
- }
#pragmaCODE_SEGNON_BANKED
- interruptVectorNumber_Vsci0voidSCI0_ISR(void)
- {
#ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)
- __asmldaaPPAGE;//3~,GetcurrentvalueofPPAGEregister
- __asmpsha;//2~,PushPPAGEregisterontocurrenttasksstack
- #endif
- __asmincOSIntNesting;//OSIntNesting++;
//if(OSIntNesting==1)
- //{
- //OSTCBCur->OSTCBStkPtr=StackPointer;
- //}
- __asm
- {
- ldabOSIntNesting
- cmpb#$01
- bneSCI0ISR1
ldxOSTCBCur
- sts0,x
- SCI0ISR1:
- }
#ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)
- __asmcallSCI0_ISR_Handler;
- __asmcallOSIntExit;
- #else
- __asmjsrSCI0_ISR_Handler;
- __asmjsrOSIntExit;
- #endif
#ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)
- __asmpula;//3~,GetvalueofPPAGEregister
- __asmstaaPPAGE;//3~,StoreintoCPUsPPAGEregister
- #endif
}
interruptVectorNumber_Vsci1voidSCI1_ISR(void)
- {
#ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)
- __asmldaaPPAGE;//3~,GetcurrentvalueofPPAGEregister
- __asmpsha;//2~,PushPPAGEregisterontocurrenttasksstack
- #endif
- __asmincOSIntNesting;//OSIntNesting++;
//if(OSIntNesting==1)
- //{
- //OSTCBCur->OSTCBStkPtr=StackPointer;
- //}
- __asm
- {
- ldabOSIntNesting
- cmpb#$01
- bneSCI1ISR1
ldxOSTCBCur
- sts0,x
- SCI1ISR1:
- }
#ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)
- __asmcallSCI1_ISR_Handler;
- __asmcallOSIntExit;
- #else
- __asmjsrSCI1_ISR_Handler;
- __asmjsrOSIntExit;
- #endif
#ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)
- __asmpula;//3~,GetvalueofPPAGEregister
- __asmstaaPPAGE;//3~,StoreintoCPUsPPAGEregister
- #endif
}
下面给个简单的例子:
#include
/*commondefinesandmacros*/ - #include"derivative.h"/*derivative-specificdefinitions*/
#include"INCLUDES.H"
- #include"crg.h"
- #include"sci.h"
- #include"sci_rtos.h"
OS_STKAppStartTaskStk[64];
staticvoidAppStartTask(void*pdata);
voidmain(void)
- {
- /*putyourowncodehere*/
- OS_CPU_SRcpu_sr;
CRGInit();
- CRGSetRTIFreqency(0x54);//200Hz
EnableInterrupts;
- OS_ENTER_CRITICAL();
- SCIInit(SCI0);
- SCIInit(SCI1);
- OS_EXIT_CRITICAL();
- OSInit();
- SCISetIEBit(SCI0,SCI_RIE);
- SCISetIEBit(SCI1,SCI_RIE);
- SCIBufferInit();
- (void)OSTaskCreate(AppStartTask,(void*)0x4321,(void*)&AppStartTaskStk[63],0);
- (void)OSStart();
- for(;;)
- {
- _FEED_COP();/*feedsthedog*/
- }/*loopforever*/
- /*pleasemakesurethatyouneverleavemain*/
- }
staticvoidAppStartTask(void*pdata)
- {
- INT8Uerr;
- charC;
- (void)pdata;
- for(;;)
- {
- C=SCIGetCharB