CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Toggle main menu visibility
Loading...
Searching...
No Matches
sdk
include
platform
sunburst
platform-pwm.hh
1
#pragma once
2
#include <
debug.hh
>
3
#include <stdint.h>
4
#include <
utils.hh
>
5
6
namespace
SonataPulseWidthModulation
7
{
8
/**
9
* A driver for Sonata's Pulse-Width Modulation (PWM).
10
*
11
* Documentation source can be found at:
12
* https://github.com/lowRISC/sonata-system/blob/97a525c48f7bf051b999d0178dba04859819bc5e/doc/ip/pwm.md
13
*
14
* Rendered documentation is served from:
15
* https://lowrisc.github.io/sonata-system/doc/ip/pwm.html
16
*/
17
struct
Output
:
private
utils::NoCopyNoMove
18
{
19
/**
20
* The duty cycle of the wave, represented as a width counter. That
21
* is, the number of clock cycles for which the signal will be on. The
22
* duty cycle as a percentage is (duty cycle / period) * 100.
23
*/
24
uint32_t
dutyCycle
;
25
26
/**
27
* The period (width) of the output block wave, set with the number of
28
* clock cycles that one period should last. The maximum period is 255
29
* as only an 8 bit counter is being used.
30
*/
31
uint32_t
period
;
32
33
/*
34
* Sets the output of a specified pulse-width modulated output.
35
*
36
* @param period The length of the output wave represented as a counter
37
* of system clock cycles.
38
* @param dutyCycle The number of clock cycles for which a high pulse is
39
* sent within that period.
40
*
41
* So for example `output_set(0, 200, 31)` should set a 15.5% output.
42
* For a constant high output (100% duty cycle), set the dutyCycle >
43
* period.
44
*/
45
void
output_set(uint8_t
period
, uint8_t
dutyCycle
)
volatile
46
{
47
this->period =
period
;
48
this->dutyCycle =
dutyCycle
;
49
}
50
};
51
52
/// A convenience structure that can map onto multiple PWM outputs.
53
template
<
size_t
NumberOfPwms = 6>
54
struct
Array
55
{
56
Output
output[NumberOfPwms];
57
58
template
<
size_t
Index>
59
volatile
Output
*get()
volatile
60
{
61
static_assert
(Index < NumberOfPwms,
"PWM index out of bounds"
);
62
return
output + Index;
63
}
64
};
65
66
/**
67
* There are six general purpose PWM outputs are general purpose that can be
68
* pinmuxed to different outputs.
69
*/
70
using
General =
Array<6>
;
71
/// There is one dedicated PWM for the LCD backlight.
72
using
LcdBacklight =
Output
;
73
}
// namespace SonataPulseWidthModulation
utils::NoCopyNoMove
Utility class to delete copy and move contructors.
Definition
utils.hh:53
debug.hh
C++ APIs for assertions, invariants, and writing formatted debug messages to a UART.
SonataPulseWidthModulation::Array
A convenience structure that can map onto multiple PWM outputs.
Definition
platform-pwm.hh:55
SonataPulseWidthModulation::Output
A driver for Sonata's Pulse-Width Modulation (PWM).
Definition
platform-pwm.hh:18
SonataPulseWidthModulation::Output::period
uint32_t period
The period (width) of the output block wave, set with the number of clock cycles that one period shou...
Definition
platform-pwm.hh:31
SonataPulseWidthModulation::Output::dutyCycle
uint32_t dutyCycle
The duty cycle of the wave, represented as a width counter.
Definition
platform-pwm.hh:24
utils.hh
Miscellaneous utility functions and classes.
Generated by
1.18.0