Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add allwinner h3 support #29

Open
wants to merge 85 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
4a99ea6
Ready for testing build
domokos Dec 15, 2022
c5d8d59
Rename cmake file
domokos Dec 15, 2022
d705109
AAdd cmake file
domokos Dec 15, 2022
9a7024d
Fix typos
domokos Dec 15, 2022
7089baf
Remove double method
domokos Dec 15, 2022
94c52d3
Add cast to hash key
domokos Dec 15, 2022
3ad2d5b
Try
domokos Dec 15, 2022
79f6273
Try2
domokos Dec 15, 2022
41e3d9a
Fix typos
domokos Dec 15, 2022
61b5744
Test fix
domokos Dec 15, 2022
42a39a1
Fix incomplete type
domokos Dec 15, 2022
9213b82
Mem map size
domokos Dec 15, 2022
3e711e7
Fix mmap pagesize
domokos Dec 16, 2022
9df4d02
pagesize again
domokos Dec 16, 2022
dc5a760
fix registers
domokos Dec 16, 2022
082a6e0
Debug
domokos Dec 16, 2022
8d3dfae
Debug
domokos Dec 16, 2022
2633634
debug
domokos Dec 16, 2022
ba761c4
debug
domokos Dec 16, 2022
be83eb4
debug
domokos Dec 16, 2022
6ed4918
debug
domokos Dec 16, 2022
dea7a6d
debug
domokos Dec 16, 2022
2bed452
debug
domokos Dec 16, 2022
769f48c
debug
domokos Dec 16, 2022
39982de
debug
domokos Dec 16, 2022
6e07e9a
debug
domokos Dec 16, 2022
3f34376
debug
domokos Dec 16, 2022
9d69763
debug
domokos Dec 16, 2022
97686b2
debug
domokos Dec 16, 2022
541cd5d
debug
domokos Dec 16, 2022
cae25c3
debug
domokos Dec 16, 2022
0df4299
debug
domokos Dec 16, 2022
3e6da5c
debug
domokos Dec 16, 2022
431cf5c
debug
domokos Dec 16, 2022
140744c
debug
domokos Dec 16, 2022
85831e1
debug
domokos Dec 16, 2022
249529b
debug
domokos Dec 16, 2022
3f43858
debug
domokos Dec 16, 2022
f06b69b
debug
domokos Dec 16, 2022
dbe9bba
debug
domokos Dec 16, 2022
a8d4078
debug
domokos Dec 16, 2022
2fb0a2c
debug
domokos Dec 16, 2022
4d1fc8a
debug
domokos Dec 16, 2022
0237449
debug
domokos Dec 16, 2022
3e97429
debug
domokos Dec 16, 2022
e55b5f2
debug
domokos Dec 16, 2022
fd2dab9
debug
domokos Dec 16, 2022
437878f
debug
domokos Dec 16, 2022
80c0436
debug
domokos Dec 16, 2022
07696a0
debug
domokos Dec 16, 2022
4cbc907
debug
domokos Dec 16, 2022
b67600f
debug
domokos Dec 16, 2022
c55ca0c
debug
domokos Dec 16, 2022
d16d975
debug
domokos Dec 16, 2022
6374c8b
debug
domokos Dec 16, 2022
c23ad72
debug
domokos Dec 16, 2022
37d4f8a
debug
domokos Dec 16, 2022
b08d325
debug
domokos Dec 16, 2022
449ef28
debug
domokos Dec 16, 2022
407a3d3
debug
domokos Dec 16, 2022
0f7f28c
debug
domokos Dec 16, 2022
6fae0bd
debug
domokos Dec 16, 2022
f150db1
debug
domokos Dec 16, 2022
d2823a5
debug
domokos Dec 16, 2022
0e7bfbd
debug
domokos Dec 16, 2022
61f7fc2
debug
domokos Dec 16, 2022
2ece1b3
debug
domokos Dec 16, 2022
6ca249c
debug
domokos Dec 16, 2022
8629acf
debug
domokos Dec 16, 2022
cab5991
debug
domokos Dec 16, 2022
6565cef
debug
domokos Dec 16, 2022
5790f27
debug
domokos Dec 16, 2022
ac3905f
debug
domokos Dec 16, 2022
c3ba864
debug
domokos Dec 16, 2022
97d8f15
debug
domokos Dec 16, 2022
384a347
debug
domokos Dec 16, 2022
d39c328
debug
domokos Dec 16, 2022
8c6cb77
debug
domokos Dec 16, 2022
d0d5552
debug
domokos Dec 16, 2022
689b047
debug
domokos Dec 16, 2022
2e1282b
debug
domokos Dec 16, 2022
f1c351c
debug
domokos Dec 16, 2022
01abd65
debug
domokos Dec 16, 2022
35b52c6
debug
domokos Dec 16, 2022
f34a9c1
debug
domokos Dec 16, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ set(INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/include)
set(PLATFORM_DEPENDENCIES "")

# select the platform
set(SUPPORTED_PLATFORMS rpi jetson)
set(SUPPORTED_PLATFORMS rpi jetson sunxih3)
set(PLATFORM "rpi" CACHE STRING "Platform")

if(NOT ${PLATFORM} IN_LIST SUPPORTED_PLATFORMS)
Expand Down
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,25 @@ centimeters, but **_before running this program, make sure you follow your
local laws with regard to restrictions on radio transmissions._**

### Platform
txtempus supports Raspberry Pi series and Nvidia Jetson Series (experimental).
txtempus supports Raspberry Pi series, Sunxi H3 Allwinner based boards (e.g. OrangePI PC) and Nvidia Jetson Series (experimental).

#### Raspberry Pi
So far, it has been tested on a Pi3 and a
Pi Zero W. There has been a report of different frequencies generated with
an older Pi (Bug #1), so until we have a definitive list of available
clock sources inside these, check out that bug for a workaround.

#### SunxiH3 - OrangePI PC
So far, it has been tested on an OrangePI PC. Any H3 based boards should work.
The H3 has only one PWM available - PWM0. This - on the OrabgePI PC board - has
a clock output on the 3-pin header debug UART UART0. The PWM output is the PA5 pin, connected to
the middle pin of the debug UART. For amplitude modulation PA6 (GPIO17) is used, just as in case of thePi.

One may consider using PA4 as the amplitude modulation pin- next to the PWM clock pin - but my
experience shows that the board would not normally boot with the default settings if the antenna
is connected to the debug UART.


#### Nvidia Jetson Series (experimental)
So far, it has been tested only on a Jetson Nano,
but all Jetson devices except for TX1 and TX2 (there is no available pwm pin) are supported.
Expand Down Expand Up @@ -62,7 +73,7 @@ If you're in/or want to display a different time-zone, issue
you.

### Minimal External Hardware
#### Raspberry Pi
#### Raspberry Pi & H3 OrangePI
The external hardware is simple: we use the frequency output on one pin and
another pin to pull the signal to a lower level for the regular attenuation.

Expand All @@ -75,7 +86,8 @@ Schematic | Real world


GPIO4 and 17 are on the inner row of the Header pin, three pins inwards on
the [Raspberry Pi GPIO]-Header.
the [Raspberry Pi GPIO]-Header. For the OrangePI instead of using GPIO4 connect
the wire to PA5 - the middle pin of the 3-pin debug UART header - UART0.

You don't need GPIO17 and the 560Ω resistor for `MSF`, as that works with
switching the signal (on-off keying) instead of attenuating. In that case, you
Expand Down Expand Up @@ -149,6 +161,12 @@ watch/clock.
make
```

#### SunxiH3 - OrangePI PC
```
cmake ../ -DPLATFORM=sunxih3
make
```

#### Nvidia Jetson Series (experimental)
Before you build txtempus on your Jetson:
- You should install [JetsonGPIO](https://github.com/pjueon/JetsonGPIO) which is a library that enables the use of Jetson's GPIOs.
Expand Down Expand Up @@ -296,4 +314,5 @@ watch holder | ... with watch
[MSF]: https://en.wikipedia.org/wiki/Time_from_NPL_(MSF)
[NTP]: https://en.wikipedia.org/wiki/Network_Time_Protocol
[Raspberry Pi GPIO]: https://www.raspberrypi.org/documentation/usage/gpio/
[Allwinner H3 Datasheet]: https://linux-sunxi.org/H3
[very wrong frequency]: https://github.com/hzeller/txtempus/issues/1
1 change: 1 addition & 0 deletions cmake/sunxih3-control.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
list(APPEND SRC_FILES src/sunxih3-control.cc)
98 changes: 98 additions & 0 deletions include/sunxih3/hardware-control-implementation.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
// Part of txtempus, a Low Frequency/Long Wave time signal transmitter.
// Copyright (C) 2022 Domokos Molnar <[email protected]>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

#ifndef SUNXIH3_HARDWARE_CONTROL_IMPLEMENTATION_H
#define SUNXIH3_HARDWARE_CONTROL_IMPLEMENTATION_H

#include "hardware-control.h"
#include <stdint.h>
#include <stdio.h>
#include <map>


// -- Implementation for Allwinner H3 SOC -- https://linux-sunxi.org/Category:H3_Devices
// Tested on OrangePI PC
class HardwareControl::Implementation {
public:

// Initialize
bool Init();

// Set frequency output on PA5 as close as possible to the requested one.
// Returns the approximate frequency it could configure or -1 if that was
// not possible.
// You need to identify PA5 on your board on the OrngePI PC it is the middle pin of the debug UART
double StartClock(double frequency_hertz);
void StopClock();

// Switches the output of the currently running clock.
void EnableClockOutput(bool enable);

// Sets the power of the output by pulling low the voltage divider's mid point
void SetTxPower(CarrierPower power);

private:
enum TPwmCtrlReg {
PWM0_RDY = 28,
PWM0_BYPASS = 9,
PWM_CH0_PUL_START = 8,
PWM_CHANNEL0_MODE = 7,
SCLK_CH0_GATING = 6,
PWM_CH0_ACT_STA = 5,
PWM_CH0_EN = 4,
PWM_CH0_PRESCAL = 0 };

enum TPwmCh0Period {
PWM_CH0_ENTIRE_CYS = 16,
PWM_CH0_ENTIRE_ACT_CYS = 0 };

// PWM clock presaclers
std::map<int, int>PwmCh0Prescale;

// PA6 and PA5 pins are used
enum gpio_pin {
PA5,
PA6
};

struct pwm_params {
int period;
int prescale;
double frequency;
};

// Registers of the board
volatile uint32_t *registers = nullptr;

uint32_t *map_register(off_t register_offset);

// Setup pin as output or LOW-Z input
void SetOutput(gpio_pin pin);
void SetInput(gpio_pin pin);

// Configure pins
void ConfigurePins(void);

// Calculate PWM parameters based on requested output frequency
pwm_params CalculatePWMParams(double requested_freq);
void WaitPwmPeriodReady();

};

using H3BOARD = HardwareControl::Implementation;

#endif // SUNXIH3_HARDWARE_CONTROL_IMPLEMENTATION_H
Loading