5 #include "libpropeller/board/board_unit_tester.h"
15 | (1 << Board::kPinTie1b)
16 | (1 << Board::kPinTie2b);
22 const int stacksize =
sizeof (_thread_state_t) +
sizeof (
int) * 30;
39 static void setUp(
void) {
45 waitcnt(CLKFREQ / 100 + CNT);
48 static void tearDown(
void) {
56 static void cog_RunSquareWaveOutput(
void * ignored) {
57 unsigned int nextCNT = CNT;
72 static void run_SquareWaveTest(
const int highCycles,
const int lowCycles) {
74 highDuration = highCycles;
75 lowDuration = lowCycles;
77 cogstart(cog_RunSquareWaveOutput, NULL, stack, stacksize);
78 waitcnt(CLKFREQ / 10 + CNT);
80 TEST_ASSERT_INT_WITHIN(kDelta, highDuration, sut->
getHighTime(k1Index));
81 TEST_ASSERT_INT_WITHIN(kDelta, lowDuration, sut->
getLowTime(k1Index));
84 waitcnt(CLKFREQ / 10 + CNT);
89 static void test_EvenSquareWave(
void) {
90 run_SquareWaveTest(CLKFREQ / 1000, CLKFREQ / 1000);
93 static void test_MostlyHighSquareWave(
void) {
94 run_SquareWaveTest(CLKFREQ / 100, CLKFREQ / 1000);
97 static void test_MostlyLowSquareWave(
void) {
98 run_SquareWaveTest(CLKFREQ / 1000, CLKFREQ / 100);
101 static void test_Something(
void) {
102 run_SquareWaveTest(CLKFREQ / 393, CLKFREQ / 484);
108 static void test_SingleHighPulse(
void) {
109 const int cycles = CLKFREQ / 1000;
112 waitcnt(CLKFREQ / 100 + CNT);
114 waitcnt(cycles + CNT);
116 waitcnt(CLKFREQ / 100 + CNT);
118 TEST_ASSERT_INT_WITHIN(kDelta, cycles, sut->
getHighTime(k1Index));
121 static void test_SingleLowPulse(
void) {
122 const int cycles = CLKFREQ / 1000;
125 waitcnt(CLKFREQ / 100 + CNT);
127 waitcnt(cycles + CNT);
129 waitcnt(CLKFREQ / 100 + CNT);
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));