1 /* 2 * Copyright (c) 2022 Winner Microelectronics Co., Ltd. All rights reserved. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 /************************************************************************** 17 * File Name : utils.h 18 * Author : 19 * Version : 1.0 20 * Date : 21 * Description : 22 * 23 * Copyright (c) 2014 Winner Microelectronics Co., Ltd. 24 * All rights reserved. 25 * 26 ***************************************************************************/ 27 #ifndef UTILS_H 28 #define UTILS_H 29 30 int chk_crc8(u8 *ptr, u32 len); 31 u8 get_crc8(u8 *ptr, u32 len); 32 u8 calculate_crc8(u8 crc8, u8 *ptr, u32 len); 33 u32 get_crc32(u8 *data, u32 data_size); 34 u32 checksum(u32 *data, u32 length, u32 init); 35 int atodec(char ch); 36 int strtodec(int *dec, char *str); 37 int atohex(char ch); 38 int strtohex(u32 *hex, char *str); 39 int strtohexarray(u8 array[], int cnt, char *str); 40 int strtoip(u32 *ipadr, char *str); 41 void iptostr(u32 ip, char *str); 42 void mactostr(u8 mac[], char *str); 43 44 int hex_to_digit(int c); 45 int digit_to_hex(int c); 46 int hexstr_to_unit(char *buf, u32 *d); 47 int string_to_uint(char *buf, u32 *d); 48 int string_to_ipaddr(const char *buf, u8 *addr); 49 char *strdup(const char *s); 50 char *strndup(const char *s, size_t len); 51 52 int sendchar(int ch); 53 54 #endif /* UTILS_H */ 55