-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathjsd_el2809.c
84 lines (65 loc) · 2.41 KB
/
jsd_el2809.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "jsd/jsd_el2809.h"
#include <assert.h>
#include "jsd/jsd_sdo.h"
/****************************************************
* Public functions
****************************************************/
/**
* @brief RxPDO struct used to set device command data in SOEM IOmap
*/
typedef struct __attribute__((__packed__)) {
uint16_t flags;
} jsd_el2809_rxpdo_t;
const jsd_el2809_state_t* jsd_el2809_get_state(jsd_t* self, uint16_t slave_id) {
assert(self);
assert(jsd_el2809_product_code_is_compatible(
self->ecx_context.slavelist[slave_id].eep_id));
return &self->slave_states[slave_id].el2809;
}
void jsd_el2809_process(jsd_t* self, uint16_t slave_id) {
assert(self);
assert(jsd_el2809_product_code_is_compatible(
self->ecx_context.slavelist[slave_id].eep_id));
jsd_el2809_rxpdo_t* rxpdo =
(jsd_el2809_rxpdo_t*)self->ecx_context.slavelist[slave_id].outputs;
int ch;
for (ch = 0; ch < JSD_EL2809_NUM_CHANNELS; ch++) {
uint8_t output = self->slave_states[slave_id].el2809.output[ch];
if (output > 0) {
rxpdo->flags |= 0x01 << ch;
} else {
rxpdo->flags &= ~(0x01 << ch);
}
}
}
void jsd_el2809_write_single_channel(jsd_t* self, uint16_t slave_id,
uint8_t channel, uint8_t output) {
assert(self);
assert(jsd_el2809_product_code_is_compatible(
self->ecx_context.slavelist[slave_id].eep_id));
self->slave_states[slave_id].el2809.output[channel] = output;
}
void jsd_el2809_write_all_channels(jsd_t* self, uint16_t slave_id,
uint8_t output[JSD_EL2809_NUM_CHANNELS]) {
int ch;
for (ch = 0; ch < JSD_EL2809_NUM_CHANNELS; ch++) {
jsd_el2809_write_single_channel(self, slave_id, ch, output[ch]);
}
}
/****************************************************
* Private functions
****************************************************/
bool jsd_el2809_init(jsd_t* self, uint16_t slave_id) {
assert(self);
assert(jsd_el2809_product_code_is_compatible(
self->ecx_context.slavelist[slave_id].eep_id));
assert(self->ecx_context.slavelist[slave_id].eep_man ==
JSD_BECKHOFF_VENDOR_ID);
jsd_slave_config_t* config = &self->slave_configs[slave_id];
// no PO2SO callback for 2809 devices, so set the success flag now
config->PO2SO_success = true;
return true;
}
bool jsd_el2809_product_code_is_compatible(uint32_t product_code) {
return product_code == JSD_EL2809_PRODUCT_CODE;
}