2021-01-20 16:44:27 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2021-04-07 01:50:26 +00:00
|
|
|
// Include all headers to check for compiler warnings
|
|
|
|
#include "hardware/adc.h"
|
|
|
|
#include "hardware/claim.h"
|
|
|
|
#include "hardware/clocks.h"
|
|
|
|
#include "hardware/divider.h"
|
2021-01-20 16:44:27 +00:00
|
|
|
#include "hardware/dma.h"
|
2021-05-05 16:45:39 +00:00
|
|
|
#include "hardware/exception.h"
|
2021-04-07 01:50:26 +00:00
|
|
|
#include "hardware/flash.h"
|
|
|
|
#include "hardware/gpio.h"
|
2021-01-20 16:44:27 +00:00
|
|
|
#include "hardware/i2c.h"
|
2021-04-07 01:50:26 +00:00
|
|
|
#include "hardware/interp.h"
|
2021-01-20 16:44:27 +00:00
|
|
|
#include "hardware/irq.h"
|
2021-04-07 01:50:26 +00:00
|
|
|
#include "hardware/pio.h"
|
2021-11-01 19:20:54 +00:00
|
|
|
#include "hardware/pio_instructions.h"
|
2021-04-07 01:50:26 +00:00
|
|
|
#include "hardware/pll.h"
|
|
|
|
#include "hardware/pwm.h"
|
|
|
|
#include "hardware/resets.h"
|
|
|
|
#include "hardware/rtc.h"
|
|
|
|
#include "hardware/spi.h"
|
|
|
|
#include "hardware/sync.h"
|
2021-01-20 16:44:27 +00:00
|
|
|
#include "hardware/timer.h"
|
2021-04-07 01:50:26 +00:00
|
|
|
#include "hardware/uart.h"
|
|
|
|
#include "hardware/vreg.h"
|
|
|
|
#include "hardware/watchdog.h"
|
|
|
|
#include "hardware/xosc.h"
|
2021-01-20 16:44:27 +00:00
|
|
|
#include "pico/binary_info.h"
|
2021-04-07 01:50:26 +00:00
|
|
|
#include "pico/bit_ops.h"
|
|
|
|
#include "pico/bootrom.h"
|
|
|
|
#include "pico/divider.h"
|
|
|
|
#include "pico/double.h"
|
|
|
|
#include "pico/fix/rp2040_usb_device_enumeration.h"
|
|
|
|
#include "pico/float.h"
|
|
|
|
#include "pico/int64_ops.h"
|
|
|
|
#include "pico/malloc.h"
|
|
|
|
#include "pico/multicore.h"
|
|
|
|
#include "pico/printf.h"
|
2021-11-01 19:20:54 +00:00
|
|
|
#include "pico/runtime.h"
|
|
|
|
#include "pico/stdio.h"
|
2021-04-07 01:50:26 +00:00
|
|
|
#include "pico/stdlib.h"
|
|
|
|
#include "pico/sync.h"
|
|
|
|
#include "pico/time.h"
|
|
|
|
#include "pico/unique_id.h"
|
2021-01-20 16:44:27 +00:00
|
|
|
|
2021-11-01 19:20:54 +00:00
|
|
|
#include "hardware/structs/adc.h"
|
|
|
|
#include "hardware/structs/bus_ctrl.h"
|
|
|
|
#include "hardware/structs/clocks.h"
|
|
|
|
#include "hardware/structs/dma.h"
|
|
|
|
#include "hardware/structs/i2c.h"
|
|
|
|
#include "hardware/structs/interp.h"
|
|
|
|
#include "hardware/structs/iobank0.h"
|
|
|
|
#include "hardware/structs/ioqspi.h"
|
|
|
|
#include "hardware/structs/mpu.h"
|
|
|
|
#include "hardware/structs/padsbank0.h"
|
|
|
|
#include "hardware/structs/pads_qspi.h"
|
|
|
|
#include "hardware/structs/pio.h"
|
|
|
|
#include "hardware/structs/pll.h"
|
|
|
|
#include "hardware/structs/psm.h"
|
|
|
|
#include "hardware/structs/pwm.h"
|
|
|
|
#include "hardware/structs/resets.h"
|
|
|
|
#include "hardware/structs/rosc.h"
|
|
|
|
#include "hardware/structs/rtc.h"
|
|
|
|
#include "hardware/structs/scb.h"
|
|
|
|
#include "hardware/structs/sio.h"
|
|
|
|
#include "hardware/structs/spi.h"
|
|
|
|
#include "hardware/structs/ssi.h"
|
|
|
|
#include "hardware/structs/syscfg.h"
|
|
|
|
#include "hardware/structs/systick.h"
|
|
|
|
#include "hardware/structs/timer.h"
|
|
|
|
#include "hardware/structs/uart.h"
|
|
|
|
#include "hardware/structs/usb.h"
|
|
|
|
#include "hardware/structs/vreg_and_chip_reset.h"
|
|
|
|
#include "hardware/structs/watchdog.h"
|
|
|
|
#include "hardware/structs/xip_ctrl.h"
|
|
|
|
#include "hardware/structs/xosc.h"
|
|
|
|
|
2021-01-20 16:44:27 +00:00
|
|
|
bi_decl(bi_block_device(
|
|
|
|
BINARY_INFO_MAKE_TAG('K', 'S'),
|
|
|
|
"foo",
|
|
|
|
0x80000,
|
|
|
|
0x40000,
|
|
|
|
NULL,
|
|
|
|
BINARY_INFO_BLOCK_DEV_FLAG_READ | BINARY_INFO_BLOCK_DEV_FLAG_WRITE |
|
|
|
|
BINARY_INFO_BLOCK_DEV_FLAG_PT_UNKNOWN));
|
|
|
|
|
|
|
|
//#pragma GCC push_options
|
|
|
|
//#pragma GCC optimize ("O3")
|
|
|
|
|
|
|
|
uint32_t *foo = (uint32_t *) 200;
|
|
|
|
|
|
|
|
uint32_t dma_to = 0;
|
|
|
|
uint32_t dma_from = 0xaaaa5555;
|
|
|
|
|
2021-02-07 22:04:25 +00:00
|
|
|
void spiggle(void) {
|
2021-01-20 16:44:27 +00:00
|
|
|
dma_channel_config c = dma_channel_get_default_config(1);
|
|
|
|
channel_config_set_bswap(&c, true);
|
|
|
|
channel_config_set_transfer_data_size(&c, DMA_SIZE_16);
|
|
|
|
channel_config_set_ring(&c, true, 13);
|
|
|
|
dma_channel_set_config(1, &c, false);
|
|
|
|
dma_channel_transfer_from_buffer_now(1, foo, 23);
|
|
|
|
}
|
|
|
|
|
2021-02-07 22:04:25 +00:00
|
|
|
void __isr dma_handler_a(void) {
|
2021-01-20 16:44:27 +00:00
|
|
|
printf("HELLO A\n");
|
|
|
|
if (dma_hw->ints1 & 1) {
|
|
|
|
dma_hw->ints1 = 1;
|
|
|
|
printf("A WINS DMA_TO %08x\n", (uint) dma_to);
|
|
|
|
irq_remove_handler(DMA_IRQ_1, dma_handler_a);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-07 22:04:25 +00:00
|
|
|
void __isr dma_handler_b(void) {
|
2021-01-20 16:44:27 +00:00
|
|
|
printf("HELLO B\n");
|
|
|
|
if (dma_hw->ints1 & 1) {
|
|
|
|
dma_hw->ints1 = 1;
|
2021-11-01 19:20:54 +00:00
|
|
|
printf("B WINS DMA_TO %08x\n", (uint) dma_to);
|
2021-01-20 16:44:27 +00:00
|
|
|
// irq_remove_handler(DMA_IRQ_1, dma_handler_b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//#pragma GCC pop_options
|
|
|
|
|
2021-02-07 22:04:25 +00:00
|
|
|
int main(void) {
|
2021-01-20 16:44:27 +00:00
|
|
|
spiggle();
|
|
|
|
|
|
|
|
stdio_init_all();
|
|
|
|
|
|
|
|
printf("HI %d\n", (int)time_us_32());
|
|
|
|
puts("Hello Everything!");
|
|
|
|
puts("Hello Everything2!");
|
|
|
|
|
|
|
|
irq_add_shared_handler(DMA_IRQ_1, dma_handler_a, 0x80);
|
|
|
|
irq_add_shared_handler(DMA_IRQ_1, dma_handler_b, 0xC0);
|
|
|
|
|
|
|
|
dma_channel_config config = dma_channel_get_default_config(0);
|
|
|
|
// set_exclusive_irq_handler(DMA_IRQ_1, dma_handler_a);
|
|
|
|
dma_channel_set_irq1_enabled(0, true);
|
|
|
|
irq_set_enabled(DMA_IRQ_1, true);
|
|
|
|
dma_channel_configure(0, &config, &dma_to, &dma_from, 1, true);
|
|
|
|
dma_channel_set_config(0, &config, false);
|
|
|
|
|
2021-03-17 18:05:48 +00:00
|
|
|
// note this loop expects to cause a breakpoint!!
|
2021-01-20 16:44:27 +00:00
|
|
|
for (int i = 0; i < 20; i++) {
|
|
|
|
puts("sleepy");
|
|
|
|
sleep_ms(1000);
|
|
|
|
dma_channel_configure(0, &config, &dma_to, &dma_from, 1, true);
|
|
|
|
if (i==3) {
|
|
|
|
irq_remove_handler(DMA_IRQ_1, dma_handler_a);
|
|
|
|
}
|
|
|
|
if (i==2) {
|
|
|
|
irq_remove_handler(DMA_IRQ_1, dma_handler_b);
|
|
|
|
}
|
|
|
|
}
|
2021-03-17 18:05:48 +00:00
|
|
|
// this should compile as we are Cortex M0+
|
|
|
|
__asm volatile("SVC #3");
|
2021-01-20 16:44:27 +00:00
|
|
|
}
|