@@ -43,35 +43,33 @@ 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 };
71
- __attribute__((weak ))
72
- const target_family_descriptor_t g_ambiq_ama3b1kk = {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
+ extern __WEAK const target_family_descriptor_t g_ambiq_ama3b1kk ;
73
60
61
+ //! @brief Terminator value for g_families list.
62
+ //!
63
+ //! This terminator value is chosen so that weak references to the family descriptors that
64
+ //! resolve to NULL at link time do not terminate the list early.
65
+ #define FAMILY_LIST_TERMINATOR ((const target_family_descriptor_t *)(0xffffffff))
74
66
67
+ //! @brief Default list of family descriptors.
68
+ //!
69
+ //! init_family() scans this list searching for a family descriptor with an ID that matches
70
+ //! the family ID set in the board info or target config structs. Because each of the family
71
+ //! descriptors has a weak reference defined above, the entry in this list for a family whose
72
+ //! descriptor is not included in the link will resolve to NULL and init_family() can skip it.
75
73
__attribute__((weak ))
76
74
const target_family_descriptor_t * g_families [] = {
77
75
& g_hw_reset_family ,
@@ -90,7 +88,7 @@ const target_family_descriptor_t *g_families[] = {
90
88
& g_renesas_family ,
91
89
& g_toshiba_tz_family ,
92
90
& g_ambiq_ama3b1kk ,
93
- 0 // list terminator
91
+ FAMILY_LIST_TERMINATOR // list terminator
94
92
};
95
93
96
94
__attribute__((weak ))
@@ -99,21 +97,25 @@ const target_family_descriptor_t *g_target_family = NULL;
99
97
100
98
void init_family (void )
101
99
{
102
- uint8_t index = 0 ;
103
- uint16_t family_id = get_family_id ();
104
- if (g_target_family != NULL ){ //already set
100
+ // Check if the family is already set.
101
+ if (g_target_family != NULL ) {
105
102
return ;
106
103
}
107
104
108
- while (g_families [index ]!= 0 ) {
109
- if (g_families [index ]-> family_id && (g_families [index ]-> family_id == family_id )) {
105
+ // Scan families table looking for matching family ID.
106
+ uint8_t index = 0 ;
107
+ uint16_t family_id = get_family_id ();
108
+
109
+ while (g_families [index ] != FAMILY_LIST_TERMINATOR ) {
110
+ if ((g_families [index ] != NULL ) && (g_families [index ]-> family_id == family_id )) {
110
111
g_target_family = g_families [index ];
111
112
break ;
112
113
}
113
114
index ++ ;
114
115
}
115
116
116
- if (g_target_family == NULL ){ //default family
117
+ // Last resort is to use a default family.
118
+ if (g_target_family == NULL ) {
117
119
g_target_family = & g_hw_reset_family ;
118
120
}
119
121
}
@@ -137,11 +139,11 @@ uint8_t target_set_state(target_state_t state)
137
139
swd_set_soft_reset (g_target_family -> soft_reset_type );
138
140
}
139
141
return swd_set_target_state_sw (state );
140
- }else {
142
+ } else {
141
143
return 1 ;
142
144
}
143
145
}
144
- }else {
146
+ } else {
145
147
return 0 ;
146
148
}
147
149
}
@@ -150,7 +152,7 @@ void swd_set_target_reset(uint8_t asserted)
150
152
{
151
153
if (g_target_family && g_target_family -> swd_set_target_reset ) {
152
154
g_target_family -> swd_set_target_reset (asserted );
153
- }else {
155
+ } else {
154
156
(asserted ) ? PIN_nRESET_OUT (0 ) : PIN_nRESET_OUT (1 );
155
157
}
156
158
}
0 commit comments