From de75051afa1c0c5d1877ceb4a92d4c23b0e868af Mon Sep 17 00:00:00 2001 From: Werner Almesberger Date: Thu, 21 Oct 2010 10:03:42 -0300 Subject: [PATCH] Support different targets. (Openmoko GTA01/02 with Dbgv3, soon c2ben.) - f32x/Makefile: added support for building for different targets (for now, just TARGET=om) - f32x/c2-drv.h: interface for C2 drivers - f32x/c2-om.c: updated title - f32x/c2-om.c: renamed all c2_* to om_* and made them "static" - f32x/c2-om.c (c2_om): driver operations - f32x/c2.c: call driver operations - f32x/c2.h: moved protocol constants to c2-drv.h --- f32x/Makefile | 31 ++++++++++++++++-------- f32x/c2-drv.h | 36 ++++++++++++++++++++++++++++ f32x/c2-om.c | 33 ++++++++++++++++++-------- f32x/c2.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ f32x/c2.h | 6 ----- 5 files changed, 146 insertions(+), 26 deletions(-) create mode 100644 f32x/c2-drv.h create mode 100644 f32x/c2.c diff --git a/f32x/Makefile b/f32x/Makefile index 3db9ae9..f19bb4e 100644 --- a/f32x/Makefile +++ b/f32x/Makefile @@ -1,8 +1,8 @@ # # f32x/Makefile - Build the C8051F326/7 Flash programmer # -# Written 2008 by Werner Almesberger -# Copyright 2008 Werner Almesberger +# Written 2008, 2010 by Werner Almesberger +# Copyright 2008, 2010 Werner Almesberger # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -11,15 +11,26 @@ # -CC=arm-angstrom-linux-gnueabi-gcc - -CFLAGS=-Wall -Wshadow -g -O -LDFLAGS= - PREFIX=/usr -NAME=f32x -OBJS=f32x.o flash.o c2-om.o gpio.o rt.o boundary.o +ifeq ($(TARGET),) +TARGET = om +endif + +CC_om = arm-angstrom-linux-gnueabi-gcc + +CFLAGS_om = -O -DDRIVER=c2_om + +LDFLAGS_om = + +OBJS_om = c2-om.o gpio.o rt.o + +NAME = f32x +CC = $(CC_$(TARGET)) +CFLAGS = -Wall -Wshadow -g $(CFLAGS_$(TARGET)) +LDFLAGS = $(LDFLAGS_$(TARGET)) +OBJS = f32x.o flash.o c2.o boundary.o $(OBJS_$(TARGET)) + .PHONY: all install uninstall clean depend spotless @@ -45,7 +56,7 @@ include .depend endif clean: - rm -f $(OBJS) .depend + rm -f $(OBJS) $(OBJS_om) .depend spotless: clean rm -f $(NAME) diff --git a/f32x/c2-drv.h b/f32x/c2-drv.h new file mode 100644 index 0000000..6ad1485 --- /dev/null +++ b/f32x/c2-drv.h @@ -0,0 +1,36 @@ +/* + * f32x/c2-drv.h - C2 driver interface + * + * Written 2010 by Werner Almesberger + * Copyright 2010 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#ifndef C2_DRV_H +#define C2_DRV_H + + +#include + + +#define C2_DATA_READ 0 +#define C2_DATA_WRITE 1 +#define C2_ADDR_READ 2 +#define C2_ADDR_WRITE 3 + + +struct c2_ops { + void (*init)(void); + void (*reset)(void); + void (*addr_write)(uint8_t addr); + uint8_t (*addr_read)(void); + void (*data_write)(uint32_t data, int bytes); + uint32_t (*data_read)(int bytes) ; +}; + +#endif /* !C2_DRV_H */ diff --git a/f32x/c2-om.c b/f32x/c2-om.c index 0b4e738..1852de1 100644 --- a/f32x/c2-om.c +++ b/f32x/c2-om.c @@ -1,8 +1,8 @@ /* - * f32x/c2.c - Basic C2 messages + * f32x/c2-om.c - Basic C2 messages, driver for Openmoko GTA01/GTA02+DebugV3 * - * Written 2008 by Werner Almesberger - * Copyright 2008 Werner Almesberger + * Written 2008, 2010 by Werner Almesberger + * Copyright 2008, 2010 Werner Almesberger * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -15,7 +15,7 @@ #include #include "gpio.h" -#include "c2.h" +#include "c2-drv.h" /* @@ -64,7 +64,7 @@ static uint32_t c2_recv(int bits) /* ----- C2 Register read/write -------------------------------------------- */ -void c2_addr_write(uint8_t addr) +static void om_addr_write(uint8_t addr) { c2_pulse(); gpio_output(C2D); @@ -75,7 +75,7 @@ void c2_addr_write(uint8_t addr) } -uint8_t c2_addr_read(void) +static uint8_t om_addr_read(void) { c2_pulse(); gpio_output(C2D); @@ -86,7 +86,7 @@ uint8_t c2_addr_read(void) } -void c2_data_write(uint32_t data, int bytes) +static void om_data_write(uint32_t data, int bytes) { c2_pulse(); gpio_output(C2D); @@ -99,7 +99,7 @@ void c2_data_write(uint32_t data, int bytes) } -uint32_t c2_data_read(int bytes) +static uint32_t om_data_read(int bytes) { c2_pulse(); gpio_output(C2D); @@ -115,7 +115,7 @@ uint32_t c2_data_read(int bytes) /* ----- C2 initialization ------------------------------------------------- */ -void c2_init(void) +static void om_init(void) { gpio_init(); gpio_input(C2D); @@ -127,7 +127,7 @@ void c2_init(void) } -void c2_reset(void) +static void om_reset(void) { gpio_input(C2D); gpio_low(C2CK); @@ -136,3 +136,16 @@ void c2_reset(void) gpio_output(C2CK); gpio_high(C2CK); } + + +/* ----- Operations -------------------------------------------------------- */ + + +struct c2_ops c2_om = { + .init = om_init, + .reset = om_reset, + .addr_write = om_addr_write, + .addr_read = om_addr_read, + .data_write = om_data_write, + .data_read = om_data_read, +}; diff --git a/f32x/c2.c b/f32x/c2.c new file mode 100644 index 0000000..62c5810 --- /dev/null +++ b/f32x/c2.c @@ -0,0 +1,66 @@ +/* + * f32x/c2.c - Basic C2 messages + * + * Written 2010 by Werner Almesberger + * Copyright 2010 Werner Almesberger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + + +#include + +#include "c2.h" +#include "c2-drv.h" + + +static struct c2_ops *c2_ops; + + +/* ----- C2 Register read/write -------------------------------------------- */ + + +void c2_addr_write(uint8_t addr) +{ + c2_ops->addr_write(addr); +} + + +uint8_t c2_addr_read(void) +{ + return c2_ops->addr_read(); +} + + +void c2_data_write(uint32_t data, int bytes) +{ + c2_ops->data_write(data, bytes); +} + + +uint32_t c2_data_read(int bytes) +{ + return c2_ops->data_read(bytes); +} + + +/* ----- C2 initialization ------------------------------------------------- */ + + +void c2_init(void) +{ + extern struct c2_ops DRIVER; + + c2_ops = &DRIVER; + if (c2_ops->init) + c2_ops->init(); +} + + +void c2_reset(void) +{ + c2_ops->reset(); +} diff --git a/f32x/c2.h b/f32x/c2.h index 2fd8739..36135cd 100644 --- a/f32x/c2.h +++ b/f32x/c2.h @@ -18,12 +18,6 @@ #include -#define C2_DATA_READ 0 -#define C2_DATA_WRITE 1 -#define C2_ADDR_READ 2 -#define C2_ADDR_WRITE 3 - - void c2_addr_write(uint8_t addr); uint8_t c2_addr_read(void); void c2_data_write(uint32_t data, int bytes);