71
eCos for SAM9G20 eCos O.S. for Atmel AT91SAM9G20 and Vulcano G20 Perbellini Giovanni, EDALab

eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos for SAM9G20

eCos O.S. for Atmel AT91SAM9G20 and

Vulcano G20

Perbellini Giovanni, EDALab

Page 2: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Agenda

• eCos introduction

– Overview

– O.S. cross-compilation

• configtool

• ecosconfig

• Example: Helloworld

– Download in Vulcano G20 RAM

• Example: PIO

– Download in Vulcano G20 NAND FLASH

• Adding new eCos device driver

– Fake counter example

– eCos configuration modification

• eCos cross-compilation (configtool and ecosconfig)

• Example: using the new eCos counter device driver

• Conclusions

– Advantages of eCos O.S.

2

Page 3: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Vulcano G20 – Metodo2

• Atmel ARM9 AT91SAM9G20 400Mhz

• Up to 64 MBytes of SDRAM

• 64M/256M/1G/2G bytes of NAND

• Up to 8 MBytes serial DataFlash

• Up to 128 KBytes TWI serial EEPROM

• 128 KBytes SRAM + battery backup

• one PHY Ethernet 100-base TX

• two USB 2.0 Full Speed Host

• one USB 2.0 Full Speed Device

• expansion connectors

• Boot from NAND Flash

• JFFS2 on NAND Flash

3

Serial ports

USB device USB host Ethernet JTAG SD card

Reset

Expansion

connector

Power

Supply

Audio Int.

USB device

http://vulcano-g20.metodo2.it/ http://www.edalab.it/index.php/it/soluzioni/13?tab=1

Page 4: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos introduction (I)

• Embedded Real-Time operating system(open source - GPL license) – http://ecos.sourceware.org

• Implemented for reduced resources devices – Memory, CPU, LCD

• Run on different architecture – ARM, MIPS, PowerPC, etc.

• HW devices support

– serial devices, ethernet controllers, FLASH memory,

etc.

Page 5: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos introduction (II)

• eCos 3.0 – Porting for new architecture

• e.g., Cortex-M4 (Freescale Kinetis), STM32 (STM32F4-Discovery), ARM7 (LPC2294)

– Device driver infrastructure:

• e.g., CAN, I2C, SPI, framebuffer, etc.

– Enhanced Flash infrastructure (flash v2)

– FAT filesystem and Journalling Flash File System version 2 (JFFS2)

– TCP/IP stack improvment • lightweight IP (lwIP) protocol: IPv6 stack

– USB driver (USB device)

– Cross-compilation tools: eCos configtool (for Linux e Windows)

Page 6: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos SW layer architecture

Target Hardware

[e.g., ARM, MIPS; x86, …]

Boot Loader

[RedBoot, Uboot]

Hardware Abstraction Layer (HAL)

[Processor, Interrupt, Exceptions,...]

Decice drivers

[serial, usb, ethernet, …]

Libraries

[C, Math, NewLib, …] Kernel

Support

[Networking stack, File System, …]

Applications

Target independent

Target specific

Page 7: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos –HAL

• Hardware Abstraction Layer (HAL)

• Abstracts hardware-specific implementations

(architecture and platform) for the same API call

– A software layer which encapsulates the specific hardware

operations

• Implements Processor Family (ARM9) and Processor

specific (AT91SAM9263 or AT91SAM9G20)

• Implemented in C and assembly language

• Processors simulator (Hitachi 8, PowerPc, etc.)

Page 8: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos – Kernel (I)

• The eCos kernel is implemented in C++

• Provides the functionality to develop multi-threaded

applications and expected in an RTOS

– The ability to create new threads in the system.

– Control over the various threads in the system, for example

manipulating their priorities.

– A choice of schedulers, determining which thread should

currently be running.

– A range of synchronization primitives, allowing threads to

interact and share data safely.

– Integration with the system's support for interrupts and

exceptions.

Page 9: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos – Kernel (II)

• cyg_start()

– infra/current/src/startup.cxx

• cyg_prestart()

– overwritten by the user

• cyg_package_start()

– init package before main user application

– e.g., ISO standard C library

• cyg_user_start

– used to perform any application-specific initialization

– create threads, create synchronization primitives,

setting up alarms, and register any necessary interrupt

handlers

– main() if ISO standard C library is included

HAL startup

cyg_start

cyg_prestart

cyg_package_start

cyg_user_start

START scheduler

Page 10: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos – Thread and synchronization

• Thread – cyg_thread_create : Creates a thread in a suspended state

– cyg_thread_resume : Causes a thread to continue execution

– cyg_thread_suspend : Postpones the execution of a thread

• Mechanisms for thread communication and synchronize access to

shared resources

– Mutex • cyg_mutex_init : Initialize a mutex in the unlocked state

• cyg_mutex_lock : Changes the state of a mutex to the locked state

• cyg_mutex_unlock : Allows the owner of a mutex to change the state to unlocked

– Semaphores • cyg_semaphore_init : Initializes a semaphore with a count value specified in the val

parameter

• cyg_semaphore_wait : wait for the semaphore.

• cyg_semaphore_post : Increment the semaphore count. If a thread is waiting on the

specified semaphore, it is awakened

Page 11: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos - Networking support

• OpenBSD and FreeBSD implementation

– IPv4, IPv6 (including UDP)

– TCP, UDP

– ICMP

– BOOTP/DHCP

– TFTP

– raw packet interface

• Common O.S. API – init_all_network_interfaces : interface[s] using

BOOTP/DHCP

Page 12: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Architecture

• ARM7 and ARM9 (Vulcano G20 and AT91SAM9263)

• CalmRISC

• Cortex-M

• FR-V

• FR30

• H8

• IA32

• 68K/ColdFire

• Matsushita AM3x

• MIPS

• NEC V8xx

• PowerPC

• SPARC

• SuperH

12

Page 13: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Repository eCos

…/ecos

<complete_ecos_build_tree>

/packages

ecos.db

/kernel

/devs

/hal

/arch1

/arch2

/…

/io

/net

Page 14: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Integrated Development Environment

• Eclipse-based IDE

• Toolchain ARM for AT91SAM9G20

• Compilation

– eCos + Application

• Download binary

• Application debug

14

Page 15: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

IDE: software

• Eclipse IDE for C/C++ Developers Indigo version

• Terminal to connect to serial port (e.g., Eclipse

Plug-in or Putty)

• Toolchain yagarto

• OpenOCD 0.4.0: installed in the following path

“C:\OpenOCD\0.4.0”

15

Page 16: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

IDE: software

• eCos

– O.S. sources repository (/opt/ecos)

– tools: configtool and ecosconfig (/opt/ecos/tools/bin)

– Cygwin (Linux environment emulator on Windows

O.S.): allows to compile eCos O.S. by using GNU

toolchain throught Configtool (/opt/ecos/gnutools)

– Examples repository (/opt/work/example)

– Working directory containing O.S. eCos image

(/opt/work/…)

16

Page 17: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

ARM GNU Yagarto Toolchain

• GNU binary utilities – GNU assembler (as) and GNU linker (ld)

• GNU compiler collection core – C compiler (gcc)

• GNU compiler collection g++ – C++ compiler (g++)

• Newlib – C library for embedded systems

• Insight or GDB – GNU debugger

Page 18: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos Configuration tool (I)

– Select target

architecture

– Select eCos

repository

– Linux/Windows

version

Configuration

Short Description

Property

Page 19: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos Configuration tool (II)

Page 20: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos Configuration tool (III)

• Configuration Window – Select the

packges/components to configure the O.S.

• Conflicts Window – Shows the conflit

generated by selecting the packages

Page 21: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos Configuration tool (IV)

• Output Window – Show the cross-compilation results

• Properties Window – Show the item properties

• Short description Window – Show the item properties dscription

Page 22: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Compilazione eCos – configtool (I)

• Repository

– eCos sources

• Select: Build →

Repository

• Toolchain

– Build tool (compiler, linker,

etc.)

• Select: Tools → Paths

→ Build Tools

– User tool (cat, ls, etc.)

• Select: Tools → Paths

→ User Tools

Page 23: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

• Templates

– HW selection to generate eCos O.S. (Atmel

AT91SAM9G20-EK evaluation board, PowePC,

MIPS, etc.)

• Select: Build → Templates

– Sometimes conflicts can be

generated

• Automatic resolution

Compilazione eCos – configtool (II)

Page 24: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

• eCos configuration generation

– Cross-compilation

• Select: Build → Library

– Output Window shows compilation results

– Save configuration file (e.g. vulcanoG20-

default.ecc)

• Otherwise before to run the compilation select: File → Save

Compilazione eCos – configtool (III)

Page 25: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

• eCos configuration generation

– “build” directory

• Generated files: makefile, object files, etc.

• e.g. vulcanoG20-default_build

– “install” directory

• Contains the O.S. image for the application desing

(library libtarget.a and header files)

• e.g. vulcanoG20-default_install

Compilazione eCos – configtool (IV)

Page 26: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos – ecosconfig (I)

• Set environment: – PATH

$ PATH=/opt/gnutools/arm-eabi/bin:/opt/ecos/tools/bin:$PATH

$ export PATH

– ECOS_REPOSITORY

$ ECOS_REPOSITORY=/opt/ecos/packages

$ export ECOS_REPOSITORY

• Create the work directory

$ mkdir /tmp/user/ecos/work-powerpc

$ cd /tmp/user/ecos/work-powerpc

Page 27: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

• ecosconfig Help

– $ ecosconfig --help

• Create the new target (e.g.: Vulcano G20)

– $ ecosconfig new <target>

– For Vulcano G20 Target <target> = at91_at91sam9g20ek

• Build directory to put the compilation file – $ ecosconfig tree

• eCos cross-compilation – $ make

eCos – ecosconfig (II)

Page 28: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

How to create the

first eCos

application…

28

Page 29: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Example: Helloworld (I)

• Create a new “Makefile project with

existing code”

29

Page 30: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Example: Helloworld (II)

INSTALL_DIR=../../vulcanoG20-default_install

include $(INSTALL_DIR)/include/pkgconf/ecos.mak

ECOS_COMMAND_PREFIX = arm-none-eabi-

XCC = $(ECOS_COMMAND_PREFIX)gcc

XCXX = $(XCC)

XLD = $(XCC)

OBJCOPY = $(ECOS_COMMAND_PREFIX)objcopy

CFLAGS = -I$(INSTALL_DIR)/include

CXXFLAGS = $(CFLAGS)

LDFLAGS = -nostartfiles -L$(INSTALL_DIR)/lib -Ttarget.ld

OBJS = $(SRCS:%.c=%.o)

# RULES

.PHONY: all clean

all: Helloworld

clean:

-rm -f \

Helloworld Helloworld.bin Helloworld.o \

%.o: %.c

$(XCC) -c -o $*.o $(CFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

%.o: %.cxx

$(XCXX) -c -o $*.o $(CXXFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

%.o: %.C

$(XCXX) -c -o $*.o $(CXXFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

%.o: %.cc

$(XCXX) -c -o $*.o $(CXXFLAGS) $(ECOS_GLOBAL_CFLAGS) $<

Helloworld: Helloworld.o

$(XLD) $(LDFLAGS) $(ECOS_GLOBAL_LDFLAGS) -o $@ [email protected]

$(OBJCOPY) -O binary $@ [email protected]

30

Page 31: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Example: Helloworld (III)

• Add new source file .c

• Press right button on “Helloworld” folder and

select “New” option

31

Page 32: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Example: Helloworld (IV)

• Add the source code

#include <cyg/infra/diag.h>

int main(int argc, char** argv) {

diag_printf("\nHello world by EDALab!\n");

return 0;

}

32

Page 33: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Example: Helloworld (V)

• Cross-compilation: press button “Build project”

33

Page 34: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Esecuzione/Debug Helloworld

• Press “Debug” button to open “Debug Configurations”

window and press “New” button to create a new

configuration

• Insert the following properties: – Main -> C/C++ application: application path (example:

C:\cygwin\work\example\Helloworld\Helloworld)

– Debugger -> GDB Command: C:\Progr\yagarto\bin\arm-none-eabi-

gdb.exe

– Debugger -> Host name: 127.0.0.1

– Debugger -> Port Number: 3333

– Startup -> uncheck “reset and delay (seconds)” and “Halt”

– Startup -> in the text editor: “monitor reset init”

– Common -> Check debug

34

Page 35: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Esecuzione/Debug Helloworld

35

Page 36: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

RAM application deploy (Eclipse)

1) Connect jtag and power-on the board

36

2) Press Eclipse

external tools button to

run OpenOCD

3) Press Eclipse Debug Helloworld button

Page 37: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

RAM application deploy (manual)

• Connect jtag and power-on the board

• Open Win7 command prompt

– Run openOCD ()

• openocd.exe -f C:\opt\eclipse\workspace\scripts\olimex-arm-usb-

tiny-h.cfg -f C:\opt\eclipse\workspace\scripts\at91sam9g20-

ek_nand.cfg

• GDB server runs on the PC running openOCD

• Open Win7 command prompt

– Enter into "examples“ directory

– Type the following command to execute the deploy of the application

into the RAM and debug the code

• arm-none-eabi-gdb --command gdb_on_at91sam9_ram

37

Page 38: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

RAM application deploy (manual)

target remote 127.0.0.1:3333

monitor reset init

load hello

file hello

38

Page 39: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Exercise

• Write an application using two threads

• To be used:

– cyg_thread_create

– cyg_thread_resume

39

Page 40: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos PIO example

and deploy in

NAND Flash…

40

Page 41: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Example: PIO Interrupt

• LED light on when a PIO interrupt is generated

• Creation of interrupt service routine

– ISR and DSR

– Interrupt create and attach

• PIO controller

– SET and GET value

41

Page 42: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos: Interrupt

• Interrupt Service Routine (ISR)

– Start when an interrupt HW happens

• Deferred Service Routine (DSR)

– Start after the ISR to manage the interrupt

• eCos O.S. API

– cyg_drv_interrupt_create: Create an interrupt object and

returns a handle to it

– cyg_drv_interrupt_attach: Attach the interrupt to the

vector so that interrupts will be delivered to the ISR when the

interrupt occurs

42

Page 43: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

PIO_INTR code

static cyg_uint32 at91_test_isr (cyg_vector_t vector, cyg_addrword_t data) {

cyg_uint32 pin = *(cyg_uint32 *)data;

at91_pio_disable_intr(pin);

return CYG_ISR_CALL_DSR;

}

static void at91_test_dsr (cyg_vector_t vector, cyg_ucount32 count, cyg_addrword_t data) {

cyg_uint32 pin = *(cyg_uint32 *)data;

if (at91_get_gpio_value(pin))

hal_at91_led_on(AT91_USER_LED1);

else

hal_at91_led_off(AT91_USER_LED1);

at91_pio_enable_intr(pin);

}

43

Page 44: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

PIO_INTR code

at91_set_gpio_input(test_pin, 1);

diag_printf("\nPin %d of PIO controller %d", HAL_ARM_AT91_PIO_NUM(test_pin),

HAL_ARM_AT91_PIO_CTRL(test_pin));

bool value = at91_get_gpio_value(test_pin);

diag_printf("\nInitial value : %d", value);

value ? hal_at91_led_on(AT91_USER_LED1) : hal_at91_led_off(AT91_USER_LED1);

cyg_vector_t vector = AT91_PIO_INTR_PIN(test_pin);

diag_printf("\nInterrupt vector : %d", vector);

cyg_drv_interrupt_create(

vector,

0,

(cyg_addrword_t)&test_pin,

at91_test_isr,

at91_test_dsr,

&intr_handle,

&intr);

cyg_drv_interrupt_attach(intr_handle);

at91_pio_enable_intr(test_pin);

44

Page 45: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos O.S. compilation

• Enable option:

“Handle interrupt from PIO”

45

Page 46: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

AT91SAM9G20 eCos boot sequence

46

AT91bootstrap

AT91bootstrap

ROM

NAND flash SDRAM

SRAM

eCos kernel

File system JFFS2

eCos kernel

ROM CODE

(Boot Media=NAND)

1

2

3

4

Page 47: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

AT91SAM9G20 eCos boot sequence

47

AT91bootstrap

NAND flash

eCos kernel

(APP)

File system

(JFFS2)

0x0

0x20000

0x400000

Page 48: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

NAND Flash deploy

• Connect jtag and board power-on

• Open Win7 command prompt

– Run openOCD

• openocd.exe -f C:\opt\eclipse\workspace\scripts\olimex-arm-

usb-tiny-h.cfg -f

C:\opt\eclipse\workspace\scripts\at91sam9g20-ek_nand.cfg

• GDB server runs on the PC running openOCD

• Open Win7 command prompt

– Enter into "examples“ directory

– Type the following command to execute the deploy of the binary

and the bootstrap into the NAND Flash

• arm-none-eabi-gdb --command gdb_on_at91sam_flash

48

Page 49: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

NAND Flash deploy

target remote 127.0.0.1:3333

monitor reset init

monitor nand raw_access 0 enable

monitor nand erase 0 0 0x100000

monitor nand raw_access 0 disable

monitor sleep 500

monitor reset init

monitor sleep 500

monitor nand write 0 "C:/cygwin/opt/work/example/Helloworld/nandflash_VulcanoG20.bin" 0

monitor sleep 500

monitor nand verify 0 "C:/cygwin/opt/work/example/Helloworld/nandflash_VulcanoG20.bin" 0

monitor nand write 0 "C:/cygwin/opt/work/example/PIO/pio_intr.bin" 0x20000

monitor sleep 500

monitor nand verify 0 "C:/cygwin/opt/work/example/PIO/pio_intr.bin" 0x20000

monitor reset

monitor shutdown

kill

quit

49

Page 50: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Vulcano G20 J14

50

Page 51: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Exercise

• Create the binary PIO application by using

the eCos O.S. image generated with

ecosconfig

– Change the ecos.cc to insert the PIO intr

management option

– Change PIO Makefile

51

Page 52: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Adding new

eCos device driver…

52

Page 53: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos repository modification (I)

• Packages/devs …/ecos

<complete_ecos_build_tree>

/packages

/devs

/counter

/arm

/at91 /v3_0b1

/cdl

/include

/src

53

Page 54: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos repository modification (II)

• cdl: directory containing .cdl file to

configure eCos (used by configtool)

• include: directory containing device

driver headers file

• src: directory containing device driver

sources file

54

Page 55: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

CDL - Component definition language

• cdl_package

– Units of the software distribution

• cdl_option

– corresponds to a single user choice

• cdl_component

– is a configuration option that can contain additional

options and sub-components

• cdl_interface

– a calculated configuration option that provides an

abstraction mechanism

55

Page 56: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

CDL - Component definition language

cdl_package PACKAGE_NAME {

<package properties and commands>

cdl_component COMPONENT_NAME {

<component properties and commands>

}

cdl_option OPTION_NAME {

<option properties and commands>

}

}

56

Page 57: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Counter CDL file (I)

• Fake counter package

cdl_package CYGPKG_DEVS_COUNTER_FAKE {

display "Workshop eCos COUNTER support" parent CYGPKG_IO

include_dir cyg/devs

description "FAKE COUNTER device support for Workshop"

compile -library=libextras.a counter_drv.c

}

57

Page 58: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Counter CDL file (II)

• Inside cdl_package

cdl_option CYGDEVS_FAKE_COUNTER_MODE {

display "Counter mode"

flavor data

legal_values { "random_get" "set_get" } default_value { "random_get" }

description "The fake counter driver can be used in one of two modes. Random counter starts from random value. Set counter starts from zero value can be set by the user.“

}

58

Page 59: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Counter CDL file (III)

• Flavor: specify the nature of a configuration option – None: placeholder

• e.g., #define CYGDEVS_FAKE_COUNTER_MODE 1

– Bool: enable o disable (generating or not the #define)

– Data: legal values associated with define • #define CYGDEVS_FAKE_COUNTER_MODE set_get

• #define CYGDEVS_FAKE_COUNTER_MODE_set_get

– Booldata: combines boll and data flavors

59

Page 60: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Device driver (I)

#ifndef COUNTER_DRV_H

#define COUNTER_DRV_H

#include <cyg/infra/diag.h>

#include <pkgconf/devs_counter_fake.h>

#include <stdlib.h>

int value;

//Initilization function

void counter_init(void);

void counter_increment(void);

int counter_getValue(void);

#endif /* COUNTER_DRV_H */

60

Page 61: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Device driver (II) #include <cyg/devs/counter_drv.h>

void counter_init(){

#if (defined(CYDEVS_FAKE_COUNTER_MODE_set_get))

value=0;

#endif

#if (defined(CYDEVS_FAKE_COUNTER_MODE_random_get))

value = rand();

#endif

diag_printf("counter_driver::INIT Function -> value = %d\n", value);

}

void counter_increment(){

diag_printf("counter_driver::START Function\n");

value++;

}

int counter_getValue(){

diag_printf("counter_driver::GET VALUE Function\n");

return value;

}

61

Page 62: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos DB configuration (I)

1. Add new eCos package representing the device driver

2. Add new eCos target

– Select template by using the ecosconfig or configtool

• Modify the following file – ecos.db inside ecos/package

62

Page 63: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos DB configuration (II)

1. Add new package

package CYGPKG_DEVS_COUNTER_FAKE {

alias {"FAKE Counter support"}

directory devs/counter/arm/at91

script counter.cdl

hardware

description "COUNTER device support for Workshop"

}

63

Page 64: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

eCos DB configuration (III)

2. Aggiunta nuovo eCos target

target at91sam9g20ek-workshop {

alias {

"Atmel VulcanoG20-Workshop" vulcanoG20_workshop

}

packages {

CYGPKG_HAL_ARM

CYGPKG_HAL_ARM_ARM9

CYGPKG_HAL_ARM_AT91

CYGPKG_HAL_ARM_AT91SAM9

CYGPKG_HAL_ARM_AT91SAM9G20EK

CYGPKG_IO_SERIAL_ARM_AT91

CYGPKG_DEVS_COUNTER_FAKE

}

64

Page 65: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Cross-compilation eCos (I)

• Repository – eCos source anche configuration file

• Select: Build → Repository

• Toolchain – Build tool (compiler, linker, etc.)

• Select: Tool → Paths → Build Tools

– User tool (cat, ls, etc.) • Select: Build → Paths → User Tools

65

Page 66: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Cross-compilation eCos (II)

• Templates – Select:

Build → Templates

– vulcanoG20_workshop

• eCos configuration generation – Select: Build → Library

66

Page 67: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Example: using the fake counter

device driver #include <cyg/infra/diag.h>

#include <cyg/devs/counter_drv.h>

int main(void) {

int i;

diag_printf("Counter Application...!\n");

counter_init();

for (i=0; i<5; i++)

counter_increment();

diag_printf("Value=%d\n",counter_getValue());

return 0;

}

67

Page 68: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Example: using the fake counter

device driver

• Create a new “Makefile project with

existing code”

68

Page 69: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Esecuzione/Debug Counter

• Press “Debug” button to open “Debug Configurations”

window and press “New” button to create a new

configuration

• Insert the following properties: – Main -> C/C++ application: application path (example:

C:\cygwin\opt\work\example\Counter\Counter)

– Debugger -> GDB Command: C:\Progr\yagarto\bin\arm-none-eabi-

gdb.exe

– Debugger -> Port Number: 3333

– Startup -> uncheck “reset and delay (seconds)” and “Halt”

– Startup -> in the text editor: “monitor reset init”

– Common -> Check debug

69

Page 70: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Exercise

• eCos cross-compilation changing the fake counter value

• Change “counter mode” flavor (data vs. bool)

70

Page 71: eCos for SAM9G20profs.scienze.univr.it/~perbellini/LabSOA/1-2-3-4... · 2015. 10. 9. · eCos – Kernel (I) • The eCos kernel is implemented in C++ • Provides the functionality

Vulcano G20 + eCos

• Open source RTOS

– Support real-time scheduling, pre-emptible kernel, interrupt handling

mechanisms needed for real-time applications

• Highly configurable to be customised to precise application requirements

– Device drivers, scheduler, libraries

• Component architecture

– Allow to extend functionality of eCos

• Fast boot time (2 sec.)

• Making GPIO programming easy

• Optimised hardware resource footprint

– Kernel footprint

• Minimal 50KB (Linux minimal = 2MB)

• eCos Vulcano G20 Full Version = 350 KB

– File system footprint

• Application dependent

71