summaryrefslogtreecommitdiffstats
path: root/pressure_control/firmware
diff options
context:
space:
mode:
authorMichael Buesch <mb@bu3sch.de>2009-05-30 17:58:32 +0200
committerMichael Buesch <mb@bu3sch.de>2009-05-30 17:58:32 +0200
commitd31ac3343c7839c2c5244c615fd498bf63c3a2a8 (patch)
tree7b5cfc16d5c55f34412ee805e91de96f480264a0 /pressure_control/firmware
parent4b9c9858e408dd8d8ef29a315496af714ccb8bdf (diff)
downloadcnc-d31ac3343c7839c2c5244c615fd498bf63c3a2a8.tar.xz
cnc-d31ac3343c7839c2c5244c615fd498bf63c3a2a8.zip
pressure_control: Add support for valves with one magnet
Signed-off-by: Michael Buesch <mb@bu3sch.de>
Diffstat (limited to 'pressure_control/firmware')
-rw-r--r--pressure_control/firmware/main.c4
-rw-r--r--pressure_control/firmware/remote.c4
-rw-r--r--pressure_control/firmware/valves.c77
-rw-r--r--pressure_control/firmware/valves.h29
4 files changed, 73 insertions, 41 deletions
diff --git a/pressure_control/firmware/main.c b/pressure_control/firmware/main.c
index c306212..65443cc 100644
--- a/pressure_control/firmware/main.c
+++ b/pressure_control/firmware/main.c
@@ -43,8 +43,8 @@ struct pressure_state state;
/* The 1000Hz jiffies counter */
static jiffies_t jiffies_counter;
-DEFINE_VALVE(xy_control_valves, D, 6, 7, 4, 5);
-DEFINE_VALVE(z_control_valves, C, 2, 3, 4, 5);
+DEFINE_VALVE(xy_control_valves, VALVES_2MAG, D, 6, 7, 4, 5);
+DEFINE_VALVE(z_control_valves, VALVES_1MAG, C, 2, 3, 4, 5);
static DEFINE_SENSOR(xy_control_sensor, 0, 245, 4400, 10000);
static DEFINE_SENSOR(z_control_sensor, (1<<MUX0), 245, 4400, 10000);
diff --git a/pressure_control/firmware/remote.c b/pressure_control/firmware/remote.c
index 8fd104e..b6d6141 100644
--- a/pressure_control/firmware/remote.c
+++ b/pressure_control/firmware/remote.c
@@ -200,12 +200,12 @@ static void handle_received_message(void)
}
if (rx_msg.valve.nr == 0) {
valve0_switch(&xy_control_valves, rx_msg.valve.state == 0 ?
- VALVE_STATE_12 : VALVE_STATE_14);
+ VALVE_STATE_CLOSE : VALVE_STATE_OPEN);
valve_wait_toggle(&xy_control_valves);
valve0_switch(&xy_control_valves, VALVE_STATE_IDLE);
} else if (rx_msg.valve.nr == 1) {
valve1_switch(&xy_control_valves, rx_msg.valve.state == 0 ?
- VALVE_STATE_12 : VALVE_STATE_14);
+ VALVE_STATE_CLOSE : VALVE_STATE_OPEN);
valve_wait_toggle(&xy_control_valves);
valve0_switch(&xy_control_valves, VALVE_STATE_IDLE);
} else
diff --git a/pressure_control/firmware/valves.c b/pressure_control/firmware/valves.c
index 8f9f2de..191842d 100644
--- a/pressure_control/firmware/valves.c
+++ b/pressure_control/firmware/valves.c
@@ -25,32 +25,50 @@
#include <avr/io.h>
-/*** Valve interface definitions ***///XXX
-#define VALVE_DDR DDRD
-#define VALVE_PORT PORTD
-#define VALVE0_14 6 /* Pin for valve-0 position 14 */
-#define VALVE0_12 7 /* Pin for valve-0 position 12 */
-#define VALVE1_14 4 /* Pin for valve-1 position 14 */
-#define VALVE1_12 5 /* Pin for valve-1 position 12 */
-
#define MMIO8(mem_addr) _MMIO_BYTE(mem_addr)
void valve0_switch(struct valves *v, uint8_t state)
{
- MMIO8(v->port) &= ~(BITMASK8(v->bit_0_12) | BITMASK8(v->bit_0_14));
- if (state == VALVE_STATE_12)
- MMIO8(v->port) |= BITMASK8(v->bit_0_12);
- else if (state == VALVE_STATE_14)
- MMIO8(v->port) |= BITMASK8(v->bit_0_14);
+ uint8_t p = MMIO8(v->port);
+
+ switch (v->type) {
+ case VALVES_1MAG:
+ if (state == VALVE_STATE_OPEN)
+ p |= BITMASK8(v->bit_0_open);
+ else if (state == VALVE_STATE_CLOSE)
+ p &= ~BITMASK8(v->bit_0_open);
+ break;
+ case VALVES_2MAG:
+ p &= ~(BITMASK8(v->bit_0_close) | BITMASK8(v->bit_0_open));
+ if (state == VALVE_STATE_CLOSE)
+ p |= BITMASK8(v->bit_0_close);
+ else if (state == VALVE_STATE_OPEN)
+ p |= BITMASK8(v->bit_0_open);
+ break;
+ }
+ MMIO8(v->port) = p;
}
void valve1_switch(struct valves *v, uint8_t state)
{
- MMIO8(v->port) &= ~(BITMASK8(v->bit_1_12) | BITMASK8(v->bit_1_14));
- if (state == VALVE_STATE_12)
- MMIO8(v->port) |= BITMASK8(v->bit_1_12);
- else if (state == VALVE_STATE_14)
- MMIO8(v->port) |= BITMASK8(v->bit_1_14);
+ uint8_t p = MMIO8(v->port);
+
+ switch (v->type) {
+ case VALVES_1MAG:
+ if (state == VALVE_STATE_OPEN)
+ p |= BITMASK8(v->bit_1_open);
+ else if (state == VALVE_STATE_CLOSE)
+ p &= ~BITMASK8(v->bit_1_open);
+ break;
+ case VALVES_2MAG:
+ p &= ~(BITMASK8(v->bit_1_close) | BITMASK8(v->bit_1_open));
+ if (state == VALVE_STATE_CLOSE)
+ p |= BITMASK8(v->bit_1_close);
+ else if (state == VALVE_STATE_OPEN)
+ p |= BITMASK8(v->bit_1_open);
+ break;
+ }
+ MMIO8(v->port) = p;
}
void valves_global_switch(struct valves *v, uint8_t state)
@@ -63,16 +81,16 @@ void __valves_global_switch(struct valves *v, uint8_t state)
{
switch (state) {
case VALVES_IDLE:
- valve0_switch(v, VALVE_STATE_12);
- valve1_switch(v, VALVE_STATE_12);
+ valve0_switch(v, VALVE_STATE_CLOSE);
+ valve1_switch(v, VALVE_STATE_CLOSE);
break;
case VALVES_FLOW_IN:
- valve1_switch(v, VALVE_STATE_12);
- valve0_switch(v, VALVE_STATE_14);
+ valve1_switch(v, VALVE_STATE_CLOSE);
+ valve0_switch(v, VALVE_STATE_OPEN);
break;
case VALVES_FLOW_OUT:
- valve0_switch(v, VALVE_STATE_12);
- valve1_switch(v, VALVE_STATE_14);
+ valve0_switch(v, VALVE_STATE_CLOSE);
+ valve1_switch(v, VALVE_STATE_OPEN);
break;
}
v->switch_to_idle_time = get_jiffies() + msec_to_jiffies(VALVE_TOGGLE_MSEC);
@@ -92,8 +110,15 @@ void valves_work(struct valves *v)
static inline void valves_ddr_setup(struct valves *v)
{
- MMIO8(v->ddr) |= BITMASK8(v->bit_0_12) | BITMASK8(v->bit_0_14) |
- BITMASK8(v->bit_1_12) | BITMASK8(v->bit_1_14);
+ switch (v->type) {
+ case VALVES_1MAG:
+ MMIO8(v->ddr) |= BITMASK8(v->bit_0_open) | BITMASK8(v->bit_1_open);
+ break;
+ case VALVES_2MAG:
+ MMIO8(v->ddr) |= BITMASK8(v->bit_0_close) | BITMASK8(v->bit_0_open) |
+ BITMASK8(v->bit_1_close) | BITMASK8(v->bit_1_open);
+ break;
+ }
}
void valves_shutdown(struct valves *v)
diff --git a/pressure_control/firmware/valves.h b/pressure_control/firmware/valves.h
index 11ec6db..7586904 100644
--- a/pressure_control/firmware/valves.h
+++ b/pressure_control/firmware/valves.h
@@ -17,31 +17,38 @@ enum valves_global_state {
/* State for one valve. */
enum valve_state {
VALVE_STATE_IDLE,
- VALVE_STATE_12,
- VALVE_STATE_14,
+ VALVE_STATE_CLOSE,
+ VALVE_STATE_OPEN,
+};
+
+enum valves_type {
+ VALVES_1MAG, /* One magnet for opening the valve. Spring reset. */
+ VALVES_2MAG, /* One magnet for opening; one magnet for closing the valve. */
};
struct valves {
+ uint8_t type; /* enum valves_type */
uint16_t ddr; /* DDRx */
uint16_t port; /* PORTx */
- uint8_t bit_0_14; /* Valve 0: Pin for valve position 14 */
- uint8_t bit_0_12; /* Valve 0: Pin for valve position 12 */
- uint8_t bit_1_14; /* Valve 1: Pin for valve position 14 */
- uint8_t bit_1_12; /* Valve 1: Pin for valve position 12 */
+ uint8_t bit_0_open; /* Pin for opening valve 0. */
+ uint8_t bit_0_close; /* Pin for closing valve 0. */
+ uint8_t bit_1_open; /* Pin for opening valve 1. */
+ uint8_t bit_1_close; /* Pin for closing valve 1. */
uint8_t current_global_state; /* enum valves_global_state */
bool need_switch_to_idle; /* Need transition to VALVE_STATE_IDLE. */
jiffies_t switch_to_idle_time; /* Deadline for VALVE_STATE_IDLE transition. */
};
-#define DEFINE_VALVE(name, portid, bit0_14, bit0_12, bit1_14, bit1_12) \
+#define DEFINE_VALVE(name, _type, portid, bit0_open, bit0_close, bit1_open, bit1_close) \
struct valves name = { \
+ .type = _type, \
.ddr = _SFR_ADDR(DDR##portid), \
.port = _SFR_ADDR(PORT##portid), \
- .bit_0_14 = bit0_14, \
- .bit_0_12 = bit0_12, \
- .bit_1_14 = bit1_14, \
- .bit_1_12 = bit1_12, \
+ .bit_0_open = bit0_open, \
+ .bit_0_close = bit0_close, \
+ .bit_1_open = bit1_open, \
+ .bit_1_close = bit1_close, \
}
#define VALVE_TOGGLE_MSEC 10
bues.ch cgit interface