Skip to content

Commit bcb1552

Browse files
committed
Merge remote-tracking branch develop into tmp-clang-test
2 parents b939e0e + e85c3e5 commit bcb1552

File tree

21 files changed

+2080
-145
lines changed

21 files changed

+2080
-145
lines changed

src/rp2_common/hardware_clocks/clocks.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ bool clock_configure(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32
102102
return false;
103103

104104
uint32_t div = (uint32_t)((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / freq);
105+
// only clock divider of 1, or >= 2 are supported
106+
if (div < (2u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB)) {
107+
div = (1u << CLOCKS_CLK_GPOUT0_DIV_INT_LSB);
108+
}
105109
uint32_t actual_freq = (uint32_t) ((((uint64_t) src_freq) << CLOCKS_CLK_GPOUT0_DIV_INT_LSB) / div);
106110

107111
clock_configure_internal(clock, src, auxsrc, actual_freq, div);

src/rp2_common/hardware_clocks/include/hardware/clocks.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,11 +262,18 @@ extern "C" {
262262

263263
typedef clock_num_t clock_handle_t;
264264

265-
/*! \brief Configure the specified clock
265+
/*! \brief Configure the specified clock with automatic clock divisor setup
266266
* \ingroup hardware_clocks
267267
*
268+
* This method allows both the src_frequency of the input clock source AND the desired
269+
* frequency to be specified, and will set the clock divider to achieve the exact or higher frequency
270+
* achievable, with the maximum being the src_freq.
271+
*
272+
* Note: That the clock hardware only support divisors of exactly 1 or 2.0->65535.0
273+
*
268274
* See the tables in the description for details on the possible values for clock sources.
269275
*
276+
*
270277
* \param clock The clock to configure
271278
* \param src The main clock source, can be 0.
272279
* \param auxsrc The auxiliary clock source, which depends on which clock is being set. Can be 0
@@ -275,7 +282,7 @@ typedef clock_num_t clock_handle_t;
275282
*/
276283
bool clock_configure(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32_t src_freq, uint32_t freq);
277284

278-
/*! \brief Configure the specified clock to use the undividded input source
285+
/*! \brief Configure the specified clock to use the undivided input source
279286
* \ingroup hardware_clocks
280287
*
281288
* See the tables in the description for details on the possible values for clock sources.
@@ -287,7 +294,7 @@ bool clock_configure(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32
287294
*/
288295
void clock_configure_undivided(clock_handle_t clock, uint32_t src, uint32_t auxsrc, uint32_t src_freq);
289296

290-
/*! \brief Configure the specified clock to use the undividded input source
297+
/*! \brief Configure the specified clock to use the undivided input source
291298
* \ingroup hardware_clocks
292299
*
293300
* See the tables in the description for details on the possible values for clock sources.

src/rp2_common/hardware_dma/include/hardware/dma.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ static inline void dma_channel_start(uint channel) {
535535
*\endcode
536536
*
537537
* \if rp2350_specific
538-
* RP2350 only: Due to errata RP12350-E5 (see the RP2350 datasheet for further detail), it is necessary to clear the enable bit of
538+
* RP2350 only: Due to errata RP2350-E5 (see the RP2350 datasheet for further detail), it is necessary to clear the enable bit of
539539
* the aborted channel and any chained channels prior to the abort to prevent re-triggering.
540540
* \endif
541541
*

src/rp2_common/hardware_flash/flash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ void flash_get_unique_id(uint8_t *id_out) {
288288
#if !PICO_RP2040
289289
// This is a static symbol because the layout of FLASH_DEVINFO is liable to change from device to
290290
// device, so fields must have getters/setters.
291-
static io_rw_16 * flash_devinfo_ptr(void) {
291+
static io_rw_16 * __no_inline_not_in_flash_func(flash_devinfo_ptr)(void) {
292292
// Note the lookup returns a pointer to a 32-bit pointer literal in the ROM
293293
io_rw_16 **p = (io_rw_16 **) rom_data_lookup_inline(ROM_DATA_FLASH_DEVINFO16_PTR);
294294
assert(p);

src/rp2_common/hardware_irq/include/hardware/irq.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,33 @@ void irq_set_mask_n_enabled(uint n, uint32_t mask, bool enabled);
286286
* This method will assert if there is already any sort of interrupt handler installed
287287
* for the specified irq number.
288288
*
289+
* NOTE: By default, the SDK uses a single shared vector table per core, and the current installed
290+
* IRQ handlers are effectively a linked list starting a vector table entry for a particular IRQ number.
291+
* Therefore, this method (when using the same vector table for both cores) sets the same interrupt handler
292+
* for both cores.
293+
*
294+
* On RP2040 this was never really a cause of any confusion, because it rarely made sense to enable
295+
* the same interrupt number in the NVIC on both cores (see \ref irq_set_enabled()), because the interrupt
296+
* would then fire on both cores, and the interrupt handlers would race.
297+
*
298+
* The problem *does* exist however when dealing with interrupts which are independent on the two cores.
299+
*
300+
* This includes:
301+
*
302+
* * the core local "spare" IRQs
303+
* * on RP2350 the SIO FIFO IRQ which is now the same irq number for both cores (vs RP2040 where it was two)
304+
*
305+
* In the cases where you want to enable the same IRQ on both cores, and both cores are sharing the same vector
306+
* table, you should install the IRQ handler once - it will be used on both cores - and check the core
307+
* number (via \ref get_core_num()) on each core.
308+
*
309+
* NOTE: It is not thread safe to add/remove/handle IRQs for the same irq number in the same vector table
310+
* from both cores concurrently.
311+
*
312+
* NOTE: The SDK defines a PICO_VTABLE_PER_CORE variable indicating whether the two vector tables are separate,
313+
* however as of version 2.1.1 the user cannot set this value, and expect the vector table duplication to be handled
314+
* for them. This functionality will be added in a future SDK version
315+
*
289316
* \param num Interrupt number \ref interrupt_nums
290317
* \param handler The handler to set. See \ref irq_handler_t
291318
* \see irq_add_shared_handler()
@@ -316,6 +343,33 @@ irq_handler_t irq_get_exclusive_handler(uint num);
316343
* the (total across all IRQs on both cores) maximum (configurable via PICO_MAX_SHARED_IRQ_HANDLERS) number of shared handlers
317344
* would be exceeded.
318345
*
346+
* NOTE: By default, the SDK uses a single shared vector table per core, and the current installed
347+
* IRQ handlers are effectively a linked list starting a vector table entry for a particular IRQ number.
348+
* Therefore, this method (when using the same vector table for both cores) add the same interrupt handler
349+
* for both cores.
350+
*
351+
* On RP2040 this was never really a cause of any confusion, because it rarely made sense to enable
352+
* the same interrupt number in the NVIC on both cores (see \ref irq_set_enabled()), because the interrupt
353+
* would then fire on both cores, and the interrupt handlers would race.
354+
*
355+
* The problem *does* exist however when dealing with interrupts which are independent on the two cores.
356+
*
357+
* This includes:
358+
*
359+
* * the core local "spare" IRQs
360+
* * on RP2350 the SIO FIFO IRQ which is now the same irq number for both cores (vs RP2040 where it was two)
361+
*
362+
* In the cases where you want to enable the same IRQ on both cores, and both cores are sharing the same vector
363+
* table, you should install the IRQ handler once - it will be used on both cores - and check the core
364+
* number (via \ref get_core_num()) on each core.
365+
*
366+
* NOTE: It is not thread safe to add/remove/handle IRQs for the same irq number in the same vector table
367+
* from both cores concurrently.
368+
*
369+
* NOTE: The SDK defines a PICO_VTABLE_PER_CORE variable indicating whether the two vector tables are separate,
370+
* however as of version 2.1.1 the user cannot set this value, and expect the vector table duplication to be handled
371+
* for them. This functionality will be added in a future SDK version
372+
*
319373
* \param num Interrupt number \ref interrupt_nums
320374
* \param handler The handler to set. See \ref irq_handler_t
321375
* \param order_priority The order priority controls the order that handlers for the same IRQ number on the core are called.

src/rp2_common/pico_double/double_aeabi_dcp.S

Lines changed: 94 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "pico/asm_helper.S"
88

99
#if !HAS_DOUBLE_COPROCESSOR
10-
#error attempt to compile double_aeabi_rp2350 when there is no DCP
10+
#error attempt to compile double_aeabi_dcp when there is no DCP
1111
#else
1212

1313
#include "hardware/dcp_instr.inc.S"
@@ -29,7 +29,7 @@ double_section WRAPPER_FUNC_NAME(\func)
2929

3030
// ============== STATE SAVE AND RESTORE ===============
3131

32-
.macro saving_func type func
32+
.macro saving_func type func, opt_label1='-', opt_label2='-'
3333
// Note we are usually 32-bit aligned already at this point, as most of the
3434
// function bodies contain exactly two 16-bit instructions: bmi and bx lr.
3535
// We want the PCMP word-aligned.
@@ -41,6 +41,12 @@ double_section WRAPPER_FUNC_NAME(\func)
4141
push {lr} // 16-bit instruction
4242
bl generic_save_state // 32-bit instruction
4343
b 1f // 16-bit instruction
44+
.ifnc \opt_label1,'-'
45+
regular_func \opt_label1
46+
.endif
47+
.ifnc \opt_label2,'-'
48+
regular_func \opt_label2
49+
.endif
4450
// This is the actual entry point:
4551
\type\()_func \func
4652
PCMP apsr_nzcv
@@ -128,53 +134,124 @@ saving_func wrapper sqrt
128134
dcp_dsqrt_m r0,r1,r0,r1,r0,r1,r2,r3,r12
129135
saving_func_return
130136

131-
// todo not a real thing
132-
double_wrapper_section __aeabi_dclassify
133-
saving_func wrapper __aeabi_dclassify
134-
@ with correct rounding
137+
double_section dclassify
138+
saving_func regular dclassify
135139
dcp_dclassify_m apsr_nzcv,r0,r1
136140
saving_func_return
137141

138142
// ============== CONVERSION FUNCTIONS ===============
139143

140144
double_wrapper_section __aeabi_d2f
141-
saving_func wrapper __aeabi_d2f
145+
saving_func wrapper __aeabi_d2f double2float
142146
@ with rounding
143147
dcp_double2float_m r0,r0,r1
144148
saving_func_return
145149

146150
double_wrapper_section __aeabi_i2d
147-
saving_func wrapper __aeabi_i2d
151+
saving_func wrapper __aeabi_i2d int2double
148152
dcp_int2double_m r0,r1,r0
149153
saving_func_return
150154

151155
double_wrapper_section __aeabi_ui2d
152-
saving_func wrapper __aeabi_ui2d
156+
saving_func wrapper __aeabi_ui2d uint2double
153157
dcp_uint2double_m r0,r1,r0
154158
saving_func_return
155159

160+
double_section double2fix_z
161+
saving_func regular double2fix_z
162+
ubfx r3, r1, #20, #11
163+
adds r3, r2
164+
beq 1f // very small; we don't care that we might make a denormal
165+
asrs ip, r3, #11
166+
beq 1f
167+
ite pl
168+
movpl r3, #0x7ff
169+
movsmi r3, #0
170+
1:
171+
bfi r1, r3, #20, #11
172+
b double2int_z_entry
173+
174+
double_section double2ufix
175+
saving_func regular double2ufix_z double2ufix
176+
double2ufix_z_entry:
177+
ubfx r3, r1, #20, #11
178+
adds r3, r2
179+
beq 1f // very small; we don't care that we might make a denormal
180+
asrs ip, r3, #11
181+
beq 1f
182+
ite pl
183+
lsrspl r3, r1, #20 // 0x7ff
184+
movsmi r3, #0
185+
1:
186+
bfi r1, r3, #20, #11
187+
b double2uint_z_entry
188+
189+
double_section double2fix
190+
saving_func regular double2fix
191+
ubfx r3, r1, #20, #11
192+
cbz r3, 2f // 0 or denormal
193+
adds r3, r2
194+
beq 1f // very small; we don't care that we might make a denormal
195+
asrs ip, r3, #11
196+
beq 1f
197+
ite pl
198+
movpl r3, #0x7ff
199+
movsmi r3, #0
200+
1:
201+
bfi r1, r3, #20, #11
202+
b double2int_entry
203+
2:
204+
movs r0, #0
205+
saving_func_return
206+
207+
208+
double_section double2int
209+
saving_func regular double2int
210+
double2int_entry:
211+
lsls r2, r1, #1
212+
bcc double2int_z_entry // positive is ok for int64_z
213+
lsrs r3, r2, #21
214+
beq double2int_z_entry // 0 or -0 or denormal is ok for int_z
215+
216+
lsrs r2, #21
217+
adds r2, #1
218+
subs r2, r2, #0x400
219+
bcc 1f // <1 means subtract 1
220+
cmp r2, #31
221+
bge double2int_z_entry // must be an integer or maxed out
222+
lsls r3, r1, #12
223+
adds r3, r3, r0, lsr #20 // r3 now has highest 32 mantissa bits
224+
lsls r3, r2
225+
orrs r3, r3, r0, lsl #12 // these bits are all guaranteed to be in the fraction
226+
beq double2int_z_entry // integer
227+
1:
228+
dcp_double2int_m r0,r0,r1
229+
subs r0, #1
230+
saving_func_return
231+
156232
double_wrapper_section __aeabi_d2iz
157-
saving_func wrapper __aeabi_d2iz
233+
saving_func wrapper __aeabi_d2iz double2int_z
234+
double2int_z_entry:
158235
@ with truncation towards 0
159236
dcp_double2int_m r0,r0,r1
237+
// note: this works with either saved or not saved call as it is just a `bx lr`
160238
saving_func_return
161239

162240
double_wrapper_section __aeabi_d2uiz
163-
saving_func wrapper __aeabi_d2uiz
241+
saving_func wrapper __aeabi_d2uiz double2uint double2uint_z
242+
double2uint_z_entry:
164243
@ with truncation towards 0
165244
dcp_double2uint_m r0,r0,r1
166245
saving_func_return
167246

168-
// todo not a real thing
169-
double_wrapper_section __aeabi_d2i_r
170-
saving_func wrapper __aeabi_d2i_r
247+
double_section double2int_r
248+
saving_func regular double2int_r
171249
@ with rounding
172250
dcp_double2int_r_m r0,r0,r1
173251
saving_func_return
174252

175-
// todo not a real thing
176-
double_wrapper_section __aeabi_d2ui_r
177-
saving_func wrapper __aeabi_d2ui_r
253+
double_section double2uint_r
254+
saving_func regular double2uint_r
178255
@ with rounding
179256
dcp_double2uint_r_m r0,r0,r1
180257
saving_func_return
@@ -189,7 +266,6 @@ saving_func wrapper __aeabi_dcmpun
189266
saving_func_return
190267

191268
double_wrapper_section __aeabi_dcmp
192-
193269
saving_func wrapper __aeabi_cdrcmple
194270
dcp_dcmp_m apsr_nzcv,r2,r3,r0,r1 // with arguments reversed
195271
bvs cmp_nan

0 commit comments

Comments
 (0)