ESTE: Light Keyboard from Scrach using GNU GCC and Binutils

De MediaWiki do Campus São José
Revisão de 15h57min de 15 de abril de 2016 por Arliones.hoeller (discussão | contribs) (Criou página com 'In the light keyboard exercise, you relied on the compiler to solve some annoying tasks in embedded system programming, such as interrupt handler generation and language integrat...')
(dif) ← Edição anterior | Revisão atual (dif) | Versão posterior → (dif)
Ir para navegação Ir para pesquisar

In the light keyboard exercise, you relied on the compiler to solve some annoying tasks in embedded system programming, such as interrupt handler generation and language integration. Let's suppose now that you were supplied a very simple compiler that isn't able to perform such tasks. This a rather normal situation in embedded systems development and, if you're a privileged developer that has the proper tools available, knowing the details behind such tasks is never useless.

So try now to reimplement the light keyboard (specially the part in which the button must be pressed for four seconds before leds are lit) considering the following restrictions:

  • Interrupt handlers must be implemented as C routines;
  • The system has now severe time constraints and the compiler handling of read and write operations on the I/O ports isn't adequate anymore, and you'll need to manually encode IN/OUT assembly instructions to give the system a good performance;
  • The compiler isn't able to automatically handle ISRs and interrupt vector generation anymore, and you'll need to manually build the interrupt vector and implement the ISRs (complete with context saving and context restoring operations);
  • GCC's initialization routines are taking too long ! Now you'll have to implement them by yourself.

Usefull links

  • AVR Instruction Set
  • ATMega328P manual
  • GCC - Declaring Attributes of Functions
  • GNU Binary Utilities documentation
  • GNU - Inline-Assembly-HOWTO
  • Memory Sections - AVR-GCC
  • GCC - Optimization control
  • Google

Some tips

  • Compile with -S and take a look at the generated assembly code. Pay attention on the code generated for the interrupt handlers;
  • Use objdump from binutils to see the generated assembly code for your elf file. Take a look at what needs to be done before running your main() function;
  • Compiling with -nostartfiles -nodefaultlibs will remove the interrupt vector and all initialization routines;
  • syntax.c and syntax_weak.c contains examples of some usefull function attributes.