summaryrefslogtreecommitdiff
path: root/digital/zigbit/bitcloud/stack/Components/HAL/drivers/include/ofdExtMemory.h
blob: e15ed8fd975c08f682a3e2c6cb3611315f409b5a (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
/**************************************************************************//**
\file   ofdExtMemory.h

\brief  The public API of external 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:
    31/07/09 A. Khromykh - Created
*******************************************************************************/

#ifndef _OFDEXTMEMORY_H
#define _OFDEXTMEMORY_H

/******************************************************************************
                   Includes section
******************************************************************************/
#include <types.h>

/******************************************************************************
                   Define(s) section
******************************************************************************/
/** \brief Size of memory block for internal ofd algorithms */
#define OFD_BLOCK_FOR_CHECK_CRC           64
#define OFD_BLOCK_SIZE                    OFD_BLOCK_FOR_CHECK_CRC

/******************************************************************************
                   Types section
******************************************************************************/
/** \brief Status messages for upper component about ofd state */
typedef enum
{
  OFD_STATUS_SUCCESS = 0,
  OFD_STATUS_SERIAL_BUSY,
  OFD_STATUS_UNKNOWN_EXTERNAL_FLASH_TYPE,
  OFD_STATUS_INCORRECT_API_PARAMETER,
  OFD_STATUS_INCORRECT_EEPROM_PARAMETER,
  OFD_SERIAL_INTERFACE_BUSY
} OFD_Status_t ;

/** \brief Number of position for image in the external flash */
typedef enum
{
  OFD_POSITION_1,
  OFD_POSITION_2,
  OFD_POSITION_MAX
} OFD_Position_t;

/** \brief Source type which was been initiator of image saving. */
typedef enum
{
  OFD_IMAGE_WAS_SAVED_FROM_MCU,
  OFD_IMAGE_WAS_WRITTEN_THROUGH_API,
} OFD_ImageSource_t;

/** \brief Parameters for access to external memory  \n
 offset - offset from start address  \n
 data - pointer to mcu ram area with\for data for\from external memory  \n
 length - size of mcu ram area with\for data. */
typedef struct
{
  uint32_t  offset;
  uint8_t  *data;
  uint32_t  length;
} OFD_MemoryAccessParam_t;

/** \brief image crc */
typedef uint8_t OFD_Crc_t;

/** \brief Image information. Crc and image type. */
typedef struct
{
  OFD_ImageSource_t type;
  OFD_Crc_t          crc;
} OFD_ImageInfo_t;

/** \brief callback methods for OFD API. \n
 ATTENTION!!!!  Callback functions must not call public OFD API directly.
 */
typedef void (* OFD_Callback_t)(OFD_Status_t);
typedef void (* OFD_InfoCallback_t)(OFD_Status_t, OFD_ImageInfo_t *);

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

\param[in]
  cb - pointer to callback
******************************************************************************/
void OFD_Open(OFD_Callback_t cb);

/**************************************************************************//**
\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);

/**************************************************************************//**
\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);

/**************************************************************************//**
\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);

/**************************************************************************//**
\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);

/**************************************************************************//**
\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);

/**************************************************************************//**
\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);

#endif /* _OFDEXTMEMORY_H */