cmicx_sim_util.h (2143B)
1 /* 2 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 3 * 4 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 5 */ 6 7 8 /* 9 * cmicx_sim_util.h 10 * 11 * utilities header file. does definitions for things like logging, error logging, etc 12 */ 13 14 #ifndef _CMICX_SIM_UTIL_H_ 15 #define _CMICX_SIM_UTIL_H_ 16 17 #ifndef __KERNEL__ 18 #ifdef __linux__ 19 #include <stdint.h> 20 #endif 21 #endif 22 23 #ifndef __KERNEL__ 24 #include <time.h> 25 #else 26 #include <linux/time.h> 27 #endif 28 29 30 /* for bool stuff */ 31 #ifndef __KERNEL__ 32 typedef unsigned char bool; 33 #endif 34 #define true 1 35 #define false 0 36 37 #ifdef __linux__ 38 typedef unsigned int addr_t; 39 #endif 40 41 /* typedefs for certain primitive types used everywhere */ 42 typedef unsigned int reg_t; 43 #ifdef CMICX_STANDALONE_SIM 44 typedef unsigned char uint8; 45 typedef unsigned char uint8_t; 46 typedef unsigned int uint32; 47 typedef unsigned int uint32_t; 48 typedef long unsigned int uint64; 49 #endif 50 51 /* pcid function types */ 52 typedef bool pcid_read_func_t(reg_t*); 53 typedef bool pcid_write_func_t(reg_t); 54 55 /* initialize cmicx logging to a certain file */ 56 bool cmicx_logging_init(char *); 57 58 /* logging and error functions */ 59 void cmicx_log_level_set(int); 60 void cmicx_log_level_cutoff_set(int); 61 void cmicx_log(char *); 62 void cmicx_error(char *); 63 void cmicx_log_str(char *); 64 void cmicx_log_addr(addr_t); 65 void cmicx_log_reg(reg_t); 66 void cmicx_log_int(int); 67 void cmicx_log_unsigned(unsigned int); 68 void cmicx_log_hex(unsigned int); 69 void cmicx_log_uint64(uint64_t); 70 void cmicx_log_byte(unsigned char); 71 void cmicx_log_long(unsigned long); 72 void cmicx_log_newline(void); 73 74 /* function to log the elapsed time since the last time this function was called. */ 75 void cmicx_log_elapsed_time(void); 76 77 /* returns the timespec formatted difference in time between two timespecs */ 78 void cmicx_timespec_diff(const struct timespec * const start_time, 79 const struct timespec * const end_time, 80 struct timespec * const diff_time); 81 82 /* random functions (endianness, etc) */ 83 reg_t cmicx_reverse_word_endianness(reg_t val); 84 85 86 #endif /* _CMICX_SIM_UTIL_H_ */ 87