Freescale 9S12 系列单片机应用笔记(SCI)3
时间:11-20
来源:互联网
点击:
这次介绍如何在 uC/OS-II 上实现串口驱动。
- /*sci_ucos.h*/
#ifndef_SCI_RTOS_H_
#define_SCI_RTOS_H_
#defineSCI_RX_BUF_SIZE64/*NumberofcharactersinRxringbuffer*/
- #defineSCI_TX_BUF_SIZE64/*NumberofcharactersinTxringbuffer*/
/*
- *********************************************************************************************************
- *CONSTANTS
- *********************************************************************************************************
- */
#ifndefNUL
- #defineNUL0x00
- #endif
/*ERRORCODES*/
- #defineSCI_NO_ERR0/*Functioncallwassuccessful*/
- #defineSCI_BAD_CH1/*Invalidcommunicationsportchannel*/
- #defineSCI_RX_EMPTY2/*Rxbufferisempty,nocharacteravailable*/
- #defineSCI_TX_FULL3/*Txbufferisfull,couldnotdepositcharacter*/
- #defineSCI_TX_EMPTY4/*IftheTxbufferisempty.*/
- #defineSCI_RX_TIMEOUT5/*Ifatimeoutoccurredwhilewaitingforacharacter*/
- #defineSCI_TX_TIMEOUT6/*Ifatimeoutoccurredwhilewaitingtosendachar.*/
- #defineSCI_PARITY_NONE0/*Definesforsettingparity*/
- #defineSCI_PARITY_ODD1
- #defineSCI_PARITY_EVEN2
- /*
- *********************************************************************************************************
- *DATATYPES
- *********************************************************************************************************
- */
- typedefstruct{
- shortRingBufRxCtr;/*NumberofcharactersintheRxringbuffer*/
- OS_EVENT*RingBufRxSem;/*PointertoRxsemaphore*/
- unsignedchar*RingBufRxInPtr;/*Pointertowherenextcharacterwillbeinserted*/
- unsignedchar*RingBufRxOutPtr;/*Pointerfromwherenextcharacterwillbeextracted*/
- unsignedcharRingBufRx[SCI_RX_BUF_SIZE];/*Ringbuffercharacterstorage(Rx)*/
- shortRingBufTxCtr;/*NumberofcharactersintheTxringbuffer*/
- OS_EVENT*RingBufTxSem;/*PointertoTxsemaphore*/
- unsignedchar*RingBufTxInPtr;/*Pointertowherenextcharacterwillbeinserted*/
- unsignedchar*RingBufTxOutPtr;/*Pointerfromwherenextcharacterwillbeextracted*/
- unsignedcharRingBufTx[SCI_TX_BUF_SIZE];/*Ringbuffercharacterstorage(Tx)*/
- }SCI_RING_BUF;
- /**
- *Toobtainacharacterfromthecommunicationschannel.
- *@paramport,portcanbeSCI0/SCI1
- *@paramto,istheamountoftime(inclockticks)thatthecallingfunctioniswillingto
- *waitforacharactertoarrive.Ifyouspecifyatimeoutof0,thefunctionwill
- *waitforeverforacharactertoarrive.
- *@paramerr,isapointertowhereanerrorcodewillbeplaced:
- **errissettoSCI_NO_ERRifacharacterhasbeenreceived
- **errissettoSCI_RX_TIMEOUTifatimeoutoccurred
- **errissettoSCI_BAD_CHifyouspecifyaninvalidchannelnumber
- *@returnThecharacterinthebuffer(orNULifatimeoutoccurred)
- */
- unsignedcharSCIGetCharB(unsignedcharch,unsignedshortto,unsignedchar*err);
/**
- *Thisfunctioniscalledbyyourapplicationtosendacharacteronthecommunications
- *channel.Thefunctionwillwaitforthebuffertoemptyoutifthebufferisfull.
- *Thefunctionreturnstoyourapplicationifthebufferdoesntemptywithinthespecified
- *timeout.Atimeoutvalueof0meansthatthecallingfunctionwillwaitforeverforthe
- *buffertoemptyout.ThecharactertosendisfirstinsertedintotheTxbufferandwill
- *besentbytheTxISR.Ifthisisthefirstcharacterplacedintothebuffer,theTxISR
- *willbeenabled.
- *
- *@paramport,portcanbeSCI0/SCI1
- *@paramcisthecharactertosend.
- *@paramtoisthetimeout(inclockticks)towaitincasethebufferisfull.Ifyou
- *specifyatimeoutof0,thefunctionwillwaitforeverforthebuffertoempty.
- *@returnSCI_NO_ERRifthecharacterwasplacedintheTxbuffer
- *SCI_TX_TIMEOUTifthebufferdidntemptywithinthespecifiedtimeoutperiod
- *SCI_BAD_CHifyouspecifyaninvalidchannelnumber
- */
- unsignedcharSCIPutCharB(unsignedcharport,unsignedcharc,unsignedshortto);
/**
- *Toinitializethecommunicationsmodule.
- *Youmustcallthisfunctionbeforecallinganyotherfunctions.
- */
- voidSCIBufferInit(void);
/**
- *Toseeifanycharacterisavailablefromthecommunicationschannel.
- *
- *@paramport,portcanbeSCI0/SCI1
- *@returnIfatleaston