Loading...
Searching...
No Matches
periph_gba.h File Reference

GBA specific definitions for internal peripheral handling. More...

Detailed Description

GBA specific definitions for internal peripheral handling.

Author
Bennet Blischke

Definition in file periph_gba.h.

#include <stdint.h>
#include "assert.h"
+ Include dependency graph for periph_gba.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  gba_timer
 Struct whose members map onto the timer register. More...
 
struct  gba_uart
 Struct whose members map onto the uart register. More...
 

Macros

#define GBA_TIMER_MAX_TICKS   (0xFFFF)
 We have 16 bit timer.
 
#define GBA_SIO_SCNT   REG16(0x4000128)
 Serial IO control register.
 
#define GBA_SIO_DATA8   REG8(0x400012A)
 Serial IO 8bit data in/out.
 
#define GBA_SIO_RCNT   REG16(0x4000134)
 Serial IO mode selection register.
 
#define GBA_UART   ((volatile gba_uart_t *) 0x4000128)
 The GBA uart (it's the SIO_SCNT register type casted)
 
#define GBA_DISPCNT   REG16(0x4000000)
 Display Control register.
 
#define GBA_DISPSTAT   REG16(0x4000004)
 General LCD Status register.
 
#define GBA_VRAM_PALETTE   MEM16(0x5000000)
 VRAM color palette memory.
 
#define GBA_VRAM   MEM16(0x6000000)
 VRAM, 96Kb, 0x6017FFF - size depends on display mode!
 

Typedefs

typedef volatile gba_timer gba_timer_t
 The type for the GBA timers.
 
typedef struct gba_uart gba_uart_t
 The type for the GBA uart.
 
#define REG32(ADDR)
 Type for 32-bit registers.
 
#define REG16(ADDR)
 Type for 16-bit registers.
 
#define REG8(ADDR)
 Type for 8-bit registers.
 
#define MEM16(ADDR)
 Type for 16-bit memory addresses.
 
#define GBA_PTR_TO_IRQ_HANDLER   REG32(0x3007ffc)
 Pointer to our IRQ handler, must be in 32bit ARM code.
 
#define GBA_IE   REG16(0x4000200)
 Interrupt enable register.
 
#define GBA_IE_TIMERS   (0x0F << 3)
 Bit mask for the timer interrupts enable-flag.
 
#define GBA_IE_UART   (1 << 7)
 Bit mask for the uart interrupt enable-flag.
 
#define GBA_IF   REG16(0x4000202)
 Interrupt flags register.
 
#define GBA_IF_CLEAR_ALL   (0x3FFF)
 Bit mask to clear all pending interrupts.
 
#define GBA_IF_TIMERS   (0x0F << 3)
 Bit mask for the timer interrupts has-fired-flag.
 
#define GBA_IF_UART   (1 << 7)
 Bit mask for the uart/serial interrupt has-fired-flag.
 
#define GBA_IME   REG16(0x4000208) /* Technically 32 bit reg, but only bit 0 is used */
 Interrupt Master Enable, globally enables / disables interrupts.
 

Timer control register

#define GBA_TM0_CNT_L   REG16(0x4000100)
 current value
 
#define GBA_TM0_CNT_H   REG16(0x4000102)
 settings
 
#define GBA_TM1_CNT_L   REG16(0x4000104)
 current value
 
#define GBA_TM1_CNT_H   REG16(0x4000106)
 settings
 
#define GBA_TM2_CNT_L   REG16(0x4000108)
 current value
 
#define GBA_TM2_CNT_H   REG16(0x400010A)
 settings
 
#define GBA_TM3_CNT_L   REG16(0x400010C)
 current value
 
#define GBA_TM3_CNT_H   REG16(0x400010E)
 settings
 
#define GBA_TIMER_FRQ_16K   (16400lu)
 Possible timer frequencies.
 
#define GBA_TIMER_FRQ_65K   (65500lu)
 F = 65.5kHz.
 
#define GBA_TIMER_FRQ_262K   (262200lu)
 F = 262.2kHz.
 
#define GBA_TIMER_FRQ_16M   (16780000lu)
 F = 16.78MHz.
 
#define GBA_TIMER_0   ((gba_timer_t *)0x4000100)
 The four timers of the GBA.
 
#define GBA_TIMER_1   ((gba_timer_t *)0x4000104)
 A GBA timer.
 
#define GBA_TIMER_2   ((gba_timer_t *)0x4000108)
 A GBA timer.
 
#define GBA_TIMER_3   ((gba_timer_t *)0x400010C)
 A GBA timer.
 
#define GBA_SCREEN_WIDTH   (240)
 Screen dimension in pixel.
 
#define GBA_SCREEN_HEIGHT   (160)
 height
 

Settings for GBA_DISPCNT

#define GBA_DISPCNT_BGMODE_0   0x0000
 Tiled, four layers, up to 1024 tiles.
 
#define GBA_DISPCNT_BGMODE_1   0x0001
 Tiled, three layers, up to 1024 tiles.
 
#define GBA_DISPCNT_BGMODE_2   0x0002
 Tiled, two layers, up to 1024 tiles.
 
#define GBA_DISPCNT_BGMODE_3   0x0003
 Bitmap, 240x160, 15-bit RGB.
 
#define GBA_DISPCNT_BGMODE_4   0x0004
 Bitmap, 240x160, 8-bit RGB.
 
#define GBA_DISPCNT_BGMODE_5   0x0005
 Bitmap, 160x128, 15-bit RGB.
 
#define GBA_DISPCNT_SDBG_0   0x0100
 Enable display of background 0.
 
#define GBA_DISPCNT_SDBG_1   0x0200
 Enable display of background 1.
 
#define GBA_DISPCNT_SDBG_2   0x0400
 Enable display of background 2.
 
#define GBA_DISPCNT_SDBG_3   0x0800
 Enable display of background 3.
 
#define GBA_DISPCNT_SDOBJ   0x1000
 Enable display of objects.
 

LCD background control registers

#define GBA_BG0CNT   REG16(0x4000008)
 BG0.
 
#define GBA_BG1CNT   REG16(0x400000a)
 BG1.
 
#define GBA_BG2CNT   REG16(0x400000c)
 BG2.
 
#define GBA_BG3CNT   REG16(0x400000e)
 BG3.
 

Macro Definition Documentation

◆ GBA_BG0CNT

#define GBA_BG0CNT   REG16(0x4000008)

BG0.

Definition at line 273 of file periph_gba.h.

◆ GBA_BG1CNT

#define GBA_BG1CNT   REG16(0x400000a)

BG1.

Definition at line 274 of file periph_gba.h.

◆ GBA_BG2CNT

#define GBA_BG2CNT   REG16(0x400000c)

BG2.

Definition at line 275 of file periph_gba.h.

◆ GBA_BG3CNT

#define GBA_BG3CNT   REG16(0x400000e)

BG3.

Definition at line 276 of file periph_gba.h.

◆ GBA_DISPCNT

#define GBA_DISPCNT   REG16(0x4000000)

Display Control register.

Definition at line 243 of file periph_gba.h.

◆ GBA_DISPCNT_BGMODE_0

#define GBA_DISPCNT_BGMODE_0   0x0000

Tiled, four layers, up to 1024 tiles.

Definition at line 249 of file periph_gba.h.

◆ GBA_DISPCNT_BGMODE_1

#define GBA_DISPCNT_BGMODE_1   0x0001

Tiled, three layers, up to 1024 tiles.

Definition at line 250 of file periph_gba.h.

◆ GBA_DISPCNT_BGMODE_2

#define GBA_DISPCNT_BGMODE_2   0x0002

Tiled, two layers, up to 1024 tiles.

Definition at line 251 of file periph_gba.h.

◆ GBA_DISPCNT_BGMODE_3

#define GBA_DISPCNT_BGMODE_3   0x0003

Bitmap, 240x160, 15-bit RGB.

Definition at line 252 of file periph_gba.h.

◆ GBA_DISPCNT_BGMODE_4

#define GBA_DISPCNT_BGMODE_4   0x0004

Bitmap, 240x160, 8-bit RGB.

Definition at line 253 of file periph_gba.h.

◆ GBA_DISPCNT_BGMODE_5

#define GBA_DISPCNT_BGMODE_5   0x0005

Bitmap, 160x128, 15-bit RGB.

Definition at line 254 of file periph_gba.h.

◆ GBA_DISPCNT_SDBG_0

#define GBA_DISPCNT_SDBG_0   0x0100

Enable display of background 0.

Definition at line 256 of file periph_gba.h.

◆ GBA_DISPCNT_SDBG_1

#define GBA_DISPCNT_SDBG_1   0x0200

Enable display of background 1.

Definition at line 257 of file periph_gba.h.

◆ GBA_DISPCNT_SDBG_2

#define GBA_DISPCNT_SDBG_2   0x0400

Enable display of background 2.

Definition at line 258 of file periph_gba.h.

◆ GBA_DISPCNT_SDBG_3

#define GBA_DISPCNT_SDBG_3   0x0800

Enable display of background 3.

Definition at line 259 of file periph_gba.h.

◆ GBA_DISPCNT_SDOBJ

#define GBA_DISPCNT_SDOBJ   0x1000

Enable display of objects.

Definition at line 261 of file periph_gba.h.

◆ GBA_DISPSTAT

#define GBA_DISPSTAT   REG16(0x4000004)

General LCD Status register.

Definition at line 267 of file periph_gba.h.

◆ GBA_IE

#define GBA_IE   REG16(0x4000200)

Interrupt enable register.

Bit Expl. 0 LCD V-Blank 1 LCD H-Blank 2 LCD V-Counter Match 3 Timer 0 Overflow 4 Timer 1 Overflow 5 Timer 2 Overflow 6 Timer 3 Overflow 7 Serial Communication 8 DMA 0 9 DMA 1 10 DMA 2 11 DMA 3 12 Keypad 13 Game Pak (external IRQ source) 14-15 Not used

Definition at line 71 of file periph_gba.h.

◆ GBA_IE_TIMERS

#define GBA_IE_TIMERS   (0x0F << 3)

Bit mask for the timer interrupts enable-flag.

Definition at line 76 of file periph_gba.h.

◆ GBA_IE_UART

#define GBA_IE_UART   (1 << 7)

Bit mask for the uart interrupt enable-flag.

Definition at line 81 of file periph_gba.h.

◆ GBA_IF

#define GBA_IF   REG16(0x4000202)

Interrupt flags register.

Bit Expl. 0 LCD V-Blank 1 LCD H-Blank 2 LCD V-Counter Match 3 Timer 0 Overflow 4 Timer 1 Overflow 5 Timer 2 Overflow 6 Timer 3 Overflow 7 Serial Communication 8 DMA 0 9 DMA 1 10 DMA 2 11 DMA 3 12 Keypad 13 Game Pak (external IRQ source) 14-15 Not used

Definition at line 103 of file periph_gba.h.

◆ GBA_IF_CLEAR_ALL

#define GBA_IF_CLEAR_ALL   (0x3FFF)

Bit mask to clear all pending interrupts.

Definition at line 108 of file periph_gba.h.

◆ GBA_IF_TIMERS

#define GBA_IF_TIMERS   (0x0F << 3)

Bit mask for the timer interrupts has-fired-flag.

Definition at line 113 of file periph_gba.h.

◆ GBA_IF_UART

#define GBA_IF_UART   (1 << 7)

Bit mask for the uart/serial interrupt has-fired-flag.

Definition at line 118 of file periph_gba.h.

◆ GBA_IME

#define GBA_IME   REG16(0x4000208) /* Technically 32 bit reg, but only bit 0 is used */

Interrupt Master Enable, globally enables / disables interrupts.

We usually keep this register enabled but use the "official" ARM IME register for our needs

Definition at line 125 of file periph_gba.h.

◆ GBA_PTR_TO_IRQ_HANDLER

#define GBA_PTR_TO_IRQ_HANDLER   REG32(0x3007ffc)

Pointer to our IRQ handler, must be in 32bit ARM code.

Definition at line 49 of file periph_gba.h.

◆ GBA_SCREEN_HEIGHT

#define GBA_SCREEN_HEIGHT   (160)

height

Definition at line 237 of file periph_gba.h.

◆ GBA_SCREEN_WIDTH

#define GBA_SCREEN_WIDTH   (240)

Screen dimension in pixel.

width

Definition at line 236 of file periph_gba.h.

◆ GBA_SIO_DATA8

#define GBA_SIO_DATA8   REG8(0x400012A)

Serial IO 8bit data in/out.

Definition at line 195 of file periph_gba.h.

◆ GBA_SIO_RCNT

#define GBA_SIO_RCNT   REG16(0x4000134)

Serial IO mode selection register.

Definition at line 200 of file periph_gba.h.

◆ GBA_SIO_SCNT

#define GBA_SIO_SCNT   REG16(0x4000128)

Serial IO control register.

Definition at line 190 of file periph_gba.h.

◆ GBA_TIMER_0

#define GBA_TIMER_0   ((gba_timer_t *)0x4000100)

The four timers of the GBA.

A GBA timer

Definition at line 181 of file periph_gba.h.

◆ GBA_TIMER_1

#define GBA_TIMER_1   ((gba_timer_t *)0x4000104)

A GBA timer.

Definition at line 182 of file periph_gba.h.

◆ GBA_TIMER_2

#define GBA_TIMER_2   ((gba_timer_t *)0x4000108)

A GBA timer.

Definition at line 183 of file periph_gba.h.

◆ GBA_TIMER_3

#define GBA_TIMER_3   ((gba_timer_t *)0x400010C)

A GBA timer.

Definition at line 184 of file periph_gba.h.

◆ GBA_TIMER_FRQ_16K

#define GBA_TIMER_FRQ_16K   (16400lu)

Possible timer frequencies.

F = 16.4kHz

Definition at line 150 of file periph_gba.h.

◆ GBA_TIMER_FRQ_16M

#define GBA_TIMER_FRQ_16M   (16780000lu)

F = 16.78MHz.

Definition at line 153 of file periph_gba.h.

◆ GBA_TIMER_FRQ_262K

#define GBA_TIMER_FRQ_262K   (262200lu)

F = 262.2kHz.

Definition at line 152 of file periph_gba.h.

◆ GBA_TIMER_FRQ_65K

#define GBA_TIMER_FRQ_65K   (65500lu)

F = 65.5kHz.

Definition at line 151 of file periph_gba.h.

◆ GBA_TIMER_MAX_TICKS

#define GBA_TIMER_MAX_TICKS   (0xFFFF)

We have 16 bit timer.

Definition at line 144 of file periph_gba.h.

◆ GBA_TM0_CNT_H

#define GBA_TM0_CNT_H   REG16(0x4000102)

settings

Definition at line 132 of file periph_gba.h.

◆ GBA_TM0_CNT_L

#define GBA_TM0_CNT_L   REG16(0x4000100)

current value

Definition at line 131 of file periph_gba.h.

◆ GBA_TM1_CNT_H

#define GBA_TM1_CNT_H   REG16(0x4000106)

settings

Definition at line 134 of file periph_gba.h.

◆ GBA_TM1_CNT_L

#define GBA_TM1_CNT_L   REG16(0x4000104)

current value

Definition at line 133 of file periph_gba.h.

◆ GBA_TM2_CNT_H

#define GBA_TM2_CNT_H   REG16(0x400010A)

settings

Definition at line 136 of file periph_gba.h.

◆ GBA_TM2_CNT_L

#define GBA_TM2_CNT_L   REG16(0x4000108)

current value

Definition at line 135 of file periph_gba.h.

◆ GBA_TM3_CNT_H

#define GBA_TM3_CNT_H   REG16(0x400010E)

settings

Definition at line 138 of file periph_gba.h.

◆ GBA_TM3_CNT_L

#define GBA_TM3_CNT_L   REG16(0x400010C)

current value

Definition at line 137 of file periph_gba.h.

◆ GBA_UART

#define GBA_UART   ((volatile gba_uart_t *) 0x4000128)

The GBA uart (it's the SIO_SCNT register type casted)

Definition at line 230 of file periph_gba.h.

◆ GBA_VRAM

#define GBA_VRAM   MEM16(0x6000000)

VRAM, 96Kb, 0x6017FFF - size depends on display mode!

Definition at line 287 of file periph_gba.h.

◆ GBA_VRAM_PALETTE

#define GBA_VRAM_PALETTE   MEM16(0x5000000)

VRAM color palette memory.

Definition at line 282 of file periph_gba.h.

◆ MEM16

#define MEM16 ( ADDR)
Value:
((uint16_t(*))(ADDR))
#define ADDR
ADDR.
Definition tmp00x.h:90

Type for 16-bit memory addresses.

Definition at line 44 of file periph_gba.h.

◆ REG16

#define REG16 ( ADDR)
Value:
(*(uint16_t volatile(*))(ADDR))

Type for 16-bit registers.

Definition at line 34 of file periph_gba.h.

◆ REG32

#define REG32 ( ADDR)
Value:
(*(uint32_t volatile(*))(ADDR))

Type for 32-bit registers.

Definition at line 29 of file periph_gba.h.

◆ REG8

#define REG8 ( ADDR)
Value:
(*(uint8_t volatile(*))(ADDR))

Type for 8-bit registers.

Definition at line 39 of file periph_gba.h.

Typedef Documentation

◆ gba_timer_t

typedef volatile gba_timer gba_timer_t

The type for the GBA timers.

Definition at line 175 of file periph_gba.h.

◆ gba_uart_t

typedef struct gba_uart gba_uart_t

The type for the GBA uart.

Definition at line 225 of file periph_gba.h.