-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
158c175
commit e2a5403
Showing
7 changed files
with
215 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#include "jsd/jsd_el2828.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__)) { | ||
uint8_t flags; | ||
} jsd_el2828_rxpdo_t; | ||
|
||
const jsd_el2828_state_t* jsd_el2828_get_state(jsd_t* self, uint16_t slave_id) { | ||
assert(self); | ||
assert(jsd_el2828_product_code_is_compatible( | ||
self->ecx_context.slavelist[slave_id].eep_id)); | ||
|
||
return &self->slave_states[slave_id].el2828; | ||
} | ||
|
||
void jsd_el2828_process(jsd_t* self, uint16_t slave_id) { | ||
assert(self); | ||
assert(jsd_el2828_product_code_is_compatible( | ||
self->ecx_context.slavelist[slave_id].eep_id)); | ||
|
||
jsd_el2828_rxpdo_t* rxpdo = | ||
(jsd_el2828_rxpdo_t*)self->ecx_context.slavelist[slave_id].outputs; | ||
|
||
int ch; | ||
for (ch = 0; ch < JSD_EL2828_NUM_CHANNELS; ch++) { | ||
uint8_t output = self->slave_states[slave_id].el2828.output[ch]; | ||
|
||
if (output > 0) { | ||
rxpdo->flags |= 0x01 << ch; | ||
} else { | ||
rxpdo->flags &= ~(0x01 << ch); | ||
} | ||
} | ||
} | ||
|
||
void jsd_el2828_write_single_channel(jsd_t* self, uint16_t slave_id, | ||
uint8_t channel, uint8_t output) { | ||
assert(self); | ||
assert(jsd_el2828_product_code_is_compatible( | ||
self->ecx_context.slavelist[slave_id].eep_id)); | ||
|
||
self->slave_states[slave_id].el2828.output[channel] = output; | ||
} | ||
|
||
void jsd_el2828_write_all_channels(jsd_t* self, uint16_t slave_id, | ||
uint8_t output[JSD_EL2828_NUM_CHANNELS]) { | ||
int ch; | ||
for (ch = 0; ch < JSD_EL2828_NUM_CHANNELS; ch++) { | ||
jsd_el2828_write_single_channel(self, slave_id, ch, output[ch]); | ||
} | ||
} | ||
|
||
/**************************************************** | ||
* Private functions | ||
****************************************************/ | ||
|
||
bool jsd_el2828_init(jsd_t* self, uint16_t slave_id) { | ||
assert(self); | ||
assert(jsd_el2828_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 2828 devices, so set the success flag now | ||
config->PO2SO_success = true; | ||
|
||
return true; | ||
} | ||
|
||
bool jsd_el2828_product_code_is_compatible(uint32_t product_code) { | ||
return product_code == JSD_EL2828_PRODUCT_CODE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#ifndef JSD_EL2828_H | ||
#define JSD_EL2828_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "jsd/jsd_el2828_pub.h" | ||
|
||
/** @brief Initializes el2828 | ||
* | ||
* @param self pointer JSD context | ||
* @param slave_id index of device on EtherCAT bus | ||
* @return true on success, false on failure | ||
*/ | ||
bool jsd_el2828_init(jsd_t* self, uint16_t slave_id); | ||
|
||
/** | ||
* @brief Checks whether a product code is compatible with EL2828. | ||
* | ||
* @param product_code The product code to be checked | ||
* @return True if the product code is compatible, false otherwise. | ||
*/ | ||
bool jsd_el2828_product_code_is_compatible(uint32_t product_code); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#ifndef JSD_EL2828_PUB_H | ||
#define JSD_EL2828_PUB_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "jsd/jsd_el2828_types.h" | ||
#include "jsd/jsd_pub.h" | ||
|
||
/** | ||
* @brief Read the EL2828 State | ||
* | ||
* Note: this device does not actually provide PDO feedback on state, | ||
* This function reads back the cmd sent to the EL2828 device | ||
* | ||
* @param self pointer to JSD context | ||
* @param slave_id id of EL2828 device | ||
* @return Pointer to EL2828 device state | ||
*/ | ||
const jsd_el2828_state_t* jsd_el2828_get_state(jsd_t* self, uint16_t slave_id); | ||
|
||
/** | ||
* @brief process loop required for proper device function | ||
* | ||
* @param self pointer to JSD context | ||
* @param slave_id id of EL2828 device | ||
*/ | ||
void jsd_el2828_process(jsd_t* self, uint16_t slave_id); | ||
|
||
/** | ||
* @brief Sets a specified channel level | ||
* | ||
* @param self pointer to JSD context | ||
* @param slave_id id of EL2828 device | ||
* @param channel specified device channel to command | ||
* @param output command level (0 or 1) | ||
*/ | ||
void jsd_el2828_write_single_channel(jsd_t* self, uint16_t slave_id, | ||
uint8_t channel, uint8_t output); | ||
|
||
/** | ||
* @brief Sets all channel levels | ||
* | ||
* @param self pointer to JSD context | ||
* @param slave_id id of EL2828 device | ||
* @param output command level (0 or 1) | ||
*/ | ||
void jsd_el2828_write_all_channels(jsd_t* self, uint16_t slave_id, | ||
uint8_t output[JSD_EL2828_NUM_CHANNELS]); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#ifndef JSD_EL2828_TYPES_H | ||
#define JSD_EL2828_TYPES_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include "jsd/jsd_common_device_types.h" | ||
|
||
#define JSD_EL2828_PRODUCT_CODE (uint32_t)0x0B0C3052 | ||
|
||
#define JSD_EL2828_NUM_CHANNELS 8 | ||
|
||
/** | ||
* @brief EL2828 State Data | ||
*/ | ||
typedef struct { | ||
uint8_t output[JSD_EL2828_NUM_CHANNELS]; ///< digital output level (0 or 1) | ||
} jsd_el2828_state_t; | ||
|
||
/** | ||
* @brief EL2828 device configuration | ||
*/ | ||
typedef struct { | ||
} jsd_el2828_config_t; | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters