Sylvain Munaut | bc9f5c4 | 2020-09-14 10:22:29 +0200 | [diff] [blame^] | 1 | /* |
| 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 | |
| 15 | struct 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 | |
| 29 | static volatile struct misc * const misc_regs = (void*)(MISC_BASE); |
| 30 | |
| 31 | |
| 32 | static const int pdm_bits[5] = { 12, 12, 8, 8, 8 }; |
| 33 | |
| 34 | |
| 35 | void |
| 36 | pdm_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 | |
| 46 | uint16_t |
| 47 | e1_tick_read(void) |
| 48 | { |
| 49 | return misc_regs->e1_tick[0].tx; |
| 50 | } |