Skip to content
This repository has been archived by the owner on May 22, 2023. It is now read-only.

Commit

Permalink
Update from SPI to SPIM
Browse files Browse the repository at this point in the history
ref #187
  • Loading branch information
Isabell Zorr committed Jul 1, 2020
1 parent 45987aa commit feedec1
Show file tree
Hide file tree
Showing 3 changed files with 225 additions and 58 deletions.
2 changes: 2 additions & 0 deletions src/core/nRF52832/main.adb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
with Gneiss;
with Serial;
with Componolit.Runtime.Drivers.GPIO;
with Spi;

procedure Main with
SPARK_Mode
Expand All @@ -15,6 +16,7 @@ is
return S & ASCII.CR & ASCII.LF;
end F;
begin
Spi.Initialize;
GPIO.Configure (18, GPIO.Port_Out);
GPIO.Write (18, GPIO.Low);
Serial.Initialize;
Expand Down
93 changes: 85 additions & 8 deletions src/core/nRF52832/spi.adb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
with System.Storage_Elements;

package body Spi with
SPARK_Mode
is
Expand All @@ -10,7 +12,7 @@ is
Import,
Address => SSE.To_Address (Base + 16#500#);

SPI_CONFIG_CPOL : Reg_SPI_CONFIG_CPOL with
CONFIG_CPOL : Reg_SPIM_CONFIG_CPOL with
Import,
Address => SSE.To_Address (Base + 16#554#);

Expand All @@ -22,27 +24,102 @@ is
Import,
Address => SSE.To_Address (Base + 16#50C#);

SPI_TXD : Reg_SPI_TXD with
TASK_START : Reg_TASK with
Import,
Address => SSE.To_Address (Base + 16#010#);

TASK_STOP : Reg_TASK with
Import,
Address => SSE.To_Address (Base + 16#014#);

TASK_SUSPEND : Reg_TASK with
Import,
Address => SSE.To_Address (Base + 16#01C#);

TASK_RESUME : Reg_TASK with
Import,
Address => SSE.To_Address (Base + 16#020#);

EVENT_STOPPED : Reg_EVENT with
Import,
Address => SSE.To_Address (Base + 16#104#);

EVENT_ENDRX : Reg_EVENT with
Import,
Address => SSE.To_Address (Base + 16#110#);

EVENT_END : Reg_EVENT with
Import,
Address => SSE.To_Address (Base + 16#118#);

EVENT_ENDTX : Reg_EVENT with
Import,
Address => SSE.To_Address (Base + 16#120#);

EVENT_STARTED : Reg_EVENT with
Import,
Address => SSE.To_Address (Base + 16#51C#);
Address => SSE.To_Address (Base + 16#14C#);

SPI_FREQUENCY : Reg_SPI_Frequency with
FREQUENCY : Reg_SPIM_Frequency with
Import,
Address => SSE.To_Address (Base + 16#524#);

TXD_PTR : Reg_TXD_PTR with
Import,
Address => SSE.To_Address (Base + 16#544#);

TXD_MAXCNT : Reg_TXD_MAXCNT with
Import,
Address => SSE.To_Address (Base + 16#548#);

TXD_AMOUNT : Reg_TXD_AMOUNT with
Import,
Address => SSE.To_Address (Base + 16#54C#);

RXD_PTR : Reg_RXD_PTR with
Import,
Address => SSE.To_Address (Base + 16#534#);

RXD_MAXCNT : Reg_RXD_MAXCNT with
Import,
Address => SSE.To_Address (Base + 16#538#);

RXD_AMOUNT : Reg_RXD_AMOUNT with
Import,
Address => SSE.To_Address (Base + 16#53C#);

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);
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);
CONFIG_CPOL := (CPOL => ActiveHIGH);
FREQUENCY := (FREQUENCY => M8);
ENABLE := (ENABLE => Enabled);
end Initialize;

procedure Send (B : Buffer) is
begin
TXD_PTR := (PTR => B'Address);
TXD_MAXCNT := (MAXCNT => B'Length);
TASK_START := (TSK => Trigger);
for I in B'Range loop
while EVENT_ENDTX.EVENT = Clear loop
pragma Inspection_Point (EVENT_ENDTX);
exit when TXD_AMOUNT.AMOUNT = TXD_MAXCNT.MAXCNT;
end loop;
EVENT_ENDTX.EVENT := Clear;
end loop;
TASK_STOP := (TSK => Trigger);
end Send;

procedure Receive is
begin
null;
end Receive;

end Spi;
188 changes: 138 additions & 50 deletions src/core/nRF52832/spi.ads
Original file line number Diff line number Diff line change
@@ -1,83 +1,171 @@
with Componolit.Runtime.Drivers.GPIO;
with System;

package Spi with
SPARK_Mode
SPARK_Mode
is
package GPIO renames Componolit.Runtime.Drivers.GPIO;

procedure Initialize;


procedure Receive;

generic
type Byte is (<>);
type Index is range <>;
type Buffer is array (Index range <>) of Byte;

procedure Send (B : Buffer);

private
type SPI_CONFIG_CPOL is (ActiveHIGH, ActiveLOW) with

type SPIM_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;

for SPIM_CONFIG_CPOL use (ActiveHIGH => 0,
ActiveLOW => 1);

type Reg_SPIM_CONFIG_CPOL is record
CPOL : SPIM_CONFIG_CPOL;
end record with
Size => 1;
type SPI_Enable is (Disabled, Enabled) with
Size => 32;

type SPIM_Enable is (Disabled, Enabled) with
Size => 4;
for SPI_Enable use (Disabled => 0,
Enabled => 1;)

for SPIM_Enable use (Disabled => 0,
Enabled => 7);

type Reg_Enable is record
ENABLE : SPI_Enable;
ENABLE : SPIM_Enable;
end record with
Size => 4;

Size => 32;

for Reg_Enable use record
ENABLE at 0 range 0 .. 3;
end record;

type Reg_TXD_PTR is record
PTR : System.Address;
end record with
Size => 32;

type Count is range 0 .. 255 with
Size => 8;

type Reg_TXD_MAXCNT is record
MAXCNT : Count;
end record with
Size => 32;

type Reg_TXD_AMOUNT is record
AMOUNT : Count;
end record with
Size => 32;

type Reg_RXD_PTR is record
PTR : System.Address;
end record with
Size => 32;

type Reg_RXD_MAXCNT is record
MAXCNT : Count;
end record with
Size => 32;

type Reg_RXD_AMOUNT is record
AMOUNG : Count;
end record with
Size => 32;

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;
PIN : GPIO.Pin;
end record with
Size => 32;


for Reg_PSEL_SCK use record
CONNECT at 0 range 31 .. 31;
PIN at 0 range 0 .. 4;
end record;

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;
PIN : GPIO.Pin;
end record with
Size => 32;

type SPI_TXD_Connected is (Connected, Disconnected) with

for Reg_PSEL_MOSI use record
CONNECT at 0 range 31 .. 31;
PIN at 0 range 0 .. 4;
end record;

type SPIM_Frequency is (K125, K250, K500, M1, M2, M4, M8) with
Size => 32;

for SPIM_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_SPIM_Frequency is record
FREQUENCY : SPIM_Frequency;
end record with
Size => 32;

-- for enabling shortcuts
type SPIM_END_START is (Disabled, Enabled) with
Size => 1;

for SPI_TXD_Connected use (Connected => 0,
Disconnected => 1);
type Reg_SPI_TXD is record
CONNECT : SPI_TXD_Connected;

for SPIM_END_START use (Disabled => 0,
Enabled => 1);

type Reg_END_START is record
ENABLED : SPIM_END_START;
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;
Size => 32;

type EVENT_Event is (Clear, Set) with
Size => 1;

for EVENT_Event use (Clear => 0,
Set => 1);

type Reg_EVENT is record
EVENT : EVENT_Event;
end record with
Size => 32;
Size => 32;

for Reg_EVENT use record
EVENT at 0 range 0 .. 0;
end record;

type TASK_Trigger is (Trigger) with
Size => 1;

for TASK_Trigger use (Trigger => 1);

type Reg_TASK is record
TSK : TASK_Trigger;
end record with
Size => 32;

for Reg_TASK use record
TSK at 0 range 0 .. 0;
end record;
end Spi;

0 comments on commit feedec1

Please sign in to comment.