uio.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #include "uio.h"
  2. #include "board.h"
  3. volatile unsigned char uiosBitStatus;
  4. unsigned char gtFlashSpeed=20;
  5. UIO_SWENUM uiosCtl[UIO_MAX];
  6. short uioTick[UIO_MAX];
  7. static void uioUpdateStatus(UIO_TYPEENUM uioType, UIO_STATUSENUM newStatus);
  8. static void newIoStatus(UIO_TYPEENUM value,UIO_SWENUM swType)
  9. {
  10. if(swType == uiosCtl[value]) return;
  11. uiosCtl[value]=swType;
  12. ;
  13. switch (uiosCtl[value])
  14. {
  15. case UIO_SW_KEEP_HIGH://保持常高
  16. case UIO_SW_KEEP_LOW: //保持常低
  17. uioTick[value]=0;
  18. break;
  19. case UIO_SW_FLASH_FAST:
  20. uioTick[value]=gtFlashSpeed;
  21. break;
  22. case UIO_SW_FLASH_SLOW:
  23. uioTick[value]=50;
  24. break;
  25. }
  26. uioUpdateStatus(value,UIO_LOW);//切换状态后让灯先灭
  27. }
  28. void uioStatusSet(UIO_INDENUM status){
  29. switch(status){
  30. case UIO_INDRX:
  31. newIoStatus(UIO_LED_RED, UIO_SW_KEEP_LOW);
  32. newIoStatus(UIO_LED_GREEN, UIO_SW_KEEP_HIGH);
  33. break;
  34. case UIO_INDTX:
  35. newIoStatus(UIO_LED_RED, UIO_SW_KEEP_HIGH);
  36. newIoStatus(UIO_LED_GREEN, UIO_SW_KEEP_LOW);
  37. break;
  38. case UIO_INDGT:
  39. gtFlashSpeed=10;
  40. newIoStatus(UIO_LED_RED, UIO_SW_FLASH_FAST);
  41. newIoStatus(UIO_LED_GREEN, UIO_SW_FLASH_FAST);
  42. uioTick[UIO_LED_GREEN]=gtFlashSpeed/2;//GT模式下经绿灯快闪错开一下
  43. break;
  44. case UIO_INDONLINE:
  45. newIoStatus(UIO_LED_RED, UIO_SW_KEEP_LOW);
  46. newIoStatus(UIO_LED_GREEN, UIO_SW_FLASH_SLOW);
  47. break;
  48. case UIO_INDOFFLINE:
  49. newIoStatus(UIO_LED_RED, UIO_SW_KEEP_LOW);
  50. newIoStatus(UIO_LED_GREEN, UIO_SW_FLASH_FAST);
  51. break;
  52. }
  53. }
  54. void uioStatusInit(void){
  55. newIoStatus(UIO_LED_RED, UIO_SW_KEEP_HIGH);
  56. newIoStatus(UIO_LED_GREEN, UIO_SW_KEEP_LOW);
  57. }
  58. static void uioUpdateStatus(UIO_TYPEENUM uioType, UIO_STATUSENUM newStatus){
  59. UIO_STATUSENUM lastBitStatus;
  60. if(uiosBitStatus & (1<<uioType)==0) lastBitStatus=UIO_LOW;
  61. else lastBitStatus=UIO_HIGH;
  62. switch(uioType){
  63. case UIO_LED_GREEN:
  64. greenLedCtl(newStatus);
  65. break;
  66. case UIO_LED_RED:
  67. redLedCtl(newStatus);
  68. break;
  69. default:return;
  70. }
  71. if(UIO_LOW==newStatus) uiosBitStatus &= ~(1<<uioType);
  72. else uiosBitStatus |= (1<<uioType);
  73. }
  74. /*定时被调用接口:dlyTime ms*/
  75. void uioProctl(unsigned int dlyTime){
  76. unsigned char i;
  77. static UIO_STATUSENUM lastStatus[UIO_MAX];
  78. for(i=0;i<UIO_MAX;i++){
  79. switch(uiosCtl[i]){
  80. case UIO_SW_KEEP_HIGH:
  81. uioUpdateStatus(i,UIO_HIGH);
  82. lastStatus[i]=UIO_HIGH;
  83. break;
  84. case UIO_SW_KEEP_LOW:
  85. uioUpdateStatus(i,UIO_LOW);
  86. lastStatus[i]=UIO_LOW;
  87. break;
  88. case UIO_SW_FLASH_FAST:
  89. if(uioTick[i]==0){
  90. if(lastStatus[i]==UIO_LOW){
  91. lastStatus[i]=UIO_HIGH;
  92. uioTick[i]=1;
  93. }else{
  94. lastStatus[i]=UIO_LOW;
  95. uioTick[i]=gtFlashSpeed;
  96. }
  97. uioUpdateStatus(i, lastStatus[i]);
  98. }else --uioTick[i];
  99. break;
  100. case UIO_SW_FLASH_SLOW:
  101. if(dlyTime<=100){//非休眠时灯的操作(休眠时会进入)
  102. if(uioTick[i]==0){
  103. if(lastStatus[i]==UIO_LOW){
  104. lastStatus[i]=UIO_HIGH;
  105. uioTick[i]=1;
  106. }else{
  107. lastStatus[i]=UIO_LOW;
  108. uioTick[i]=50;
  109. }
  110. uioUpdateStatus(i, lastStatus[i]);
  111. }else --uioTick[i];
  112. }else{//休眠时灯的操作
  113. //亮一会
  114. uioUpdateStatus(i, UIO_HIGH);
  115. LSAPI_OSI_ThreadSleep(100);
  116. uioUpdateStatus(i, UIO_LOW);
  117. }
  118. break;
  119. }
  120. }
  121. }