02.03.2014 Views

BSP Developer's Guide

BSP Developer's Guide

BSP Developer's Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

VxWorks 5.5<br />

<strong>BSP</strong> Developer’s <strong>Guide</strong><br />

Access Macros<br />

Every access to chip registers should be made through macros that can be<br />

redefined to accommodate different access methods. Usually, just a read and a<br />

write macro should suffice. In some cases, a modify macro to change individual<br />

bits in a register is also needed. For example:<br />

M68681_READ(addr, pData)<br />

M68681_WRITE(addr, data)<br />

M68681_CLR_SET(addr, clear_bits, set_bits)<br />

Accesses to a command block in memory or on a bus must also be through a<br />

redefinable macro to accommodate byte swapping and address manipulation.<br />

Note that read macros are passed the address of where to return the value read.<br />

They do not return a value like a subroutine returns a value. This is deliberate.<br />

Macros written this way can be replaced by a simple statements, subroutine calls,<br />

or by a block statement. Macros written to return a value cannot be replaced by a<br />

C block statement. For example:<br />

xxx = M68681_READ (x); /* Limited */<br />

M68681_READ (x, &xxx); /* Better */<br />

Minimize preprocessor conditional expressions within code blocks. They should<br />

add to the readability of the code, not reduce it. If the conditional only changes the<br />

value of an argument to a routine, it should be done at the beginning of the file<br />

using a #define. Only conditional expressions that actually change the flow of logic<br />

should be within a function.<br />

In this example, the only change is to one argument of a subroutine call. Putting<br />

the conditional statements inside the subroutine only confuses the reader. It does<br />

this because it has absolutely no effect on the flow of execution.<br />

#ifdef INCL_FOO<br />

fooReset (&myFoo,<br />

#else<br />

fooReset (&yourFoo,<br />

#endif<br />

arg2, arg3, arg4);<br />

98

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!