Hal Embedded
Hal Embedded
Lukasz Krzak
Department od Electronics,
Faculty of Computer Science, Electronics and Telecommunications
AGH University of Science and Technology in Kraków
lukasz.krzak@agh.edu.pl
www.wsn.agh.edu.pl
Outline
2
How the story began...
3
Wireless Sensor and Control Networks Laboratory
● Wireless communications (hardware and software)
● Embedded systems
● Electromagnetic compatibility
5
Important qualities of embedded software
6
Important qualities of embedded software
AKA: How to distinguish good code from bad code
A good code:
● is feature-rich
7
Important qualities of embedded software
reusable
speeds up the development
(off-the shelf components)
increases reliability
(more applications, more confidence)
embedded
software
simple feature-rich
8
reusable == portable
9
Reusable == portable
because
changes
sucks!
13
AUTOSAR (AUTomotive Open System Architecture)
“Cooperate on standards,compete on implementation”
source: www.autosar.org
14
CMSIS (Cortex Microcontroller Software Interface Standard)
source: www.arm.com
15
Arduino
source: http://arduino.cc/
16
Why reinvent the wheel? We have C stdlib!
#include <stdio.h>
Standard C library is already
portable (same with C++/STL)
It supports I/O operations
int main(void) Works in embedded world too!
{ Focused on batch processing and
text communication
printf(“Hello World!”); Lack of support for multithreaded
applications
return 0; Lack of support for real-time
Usually leads to large code
}
MISRA says: no!
17
Component based software architecture
18
Component-based architecture
Communication
LCD driver
port driver
Hardware
19
How to design reusable/portable code?
My Precious Code
20
Important design choices
Applications
My Precious Code
21
Important design choices
Applications
My Precious Code
Hardware
22
Important design choices
Applications
My Precious Code
RTOS
Hardware (Really Tricky
Operating System)
23
Important design choices
Applications
RTOS
Hardware (Really Tricky
Operating System)
24
Important design choices
Toolchain
Applications
(Complainer etc)
RTOS
Hardware (Really Tricky
Operating System)
25
Important design choices
Toolchain
Applications
(Complainer etc)
RTOS
Hardware (Really Tricky
Operating System)
26
How to design reusable software?
Application code
Defines usability
Component code
Defines portability
Hardware RTOS
27
How to design reusable software?
Application code
“egocentric” approach
Component code
HW glue OS glue
Hardware RTOS
28
How to design reusable software?
Application code
“egocentric” approach
Component code Component code multiplied
Hardware RTOS
29
Towards abstraction...
Application code
HW/OS
HW interface RTOS interface abstraction
layer
Hardware RTOS
30
Hardware Abstraction Layer (HAL)
31
Bad reputation: HAL 9000
32
Consequences of having HAL
HW/OS-dependent code
(changes with hardware or operating
system used -in ex. peripheral drivers)
Hardware RTOS
33
Advantages of HAL: switching HW/OS
Hardware RTOS
(AT91SAM3S)
(STM32) (FreeRTOS)
(uC/OS-II)
34
Advantages of HAL: cross-development
Hardware RTOS
OS
(STM32)
(PC) (Windows/Linux)
(FreeRTOS)
35
Advantages of HAL: less effort == less bugs
Effort ~ number of errors
coding
architecture testing
requirement
analysis
time
deadline !
coding
requirement testing
architecture
analysis
time
deadline !
36
Advantages of HAL: cross platform testing
We can reuse the software across platfroms to enable communication between them.
This is useful for both the application development and testing.
software
test case software
under test
communication communication
Embedded hardware PC
37
Advantages of HAL: automated unit testing
38
Disadvantages of HAL – major concerns
Efficiency.
Our experiments show that handling HAL abstraction can have little or no overhead
compared to chip vendor libraries. We try to follow the “only pay for what you use”
paradigm. The efficiency depends heavily on the actual realization of HAL interfaces on
the target platform.
39
HALFRED
Hardware Abstraction Layer For Real-time Embedded Designs
www.wsn.agh.edu.pl/halfred
40
HALFRED wishlist
41
HALFRED current modules
www.wsn.agh.edu.pl/halfred
42
Design process example
(GPIO module)
43
HALFRED design process
44
STEP1: Analyze representative microcontrolers
STM32F1
45
STEP1: Analyze representative microcontrolers
EFM32LG
46
STEP2: Identify abstract model
output state
register (0/1)
OD/PP
peripherals
(USART, SPI etc.)
PORT.PIN
input state
register (0/1)
configuration
interrupts
register
47
STEP3: Design and generate interfaces
48
STEP4: Write test case
main.c
void testGPIO(void)
{
int i;
49
STEP5: Implement and test
hal_config.h
#define TEST_PIN_PORT GPIOC
#define TEST_PIN_PIN 13
#define TEST_PIN_DEFAULT_CONFIG GPIO_Mode_Out_PP
50
Results
51
What we've done so far
52
Supported hardware / OS / toolchain
FreeRTOS
uC/OS-II
Linux (posix)
Windows (win32 api)
53
Feedback from our initial project
54
(not so) Unexpected outcomes
55
Emulating and developing distributed systems
Application code
Component code
HALFRED
OMNeT++
56
Emulating and developing distributed systems
Application code
Component code
HALFRED
EFM32
57
The future
58
Current design choices
Switch to C++11.
59
Vendor libraries independency
Vendor libraries
HALFRED
Hardware RTOS
60
We need your help!
61