summaryrefslogtreecommitdiff
path: root/source/LCM/include/t_protrom_network.h
blob: b29a65a8afc9866171c4da7ae9d913a06ab25812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*******************************************************************************
 * Copyright (C) ST-Ericsson SA 2011
 * License terms: 3-clause BSD license
 ******************************************************************************/
#ifndef T_PROTROM_NETWORK_H_
#define T_PROTROM_NETWORK_H_
/**
 *  @addtogroup ldr_communication_serv
 *  @{
 *    @addtogroup protrom_family
 *    @{
 *      @addtogroup ldr_protrom_network_layer
 *      @{
 */

/*******************************************************************************
 * Includes
 ******************************************************************************/
#include "t_communication_service.h"
#include "t_critical_section.h"
#include "t_protrom_header.h"

/*******************************************************************************
 * Types, constants
 ******************************************************************************/

/** PROTROM protocol ID */
#define PROTROM_PROTOCOL        (0xFB)
/** PROTROM CRC length */
#define PROTROM_CRC_LENGTH      (2)

/** Defined state of the receiver */
typedef enum {
    PROTROM_RECEIVE_HEADER,   /**< State for receiving Header.*/
    PROTROM_RECEIVE_PAYLOAD,  /**< State for receiving Payload.*/
    PROTROM_RECEIVE_ERROR,    /**< State for error handling.*/
    PROTROM_RECEIVE_IDLE      /**< State for receiver idle.*/
} Protrom_InboundState_t;

/** Defined state of the transmitter */
typedef enum {
    PROTROM_SEND_IDLE,       /**< Transmiter idle state.*/
    PROTROM_SEND_HEADER,     /**< Transmiter send header. */
    PROTROM_SEND_PAYLOAD,    /**< Transmiter send payload. */
    PROTROM_SENDING_HEADER,  /**< Transmiter is in process sending header.*/
    PROTROM_SENDING_PAYLOAD  /**< Transmiter is in process sending payload.*/
} Protrom_OutboundState_t;

/** Structure for the packet meta data type. */
typedef struct Protrom_Packet {
    Protrom_Header_t  Header;           /**< PROTROM header structure. */
    uint8             *Buffer_p;        /**< Temporary buffer for receiving data.*/
    uint16            CRC;              /**< Calculated CRC of received packet. */
    Communication_t   *Communication_p; /**< The communication over which this
                                           packet has been/is to be transferred
                                           over */
} Protrom_Packet_t;

/** Structure for handling incoming PROTROM packets.*/
typedef struct {
    /**< State of the state machine for handling incoming PROTROM packets. */
    Protrom_InboundState_t State;
    /**< Number of requested data for receiving from communication device. */
    uint32                 ReqData;
    /**< Number of receivied data from communication device. */
    uint32                 RecData;
    /**< Number of receivied data from backup buffer used for switching the
     * protocol family. */
    uint32                 RecBackupData;
    /**< Offset in the buffer for next data that should be received. */
    uint32                 ReqBuffOffset;
    /**< Temporary pointer to buffer for handling received data.*/
    uint8                  *Target_p;
    /**< Temporary buffer for receiving data. */
    uint8                  Scratch[PROTROM_HEADER_LENGTH];
    /** Number of packets before receiver is stoped. */
    uint8                  PacketsBeforeReceiverStop;
    /** Indicator for stopping the receiver. */
    boolean                StopTransfer;
    /** Temporary structure for handling PROTROM packet.*/
    Protrom_Packet_t       *Packet_p;
} Protrom_Inbound_t;

/** Structure for handling outgoing PROTROM packets.*/
typedef struct {
    /**< State of the state machine for handling outgoing PROTROM packets. */
    Protrom_OutboundState_t State;
    /** Temporary pointer for handling PROTROM packet.*/
    Protrom_Packet_t        *Packet_p;
    /**< Synchronization object to avoid parallel access in transmitter function. */
    CriticalSection_t       TxCriticalSection;
} Protrom_Outbound_t;


/** PROTROM Network context */
typedef struct {
    /**< Structure for handling incoming PROTROM packets.*/
    Protrom_Inbound_t  Inbound;
    /**< Structure for handling outgoing PROTROM packets.*/
    Protrom_Outbound_t Outbound;
} Protrom_NetworkContext_t;

/** @} */
/** @} */
/** @} */
#endif /*T_NETWORK_LAYER_H_*/