1 /* 2 * Copyright (c) 2012-2014 Wind River Systems, Inc. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _LATENCY_MEASURE_UNIT_H 8 #define _LATENCY_MEASURE_UNIT_H 9 /* 10 * @brief This file contains function declarations, macroses and inline functions 11 * used in latency measurement. 12 */ 13 14 #include <zephyr/timing/timing.h> 15 #include <zephyr/sys/printk.h> 16 #include <stdio.h> 17 #include <zephyr/timestamp.h> 18 19 #define INT_IMM8_OFFSET 1 20 #define IRQ_PRIORITY 3 21 22 extern int error_count; 23 24 #define TICK_OCCURRENCE_ERROR "Error: Tick Occurred" 25 26 #ifdef CSV_FORMAT_OUTPUT 27 #define FORMAT_STR "%-52s,%s,%s,%s\n" 28 #define CYCLE_FORMAT "%8u" 29 #define NSEC_FORMAT "%8u" 30 #else 31 #define FORMAT_STR "%-52s:%s , %s : %s\n" 32 #define CYCLE_FORMAT "%8u cycles" 33 #define NSEC_FORMAT "%8u ns" 34 #endif 35 36 /** 37 * @brief Display a line of statistics 38 * 39 * This macro displays the following: 40 * 1. Test description summary 41 * 2. Number of cycles - See Note 42 * 3. Number of nanoseconds - See Note 43 * 4. Additional notes describing the nature of any errors 44 * 45 * Note - If the @a error parameter is not false, then the test has no 46 * numerical information to print and it will instead print "FAILED". 47 */ 48 #define PRINT_F(summary, cycles, nsec, error, notes) \ 49 do { \ 50 char cycle_str[32]; \ 51 char nsec_str[32]; \ 52 \ 53 if (!error) { \ 54 snprintk(cycle_str, 30, CYCLE_FORMAT, cycles); \ 55 snprintk(nsec_str, 30, NSEC_FORMAT, nsec); \ 56 } else { \ 57 snprintk(cycle_str, 30, "%15s", "FAILED"); \ 58 snprintk(nsec_str, 30, "%15s", "FAILED"); \ 59 } \ 60 printk(FORMAT_STR, summary, cycle_str, nsec_str, notes); \ 61 } while (0) 62 63 #define PRINT_STATS(summary, value, error, notes) \ 64 PRINT_F(summary, value, \ 65 (uint32_t)timing_cycles_to_ns(value), \ 66 error, notes) 67 68 #define PRINT_STATS_AVG(summary, value, counter, error, notes) \ 69 PRINT_F(summary, value / counter, \ 70 (uint32_t)timing_cycles_to_ns_avg(value, counter), \ 71 error, notes); 72 73 74 #endif 75