25

AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

Embed Size (px)

Citation preview

Page 1: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library
Page 2: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

Senior Software Engineer

Making the Ada Drivers Library

Fabien Chouteau

Page 3: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library
Page 4: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

Ada & Device Drivers:A Well-Engineered Collaboration

Ada’s strong typing systemencourages communication and demands precision

Representation clausesare the killer feature for coding drivers

Contract-based programminghelps eliminate problems earlier in the development cycle

Object-oriented featurescan improve code reuse

Multitasking support is available for bare metal platforms

Page 5: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

We wanted to experiment.

So, we started this project as a proof of concept to explore whether this was demonstrable with modern ARM

microcontrollers.

We wanted to use the best features of Ada to provide:

• clean hardware mapping,

• good interfaces,

• code reuse, and

• easy debugging.

Page 6: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

What did we learn?

• Modern microcontrollers are gigantic beasts.

• Accessing memory mapped register can be tricky (pragma Volatile_Full_Access).

• Customization of run-times is still not flexible enough.

• Confirmed that Ada had good properties for programming device drivers.

Page 7: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

Representation clauses

GPIO->MODER &= ~(GPIO_MODER_MODER0 << (pin_nbr* 2));

VS

GPIO.MODER.Arr (Pin_Nbr) := 0;

Page 8: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

package STM32_SVD.RNG ispragma Preelaborate;

----------------- Registers -----------------

-- control registertype CR_Register is record

-- unspecifiedReserved_0_1 : HAL.UInt2 := 16#0#;-- Random number generator enableRNGEN : Boolean := False;-- Interrupt enableIE : Boolean := False;-- unspecifiedReserved_4_31 : HAL.UInt28 := 16#0#;

end recordwith Volatile_Full_Access, Size => 32,

Bit_Order => System.Low_Order_First;

for CR_Register use recordReserved_0_1 at 0 range 0 .. 1;RNGEN at 0 range 2 .. 2;IE at 0 range 3 .. 3;Reserved_4_31 at 0 range 4 .. 31;

end record;

SVD2ada: generating hardware register mapping

Page 9: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

<?xml version="1.0" encoding="utf-8" standalone="no"?><device schemaVersion="1.1"xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"xs:noNamespaceSchemaLocation="CMSIS-SVD_Schema_1_1.xsd"><name>STM32F46_79x</name><version>1.0</version><description>STM32F46_79x</description><!--Bus Interface Properties--><!--Cortex-M4 is byte addressable--><addressUnitBits>8</addressUnitBits><!--the maximum data bit width accessible within a single transfer--><width>32</width><!--Register Default Properties--><size>0x20</size><resetValue>0x0</resetValue><resetMask>0xFFFFFFFF</resetMask><peripherals><peripheral><name>RNG</name><description>Random number generator</description><groupName>RNG</groupName><baseAddress>0x50060800</baseAddress><addressBlock><offset>0x0</offset><size>0x400</size><usage>registers</usage>

</addressBlock><interrupt><name>HASH_RNG</name>

SVD2ada: generating hardware register mapping

Page 10: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

Now what?

Page 11: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

Introducing the Ada_Drivers_Library

An Open Community Project hosted on GitHub

Vendor-independent

Makes it easy to use Ada to do interesting things with a

variety of ARM microcontrollers!

Page 12: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

Ada_Drivers_Library Framework

MCU

HAL

Components

Services

Low-level drivers to interface with peripherals on particular microcontrollers

Ada layer providing clean abstraction of hardware

External components connected to the MCU in a standard way (I2C, UART, SPI, SDIO, MMC, etc.)

OS services (we have a filesystem; on our wishlist is a network stack, USB stack, Bluetooth, etc.)

Page 13: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

What’s in it?

• GPIOs

• I2C, SPI, UART

• ADC, DAC

• Audio (SAI)

• LCD and touch screen drivers

• Timers, PWM

• DMA

• Flexible Memory Controller (external RAM)

• Camera (DCMI)

• Random Number Generator

• SDcard

Page 14: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

On what board?

Page 15: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

Crazyflie 2.0

Page 16: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

OpenMV

Page 17: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

BBC Micro:Bit

Page 18: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

Roadmap

• More boards from more vendors

• More device drivers

• More services (Filesystem, Bluetooth, USB)

•Robotics utilities and drivers

• General purpose control system code

Page 19: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

Making with Ada

Page 20: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

Make with Ada: Candy dispenser, with

a twist

Page 21: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

Make with Ada: DIY Instant

Camera

Page 22: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

Make with Ada: ARM

Cortex-M CNC controller

Page 23: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library
Page 24: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library

More Information Online

• The Ada_Drivers_Libraryhttps://github.com/AdaCore/Ada_Drivers_Library

• Ada Driver Library for ARM Cortex-M/R - Part 1https://community.arm.com/groups/embedded/blog/2016/07/08/ada-driver-library

• MCQ Candy Dispenserhttp://blog.adacore.com/make-with-ada-candy-dispenser-with-twist

• DIY Instant Camerahttps://www.youtube.com/watch?v=MHo5bcHWx3o

• ARM Cortex-M CNC Controllerhttp://blog.adacore.com/make-with-ada-arm-cortex-m-cnc-controller

Page 25: AdaCore Paris Tech Day 2016: Fabien Chouteau - Making the Ada Drivers Library