kju
15 years ago
8 changed files with 349 additions and 22 deletions
@ -0,0 +1,74 @@ |
|||
dep_bool_menu "CAN bus support" CAN_SUPPORT y |
|||
|
|||
choice 'SPI Port' \ |
|||
"PORTA 0 \ |
|||
PORTB 1 \ |
|||
PORTC 2 \ |
|||
PORTD 3" \ |
|||
'PORTB' SPI_PORTIDX |
|||
|
|||
choice 'Bit MOSI' \ |
|||
"Bit0 0 \ |
|||
Bit1 1 \ |
|||
Bit2 2 \ |
|||
Bit3 3 \ |
|||
Bit4 4 \ |
|||
Bit5 5 \ |
|||
Bit6 6 \ |
|||
Bit7 7" \ |
|||
'Bit5' SPI_PIN_MOSI |
|||
|
|||
choice 'Bit MISO' \ |
|||
"Bit0 0 \ |
|||
Bit1 1 \ |
|||
Bit2 2 \ |
|||
Bit3 3 \ |
|||
Bit4 4 \ |
|||
Bit5 5 \ |
|||
Bit6 6 \ |
|||
Bit7 7" \ |
|||
'Bit6' SPI_PIN_MISO |
|||
|
|||
choice 'Bit SCK' \ |
|||
"Bit0 0 \ |
|||
Bit1 1 \ |
|||
Bit2 2 \ |
|||
Bit3 3 \ |
|||
Bit4 4 \ |
|||
Bit5 5 \ |
|||
Bit6 6 \ |
|||
Bit7 7" \ |
|||
'Bit7' SPI_PIN_SCK |
|||
|
|||
choice 'Bit SS' \ |
|||
"Bit0 0 \ |
|||
Bit1 1 \ |
|||
Bit2 2 \ |
|||
Bit3 3 \ |
|||
Bit4 4 \ |
|||
Bit5 5 \ |
|||
Bit6 6 \ |
|||
Bit7 7" \ |
|||
'Bit4' SPI_PIN_SS |
|||
|
|||
bool "Use interrupt" CAN_INTERRUPT |
|||
|
|||
choice 'Interrupt Port' \ |
|||
"PINA PINA \ |
|||
PINB PINB \ |
|||
PINC PINC \ |
|||
PIND PIND" \ |
|||
'PIND' SPI_REG_PIN_MCP_INT |
|||
|
|||
choice 'Interrupt Bit' \ |
|||
"Bit0 0 \ |
|||
Bit1 1 \ |
|||
Bit2 2 \ |
|||
Bit3 3 \ |
|||
Bit4 4 \ |
|||
Bit5 5 \ |
|||
Bit6 6 \ |
|||
Bit7 7" \ |
|||
'Bit2' SPI_PIN_MCP_INT |
|||
|
|||
endmenu |
@ -0,0 +1,123 @@ |
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
|
|||
#include "can.h" |
|||
#include "lap.h" |
|||
|
|||
/****************************************************************************
|
|||
* STUBS: LAP Core Services |
|||
*/ |
|||
|
|||
// send ping to dst
|
|||
void lap_ping( can_addr dst ) |
|||
{ |
|||
pdo_message *msg = (pdo_message *)can_buffer_get(); |
|||
|
|||
msg->addr_src = 0; |
|||
msg->addr_dst = dst; |
|||
msg->port_src = PORT_MGT; |
|||
msg->port_dst = PORT_MGT; |
|||
msg->dlc = 1; |
|||
msg->cmd = FKT_MGT_PING; |
|||
|
|||
can_transmit( (can_message *)msg ); |
|||
} |
|||
|
|||
// send reset request to dst
|
|||
void lap_reset( can_addr dst ) |
|||
{ |
|||
pdo_message *msg = (pdo_message *)can_buffer_get(); |
|||
|
|||
msg->addr_src = 0; |
|||
msg->addr_dst = dst; |
|||
msg->port_src = PORT_MGT; |
|||
msg->port_dst = PORT_MGT; |
|||
msg->dlc = 1; |
|||
msg->cmd = FKT_MGT_RESET; |
|||
|
|||
can_transmit( (can_message *)msg ); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
/*
|
|||
char *sdo_readbuf(lap_message *first_msg, |
|||
unsigned char int length, unsigned char &reallength) |
|||
{ |
|||
unsigned char len = first_message->data[0]; |
|||
char *buf = malloc(length); |
|||
char *cur = buf; |
|||
|
|||
reallength = 0; |
|||
while( reallength < length ) { |
|||
can_message *msg = can_get(); |
|||
|
|||
if ( msg->addr_src != first_msg->addr_src || |
|||
msg->addr_dest != fisrt_msg->addr_dest || |
|||
msg->port_src != fisrt_msg->port_src || |
|||
msg->port_dest != fisrt_msg->port_dest ) |
|||
{ |
|||
return buf; |
|||
} |
|||
|
|||
memcpy(cur, msg->data, msg->dlc); |
|||
reallength+=msg->dlc; |
|||
msg->flags = 0x00; |
|||
} |
|||
|
|||
return buf; |
|||
} |
|||
|
|||
// unsigned char sdo_sendpacket(lap_message *msg)
|
|||
// {
|
|||
// }
|
|||
//
|
|||
// unsigned char sdo_sendpacket_nb(lap_message *msg)
|
|||
// {
|
|||
// }
|
|||
|
|||
unsigned char sdo_sendbuf(lap_message *fst_msg, unsigned char *buf, unsigned char len) |
|||
{ |
|||
while(len > 0) { |
|||
can_message *msg = can_buffer_get(); |
|||
msg->addr_src = fst_msg->addr_src; |
|||
msg->addr_dest = fst_msg->addr_dest; |
|||
msg->port_src = fst_msg->port_src; |
|||
msg->port_dest = fst_msg->port_dest; |
|||
|
|||
msg->dlc = len > 8 ? 8 : len; |
|||
memcpy(msg->data, buf, msg->dlc); |
|||
msg->flags = 0x01; |
|||
can_transmit(); |
|||
} |
|||
// XXX wait for ACK
|
|||
} |
|||
|
|||
|
|||
unsigned char sdo_sendbuf_nb(lap_message *fst_msg, unsigned char *buf, unsigned char len) |
|||
{ |
|||
while(len > 0) { |
|||
can_message *msg = can_buffer_get(); |
|||
msg->addr_src = fst_msg->addr_src; |
|||
msg->addr_dest = fst_msg->addr_dest; |
|||
msg->port_src = fst_msg->port_src; |
|||
msg->port_dest = fst_msg->port_dest; |
|||
|
|||
msg->dlc = len > 8 ? 8 : len; |
|||
memcpy(msg->data, buf, msg->dlc); |
|||
msg->flags = 0x01; |
|||
can_transmit(); |
|||
} |
|||
// XXX wait for ACK
|
|||
|
|||
} |
|||
*/ |
@ -0,0 +1,120 @@ |
|||
#ifndef LAP_H |
|||
#define LAP_H |
|||
|
|||
/****************************************************************************
|
|||
* Labor Automation Protocol |
|||
* |
|||
*/ |
|||
|
|||
#include <inttypes.h> |
|||
|
|||
|
|||
/****************************************************************************
|
|||
* Types |
|||
*/ |
|||
|
|||
// "inherits" from can_message
|
|||
typedef struct { |
|||
can_addr addr_src; |
|||
can_addr addr_dst; |
|||
can_port port_src; |
|||
can_port port_dst; |
|||
unsigned char dlc; |
|||
unsigned char cmd; |
|||
uint16_t index; |
|||
uint16_t size; |
|||
uint16_t address; |
|||
} sdo_message; |
|||
|
|||
// "inherits" from can_message
|
|||
typedef struct{ |
|||
can_addr addr_src; |
|||
can_addr addr_dst; |
|||
can_port port_src; |
|||
can_port port_dst; |
|||
unsigned char dlc; |
|||
unsigned char cmd; |
|||
unsigned char data[7]; |
|||
} pdo_message; |
|||
|
|||
/****************************************************************************
|
|||
* Known ports and services |
|||
*/ |
|||
|
|||
typedef enum { PORT_MGT=0x30, PORT_LAMPE=0x20, PORT_SDO=0x15, PORT_SDO_DATA=0x16, PORT_LAPD=0x18, |
|||
PORT_BORG=0x23, PORT_MOOD=0x17, PORT_REMOTE=0x21, PORT_GATE=0x22, PORT_CHUCK=0x26 } ports; |
|||
|
|||
typedef enum { FKT_MGT_PING=0x00, FKT_MGT_PONG=0x01, |
|||
FKT_MGT_RESET=0x02, FKT_MGT_AWAKE=0x03, FKT_MGT_TIMEREQUEST=0x04, FKT_MGT_TIMEREPLY=0x05 } lap_mgt_fkts; |
|||
|
|||
typedef enum { FKT_LAMPE_SET=0x00, FKT_LAMPE_SETMASK=0x01, |
|||
FKT_LAMPE_SETDELAY=0x02, FKT_LAMPE_ADD=0x03 } lap_lampe_fkts; |
|||
|
|||
typedef enum { FKT_BORG_INFO=0x00, FKT_BORG_MODE=0x01, FKT_BORG_SCROLLTEXT_RESET=0x02, |
|||
FKT_BORG_SCROLLTEXT_APPEND=0x03 } lap_borg_fkts; |
|||
|
|||
typedef enum { FKT_ONOFF_INFO=0, FKT_ONOFF_SET=1, FKT_ONOFF_GET=2, |
|||
} lap_lapd_fkts; |
|||
|
|||
typedef enum { FKT_MOOD_INFO=0x00, FKT_MOOD_GET=0x01, FKT_MOOD_SET=0x02, FKT_MOOD_ONOFF=0x03} lap_mood_fkts; |
|||
#define SDO_CMD_READ 0x20 |
|||
#define SDO_CMD_REPLY 0x21 |
|||
#define SDO_CMD_INFO 0x22 |
|||
#define SDO_CMD_READ_BLK 0x40 |
|||
#define SDO_CMD_READ_BLK_ACK 0x41 |
|||
#define SDO_CMD_WRITE_BLK 0x48 |
|||
#define SDO_CMD_WRITE_BLK_ACK 0x49 |
|||
|
|||
|
|||
#define SDO_CMD_ERROR_INDEX 0x80 |
|||
|
|||
#define SDO_TYPE_UINT8_RO 0x00 |
|||
#define SDO_TYPE_UINT8_RW 0x01 |
|||
#define SDO_TYPE_UINT16_RO 0x04 |
|||
#define SDO_TYPE_UINT16_RW 0x05 |
|||
#define SDO_TYPE_UINT32_RO 0x08 |
|||
#define SDO_TYPE_UINT32_RW 0x09 |
|||
#define SDO_TYPE_STRING_RO 0x80 |
|||
#define SDO_TYPE_STRING_RW 0x81 |
|||
#define SDO_TYPE_STRING_WO 0x82 |
|||
|
|||
|
|||
/****************************************************************************
|
|||
* STUBS: LAP Core Services |
|||
*/ |
|||
|
|||
// send ping to dst
|
|||
void lap_ping( can_addr dst ); |
|||
|
|||
// send reset request to dst
|
|||
void lap_reset( can_addr dst ); |
|||
|
|||
/**
|
|||
* ServiceDataObject routinen |
|||
* |
|||
unsigned char *sdo_readbuf(sdo_message *first_message, |
|||
unsigned char length, unsigned char *actuallength); |
|||
|
|||
unsigned char sdo_sendbuf(sdo_message *fst_msg, unsigned char *buf, unsigned char len); |
|||
unsigned char sdo_sendbuf_nb(sdo_message *fst_msg, unsigned char *buf, unsigned char len); |
|||
|
|||
*/ |
|||
/////////////////////////////////////////////////////////////////////////////
|
|||
/* Usage
|
|||
|
|||
while(1) { |
|||
lap_message msg = lap_rcvpacket(); |
|||
switch( msg->fkt_id ) { |
|||
case FKT_BLA: |
|||
unsigned char length = data[0] |
|||
|
|||
data |
|||
|
|||
char *buf = lap_read(msg, length); |
|||
if ( !buf ) continue; |
|||
|
|||
// interpret buffer
|
|||
} |
|||
*/ |
|||
|
|||
#endif |
Loading…
Reference in new issue