-
Notifications
You must be signed in to change notification settings - Fork 844
/
addition.c
35 lines (29 loc) · 881 Bytes
/
addition.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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));
}
}