blob: 73bbf38d2ad2531029a9120118afab06aed0f25f [file] [log] [blame]
John Wangd8702f62019-10-31 10:06:35 +08001#ifndef UTILS_H__
2#define UTILS_H__
3
4#ifdef __cplusplus
5extern "C" {
6#endif
7
John Wang72136232019-11-14 15:33:42 +08008#include "pldm_types.h"
John Wangd8702f62019-10-31 10:06:35 +08009#include <stddef.h>
10#include <stdint.h>
11
12/** @brief Compute Crc32(same as the one used by IEEE802.3)
13 *
14 * @param[in] data - Pointer to the target data
15 * @param[in] size - Size of the data
16 * @return The checksum
17 */
18uint32_t crc32(const void *data, size_t size);
19
John Wang72136232019-11-14 15:33:42 +080020/** @brief Convert ver32_t to string
21 * @param[in] version - Pointer to ver32_t
22 * @param[out] buffer - Pointer to the buffer
23 * @param[in] buffer_size - Size of the buffer
24 * @return The number of characters(excluding the null byte) or negative if
25 * error is encountered
26 */
27int ver2str(const ver32_t *version, char *buffer, size_t buffer_size);
28
John Wang5bdb30a2019-11-20 15:28:37 +080029/** @breif Convert bcd number(uint8_t) to decimal
30 * @param[in] bcd - bcd number
31 * @return the decimal number
32 */
33uint8_t bcd2dec8(uint8_t bcd);
34
35/** @breif Convert decimal number(uint8_t) to bcd
36 * @param[in] dec - decimal number
37 * @return the bcd number
38 */
39uint8_t dec2bcd8(uint8_t dec);
40
41/** @breif Convert bcd number(uint16_t) to decimal
42 * @param[in] bcd - bcd number
43 * @return the decimal number
44 */
45uint16_t bcd2dec16(uint16_t bcd);
46
47/** @breif Convert decimal number(uint16_t) to bcd
48 * @param[in] dec - decimal number
49 * @return the bcd number
50 */
51uint16_t dec2bcd16(uint16_t dec);
52
53/** @breif Convert bcd number(uint32_t) to decimal
54 * @param[in] bcd - bcd number
55 * @return the decimal number
56 */
57uint32_t bcd2dec32(uint32_t bcd);
58
59/** @breif Convert decimal number(uint32_t) to bcd
60 * @param[in] dec - decimal number
61 * @return the bcd number
62 */
63uint32_t dec2bcd32(uint32_t dec);
64
John Wangd8702f62019-10-31 10:06:35 +080065#ifdef __cplusplus
66}
67#endif
68
John Wang72136232019-11-14 15:33:42 +080069#endif