John Wang | d8702f6 | 2019-10-31 10:06:35 +0800 | [diff] [blame] | 1 | #ifndef UTILS_H__ |
| 2 | #define UTILS_H__ |
| 3 | |
| 4 | #ifdef __cplusplus |
| 5 | extern "C" { |
| 6 | #endif |
| 7 | |
John Wang | 7213623 | 2019-11-14 15:33:42 +0800 | [diff] [blame] | 8 | #include "pldm_types.h" |
John Wang | d8702f6 | 2019-10-31 10:06:35 +0800 | [diff] [blame] | 9 | #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 | */ |
| 18 | uint32_t crc32(const void *data, size_t size); |
| 19 | |
John Wang | 7213623 | 2019-11-14 15:33:42 +0800 | [diff] [blame] | 20 | /** @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 | */ |
| 27 | int ver2str(const ver32_t *version, char *buffer, size_t buffer_size); |
| 28 | |
John Wang | 5bdb30a | 2019-11-20 15:28:37 +0800 | [diff] [blame] | 29 | /** @breif Convert bcd number(uint8_t) to decimal |
| 30 | * @param[in] bcd - bcd number |
| 31 | * @return the decimal number |
| 32 | */ |
| 33 | uint8_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 | */ |
| 39 | uint8_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 | */ |
| 45 | uint16_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 | */ |
| 51 | uint16_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 | */ |
| 57 | uint32_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 | */ |
| 63 | uint32_t dec2bcd32(uint32_t dec); |
| 64 | |
John Wang | d8702f6 | 2019-10-31 10:06:35 +0800 | [diff] [blame] | 65 | #ifdef __cplusplus |
| 66 | } |
| 67 | #endif |
| 68 | |
John Wang | 7213623 | 2019-11-14 15:33:42 +0800 | [diff] [blame] | 69 | #endif |