XILINX GPIO驱动分析
High Level – level 1 hardware driver api
Low Level – level 0 hardware driver api
XGPIO.H
#include "xil_types.h"
#include "xil_assert.h"
#include "xstatus.h"
#include "xgpio_l.h"
Define:
XGpio_CfgInitialize
XGpio_SetDataDirection
XGPIO.C
#include "xgpio.h"
#include "xstatus.h"
Implement:
XGpio_CfgInitialize
XGpio_SetDataDirection
<==上面API:
#include "xgpio_l.h" (xgpio low level)
XGPIO_L.H:
#include "xil_types.h"
#include "xil_assert.h"
#include "xil_io.h"
#define XGPIO_DATA_OFFSET 0x0 /**< Data register for 1st channel */
#define XGPIO_TRI_OFFSET 0x1 /**< I/O direction reg for 1st channel */
#define XGPIO_DATA2_OFFSET 0x2 /**< Data register for 2nd channel */
#define XGPIO_TRI2_OFFSET 0x3 /**< I/O direction reg for 2nd channel */
#define XGPIO_GIE_OFFSET 0x47 /**< Global interrupt enable register */
#define XGPIO_ISR_OFFSET 0x48 /**< Interrupt status register */
#define XGPIO_IER_OFFSET 0x4A /**< Interrupt enable register */
#define XGpio_ReadReg Xil_In32 ==> (xil_io.c)
XGPIO_L.C文件不存在,因为LOW LEVEL的驱动全是MACRO写的,不需要C文件实现。
< == 上面API:
#include "xil_io.h"
XIL_IO.H:
#include "xil_types.h"
#include "xpseudo_asm.h"
#include "xil_printf.h"
DEFINE:
u8 Xil_In8(u32 Addr);
u16 Xil_In16(u32 Addr);
u32 Xil_In32(u32 Addr);
XIL_IO.C
#include "xil_io.h"
#include "xil_types.h"
#include "xil_assert.h"
#include "xpseudo_asm.h"
#include "xreg_cortexa9.h"
Implement:
u8 Xil_In8(u32 Addr);
u16 Xil_In16(u32 Addr);
u32 Xil_In32(u32 Addr);
<= =上层API:
H:
#include "xpseudo_asm.h"
C:
#include "xpseudo_asm.h"
#include "xreg_cortexa9.h"
XPSEUDO_ASM.H 没有C文件
#include "xreg_cortexa9.h"
#include "xpseudo_asm_gcc.h"
XREG_CORTEXA9.H 没有C文件
/* GPRs */
#define XREG_GPR0 r0
#define XREG_GPR1 r1
#define XREG_GPR2 r2
#define XREG_GPR14 r14
#define XREG_GPR15 r15
#define XREG_CPSR cpsr
XPSEUDO_ASM_GCC.H:没有C文件
/* pseudo assembler instructions */
#define mfcpsr() ({unsigned int rval; \
__asm__ __volatile__(\
"mrs %0, cpsr\n"\
: "=r" (rval)\
);\
rval;\
})
/* Memory Operations */
#define ldr(adr) ({unsigned long rval; \
__asm__ __volatile__(\
"ldr %0,[%1]"\
: "=r" (rval) : "r" (adr)\
);\
rval;\
})
下图是各个文件与其对应的功能图:
下图是GPIO模块驱动API的层次结构图: