Embedded system programming: HCS12



Similar documents
Lecture 3 Addressing Modes, Instruction Samples, Machine Code, Instruction Execution Cycle

Chapter 12. Development Tools for Microcontroller Applications

HC12 Assembly Language Programming

Keil C51 Cross Compiler

Embedded Software development Process and Tools: Lesson-4 Linking and Locating Software

Interrupts and the Timer Overflow Interrupts Huang Sections What Happens When You Reset the HCS12?

Use of Simulator in Teaching Introductory Computer Engineering*

Motorola 8- and 16-bit Embedded Application Binary Interface (M8/16EABI)

Lecture 22: C Programming 4 Embedded Systems

Programing the Microprocessor in C Microprocessor System Design and Interfacing ECE 362

SKP16C62P Tutorial 1 Software Development Process using HEW. Renesas Technology America Inc.

Using the HCS12 Serial Monitor on Wytec Dragon-12 boards. Using Motorola s HCS12 Serial Monitor on Wytec s Dragon-12 boards

Microcontroller Basics A microcontroller is a small, low-cost computer-on-a-chip which usually includes:

AN4296 Application note

EMBEDDED C USING CODEWARRIOR Getting Started Manual

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

Freescale Semiconductor, I

Quick Start Tutorial. Using the TASKING* Software Development Tools with the Intel 8x930 Family Evaluation Board

Freescale Semiconductor, I

HVM TP : A Time Predictable and Portable Java Virtual Machine for Hard Real-Time Embedded Systems JTRES 2014

Digitale Signalverarbeitung mit FPGA (DSF) Soft Core Prozessor NIOS II Stand Mai Jens Onno Krah

Hardware and Software Requirements

HC08 Welcome Kit. Hardware- Version User Manual

An Introduction to the ARM 7 Architecture

Programming the Motorola MC68HC11 Microcontroller

Programming Languages

WIND RIVER DIAB COMPILER

M6800. Assembly Language Programming

An Introduction to MPLAB Integrated Development Environment

The programming language C. sws1 1

Real-time system programs

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Hitchhiker's Guide to CodeWarrior EE371, EE475 Fall 2005

Exception and Interrupt Handling in ARM

The stack and the stack pointer

Embedded Software development Process and Tools: Lesson-3 Host and Target Machines

3. Programming the STM32F4-Discovery

C# and Other Languages

Assignment 09. Problem statement : Write a Embedded C program to switch-on/switch-off LED.

Ch. 10 Software Development. (Computer Programming)

Comp 255Q - 1M: Computer Organization Lab #3 - Machine Language Programs for the PDP-8

umps software development

ELEG3924 Microprocessor Ch.7 Programming In C

DsPIC HOW-TO GUIDE Creating & Debugging a Project in MPLAB

RVDS 3.x with Eclipse IDE

USB HID bootloader for the MC9S08JM60

Embedded devices as an attack vector

Lab 1: Introduction to Xilinx ISE Tutorial

13. Publishing Component Information to Embedded Software

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

Adapting the PowerPC 403 ROM Monitor Software for a 512Kb Flash Device

Embedded SQL. Unit 5.1. Dr Gordon Russell, Napier University

Faculty of Engineering Student Number:

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

UT69R000 MicroController Software Tools Product Brief

A Utility for Programming Single FLASH Array HCS12 MCUs, with Minimum RAM Overhead

AN10866 LPC1700 secondary USB bootloader

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

CSE2102 Digital Design II - Topics CSE Digital Design II

Software Serial Port for ROM/RAM Monitor

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

A deeper look at Inline functions

Application Note. Introduction AN2471/D 3/2003. PC Master Software Communication Protocol Specification

Developing an Application on Core8051s IP-Based Embedded Processor System Using Firmware Catalog Drivers. User s Guide

etpu Host Interface by:

An Implementation Of Multiprocessor Linux

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

Using C to Access Data Stored in Program Space Memory on the TMS320C24x DSP

Bachelors of Computer Application Programming Principle & Algorithm (BCA-S102T)

CPU performance monitoring using the Time-Stamp Counter register

ASSEMBLY LANGUAGE PROGRAMMING (6800) (R. Horvath, Introduction to Microprocessors, Chapter 6)

APPLICATION NOTE. AT07175: SAM-BA Bootloader for SAM D21. Atmel SAM D21. Introduction. Features

Introduction to Microcontrollers

Introducing PgOpenCL A New PostgreSQL Procedural Language Unlocking the Power of the GPU! By Tim Child

Develop a Dallas 1-Wire Master Using the Z8F1680 Series of MCUs

SOFTUNE REALOS CONFIGURATOR MANUAL

A3 Computer Architecture

Exceptions in MIPS. know the exception mechanism in MIPS be able to write a simple exception handler for a MIPS machine

Building Applications Using Micro Focus COBOL

Programming Embedded Systems

Microcontrollers A Brief History of Microprocessors

Programming A PLC. Standard Instructions

Non-Volatile Memory Programming on the Agilent 3070

AN1229. Class B Safety Software Library for PIC MCUs and dspic DSCs OVERVIEW OF THE IEC STANDARD INTRODUCTION

Programmer s Model = model of µc useful to view hardware during execution of software instructions

================================================================

S7 for Windows S7-300/400

Application Note: AN00141 xcore-xa - Application Development

Microtronics technologies Mobile:

Compiler Construction

Freescale Semiconductors, Inc. Freescale HC12 Assembler

MPLAB TM C30 Managed PSV Pointers. Beta support included with MPLAB C30 V3.00

USBSPYDER08 Discovery Kit for Freescale MC9RS08KA, MC9S08QD and MC9S08QG Microcontrollers User s Manual

Introduction to Operating Systems. Perspective of the Computer. System Software. Indiana University Chen Yu

Software development and debugging for NXP ARM7 MCUs

FRONT FLYLEAF PAGE. This page has been intentionally left blank

Intel Tunnel Mountain Software Development Platform Overview, IHV Tools Update

AN3265 Application note

Transcription:

Embedded system programming: HCS12 Cross developments environments and tools XCC12 cross C compiler in particular Low level programming in C Embedded system programming: HCS12 1 Low level programming in C Short history Cross development Software libraries Embedded assembly code Interrupts Embedded system programming: HCS12 2

The program language C The philosophy of BCPL is not one of the tyrant who thinks he knows best and lays down the law on what is and what is not allowed; rather, BCPL acts more as a servant offering his services to the best of his ability without complaint, even when confronted with apparent nonsense. The programmer is always assumed to know what he is doing and is not hemmed in by petty restrictions. Martin Richards Brian Kernighan BCPL Basic Combined Programming Language (Martin Richards 1966 Dennis Ritchie B - (Johnson/Kernighan 1973 C (Kernighan/Ritchie 1978 ANSI C 1983, first standardisation C++ (Stroustrup 1986 ISO 1995, 1999 Embedded system programming: HCS12 3 Cross development Development for one type of computer (target computer with another type of computer (host computer Tools: Cross assembler Cross compiler Embedded system programming: HCS12 4

Cross development environment HOST Cross Development tools RS-232 TARGET monitor/ debugger Requires a resident software debugger in the target Embedded system programming: HCS12 5 Cross development environment HOST Cross Development tools RS-232 BDM adapter TARGET BDM Requires extra hardware (BDM-adapter Embedded system programming: HCS12 6

Cross development tools Host system Cross compilers (C/C++/Java/Ada/Fortran Cross assemblers Linker Terminal emulation, download Simulators Debug adapters and and software Embedded system programming: HCS12 7 The compiler Assembly source code CC C++ Ada ASL mc68000 mc68020 mc68hc11 mc68hc12 Java Source code I80386 Pentium III III Embedded system programming: HCS12 8

The assembler mc68hc12 Assembly source code Assembler o12 Object code with symbolic debug information Embedded system programming: HCS12 9 Linking o12 o12 Linker Motorola S- S- format Binary code for download to target Library module(s script-file Instructions for for linking linking o12 Library module Embedded system programming: HCS12 10

Software development with XCC12 Embedded system programming: HCS12 11 XCC12 Project Manager Project All source code files belonging to an application. Result is an executable program Workspace A practical way of grouping related projects. Embedded system programming: HCS12 12

XCC12 Application Any application requires a startup procedure. The procedure can often be standardised, i.e. several applications use the same startup. Embedded system programming: HCS12 13 XCC12 Compiler libraries Performs standard operations wich cannot be handled by a single instruction in CPU12. For example addition of 32-bit numbers. * long int la,lb,lc; * lc la + lb; ldd 2+_lb ldx _lb pshd pshx ldd 2+_la ldx _la pshd pshx jsr add32 leas 8,sp std 2+_lc stx _lc add32 a function in the precompiled library Embedded system programming: HCS12 14

XCC12 Standard libraries Three different libraries with common functions Embedded system programming: HCS12 15 CC12 segment The compiler distinguishes the generated code by placing it in one of four possible segments. text this is the segment for machine instructions (executable code data this is the segment for initialised variables. These variables have user defined values when the program starts but they may be changed by the program. cdata - this segment is also for initialised variables. These variables have user defined values when the program starts and they can not be changed by the program. bss this segment provides space for variables which don t have initialised values Embedded system programming: HCS12 16

CC12 segment - EXAMPLE int var; const int novar 1; int init_var 2; segment data.stab sym G:init_var:_init_var:(typ11 define _init_var _init_var: fdb $2 segment bss define _var _var: rmb 2.stab sym G:var:_var:(typ11 segment cdata.stab sym G:novar:_novar:(typ11 define _novar _novar: fdb $1 Embedded system programming: HCS12 17 XCC12 linker instructions // // default.lsc // script for QLD // for XCC12 applications in RWM // Embedded system programming: HCS12 18

XCC12 default.lsc // OPTIONS SECTION -M // generate listfile <basename>.map // define program entry for debugger entry( start group ( c, const_group abs group( r, test_group startupseg, text, cdata, data, bss group( r, interrupt_ layout 0x1000,0x3C80 < test_group, 0x3F80,0x3FFF < interrupt_ Embedded system programming: HCS12 19 XCC12 Embedded assembly code Operations, which cannot be accomplished with C -syntax, requires embedded assembly code : /* /* EXAMPLE EXAMPLE */ */ main( main( asm( asm( " andcc andcc #$F0"; #$F0"; /* /* clear clear condition condition flags flags */ */ NOTE: This is not a part of the C -language and may be compiler dependent. Embedded system programming: HCS12 20

XCC12 Embedded assembly code Variables and parameters can be referenced by name in embedded assembly code. callfunc( callfunc( int int aa aa, int int ab ab aa aa 1; 1; ab ab 2; 2; callfunc( callfunc( int int aa aa, int int ab ab asm(" asm(" movw movw #1,%a", #1,%a", aa; aa; asm(" asm(" movw movw #2,%a", #2,%a", ab; ab; Embedded system programming: HCS12 21 Remapping interrupt handlers ROM Address (hex FFFE FFFC FFFA Function RESET, Startvector Clock Monitor Fail, JMP [3FFE] COP Watchdog Timeout, JMP [3FFC] Main program FFF8 FFF6 Illegal Op Code, SWI, JMP [3FFA] JMP [3FF8] IRQHandler FFF4 FFF2 XIRQ, IRQ, JMP [3FF4] JMP [3FF2] IRQ FF8C FFF0 JMP [3Fxx] Service interrupt RWM Address (hex 3FFE 3FFC Funktion Not used ClockFailHandler 3FFA COPFailHandler RTI 3FF8 3FF6 3FF4 IllOpHandler SWIHandler XIRQHandler 3FF2 IRQHandler 3F8C 3FF0 Embedded system programming: HCS12 22

Specification of interrupt handler name( ; ; Keyword is the first word in the specification. An interrupt handler can neither have parameters nor return values. Embedded system programming: HCS12 23 Interrupt vector table in XCC12 #pragma #pragma DATA DATA /* /* 3F80 3F80 - - 3FFF 3FFF */ */ (*irqvecs[]( (*irqvecs[](.... PWMEShutdownHandler, PWMEShutdownHandler, PortPIntHandler, PortPIntHandler, TimerCh1Handler, TimerCh1Handler, TimerCh0Handler, TimerCh0Handler, RTIHandler, RTIHandler, IRQHandler, IRQHandler, XIRQHandler, XIRQHandler, SWIHandler, SWIHandler, IllopHandler, IllopHandler, COPFailHandler, COPFailHandler, ClockFailHandler, ClockFailHandler, ResetHandler ResetHandler ; ; script file for the application.... group( group( r, r, interrupt_ interrupt_.... layout layout.,., 0x3F80,0x3FFF 0x3F80,0x3FFF < < interrupt_ interrupt_ Embedded system programming: HCS12 24

Interrupt vector table, static initialisation IRQHandler( IRQHandler( /* /* Interrupt Interrupt service service routine routine */ */ declarations #pragma #pragma DATA DATA *irqvecs *irqvecs IRQHandler; IRQHandler; script file group( group( r, r, interrupt_ interrupt_ layout layout.,., 0x3FF2,0x3FF4 0x3FF2,0x3FF4 < < interrupt_ interrupt_ Embedded system programming: HCS12 25 Interrupt vector table, run time initialisation IRQHandler( IRQHandler( /* /* Interrupt Interrupt service service routine routine */ */ #pragma #pragma DATA DATA *irqvecs; *irqvecs; #pragma #pragma DATA DATA data data main( main( irqvecs irqvecs IRQHandler; IRQHandler; Embedded system programming: HCS12 26

Run time initialisation no vector table IRQHandler( IRQHandler( /* /* Interrupt Interrupt service service routine routine */ */ main( main( *(unsigned *(unsigned short short * * 0x3FF2 0x3FF2 (unsigned (unsigned short short IRQHandler; IRQHandler; alternatively #define #define SET_IRQ_VECTOR(x,y SET_IRQ_VECTOR(x,y *(unsigned *(unsigned short short * * y y (unsigned (unsigned short short x x main( main( SET_IRQ_VECTOR( SET_IRQ_VECTOR( IRQHandler IRQHandler,, 0x3FF2 0x3FF2 ; ; Embedded system programming: HCS12 27 Function call conventions in XCC12 EXAMPLE: EXAMPLE: Function Function call call int int a,b; a,b; main( main( callfunc( callfunc( a,b a,b ; ; ----------------------------------------------------------- The The following following assembly assembly code code is is generated generated by by the the compiler: compiler: * 0009 0009 callfunc( callfunc( a,b a,b ; ; ldd ldd _b _b pshd pshd ldd ldd _a _a pshd pshd jsr jsr _callfunc _callfunc Embedded system programming: HCS12 28

Function conventions in XCC12 callfunc( callfunc( aa aa, ab ab aa aa 1; 1; ab ab 2; 2; 4 6 old Y msb old Y lsb PC msb PC lsb ab msb ab lsb aa msb aa lsb Y and SP decreasing address The The following following assembly assembly code code is is generated generated by by the the compiler: compiler: * 0007 0007 callfunc( callfunc( aa aa, ab ab segment segment text text define define _callfunc _callfunc _callfunc: _callfunc: pshy pshy tfr tfr sp,y sp,y * 0008 0008 * 0009 0009 aa aa 1; 1; movw movw #1,4,y #1,4,y * 0010 0010 ab ab 2; 2; movw movw #2,6,y #2,6,y * 0011 0011 puly puly rts rts Embedded system programming: HCS12 29 Background Debug Mode BDM adapter Single wire electrical interface Used for debugging and programming the FLASH memory in HCS12 Embedded system programming: HCS12 30

BDM adapter ( pod Embedded system programming: HCS12 31 Summary we we have got a brief introduction to to Low level programming in C Cross developments environments and tools in general XCC12 cross C compiler in particular which finishes today s lecture Embedded system programming: HCS12 32