uio.c 2.9 KB

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