微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > Freescale 9S12 系列单片机应用笔记(SCI)3

Freescale 9S12 系列单片机应用笔记(SCI)3

时间:11-20 来源:互联网 点击:
这次介绍如何在 uC/OS-II 上实现串口驱动。

  1. /*sci_ucos.h*/
  2. #ifndef_SCI_RTOS_H_

  3. #define_SCI_RTOS_H_

    #defineSCI_RX_BUF_SIZE64/*NumberofcharactersinRxringbuffer*/

  4. #defineSCI_TX_BUF_SIZE64/*NumberofcharactersinTxringbuffer*/

    /*

  5. *********************************************************************************************************
  6. *CONSTANTS
  7. *********************************************************************************************************
  8. */

    #ifndefNUL

  9. #defineNUL0x00
  10. #endif

    /*ERRORCODES*/

  11. #defineSCI_NO_ERR0/*Functioncallwassuccessful*/
  12. #defineSCI_BAD_CH1/*Invalidcommunicationsportchannel*/
  13. #defineSCI_RX_EMPTY2/*Rxbufferisempty,nocharacteravailable*/
  14. #defineSCI_TX_FULL3/*Txbufferisfull,couldnotdepositcharacter*/
  15. #defineSCI_TX_EMPTY4/*IftheTxbufferisempty.*/
  16. #defineSCI_RX_TIMEOUT5/*Ifatimeoutoccurredwhilewaitingforacharacter*/
  17. #defineSCI_TX_TIMEOUT6/*Ifatimeoutoccurredwhilewaitingtosendachar.*/

  18. #defineSCI_PARITY_NONE0/*Definesforsettingparity*/
  19. #defineSCI_PARITY_ODD1
  20. #defineSCI_PARITY_EVEN2

  21. /*
  22. *********************************************************************************************************
  23. *DATATYPES
  24. *********************************************************************************************************
  25. */
  26. typedefstruct{
  27. shortRingBufRxCtr;/*NumberofcharactersintheRxringbuffer*/
  28. OS_EVENT*RingBufRxSem;/*PointertoRxsemaphore*/
  29. unsignedchar*RingBufRxInPtr;/*Pointertowherenextcharacterwillbeinserted*/
  30. unsignedchar*RingBufRxOutPtr;/*Pointerfromwherenextcharacterwillbeextracted*/
  31. unsignedcharRingBufRx[SCI_RX_BUF_SIZE];/*Ringbuffercharacterstorage(Rx)*/
  32. shortRingBufTxCtr;/*NumberofcharactersintheTxringbuffer*/
  33. OS_EVENT*RingBufTxSem;/*PointertoTxsemaphore*/
  34. unsignedchar*RingBufTxInPtr;/*Pointertowherenextcharacterwillbeinserted*/
  35. unsignedchar*RingBufTxOutPtr;/*Pointerfromwherenextcharacterwillbeextracted*/
  36. unsignedcharRingBufTx[SCI_TX_BUF_SIZE];/*Ringbuffercharacterstorage(Tx)*/
  37. }SCI_RING_BUF;

  38. /**
  39. *Toobtainacharacterfromthecommunicationschannel.
  40. *@paramport,portcanbeSCI0/SCI1
  41. *@paramto,istheamountoftime(inclockticks)thatthecallingfunctioniswillingto
  42. *waitforacharactertoarrive.Ifyouspecifyatimeoutof0,thefunctionwill
  43. *waitforeverforacharactertoarrive.
  44. *@paramerr,isapointertowhereanerrorcodewillbeplaced:
  45. **errissettoSCI_NO_ERRifacharacterhasbeenreceived
  46. **errissettoSCI_RX_TIMEOUTifatimeoutoccurred
  47. **errissettoSCI_BAD_CHifyouspecifyaninvalidchannelnumber
  48. *@returnThecharacterinthebuffer(orNULifatimeoutoccurred)
  49. */
  50. unsignedcharSCIGetCharB(unsignedcharch,unsignedshortto,unsignedchar*err);

    /**

  51. *Thisfunctioniscalledbyyourapplicationtosendacharacteronthecommunications
  52. *channel.Thefunctionwillwaitforthebuffertoemptyoutifthebufferisfull.
  53. *Thefunctionreturnstoyourapplicationifthebufferdoesntemptywithinthespecified
  54. *timeout.Atimeoutvalueof0meansthatthecallingfunctionwillwaitforeverforthe
  55. *buffertoemptyout.ThecharactertosendisfirstinsertedintotheTxbufferandwill
  56. *besentbytheTxISR.Ifthisisthefirstcharacterplacedintothebuffer,theTxISR
  57. *willbeenabled.
  58. *
  59. *@paramport,portcanbeSCI0/SCI1
  60. *@paramcisthecharactertosend.
  61. *@paramtoisthetimeout(inclockticks)towaitincasethebufferisfull.Ifyou
  62. *specifyatimeoutof0,thefunctionwillwaitforeverforthebuffertoempty.
  63. *@returnSCI_NO_ERRifthecharacterwasplacedintheTxbuffer
  64. *SCI_TX_TIMEOUTifthebufferdidntemptywithinthespecifiedtimeoutperiod
  65. *SCI_BAD_CHifyouspecifyaninvalidchannelnumber
  66. */
  67. unsignedcharSCIPutCharB(unsignedcharport,unsignedcharc,unsignedshortto);

    /**

  68. *Toinitializethecommunicationsmodule.
  69. *Youmustcallthisfunctionbeforecallinganyotherfunctions.
  70. */
  71. voidSCIBufferInit(void);

    /**

  72. *Toseeifanycharacterisavailablefromthecommunicationschannel.
  73. *
  74. *@paramport,portcanbeSCI0/SCI1
  75. *@returnIfatleaston

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top