Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F103798756
packet.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
Tue, Mar 4, 20:09
Size
3 KB
Mime Type
text/x-c
Expires
Thu, Mar 6, 20:09 (1 d, 20 h)
Engine
blob
Format
Raw Data
Handle
24667469
Attached To
R6616 sbcp-uc
packet.h
View Options
/*
File: tx_packet.h
Author: tuleu
Created on May 23, 2012, 10:13 AM
*/
#ifndef SBCP_TX_PACKET_H_
#define SBCP_TX_PACKET_H_
#include "sbcp-uc_config.h"
#include "buffers.h"
#include "sbcp.h"
/**
* \defgroup sbcp_packet_m SBCP Packet
*
* \brief Defines function to generate and manipulate response packet.
*
* These are intended to be used in sbcp_instruction_callback. To make a response
* packet one should :
*
* -# prepare the packet using sbcp_prepare_r_packet()
* -# insert the data if any inside the packet by either :
* - use *only* sbcp_put_reg_in_r_packet() if you are only sending back
* sbcp_registers. It will also efficiently compute the checksum of the
* packet, so no other calls are needed :).
* - diretcly manipulate the data :
* -# Access the data array using sbcp_r_packet_payload_buffer()
* -# Oncle all data i inserted, use sbcp_compute_packet_cs() to compute
* the checksum and place it inside
* sbcp_r_packet_buffer[SBCP_PAYLOAD_START_POS + sbcp_r_packet_buffer[SBCP_PAYLOAD_SIZE_POS]]
* -# Mark that the response packet is ready, using sbcp_mark_r_packet_ready().
*
*
* \ingroup sbcp_m
*/
/**
* Returns the payload array of the response packet. If you put a register inside the
* packet, please prefer sbcp_put_reg_in_r_packet(), as it efficiently compute
* the checksum,
*/
#define sbcp_r_packet_payload_buffer (&(sbcp_r_packet_buffer[SBCP_PAYLOAD_START_POS]))
/**
* Prepares the feedback packet with the given size and error code.
* @param payload the sbcp_payload_size of the packet
* @param error the sbcp_error code of the packet.
*/
#define sbcp_prepare_r_packet(payload,error) do{\
sbcp_r_packet_buffer[SBCP_INSTRUCTION_POS] = (error);\
sbcp_r_packet_buffer[SBCP_PAYLOAD_SIZE_POS] = (payload);\
sbcp_r_packet_buffer[SBCP_PAYLOAD_START_POS + payload] = SBCP_MY_CLASS + SBCP_MY_ID + payload + error;\
}while(0)
/**
*
* @param buffer
* @return
*/
#define sbcp_put_reg_in_r_packet(payload_index,reg_addr)do{\
sbcp_r_packet_payload_buffer[payload_index ] = sbcp_reg_msb(reg_addr);\
sbcp_r_packet_payload_buffer[payload_index + sbcp_r_packet_buffer[SBCP_PAYLOAD_SIZE_POS]] += sbcp_reg_msb(reg_addr);\
sbcp_r_packet_payload_buffer[payload_index + 1] = sbcp_reg_lsb(reg_addr);\
sbcp_r_packet_payload_buffer[payload_index + sbcp_r_packet_buffer[SBCP_PAYLOAD_SIZE_POS]] += sbcp_reg_lsb(reg_addr);\
}while(0)
#ifdef SBCP_NO_BUFFER_ALLOCATION
#define sbcp_mark_r_packet_ready() do{\
/*finish the cs*/
\
sbcp_r_packet_buffer[SBCP_PAYLOAD_START_POS + sbcp_r_packet_buffer[SBCP_PAYLOAD_SIZE_POS] ] = ~(sbcp_r_packet_buffer[SBCP_PAYLOAD_START_POS + sbcp_r_packet_buffer[SBCP_PAYLOAD_SIZE_POS] ]) & 0x00ff;\
/**\todo implement */
\
}while(0)
#else
#define sbcp_mark_r_packet_ready() do{\
/*finish the cs*/
\
sbcp_r_packet_buffer[SBCP_PAYLOAD_START_POS + sbcp_r_packet_buffer[SBCP_PAYLOAD_SIZE_POS] ] = (sbcp_r_packet_buffer[SBCP_PAYLOAD_START_POS + sbcp_r_packet_buffer[SBCP_PAYLOAD_SIZE_POS] ]) & 0x00ff;\
sbcp_mark_tx_buffer_occupied();\
}while(0)
#endif
uint8_t
sbcp_compute_packet_cs
(
unsigned
int
*
buffer
);
#endif
// SBCP_TX_PACKET_H_
Event Timeline
Log In to Comment