Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access to volatile register in Ada

Tags:

ada

gnat

I want to write a very simple driver to initialize, write to/read from some peripherals on a microcontroller, the same way I have done it in C. I am using as an example a GPIO peripheral to initialize, write and read.

GPIOA : GPIO_Register with
   Volatile,
   Address => System'To_Address (GPIOA_Base);
   pragma Import (Ada, GPIOA);

If I declare a list to access all the GPIOs:

 type GPIO_Register_ptr is access all GPIO_Register with volatile;

 Gpio_List_Pointers : array (Integer range 1 .. 8) of aliased GPIO_Register_ptr;

And then assign:

  Gpio_List_Pointers(1) := GPIOA'Access;

I get the error :

  142:29 prefix of "ACCESS" attribute must be aliased

Any ideas how to sort it out ?

like image 977
Elisabeth Avatar asked Feb 10 '15 15:02

Elisabeth


1 Answers

The short answer is:

declare GPIOA as aliased, like this:

GPIOA : aliased GPIO_Register 

EDIT:

A bit longer answer:

GPIOA is declared like this:

GPIOA : aliased GPIO_Register with
   Volatile,
   Address => System'To_Address (GPIOA_Base);

This means that it is a volatile object. The type of the object is still GPIO_Register, which is not volatile. So, when you do

 Gpio_List_Pointers(1) := GPIOA'Access;

The 'Access returns an access to an object of type GPIO_Register, which is not volatile, and the compiler won't let you do that.

To make this legal, GPIO_Register needs to be a volatile type. This is done by changing the type definition to include an aspect specification:

type GPIO_Register is record 
   MODER : Bits_16x2;
   IDR : Word;
   ODR : Word; 
end record
   with Volatile;

Now we have a volatile type, not just a volatile object

like image 176
egilhh Avatar answered Oct 13 '22 10:10

egilhh