@@ -43,32 +43,32 @@ const target_family_descriptor_t g_sw_sysresetreq_family = {
43
43
.soft_reset_type = SYSRESETREQ ,
44
44
};
45
45
46
- //Weakly define family
47
- __attribute__((weak ))
48
- const target_family_descriptor_t g_nxp_kinetis_kseries = {0 };
49
- __attribute__((weak ))
50
- const target_family_descriptor_t g_nxp_kinetis_lseries = {0 };
51
- __attribute__((weak ))
52
- const target_family_descriptor_t g_nxp_kinetis_k32w_series = {0 };
53
- __attribute__((weak ))
54
- const target_family_descriptor_t g_nxp_mimxrt = {0 };
55
- __attribute__((weak ))
56
- const target_family_descriptor_t g_nxp_rapid_iot = {0 };
57
- __attribute__((weak ))
58
- const target_family_descriptor_t g_nordic_nrf51 = {0 };
59
- __attribute__((weak ))
60
- const target_family_descriptor_t g_nordic_nrf52 = {0 };
61
- __attribute__((weak ))
62
- const target_family_descriptor_t g_realtek_rtl8195am = {0 };
63
- __attribute__((weak ))
64
- const target_family_descriptor_t g_ti_family = {0 };
65
- __attribute__((weak ))
66
- const target_family_descriptor_t g_wiznet_family = {0 };
67
- __attribute__((weak ))
68
- const target_family_descriptor_t g_renesas_family = {0 };
69
- __attribute__((weak ))
70
- const target_family_descriptor_t g_toshiba_tz_family = {0 };
46
+ // Weak references to family definitions.
47
+ extern __WEAK const target_family_descriptor_t g_nxp_kinetis_kseries ;
48
+ extern __WEAK const target_family_descriptor_t g_nxp_kinetis_lseries ;
49
+ extern __WEAK const target_family_descriptor_t g_nxp_kinetis_k32w_series ;
50
+ extern __WEAK const target_family_descriptor_t g_nxp_mimxrt ;
51
+ extern __WEAK const target_family_descriptor_t g_nxp_rapid_iot ;
52
+ extern __WEAK const target_family_descriptor_t g_nordic_nrf51 ;
53
+ extern __WEAK const target_family_descriptor_t g_nordic_nrf52 ;
54
+ extern __WEAK const target_family_descriptor_t g_realtek_rtl8195am ;
55
+ extern __WEAK const target_family_descriptor_t g_ti_family ;
56
+ extern __WEAK const target_family_descriptor_t g_wiznet_family ;
57
+ extern __WEAK const target_family_descriptor_t g_renesas_family ;
58
+ extern __WEAK const target_family_descriptor_t g_toshiba_tz_family ;
59
+
60
+ //! @brief Terminator value for g_families list.
61
+ //!
62
+ //! This terminator value is chosen so that weak references to the family descriptors that
63
+ //! resolve to NULL at link time do not terminate the list early.
64
+ #define FAMILY_LIST_TERMINATOR ((const target_family_descriptor_t *)(0xffffffff))
71
65
66
+ //! @brief Default list of family descriptors.
67
+ //!
68
+ //! init_family() scans this list searching for a family descriptor with an ID that matches
69
+ //! the family ID set in the board info or target config structs. Because each of the family
70
+ //! descriptors has a weak reference defined above, the entry in this list for a family whose
71
+ //! descriptor is not included in the link will resolve to NULL and init_family() can skip it.
72
72
__attribute__((weak ))
73
73
const target_family_descriptor_t * g_families [] = {
74
74
& g_hw_reset_family ,
@@ -86,7 +86,7 @@ const target_family_descriptor_t *g_families[] = {
86
86
& g_wiznet_family ,
87
87
& g_renesas_family ,
88
88
& g_toshiba_tz_family ,
89
- 0 // list terminator
89
+ FAMILY_LIST_TERMINATOR // list terminator
90
90
};
91
91
92
92
__attribute__((weak ))
@@ -95,21 +95,25 @@ const target_family_descriptor_t *g_target_family = NULL;
95
95
96
96
void init_family (void )
97
97
{
98
- uint8_t index = 0 ;
99
- uint16_t family_id = get_family_id ();
100
- if (g_target_family != NULL ){ //already set
98
+ // Check if the family is already set.
99
+ if (g_target_family != NULL ) {
101
100
return ;
102
101
}
103
102
104
- while (g_families [index ]!= 0 ) {
105
- if (g_families [index ]-> family_id && (g_families [index ]-> family_id == family_id )) {
103
+ // Scan families table looking for matching family ID.
104
+ uint8_t index = 0 ;
105
+ uint16_t family_id = get_family_id ();
106
+
107
+ while (g_families [index ] != FAMILY_LIST_TERMINATOR ) {
108
+ if ((g_families [index ] != NULL ) && (g_families [index ]-> family_id == family_id )) {
106
109
g_target_family = g_families [index ];
107
110
break ;
108
111
}
109
112
index ++ ;
110
113
}
111
114
112
- if (g_target_family == NULL ){ //default family
115
+ // Last resort is to use a default family.
116
+ if (g_target_family == NULL ) {
113
117
g_target_family = & g_hw_reset_family ;
114
118
}
115
119
}
@@ -133,11 +137,11 @@ uint8_t target_set_state(target_state_t state)
133
137
swd_set_soft_reset (g_target_family -> soft_reset_type );
134
138
}
135
139
return swd_set_target_state_sw (state );
136
- }else {
140
+ } else {
137
141
return 1 ;
138
142
}
139
143
}
140
- }else {
144
+ } else {
141
145
return 0 ;
142
146
}
143
147
}
@@ -146,7 +150,7 @@ void swd_set_target_reset(uint8_t asserted)
146
150
{
147
151
if (g_target_family && g_target_family -> swd_set_target_reset ) {
148
152
g_target_family -> swd_set_target_reset (asserted );
149
- }else {
153
+ } else {
150
154
(asserted ) ? PIN_nRESET_OUT (0 ) : PIN_nRESET_OUT (1 );
151
155
}
152
156
}
0 commit comments