GR712RC unit tests 1.0
Bare-metal C++ hardware tests for the PLATO DPU (IAA-CSIC, 2019)
Loading...
Searching...
No Matches
spw_periph.cpp
Go to the documentation of this file.
1
14
15#include <cstdint>
16#include <array>
17#include <mcal/mcal.h>
18
19namespace
20{
21
22constexpr std::uint32_t max_packet_size = 4*1024*1024;
23std::array<std::uint8_t, max_packet_size> spw0_memory_pool;
24std::array<std::uint8_t, max_packet_size> spw1_memory_pool;
25std::array<std::uint8_t, max_packet_size> spw2_memory_pool;
26std::array<std::uint8_t, max_packet_size> spw3_memory_pool;
27std::array<std::uint8_t, max_packet_size> spw4_memory_pool;
28std::array<std::uint8_t, max_packet_size> spw5_memory_pool;
29
30
31mcal::port::port_pin<std::uint32_t,
32 std::uint32_t,
34 UINT32_C(26) > gpio26_output_pin;
35
36mcal::spw::spw_communication<std::uint32_t,
37 std::uint32_t, //Minimal transmission packet 4 bytes.
39
41 std::uint8_t,
43
44//Active delay, loops for x time.
45void delay()
46{
47 for (std::uint32_t iter= 0; iter < 4000; ++iter)
48 for (std::uint32_t iter2 = 0; iter2 < 100; iter2++)
49 {
51 }
52}
53}
54
55
56int main()
57{
58
59 constexpr std::uint32_t def_pattern = 0x55555500UL;
60
61 constexpr std::array<std::uint8_t,13> welcome_msg = {'\n', '\r', 'U', 'A', 'R', 'T',' ', 'T','e', 's', 't', '\n', '\r'};
62 constexpr std::array<std::uint8_t,12> underline_msg = {'=', '=', '=', '=', '=','=', '=','=', '=', '=', '\n', '\r'};
63
64 constexpr std::array<std::uint32_t,20> spw_msg = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
65 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19};
66
67 enum class spw_error : uint32_t {CREDIT_ERR = 0x02, ESCAPE_ERR = 0x04, DISCONNECT_ERR = 0x08,
68 PARITY_ERR = 0x10, INVALID_ADDR_ERR = 0x80, END_OF_PACKET_ERR = 0x100 };
69
70 mcal::init(nullptr);
71
72 gpio26_output_pin.set_direction_output();
73
74 //Print the Welcome Message
75 the_uart0.send_n( welcome_msg.begin(), welcome_msg.end() );
76 delay();
77 the_uart0.send_n( underline_msg.begin(), underline_msg.end() );
78 delay();
79
80 std::uint32_t counter = 0 ;
81 while(1) {
82
83 the_uart0.send('T');
84 // Geet the Spw Link Status
85 const std::uint32_t link_status = the_spw0.get_link_status();
86 const std::uint8_t link_state = (link_status >> 21) & 0x7;
87 const std::uint8_t link_err = (link_status & 0xF);
88 the_uart0.send( link_state + 0x30);
89 the_uart0.send( link_err + 0x30);
90
91 if ((link_status >> 21) == 0x5U)
92 {
93 the_uart0.send('C');
94 the_spw0.send(def_pattern | counter);
95
96 the_spw0.send_n(spw_msg.begin(), spw_msg.end());
97 counter ++;
98 }
99
100 delay();
101 gpio26_output_pin.toggle_pin();
102
103 }
104
105
106
107 return 0;
108}
static void set_direction_output()
Definition mcal_port.h:27
static void toggle_pin()
Definition mcal_port.h:101
bool send(const bval_type byte_to_send)
Definition mcal_uart.h:66
Microcontroller abstraction layer.
void nop()
Definition mcal_cpu.h:24
constexpr std::uint32_t grgpio1_base_address
Definition mcal_reg.h:27
constexpr std::uint32_t grspw0_base_address
Definition mcal_reg.h:54
constexpr std::uint32_t uart0_base_address
Definition mcal_reg.h:46
void init(config_type *)
Definition mcal.cpp:12
int main()