Blame view

RIOT/sys/include/checksum/crc16_ccitt.h 1.75 KB
fb11e647   vrobic   reseau statique a...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
  /*
   * Copyright 2016 Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
   *
   * This file is subject to the terms and conditions of the GNU Lesser
   * General Public License v2.1. See the file LICENSE in the top level
   * directory for more details.
   */
  
  /**
   * @defgroup    sys_checksum_crc16_ccitt CRC16-CCITT
   * @ingroup     sys_checksum
   *
   * @brief       CRC16-CCITT checksum algorithm
   * @details     This implementation of CRC16 is based on the CCITT
   *              specification using 0x1D0F as a start value.
   *              Using a different start value is possible by calling
   *              crc16_ccitt_update() with the desired start value
   *              instead of crc16_ccitt_calc().
   *
   * @{
   * @file
   * @author      Ludwig Knüpfer <ludwig.knuepfer@fu-berlin.de>
   */
  
  #ifndef CRC16_CCITT_H
  #define CRC16_CCITT_H
  
  #include <stdint.h>
  #include <stdlib.h>
  
  #ifdef __cplusplus
  extern "C" {
  #endif
  
  /**
   * @brief           Update CRC16-CCITT
   *
   * @param[in]  crc  A start value for the CRC calculation, usually the
   *                  return value of a previous call to
   *                  crc16_ccitt_calc() or crc16_ccitt_update()
   * @param[in]  buf  Start of the memory area to checksum
   * @param[in]  len  Number of bytes to checksum
   *
   * @return          Checksum of the specified memory area based on the
   *                  given start value
   */
  uint16_t crc16_ccitt_update(uint16_t crc, const unsigned char *buf, size_t len);
  
  /**
   * @brief           Calculate CRC16-CCITT
   *
   * @param[in]  buf  Start of the memory area to checksum
   * @param[in]  len  Number of bytes to checksum
   *
   * @return          Checksum of the specified memory area
   */
  uint16_t crc16_ccitt_calc(const unsigned char *buf, size_t len);
  
  
  #ifdef __cplusplus
  }
  #endif
  
  #endif /* CRC16_CCITT_H */
  
  /** @} */