firmware  v0.1.2
Chromation Spectrometer Dev-Kit
test_UartSpi.c
1 #include "unity.h"
2 #include "test_UartSpi.h"
3 #include "UartSpi.h"
4 void UartSpiInit_clocks_SPI_bus_at_5MHz(void)
5 {
6  /* =====[ Setup ]===== */
7  *UartSpi_UBRR0 = 1;
8  /* =====[ Operate ]===== */
9  UartSpiInit();
10  /* =====[ Test ]===== */
11  TEST_ASSERT_EQUAL_HEX8(0, *UartSpi_UBRR0);
12 }
13 void UartSpiInit_sets_Sck_as_an_output(void)
14 {
15  /* =====[ Setup ]===== */
16  *UartSpi_ddr = 0x00;
17  /* =====[ Operate ]===== */
18  UartSpiInit();
19  /* =====[ Test ]===== */
20  TEST_ASSERT_BIT_HIGH_MESSAGE(
21  UartSpi_Sck, *UartSpi_ddr, "Failed for pin Sck."
22  );
23 }
24 void UartSpiInit_sets_AdcConv_to_idle_low(void)
25 {
26  /* =====[ Setup ]===== */
27  *UartSpi_port = 0xFF;
28  /* =====[ Operate ]===== */
29  UartSpiInit();
30  /* =====[ Test ]===== */
31  TEST_ASSERT_BIT_LOW_MESSAGE(
32  UartSpi_AdcConv, *UartSpi_port, "Failed for pin AdcConv."
33  );
34 }
35 void UartSpiInit_sets_AdcConv_as_an_output(void)
36 {
37  /* =====[ Setup ]===== */
38  *UartSpi_ddr = 0x00;
39  /* =====[ Operate ]===== */
40  UartSpiInit();
41  /* =====[ Test ]===== */
42  TEST_ASSERT_BIT_HIGH_MESSAGE(
43  UartSpi_AdcConv, *UartSpi_ddr, "Failed for pin AdcConv."
44  );
45 }
46 void UartSpiInit_enables_the_UART_in_Master_SPI_Mode(void)
47 {
48  /* =====[ Setup ]===== */
49  *UartSpi_UCSR0C = 0x00;
50  /* =====[ Operate ]===== */
51  UartSpiInit();
52  /* =====[ Test ]===== */
53  TEST_ASSERT_BIT_HIGH_MESSAGE(
54  UartSpi_UMSEL00,
55  *UartSpi_UCSR0C,
56  "Failed for bit ModeSelect0."
57  );
58  TEST_ASSERT_BIT_HIGH_MESSAGE(
59  UartSpi_UMSEL01,
60  *UartSpi_UCSR0C,
61  "Failed for bit ModeSelect1."
62  );
63 }
64 void UartSpiInit_uses_SPI_data_mode_CPOL_1_CPHA_1(void)
65 {
66  /* =====[ Setup ]===== */
67  *UartSpi_UCSR0C = 0x00;
68  /* =====[ Operate ]===== */
69  UartSpiInit();
70  /* =====[ Test ]===== */
71  TEST_ASSERT_BIT_HIGH_MESSAGE(
72  UartSpi_UCPOL0,
73  *UartSpi_UCSR0C,
74  "Failed for bit ClockPolarity."
75  );
76  TEST_ASSERT_BIT_HIGH_MESSAGE(
77  UartSpi_UCPHA0,
78  *UartSpi_UCSR0C,
79  "Failed for bit ClockPhase."
80  );
81 }
82 void UartSpiInit_cfgs_SPI_to_transfer_MSB_first(void)
83 {
84  /* =====[ Setup ]===== */
85  *UartSpi_UCSR0C = 0xFF;
86  /* =====[ Operate ]===== */
87  UartSpiInit();
88  /* =====[ Test ]===== */
89  TEST_ASSERT_BIT_LOW_MESSAGE(
90  UartSpi_UDORD0,
91  *UartSpi_UCSR0C,
92  "Failed for bit DataOrder."
93  );
94 }
95 void UartSpiInit_gives_SPI_control_over_Miso_and_Mosi_pin_behavior(void)
96 {
97  /* =====[ Setup ]===== */
98  *UartSpi_UCSR0B = 0x00;
99  /* =====[ Operate ]===== */
100  UartSpiInit();
101  /* =====[ Test ]===== */
102  TEST_ASSERT_BIT_HIGH_MESSAGE(
103  UartSpi_RXEN0,
104  *UartSpi_UCSR0B,
105  "Failed for bit RxEnable."
106  );
107  TEST_ASSERT_BIT_HIGH_MESSAGE(
108  UartSpi_TXEN0,
109  *UartSpi_UCSR0B,
110  "Failed for bit TxEnable."
111  );
112 }
void UartSpiInit(void)
Definition: UartSpi.h:164