/
ErrorCodes.h
133 lines (113 loc) · 6.54 KB
/
ErrorCodes.h
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
/** \file ErrorCodes.h
* Header file for the result and error codes, and associated macros.
* \author Garry Jeromson
* \date 18.06.2015
*
* Copyright (c) 2015 Enclustra GmbH, Switzerland.
* All rights reserved.
*/
#pragma once
//-------------------------------------------------------------------------------------------------
// Error code definitions
//-------------------------------------------------------------------------------------------------
/** \cond */
typedef enum EN_RESULT
{
EN_SUCCESS = 0x00000000,
EN_ERROR_NULL_POINTER = 0x80000000,
EN_ERROR_INVALID_ARGUMENT,
EN_ERROR_FAILED_TO_SET_I2C_DEVICE_ADDRESS,
EN_ERROR_FAILED_TO_INITIALISE_I2C_CONTROLLER,
EN_ERROR_FAILED_TO_START_XIIC_DEVICE,
EN_ERROR_FAILED_TO_STOP_XIIC_DEVICE,
EN_ERROR_FAILED_TO_INITIALISE_INTERRUPT_CONTROLLER,
EN_ERROR_FAILED_TO_START_INTERRUPT_CONTROLLER,
EN_ERROR_XIIC_SEND_FAILED,
EN_ERROR_XIIC_RECEIVE_FAILED,
EN_ERROR_I2C_READ_FAILED,
EN_ERROR_I2C_WRITE_FAILED,
EN_ERROR_I2C_READ_TIMEOUT,
EN_ERROR_I2C_WRITE_TIMEOUT,
EN_ERROR_I2C_SLAVE_NACK,
EN_ERROR_TIMER_INITIALISATION_FAILED,
EN_ERROR_TIMER_SELF_TEST_FAILED,
EN_ERROR_INVALID_MODULE_CONFIG_PROPERTY_INDEX,
EN_ERROR_MODULE_CONFIG_PROPERTY_VALUE_OUT_OF_RANGE,
EN_ERROR_MODULE_CONFIG_PROPERTIES_NOT_YET_READ,
EN_ERROR_MODULE_CONFIG_PROPERTY_DOES_NOT_HAVE_VALUE_KEY,
EN_ERROR_FAILED_TO_INITIALISE_EEPROM,
EN_ERROR_FAILED_TO_WAKE_ATMEL_ATSHA204A,
EN_ERROR_ATSHA204A_INVALID_ADDRESS_PARAMETER,
EN_ERROR_ATSHA204A_INVALID_RESPONSE_CRC,
EN_ERROR_ATSHA204A_INVALID_RESPONSE_SIZE,
EN_ERROR_ATSHA204A_EXECUTION_ERROR,
EN_ERROR_ATSHA204A_FIRST_COMMAND_AFTER_WAKE,
EN_ERROR_ATSHA204A_INVALID_MAC,
EN_ERROR_ATSHA204A_IO_ERROR,
EN_ERROR_ATSHA204A_PARSE_ERROR,
EN_ERROR_ATSHA204A_UNKNOWN_ERROR,
EN_ERROR_ATSHA204A_FUNCTIONALITY_NOT_YET_IMPLEMENTED,
EN_ERROR_ATSHA204A_WRITE_VERIFICATION_ERROR,
EN_ERROR_ATSHA204A_INVALID_DATA_SLOT_INDEX,
EN_ERROR_RTC_DEVICE_NOT_DETECTED,
EN_ERROR_RTC_FEATURE_NOT_SUPPORTED,
EN_ERROR_RTC_NOT_WORKING,
EN_ERROR_IOTEST_FAILED,
EN_ERROR_SUPPLY_OUT_OF_RANGE
} EN_RESULT;
/** \endcond */
//-------------------------------------------------------------------------------------------------
// Macros
//-------------------------------------------------------------------------------------------------
/**
* \brief Returns a boolean true if the argument status code \a status represents an error.
*/
#define EN_FAILED(status) (((EN_RESULT)(status)) != EN_SUCCESS)
/**
* \brief Returns a boolean true if the argument status code \a status represents a success.
*/
#define EN_SUCCEEDED(status) (((EN_RESULT)(status)) == EN_SUCCESS)
#define EN_PRINT_ERROR(status, message) \
do \
{ \
xil_printf("Error, status code 0x%x: %s\r\n", status, message); \ \
} while (0)
/**
* \brief Tests the status code \a status and returns if it's a failure code.
*
* Used to neaten code and avoid large if-else trees.
*/
#define EN_RETURN_IF_FAILED(status) \
do \
{ \
EN_RESULT _status = status; \
if (EN_FAILED(_status)) \
{ \
return _status; \
} \
} while (0)
/**
* \brief Tests the status code \a status and returns if it's a failure code.
*
* Used to neaten code and avoid large if-else trees.
*/
#define EN_RETURN_IF_FAILED_PRINT(status, message) \
do \
\
{ \
EN_RESULT _status = status; \
if (EN_FAILED(_status)) \
{ \
xil_printf("Error: %s (status code = 0x%x)\r\n", message, status); \
return _status; \
} \
} while (0)
#define RETURN_IF_XILINX_CALL_FAILED(x, returnCode) \
do \
{ \
int _status = x; \
if (_status != XST_SUCCESS) \
{ \
return returnCode; \
} \
} while (0)