SLIDE 9 Callback functions
1 void (∗ myCallbackFunction )( u i n t 8 t ) ; // g l o b a l f u n c t i o n p o i n t e r v a r i a b l e 2 3 ISR (MY TIMER INTERRUPT , ISR NOBLOCK){ 4 /∗ execute the c a l l b a c k f u n c t i o n ∗/ 5 myCallbackFunction ( 1 ) ; 6 } 7 void s e t c a l l b a c k ( void (∗ c a l l b a c k )( u i n t 8 t )){ 8 myCallbackFunction = c a l l b a c k ; 9 } 10 void myfunc ( u i n t 8 t i ){ 11 . . . 12 } 13 14 i n t main ( void ){ 15 s e t c a l l b a c k ( myfunc ) ; // r e g i s t e r myfunc as c a l l b a c k f u n c t i o n 16 } 147
ATMega1280’s memories
◮ 128 KB program memory (flash)
◮ Biggest memory in ATMega1280 ◮ Great for storing constants
◮ 8 KB internal RAM
◮ RAM size is quite restricted ◮ Beware of stack overflow
◮ 4 KB EEPROM
◮ Useful for storing values that rarely change ◮ Limited number of read/write cycles 148
Using ATMega1280’s memories in C
◮ Memory sections available:
◮ .text: program memory, flash ◮ .data: RAM and flash ◮ .bss: RAM ◮ .eeprom
◮ The .data memory section contains constants and variable
initializations; it occupies both RAM and flash space.
◮ RAM is volatile and therfore not programmable (before
run-time).
◮ Therefore: put constant values into flash alone!
◮ No need to occupy twice the required memory! ◮ How? See Section 5 of the avr-libc manual. 149