Uc os ii real time kernel porting on atmega128 and his her applications
Download
1 / 78

uC/OS-II Real Time Kernel Porting on Atmega128 And His/Her Applications - PowerPoint PPT Presentation


  • 1237 Views
  • Updated On :

uC/OS-II Real Time Kernel Porting on Atmega128 And His/Her Applications. Embedded System Design 2004 Fall, Term Project since October 06, 2004 Jongbin Park Sungkyunkwan University Digital Media Lab URL: http://media.skku.ac.kr. Embedded System Design 2004. Project Introduction

Related searches for uC/OS-II Real Time Kernel Porting on Atmega128 And His/Her Applications

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'uC/OS-II Real Time Kernel Porting on Atmega128 And His/Her Applications' - erika


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Uc os ii real time kernel porting on atmega128 and his her applications l.jpg

uC/OS-II Real Time Kernel Porting on Atmega128And His/Her Applications

Embedded System Design 2004 Fall, Term Project

since October 06, 2004

Jongbin Park

Sungkyunkwan University Digital Media Lab

URL: http://media.skku.ac.kr


Embedded system design 2004 l.jpg
Embedded System Design 2004

  • Project Introduction

  • Overview of uC/OS-II

  • Overview of Atmega128

  • The Construction of Development Environment

  • uC/OS-II Porting on Atmega128

  • Development of a Application

  • Project Conclusion

Digital Media Lab 2004


Project objective 1 l.jpg
Project Objective(1)

  • Objective One

    • uC/OS-II Real Time Kernel Porting on Atmega128, which is a 8-bit RISC type Micro controller

  • Objective Two

    • And His Applications

      • (ex) Motor Control  Robot Joint Part

      • (ex) Display on Graphic LCD  Text, BMP, Movie display

      • (ex) uC/OS-II based “Task-Manager” like The MS-windows “Task-Manager”  Current Project

Digital Media Lab 2004


Project objective 2 l.jpg
Project Objective(2)

1. Porting

TaskManger

2. App (motor ctl)

4. App (ETC.)

3. App (GLCD)

ETC.

Digital Media Lab 2004


Project result 1 l.jpg
Project Result (1)

Digital Media Lab 2004


Project result 2 l.jpg
Project Result (2)

Digital Media Lab 2004


Approach for this project l.jpg
Approach for this Project

  • Step 1. Prepare the Atmega128 MCU board

  • Step 2. Get uC/OS-II source code from Jean J. Labrosse

    • Our Project kernel Version is V2.76

  • Step 3. Understand the architecture of uC/OS-II’s Real-Time Kernel

  • Step 4. Understand Atmega128 architecture and software development using GCC (winavr) compiler

  • Step 5. Compile the uC/OS-II source code, which is written in ANSI C with GCC or IAR compiler

  • Step 6. Development of Demo Application

  • Step 7. Debugging and final report

  • Digital Media Lab 2004


    Embedded system design 20048 l.jpg
    Embedded System Design 2004

    • Project Introduction

    • Overview of uC/OS-II

    • Overview of Atmega128

    • The Construction of Development Environment

    • uC/OS-II Porting on Atmega128

    • Development of a Application

    • Project Conclusion

    Digital Media Lab 2004


    Uc os ii support page l.jpg

    Many Porting Information

    FAQ and

    Development Intuitions !!!

    uC/OS-II support page

    • http://www.ucos-ii.com/

    Digital Media Lab 2004


    What is uc os ii l.jpg

    1 Idel task, 63 Appliction task = 64 tasks

    What is uC/OS-II ?

    • uC/OS-II, The Real-Time Kernel

    • Highly portable,

    • ROMable,

    • Very scalable,

    • Preemptive real-time

    • Multi-tasking kernel

      • For micro-processor

      • For micro-controller

    • uC/OS-II can manage up to 63 application tasks

    • Over 100 microprocessor ports available

    • GO to uC/OS world !!!

    Digital Media Lab 2004


    What uc os ii can l.jpg

    Prevent the Priority Inversion Problem

    What uC/OS-II can ?

    • uC/OS-II can manage up to 63 application tasks

      • (c.f.) windows 2000 ?,

      • (c.f.) linux ?

    • Semaphores

    • Mutual Exclusion Semaphores ( to reduce priority inversions) (added in V2.04)

    • Event Flags (added in V2.51)

    • Message Mailboxes

    • Message Queues

    • Task Management (Create, Delete, Change Priority, Suspend/Resume etc.)

    • Fixed Sized Memory Block management

    • Time management

    Digital Media Lab 2004


    Uc os ii kernel architecture l.jpg
    uC/OS-II Kernel Architecture

    Digital Media Lab 2004


    Uc os ii kernel architecture13 l.jpg

    Test.c

    OS_CFG.h

    INCLUDES.h

    Never Change

    OS_CPU.h

    OS_CPU_A.asm

    OS_CPU_C.c

    uC/OS-II Kernel Architecture

    Our Application

    uC/OS-II

    Application Specific Layer

    uC/OS-II

    Hardware independent Layer

    uC/OS-II

    Hardware Specific Layer

    Atmega128 (HardWare)

    Digital Media Lab 2004


    Embedded system design 200414 l.jpg
    Embedded System Design 2004

    • Project Introduction

    • Overview of uC/OS-II

    • Overview of Atmega128

    • The Construction of Development Environment

    • uC/OS-II Porting on Atmega128

    • Development of a Application

    • Project Conclusion

    Digital Media Lab 2004


    Atmega128 support page l.jpg

    We can get the Specification Doc

    We can get the Application Notes

    Atmega128 support page

    • http://www.atmel.com/products/avr/

    Digital Media Lab 2004


    What is atmega128 l.jpg
    What is Atmega128?

    • Atmel’s AVR, which microcontrollers

    • A RISC core running single cycle instructions  FAST

    • Internal oscillators, timers, UART, SPI, pull-up resistors, pulse width modulation, ADC, analog comparator and watch-doc timers  System On Chip

    • With on-chip in system programmable Flash and EEPROM  Very Easy Development

    • In order to optimize cost and get product to the market quickly  for Time to Market

    Digital Media Lab 2004


    Atmega128 feature 1 l.jpg
    Atmega128 feature (1)

    • Advanced RISC Architecture

      • Up to 16 MIPS Throughput at 16 MHz

      • On-chip 2-cycle Multiplier

      • Etc.

    • Nonvolatile program and data memories

      • 128 K bytes of In-System Reprogrammable Flash

      • 4 K bytes EEPROM

      • 4 K Bytes internal SRAM

      • Etc.

    Digital Media Lab 2004


    Atmega128 feature 2 l.jpg
    Atmega128 feature (2)

    • Peripheral Features

      • Two 8-bit Timer/Counters

      • Two Expanded 16-bit Timer/Counters

      • Two 8-bit PWM(Pulse Width Modulation) channels

      • 8-channels, 10-bit ADC(Analog to Digital Converter)

      • Dual Programmable Serial USARTs (UART0, UART1)

      • Master/Slave SPI serial interface

      • On-chip analog comparator

      • Etc.

    Digital Media Lab 2004


    Atmega128 architecture l.jpg
    Atmega128 Architecture

    Digital Media Lab 2004



    Avr for a true single chip solution l.jpg

    ADC

    TIMERS

    RTC

    SPI

    CPU

    PWM

    TWI

    USART

    PWM

    FLASH

    RAM

    EEPROM

    Brown-Out

    Detector

    Brown-Out

    Detector

    Pull-ups

    on demand

    Reset

    Circuitry

    High-current

    outputs

    Output Stage

    Programmable

    Watchdog

    Calibrated

    On-Chip OSC

    Watchdog

    Costly

    Emulator

    OCD / JTAG

    ISP

    Programming

    Circuitry

    AVR, for a true single-chip solution

    Page from www.prochild.com

    AVR does not only give you that

    BUT ALSO

    AVR

    Digital Media Lab 2004

    TO open the way to a truesingle-chip solution !


    The three avr families l.jpg
    The three AVR families

    Page from www.prochild.com

    Features

    ( 16KB - 128KB)

    Fully Compatible

    ( 1KB- 8KB )

    Memory

    Density

    ( 1KB - 2KB )

    Digital Media Lab 2004


    Avr register file l.jpg
    AVR Register File

    Page from www.prochild.com

    R0

    R1

    R2

    R3

    R26

    XL

    X Pointer

    R27

    XH

    R28

    YL

    Y Pointer

    R29

    YH

    R30

    ZL

    Z Pointer

    R31

    ZH

    Register File

    Digital Media Lab 2004


    Direct register alu connection l.jpg
    Direct Register - ALU Connection

    Page from www.prochild.com

    Register File

    Register operations

    take ONE clock pulse

    on the EXTERNAL clock

    input

    ALU

    Digital Media Lab 2004


    Execute 2 instructions l.jpg

    1

    2

    Done!

    Done!

    1

    2

    Done!

    1

    2

    1

    Done!

    2

    Execute 2 Instructions

    Page from www.prochild.com

    PIC

    HC05

    ‘C51

    Digital Media Lab 2004


    How to program the flash l.jpg

    FactoryProgramming

    • For stable release

    • Time saving

    Any other physical link !

    The programming channels can be disabled to avoid any further download !

    • Program through any interface (e.g. SPI, TWI)

    • Variable Boot Block Size

    • Allows 100% Secure Encrypted Remote updates

    Parallel

    • One of the fastest way to download

    • Compatible with major programmers

    • IEEE std. 1149.1 Compliant interface

    • Can program NVMs, fuses and lock bits

    • Used also to debug the application (On-Chip debugging)

    • Can be used to test the PCB (Boundary-Scan)

    JTAG

    ISP

    • The native 3-wire interface for a quick update in the field

    • Easy-to-use and efficient

    How to Program the Flash?

    Page from www.prochild.com

    SPM

    Digital Media Lab 2004


    In system programmable flash and eeprom l.jpg

    6-wire

    serial programming

    interface

    In-System Programmable Flash and EEPROM

    Page from www.prochild.com

    Your device sits in the application. It is clocked from

    the application clock, and Vcc can be as low as 2.7V.

    Now, with four logical signals + Ground, you can

    REPROGRAM THE FLASH AND THE EEPROM

    NO +12V PROGRAMMING VOLTAGE REQUIRED!

    Digital Media Lab 2004


    Self programming security l.jpg

    w

    Data to program can be obtained from the application, internal RAM or from outside

    x

    y

    The Boot Section can program :

    v

    From the Application, it’s possible to jump to the Boot Section

    y

    RESET

    y

    Boot Section and Application Section can be locked to avoid :

    u

    Application

    u

    After a Reset the device can start in Application or Boot Loader Mode

    Self Programming Security

    Page from www.prochild.com

    w

    x

    Boot Section

    The Application Section

    v

    The Boot Section

    w

    x

    Read

    Write

    Read and Write

    Digital Media Lab 2004


    I o pin block diagram l.jpg
    I/O Pin Block Diagram

    Page from www.prochild.com

    DDRx

    0

    Pull-Up

    PORTx

    0

    PINx

    Physical Pin

    X

    X

    Direction: INPUT

    PORTx : Output data or Pull-up Control bit

    DDRx Data Direction Control Bit

    PINx : Pin Level bit

    Pull-Up: OFF (Tri-State)

    Digital Media Lab 2004


    Embedded system design 200430 l.jpg
    Embedded System Design 2004

    • Project Introduction

    • Overview of uC/OS-II

    • Overview of Atmega128

    • The Construction of Development Environment

    • uC/OS-II Porting on Atmega128

    • Development of a Application

    • Project Conclusion

    Digital Media Lab 2004


    Development procedure l.jpg

    1

    2

    3

    Binary format

    Intel hex

    Etc.

    5

    4

    Hi @@ world!!

    Development Procedure

    Programmer or Artist

    Ultra Editor

    My Application code

    uC/OS-II source

    Makefile

    WinAVR

    GCC compiler

    For AVR MCU

    CodeVision

    ISP Programmer

    Atmega128

    Digital Media Lab 2004


    Prepare the atmega128 main board l.jpg
    Prepare the Atmega128 Main board

    • Atmega128, 16 Mhz (real-sys)

    Digital Media Lab 2004


    How can get the uc os ii kernal l.jpg
    How can get the uC/OS-II kernal?

    • Get uC/OS-II source code

      • buy the book

      • MicroC/OS-II: The Real-Time Kernel (2nd Edition, Revised) (with Compact Disc)

      • Embedded systems building blocks

    • Our Project kernel Version

      • V2.76

    Digital Media Lab 2004


    Ultra editor and gcc compiler l.jpg
    Ultra Editor and GCC compiler

    • Ultra Editor + GCC compiler (winavr)

      • http://www.project-hf.net//ehobby/Projects/Mp3_Jukebox/2_mcu.htm

        • Winavr (gcc compiler) :

          • http://winavr.sourceforge.net/

        • Ultra-editor

          • ftp://ultraedit.com/

    • Step 1. winavr install

      • Notice !!! : Set the “PATH”

    • Step 2. ultra-editor install & compile setting

      • Go to the http://www.project-hf.net//ehobby/Projects/Mp3_Jukebox/2_mcu.htm

    Ultra Editor

    My Application code

    uC/OS-II source

    Makefile

    WinAVR

    GCC compiler

    For AVR MCU

    Digital Media Lab 2004


    Ultra editor compile setting l.jpg
    Ultra-editor compile setting

    • Ultra-editor compile setting

      • http://www.project-hf.net//ehobby/Projects/Mp3_Jukebox/2_mcu.htm

    Digital Media Lab 2004


    Codevision compiler l.jpg
    CodeVision Compiler

    • Codevision si a program of high talents

      • Avr C Compiler

      • ISP (In System Programming)

        •  Parallel(Printer) Port

      • UART communication Terminal

      • ETC..

    http://www.hpinfotech.ro/

    Digital Media Lab 2004


    Embedded system design 200437 l.jpg
    Embedded System Design 2004

    • Project Introduction

    • Overview of uC/OS-II

    • Overview of Atmega128

    • The Construction of Development Environment

    • uC/OS-II Porting on Atmega128

    • Development of a Application

    • Project Conclusion

    Digital Media Lab 2004


    Porting feature summary l.jpg
    Porting feature summary

    • Target board

      • Atmega128 (realsys minicom128), 16 MHz

      • (Case1) Without External SRAM  internal SRAM (4Kbytes)

      • (Case2) With External SRAM (32 Kbytes)

    • uC/OS-II Kernel Version

      • V-2.76

    • Cross Compiler

      • WinAvr gcc compiler (GCC 3.3.2) with gcc licence

    • UART baud-rate

      • UART0, 115200, 8bits, None Parity, 1Stop-bits

    Digital Media Lab 2004


    Memory sections default map l.jpg
    Memory Sections : Default Map

    .text  Flash ROM (128 Kbytes)

    .data, .bss, heap, stack  internal SRAM

    Digital Media Lab 2004


    Memory sections can we change the section map 1 l.jpg
    Memory Sections : Can we change the Section Map? (1)

    • Problem: If you want coding the very large program, How?

    So Small !!

    I want big big Program !!!

    Digital Media Lab 2004


    Memory sections can we change the section map 2 l.jpg
    Memory Sections : Can we change the Section Map? (2)

    • Answer: We can it !!! We can speak to the Linker !!!

      • WinAvr’s Linker FLAGS (LDFLAGS) is the KEY

      • It is possible to tell the linker the SRAM address of the beginning of the .data section

    WinAVR Liner

    (in Makefile)

    LDFLAGS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x807fff

    LDFLAGS += -Wl,-Map=$(TARGET).map,--cref

    Digital Media Lab 2004


    Memory sections can we change the section map 3 l.jpg
    Memory Sections : Can we change the Section Map? (3)

    • We can use the external SRAM

    • Aslo we can change the Section Map !!

    avr-gcc ... -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff ...

    Internal RAM: stack only, external RAM: variables and heap

    Digital Media Lab 2004


    Memory sections can we change the section map 4 l.jpg
    Memory Sections : Can we change the Section Map? (4)

    • Q. If you want “malloc()” operation on a MCU?

    • It is a Quite challenge, But we can also it!!!

    avr-gcc ... -Wl,--defsym=__heap_start=0x802000,--defsym=__heap_end=0x803fff ...

    Internal RAM: variables and stack, external RAM: heap

    Digital Media Lab 2004


    Review of the memory sections text section l.jpg
    Review of the Memory Sections.text section

    • Refer to the avr-libc documentation

    • The .text section

      • The actual machine instructions

      • Subdivided by the .initN and .finiN sections

      • In a Flash ROM

    #include <stdio.h>

    Int main(void)

    {

    while(1){ // always !!!

    printf(“Hi !!! \n”);

    }

    }

    .initN sections

    .finiN sections

    Digital Media Lab 2004


    Review of the memory sections data section l.jpg
    Review of the Memory Sections :.data section

    • The .data section

      • Static data

    char err_str[] = "Your program has died a horrible death!";

    struct point pt = { 1, 1 };

    char my_mind = “I miss you ^^”;

    // 매우 그립소

    char your_mind = “Your mind is just a springtime fantasy”;

    // 꿈 깨시오, 일장춘몽이오

    Digital Media Lab 2004


    Review of the memory sections bss eeprom noinit initn finin l.jpg
    Review of the Memory Sections :.bss, .eeprom, .noinit, .initN, finiN

    • .bss

      • Global

      • Static variables

    • .eeprom

      • This is where eeprom variables are stored.

    • .noinit

      • a part of the .bss section

    • .initN

      • define the startup code from reset up through the start of main()

      • These all are subparts of the .text section

      • The purpose of these sections is to allow for more specific placement of code within your program.

    • .finiN

      • define the exit code executed after return from main() or a call to exit()

    Digital Media Lab 2004


    Actual porting l.jpg

    (Case 1)

    In internal SRAM

    uC/OS-II

    and

    Simple Application

    Internal SRAM

    External SRAM

    (Case 2)

    With External SRAM

    32 Kbytes

    uC/OS-II

    and

    More Complex

    Applicatons

    Actual Porting

    0x0000

    4 K

    0x10ff

    0x1100

    32 K

    0x7FFF

    Digital Media Lab 2004


    Loader setting l.jpg

    in Makefile

    LDFLAGS += -Wl,-Map=$(TARGET).map,--cref

    In Application File

    (Enable the Exeternal RAM)

    outp(0x80, MCUCR);

    in Makefile

    (setting the Loader Flag)

    LDFLAGS = -Wl,-Tdata=0x801100

    ,--defsym=__heap_end=0x807fff

    LDFLAGS += -Wl,-Map=$(TARGET).map,--cref

    Loader Setting

    Case 1

    0x0000

    4 K

    0x10ff

    Case 2

    0x1100

    32 K

    0x7FFF

    Digital Media Lab 2004


    Retouching the uc os kernel l.jpg
    Retouching the uC/OS-Kernel

    Digital Media Lab 2004


    Retouching the uc os kernel50 l.jpg

    Test.c

    OS_CFG.h

    INCLUDES.h

    Never Change

    OS_CPU.h

    OS_CPU_A.asm

    OS_CPU_C.c

    Retouching the uC/OS-Kernel

    Our Application

    uC/OS-II

    Application Specific Layer

    uC/OS-II

    Hardware independent Layer

    uC/OS-II

    Hardware Specific Layer

    Atmega128 (HardWare)

    Digital Media Lab 2004


    Uc os ii hardware specific layer l.jpg

    Test.c

    OS_CFG.h

    INCLUDES.h

    OS_CPU.h

    OS_CPU_A.asm

    OS_CPU_C.c

    uC/OS-II Hardware Specific Layer

    Our Application

    uC/OS-II

    Application Specific Layer

    uC/OS-II

    Hardware independent Layer

    uC/OS-II

    Hardware Specific Layer

    Atmega128 (HardWare)

    Digital Media Lab 2004


    Os cpu h l.jpg

    OS_CPU.h

    OS_CPU_A.asm

    OS_CPU_C.c

    OS_CPU.h

    • We can use Ole Saether’s Porting source

      •  No pain !! (Don’t Need change), Just Need Analysis

    uC/OS-II

    By C

    Atmega128

    By C

    #if OS_CRITICAL_METHOD == 1

    #define OS_ENTER_CRITICAL()asm volatile ("cli") // Disable interrupts

    #define OS_EXIT_CRITICAL()asm volatile ("sei") // Enable interrupts

    #endif

    Digital Media Lab 2004


    Os cpu a asm l.jpg

    OS_CPU.h

    OS_CPU_A.asm

    OS_CPU_C.c

    OS_CPU_A.asm

    OSCtxSw: PUSHRS ; Save current tasks context

    PUSHSREG ; Save SREG

    lds R30,OSTCBCur ; Z = OSTCBCur->OSTCBStkPtr

    lds R31,OSTCBCur+1 ;

    in r28,_SFR_IO_ADDR(SPL)

    st Z+,R28 ; Save Y (R29:R28) pointer

    in r29,_SFR_IO_ADDR(SPH)

    st Z+,R29 ;

    #if OS_TASK_SW_HOOK_EN > 0

    call OSTaskSwHook ; Call user defined task switch hook

    #endif

    lds R16,OSPrioHighRdy ; OSPrioCur = OSPrioHighRdy

    sts OSPrioCur,R16

    lds R30,OSTCBHighRdy ; Let Z point to TCB of highest priority task

    lds R31,OSTCBHighRdy+1 ; ready to run

    sts OSTCBCur,R30 ; OSTCBCur = OSTCBHighRdy

    sts OSTCBCur+1,R31 ;

    ld R28,Z+ ; Restore Y pointer

    out _SFR_IO_ADDR(SPL),R28

    ld R29,Z+ ;

    out _SFR_IO_ADDR(SPH),R29

    POPSREG ; Restore the status register

    POPRS ; Restore all registers

    ret

    uC/OS-II

    C function name

    Atmega128

    By Assembly

    Digital Media Lab 2004


    Os cpu c c l.jpg

    OS_CPU.h

    OS_CPU_A.asm

    OS_CPU_C.c

    OS_CPU_C.c

    OS_STK *OSTaskStkInit (void (*task)(void *pd), void *pdata, OS_STK *ptos, INT16U opt)

    {

    INT8U *stk;

    INT16U tmp;

    opt = opt; /* 'opt' is not used, prevent warning */

    stk = (INT8U *)ptos; /* AVR return stack ("hardware stack") */

    tmp = (INT16U)task;

    /* "push" initial register values onto the stack */

    *stk-- = (INT8U)tmp; /* Put task start address on top of stack */

    *stk-- = (INT8U)(tmp >> 8);

    *stk-- = (INT8U)0x00; /* R0 = 0x00 */

    *stk-- = (INT8U)0x00; /* R1 = 0x00 */

    *stk-- = (INT8U)0x00; /* R2 = 0x00 */

    *stk-- = (INT8U)0x00; /* R3 = 0x00 */

    *stk-- = (INT8U)0x00; /* R30 = 0x00 */

    *stk-- = (INT8U)0x00; /* R31 = 0x00 */

    #ifdef RAMPZ

    *stk-- = (INT8U)0x00; /* RAMPZ = 0x00 */

    #endif

    *stk-- = (INT8U)0x80; /* SREG = Interrupts enabled */

    return ((OS_STK *)stk);

    }

    uC/OS-II

    By C

    Atmega128

    By C

    Digital Media Lab 2004


    Uc os ii application specific layer l.jpg

    Test.c

    OS_CFG.h

    INCLUDES.h

    OS_CPU.h

    OS_CPU_A.asm

    OS_CPU_C.c

    uC/OS-II Application Specific Layer

    Our Application

    uC/OS-II

    Application Specific Layer

    uC/OS-II

    Hardware independent Layer

    uC/OS-II

    Hardware Specific Layer

    Atmega128 (HardWare)

    Digital Media Lab 2004


    Os cfg h l.jpg
    OS_CFG.h

    OS_CFG.h

    INCLUDES.h

    • We can use Ole Saether’s Porting source

    System clock frequency

    uC/OS-II setting !!!

    RTOS function On/Off

    #define CPU_CLOCK_HZ 6000000 //3686400

    #define OS_TASK_DEF_STK_SIZE 128 /* Default stack size */

    /* ---------------------- MISCELLANEOUS ----------------------- */

    #define OS_ARG_CHK_EN 0 /* Enable (1) or Disable (0) argument checking */

    #define OS_CPU_HOOKS_EN 1 /* uC/OS-II hooks are found in the processor port files */

    #define OS_DEBUG_EN 1 /* Enable(1) debug variables */

    #define OS_EVENT_NAME_SIZE 32 /* Determine the size of the name of a Sem, Mutex, Mbox or Q */

    #define OS_LOWEST_PRIO 12 /* Defines the lowest priority that can be assigned ... */

    Digital Media Lab 2004


    Includes h l.jpg

    OS_CFG.h

    INCLUDES.h

    INCLUDES.h

    Include files

    WinAvr compiler !!!

    ANSI C compatable

    #include <avr/io.h>

    #include <avr/signal.h>

    #include <avr/interrupt.h>

    /* If you have uC/OS-II version below 2.70 uncomment the includes for os_cpu.h and os_cfg.h */

    /* #include "os_cpu.h" */

    /* #include "os_cfg.h" */

    #include <uC/OS_ii.h>

    /* ISR support macros */

    #include <avr_isr.h>

    Digital Media Lab 2004


    Our application l.jpg

    Test.c

    OS_CFG.h

    INCLUDES.h

    OS_CPU.h

    OS_CPU_A.asm

    OS_CPU_C.c

    Our Application

    Our Application

    uC/OS-II

    Application Specific Layer

    uC/OS-II

    Hardware independent Layer

    uC/OS-II

    Hardware Specific Layer

    Atmega128 (HardWare)

    Digital Media Lab 2004


    Our application test c l.jpg
    Our Application : test.c

    Our Application

    OSTaskCreate(Task1);

    OSTaskCreate(Task2);

    OSTaskCreate(Task3); … ETC.

    Int main(void)

    {

    AvrInit();

    OSInit();

    OSTaskCreate(TesK0);

    OSStart();

    return 0;

    }

    Multi

    Tasking!!

    Task1()

    {

    while(1){..}

    }

    Task2()

    {

    while(1){..}

    }

    Task3()

    {

    while(1){..}

    }

    Digital Media Lab 2004


    Embedded system design 200460 l.jpg
    Embedded System Design 2004

    • Project Introduction

    • Overview of uC/OS-II

    • Overview of Atmega128

    • The Construction of Development Environment

    • uC/OS-II Porting on Atmega128

    • Development of a Application

    • Project Conclusion

    Digital Media Lab 2004


    Example 01 create tasks l.jpg
    Example01 : Create Tasks

    • Create Tasks

    Task 1

    OSTaskCreate()

    Task 2

    TaskStart

    OSTaskCreate()

    …..

    OSTaskCreate()

    OSTaskCreate()

    Task N

    Digital Media Lab 2004


    Example 01 create tasks62 l.jpg
    Example01 : Create Tasks

    • 1. Create Tasks

      • OSTaskCreate(void (*task)(void *pd), void *p_arg, OS_STK *ptos, INT8U prio);

    • 2. Statistics on the screen

      • The number of task switches in one second

        • OSTaskCtr // global variables

      • The CPU usage in %

        • OSCPUUsage // global variables

      • The number of context switches

        • OSCtxSwCtr // global variables

      • The uC/OS-II version

        • OSVersion(); // support function

    Digital Media Lab 2004


    Example 01 l.jpg

    Create the Tasks !!!

    OSTaskCreate(i);

    Example01

    TaskStart()

    void TaskStart (void *data)

    {

    INT8U i;

    char s[10];

    data = data; // Prevent compiler warning

    OSStatInit(); // Initialize uC/OS-II's statistics

    for (i = 0; i < N_TASKS; i++) { // Create N_TASKS identical tasks

    TaskData[i] = '0' + i; // Each task will display its own letter

    OSTaskCreate(Task, (void *)&TaskData[i], (void *)&TaskStk[i][TASK_STK_SIZE - 1], i + 1);

    }

    //...................1234567890..........1234567890..........1234567890

    VT102DispStr(1, 25, "- # of Tasks : xxxxx ", COLOR_WHITE, COLOR_BLACK);

    VT102DispStr(1, 26, "- CPU Usage : xxxxx %", COLOR_WHITE, COLOR_BLACK);

    VT102DispStr(1, 27, "- # of Task switchs/sec: xxxxx ", COLOR_WHITE, COLOR_BLACK);

    for (;;) {

    SPrintDec(s, (INT16U)OSTaskCtr, 5); // Display #tasks running

    VT102DispStr(26, 25, s, COLOR_WHITE, COLOR_BLUE);

    SPrintDec(s, (INT16U)OSCPUUsage, 5); // Display CPU usage in %

    VT102DispStr(26, 26, s, COLOR_WHITE, COLOR_BLUE);

    SPrintDec(s, (INT16U)OSCtxSwCtr, 5); // Display #context switches per second

    VT102DispStr(26, 27, s, COLOR_WHITE, COLOR_BLUE);

    OSCtxSwCtr = 0;

    OSTimeDlyHMSM(0, 0, 1, 0); // Wait one second

    }

    }

    CPU Usage

    Context Switching Rate

    # of Tasks …

    Digital Media Lab 2004


    Example 0164 l.jpg
    Example01

    Display the task Number : UART terminal

    Infinite ROOP (Super roop) structure

    Task()

    void Task (void *data)

    {

    INT8U x;

    INT8U y;

    INT8U err;

    for (;;) {

    OSSemPend(RandomSem, 0, &err);

    // Acquire semaphore to perform random numbers

    x = random(TERMINAL_RANDOM_RIGHT -TERMINAL_RANDOM_LEFT);

    // Find X position where task number will appear

    // Find Y position where task number will appear

    y = random(TERMINAL_RANDOM_BOTTOM-TERMINAL_RANDOM_TOP);

    OSSemPost(RandomSem); // Release semaphore

    // Display the task number on the screen

    VT102DispChar(TERMINAL_RANDOM_LEFT+x

    , TERMINAL_RANDOM_TOP+y

    , *(char *)data, COLOR_WHITE, COLOR_BLACK);

    OSTimeDly(6); // Delay 6 clock ticks

    }

    }

    Digital Media Lab 2004


    Example 01 makefile l.jpg
    Example01 Makefile

    Enable the 32 Kbytes External RAM

    Loader Flag Setting

    # MCU name

    MCU = atmega128

    # Output format. (can be srec, ihex, binary)

    FORMAT = ihex

    # Target file name (without extension).

    TARGET = test

    # Optional linker flags.

    # -Wl,...: tell GCC to pass this to linker.

    # -Map: create map file

    # --cref: add cross reference to map file

    # 내부램을 사용할 경우 ... 실험결과 동작함

    #LDFLAGS = -Wl,-Map=$(TARGET).map,--cref

    # 외부램을 사용할 경우 A ... 실험결과 동작함

    LDFLAGS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x807fff

    LDFLAGS += -Wl,-Map=$(TARGET).map,--cref

    Digital Media Lab 2004


    Example 01 result l.jpg
    Example01 Result

    Digital Media Lab 2004


    Example 02 l.jpg
    Example02

    TxMbox

    • Mailbox

    OSMboxPost()

    OSMboxPend()

    Task 4

    Task 5

    OSMboxPend()

    OSMboxPost()

    AckMbox

    Digital Media Lab 2004


    Example 02 message mailbox l.jpg
    Example02 : Message MailBox

    • Task 1. Stack checking task

      • OSTaskStkChk(TASK_START_PRIO+i, &data);

    • Task 2. Clockwise-rotating wheel task

      • OSTimeDly()

    • Task 3. Counterclockwise-rotating wheel task

    • Task 4. communicates with Task 5

      • AckMbox = OSMboxCreate((void *)0);

      • TxMbox = OSMboxCreate((void *)0);

      • OSMboxPost (TxMbox, (void *)&txmsg);

      • OSMboxPend (AckMbox, 0, &err);

    • Task 5. receives and displays a message (with Task 4)

      • rxmsg = (char *)OSMboxPend (TxMbox, 0, &err);

      • OSTimeDlyHMSM (0, 0, 1, 0);

      • OSMboxPost (AckMbox, (void *)1);

    Digital Media Lab 2004


    Example 02 notice l.jpg
    Example02 Notice!!

    OS_CFG.H

    • If we want to use the Message Mailbox

      • Then have to enable the “Mbox” Options

    /* -------------------- MESSAGE MAILBOXES --------------------- */

    #define OS_MBOX_EN 1

    /* Enable (1) or Disable (0) code generation for MAILBOXES */

    #define OS_MBOX_ACCEPT_EN 1

    /* Include code for OSMboxAccept() */

    #define OS_MBOX_DEL_EN 0

    /* Include code for OSMboxDel() */

    #define OS_MBOX_POST_EN 1

    /* Include code for OSMboxPost() */

    #define OS_MBOX_POST_OPT_EN 0

    /* Include code for OSMboxPostOpt() */

    #define OS_MBOX_QUERY_EN 0

    /* Include code for OSMboxQuery() */

    Digital Media Lab 2004


    Example 02 result l.jpg
    Example02 Result

    Stack

    Information

    Message

    Mailbox

    Digital Media Lab 2004


    Example 03 message queue l.jpg
    Example03 : Message Queue

    OSQPend() forever

    Message Queue

    Task 2

    OSQPost()

    Task 1

    Task 3

    OSQPend() untill…

    Digital Media Lab 2004


    Example 03 message queue72 l.jpg
    Example03 : Message Queue

    • Task 1. Message Queue Transmit (TX)

      • OSQPost (MsgQueue, (void *)&one);

      • OSTimeDlyHMSM(0, 0, 1, 0);

      • OSQPost (MsgQueue, (void *)&two);

      • OSTimeDlyHMSM(0, 0, 0, 500);

      • OSQPost (MsgQueue, (void *)&three);

      • OSTimeDlyHMSM(0, 0, 1, 0);

      • OSQPost (MsgQueue, (void *)&three);

    • Task 2. Message Queue Receive (RX) #01

      • OSQPend (MsgQueue, 0, &err);

        • /* Wait forever for message */

    • Task 3. Message Queue Receive (RX) #02

      • OSQPend (MsgQueue, OS_TICKS_PER_SEC / 4, &err);

        • /* Wait up to 250 mS for a msg */

    Only Difference is

    Timeout !!!

    Task2 : wait forever

    Task3 : Wait up to 250 ms

    Tenacious

    (끈질긴, 고집센)

    Reasonable

    Digital Media Lab 2004


    Example 03 result l.jpg
    Example03 Result

    Digital Media Lab 2004


    Example 04 tasks synchronization l.jpg
    Example04 : Tasks Synchronization

    TxMbox

    • Using Mailbox

    OSMboxPost()

    OSMboxPend()

    Task 4

    Task 5

    OSMboxPend()

    OSMboxPost()

    AckMbox

    Digital Media Lab 2004


    Example 04 tasks synchronization75 l.jpg
    Example04 : Tasks Synchronization

    Synchronized

    Parade :

    Two Tasks is

    Synchronized !!!

    Digital Media Lab 2004


    Embedded system design 200476 l.jpg
    Embedded System Design 2004

    • Project Introduction

    • Overview of uC/OS-II

    • Overview of Atmega128

    • The Construction of Development Environment

    • uC/OS-II Porting on Atmega128

    • Development of a Application

    • Project Conclusion

    Digital Media Lab 2004


    Conclusion and etc l.jpg
    Conclusion and Etc.

    • 1. uC/OS-II Porting on Atmega128

      •  we have to know about

        • Software architecture and

        • Hardware architecture

    • 2. uC/OS-II RTOS kernel

      • Software Design Skill

      • Coding Style

    • Documentation

      • History …

    Digital Media Lab 2004


    Thank you l.jpg
    Thank you !!!

    • End of file

    Digital Media Lab 2004


    ad