Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F73533014
sbcp.h
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Mon, Jul 22, 11:32
Size
6 KB
Mime Type
text/x-c
Expires
Wed, Jul 24, 11:32 (2 d)
Engine
blob
Format
Raw Data
Handle
19218276
Attached To
R6619 Oncilla Motordriver Firmware
sbcp.h
View Options
/*
sbcp.h
Copyright (C) 2010 Rico Moeckel <rico.moeckel at epfl dot ch>,
EPFL Biorobotics Laboratory (http://biorob.epfl.ch)
EPFL Ecole Polytechnique Federale de Lausanne (http://www.epfl.ch)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/** \addtogroup sbcp */
/*@{*/
/** \file sbcp.h
\brief Simple Binary Communication Protocol.
This file contains the public definitions and function declarations for
Simple Binary Communication Protocol (Master device).
\author Rico Moeckel
\version 1.1
\date 2011-04-28
*/
#ifndef __SBCP_H__
#define __SBCP_H__
#include "dma_packet_queue.h"
/*************************************************************************
*
* DEFINES
*
*************************************************************************/
#define SBCP_MAX_MESSAGE_LENGTH (128)
///< Maximum length of a SBCP packet (256 bytes of payload + 6 bytes header).
#define SBCP_HEADER 0xFF
///< Position of header in packet (counting starts with 0).
#define SBCP_POS_HEADER 0
///< Position of header in packet (counting starts with 0).
#define SBCP_POS_CLASS 1
///< Position of class identifyer in packet (counting starts with 0).
#define SBCP_POS_ID 2
///< Position of device ID in packet (counting starts with 0).
#define SBCP_POS_PAYLOAD_LENGTH 3
///< Position of payload length in packet (counting starts with 0).
#define SBCP_POS_INSTRUCTION 4
///< Position of instruction in packet (counting starts with 0).
#define SBCP_POS_PAYLOAD_START 5
///< Position of payload start in packet (counting starts with 0).
#define SBCP_PACKET_START(A) ((A == SBCP_HEADER) ? 1 : 0)
///< Returns 1 if byte contains packet start - 0 if not.
#define SBCP_STANDARD_ACKNOWLEDGEMENT 0x00
///< Standard answer byte that the device is responding with when no error occured
#define SBCP_ERROR_FLAG_COM_ERROR 0x80
///< A Communicationn Errors happened on any bus
#define SBCP_ERROR_FLAG_DEVICE_SPECIFIC_MASK 0x7f
#define SBCP_COM_ERROR_CODE_BUS_TIMEOUT 0x01
///< Error code for packets that were not received within time limit via RS485 communication bus.
#define SBCP_COM_ERROR_CODE_USB_TIMEOUT 0x02
///< Error code for packets that were not received within time limit via USB interface.
#define SBCP_COM_ERROR_CODE_CHECKSUM_INCORRECT 0x04
///< Error code for packets with incorrect checksum.
#define SBCP_COM_ERROR_CODE_BUS_FRAME_ERROR 0x08
///< Error code when getted an UART FERR over the bus
#define SBCP_COM_ERROR_CODE_USB_FRAME_ERROR 0x10
///< Error code when getted an UART FERR over the usb
#define SBCP_COM_ERROR_CODE_UNKNOWN_INSTRUCTION 0x20
///< Error code getted when we had an unrecognized instruction
#define SBCP_BAD_PACKET_BUFFER_HANDLER 0xff
#define SBCP_LOW_LATENCY_INSTRUCTION 0xff
#define SBCP_LOW_LATENCY_INSTRUCTION_FEEDBACK_PAYLOAD_SIZE 26
#define SBCP_LOW_LATENCY_INSTRUCTION_COMMAND_PAYLOAD_SIZE 4
/*************************************************************************
*
* TYPE DEFINITIONS
*
*************************************************************************/
/// Command function type. All functions being automatically called by the SBCP when
/// their corresponding instruction is found in a communication packet have to be of
/// this type. \warning it uses a pointer to a ring buffer not a standard c buffer !
typedef
void
(
*
tSbcpCmdFunc
)(
const
unsigned
int
*
buffer
);
/// Definiton of command table.
typedef
struct
{
tSbcpCmdFunc
cmd_function
;
///< command function pointer
const
char
*
cmd_description
;
///< command description string
}
tSBCP_CmdTbl
;
#ifdef SBCP_IS_MASTER
///< state of a transmission channel
/// Struct storing the local variables for the SBCP.
typedef
struct
{
//two variable to keep track of how many packet are send over buses
//we cannot send a packet to a slave, unlike this two variable are equal.
//should be incremented as soon than a transfer to UART is started
//unsigned int nb_packet_received_from_host;
//should be incremented as soon than a transfer to USB from the BUS is started
//unsigned int nb_packet_response_transmission_started;
//eSBCP_tx_state bus_tx_state; ///< transmisison state of the RS485 bus
//eSBCP_tx_state usb_tx_state; ///< transmission state of the RS232 bus
// struct DMA_packet_queue usb_ready_packet_queue; ///< packet queue that store ready packet from the RS232 bus.
// struct DMA_packet_queue bus_ready_packet_queue; ///< packet queue that stores ready packet from the RS485 bus.
//eSBCP_usb_rx_flags usb_packet_flags[DMA_PACKET_QUEUE_LENGTH];
//eSBCP_usb_rx_flags bus_packet_flags[DMA_PACKET_QUEUE_LENGTH];
}
tSBCP_AppVar
;
#elif defined(SBCP_IS_SLAVE)
///Bus Tx flags
typedef
enum
eSBCP_tx_flags
{
SBCP_TX_BUFFER_FREE
=
0x00
,
SBCP_TX_BUFFER_OCCUPIED
=
0x01
,
SBCP_TX_BUFFER_IN_TX
=
0x02
}
eSBCP_tx_flags
;
/// Struct storing the local variables for the SBCP.
typedef
enum
eSBCP_ll_tx_flags
{
SBCP_LL_NOTHING
=
0x00
,
SBCP_LL_RX_IS_AVAILABLE
=
0x01
,
SBCP_LL_TX_IS_AVAILABLE
=
0x02
,
SBCP_LL_IS_DISABLED
=
0x04
,
}
eSBCP_ll_tx_flags
;
typedef
struct
{
struct
DMA_packet_queue
bus_ready_packet_queue
;
eSBCP_tx_flags
bus_tx_flags
;
unsigned
int
is_for_us
;
eSBCP_ll_tx_flags
bus_low_latency_flags
;
unsigned
char
bus_low_latency_payload
[
4
];
unsigned
char
bus_low_latency_previous_error_code
;
}
tSBCP_AppVar
;
#endif
extern
volatile
tSBCP_AppVar
sbcp
;
/*************************************************************************
*
* PUBLIC FUNCTIONS
*
*************************************************************************/
void
sbcp_init
();
void
sbcp_main
();
extern
unsigned
char
sbcp_compute_checksum_of_packet
(
const
unsigned
int
*
packet
);
#ifdef SBCP_IS_MASTER
//unsigned int * sbcp_get_new_usb_tx_packet(DMA_packet_queue_buffer_handler bh);
void
sbcp_usb_send_com_error_code
(
DMA_packet_queue_buffer_handler
bh
,
unsigned
char
error_code
);
void
sbcp_usb_send_standard_acknowlegement
(
DMA_packet_queue_buffer_handler
bh
);
#elif defined(SBCP_IS_SLAVE)
#define SBCP_GET_TX_PACKET_BUFFER(s,buffer) do{\
while(s.has_message_to_transmit){\
}\
s.has_message_to_transmit = 1;\
buffer = DMA_PACKET_QUEUE_BUS_TX_BUFFER_CPU;\
}while(0)
void
sbcp_bus_send_standard_acknowlegement
();
void
sbcp_bus_send_com_error_code
(
unsigned
char
error_code
);
#endif
#endif
/* __SBCP_H__ */
Event Timeline
Log In to Comment