July 2025
Beginner
528 pages
13h 18m
English
This chapter contains two header files for the abstract microcontroller AM0 used in chapters 17 to 19: am0_regs.h, which defines the memory-mapped peripheral registers, and am0.h, which defines application programming interface (API) for accessing the peripherals.
A microcontroller vendor typically provides a platform header file that contains definitions of all the memory-mapped registers. Since we have defined the AM0 peripherals, let us create its header file am0_regs.h.
Quite often, a header file also includes definitions of individual bits and their positions within a register. We will omit these from am0_regs.h for simplicity.
#ifndef AM0_REGS_H#define AM0_REGS_H#define IOREG(addr) (*(volatile long *)(addr))#define GPIO_DAT IOREG(0x40001000) // GPIO data register#define GPIO_DIR IOREG(0x40001004) // GPIO direction register#define GPIO_INT IOREG(0x40001008) // GPIO interrupt enable register#define TIMER_CSR IOREG(0x40002000) // Timer control and status register#define TIMER_RVR IOREG(0x40002004) // Timer reload value register#define TIMER_CVR IOREG(0x40002008) // Timer current value register#define ADC_DAT IOREG(0x40003000) // ADC data register#define DAC_DAT IOREG(0x40004000) // DAC data register#define UART_CSR IOREG(0x40005000) // UART control and status register#define UART_RDR IOREG(0x40005004) // UART receive data register#define UART_TDR IOREG(0x40005008) // UART transmit data register#define ...
Read now
Unlock full access