7 #include "test_SpiSlave.h"
10 #include "ReadWriteBits.h"
13 void SpiSlave_faked_calls_are_still_available_for_testing(
void)
15 printf(
"SpiSlave_faked_calls_are_still_available_for_testing:\n");
19 "1. Tests are able to call "
20 "real version of `EnableSpiInterrupt` "
21 "(compiler successfully outputs `test_SpiSlave.o`).\n"
26 "2. When tests call `SpiSlaveInit`, it calls "
27 "`EnableSpiInterrupt_fake` (the fake records the call):\n"
30 TEST_ASSERT_TRUE_MESSAGE(
31 AssertCall(mock, call_n,
"EnableSpiInterrupt"),
32 "Expect SpiSlaveInit calls fake which records call name."
37 void SignalDataReady_drives_DataReady_LOW(
void)
41 TEST_ASSERT_BIT_HIGH_MESSAGE(
44 "Cannot run test: must start with DataReady HIGH!"
53 void DisableSpiInterrupt_clears_the_SPI_Interrupt_Enable_bit(
void)
56 SetBit(
Spi_SPCR, Spi_InterruptEnable);
57 TEST_ASSERT_BIT_HIGH_MESSAGE(
60 "Cannot run test: must start with bit HIGH!"
65 TEST_ASSERT_BIT_LOW(Spi_InterruptEnable, *
Spi_SPCR);
69 void EnableSpiInterrupt_clears_SPI_interrupt_flag(
void)
76 AssertCall(mock, call_n,
"ClearSpiInterruptFlag")
79 void EnableSpiInterrupt_enables_interrupt_SPI_Transfer_Complete(
void)
82 ClearBit(
Spi_SPCR, Spi_InterruptEnable);
86 TEST_ASSERT_BIT_HIGH(Spi_InterruptEnable, *
Spi_SPCR);
88 void EnableSpiInterrupt_consumes_6_cycles(
void)
103 void SpiSlaveInit_makes_DataReady_an_output_pin(
void)
107 TEST_ASSERT_BIT_LOW_MESSAGE(
110 "Cannot run test: must start with ddr bit clear!"
115 TEST_ASSERT_BIT_HIGH_MESSAGE(
118 "Expect DataReady to be an output."
121 void SpiSlaveInit_idles_DataReady_high(
void)
125 TEST_ASSERT_BIT_LOW_MESSAGE(
128 "Cannot run test: must start with port bit clear!"
136 TEST_ASSERT_BIT_HIGH_MESSAGE(
139 "Expect DataReady to idle high."
142 void SpiSlaveInit_makes_Miso_an_output_pin(
void)
146 TEST_ASSERT_BIT_LOW_MESSAGE(
149 "Cannot run test: must start with ddr bit clear!"
154 TEST_ASSERT_BIT_HIGH_MESSAGE(
157 "Expect Miso to be an output."
160 void SpiSlaveInit_enables_SPI(
void)
164 TEST_ASSERT_BIT_LOW_MESSAGE(
167 "Cannot run test: must start with bit clear!"
172 TEST_ASSERT_BIT_HIGH_MESSAGE(
175 "Expect bit 6 HIGH to enable SPI module."
178 void SpiSlaveInit_enables_SPI_interrupt(
void)
186 TEST_ASSERT_TRUE_MESSAGE(
187 AssertCall(mock, call_n,
"EnableSpiInterrupt"),
188 "Expect SpiSlaveInit enables the SPI interrupt."
193 void SpiSlaveTx_sends_nbytes_of_input_buffer_to_SpiMaster(
void)
196 uint8_t input_buffer[] = {0xa0, 0xb1, 0xc2};
197 puts(
"Transmit these bytes: {0xa0, 0xb1, 0xc2}");
198 uint16_t nbytes = (uint16_t)
sizeof(input_buffer);
205 uint16_t arg_n = 1; uint8_t *p_argval = input_buffer;
207 while (call_n <= nbytes)
210 SilentAssertCall(mock, call_n,
"SpiSlaveTxByte")
213 AssertArg(mock, call_n++, arg_n, p_argval++)
219 void SpiSlaveTxByte_loads_SPI_data_register_with_input_byte(
void)
222 uint8_t input_byte = 0xAB;
226 TEST_ASSERT_EQUAL_UINT8(input_byte, *
Spi_SPDR);
228 void SpiSlaveTxByte_disables_SPI_ISR_before_signaling_data_ready(
void)
234 TEST_ASSERT_TRUE(AssertCall(mock, call_n++,
"DisableSpiInterrupt"));
235 TEST_ASSERT_TRUE(AssertCall(mock, call_n,
"_SignalDataReady"));
237 void SpiSlaveTxByte_drives_DataReady_LOW_to_signal_data_is_ready(
void)
241 TEST_ASSERT_BIT_HIGH_MESSAGE(
244 "Cannot run test: must start with DataReady HIGH!"
251 TEST_ASSERT_TRUE(AssertCall(mock, call_n,
"_SignalDataReady"));
253 void SpiSlaveTxByte_waits_until_SPI_transfer_is_done(
void)
256 ClearBit(
Spi_SPSR, Spi_InterruptFlag);
257 TEST_ASSERT_BIT_LOW_MESSAGE(
260 "Cannot run test: must start with bit clear!"
267 TEST_ASSERT_TRUE(AssertCall(mock, call_n,
"_SpiTransferIsDone"));
268 TEST_ASSERT_BIT_HIGH(Spi_InterruptFlag, *
Spi_SPSR);
270 void SpiSlaveTxByte_drives_DataReady_HIGH_immediately_after_SPI_transfer_finishes(
void)
274 TEST_ASSERT_BIT_LOW_MESSAGE(
277 "Cannot run test: must start with DataReady LOW!"
284 void SpiSlaveTxByte_enables_SPI_ISR_after_transfer(
void)
287 ClearBit(
Spi_SPCR, Spi_InterruptEnable);
288 TEST_ASSERT_BIT_LOW_MESSAGE(
291 "Cannot run test: must start with bit clear!"
296 TEST_ASSERT_BIT_HIGH(Spi_InterruptEnable, *
Spi_SPCR);
spi_ptr Spi_SPSR
SPI Status Register.
spi_ptr Spi_SPCR
SPI Control Register.
spi_ptr Spi_SPDR
SPI Data Register.
void EnableSpiInterrupt(void)
void DisableSpiInterrupt(void)
void SpiSlaveTx(uint8_t const *input_buffer, uint16_t nbytes)
void SpiSlaveTxByte(uint8_t input_byte)
void _SignalDataReady(void)
Spi.h declares SPI hardware types and variables common to the SPI Master and SPI Slave.
spi_reg Spi_PortOutput
Atmel PORT.
spi_reg Spi_PortDirection
Atmel DDR.