zig-riscv-embedded

Experimental Zig-based CoAP node for the HiFive1 RISC-V board

git clone https://git.8pit.net/zig-riscv-embedded.git

 1// Copyright © 2021 Sören Tempel
 2//
 3// This program is free software: you can redistribute it and/or modify
 4// it under the terms of the GNU Affero General Public License as
 5// published by the Free Software Foundation, either version 3 of the
 6// License, or (at your option) any later version.
 7//
 8// This program is distributed in the hope that it will be useful, but
 9// WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Affero General Public License for more details.
12//
13// You should have received a copy of the GNU Affero General Public License
14// along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16const gpio = @import("gpio.zig");
17const plic = @import("plic.zig");
18const uart = @import("uart.zig");
19const smux = @import("slipmux.zig");
20
21// Addresses of FE310 peripherals.
22const UART0_CTRL_ADDR: usize = 0x10013000;
23const UART1_CTRL_ADDR: usize = 0x10023000;
24const PLIC_CTRL_ADDR: usize = 0x0C000000;
25const GPIO_CTRL_ADDR: usize = 0x10012000;
26
27// LEDs.
28pub const led0 = gpio.pin(0, 22);
29pub const led1 = gpio.pin(0, 19);
30pub const led2 = gpio.pin(0, 21);
31
32pub const gpio0 = gpio.Gpio{
33    .base_addr = GPIO_CTRL_ADDR,
34};
35pub const plic0 = plic.Plic{
36    .base_addr = PLIC_CTRL_ADDR,
37};
38
39const uart0 = uart.Uart{
40    .base_addr = UART0_CTRL_ADDR,
41    .rx_pin = gpio.pin(0, 16),
42    .tx_pin = gpio.pin(0, 17),
43    .irq = 3,
44};
45var slip0 = smux.Slip{
46    .uart = &uart0,
47    .plic = &plic0,
48};
49pub var slipmux = smux.SlipMux{
50    .slip = &slip0,
51};
52
53pub fn init() void {
54    plic0.init();
55    uart0.init(gpio0, .{ .tx = true, .rx = true });
56
57    gpio0.init(led0, gpio.Mode.OUT);
58    gpio0.init(led1, gpio.Mode.OUT);
59    gpio0.init(led2, gpio.Mode.OUT);
60
61    gpio0.set(led0, 1);
62    gpio0.set(led1, 1);
63    gpio0.set(led2, 1);
64}