Browse Source

Added sketch of bit-bashing interface common code

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
e90b64d625
3 changed files with 100 additions and 0 deletions
  1. 1
    0
      src/Makefile
  2. 55
    0
      src/drivers/bitbash/bitbash.c
  3. 44
    0
      src/include/gpxe/bitbash.h

+ 1
- 0
src/Makefile View File

@@ -140,6 +140,7 @@ SRCDIRS		+= drivers/block
140 140
 SRCDIRS		+= drivers/scsi
141 141
 SRCDIRS		+= drivers/ata
142 142
 SRCDIRS		+= drivers/nvs
143
+SRCDIRS		+= drivers/bitbash
143 144
 SRCDIRS		+= interface/pxe
144 145
 SRCDIRS		+= tests
145 146
 

+ 55
- 0
src/drivers/bitbash/bitbash.c View File

@@ -0,0 +1,55 @@
1
+/*
2
+ * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
3
+ *
4
+ * This program is free software; you can redistribute it and/or
5
+ * modify it under the terms of the GNU General Public License as
6
+ * published by the Free Software Foundation; either version 2 of the
7
+ * License, or any later version.
8
+ *
9
+ * This program is distributed in the hope that it will be useful, but
10
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
+ * General Public License for more details.
13
+ *
14
+ * You should have received a copy of the GNU General Public License
15
+ * along with this program; if not, write to the Free Software
16
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
+ */
18
+
19
+#include <timer.h>
20
+#include <gpxe/bitbash.h>
21
+
22
+/** @file
23
+ *
24
+ * Bit-bashing interfaces
25
+ *
26
+ */
27
+
28
+/**
29
+ * Set/clear output bit
30
+ *
31
+ * @v basher		Bit-bashing interface
32
+ * @v bit_id		Bit number
33
+ * @v data		Value to write
34
+ * 
35
+ * If @c data is 0, a logic 0 will be written.  If @c data is
36
+ * non-zero, a logic 1 will be written.
37
+ */
38
+void write_bit ( struct bit_basher *basher, unsigned int bit_id,
39
+		 unsigned long data ) {
40
+	basher->write ( basher, bit_id, ( data ? -1UL : 0 ) );
41
+	udelay ( basher->udelay );
42
+}
43
+
44
+/**
45
+ * Read input bit
46
+ *
47
+ * @v basher		Bit-bashing interface
48
+ * @v bit_id		Bit number
49
+ * @ret data		Value read
50
+ *
51
+ * @c data will always be either 0 or 1.
52
+ */
53
+int read_bit ( struct bit_basher *basher, unsigned int bit_id ) {
54
+	return ( basher->read ( basher, bit_id ) ? 1 : 0 );
55
+}

+ 44
- 0
src/include/gpxe/bitbash.h View File

@@ -0,0 +1,44 @@
1
+#ifndef _GPXE_BITBASH_H
2
+#define _GPXE_BITBASH_H
3
+
4
+/** @file
5
+ *
6
+ * Bit-bashing interfaces
7
+ *
8
+ */
9
+
10
+/** A bit-bashing interface */
11
+struct bit_basher {
12
+	/**
13
+	 * Set/clear output bit
14
+	 *
15
+	 * @v basher		Bit-bashing interface
16
+	 * @v bit_id		Bit number
17
+	 * @v data		Value to write
18
+	 * 
19
+	 * @c data will be 0 if a logic 0 should be written (i.e. the
20
+	 * bit should be cleared), or -1UL if a logic 1 should be
21
+	 * written (i.e. the bit should be set).  This is done so that
22
+	 * the method may simply binary-AND @c data with the
23
+	 * appropriate bit mask.
24
+	 */
25
+	void ( * write ) ( struct bit_basher *basher, unsigned int bit_id,
26
+			   unsigned long data );
27
+	/**
28
+	 * Read input bit
29
+	 *
30
+	 * @v basher		Bit-bashing interface
31
+	 * @v bit_id		Bit number
32
+	 * @ret zero		Input is a logic 0
33
+	 * @ret non-zero	Input is a logic 1
34
+	 */
35
+	int ( * read ) ( struct bit_basher *basher, unsigned int bit_id );
36
+	/** Delay between subsequent calls to write(), in microseconds */
37
+	unsigned int udelay;
38
+};
39
+
40
+extern void write_bit ( struct bit_basher *basher, unsigned int bit_id,
41
+			unsigned long data );
42
+extern int read_bit ( struct bit_basher *basher, unsigned int bit_id );
43
+
44
+#endif /* _GPXE_BITBASH_H */

Loading…
Cancel
Save