Getting Started

(lily) #1

Appendix 3: Debugging Tale


Appendix 3: Debugging Tale


Sometimes you have to search high and low to find out what a something really
means. For instance, we often see the sbi() function, as in Butterfly main.c:


sbi(DDRB, 5); // set OC1A as output
sbi(PORTB, 5); // set OC1A high


We search around a while and eventually in sfr_def.h we find:


/** \def sbi
\ingroup avr_sfr
\deprecated
\code #include <avr/io.h>\endcode
For backwards compatibility only. This macro will eventually be removed.


S b


#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))


his means that sbi() is not a function, it’s a macro, and a deprecated one at that.
y deprecation, they mean that we shouldn’t use in and eventually it may go
away. To understand what it does though, we need to find the definition of
SFR_BYTE(sfr) and _BV(bit) and we can now guess these aren’t functions, but
macros. More searching and in the same header we find:


#define _SFR_BYTE(sfr) _MMIO_BYTE(_SFR_ADDR(sfr))


Hmmm... that’s not a lot of help so more searching to find out what
_MMIO_BYTE and _SFR_ADDR mean. In the same header we find:


#define _MMIO_BYTE(mem_addr) ((volatile uint8_t )(mem_addr))


Okay, we still don’t know. So we look for uint8_t, which is tucked away in the
bf_gcc directory readme.txt:



  • changed some char to uint8_t to avoid compiler warnings.


et it \c bit in IO register \c sfr. */

T

B
Free download pdf