From 45987aa3c268f4986dfa3d88da432889438c01a5 Mon Sep 17 00:00:00 2001 From: Isabell Zorr Date: Wed, 17 Jun 2020 18:45:21 +0200 Subject: [PATCH] Initialize SPI driver ref #187 --- src/core/nRF52832/spi.adb | 48 ++++++++++++++++++++++ src/core/nRF52832/spi.ads | 83 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 src/core/nRF52832/spi.adb create mode 100644 src/core/nRF52832/spi.ads diff --git a/src/core/nRF52832/spi.adb b/src/core/nRF52832/spi.adb new file mode 100644 index 0000000..f55b4fc --- /dev/null +++ b/src/core/nRF52832/spi.adb @@ -0,0 +1,48 @@ +package body Spi with +SPARK_Mode +is + package SSE renames System.Storage_Elements; + use type SSE.Integer_Address; + + Base : constant SSE.Integer_Address := 16#40003000#; + + ENABLE : Reg_Enable with + Import, + Address => SSE.To_Address (Base + 16#500#); + + SPI_CONFIG_CPOL : Reg_SPI_CONFIG_CPOL with + Import, + Address => SSE.To_Address (Base + 16#554#); + + PSEL_SCK : Reg_PSEL_SCK with + Import, + Address => SSE.To_Address (Base + 16#508#); + + PSEL_MOSI : Reg_PSEL_MOSI with + Import, + Address => SSE.To_Address (Base + 16#50C#); + + SPI_TXD : Reg_SPI_TXD with + Import, + Address => SSE.To_Address (Base + 16#51C#); + + SPI_FREQUENCY : Reg_SPI_Frequency with + Import, + Address => SSE.To_Address (Base + 16#524#); + + procedure Initialize is + begin + ENABLE := (ENABLE => Disabled); + GPIO.Configure (26, GPIO.Port_Out); + GPIO.Write (26, GPIO.High); + GPIO.Configure (27, GPIO.Port_Out); + GPIO.Write(27, GPIO.High); + PSEL_SCK := (CONNECT => Connected, PIN => 26); + PSEL_MOSI := (CONNECT => Connected, PIN => 27); + SPI_CONFIG_CPOL := (CPOL => ActiveHIGH); + SPI_FREQUENCY := (FREQUENCY => M8); + ENABLE := (ENABLE => Enabled); + end Initialize; + + +end Spi; diff --git a/src/core/nRF52832/spi.ads b/src/core/nRF52832/spi.ads new file mode 100644 index 0000000..a9b0604 --- /dev/null +++ b/src/core/nRF52832/spi.ads @@ -0,0 +1,83 @@ +with Componolit.Runtime.Drivers.GPIO; + +package Spi with + SPARK_Mode +is + package GPIO renames Componolit.Runtime.Drivers.GPIO; + procedure Initialize; + +private + + type SPI_CONFIG_CPOL is (ActiveHIGH, ActiveLOW) with + Size => 1; + + for SPI_CONFIG_CPOL use (ActiveHIGH => 0, + ActiveLOW => 1); + + type Reg_SPI_CONFIG_CPOL is record + CPOL : SPI_CONFIG_CPOL; + end record with + Size => 1; + + type SPI_Enable is (Disabled, Enabled) with + Size => 4; + + for SPI_Enable use (Disabled => 0, + Enabled => 1;) + + type Reg_Enable is record + ENABLE : SPI_Enable; + end record with + Size => 4; + + type PSEL_SCK_Connected is (Connected, Disconnected) with + Size => 32; + + for PSEL_SCK_Connected use (Connected => 0, + Disconnected => 1); + + type Reg_PSEL_SCK is record + CONNECT : PSEL_SCK_Connected; + PIN : GPIO.Pin; + end record with + Size => 32; + + type PSEL_MOSI_Connected is (Connected, Disconnected) with + Size => 32; + + for PSEL_MOSI_Connected use (Connected => 0, + Disconnected => 1); + + type Reg_PSEL_MOSI is record + CONNECT : PSEL_MOSI_Connected; + PIN : GPIO.Pin; + end record with + Size => 32; + + type SPI_TXD_Connected is (Connected, Disconnected) with + Size => 1; + + for SPI_TXD_Connected use (Connected => 0, + Disconnected => 1); + type Reg_SPI_TXD is record + CONNECT : SPI_TXD_Connected; + end record with + Size => 8; + + type SPI_Frequency is (K125,K250, K500, M1, M2, M4, M8) with + Size =>32; + + for SPI_Frequency use (K125 => 16#02000000#, + K250 => 16#04000000#, + K500 => 16#08000000#, + M1 => 16#10000000#, + M2 => 16#20000000#, + M4 => 16#40000000#, + M8 => 16#80000000#); + + type Reg_SPI_Frequency is record + FREQUENCY : SPI_Frequency; + end record with + Size => 32; + +end Spi;