00001 /* 00002 * Author: Omar Choudary 00003 * 00004 * File used to combine both C and assembler to use a relative timer/counter. 00005 * 00006 * Hepful hints provided by Joerg Wunsch: 00007 * http://www.nongnu.org/avr-libc/user-manual/group__asmdemo.html 00008 * 00009 * --------------------------------------------------------------------------- 00010 * "THE BEER-WARE LICENSE" (Revision 42): 00011 * Joerg Wunsch wrote this file. As long as you retain this notice you 00012 * can do whatever you want with this stuff. If we meet some day, and you think 00013 * this stuff is worth it, you can buy me a beer in return. Joerg Wunsch 00014 * --------------------------------------------------------------------------- 00015 */ 00016 00017 #ifndef _COUNTER_H_ 00018 #define _COUNTER_H_ 00019 00020 /* 00021 * Global register variables. 00022 */ 00023 #ifdef __ASSEMBLER__ 00024 00025 // Syncronization counter, 32 bit value accessed through 4 CONSECUTIVE registers 00026 // In the code, these values should be loaded using the C global variable as follows 00027 # define counter_b0 r18 00028 # define counter_b1 r19 00029 # define counter_b2 r20 00030 # define counter_b3 r21 00031 00032 // Variables used in asm subroutines to store temporary values 00033 # define counter_inc r26 00034 # define counter_sreg r27 00035 00036 #else /* !ASSEMBLER */ 00037 00038 #include <stdint.h> 00039 00040 volatile uint32_t counter_t2; // this will be updated and used in both C and asm code 00041 #define counter_res_us 1024 // each counter unit represents 1024 micro-seconds 00042 #define SYNC_COUNTER_SIZE (sizeof(counter_t2)) // size of counter variable in bytes 00043 00044 #endif /* ASSEMBLER */ 00045 00046 #endif // _COUNTER_H_ 00047