C8051F32x firmware infrastructure
Sign in or create your account | Project List | Help
C8051F32x firmware infrastructure Commit Details
Date: | 2010-10-22 00:09:43 (13 years 5 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | 6a4da0eaefcce12f63a8a7f44fc2d9f546405f26 |
Message: | Moved C2 bitbang functions from c2-om.c to (#included) c2-bitbang.c - f32x/c2-om.c: renamed C2 bitbang functions from om_* to c2_* - f32x/c2-om.c, f32x/c2-bitbang.c: moved most of the content of c2-om.c to c2-bitbang.c and #include c2-bitbang.c - f32x/Makefile: c2-om.o depends on c2-bitbang.c now |
Files: |
f32x/Makefile (1 diff) f32x/c2-bitbang.c (1 diff) f32x/c2-om.c (1 diff) |
Change Details
f32x/Makefile | ||
---|---|---|
55 | 55 | include .depend |
56 | 56 | endif |
57 | 57 | |
58 | c2-om.o: c2-bitbang.c | |
59 | ||
58 | 60 | clean: |
59 | 61 | rm -f $(OBJS) $(OBJS_om) .depend |
60 | 62 |
f32x/c2-bitbang.c | ||
---|---|---|
1 | /* | |
2 | * f32x/c2-bitbang.c - Basic C2 messages, bitbang | |
3 | * | |
4 | * Written 2008, 2010 by Werner Almesberger | |
5 | * Copyright 2008, 2010 Werner Almesberger | |
6 | * | |
7 | * This program is free software; you can redistribute it and/or modify | |
8 | * it under the terms of the GNU General Public License as published by | |
9 | * the Free Software Foundation; either version 2 of the License, or | |
10 | * (at your option) any later version. | |
11 | */ | |
12 | ||
13 | /* | |
14 | * This file is meant to be #included by a .c file that defines C2CK and C2D, | |
15 | * provides the gpio_* functions, etc. | |
16 | */ | |
17 | ||
18 | ||
19 | /* ----- Bit-level operations ---------------------------------------------- */ | |
20 | ||
21 | ||
22 | static void c2_pulse(void) | |
23 | { | |
24 | gpio_low(C2CK); | |
25 | gpio_high(C2CK); | |
26 | } | |
27 | ||
28 | ||
29 | static void c2_send(uint32_t value, int bits) | |
30 | { | |
31 | int i; | |
32 | ||
33 | for (i = 0; i != bits; i++) { | |
34 | gpio_set(C2D, (value >> i) & 1); | |
35 | c2_pulse(); | |
36 | } | |
37 | } | |
38 | ||
39 | ||
40 | static uint32_t c2_recv(int bits) | |
41 | { | |
42 | uint32_t v = 0; | |
43 | int i; | |
44 | ||
45 | for (i = 0; i != bits; i++) { | |
46 | v |= gpio_get(C2D) << i; | |
47 | c2_pulse(); | |
48 | } | |
49 | return v; | |
50 | } | |
51 | ||
52 | ||
53 | /* ----- C2 Register read/write -------------------------------------------- */ | |
54 | ||
55 | ||
56 | static void c2_addr_write(uint8_t addr) | |
57 | { | |
58 | c2_pulse(); | |
59 | gpio_output(C2D); | |
60 | c2_send(C2_ADDR_WRITE, 2); | |
61 | c2_send(addr, 8); | |
62 | gpio_input(C2D); | |
63 | c2_pulse(); | |
64 | } | |
65 | ||
66 | ||
67 | static uint8_t c2_addr_read(void) | |
68 | { | |
69 | c2_pulse(); | |
70 | gpio_output(C2D); | |
71 | c2_send(C2_ADDR_READ, 2); | |
72 | gpio_input(C2D); | |
73 | c2_pulse(); | |
74 | return c2_recv(8); | |
75 | } | |
76 | ||
77 | ||
78 | static void c2_data_write(uint32_t data, int bytes) | |
79 | { | |
80 | c2_pulse(); | |
81 | gpio_output(C2D); | |
82 | c2_send(C2_DATA_WRITE, 2); | |
83 | c2_send(bytes-1, 2); | |
84 | c2_send(data, 8*bytes); | |
85 | gpio_input(C2D); | |
86 | c2_pulse(); | |
87 | while (!c2_recv(1)); | |
88 | } | |
89 | ||
90 | ||
91 | static uint32_t c2_data_read(int bytes) | |
92 | { | |
93 | c2_pulse(); | |
94 | gpio_output(C2D); | |
95 | c2_send(C2_DATA_READ, 2); | |
96 | c2_send(bytes-1, 2); | |
97 | gpio_input(C2D); | |
98 | c2_pulse(); | |
99 | while (!c2_recv(1)); | |
100 | return c2_recv(8*bytes); | |
101 | } | |
102 | ||
103 | ||
104 | /* ----- C2 initialization ------------------------------------------------- */ | |
105 | ||
106 | ||
107 | static void c2_init(void) | |
108 | { | |
109 | gpio_init(); | |
110 | gpio_input(C2D); | |
111 | gpio_output(C2CK); | |
112 | gpio_low(C2CK); | |
113 | usleep(20); | |
114 | gpio_high(C2CK); | |
115 | usleep(2); | |
116 | } | |
117 | ||
118 | ||
119 | static void c2_reset(void) | |
120 | { | |
121 | gpio_input(C2D); | |
122 | gpio_low(C2CK); | |
123 | usleep(20); | |
124 | // gpio_input(C2CK); | |
125 | gpio_output(C2CK); | |
126 | gpio_high(C2CK); | |
127 | } |
f32x/c2-om.c | ||
---|---|---|
27 | 27 | #define C2D 4, 13 /* E12 = SPI_CLK0 */ |
28 | 28 | |
29 | 29 | |
30 | /* ----- Bit-level operations ---------------------------------------------- */ | |
31 | ||
32 | ||
33 | static void c2_pulse(void) | |
34 | { | |
35 | gpio_low(C2CK); | |
36 | gpio_high(C2CK); | |
37 | } | |
38 | ||
39 | ||
40 | static void c2_send(uint32_t value, int bits) | |
41 | { | |
42 | int i; | |
43 | ||
44 | for (i = 0; i != bits; i++) { | |
45 | gpio_set(C2D, (value >> i) & 1); | |
46 | c2_pulse(); | |
47 | } | |
48 | } | |
49 | ||
50 | ||
51 | static uint32_t c2_recv(int bits) | |
52 | { | |
53 | uint32_t v = 0; | |
54 | int i; | |
55 | ||
56 | for (i = 0; i != bits; i++) { | |
57 | v |= gpio_get(C2D) << i; | |
58 | c2_pulse(); | |
59 | } | |
60 | return v; | |
61 | } | |
62 | ||
63 | ||
64 | /* ----- C2 Register read/write -------------------------------------------- */ | |
65 | ||
66 | ||
67 | static void om_addr_write(uint8_t addr) | |
68 | { | |
69 | c2_pulse(); | |
70 | gpio_output(C2D); | |
71 | c2_send(C2_ADDR_WRITE, 2); | |
72 | c2_send(addr, 8); | |
73 | gpio_input(C2D); | |
74 | c2_pulse(); | |
75 | } | |
76 | ||
77 | ||
78 | static uint8_t om_addr_read(void) | |
79 | { | |
80 | c2_pulse(); | |
81 | gpio_output(C2D); | |
82 | c2_send(C2_ADDR_READ, 2); | |
83 | gpio_input(C2D); | |
84 | c2_pulse(); | |
85 | return c2_recv(8); | |
86 | } | |
87 | ||
88 | ||
89 | static void om_data_write(uint32_t data, int bytes) | |
90 | { | |
91 | c2_pulse(); | |
92 | gpio_output(C2D); | |
93 | c2_send(C2_DATA_WRITE, 2); | |
94 | c2_send(bytes-1, 2); | |
95 | c2_send(data, 8*bytes); | |
96 | gpio_input(C2D); | |
97 | c2_pulse(); | |
98 | while (!c2_recv(1)); | |
99 | } | |
100 | ||
101 | ||
102 | static uint32_t om_data_read(int bytes) | |
103 | { | |
104 | c2_pulse(); | |
105 | gpio_output(C2D); | |
106 | c2_send(C2_DATA_READ, 2); | |
107 | c2_send(bytes-1, 2); | |
108 | gpio_input(C2D); | |
109 | c2_pulse(); | |
110 | while (!c2_recv(1)); | |
111 | return c2_recv(8*bytes); | |
112 | } | |
113 | ||
114 | ||
115 | /* ----- C2 initialization ------------------------------------------------- */ | |
116 | ||
117 | ||
118 | static void om_init(void) | |
119 | { | |
120 | gpio_init(); | |
121 | gpio_input(C2D); | |
122 | gpio_output(C2CK); | |
123 | gpio_low(C2CK); | |
124 | usleep(20); | |
125 | gpio_high(C2CK); | |
126 | usleep(2); | |
127 | } | |
128 | ||
129 | ||
130 | static void om_reset(void) | |
131 | { | |
132 | gpio_input(C2D); | |
133 | gpio_low(C2CK); | |
134 | usleep(20); | |
135 | // gpio_input(C2CK); | |
136 | gpio_output(C2CK); | |
137 | gpio_high(C2CK); | |
138 | } | |
30 | #include "c2-bitbang.c" | |
139 | 31 | |
140 | 32 | |
141 | 33 | /* ----- Operations -------------------------------------------------------- */ |
142 | 34 | |
143 | 35 | |
144 | 36 | struct c2_ops c2_om = { |
145 | .init = om_init, | |
146 | .reset = om_reset, | |
147 | .addr_write = om_addr_write, | |
148 | .addr_read = om_addr_read, | |
149 | .data_write = om_data_write, | |
150 | .data_read = om_data_read, | |
37 | .init = c2_init, | |
38 | .reset = c2_reset, | |
39 | .addr_write = c2_addr_write, | |
40 | .addr_read = c2_addr_read, | |
41 | .data_write = c2_data_write, | |
42 | .data_read = c2_data_read, | |
151 | 43 | }; |
Branches:
master