aboutsummaryrefslogtreecommitdiff
path: root/debugger/include/checkpoint.h
blob: 1155295badd767bd54277104be498c6b8957e63f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
 * Arm SCP/MCP Software
 * Copyright (c) 2020, Arm Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */
#ifndef CHECKPOINT_H
#define CHECKPOINT_H

#include <stdbool.h>
#include <stdint.h>

/*!
 * \addtogroup GroupCLIDebugger
 * \{
 */

/*!
 * Length of checkpoint thread names.
 *
 */
#define CHECKPOINT_NAME_LEN 16

/*!
 * Length of checkpoint tags.
 *
 */
#define CHECKPOINT_TAG_LEN 32

/*!
 * Maximum number of checkpoints.
 *
 */
#define CHECKPOINT_NUM 4

/*!
 * \brief Checkpoint bypass value.
 *
 */
enum cp_bypass_value {
    /*! Stop execution when checkpoint is reached. */
    CHECKPOINT_ENABLED = 0,
    /*! Ignore checkpoint */
    CHECKPOINT_DISABLED = -1
};

/*!
 * \brief Checkpoint descriptor
 *
 * \details This structure holds the proparities of a checkpoint.
 *      It should be populated by calling checkpoint_register function.
 *
 */
typedef struct {
    /*! Index in the checkpoint table */
    uint32_t index;
    /*! Description of the function registering */
    char name[CHECKPOINT_NAME_LEN];
    /*! Tag is used to identify the checkpoint */
    char tag[CHECKPOINT_TAG_LEN];
    /*! Enable or disable the checkpoint */
    volatile int32_t bypass;
    /*! Valid checkpoint in the checkpoint table */
    bool in_use;
} checkpoint_st;

/*!
 * \brief Disables all checkpoints in the system.
 *
 */
void checkpoint_disable_all(void);

#ifdef BUILD_HAS_DEBUGGER

/*!
 * \brief Enables all checkpoints in the system.
 *
 */
void checkpoint_enable_all(void);

/*!
 * \brief Request a new checkpoint structure
 *
 * \param c Pointer to a checkpoint_st pointer, is set when the function returns
 *          successfully.
 * \param name Name or description of the function registering. Must be less
 *             than CHECKPOINT_NAME_LEN characters in length.
 * \retval ::FWK_SUCCESS if operation is successful.
 * \retval ::FWK_E_NOMEM when checkpoints limit is reached.
 *
 */
int32_t checkpoint_register(checkpoint_st **c, char *name);

/*!
 * \brief Insert a checkpoint
 *
 * \details Checkpoint function for use within code. When this function is
 *      called and checkpoints are disabled, it will return immediately.
 *      If checkpoints are enabled, it will print a message indicating that
 *      it is pausing and activate the CLI. When the command line exists This
 *      function will return and normal execution is resumed.
 *
 * \param c Pointer to valid checkpoint structure, obtained through a call to
 *          checkpoint_register.
 * \param file Name of the file in which the checkpoint exists,
 *             use __FILE__ macro.
 * \param line Line number of the checkpoint, use __LINE__ macro.
 * \param tag Checkpoint tag string.
 */
void checkpoint(checkpoint_st *c, char *file, int32_t line, char *tag);

#else

/*!
 * \brief Enables all checkpoints in the system.
 *
 */
#define checkpoint_enable_all() (void)0

/*!
 * \brief Request a new checkpoint structure
 *
 * \param c Pointer to a checkpoint_st pointer, is set when the function returns
 *          successfully.
 * \param name Name or description of the function registering. Must be less
 *             than CHECKPOINT_NAME_LEN characters in length.
 * \retval ::FWK_SUCCESS if operation is successful.
 * \retval ::FWK_E_NOMEM when checkpoints limit is reached.
 *
 */
#    define checkpoint_register(c, name) \
        ({ \
            (void)c; \
            (void)name; \
            FWK_SUCCESS; \
        })

/*!
 * \brief Insert a checkpoint
 *
 * \details Checkpoint function for use within code. When this function is
 *      called and checkpoints are disabled, it will return immediately.
 *      If checkpoints are enabled, it will print a message indicating that
 *      it is pausing and activate the CLI. When the command line exists This
 *      function will return and normal execution is resumed.
 *
 * \param c Pointer to valid checkpoint structure, obtained through a call to
 *          checkpoint_register.
 * \param file Name of the file in which the checkpoint exists,
 *             use __FILE__ macro.
 * \param line Line number of the checkpoint, use __LINE__ macro.
 * \param tag Checkpoint tag string.
 */
#    define checkpoint(c, file, line, tag) \
        do { \
            (void)c; \
            (void)file; \
            (void)line; \
            (void)tag; \
        } while (0)

#endif

/*!
 * \}
 */

#endif /* CHECKPOINT_H */