OpenOCD
versaloon_include.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 /***************************************************************************
4  * Copyright (C) 2009 by Simon Qian <SimonQian@SimonQian.com> *
5  ***************************************************************************/
6 
7 #ifndef OPENOCD_JTAG_DRIVERS_VERSALOON_VERSALOON_INCLUDE_H
8 #define OPENOCD_JTAG_DRIVERS_VERSALOON_VERSALOON_INCLUDE_H
9 
10 #include "helper/system.h"
11 /* This file is used to include different header and macros */
12 /* according to different platform */
13 #include <jtag/interface.h>
14 #include <jtag/commands.h>
15 
16 #define PARAM_CHECK 1
17 
18 #define sleep_ms(ms) jtag_sleep((ms) * 1000)
19 #define TO_STR(name) #name
20 
21 #define RESULT int
22 #define LOG_BUG LOG_ERROR
23 
24 /* Common error messages */
25 #define ERRMSG_NOT_ENOUGH_MEMORY "Lack of memory."
26 #define ERRCODE_NOT_ENOUGH_MEMORY ERROR_FAIL
27 
28 #define ERRMSG_INVALID_VALUE "%d is invalid for %s."
29 #define ERRMSG_INVALID_INDEX "Index %d is invalid for %s."
30 #define ERRMSG_INVALID_USAGE "Invalid usage of %s"
31 #define ERRMSG_INVALID_TARGET "Invalid %s"
32 #define ERRMSG_INVALID_PARAMETER "Invalid parameter of %s."
33 #define ERRMSG_INVALID_INTERFACE_NUM "invalid interface %d"
34 #define ERRMSG_INVALID_BUFFER "Buffer %s is not valid."
35 #define ERRCODE_INVALID_BUFFER ERROR_FAIL
36 #define ERRCODE_INVALID_PARAMETER ERROR_FAIL
37 
38 #define ERRMSG_NOT_SUPPORT_BY "%s is not supported by %s."
39 
40 #define ERRMSG_FAILURE_OPERATION "Fail to %s."
41 #define ERRMSG_FAILURE_OPERATION_MESSAGE "Fail to %s, %s"
42 #define ERRCODE_FAILURE_OPERATION ERROR_FAIL
43 
44 #define GET_U16_MSBFIRST(p) (((*((uint8_t *)(p) + 0)) << 8) | \
45  ((*((uint8_t *)(p) + 1)) << 0))
46 #define GET_U32_MSBFIRST(p) (((*((uint8_t *)(p) + 0)) << 24) | \
47  ((*((uint8_t *)(p) + 1)) << 16) | \
48  ((*((uint8_t *)(p) + 2)) << 8) | \
49  ((*((uint8_t *)(p) + 3)) << 0))
50 #define GET_U16_LSBFIRST(p) (((*((uint8_t *)(p) + 0)) << 0) | \
51  ((*((uint8_t *)(p) + 1)) << 8))
52 #define GET_U32_LSBFIRST(p) (((*((uint8_t *)(p) + 0)) << 0) | \
53  ((*((uint8_t *)(p) + 1)) << 8) | \
54  ((*((uint8_t *)(p) + 2)) << 16) | \
55  ((*((uint8_t *)(p) + 3)) << 24))
56 
57 #define SET_U16_MSBFIRST(p, v) \
58  do {\
59  *((uint8_t *)(p) + 0) = (((uint16_t)(v)) >> 8) & 0xFF;\
60  *((uint8_t *)(p) + 1) = (((uint16_t)(v)) >> 0) & 0xFF;\
61  } while (0)
62 #define SET_U32_MSBFIRST(p, v) \
63  do {\
64  *((uint8_t *)(p) + 0) = (((uint32_t)(v)) >> 24) & 0xFF;\
65  *((uint8_t *)(p) + 1) = (((uint32_t)(v)) >> 16) & 0xFF;\
66  *((uint8_t *)(p) + 2) = (((uint32_t)(v)) >> 8) & 0xFF;\
67  *((uint8_t *)(p) + 3) = (((uint32_t)(v)) >> 0) & 0xFF;\
68  } while (0)
69 #define SET_U16_LSBFIRST(p, v) \
70  do {\
71  *((uint8_t *)(p) + 0) = (((uint16_t)(v)) >> 0) & 0xFF;\
72  *((uint8_t *)(p) + 1) = (((uint16_t)(v)) >> 8) & 0xFF;\
73  } while (0)
74 #define SET_U32_LSBFIRST(p, v) \
75  do {\
76  *((uint8_t *)(p) + 0) = (((uint32_t)(v)) >> 0) & 0xFF;\
77  *((uint8_t *)(p) + 1) = (((uint32_t)(v)) >> 8) & 0xFF;\
78  *((uint8_t *)(p) + 2) = (((uint32_t)(v)) >> 16) & 0xFF;\
79  *((uint8_t *)(p) + 3) = (((uint32_t)(v)) >> 24) & 0xFF;\
80  } while (0)
81 
82 #define GET_LE_U16(p) GET_U16_LSBFIRST(p)
83 #define GET_LE_U32(p) GET_U32_LSBFIRST(p)
84 #define GET_BE_U16(p) GET_U16_MSBFIRST(p)
85 #define GET_BE_U32(p) GET_U32_MSBFIRST(p)
86 #define SET_LE_U16(p, v) SET_U16_LSBFIRST(p, v)
87 #define SET_LE_U32(p, v) SET_U32_LSBFIRST(p, v)
88 #define SET_BE_U16(p, v) SET_U16_MSBFIRST(p, v)
89 #define SET_BE_U32(p, v) SET_U32_MSBFIRST(p, v)
90 
91 #endif /* OPENOCD_JTAG_DRIVERS_VERSALOON_VERSALOON_INCLUDE_H */