summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/HAL/drivers/OFD/src/ofdFakeDriver.c
blob: 2d781c70f05103a7f2173d4168b0123ead1b2890 (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/**************************************************************************//**
\file  ofdFakeDriver.c

\brief Implementation of OTAU fake flash driver.

\author
    Atmel Corporation: http://www.atmel.com \n
    Support email: avr@atmel.com

  Copyright (c) 2008-2011, Atmel Corporation. All rights reserved.
  Licensed under Atmel's Limited License Agreement (BitCloudTM).

\internal
  History:
    2/06/10 A. Khromykh - Created
*******************************************************************************/
/******************************************************************************
 *   WARNING: CHANGING THIS FILE MAY AFFECT CORE FUNCTIONALITY OF THE STACK.  *
 *   EXPERT USERS SHOULD PROCEED WITH CAUTION.                                *
 ******************************************************************************/

#ifdef _OTAU_
#if (APP_USE_OTAU == 1)
#if APP_USE_FAKE_OFD_DRIVER == 1

/******************************************************************************
                   Includes section
******************************************************************************/
#include <ofdExtMemory.h>
#include <appTimer.h>

/******************************************************************************
                   Define(s) section
******************************************************************************/
#define CALL_CALLBACK_TIME      10

/******************************************************************************
                   Prototypes section
******************************************************************************/
static void ofdRunDriverCb(void);
static void ofdRunInfoDriverCb(void);

/******************************************************************************
                   Global variables section
******************************************************************************/
static HAL_AppTimer_t ofdCallbackRunner =
{
  .interval = CALL_CALLBACK_TIME,
  .mode     = TIMER_ONE_SHOT_MODE,
};
OFD_Callback_t ofdFuncCb = NULL;
OFD_InfoCallback_t ofdFuncInfoCb = NULL;
OFD_ImageInfo_t  ofdImageInfo =
{
  .type = OFD_IMAGE_WAS_SAVED_FROM_MCU,
  .crc  = 0x00
};

/******************************************************************************
                   Implementations section
******************************************************************************/
/**************************************************************************//**
\brief Run flash driver callback if that has been initialized.
******************************************************************************/
static void ofdRunDriverCb(void)
{
  if (ofdFuncCb)
  {
    ofdFuncCb(OFD_STATUS_SUCCESS);
  }
}

/**************************************************************************//**
\brief Run flash information driver callback if that has been initialized.
******************************************************************************/
static void ofdRunInfoDriverCb(void)
{
  if (ofdFuncInfoCb)
  {
    ofdFuncInfoCb(OFD_STATUS_SUCCESS, &ofdImageInfo);
  }
}

/**************************************************************************//**
\brief Opens serial interface and checks memory type.

\param[in]
  cb - pointer to callback
******************************************************************************/
void OFD_Open(OFD_Callback_t cb)
{
  ofdFuncCb = cb;
  ofdCallbackRunner.callback = ofdRunDriverCb;
  HAL_StartAppTimer(&ofdCallbackRunner);
}

/**************************************************************************//**
\brief Closes serial interface.
******************************************************************************/
void OFD_Close(void)
{
}

/**************************************************************************//**
\brief Erases image in the external memory.

\param[in]
  pos - image position in the external memory
\param[in]
  cb - pointer to callback
******************************************************************************/
void OFD_EraseImage(OFD_Position_t pos, OFD_Callback_t cb)
{
  (void)pos;
  ofdFuncCb = cb;
  ofdCallbackRunner.callback = ofdRunDriverCb;
  HAL_StartAppTimer(&ofdCallbackRunner);
}

/**************************************************************************//**
\brief Writes data to the external memory.

\param[in]
  pos - image position for new data
\param[in]
  accessParam - pointer to the access structure
\param[in]
  cb - pointer to callback
******************************************************************************/
void OFD_Write(OFD_Position_t pos, OFD_MemoryAccessParam_t *accessParam, OFD_Callback_t cb)
{
  (void)pos;
  (void)accessParam;
  ofdFuncCb = cb;
  ofdCallbackRunner.callback = ofdRunDriverCb;
  HAL_StartAppTimer(&ofdCallbackRunner);
}

/**************************************************************************//**
\brief Flushes data from internal buffer, checks image crc and saves it to
the external memory.

\param[in]
  pos - image position for new data
\param[in]
  countBuff - pointer to the memory for internal data (memory size must be OFD_BLOCK_FOR_CHECK_CRC)
\param[in]
  cb - pointer to callback
******************************************************************************/
void OFD_FlushAndCheckCrc(OFD_Position_t pos, uint8_t *countBuff, OFD_InfoCallback_t cb)
{
  (void)pos;
  (void)countBuff;
  ofdFuncInfoCb = cb;
  ofdCallbackRunner.callback = ofdRunInfoDriverCb;
  HAL_StartAppTimer(&ofdCallbackRunner);
}

/**************************************************************************//**
\brief Saves current mcu flash and eeprom to the external memory, checks crc for its
and set command for bootloader.

\param[in]
  whereToSave - image position for current mcu flash and eeprom
\param[in]
  from        - new image position
\param[in]
  copyBuff - pointer to the memory for internal data (memory size must be OFD_BLOCK_FOR_CHECK_CRC)
\param[in]
  cb - pointer to callback
******************************************************************************/
void OFD_SwitchToNewImage(OFD_Position_t whereToSave, OFD_Position_t from, uint8_t *copyBuff, OFD_Callback_t cb)
{
  (void)whereToSave;
  (void)from;
  (void)copyBuff;
  ofdFuncCb = cb;
  ofdCallbackRunner.callback = ofdRunDriverCb;
  HAL_StartAppTimer(&ofdCallbackRunner);
}

/**************************************************************************//**
\brief Sets command for bootloader.

\param[in]
  from        - image position
\param[in]
  cb - pointer to callback
******************************************************************************/
void OFD_ChangeImage(OFD_Position_t from, OFD_Callback_t cb)
{
  (void)from;
  ofdFuncCb = cb;
  ofdCallbackRunner.callback = ofdRunDriverCb;
  HAL_StartAppTimer(&ofdCallbackRunner);
}

/**************************************************************************//**
\brief Reads image informations.

\param[in]
  pos - image position
\param[in]
  cb - pointer to callback
******************************************************************************/
void OFD_ReadImageInfo(OFD_Position_t pos, OFD_InfoCallback_t cb)
{
  (void)pos;
  ofdFuncInfoCb = cb;
  ofdCallbackRunner.callback = ofdRunInfoDriverCb;
  HAL_StartAppTimer(&ofdCallbackRunner);
}

#endif // _OTAU_
#endif // (APP_USE_OTAU == 1)
#endif // APP_USE_FAKE_OFD_DRIVER == 1

// eof ofdFakeDriver.c