uio.c 2.8 KB

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