diff --git a/lambda-test/lambda-test.c b/lambda-test/lambda-test.c index 1628fc8..ad0c6e4 100644 --- a/lambda-test/lambda-test.c +++ b/lambda-test/lambda-test.c @@ -39,69 +39,6 @@ {20, 20} }; -/* Module interrupts */ - -bool testSetupPorts(void) { - setupPorts(); - - // test that the pull-up resistor for the mouton is enabled - assertTrue(bit_is_set(PORTB, PB0)); - - // test that the beep output pin is enabled - assertTrue(bit_is_set(DDRB, PB1)); - - return true; -} - -bool testSetupSleepMode(void) { - setupSleepMode(); - - // set_sleep_mode(SLEEP_MODE_IDLE); - assertFalse(bit_is_set(SMCR, SM2)); - assertFalse(bit_is_set(SMCR, SM1)); - assertFalse(bit_is_set(SMCR, SM0)); - - return true; -} - -bool testInitInterrupts(void) { - initInterrupts(); - - // ADC interrupt enabled - assertTrue(bit_is_set(ADCSRA, ADIE)); - // PC interrupts enabled - // assertTrue(bit_is_set(PCICR, PCIE0)); - // assertTrue(bit_is_set(PCMSK0, PB0)); - // enable timer 0 overflow interrupt - assertTrue(bit_is_set(TIMSK0, TOIE0)); - // USART RX complete interrupt 0 enabled - assertTrue(bit_is_set(UCSR0B, RXCIE0)); - - // sei(); // enable global interrupts - assertTrue(bit_is_set(SREG, SREG_I)); - - return true; -} - -bool testInitTimers(void) { - initInterrupts(); - - // timer0 clock prescaler /64 = 15.625 kHz overflowing every 16.2 ms - uint8_t prescalerBy64 = (1 << CS00) | (1 << CS01); - assertTrue((TCCR0B & prescalerBy64) == prescalerBy64); - - // timer1 Clear Timer on Compare Match mode, TOP OCR1A - assertTrue(bit_is_set(TCCR1B, WGM12)); - // timer1 clock prescaler/8 - assertTrue(bit_is_set(TCCR1B, CS11)); - // toggles PB1 at 7.8 kHz generating a 3.9 kHz beep - // assertTrue(OCR1A == 16); - // 1.8 kHz is less noisy on the small piezo beeper - assertTrue(OCR1A == 32); - - return true; -} - /* Module adc */ bool testSetupADC(void) { @@ -135,6 +72,59 @@ return mV > 4900; } +/* Module command */ + +bool testIsSimulation(void) { + assertFalse(isSimulation()); + runCommand("se"); + assertTrue(isSimulation()); + runCommand("sd"); + assertFalse(isSimulation()); + + return true; +} + +bool testIsLogging(void) { + assertFalse(isLogging()); + runCommand("le"); + assertTrue(isLogging()); + runCommand("ld"); + assertFalse(isLogging()); + + return true; +} + +/* Module display */ + +// TODO assertions +bool testCycle(void) { + cycleDisplay(); + + return true; +} + +// TODO assertions +bool testUpdateInitial(void) { + + return true; +} + +// TODO assertions +bool testUpdate(void) { + measurement meas = {0, 0, 0}; + updateMeas(meas); + + return true; +} + +// TODO test display() with no display connected? +bool testDisplay(void) { + measurement meas = {0, 0, 0}; + displayMeas(meas, " "); + + return true; +} + /* Module integers */ bool testDivRoundNearest(void) { @@ -201,6 +191,69 @@ return true; } +/* Module interrupts */ + +bool testSetupPorts(void) { + setupPorts(); + + // test that the pull-up resistor for the mouton is enabled + assertTrue(bit_is_set(PORTB, PB0)); + + // test that the beep output pin is enabled + assertTrue(bit_is_set(DDRB, PB1)); + + return true; +} + +bool testSetupSleepMode(void) { + setupSleepMode(); + + // set_sleep_mode(SLEEP_MODE_IDLE); + assertFalse(bit_is_set(SMCR, SM2)); + assertFalse(bit_is_set(SMCR, SM1)); + assertFalse(bit_is_set(SMCR, SM0)); + + return true; +} + +bool testInitInterrupts(void) { + initInterrupts(); + + // ADC interrupt enabled + assertTrue(bit_is_set(ADCSRA, ADIE)); + // PC interrupts enabled + // assertTrue(bit_is_set(PCICR, PCIE0)); + // assertTrue(bit_is_set(PCMSK0, PB0)); + // enable timer 0 overflow interrupt + assertTrue(bit_is_set(TIMSK0, TOIE0)); + // USART RX complete interrupt 0 enabled + assertTrue(bit_is_set(UCSR0B, RXCIE0)); + + // sei(); // enable global interrupts + assertTrue(bit_is_set(SREG, SREG_I)); + + return true; +} + +bool testInitTimers(void) { + initInterrupts(); + + // timer0 clock prescaler /64 = 15.625 kHz overflowing every 16.2 ms + uint8_t prescalerBy64 = (1 << CS00) | (1 << CS01); + assertTrue((TCCR0B & prescalerBy64) == prescalerBy64); + + // timer1 Clear Timer on Compare Match mode, TOP OCR1A + assertTrue(bit_is_set(TCCR1B, WGM12)); + // timer1 clock prescaler/8 + assertTrue(bit_is_set(TCCR1B, CS11)); + // toggles PB1 at 7.8 kHz generating a 3.9 kHz beep + // assertTrue(OCR1A == 16); + // 1.8 kHz is less noisy on the small piezo beeper + assertTrue(OCR1A == 32); + + return true; +} + /* Module sensors */ bool testMeasure(void) { @@ -309,59 +362,6 @@ return ! strcmp(info, RICH); } -/* Module display */ - -// TODO assertions -bool testCycle(void) { - cycleDisplay(); - - return true; -} - -// TODO assertions -bool testUpdateInitial(void) { - - return true; -} - -// TODO assertions -bool testUpdate(void) { - measurement meas = {0, 0, 0}; - updateMeas(meas); - - return true; -} - -// TODO test display() with no display connected? -bool testDisplay(void) { - measurement meas = {0, 0, 0}; - displayMeas(meas, " "); - - return true; -} - -/* Module command */ - -bool testIsSimulation(void) { - assertFalse(isSimulation()); - runCommand("se"); - assertTrue(isSimulation()); - runCommand("sd"); - assertFalse(isSimulation()); - - return true; -} - -bool testIsLogging(void) { - assertFalse(isLogging()); - runCommand("le"); - assertTrue(isLogging()); - runCommand("ld"); - assertFalse(isLogging()); - - return true; -} - /* Module strings */ bool testSplit(void) { @@ -395,12 +395,14 @@ // TODO these long function names passed along as strings use a lot of memory // use PROGMEM? test tests[] = { - {"interrupts", "testSetupPorts", testSetupPorts}, - {"interrupts", "testSetupSleepMode", testSetupSleepMode}, - {"interrupts", "testInitInterrupts", testInitInterrupts}, - {"interrupts", "testInitTimers", testInitInterrupts}, {"adc", "testSetupADC", testSetupADC}, {"adc", "testGetVoltage", testGetVoltage}, + {"command", "testIsSimulation", testIsSimulation}, + {"command", "testIsLogging", testIsLogging}, + {"display", "testCycle", testCycle}, + {"display", "testUpdateInitial", testUpdateInitial}, + {"display", "testUpdate", testUpdate}, + {"display", "testDisplay", testDisplay}, {"integers", "testDivRoundNearest", testDivRoundNearest}, {"integers", "testDivRoundNearestNumNeg", testDivRoundNearestNumNeg}, {"integers", "testDivRoundNearestDenNeg", testDivRoundNearestDenNeg}, @@ -409,6 +411,10 @@ {"integers", "testDivRoundUpNumNeg", testDivRoundUpNumNeg}, {"integers", "testDivRoundUpDenNeg", testDivRoundUpDenNeg}, {"integers", "testDivRoundUpBothNeg", testDivRoundUpBothNeg}, + {"interrupts", "testSetupPorts", testSetupPorts}, + {"interrupts", "testSetupSleepMode", testSetupSleepMode}, + {"interrupts", "testInitInterrupts", testInitInterrupts}, + {"interrupts", "testInitTimers", testInitInterrupts}, {"sensors", "testMeasure", testMeasure}, {"sensors", "testToLambdaValue", testToLambdaValue}, {"sensors", "testToLambdaInter", testToLambdaInter}, @@ -423,12 +429,6 @@ {"sensors", "testToInfoOkay", testToInfoOkay}, {"sensors", "testToInfoIdeal", testToInfoIdeal}, {"sensors", "testToInfoRich", testToInfoRich}, - {"display", "testCycle", testCycle}, - {"display", "testUpdateInitial", testUpdateInitial}, - {"display", "testUpdate", testUpdate}, - {"display", "testDisplay", testDisplay}, - {"command", "testIsSimulation", testIsSimulation}, - {"command", "testIsLogging", testIsLogging}, {"strings", "testSplit", testSplit}, {"strings", "testSplitSizeTooSmall", testSplitSizeTooSmall} };