|
20 | 20 |
|
21 | 21 | #include "cmsis_compiler.h"
|
22 | 22 | #include "info.h"
|
| 23 | +#include "util.h" |
| 24 | +#include "target_board.h" |
| 25 | + |
| 26 | +#if !defined(CMSIS_DAP_PRODUCT_NAME) |
| 27 | +#define CMSIS_DAP_PRODUCT_NAME "DAPLink" |
| 28 | +#endif |
| 29 | + |
| 30 | +//! Maximum output buffer length of all these functions. |
| 31 | +#define MAX_DAP_STR_LEN (60) |
| 32 | + |
| 33 | +//! @brief Utility to copy string to output buffer and return length. |
| 34 | +//! |
| 35 | +//! The source string is limited to the maximum output buffer size defined |
| 36 | +//! by the MAX_DAP_STR_LEN macro. |
| 37 | +static uint8_t return_dap_string(char *dst, const char *src) |
| 38 | +{ |
| 39 | + int length = MIN(MAX_DAP_STR_LEN, strlen(src) + 1); |
| 40 | + memcpy(dst, src, length); |
| 41 | + dst[MAX_DAP_STR_LEN - 1] = 0; // Ensure there's a terminating NULL. |
| 42 | + return length; |
| 43 | +} |
23 | 44 |
|
24 | 45 | /** Get Vendor Name string.
|
25 | 46 | \param str Pointer to buffer to store the string (max 60 characters).
|
26 | 47 | \return String length (including terminating NULL character) or 0 (no string).
|
27 | 48 | */
|
28 | 49 | __STATIC_INLINE uint8_t DAP_GetVendorString (char *str) {
|
29 |
| - (void)str; |
30 |
| - return (0U); |
| 50 | +#if defined(CMSIS_DAP_VENDOR_NAME) |
| 51 | + return return_dap_string(str, CMSIS_DAP_VENDOR_NAME); |
| 52 | +#else |
| 53 | + (void)str; |
| 54 | + return (0U); |
| 55 | +#endif |
31 | 56 | }
|
32 | 57 |
|
33 | 58 | /** Get Product Name string.
|
34 | 59 | \param str Pointer to buffer to store the string (max 60 characters).
|
35 | 60 | \return String length (including terminating NULL character) or 0 (no string).
|
36 | 61 | */
|
37 | 62 | __STATIC_INLINE uint8_t DAP_GetProductString (char *str) {
|
38 |
| - (void)str; |
39 |
| - return (0U); |
| 63 | + return return_dap_string(str, CMSIS_DAP_PRODUCT_NAME); |
40 | 64 | }
|
41 | 65 |
|
42 | 66 | /** Get Serial Number string.
|
43 | 67 | \param str Pointer to buffer to store the string (max 60 characters).
|
44 | 68 | \return String length (including terminating NULL character) or 0 (no string).
|
45 | 69 | */
|
46 | 70 | __STATIC_INLINE uint8_t DAP_GetSerNumString (char *str) {
|
47 |
| - const char * data = info_get_unique_id(); |
48 |
| - uint8_t length = (uint8_t)strlen(data) + 1; |
49 |
| - memcpy(str, data, length); |
50 |
| - return length; |
| 71 | + return return_dap_string(str, info_get_unique_id()); |
51 | 72 | }
|
52 | 73 |
|
53 | 74 | /** Get Target Device Vendor string.
|
54 | 75 | \param str Pointer to buffer to store the string (max 60 characters).
|
55 | 76 | \return String length (including terminating NULL character) or 0 (no string).
|
56 | 77 | */
|
57 | 78 | __STATIC_INLINE uint8_t DAP_GetTargetDeviceVendorString (char *str) {
|
58 |
| -#if TARGET_FIXED != 0 |
59 |
| - uint8_t len; |
60 |
| - |
61 |
| - strcpy(str, TargetDeviceVendor); |
62 |
| - len = (uint8_t)(strlen(TargetDeviceVendor) + 1U); |
63 |
| - return (len); |
64 |
| -#else |
65 |
| - (void)str; |
66 |
| - return (0U); |
67 |
| -#endif |
| 79 | + if (g_board_info.target_cfg && g_board_info.target_cfg->target_vendor) { |
| 80 | + return return_dap_string(str, g_board_info.target_cfg->target_vendor); |
| 81 | + } |
| 82 | + else { |
| 83 | + return (0U); |
| 84 | + } |
68 | 85 | }
|
69 | 86 |
|
70 | 87 | /** Get Target Device Name string.
|
71 | 88 | \param str Pointer to buffer to store the string (max 60 characters).
|
72 | 89 | \return String length (including terminating NULL character) or 0 (no string).
|
73 | 90 | */
|
74 | 91 | __STATIC_INLINE uint8_t DAP_GetTargetDeviceNameString (char *str) {
|
75 |
| -#if TARGET_FIXED != 0 |
76 |
| - uint8_t len; |
77 |
| - |
78 |
| - strcpy(str, TargetDeviceName); |
79 |
| - len = (uint8_t)(strlen(TargetDeviceName) + 1U); |
80 |
| - return (len); |
81 |
| -#else |
82 |
| - (void)str; |
83 |
| - return (0U); |
84 |
| -#endif |
| 92 | + if (g_board_info.target_cfg && g_board_info.target_cfg->target_part_number) { |
| 93 | + return return_dap_string(str, g_board_info.target_cfg->target_part_number); |
| 94 | + } |
| 95 | + else { |
| 96 | + return (0U); |
| 97 | + } |
85 | 98 | }
|
86 | 99 |
|
87 | 100 | /** Get Target Board Vendor string.
|
88 | 101 | \param str Pointer to buffer to store the string (max 60 characters).
|
89 | 102 | \return String length (including terminating NULL character) or 0 (no string).
|
90 | 103 | */
|
91 | 104 | __STATIC_INLINE uint8_t DAP_GetTargetBoardVendorString (char *str) {
|
92 |
| -#if TARGET_FIXED != 0 |
93 |
| - uint8_t len; |
94 |
| - |
95 |
| - strcpy(str, TargetBoardVendor); |
96 |
| - len = (uint8_t)(strlen(TargetBoardVendor) + 1U); |
97 |
| - return (len); |
98 |
| -#else |
99 |
| - (void)str; |
100 |
| - return (0U); |
101 |
| -#endif |
| 105 | + if (g_board_info.board_vendor) { |
| 106 | + return return_dap_string(str, g_board_info.board_vendor); |
| 107 | + } |
| 108 | + else { |
| 109 | + return (0U); |
| 110 | + } |
102 | 111 | }
|
103 | 112 |
|
104 | 113 | /** Get Target Board Name string.
|
105 | 114 | \param str Pointer to buffer to store the string (max 60 characters).
|
106 | 115 | \return String length (including terminating NULL character) or 0 (no string).
|
107 | 116 | */
|
108 | 117 | __STATIC_INLINE uint8_t DAP_GetTargetBoardNameString (char *str) {
|
109 |
| -#if TARGET_FIXED != 0 |
110 |
| - uint8_t len; |
111 |
| - |
112 |
| - strcpy(str, TargetBoardName); |
113 |
| - len = (uint8_t)(strlen(TargetBoardName) + 1U); |
114 |
| - return (len); |
115 |
| -#else |
116 |
| - (void)str; |
117 |
| - return (0U); |
118 |
| -#endif |
| 118 | + if (g_board_info.board_name) { |
| 119 | + return return_dap_string(str, g_board_info.board_name); |
| 120 | + } |
| 121 | + else { |
| 122 | + return (0U); |
| 123 | + } |
119 | 124 | }
|
120 | 125 |
|
121 | 126 | /** Get Product Firmware Version string.
|
122 | 127 | \param str Pointer to buffer to store the string (max 60 characters).
|
123 | 128 | \return String length (including terminating NULL character) or 0 (no string).
|
124 | 129 | */
|
125 | 130 | __STATIC_INLINE uint8_t DAP_GetProductFirmwareVersionString (char *str) {
|
126 |
| - const char * data = info_get_version(); |
127 |
| - uint8_t length = (uint8_t)strlen(data) + 1; |
128 |
| - memcpy(str, data, length); |
129 |
| - return length; |
| 131 | + return return_dap_string(str, info_get_version()); |
130 | 132 | }
|
0 commit comments