po_hi_utils.h 3.27 KB
Newer Older
1
2
3
4
5
/*
 * This is a part of PolyORB-HI-C distribution, a minimal
 * middleware written for generated code from AADL models.
 * You should use it with the Ocarina toolsuite.
 *
yoogx's avatar
yoogx committed
6
 * For more informations, please visit http://taste.tuxfamily.org/wiki
7
 *
8
 * Copyright (C) 2007-2009 Telecom ParisTech, 2010-2017 ESA & ISAE.
9
10
11
12
13
14
15
16
17
18
19
20
 */

#ifndef __PO_HI_UTILS_H__
#define __PO_HI_UTILS_H__

#include <po_hi_time.h>
#include <po_hi_types.h>

/*
 * Take a rate as argument, returns the probability that we meet this rate.
 */
int __po_hi_compute_miss (__po_hi_uint8_t rate);
21
22

unsigned long __po_hi_swap_byte (unsigned long value);
23

yoogx's avatar
yoogx committed
24
#if defined(__PO_HI_USE_VCD) && defined(__unix__)
25

26
27
#include <pthread.h>
#include <string.h>
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <deployment.h>

/* Types used to store the vcd trace */
typedef struct
{
  __po_hi_vcd_event_kind_t vcd_event_kind;
  uint64_t __po_hi_vcd_trace_timestamp;
  __po_hi_task_id task_id;
  __po_hi_local_port_t port_id;
  __po_hi_port_id_t port_queue_used_size;
  
} __po_hi_vcd_trace_element_t;

/* __po_hi_vcd_trace_max_nb_events used to reallocate the array 
 * of the vcd trace */
__po_hi_int32_t __po_hi_vcd_trace_max_nb_events;

/* __po_hi_vcd_trace_array an array containing the vcd trace
 * as elements with type __po_hi_vcd_trace_element_t  */
__po_hi_vcd_trace_element_t* __po_hi_vcd_trace_array;

/* __po_hi_vcd_trace_array_index is the index of __po_hi_vcd_trace_array
 * it should be protected as it is shared between tasks used to
 * save a new element in the array*/
__po_hi_int32_t __po_hi_vcd_trace_array_index;

/* mutex used to protect the index __po_hi_vcd_trace_array_index */
pthread_mutex_t __po_hi_vcd_trace_mutex;

/* __po_hi_get_larger_array_for_vcd_trace allows to reallocate a larger
 * array to save the vcd trace */
void __po_hi_get_larger_array_for_vcd_trace (void);

/* __po_hi_save_event_in_vcd_trace allows to save an element in
 * __po_hi_vcd_trace_array */
void __po_hi_save_event_in_vcd_trace (uint64_t timestamp, __po_hi_vcd_event_kind_t event_kind, __po_hi_task_id task, __po_hi_local_port_t port, __po_hi_port_id_t queue_size);

/* __po_hi_compute_timestamp : returns the actual instant
 * based on the __po_hi_vcd_start_t instant. The returned
 * value is in (ms) */
uint64_t __po_hi_compute_timestamp (void);

/* __po_hi_vcd_start_t is the start time and it is
 * set in the procedure __po_hi_initialize_vcd_trace */
__po_hi_time_t  __po_hi_vcd_start_t;

/* __po_hi_signalHandler is a SIGINT signal handler : it is invoked when
 * Ctrl-c is pressed in the keyboard to interrupt the execution
 * of the application. This handler allows a normal exit
 * of the program which enables the invocation
 * of the atexit function */
void __po_hi_signalHandler(int signo);

/* __po_hi_signalHandler create the vcd file and fill it
 * with the vcd trace saved in __po_hi_vcd_trace_array */
void __po_hi_create_vcd_file(void);

/* __po_hi_initialize_vcd_trace initializes some variables and catches
 * the SIGINT signal*/
void __po_hi_initialize_vcd_trace (void);
88

89
90
91
92
93
/* Variable keeping track of whether VCD tracing is enabled or not */
enum tagVCD {
    VCD_UNCHECKED,
    VCD_DISABLED,
    VCD_ENABLED
94
};
95

96
97
void __po_hi_instrumentation_vcd_init (void);

98
#define __PO_HI_INITIALIZE_VCD_TRACE __po_hi_initialize_vcd_trace ();
99
#else
100
   #define __PO_HI_INITIALIZE_VCD_TRACE
101
102
#endif

yoogx's avatar
yoogx committed
103
#endif /* __PO_HI_UTILS_H__ */