blob: 9ceb8c642a18bac4c72b61aac3fa34e3b0bf9a44 [file] [log] [blame]
Sylvain Munautbc9f5c42020-09-14 10:22:29 +02001/*
2 * misc.c
3 *
4 * Copyright (C) 2019-2020 Sylvain Munaut <tnt@246tNt.com>
5 * SPDX-License-Identifier: GPL-3.0-or-later
6 */
7
8#include <stdbool.h>
9#include <stdint.h>
10
11#include "config.h"
12#include "misc.h"
13
14
15struct misc {
16 uint32_t warmboot;
17 uint32_t gpio;
18 uint32_t e1_led;
19 uint32_t _rsvd;
20 struct {
21 uint16_t tx;
22 uint16_t rx;
23 } e1_tick[2];
24 uint32_t gps;
25 uint32_t time;
26 uint32_t pdm[8];
27} __attribute__((packed,aligned(4)));
28
29static volatile struct misc * const misc_regs = (void*)(MISC_BASE);
30
31
32static const int pdm_bits[5] = { 12, 12, 8, 8, 8 };
33
34
35void
36pdm_set(int chan, bool enable, unsigned value, bool normalize)
37{
38 if (normalize)
39 value >>= (16 - pdm_bits[chan]);
40 if (enable)
41 value |= 0x80000000;
42 misc_regs->pdm[chan] = value;
43}
44
45
46uint16_t
47e1_tick_read(void)
48{
49 return misc_regs->e1_tick[0].tx;
50}