Chameleon-Mini
DESFireMemoryOperations.h
1 /*
2 The DESFire stack portion of this firmware source
3 is free software written by Maxie Dion Schmidt (@maxieds):
4 You can redistribute it and/or modify
5 it under the terms of this license.
6 
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 
11 The complete source distribution of
12 this firmware is available at the following link:
13 https://github.com/maxieds/ChameleonMiniFirmwareDESFireStack.
14 
15 Based in part on the original DESFire code created by
16 @dev-zzo (GitHub handle) [Dmitry Janushkevich] available at
17 https://github.com/dev-zzo/ChameleonMini/tree/desfire.
18 
19 This notice must be retained at the top of all source files where indicated.
20 */
21 
22 /*
23  * DESFireMemoryOperations.h :
24  * Maxie D. Schmidt (github.com/maxieds)
25  */
26 
27 #ifndef __DESFIRE_MEMORY_OPERATIONS_H__
28 #define __DESFIRE_MEMORY_OPERATIONS_H__
29 
30 #include "DESFireFirmwareSettings.h"
31 #include "DESFireLogging.h"
32 
33 /* Reserve some space on the stack (text / data segment) for intermediate
34  storage of strings and data we need to write so we do not have to rely
35  on a bothersome heap-based scheme for passing pointers to functions: */
36 #define DATA_BUFFER_SIZE_SMALL (32)
37 #define STRING_BUFFER_SIZE (92)
38 extern volatile char __InternalStringBuffer[STRING_BUFFER_SIZE];
39 extern char __InternalStringBuffer2[DATA_BUFFER_SIZE_SMALL];
40 
41 /*
42  * EEPROM and FRAM memory management routines:
43  */
44 void ReadBlockBytes(void *Buffer, SIZET StartBlock, SIZET Count);
45 
46 void WriteBlockBytesMain(const void *Buffer, SIZET StartBlock, SIZET Count);
47 #define WriteBlockBytes(Buffer, StartBlock, Count) \
48  WriteBlockBytesMain(Buffer, StartBlock, Count);
49 
50 void CopyBlockBytes(SIZET DestBlock, SIZET SrcBlock, SIZET Count);
51 
52 uint16_t AllocateBlocksMain(uint16_t BlockCount);
53 #define AllocateBlocks(BlockCount) \
54  AllocateBlocksMain(BlockCount);
55 
56 BYTE GetCardCapacityBlocks(void);
57 
58 void MemsetBlockBytes(uint8_t initValue, SIZET startBlock, SIZET byteCount);
59 
60 /* File data transfer related routines: */
61 void ReadDataEEPROMSource(uint8_t *Buffer, uint8_t Count);
62 void WriteDataEEPROMSink(uint8_t *Buffer, uint8_t Count);
63 
64 #endif