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



Similar documents
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)

Keil C51 Cross Compiler

The programming language C. sws1 1

The C Programming Language course syllabus associate level

Compiler Construction

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

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

Sources: On the Web: Slides will be available on:

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

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

MPLAB Harmony System Service Libraries Help

Lecture 22: C Programming 4 Embedded Systems

Crash Course in Java

ASSEMBLY PROGRAMMING ON A VIRTUAL COMPUTER

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Freescale Semiconductor, I

C++ Programming Language

Cost Model: Work, Span and Parallelism. 1 The RAM model for sequential computation:

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

A C Test: The 0x10 Best Questions for Would-be Embedded Programmers

Moving from CS 61A Scheme to CS 61B Java

Illustration 1: Diagram of program function and data flow

X86-64 Architecture Guide

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

Habanero Extreme Scale Software Research Project

CS 3530 Operating Systems. L02 OS Intro Part 1 Dr. Ken Hoganson

Informatica e Sistemi in Tempo Reale

Semantic Analysis: Types and Type Checking

16.1 MAPREDUCE. For personal use only, not for distribution. 333

Fast Arithmetic Coding (FastAC) Implementations

Hitchhiker's Guide to CodeWarrior EE371, EE475 Fall 2005

An Implementation Of Multiprocessor Linux

How To Write Portable Programs In C

Configuring CoreNet Platform Cache (CPC) as SRAM For Use by Linux Applications

ECE 341 Coding Standard

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

Chapter 2 Basic Structure of Computers. Jin-Fu Li Department of Electrical Engineering National Central University Jungli, Taiwan

13. Publishing Component Information to Embedded Software

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Chapter 12. Development Tools for Microcontroller Applications

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

AN AES encryption and decryption software on LPC microcontrollers. Document information

GDB Tutorial. A Walkthrough with Examples. CMSC Spring Last modified March 22, GDB Tutorial

Migrating Application Code from ARM Cortex-M4 to Cortex-M7 Processors

SYSTEM ecos Embedded Configurable Operating System

Top 10 Bug-Killing Coding Standard Rules

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

Introduction. What is an Operating System?

Chapter 7D The Java Virtual Machine

1 The Java Virtual Machine

A Comparison Of Shared Memory Parallel Programming Models. Jace A Mogill David Haglin

Course Name: ADVANCE COURSE IN SOFTWARE DEVELOPMENT (Specialization:.Net Technologies)

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

Memory Systems. Static Random Access Memory (SRAM) Cell

Object Oriented Software Design II

Embedded Systems Design Course Applying the mbed microcontroller

This documentation is made available before final release and is subject to change without notice and comes with no warranty express or implied.

Industry White Paper. Ensuring system availability in RSView Supervisory Edition applications

Implementation Aspects of OO-Languages

RTI Monitoring Library Getting Started Guide

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

Advanced Encryption Standard (AES) User's Guide

Buffer Overflows. Security 2011

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

Jonathan Worthington Scarborough Linux User Group

GPU Hardware Performance. Fall 2015

TivaWare Utilities Library

Format string exploitation on windows Using Immunity Debugger / Python. By Abysssec Inc

SECTION C [short essay] [Not to exceed 120 words, Answer any SIX questions. Each question carries FOUR marks] 6 x 4=24 marks

Chapter 13 Storage classes

6. Storage and File Structures

Advanced Bash Scripting. Joshua Malone

Outline. hardware components programming environments. installing Python executing Python code. decimal and binary notations running Sage

Affdex SDK for Windows!

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

Setting up PostgreSQL

Helping you avoid stack overflow crashes!

C++FA 5.1 PRACTICE MID-TERM EXAM

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

Molecular Dynamics Simulations with Applications in Soft Matter Handout 7 Memory Diagram of a Struct

Pemrograman Dasar. Basic Elements Of Java

Leak Check Version 2.1 for Linux TM

Creating the program. TIA Portal. SIMATIC Creating the program. Loading the block library. Deleting program block Main [OB1] Copying program blocks

MatrixSSL Porting Guide

8.5. <summary> Cppcheck addons Using Cppcheck addons Where to find some Cppcheck addons

what operations can it perform? how does it perform them? on what kind of data? where are instructions and data stored?

Programming Languages CIS 443

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

NEON. Support in Compilation Tools. Development Article. Copyright 2009 ARM Limited. All rights reserved. DHT 0004A (ID081609)

Tutorial on C Language Programming

by NetMedia, Inc. All rights reserved. Basic Express, BasicX, BX-01, BX-24 and BX-35 are trademarks of NetMedia, Inc. 2.

Faculty of Engineering Student Number:

Fastboot Techniques for x86 Architectures. Marcus Bortel Field Application Engineer QNX Software Systems

A deeper look at Inline functions

Lecture 3. Arrays. Name of array. c[0] c[1] c[2] c[3] c[4] c[5] c[6] c[7] c[8] c[9] c[10] c[11] Position number of the element within array c

Yun Shield Quick Start Guide VERSION: 1.0 Version Description Date 1.0 Release 2014-Jul-08 Yun Shield Quick Start Guide 1 / 14

etpu Host Interface by:

Transcription:

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

Contents 1 Overview 2 1.1 Why Beta?.............................. 2 1.2 Other Sources of Reference..................... 2 2 Current feature support 2 3 Goals 4 4 Managed PSV pointers - 24-bit pointers 5 4.1 Actual concrete examples...................... 6 4.1.1 Example 1: Managed Pointers as Function Arguments.. 7 4.1.2 Example 2: Managed Pointer (to an Array) as Function Arguments.......................... 9 4.1.3 Example 3: managed array of managed pointers..... 9 4.1.4 Example 4: Accessing FLASH Variables Directly..... 10 5 Managed PSV Pointers - ISR Considerations 10 6 Support information 11 1

1 Overview The dspic30f/33f and PIC24F/H families of processors contain hardware support for accessing data from within program FLASH. Previous versions of MPLAB C30 only supported direct access via one single PSV page. As the 16-bit parts are getting larger program memories, customers will need to easily access many pages. This feature provides better support in this area. The extensions presented here are beyond the scope of C89, though the method chosen to implement them is within the scope of C99. 1.1 Why Beta? We hope to provide a feature that will benefit our customers; internal consultation has come up with a set of features described within this document. By marking the feature as Beta we acknowledge that this design may be incomplete, and leave room for further customer directed enhancement. 1.2 Other Sources of Reference Other concepts used in this document can be found in manuals that reside in the doc folder that may have been installed with the product, or online at http://www.microchip.com/c30. Doc Id DS51284 DS51317 Title MPLAB C30 C compiler User s Guide MPLAB ASM30 MPLAB LINK30 and Utilities User s Guide 2 Current feature support Today MPLAB C30 allows the programmer to easily create data in program memory using the following features: the compiler supports a variable attribute, space() which allows the user to nominate: psv to place the variable into program memory in suitable chunks for PSV access to be managed by the user auto psv to place the variable into program memory in suitable chunks for PSV access, to be managed by the compiler (currently only 1 PSVPAG setting) eedata to place the variable into EEDATA memory, access is completely defined by the user prog to place the variable into unrestricted program memory, access is completely defined by the user 2

among other spaces. For a complete description of the space attribute, please refer to the MPLAB C30 User s Guide. the compiler will place (by default) all const qualified variables into the auto psv space; this may be disabled by using the command line switch -mconst-in-data MPLAB C30 will enable and support the use of 1 PSV page Using the current features, the programmer can create data and access data in several different ways: Variables stored in compiler managed PSV section const char *foo = "a constant string"; int fibonacci[4] attribute ((space(auto_psv))) = { 1, 1, 2, 3 ; void bar() { fprintf(stderr,"%s: %d %d\n", foo, fibonacci[1], fibonacci[3]); When compiled without specifying the constants-in-data memory model both foo and fibonacci will be placed into the (same) compiler managed PSV section. If this section exceeds 32K in size, the linker will complain and the application will fail to link. The tool chain will arrange for the PSVPAG to be correctly set at program start-up. Function bar() requires no special treatment to access the variables defined in this way. The tool chain assumes that the PSVPAG has not changed. Variables stored in a user managed PSV section char *foo attribute ((space(psv))) = "a constant string"; int fibonacci[4] attribute ((space(psv))) = { 1, 1, 2, 3 ; void bar() { int a,b; CORCONbits.PSV = 1; PSVPAG = builtin_psvpage(fibonacci); a = fibonacci[1]; b = fibonacci[3]; PSVPAG = builtin_psvpage(foo); 3

fprintf(stderr,"%s: %d %d\n", foo, a, b); When compiled without specifying the constants-in-data memory model this program will fail at run-time. That is because the literal string in the call to fprintf will occupy the auto psv space and the PSVPAG setting has been changed. The other things to note are: the user must ensure that the PSV window is enabled only one PSVPAG is available at a time, so the user must cache some of the values before the call to fprintf it really isn t hard, just annoying Note, that this example can apply to data stored in EEDATA too as the hardware allows the EEDATA memory to be accessed via the PSV window. Variables stored in a general program section char *foo attribute ((space(prog))) = "a constant string"; int fibonacci[4] attribute ((space(prog))) = { 1, 1, 2, 3 ; void bar() { /* eek! */ Well, I have been slightly lazy and omitted the code for bar to show how to access this kind of memory. Mostly to prove a point. There are two choices, using PSV or using the TBLRD 1 machine instructions. In this case, both are just as hard because the tool chain has not ensured that either variable doesn t cross a PSV boundary and table operations are hard to perform in C. 3 Goals Ideally a programmer should be able to make use of variables, where ever they are, without needing to configure hardware resources. In general this would require the language to support a new kind of pointer, one that represents a complete 24-bit address in program FLASH. In the ideal world, our user managed PSV example could be coded in the following manner: 1 V3.00 contains built-in definitions to make this easier 4

char *foo attribute ((space(psv))) = "this is a constant string"; int fibonacci[4] attribute ((space(psv))) = { 1, 1, 2, 3 ; void foo() { fprintf(stderr,"%s: %d %d\n", foo, a, b); I don t think this ideal will be reached (unfortunately) but we can come very close. Incidentally, the reason why I don t think this will happen is solely due to they way library functions like fprintf are implemented, but it shows a general problem that is likely to affect many users. In this case, when fprintf processes the %s formatting character, it expects the string to be located in data memory. It is not, so the function will fail. There are other, architectural, caveats that prevent us from reaching the ideal. In the following sections, I hope, the reader will observe that our extensions meet the spirit of this ideal goal. Functionality that we provide includes: ability to easily create data in program FLASH memory ability to access the data without having to think about the hardware limitations involved with the access and is discussed in the following sections. 4 Managed PSV pointers - 24-bit pointers Managed PSV pointers allow the compiler set keep track of the full 24-bit address of an object. When a managed PSV pointer is accessed, the compiler knows that the PSVPAG must be set before access. This operation is most certainly not atomic, so the compiler s view of what must be saved in an ISR has changed. ISR routines that use the PSVPAG resource will be required to set it first (an incompatibility with old objects). We will support two kinds of managed pointer, a small pointer where the address is constrained to single PSV page and a large pointer where addresses may overlap the page boundary. The small pointer, psv, can be used to create a pointer to data stored in space(psv). The large pointer, prog, is more general and should be used when the data may be stored in space(prog). Large pointers are much more general. A managed pointer is identified by a new syntax feature which resembles a cv-qualifier like const or volatile. Note that using this new pseudo-qualifier does not imply that the storage is in a PSV range. It is possible, for example, to define pointers to PSV objects where the pointer itself lives in normal data memory. Some examples: 5

int foo attribute ((space(psv))); foo lives in FLASH; it is not a managed variable - just like current syntax psv int foo attribute ((space(psv))); foo lives in FLASH; it is a managed variable, the programmer can accesses it as if it were a normal C variable int psv bar = &foo; bar lives in RAM; it is a managed pointer to an int (like other cv-qualifiers, read out from the pointer until the type is complete); assignments to bar should be addresses of variables in FLASH and can be dereferenced with normal C syntax - the compiler will do the hard work. Pointer arithmetic on a psv pointer will fail if the programmer tries to overflow the PSV page. int big foo[256] attribute ((space(prog))) = {... ; int prog big bar = big foo; big foo is an array that lives in FLASH, but it is not constrained by PSV address boundaries like a space(psv) would be. like bar, big bar is a managed pointer to an int. This pointer is not constrained by a PSV page boundary; any arithmetic performed will also update the page. A prog pointer can point to something placed into a space(psv)) constrained section. 4.1 Actual concrete examples Caveat: code-generation is supplied for illustrative purposes only. 6

4.1.1 Example 1: Managed Pointers as Function Arguments In the following function: int eek(const char *bar, prog int *foo, prog int *foo2) { int i = *foo2 + *foo; baz(); return i + *foo; foo and foo2 are pointers to an int in program space. The compiler will generate a sequence of code that preserves the PSVPAG and determine the correct PSV page and offset to access each pointer. For example: _eek: mov.d w8,[w15++] mov w10,[w15++] mov.d w2,w8 mov.d w4,w2 mov _PSVPAG, w0 ; preserve current _PSVPAG mov w5, _PSVPAG ; PSVPAG for foo rrnc w2, w2 ; create *real* offset for foo mov [w2],w1 ; dereference foo mov w0, _PSVPAG ; restore _PSVPAG mov.d w8,w2 mov _PSVPAG, w4 ; preserve _PSVPAG mov w9, _PSVPAG ; PSVPAG for foo2 rrnc w2, w2 ; create *real* offset for foo2 mov [w2],w0 ; dereference foo2 mov w4, _PSVPAG ; restore _PSVPAG add w1,w0,w10 ; i = *foo2 + *foo rcall _baz mov.d w8,w2 mov _PSVPAG, w4 ; preserve _PSVPAG mov w9, _PSVPAG ; PSVPAG for foo rrnc w2, w2 ; create *real* offset for foo2 mov [w2],w0 ; derefence foo2 mov w4, _PSVPAG ; restore _PSVPAG add w10,w0,w0 ; return i + *foo; mov [--w15],w10 mov.d [--w15],w8 return One might call this function by: 7

int foo_value, foo2_value attribute ((space(prog))); main() { eek("test", &foo_value, &foo2_value); The assembly for the function call looks like: mov mov mov mov mov rcall #psvpage(_foo_value),w3 #psvptr(_foo_value),w2 #psvpage(_foo2_value),w5 #psvptr(_foo2_value),w4 #.LC0,w0 _eek 8

4.1.2 Example 2: Managed Pointer (to an Array) as Function Arguments In the function below, foo points to a null-terminated buffer somewhere in FLASH. int eek(const char *bar, prog int *foo) { int sum = 0; while (*foo) sum += *foo++; return sum; int foo_buffer[256] attribute ((space(prog))); main() { eek("test", foo_buffer); 4.1.3 Example 3: managed array of managed pointers ppi array is an array of pointers to ints; the pointers are themselves managed (24-bit) pointers. I used the typedef because it makes the definition easier to read! typedef int prog *prog_int; /* pointer int in space(prog) */ /* ppi_array is an array of 16 managed pointers to ints; The array itself is in a psv space, and we would like the compiler to access the array using a managed access */ prog prog_int ppi_array[16] attribute ((space(psv))); int main() { int sum = 0; int i; int psv *p; for (i = 0; i < 15; i++) { p = ppi_array[i]; sum += *p; return sum; 9

4.1.4 Example 4: Accessing FLASH Variables Directly Although we talk about this new feature as 24-bit pointers, it really extends beyond that. It is possible to identify a variable as being in FLASH, and accessing them without the need to use a pointer. #include <stdio.h> psv int foo attribute ((space(psv))) = 1; psv float bar attribute ((space(psv))) = 3.14159; psv int eek[256] attribute ((space(psv))) = { 200,201,202 ; main() { fprintf(stderr,"foo (@ 0x%6.6lx) is: %d\n", &foo, foo); fprintf(stderr,"bar (@ 0x%6.6lx) is: %f\n", &bar, bar); fprintf(stderr,"eek[2] (@ 0x%6.6lx) is: %d\n", &eek[2], eek[2]); Running this under the simulator might yield the following to stdout: foo (@ 0x004459) is: 1 bar (@ 0x004451) is: 3.141590 eek[2] (@ 0x004059) is: 202 The correct answers, but those addresses do look odd! In order to make certain operations easier, the compiler represents the PSV addresses in a nonstandard way. If you d like to decompose them, the format of a 24-bit pointer (consuming 32-bits) is: bits 31... 24 23... 16 15... 1 0 padding PSV page PSV offset PSV offset 8 bits 8 bits bits 0 to 14 bit 15 5 Managed PSV Pointers - ISR Considerations A data access using 24-bit pointers is definitely non-atomic. Furthermore an interrupt service routine never really knows what the current state of the PSVPAG register will be. Unfortunately the compiler is not really in any position to determine whether or not this is important in all cases. The compiler will make the simplifying assumption that the writer of the interrupt service routine will know whether or not the the auto, compiler managed, PSVPAG is required by the ISR (or any functions called by the ISR) and will request that the programmer specify whether or not it is necessary to assert the default setting of the the 10

PSVPAG register. This is achieved by adding a further attribute to the interrupt function definition: auto psv For example: no auto psv the compiler will set the PSVPAG register to the correct value for auto psv or const (by default) variables, and restore the PSVPAG before returning the compiler will not set the PSVPAG register void attribute ((interrupt, no_auto_psv)) _T1Interrupt(void) { IFS0bits.T1IF = 0; Current code (that does not assert this) may not execute properly unless recompiled. When recompiled, if no indication is made, the compiler will generate a warning message and select the auto psv model. The choice is provided so that programmers that are especially conscious of interrupt latency may select the best option for them. Saving and setting the PSVPAG will consume approximately 3 cycles at the entry to the function and one further cycle to restore the setting upon exist from the function. Note that boot or secure interrupt service routines will use a different setting of the PSVPAG register for their constant data from interrupt routines in a general FLASH area. 6 Support information Questions, comments or suggestions can be sent to Microchip in the usual ways: via your FSE/FAE representive, directly through support@microchip.com. 11