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