113 lines
2.1 KiB
C
Executable File
113 lines
2.1 KiB
C
Executable File
#pragma once
|
|
|
|
#include <can/can.h>
|
|
#include <sys/mutex.h>
|
|
#include <util/list.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
/** Constants... **/
|
|
#define J_LONG 11
|
|
#define J_FLOAT 12
|
|
|
|
typedef struct jetterSlave
|
|
{
|
|
uint16_t refID;
|
|
uint8_t modcode;
|
|
|
|
} JSlave;
|
|
|
|
|
|
typedef struct jetterParm
|
|
{
|
|
uint8_t slave;
|
|
uint16_t parm;
|
|
uint8_t flags;
|
|
|
|
uint32_t lastReadValue;
|
|
} JParm;
|
|
|
|
typedef struct jetcan_state
|
|
{
|
|
uint8_t initialized:1;
|
|
|
|
MUTEX mutex;
|
|
} JState;
|
|
|
|
struct jetcan_request
|
|
{
|
|
list_t list;
|
|
|
|
uint8_t read:1;
|
|
uint8_t write:1;
|
|
uint8_t typint:1;
|
|
uint8_t typfloat:1;
|
|
|
|
uint8_t slave;
|
|
uint16_t register_no;
|
|
|
|
uint8_t retry;
|
|
|
|
union {
|
|
int32_t i32;
|
|
float f32;
|
|
};
|
|
};
|
|
|
|
struct jetcan_status
|
|
{
|
|
list_t requests;
|
|
};
|
|
|
|
struct _jetcan {
|
|
MUTEX lock;
|
|
uint8_t nSlaves;
|
|
JSlave slaves[4];
|
|
};
|
|
|
|
extern struct _jetcan jetcan;
|
|
|
|
|
|
extern int32_t _dbg_jetcan_requests,
|
|
_dbg_jetcan_misses,
|
|
_dbg_jetcan_timeouts,
|
|
_dbg_jetcan_rtt,
|
|
_dbg_jetcan_rtt_min,
|
|
_dbg_jetcan_rtt_max;
|
|
|
|
|
|
/* jSetCModeCallback()
|
|
Callback um die CMODE0 und CMODE1 Leitungen zu setzen (Bits 0 + 1 von cmode)
|
|
*/
|
|
typedef void (*jSetCModeCallback)(uint8_t cmode);
|
|
|
|
/* jSetRegister32Ex - Write Register Value to Slave (via CAN) with Result */
|
|
int jSetRegister32Ex(uint8_t slave,uint16_t parm,void *pValue,uint8_t type);
|
|
int jSetRegister32Exl(uint8_t slave,uint16_t parm,int32_t value);
|
|
int jSetRegister32Exd(uint8_t slave,uint16_t parm,float value);
|
|
|
|
/* jReadRegister32Ex - Read Register Value to Slave (via CAN) with Result */
|
|
int jReadRegister32Ex(uint8_t slave,uint16_t parm,void *pValue,uint8_t* type);
|
|
int jReadRegister32Exl(uint8_t slave,uint16_t parm,int32_t *value);
|
|
int jReadRegister32Exd(uint8_t slave,uint16_t parm,float *value);
|
|
|
|
|
|
/* Bit Manipulationen */
|
|
void jSetRegisterBit(uint8_t slave,uint16_t parm,uint8_t bit);
|
|
void jClearRegisterBit(uint8_t slave,uint16_t parm,uint8_t bit);
|
|
int jReadRegisterBit(uint8_t slave,uint16_t parm,uint8_t bit);
|
|
|
|
/* JM2XX Command */
|
|
int jCommand(uint8_t slave,uint32_t command);
|
|
|
|
/** Initialization **/
|
|
int jcan_setup_bus(jSetCModeCallback cmodecallback);
|
|
int jcan_num_slaves(void);
|
|
JSlave* jcan_slave(uint8_t num);
|
|
|
|
int jcan_lock(void);
|
|
int jcan_unlock(void);
|
|
|
|
|
|
|