summaryrefslogtreecommitdiff
path: root/source/LcmInterface.h
blob: 9525f021554c9433ed27ad43d4b37ce74a338241 (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*******************************************************************************
 * Copyright (C) ST-Ericsson SA 2011
 * License terms: 3-clause BSD license
 ******************************************************************************/

#ifndef _LCMINTERFACE_H_
#define _LCMINTERFACE_H_

#include "t_communication_service.h"
#include "t_bulk_protocol.h"
#include "t_a2_protocol.h"

#ifdef _WIN32
#include "WinApiWrappers.h"
#else
#include "LinuxApiWrappers.h"
typedef void *HMODULE;
#endif

typedef ErrorCode_e(*CommunicationInitialize_t)(void *Object_p, Communication_t **Communication_pp, Family_t Family, HashDevice_t *HashDevice_p, CommunicationDevice_t *CommunicationDevice_p, Do_CEH_Call_t CommandCallback_p, BuffersInterface_t *Buffers_p, TimersInterface_t *Timers_p, QueueInterface_t *Queue_p);
typedef ErrorCode_e(*CommunicationShutdown_t)(Communication_t **Communication_pp);
typedef ErrorCode_e(*CommunicationPoll_t)(Communication_t *Communication_p);
typedef ErrorCode_e(*CommunicationSetFamily_t)(Communication_t *Communication_p, Family_t Family, Do_CEH_Call_t CEHCallback);
typedef ErrorCode_e(*CommunicationSend_t)(Communication_t *Communication_p, void *InputData_p);
typedef ErrorCode_e(*CommunicationSetProtocolTimeouts_t)(Communication_t *Communication_p, void *TimeoutData_p);
typedef ErrorCode_e(*CommunicationGetProtocolTimeouts_t)(Communication_t *Communication_p, void *TimeoutData_p);
typedef ErrorCode_e(*CommunicationCancelReceiver_t)(Communication_t *Communication_p, uint8 PacketsBeforeTransferStop);

typedef ErrorCode_e(*R15CommandSend_t)(Communication_t *Communication_p, CommandData_t *CmdData_p);
typedef ErrorCode_e(*R15CommandResetSessionCounters_t)(const Communication_t *const Communication_p);

typedef ErrorCode_e(*R15BulkStartSession_t)(Communication_t *Communication_p, TL_BulkVectorList_t *BulkVector_p, const uint64 Offset);
typedef ErrorCode_e(*R15BulkCloseSession_t)(Communication_t *Communication_p, TL_BulkVectorList_t *BulkVector_p);
typedef TL_BulkVectorList_t*(*R15BulkCreateVector_t)(const Communication_t *const Communication_p, const uint32 BulkVector, uint32 Length, const uint32 BuffSize, TL_BulkVectorList_t *CreatedBulkVector_p);
typedef TL_BulkSessionState_t (*R15BulkGetStatusSession_t)(const Communication_t *const Communication_p, const TL_BulkVectorList_t *BulkVector_p);
typedef uint32(*R15BulkDestroyVector_t)(const Communication_t *const Communication_p, TL_BulkVectorList_t *BulkVector_p, boolean ReqReleaseBuffer);
typedef uint32(*R15BulkOpenSession_t)(const Communication_t *const Communication_p, const uint16 SessionId, const TL_SessionMode_t Mode, uint32 Length);
typedef void (*R15BulkSetCallbacks_t)(Communication_t *Communication_p, void *BulkCommandCallback_p, void *BulkDataCallback_p, void *BulkDataEndOfDump_p);

typedef ErrorCode_e(*A2CommandSend_t)(Communication_t *Communication_p, A2_CommandData_t *CmdData_p);
typedef void (*A2SpeedflashStart_t)(Communication_t *Communication_p);
typedef void (*A2SpeedflashSetLastBlock_t)(Communication_t *Communication_p);
typedef ErrorCode_e(*A2SpeedflashWriteBlock_t)(Communication_t *Communication_p, const void *Buffer, const size_t BufferSize);

typedef struct {
    CommunicationInitialize_t           Initialize_Fn;
    CommunicationShutdown_t             Shutdown_Fn;
    CommunicationPoll_t                 Poll_Fn;
    CommunicationSetFamily_t            SetFamily_Fn;
    CommunicationSend_t                 Send_Fn;
    CommunicationSetProtocolTimeouts_t  SetProtocolTimeouts_Fn;
    CommunicationGetProtocolTimeouts_t  GetProtocolTimeouts_Fn;
    CommunicationCancelReceiver_t       CancelReceiver_Fn;
} CommunicationInterface_t;

typedef struct {
    R15CommandSend_t                    Send_Fn;
    R15CommandResetSessionCounters_t    ResetSessionCounters_Fn;
} R15CommandInterface_t;

typedef struct {
    R15BulkStartSession_t           StartSession_Fn;
    R15BulkCloseSession_t           CloseSession_Fn;
    R15BulkCreateVector_t           CreateVector_Fn;
    R15BulkGetStatusSession_t       GetStatusSession_Fn;
    R15BulkDestroyVector_t          DestroyVector_Fn;
    R15BulkOpenSession_t            OpenSession_Fn;
    R15BulkSetCallbacks_t           SetCallbacks_Fn;
} R15BulkInterface_t;

typedef struct {
    A2CommandSend_t             Send_Fn;
    A2SpeedflashStart_t         SpeedflashStart_Fn;
    A2SpeedflashSetLastBlock_t      SpeedflashSetLastBlock_Fn;
    A2SpeedflashWriteBlock_t        SpeedflashWriteBlock_Fn;
} A2CommandInterface_t;

class LcmInterface
{
public:
    LcmInterface();
    virtual ~LcmInterface();

    ErrorCode_e CommunicationInitialize(void *Object_p, Family_t Family, HashDevice_t *HashDevice_p, CommunicationDevice_t *CommunicationDevice_p, Do_CEH_Call_t CommandCallback_p, BuffersInterface_t *Buffers_p, TimersInterface_t *Timers_p, QueueInterface_t *Queue_p);
    ErrorCode_e CommunicationPoll();
    ErrorCode_e CommunicationSend(void *InputData_p);
    ErrorCode_e CommunicationSetFamily(Family_t family, Do_CEH_Call_t CEHCallback);
    ErrorCode_e CommunicationSetProtocolTimeouts(void *TimeoutData_p);
    ErrorCode_e CommunicationGetProtocolTimeouts(void *TimeoutData_p);
    ErrorCode_e CommunicationShutdown();
    ErrorCode_e CommunicationCancelReceiver(uint8 PacketsBeforeReceiverStop);

    ErrorCode_e CommandSend(CommandData_t *CmdData_p);
    ErrorCode_e CommandResetSessionCounters();

    void BulkSetCallbacks(void *BulkCommandCallback_p, void *BulkDataCallback_p, void *BulkDataEndOfDump_p);
    uint32 BulkOpenSession(const uint16 SessionId, const TL_SessionMode_t Mode, uint32 Length);
    TL_BulkVectorList_t *BulkCreateVector(const uint32 BulkVector, uint32 Length, const uint32 BuffSize, TL_BulkVectorList_t *CreatedBulkVector_p);
    ErrorCode_e BulkStartSession(TL_BulkVectorList_t *BulkVector_p, const uint64 Offset);
    uint32 BulkDestroyVector(TL_BulkVectorList_t *BulkVector_p, boolean ReqReleaseBuffer);
    ErrorCode_e BulkCloseSession(TL_BulkVectorList_t *BulkVector_p);

    ErrorCode_e A2CommandSend(A2_CommandData_t *CmdData_p);
    void A2SpeedflashStart();
    void A2SpeedflashSetLastBlock();
    ErrorCode_e A2SpeedflashWriteBlock(const void *Buffer, const size_t BufferSize);

    void *getLCMContext() {
        return m_pCommunication;
    }
private:
    Communication_t *m_pCommunication;
    ErrorCode_e lcmError_;
public:
    static void SetLCMLibPath(const char *lcmLibPath);
    static int LoadLCMLibrary();
    static void CloseLCMLibrary();
private:
    static CommunicationInterface_t Communication;
    static R15CommandInterface_t    R15Command;
    static R15BulkInterface_t       R15Bulk;
    static A2CommandInterface_t     A2Command;

    static HMODULE m_hDLL;
    static char *m_pchLCMLibPath;
    static CCriticalSectionObject   m_CriticalSection;
};

#endif // _LCMINTERFACE_H_