Initial Release

This commit is contained in:
graham sanderson
2021-01-20 10:49:34 -06:00
commit 46078742c7
245 changed files with 21157 additions and 0 deletions

View File

@@ -0,0 +1,11 @@
add_executable(pio_addition)
pico_generate_pio_header(pio_addition ${CMAKE_CURRENT_LIST_DIR}/addition.pio)
target_sources(pio_addition PRIVATE addition.c)
target_link_libraries(pio_addition PRIVATE pico_stdlib hardware_pio)
pico_add_extra_outputs(pio_addition)
# add url via pico_set_program_url
example_auto_set_url(pio_addition)

35
pio/addition/addition.c Normal file
View File

@@ -0,0 +1,35 @@
/**
* Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <stdlib.h>
#include <stdio.h>
#include "pico/stdlib.h"
#include "hardware/pio.h"
#include "addition.pio.h"
// Pop quiz: how many additions does the processor do when calling this function
uint32_t do_addition(PIO pio, uint sm, uint32_t a, uint32_t b) {
pio_sm_put_blocking(pio, sm, a);
pio_sm_put_blocking(pio, sm, b);
return pio_sm_get_blocking(pio, sm);
}
int main() {
stdio_init_all();
PIO pio = pio0;
uint sm = 0;
uint offset = pio_add_program(pio, &addition_program);
addition_program_init(pio, sm, offset);
printf("Doing some random additions:\n");
for (int i = 0; i < 10; ++i) {
uint a = rand() % 100;
uint b = rand() % 100;
printf("%u + %u = %u\n", a, b, do_addition(pio, sm, a, b));
}
}

27
pio/addition/addition.pio Normal file
View File

@@ -0,0 +1,27 @@
.program addition
; Pop two 32 bit integers from the TX FIFO, add them together, and push the
; result to the TX FIFO. Autopush/pull should be disabled as we're using
; explicit push and pull instructions.
;
; This program uses the two's complement identity x + y == ~(~x - y)
pull
mov x, ~osr
pull
mov y, osr
jmp test ; this loop is equivalent to the following C code:
incr: ; while (y--)
jmp x-- test ; x--;
test: ; This has the effect of subtracting y from x, eventually.
jmp y-- incr
mov isr, ~x
push
% c-sdk {
static inline void addition_program_init(PIO pio, uint sm, uint offset) {
pio_sm_config c = addition_program_get_default_config(offset);
pio_sm_init(pio, sm, offset, &c);
pio_sm_set_enabled(pio, sm, true);
}
%}