view target-utils/include/timer.h @ 964:a96cb97b66a2

ringtools/imy: fix duplicate definition of tdma_durations[] The bug was reported by Vadim Yanitskiy <fixeria@osmocom.org>, although the present fix is slightly different from the contributed patch: because main.c doesn't need this tdma_durations[] array at all, let's simply remove the reference to this array from main.c rather than turn it into an extern. I no longer remember my original thought flow that resulted (by mistake) in tdma_durations[] being multiply defined in main.c and durations.c. My intent might have been to define all globals in main.c and have the reference in durations.c be an extern - and I missed that extern - but without clear memory, I have no certainty. In any case, having this data array defined in the same module that fills it (durations.c) is sensible, so let's make it the new way.
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 31 Aug 2023 19:38:18 +0000
parents 0f11da299b7d
children
line wrap: on
line source

/*
 * Definitions for Calypso general-purpose timer registers
 *
 * This header is usable from both .c and .S source files.
 */

#ifndef _CALYPSO_TIMER_H
#define _CALYPSO_TIMER_H

#define	TIMER1_BASE_ADDR	0xFFFE3800
#define	TIMER2_BASE_ADDR	0xFFFE6800

#ifdef __ASSEMBLER__

/*
 * Assembly source with cpp
 *
 * The most convenient way to access registers like these from ARM
 * assembly is to load the base address of the register block in some
 * ARM register, using only one ldr rN, =xxx instruction and only one
 * literal pool entry, and then access various registers in the block
 * from the same base using the immediate offset addressing mode.
 *
 * Here we define the offsets for the usage scenario above.
 */

#define	CNTL_TIM	0x00
#define	LOAD_TIM	0x02
#define	READ_TIM	0x04

#else

/*
 * C source
 *
 * For access from C, we define the layout of each timer register block
 * as a struct, and then define a pleudo-global-var for easy "volatile"
 * access to each of the 2 timers.
 */

struct timer_regs {
	unsigned char	cntl;
	unsigned char	pad;
	unsigned short	load;
	unsigned short	read;
};

#define	TIMER1_REGS	(*(volatile struct timer_regs *) TIMER1_BASE_ADDR)
#define	TIMER2_REGS	(*(volatile struct timer_regs *) TIMER2_BASE_ADDR)

#endif

/* CNTL register bit definitions */
#define	CNTL_START		0x01
#define	CNTL_AUTO_RELOAD	0x02
#define	CNTL_CLOCK_ENABLE	0x20

#endif /* include guard */