From c9094c7d7b49e21bc53d273288463723beec6601 Mon Sep 17 00:00:00 2001 From: Marc Poulhiès Date: Thu, 7 Jul 2022 22:36:29 +0200 Subject: Initial Ada firmware Missing doc, comment. --- firmware/ada/src/logging.adb | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 firmware/ada/src/logging.adb (limited to 'firmware/ada/src/logging.adb') diff --git a/firmware/ada/src/logging.adb b/firmware/ada/src/logging.adb new file mode 100644 index 0000000..f6a159f --- /dev/null +++ b/firmware/ada/src/logging.adb @@ -0,0 +1,61 @@ +with HAL; use HAL; +with STM32.Device; use STM32.Device; +with STM32.GPIO; use STM32.GPIO; +with STM32.USARTs; use STM32.USARTs; + +package body Logging is + + TX_Pin : constant GPIO_Point := PB6; + RX_Pin : constant GPIO_Point := PB7; + + procedure Init is + begin + Enable_Clock (USART_1); + Enable_Clock (RX_Pin & TX_Pin); + + Configure_IO + (RX_Pin & TX_Pin, + (Mode => Mode_AF, + AF => GPIO_B_AF_USART1_0, + Resistors => Pull_Up, + AF_Speed => Speed_50MHz, + AF_Output_Type => Push_Pull)); + + Disable (USART_1); + + Set_Oversampling_Mode (USART_1, Oversampling_By_16); + Set_Baud_Rate (USART_1, 115200); + Set_Mode (USART_1, Tx_Rx_Mode); + Set_Stop_Bits (USART_1, Stopbits_1); + Set_Word_Length (USART_1, Word_Length_8); + Set_Parity (USART_1, No_Parity); + Set_Flow_Control (USART_1, No_Flow_Control); + + Enable (USART_1); + + end Init; + + procedure Await_Send_Ready (This : USART) is + begin + loop + exit when Tx_Ready (This); + end loop; + end Await_Send_Ready; + + procedure Put_Blocking (This : in out USART; Data : UInt16) is + begin + Await_Send_Ready (This); + Transmit (This, UInt9 (Data)); + end Put_Blocking; + + procedure Log (S : String; L : Integer := 1; Deindent : Integer := 0) is + begin + + for C of S loop + Put_Blocking (USART_1, Character'Pos (C)); + end loop; + + Put_Blocking (USART_1, UInt16 (13)); -- CR + Put_Blocking (USART_1, UInt16 (10)); -- LF + end Log; +end Logging; -- cgit v1.2.3