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

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

时间:11-20 来源:互联网 点击:

  1. if(pbuf->RingBufTxOutPtr==&pbuf->if(pbuf->RingBufTxOutPtr==&pbuf->RingBufTx[SCI_TX_BUF_SIZE]){/*WrapOUTpointer*/
  2. pbuf->RingBufTxOutPtr=&pbuf->RingBufTx[0];
  3. }
  4. (void)OSSemPost(pbuf->RingBufTxSem);/*Indicatethatcharacterwillbesent*/
  5. *err=SCI_NO_ERR;
  6. return(c);/*Charactersarestillavailable*/
  7. }else{
  8. *err=SCI_TX_EMPTY;
  9. return(NUL);/*Bufferisempty*/
  10. }
  11. }

  12. voidSCI0_ISR_Handler(void)
  13. {
  14. charstatus;
  15. chardata;
  16. unsignedcharerr;
  17. status=SCI0SR1;

    if(status&0x0F)//0x1F=00011111,ifstatusisnotReceiveDataRegFullFlag

  18. {
  19. //Seeifwehavesomekindoferror
  20. //Clearinterrupt(donothingaboutit!)
  21. data=SCI0DRL;
  22. }
  23. elseif(status&0x20)//ReceiveDataRegFullFlag
  24. {
  25. data=SCI0DRL;
  26. SCIPutRxChar(SCI0,data);//Insertreceivedcharacterintobuffer
  27. }
  28. elseif(status&0x80)
  29. {
  30. data=SCIGetTxChar(SCI0,&err);//Getnextcharactertosend.
  31. if(err==SCI_TX_EMPTY)
  32. {//Dowehaveanymorecharacterstosend?
  33. //No,DisableTxinterrupts
  34. SCIDisTxInt(SCI0);
  35. }
  36. else
  37. {
  38. SCI0DRL=data;//Yes,Sendcharacter
  39. }
  40. }
  41. }

  42. voidSCI1_ISR_Handler(void)
  43. {
  44. charstatus;
  45. chardata;
  46. unsignedcharerr;
  47. status=SCI1SR1;

    if(status&0x0F)//0x1F=00011111,ifstatusisnotReceiveDataRegFullFlag

  48. {
  49. //Seeifwehavesomekindoferror
  50. //Clearinterrupt(donothingaboutit!)
  51. data=SCI1DRL;
  52. }
  53. elseif(status&0x20)//ReceiveDataRegFullFlag
  54. {
  55. data=SCI1DRL;
  56. SCIPutRxChar(SCI1,data);//Insertreceivedcharacterintobuffer
  57. }
  58. elseif(status&0x80)
  59. {
  60. data=SCIGetTxChar(SCI1,&err);//Getnextcharactertosend.
  61. if(err==SCI_TX_EMPTY)
  62. {//Dowehaveanymorecharacterstosend?
  63. //No,DisableTxinterrupts
  64. SCIDisTxInt(SCI1);
  65. }
  66. else
  67. {
  68. SCI1DRL=data;//Yes,Sendcharacter
  69. }
  70. }
  71. }

    #pragmaCODE_SEGNON_BANKED

  72. interruptVectorNumber_Vsci0voidSCI0_ISR(void)
  73. {

    #ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)

  74. __asmldaaPPAGE;//3~,GetcurrentvalueofPPAGEregister
  75. __asmpsha;//2~,PushPPAGEregisterontocurrenttasksstack
  76. #endif
  77. __asmincOSIntNesting;//OSIntNesting++;

    //if(OSIntNesting==1)

  78. //{
  79. //OSTCBCur->OSTCBStkPtr=StackPointer;
  80. //}
  81. __asm
  82. {
  83. ldabOSIntNesting
  84. cmpb#$01
  85. bneSCI0ISR1

    ldxOSTCBCur

  86. sts0,x
  87. SCI0ISR1:
  88. }

    #ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)

  89. __asmcallSCI0_ISR_Handler;
  90. __asmcallOSIntExit;
  91. #else
  92. __asmjsrSCI0_ISR_Handler;
  93. __asmjsrOSIntExit;
  94. #endif

    #ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)

  95. __asmpula;//3~,GetvalueofPPAGEregister
  96. __asmstaaPPAGE;//3~,StoreintoCPUsPPAGEregister
  97. #endif

    }

    interruptVectorNumber_Vsci1voidSCI1_ISR(void)

  98. {

    #ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)

  99. __asmldaaPPAGE;//3~,GetcurrentvalueofPPAGEregister
  100. __asmpsha;//2~,PushPPAGEregisterontocurrenttasksstack
  101. #endif
  102. __asmincOSIntNesting;//OSIntNesting++;

    //if(OSIntNesting==1)

  103. //{
  104. //OSTCBCur->OSTCBStkPtr=StackPointer;
  105. //}
  106. __asm
  107. {
  108. ldabOSIntNesting
  109. cmpb#$01
  110. bneSCI1ISR1

    ldxOSTCBCur

  111. sts0,x
  112. SCI1ISR1:
  113. }

    #ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)

  114. __asmcallSCI1_ISR_Handler;
  115. __asmcallOSIntExit;
  116. #else
  117. __asmjsrSCI1_ISR_Handler;
  118. __asmjsrOSIntExit;
  119. #endif

    #ifdefined(__BANKED__)||defined(__LARGE__)||defined(__PPAGE__)

  120. __asmpula;//3~,GetvalueofPPAGEregister
  121. __asmstaaPPAGE;//3~,StoreintoCPUsPPAGEregister
  122. #endif

    }

下面给个简单的例子:

  1. #include/*commondefinesandmacros*/

  2. #include"derivative.h"/*derivative-specificdefinitions*/

    #include"INCLUDES.H"

  3. #include"crg.h"
  4. #include"sci.h"
  5. #include"sci_rtos.h"

    OS_STKAppStartTaskStk[64];

    staticvoidAppStartTask(void*pdata);

    voidmain(void)

  6. {
  7. /*putyourowncodehere*/
  8. OS_CPU_SRcpu_sr;

    CRGInit();

  9. CRGSetRTIFreqency(0x54);//200Hz

    EnableInterrupts;

  10. OS_ENTER_CRITICAL();
  11. SCIInit(SCI0);
  12. SCIInit(SCI1);
  13. OS_EXIT_CRITICAL();
  14. OSInit();
  15. SCISetIEBit(SCI0,SCI_RIE);
  16. SCISetIEBit(SCI1,SCI_RIE);
  17. SCIBufferInit();
  18. (void)OSTaskCreate(AppStartTask,(void*)0x4321,(void*)&AppStartTaskStk[63],0);
  19. (void)OSStart();
  20. for(;;)
  21. {
  22. _FEED_COP();/*feedsthedog*/
  23. }/*loopforever*/
  24. /*pleasemakesurethatyouneverleavemain*/
  25. }

    staticvoidAppStartTask(void*pdata)

  26. {
  27. INT8Uerr;
  28. charC;
  29. (void)pdata;
  30. for(;;)
  31. {
  32. C=SCIGetCharB

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

网站地图

Top