Digital Signal Processing Reference
In-Depth Information
Below, each type of peripheral access is discussed. As an example, the C code
necessary to provide a one second delay using each method is shown in Figures
16.4-6.
#include “system.h”
#include “altera_avalon_timer_regs.h”
int main( void ) {
IOWR_ALTERA_AVALON_TIMER_PERIODL( TIMER0_BASE,
(48000000 & 0xFFFF) );
IOWR_ALTERA_AVALON_TIMER_PERIODH( TIMER0_BASE,
((48000000>>16) & 0xFFFF) );
IOWR_ALTERA_AVALON_TIMER_STATUS( TIMER0_BASE, 0 );
IOWR_ALTERA_AVALON_TIMER_CONTROL( TIMER0_BASE, 0x4 );
while( (IORD_ALTERA_AVALON_TIMER_STATUS( TIMER0_BASE ) &
ALTERA_AVALON_TIMER_STATUS_TO_MSK) == 0 ) {}
}
Figure 16.4 This is the C code necessary for providing a one second delay by directly accessing the
system timer's registers. The timer peripheral in this system is called timer0 .
Direct Register Access
Each peripheral's registers can be directly accessed through read and write
macros that are defined in each component's device driver header file. This
type of communication is the lowest level and while it provides the most
flexibility in interfacing with peripherals, it can also be the most tedious. As
illustrated in Figure 16.4, interfacing with the timer device can be quite
cumbersome, even to provide a relatively straight-forward function such as a
one second delay. If you read the actual count to determine elapsed time, you
also need to keep in mind how your code will function when the timer count
wraps around and starts over.
Search WWH ::




Custom Search