UoS³ Flight Computer Firmware
 All Data Structures Files Functions Groups Pages
interleave.c
1 #include "../../firmware.h"
2 #include "../../test.h"
3 
4 #define PACKET_LENGTH_32x32 128 // 1024/8
5 
6 uint8_t packet_test_32x32[PACKET_LENGTH_32x32];
7 uint8_t packet_reference_32x32[PACKET_LENGTH_32x32];
8 
9 #define PACKET_LENGTH_64x64 512 // 4096/8
10 
11 uint8_t packet_test_64x64[PACKET_LENGTH_64x64];
12 uint8_t packet_reference_64x64[PACKET_LENGTH_64x64];
13 
14 bool test_interleave(void)
15 {
16  uint32_t i;
17 
18  /* Populate packet */
19  for(i=0; i<PACKET_LENGTH_32x32; i++)
20  {
21  packet_reference_32x32[i] = (uint8_t)(Random(255));
22  packet_test_32x32[i] = packet_reference_32x32[i];
23  }
24 
25  if(TEST_VERBOSE)
26  {
27  Debug_print("Original packet\r\n");
28  buffer_print_bin(packet_test_32x32, PACKET_LENGTH_32x32);
29  }
30 
31  /* Interleave packet */
32  if(TEST_VERBOSE)
33  {
34  Debug_print("Interleaving packet..\r\n");
35  }
36  Packet_interleave_32x32(packet_test_32x32);
37 
38  if(TEST_VERBOSE)
39  {
40  Debug_print("Interleaved packet\r\n");
41  buffer_print_bin(packet_test_32x32, PACKET_LENGTH_32x32);
42  }
43 
44  Packet_uninterleave_32x32(packet_test_32x32);
45 
46  if(TEST_VERBOSE)
47  {
48  Debug_print("Un-interleaved packet\r\n");
49  buffer_print_bin(packet_test_32x32, PACKET_LENGTH_32x32);
50  }
51 
52  if(memcmp(packet_test_32x32, packet_reference_32x32, PACKET_LENGTH_32x32) != 0)
53  {
54  return false;
55  }
56 
57 
58  /* Populate packet */
59  for(i=0; i<PACKET_LENGTH_64x64; i++)
60  {
61  packet_reference_64x64[i] = (uint8_t)(Random(255));
62  packet_test_64x64[i] = packet_reference_64x64[i];
63  }
64 
65  if(TEST_VERBOSE)
66  {
67  Debug_print("Original packet\r\n");
68  buffer_print_bin(packet_test_64x64, PACKET_LENGTH_64x64);
69  }
70 
71  /* Interleave packet */
72  if(TEST_VERBOSE)
73  {
74  Debug_print("Interleaving packet..\r\n");
75  }
76  Packet_interleave_64x64(packet_test_64x64);
77 
78  if(TEST_VERBOSE)
79  {
80  Debug_print("Interleaved packet\r\n");
81  buffer_print_bin(packet_test_64x64, PACKET_LENGTH_64x64);
82  }
83 
84  Packet_uninterleave_64x64(packet_test_64x64);
85 
86  if(TEST_VERBOSE)
87  {
88  Debug_print("Un-interleaved packet\r\n");
89  buffer_print_bin(packet_test_64x64, PACKET_LENGTH_64x64);
90  }
91 
92  if(memcmp(packet_test_64x64, packet_reference_64x64, PACKET_LENGTH_64x64) == 0)
93  {
94  return true;
95  }
96  else
97  {
98  return false;
99  }
100 }
uint32_t Random(uint32_t max)
Definition: random.c:21
void Debug_print(char *fmt,...)
Definition: debug.c:16
void buffer_print_bin(uint8_t *buffer, uint32_t length)
Definition: test.c:71