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 a7b93e8
Show file tree
Hide file tree
Showing 2 changed files with 186 additions and 47 deletions.
69 changes: 65 additions & 4 deletions src/core/nRF52832/spi.adb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ is
Import,
Address => SSE.To_Address (Base + 16#500#);

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

Expand All @@ -22,14 +22,75 @@ 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#51C#);
Address => SSE.To_Address (Base + 16#010#);

SPI_FREQUENCY : Reg_SPI_Frequency with
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#14C#);

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

EVENT_Ready : Reg_EVENT_Ready with
Import,
Address => SSE.To_Address (Base + 16#108#);

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_Integer (Base + 16#54C#);

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

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

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


procedure Initialize is
begin
ENABLE := (ENABLE => Disabled);
Expand Down
164 changes: 121 additions & 43 deletions src/core/nRF52832/spi.ads
Original file line number Diff line number Diff line change
@@ -1,83 +1,161 @@
with Componolit.Runtime.Drivers.GPIO;

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,

for SPIM_CONFIG_CPOL use (ActiveHIGH => 0,
ActiveLOW => 1);
type Reg_SPI_CONFIG_CPOL is record
CPOL : SPI_CONFIG_CPOL;

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

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;


for Reg_Enable use record
ENABLE at range 4 at 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 => 8;

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

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 => 8;

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

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 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 SPI_TXD_Connected is (Connected, Disconnected) with
type Reg_SPIM_Frequency is record
FREQUENCY : SPIM_Frequency;
end record with
Size => 32;

-- for enabling shortcuts
type SPIM_END_START is (Enabled, Disabled) 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 (Enabled => 1,
Disabled => 0);

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 => 1;

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 a7b93e8

Please sign in to comment.