2 #include "libpropeller/pulsewidthreader/pulse_width_reader.h"
5 #include "libpropeller/board/board_unit_tester.h"
6 #include "libpropeller/pin/pin.h"
14 const int kPulseMask = (1 << libpropeller::Board::kPinSqw)
15 | (1 << libpropeller::Board::kPinTie1b)
16 | (1 << libpropeller::Board::kPinTie2b);
23 int stack [stacksize];
26 const int kSqwIndex = 0;
27 const int k1Index = 1;
28 const int k2Index = 2;
30 const int kDelta = 700;
32 volatile bool runCog =
false;
39 static void setUp(
void) {
40 sqwOutputPin1.
input();
41 sqwOutputPin2.
input();
44 sut->Start(kPulseMask);
48 static void tearDown(
void) {
56 static void cog_RunSquareWaveOutput(
void * ignored) {
57 unsigned int nextCNT =
CNT;
60 nextCNT += highDuration;
65 nextCNT += lowDuration;
72 static void run_SquareWaveTest(
const int highCycles,
const int lowCycles) {
74 highDuration = highCycles;
75 lowDuration = lowCycles;
77 cogstart(cog_RunSquareWaveOutput, NULL, stack, stacksize);
80 TEST_ASSERT_INT_WITHIN(kDelta, highDuration, sut->getHighTime(k1Index));
81 TEST_ASSERT_INT_WITHIN(kDelta, lowDuration, sut->getLowTime(k1Index));
89 static void test_EvenSquareWave(
void) {
93 static void test_MostlyHighSquareWave(
void) {
97 static void test_MostlyLowSquareWave(
void) {
101 static void test_Something(
void) {
108 static void test_SingleHighPulse(
void) {
109 const int cycles =
CLKFREQ / 1000;
113 sqwOutputPin1.
high();
118 TEST_ASSERT_INT_WITHIN(kDelta, cycles, sut->getHighTime(k1Index));
121 static void test_SingleLowPulse(
void) {
122 const int cycles =
CLKFREQ / 1000;
124 sqwOutputPin1.
high();
128 sqwOutputPin1.
high();
131 TEST_ASSERT_INT_WITHIN(kDelta, cycles, sut->getLowTime(k1Index));
136 static void test_32768SquareWave(
void) {
137 const int kClockFrequency = 32768;
138 TEST_ASSERT_INT_WITHIN(130,
CLKFREQ / (2 * kClockFrequency), sut->getHighTime(kSqwIndex));
139 TEST_ASSERT_INT_WITHIN(130,
CLKFREQ / (2 * kClockFrequency), sut->getLowTime(kSqwIndex));