PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* Copyright (c) 2002, 2003, 2004 Marek Michalkiewicz
  2. Copyright (c) 2005, 2007 Joerg Wunsch
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in
  10. the documentation and/or other materials provided with the
  11. distribution.
  12. * Neither the name of the copyright holders nor the names of
  13. contributors may be used to endorse or promote products derived
  14. from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  18. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  19. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  20. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  21. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  22. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  23. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  24. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  25. POSSIBILITY OF SUCH DAMAGE. */
  26. // Port to Energia / MPS430 by Yannick DEVOS XV4Y - (c) 2013
  27. // http://xv4y.radioclub.asia/
  28. //
  29. // Adapted to RadioHead use by Mike McCauley 2014
  30. // This is to prevent name collisions with other similar library functions
  31. // and to provide a consistent API amonng all processors
  32. //
  33. /* $Id: RHCRC.cpp,v 1.1 2014/06/24 02:40:12 mikem Exp $ */
  34. #include <RHCRC.h>
  35. #define lo8(x) ((x)&0xff)
  36. #define hi8(x) ((x)>>8)
  37. uint16_t RHcrc16_update(uint16_t crc, uint8_t a)
  38. {
  39. int i;
  40. crc ^= a;
  41. for (i = 0; i < 8; ++i)
  42. {
  43. if (crc & 1)
  44. crc = (crc >> 1) ^ 0xA001;
  45. else
  46. crc = (crc >> 1);
  47. }
  48. return crc;
  49. }
  50. uint16_t RHcrc_xmodem_update (uint16_t crc, uint8_t data)
  51. {
  52. int i;
  53. crc = crc ^ ((uint16_t)data << 8);
  54. for (i=0; i<8; i++)
  55. {
  56. if (crc & 0x8000)
  57. crc = (crc << 1) ^ 0x1021;
  58. else
  59. crc <<= 1;
  60. }
  61. return crc;
  62. }
  63. uint16_t RHcrc_ccitt_update (uint16_t crc, uint8_t data)
  64. {
  65. data ^= lo8 (crc);
  66. data ^= data << 4;
  67. return ((((uint16_t)data << 8) | hi8 (crc)) ^ (uint8_t)(data >> 4)
  68. ^ ((uint16_t)data << 3));
  69. }
  70. uint8_t RHcrc_ibutton_update(uint8_t crc, uint8_t data)
  71. {
  72. uint8_t i;
  73. crc = crc ^ data;
  74. for (i = 0; i < 8; i++)
  75. {
  76. if (crc & 0x01)
  77. crc = (crc >> 1) ^ 0x8C;
  78. else
  79. crc >>= 1;
  80. }
  81. return crc;
  82. }