Subversion Repositories HomeAutomation

Rev

Rev 1530 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. #include "sns_identification.h"
  3. uint8_t sns_identification_pinStatus;
  4. #define HIGH        1
  5. #define LOW         2
  6. #define NOCHANGE    0
  7. #define HIGH_NOCH   3
  8. #define LOW_NOCH    4
  9.  
  10. #define IO_HIGH     1
  11. #define IO_LOW      0
  12.  
  13.  
  14. void sns_identification_pcint_callback(uint8_t id, uint8_t status)
  15. {
  16. #ifdef  sns_identification_PIN
  17. #if sns_identification_PCA95xxIO==0
  18.     if (id == sns_identification_PCINT) {
  19.       if (IO_LOW != status) {
  20.         sns_identification_pinStatus = HIGH;
  21.       } else {
  22.         sns_identification_pinStatus = LOW;
  23.       }
  24.     }
  25. #endif
  26. #endif
  27. }
  28.  
  29. #if sns_identification_PCA95xxIO==1
  30. /*void sns_identification_PCA95xx_callback(uint16_t status)
  31. {
  32.     printf("0x%x\n",status);
  33. }*/
  34. #endif
  35.  
  36. void sns_identification_Init(void)
  37. {
  38.     sns_identification_pinStatus = NOCHANGE;
  39.  
  40. #if sns_identification_PCA95xxIO==1
  41.     Pca95xx_Init(0);
  42. #endif
  43.  
  44. #ifdef  sns_identification_PIN
  45. #if sns_identification_PCA95xxIO==0
  46.     #if (sns_identification_pullup == 1)
  47.         gpio_set_pullup(sns_identification_PIN);
  48.     #else
  49.         gpio_clr_pullup(sns_identification_PIN);
  50.     #endif
  51.         gpio_set_in(sns_identification_PIN);
  52.         Pcint_SetCallbackPin(sns_identification_PCINT, sns_identification_PIN, &sns_identification_pcint_callback);
  53. #else
  54.         Pca95xx_set_in(sns_identification_PIN);
  55. #endif
  56. #endif
  57.  
  58. #if sns_identification_PCA95xxIO==1
  59.     uint16_t status = Pca95xx_GetInputs();
  60. #ifdef  sns_identification_PIN
  61. #if sns_identification_PCA95xxIO==1
  62.     if (((status>>sns_identification_PIN)&0x1) != IO_LOW) {
  63.         sns_identification_pinStatus = HIGH_NOCH;
  64.     } else {
  65.         sns_identification_pinStatus = LOW_NOCH;
  66.     }
  67. #endif
  68. #endif
  69.     /* Currently only polling of ports is implemented */
  70.     //Pca95xx_SetCallback(sns_identification_PCA95XX_CALLBACK_INDEX, &sns_identification_PCA95xx_callback);
  71. #endif
  72.  
  73.     Timer_SetTimeout(sns_identification_POLL_TIMER, sns_identification_POLL_TIME_MS, TimerTypeFreeRunning, 0);
  74. }
  75.  
  76. void sns_identification_Process(void)
  77. {
  78.     if (Timer_Expired(sns_identification_POLL_TIMER))
  79.     {
  80. #if sns_identification_PCA95xxIO==1
  81.         uint16_t status = Pca95xx_GetInputs();
  82. #ifdef  sns_identification_PIN
  83. #if sns_identification_PCA95xxIO==1
  84.         if (sns_identification_pinStatus == LOW_NOCH && ((status>>sns_identification_PIN)&0x1) == IO_HIGH) {
  85.             sns_identification_pinStatus = HIGH;
  86.         } else if (sns_identification_pinStatus == HIGH_NOCH && ((status>>sns_identification_PIN)&0x1) == IO_LOW) {
  87.             sns_identification_pinStatus = LOW;
  88.         }
  89. #endif
  90. #endif
  91. #endif
  92.  
  93.         if (sns_identification_pinStatus == LOW) {
  94.             StdCan_Msg_t txMsg;
  95.             StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
  96.             StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  97.             txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IDENTIFICATION;
  98.             txMsg.Header.ModuleId = sns_identification_ID;
  99.             txMsg.Header.Command = CAN_MODULE_CMD_IDENTIFICATION_ID;
  100.             txMsg.Length = 4;
  101.             uint32_t HwId=BIOS_GetHwId();
  102.             txMsg.Data[0] = HwId&0xff;
  103.             txMsg.Data[1] = (HwId>>8)&0xff;
  104.             txMsg.Data[2] = (HwId>>16)&0xff;
  105.             txMsg.Data[3] = (HwId>>24)&0xff;
  106.             sns_identification_pinStatus = LOW_NOCH;
  107.             while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  108.         }
  109.         else if (sns_identification_pinStatus == HIGH)
  110.         {
  111.             sns_identification_pinStatus = HIGH_NOCH;
  112.         }
  113.     }
  114. }
  115.  
  116. void sns_identification_HandleMessage(StdCan_Msg_t *rxMsg)
  117. {
  118.    
  119. }
  120.  
  121. void sns_identification_List(uint8_t ModuleSequenceNumber)
  122. {
  123.     StdCan_Msg_t txMsg;
  124.    
  125.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
  126.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  127.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_IDENTIFICATION;
  128.     txMsg.Header.ModuleId = sns_identification_ID;
  129.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  130.     txMsg.Length = 6;
  131.  
  132.     uint32_t HwId=BIOS_GetHwId();
  133.     txMsg.Data[0] = HwId&0xff;
  134.     txMsg.Data[1] = (HwId>>8)&0xff;
  135.     txMsg.Data[2] = (HwId>>16)&0xff;
  136.     txMsg.Data[3] = (HwId>>24)&0xff;
  137.    
  138.     txMsg.Data[4] = NUMBER_OF_MODULES;
  139.     txMsg.Data[5] = ModuleSequenceNumber;
  140.    
  141.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  142. }
  143.