@@ -43,31 +43,21 @@ 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
+ #define FAMILY_LIST_TERMINATOR ((const target_family_descriptor_t *)(0xffffffff))
71
61
72
62
__attribute__((weak ))
73
63
const target_family_descriptor_t * g_families [] = {
@@ -86,30 +76,34 @@ const target_family_descriptor_t *g_families[] = {
86
76
& g_wiznet_family ,
87
77
& g_renesas_family ,
88
78
& g_toshiba_tz_family ,
89
- 0 // list terminator
90
- };
79
+ FAMILY_LIST_TERMINATOR // list terminator
80
+ };
91
81
92
82
__attribute__((weak ))
93
83
const target_family_descriptor_t * g_target_family = NULL ;
94
84
95
85
96
86
void init_family (void )
97
87
{
98
- uint8_t index = 0 ;
99
- uint16_t family_id = get_family_id ();
100
- if (g_target_family != NULL ){ //already set
88
+ // Check if the family is already set.
89
+ if (g_target_family != NULL ) {
101
90
return ;
102
91
}
103
-
104
- while (g_families [index ]!= 0 ) {
105
- if (g_families [index ]-> family_id && (g_families [index ]-> family_id == family_id )) {
92
+
93
+ // Scan families table looking for matching family ID.
94
+ uint8_t index = 0 ;
95
+ uint16_t family_id = get_family_id ();
96
+
97
+ while (g_families [index ] != FAMILY_LIST_TERMINATOR ) {
98
+ if ((g_families [index ] != NULL ) && (g_families [index ]-> family_id == family_id )) {
106
99
g_target_family = g_families [index ];
107
100
break ;
108
101
}
109
102
index ++ ;
110
103
}
111
-
112
- if (g_target_family == NULL ){ //default family
104
+
105
+ // Last resort is to use a default family.
106
+ if (g_target_family == NULL ) {
113
107
g_target_family = & g_hw_reset_family ;
114
108
}
115
109
}
@@ -138,11 +132,11 @@ uint8_t target_set_state(TARGET_RESET_STATE state)
138
132
swd_set_soft_reset (g_target_family -> soft_reset_type );
139
133
}
140
134
return swd_set_target_state_sw (state );
141
- }else {
135
+ } else {
142
136
return 1 ;
143
137
}
144
138
}
145
- }else {
139
+ } else {
146
140
return 0 ;
147
141
}
148
142
}
@@ -151,7 +145,7 @@ void swd_set_target_reset(uint8_t asserted)
151
145
{
152
146
if (g_target_family && g_target_family -> swd_set_target_reset ) {
153
147
g_target_family -> swd_set_target_reset (asserted );
154
- }else {
148
+ } else {
155
149
(asserted ) ? PIN_nRESET_OUT (0 ) : PIN_nRESET_OUT (1 );
156
150
}
157
151
}
0 commit comments