avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] Fixing function locations


From: Dave Hansen
Subject: Re: [avr-gcc-list] Fixing function locations
Date: Wed, 07 Jan 2004 15:16:42 -0500


From: "E. Weddington" <address@hidden>
[...]
On 7 Jan 2004 at 16:36, Tom Maughan wrote:

> Is it possible to fix the location of a function to a specific flash address?
>
> I'm writing some bootloader code which no doubt will get changed in the
> future but I'd like to fix certain externally accessable functions to
> specific address locations such that if I run maincode designed for a
> newer version of the bootloader it won't die horribly.
> Many thanks,


In brief, place your function(s) in it's own named section and then relocate
that section to the desired address.

There's something else you might want to do from a design standpoint. I've never done it on an AVR, but I would guess the mechanics are similar to what Eric has described.

In your bootloader, define an array of pointers to functions. If some of the functions require parameters, pass them through a void pointer. That way you can declare a struct to pass whatever parameters you require, and even use the same struct for return values. E.g.:

  void (*API_function[NUM_API_FNS])(void *) = {<function list>};

Locate this array in a fixed location in flash (probably using a mechanism similar tto that described by Eric).

Your application code can define the same array (extern), along with some symbols to index the array and the parameter structures. Then to call the functions, you would used something like:

  #include "bootloaderapi.h"

  PARM_API_START_BOOTLOADER start;
  PARM_API_GET_VERSION ver;

  API_function[GET_VERSION](&ver);
  if (ver.major < 1) {
     error("Test Version of Bootloader");
  }else{
     start.mode = MODE_API_COLD_BOOT;
     API_function[START_BOOTLOADER](&start);
  }

The advantage to doing it this way is maintenance: Even if the functions change size or must move, the pointers don't. If you need to add API functions, you simply extend the array. The scheme is similar to the software interrupt BIOS interface.

HTH,
  -=Dave

_________________________________________________________________
Enjoy a special introductory offer for dial-up Internet access — limited time only! http://join.msn.com/?page=dept/dialup



reply via email to

[Prev in Thread] Current Thread [Next in Thread]