annotate Discovery/Src/externLogbookFlash.c @ 389:ebc2b571a0b9 maintain-1

Fix case for case sensitive OS The new file is called motion.h and not Motion.h Signed-off-by: Jan Mulder <jan@jlmulder.nl>
author Jan Mulder <jan@jlmulder.nl>
date Sun, 01 Dec 2019 17:28:35 +0100
parents c7e665e0b08f
children 2174fb133dbe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1 /**
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
3 * @copyright heinrichs weikamp
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
4 * @file externLogbookFlash.c
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
5 * @author heinrichs weikamp gmbh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
6 * @date 07-Aug-2014
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
7 * @version V0.0.4
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
8 * @since 29-Sept-2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
9 * @brief Main File to access the new 1.8 Volt Spansion S25FS256S 256 Mbit (32 Mbyte)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
10 * @bug
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
11 * @warning
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
12 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
13 @verbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
14 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
15 ##### Logbook Header (TOC) #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
16 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
17 [..] Memory useage:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
18 NEW: Spansion S25FS-S256S
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
19
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
20 only 8x 4KB and 1x 32KB, remaining is 64KB or 256KB
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
21 Sector Size (kbyte) Sector Count Sector Range Address Range (Byte Address) Notes
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
22 4 8 SA00 00000000h-00000FFFh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
23 : :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
24 SA07 00007000h-00007FFFh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
25
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
26 32 1 SA08 00008000h-0000FFFFh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
27
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
28 64 511 SA09 00010000h-0001FFFFh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
29 : :
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
30 SA519 01FF0000h-01FFFFFFh
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
31 OLD:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
32 1kB each header
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
33 with predive header at beginning
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
34 and postdive header with 0x400 HEADER2OFFSET
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
35 4kB (one erase) has two dives with 4 headers total
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
36 total of 512 kB (with 256 header ids (8 bit))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
37 Size is 280 Byte (as of 25.Nov. 2014)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
39 [..] Output to PC / UART is postdive header
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
40
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
41 [..] Block Protection Lock-Down is to erase logbook only
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
42
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
43 [..] Timing (see page 137 of LOGBOOK_V3_S25FS-S_00-271247.pdf
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
44 bulk erase is 2 minutes typ., 6 minutes max.
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
45
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
46 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
47 ##### DEMOMODE #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
48 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
49 151215: ext_flash_write_settings() is DISABLED!
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
50
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
51 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
52 ##### bug fixes #####
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
53 ==============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
54 150917: end in header and length of sample was one byte too long
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
55 as stated by Jef Driesen email 15.09.2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
56
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
57 @endverbatim
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
58 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
59 * @attention
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
60 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
61 * <h2><center>&copy; COPYRIGHT(c) 2015 heinrichs weikamp</center></h2>
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
62 *
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
63 ******************************************************************************
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
64 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
65
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
66 /* Includes ------------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
67 #include "stm32f4xx_hal.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
68 #include "externLogbookFlash.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
69 #include "ostc.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
70 #include "settings.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
71 #include "gfx_engine.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
72
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
73 #ifndef BOOTLOADER_STANDALONE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
74 #include "logbook.h"
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
75 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
76
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
77 /* Private types -------------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
78 #define FLASHSTART 0x000000
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
79 //#define FLASHSTOP 0x01FFFFFF all 32 MB with 4byte addressing
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
80 #define FLASHSTOP 0x00FFFFFF
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
81 //#define FLASHSTOP 0x3FFFFF
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
82 #define RELEASE 1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
83 #define HOLDCS 0
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
84
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
85 #define HEADER2OFFSET 0x400
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
86
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
87 typedef enum{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
88 EF_HEADER,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
89 EF_SAMPLE,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
90 EF_DEVICEDATA,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
91 EF_VPMDATA,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
92 EF_SETTINGS,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
93 EF_FIRMWARE,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
94 EF_FIRMWARE2,
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
95 }which_ring_enum;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
96
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
97
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
98 typedef struct{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
99 uint8_t IsBusy:1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
100 uint8_t IsWriteEnabled:1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
101 uint8_t BlockProtect0:1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
102 uint8_t BlockProtect1:1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
103 uint8_t BlockProtect2:1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
104 uint8_t BlockProtect3:1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
105 uint8_t IsAutoAddressIncMode:1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
106 uint8_t BlockProtectL:1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
107 } extFlashStatusUbit8_t;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
108
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
109 typedef union{
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
110 extFlashStatusUbit8_t ub;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
111 uint8_t uw;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
112 } extFlashStatusBit8_Type;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
113
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
114
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
115 /* Exported variables --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
116
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
117 /* Private variables ---------------------------------------------------------*/
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
118 static uint32_t actualAddress = 0;
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
119 static uint32_t entryPoint = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
120
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
121 static uint32_t actualPointerHeader = 0;
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
122 static uint32_t actualPointerSample = 0;
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
123 static uint32_t LengthLeftSampleRead = 0;
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
124 static uint32_t actualPointerDevicedata = 0;
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
125 static uint32_t actualPointerVPM = 0;
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
126 static uint32_t actualPointerSettings = 0;
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
127 static uint32_t actualPointerFirmware = 0;
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
128 static uint32_t actualPointerFirmware2 = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
129
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
130 /* Private function prototypes -----------------------------------------------*/
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
131 static void chip_unselect(void);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
132 static void chip_select(void);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
133 static void error_led_on(void);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
134 static void error_led_off(void);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
136 static void write_spi(uint8_t data, uint8_t unselect_CS_afterwards);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
137 static uint8_t read_spi(uint8_t unselect_CS_afterwards);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
138 static void write_address(uint8_t unselect_CS_afterwards);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
139 static void Error_Handler_extflash(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
140 static void wait_chip_not_busy(void);
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
141 static void ext_flash_incf_address(uint8_t type);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
142 //void ext_flash_incf_address_ring(void);
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
143 static void ext_flash_decf_address_ring(uint8_t type);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
144
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
145 static void ext_flash_erase4kB(void);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
146 static void ext_flash_erase32kB(void);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
147 static void ext_flash_erase64kB(void);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
148 static uint8_t ext_flash_erase_if_on_page_start(void);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
149
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
150 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
152 static void ext_flash_read_block(uint8_t *getByte, uint8_t type);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
153 static void ext_flash_read_block_multi(void *getByte, uint32_t size, uint8_t type);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
154 static void ext_flash_read_block_stop(void);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
155
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
156 static void ef_hw_rough_delay_us(uint32_t delayUs);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
157 static void ef_erase_64K(uint32_t blocks);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
158
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
159 static void ext_flash_overwrite_sample_without_erase(uint8_t *pSample, uint16_t length);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
160
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
161 static void ext_flash_disable_protection(void);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
162
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
163 static _Bool ext_flash_test_remaining_space_of_page_empty(uint32_t pointer, uint16_t length);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
164 static void ext_flash_set_to_begin_of_next_page(uint32_t *pointer, uint8_t type);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
165 static void ext_flash_find_start(void);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
169
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
170 void ext_flash_write_firmware(uint8_t *pSample1, uint32_t length1)//, uint8_t *pSample2, uint32_t length2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
171 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
172 general32to8_Type lengthTransform;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174 lengthTransform.u32 = length1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 actualPointerFirmware = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177 ef_write_block(lengthTransform.u8,4, EF_FIRMWARE, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 ef_write_block(pSample1,length1, EF_FIRMWARE, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
179
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 // if(length2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181 // ef_write_block(pSample2,length2, EF_FIRMWARE, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 uint8_t ext_flash_read_firmware_version(char *text)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 uint32_t backup = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187 uint8_t buffer[4];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 // + 4 for length data, see ext_flash_write_firmware
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 actualAddress = FWSTART + 4 + 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 ext_flash_read_block(&buffer[0], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 ext_flash_read_block(&buffer[1], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 ext_flash_read_block(&buffer[2], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 ext_flash_read_block(&buffer[3], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 actualAddress = backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 uint8_t ptr = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 text[ptr++] = 'V';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 ptr += gfx_number_to_string(2,0,&text[ptr],buffer[0] & 0x3F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 text[ptr++] = '.';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204 ptr += gfx_number_to_string(2,0,&text[ptr],buffer[1] & 0x3F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 text[ptr++] = '.';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 ptr += gfx_number_to_string(2,0,&text[ptr],buffer[2] & 0x3F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207 text[ptr++] = ' ';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 if(buffer[3])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 text[ptr++] = 'b';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 text[ptr++] = 'e';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 text[ptr++] = 't';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 text[ptr++] = 'a';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 text[ptr++] = ' ';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 return ptr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 uint32_t ext_flash_read_firmware(uint8_t *pSample1, uint32_t max_length, uint8_t *magicByte)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 uint32_t backup = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 general32to8_Type lengthTransform;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 actualAddress = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 ext_flash_read_block(&lengthTransform.u8[0], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
229 ext_flash_read_block(&lengthTransform.u8[1], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 ext_flash_read_block(&lengthTransform.u8[2], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 ext_flash_read_block(&lengthTransform.u8[3], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 if(lengthTransform.u32 == 0xFFFFFFFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 lengthTransform.u32 = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 if(lengthTransform.u32 > max_length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241 lengthTransform.u32 = 0xFF000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 for(uint32_t i = 0; i<lengthTransform.u32; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 ext_flash_read_block(&pSample1[i], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 if(magicByte)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 *magicByte = pSample1[0x10000 + 0x3E]; // 0x3E == 62
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
257 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
258
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
259 actualAddress = backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 return lengthTransform.u32;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 void ext_flash_write_firmware2(uint32_t offset, uint8_t *pSample1, uint32_t length1, uint8_t *pSample2, uint32_t length2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266 general32to8_Type lengthTransform, offsetTransform;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 lengthTransform.u32 = length1 + length2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 offsetTransform.u32 = offset;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271 actualPointerFirmware2 = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 ef_write_block(lengthTransform.u8,4, EF_FIRMWARE2, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
273 ef_write_block(offsetTransform.u8,4, EF_FIRMWARE2, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 ef_write_block(pSample1,length1, EF_FIRMWARE2, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275 if(length2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 ef_write_block(pSample2,length2, EF_FIRMWARE2, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 uint32_t ext_flash_read_firmware2(uint32_t *offset, uint8_t *pSample1, uint32_t max_length1, uint8_t *pSample2, uint32_t max_length2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 uint32_t backup = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 uint32_t length1, length2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 general32to8_Type lengthTransform, offsetTransform;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286 actualAddress = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
289 ext_flash_read_block(&lengthTransform.u8[0], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 ext_flash_read_block(&lengthTransform.u8[1], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 ext_flash_read_block(&lengthTransform.u8[2], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 ext_flash_read_block(&lengthTransform.u8[3], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 ext_flash_read_block(&offsetTransform.u8[0], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 ext_flash_read_block(&offsetTransform.u8[1], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296 ext_flash_read_block(&offsetTransform.u8[2], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 ext_flash_read_block(&offsetTransform.u8[3], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 *offset = offsetTransform.u32;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301 if(lengthTransform.u32 == 0xFFFFFFFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 lengthTransform.u32 = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306 if(lengthTransform.u32 > max_length1 + max_length2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308 lengthTransform.u32 = 0xFF000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 if(lengthTransform.u32 < max_length1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 length1 = lengthTransform.u32;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 length2 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 length1 = max_length1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 length2 = lengthTransform.u32 - max_length1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 if(pSample1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 for(uint32_t i = 0; i<length1; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 ext_flash_read_block(&pSample1[i], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 if(pSample2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 for(uint32_t i = 0; i<length2; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 ext_flash_read_block(&pSample2[i], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 else if(pSample2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 actualAddress += length1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 for(uint32_t i = 0; i<length2; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 ext_flash_read_block(&pSample2[i], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
343 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
344 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
345 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 actualAddress = backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 return lengthTransform.u32;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 void ext_flash_read_fixed_16_devicedata_blocks_formated_128byte_total(uint8_t *buffer)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 SDeviceLine data[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 uint8_t tempLengthIngnore;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 uint16_t count;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 uint8_t transfer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359 RTC_DateTypeDef Sdate;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 RTC_TimeTypeDef Stime;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 actualAddress = DDSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 ext_flash_read_block(&tempLengthIngnore, EF_DEVICEDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366 ext_flash_read_block(&tempLengthIngnore, EF_DEVICEDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 ext_flash_read_block_multi((uint8_t *)data,16*3*4, EF_DEVICEDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371 count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 for(int i=0;i<16;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 transfer = (data[i].value_int32 >> 24) & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375 buffer[count++] = transfer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 transfer = (data[i].value_int32 >> 16) & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 buffer[count++] = transfer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378 transfer = (data[i].value_int32 >> 8) & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 buffer[count++] = transfer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 transfer = (data[i].value_int32) & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 buffer[count++] = transfer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 translateDate(data[i].date_rtc_dr, &Sdate);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 translateTime(data[i].time_rtc_tr, &Stime);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 buffer[count++] = Sdate.Year;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 buffer[count++] = Sdate.Month;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 buffer[count++] = Sdate.Date;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 buffer[count++] = Stime.Hours;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 #ifndef BOOTLOADER_STANDALONE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 void ext_flash_write_devicedata(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 uint8_t *pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 const uint16_t length = sizeof(SDevice);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399 uint8_t length_lo, length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400 uint8_t dataLength[2] = { 0 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402 ext_flash_disable_protection();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
403
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 pData = (uint8_t *)stateDeviceGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 actualPointerDevicedata = DDSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 length_lo = (uint8_t)(length & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
409 length_hi = (uint8_t)(length >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410 dataLength[0] = length_lo;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 dataLength[1] = length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 ef_write_block(dataLength,2, EF_DEVICEDATA, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414 ef_write_block(pData,length, EF_DEVICEDATA, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
415 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
416
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
417
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
418 uint16_t ext_flash_read_devicedata(uint8_t *buffer, uint16_t max_length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
419 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
420 uint16_t length;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421 uint8_t length_lo, length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 actualAddress = DDSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426 ext_flash_read_block(&length_lo, EF_DEVICEDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 ext_flash_read_block(&length_hi, EF_DEVICEDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
429 length = (length_hi * 256) + length_lo;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
430
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
431 if(length > max_length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434 ext_flash_read_block_multi(buffer,length,EF_DEVICEDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 return length;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
440
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441 void ext_flash_write_vpm(SVpm *vpmInput)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
442 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
443 uint8_t *pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
444 const uint16_t length = sizeof(SVpm);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
446 uint8_t length_lo, length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
447 uint8_t dataLength[2] = { 0 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 pData = (uint8_t *)vpmInput;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
451 actualPointerVPM = VPMSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
452
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
453 length_lo = (uint8_t)(length & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
454 length_hi = (uint8_t)(length >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
455 dataLength[0] = length_lo;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
456 dataLength[1] = length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
457
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
458 ef_write_block(dataLength,2, EF_VPMDATA, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
459 ef_write_block(pData,length, EF_VPMDATA, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
460 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
461
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
462
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
463 int ext_flash_read_vpm(SVpm *vpmOutput)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
464 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 uint8_t *pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
466 const uint16_t length = sizeof(SVpm);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
467 uint8_t length_lo, length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
468 int output;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
469
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
470 actualAddress = VPMSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473 ext_flash_read_block(&length_lo, EF_VPMDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474 ext_flash_read_block(&length_hi, EF_VPMDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 if((length_lo == (uint8_t)(length & 0xFF))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 &&(length_hi == (uint8_t)(length >> 8)))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 pData = (uint8_t *)vpmOutput;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479 for(uint16_t i = 0; i < length; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 ext_flash_read_block(&pData[i], EF_VPMDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 output = length;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484 output = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 return output;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 #ifdef DEMOMODE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491 void ext_flash_write_settings(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495 #else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496 void ext_flash_write_settings(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 uint8_t *pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 const uint16_t length = sizeof(SSettings);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 uint8_t length_lo, length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 uint8_t dataLength[2] = { 0 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503 ext_flash_disable_protection();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505 if(stateRealGetPointer()->lastKnownBatteryPercentage)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 settingsGetPointer()->lastKnownBatteryPercentage = stateRealGetPointer()->lastKnownBatteryPercentage;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 settingsGetPointer()->backup_localtime_rtc_tr = stateRealGetPointer()->lifeData.timeBinaryFormat;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 settingsGetPointer()->backup_localtime_rtc_dr = stateRealGetPointer()->lifeData.dateBinaryFormat;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 pData = (uint8_t *)settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 actualPointerSettings = SETTINGSSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 length_lo = (uint8_t)(length & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 length_hi = (uint8_t)(length >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 dataLength[0] = length_lo;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519 dataLength[1] = length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 ef_write_block(dataLength,2, EF_SETTINGS, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 ef_write_block(pData,length, EF_SETTINGS, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523 // ext_flash_enable_protection();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 /* CHANGES 150929 hw
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 * this now allows to read old settings too
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
530 * but make sure that everything is fixed in
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 * set_new_settings_missing_in_ext_flash
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 * new settings should be fine as they are added
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 * and loaded before calling this function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 uint8_t ext_flash_read_settings(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 uint8_t returnValue = HAL_BUSY;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538 uint8_t *pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 const uint16_t lengthStandardNow = sizeof(SSettings);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 uint8_t length_lo, length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 uint16_t lengthOnEEPROM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 uint32_t header;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 SSettings *pSettings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545 actualAddress = SETTINGSSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
548 ext_flash_read_block(&length_lo, EF_SETTINGS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
549 ext_flash_read_block(&length_hi, EF_SETTINGS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
550
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
551 lengthOnEEPROM = length_hi * 256;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
552 lengthOnEEPROM += length_lo;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553 if(lengthOnEEPROM <= lengthStandardNow)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 ext_flash_read_block_multi(&header, 4, EF_SETTINGS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 if((header <= pSettings->header) && (header >= pSettings->updateSettingsAllowedFromHeader))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558 returnValue = HAL_OK;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 pSettings->header = header;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 pData = (uint8_t *)pSettings + 4; /* header */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 for(uint16_t i = 0; i < (lengthOnEEPROM-4); i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 ext_flash_read_block(&pData[i], EF_SETTINGS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 returnValue = HAL_ERROR;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 return returnValue;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
576 /* ext_flash_start_new_dive_log_and_set_actualPointerSample
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 * prepares the write sample pointer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 * to be used by ext_flash_write_sample()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 * to be set in the * pHeaderPreDive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 * for write with ext_flash_create_new_dive_log() and ext_flash_close_new_dive_log()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 void ext_flash_start_new_dive_log_and_set_actualPointerSample(uint8_t *pHeaderPreDive)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 convert_Type data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585 SSettings *settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 /* new 5. Jan. 2015 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 actualPointerSample = settings->logFlashNextSampleStartAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
590 if(!ext_flash_test_remaining_space_of_page_empty(actualPointerSample, 4))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 ext_flash_set_to_begin_of_next_page(&actualPointerSample, EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
592
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
593 if((actualPointerSample < SAMPLESTART) || (actualPointerSample > SAMPLESTOP))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
594 actualPointerSample = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
596 data.u32bit = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
597 pHeaderPreDive[2] = data.u8bit.byteLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
598 pHeaderPreDive[3] = data.u8bit.byteMidLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
599 pHeaderPreDive[4] = data.u8bit.byteMidHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
600 /* to start sample writing and header etc. pp. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
601 ext_flash_disable_protection_for_logbook();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
602 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
603
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
604
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
605 /* ext_flash_create_new_dive_log
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
606 * uses the first header without HEADER2OFFSET
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
607 * for the header it is not important to be complete
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
608 * and can be reconstructed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
609 * ext_flash_start_new_dive_log_and_set_actualPointerSample()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
610 * has to be called before to set the actualPointerSample
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
611 * in the header
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
612 * the following func writes to header to the ext_flash
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
613 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
614 void ext_flash_create_new_dive_log(uint8_t *pHeaderPreDive)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
615 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
616 SSettings *settings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
617 uint8_t id, id_next;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
618 uint8_t header1, header2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
619
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
620 settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
621 id = settings->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
622
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
623 actualAddress = HEADERSTART + (0x800 * id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
624 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
625 ext_flash_read_block(&header1, EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
626 ext_flash_read_block(&header2, EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
627 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
628
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
629 if((header1 == 0xFA) && (header2 == 0xFA))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
630 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
631 id += 1; /* 0-255, auto rollover */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 if(id & 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
633 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
634 actualAddress = HEADERSTART + (0x800 * id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
635 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
636 ext_flash_read_block(&header1, EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
637 ext_flash_read_block(&header2, EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
638 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
639 if((header1 == 0xFA) && (header2 == 0xFA))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
640 id += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
641 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
642 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 id = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
646 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
647
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
648 /* delete next header */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649 id_next = id + 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650 actualPointerHeader = HEADERSTART + (0x800 * id_next);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 ef_write_block(0,0, EF_HEADER, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 settings->lastDiveLogId = id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 actualPointerHeader = HEADERSTART + (0x800 * id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
656 if(pHeaderPreDive != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 ef_write_block(pHeaderPreDive,HEADERSIZE, EF_HEADER, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661 void ext_flash_close_new_dive_log(uint8_t *pHeaderPostDive )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 SSettings * settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664 uint8_t id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 convert_Type startAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 convert_Type data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667 uint32_t backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 uint8_t sampleData[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670 actualAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 sampleData[0] = 0xFD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 sampleData[1] = 0xFD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 ext_flash_write_sample(sampleData, 2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 /* end of sample data, pointing to the last sample 0xFD
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 actualAddress = actualPointerSample; // change hw 17.09.2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678 ext_flash_decf_address_ring(EF_SAMPLE); // 17.09.2015: this decf actualAddress only!!
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679 actualPointerSample = actualAddress; // change hw 17.09.2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 data.u32bit = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 pHeaderPostDive[5] = data.u8bit.byteLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 pHeaderPostDive[6] = data.u8bit.byteMidLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 pHeaderPostDive[7] = data.u8bit.byteMidHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 /* take data written before, calculate length and write
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 SLogbookHeader has different order: length (byte# 8,9,10) prior to profile version (byte# 11)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 startAddress.u8bit.byteLow = pHeaderPostDive[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 startAddress.u8bit.byteMidLow = pHeaderPostDive[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 startAddress.u8bit.byteMidHigh = pHeaderPostDive[4];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
692 startAddress.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694 if(startAddress.u32bit < actualPointerSample)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 data.u32bit = 1 + actualPointerSample - startAddress.u32bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697 data.u32bit = 2 + (actualPointerSample - SAMPLESTART) + (SAMPLESTOP - startAddress.u32bit);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 pHeaderPostDive[8] = data.u8bit.byteLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
700 pHeaderPostDive[9] = data.u8bit.byteMidLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
701 pHeaderPostDive[10] = data.u8bit.byteMidHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703 /* set id and write post-dive-header
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
704 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
705 id = settings->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 actualPointerHeader = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 ef_write_block(pHeaderPostDive,HEADERSIZE, EF_HEADER, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 /* write length at beginning of sample
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 and write proper beginning for next dive to actualPointerSample
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 backup = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 actualPointerSample = startAddress.u32bit; // is still 0xFF
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 sampleData[0] = data.u8bit.byteLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 sampleData[1] = data.u8bit.byteMidLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 sampleData[2] = data.u8bit.byteMidHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 ext_flash_overwrite_sample_without_erase(sampleData, 3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 actualAddress = backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 ext_flash_incf_address(EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 actualPointerSample = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 ext_flash_enable_protection();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727 void ext_flash_write_sample(uint8_t *pSample, uint16_t length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 ef_write_block(pSample,length, EF_SAMPLE, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731 SSettings *settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732 settings->logFlashNextSampleStartAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
735 static void ext_flash_overwrite_sample_without_erase(uint8_t *pSample, uint16_t length)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 ef_write_block(pSample,length, EF_SAMPLE, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 uint8_t ext_flash_count_dive_headers(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 uint8_t id = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 uint8_t counter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 uint16_t headerStartData = 0x0000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 id = settingsGetPointer()->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 do
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753 ext_flash_read_block_multi((uint8_t *)&headerStartData, 2, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 counter++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 id -=1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757 } while((headerStartData == 0xFAFA) && (counter < 255));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 return (counter - 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 void ext_flash_read_dive_header(uint8_t *pHeaderToFill, uint8_t StepBackwards)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 SSettings *settings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765 uint8_t id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 uint16_t i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 id = settings->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770 id -= StepBackwards; /* 0-255, auto rollover */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774 for(i = 0; i < HEADERSIZE; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 ext_flash_read_block(&pHeaderToFill[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 void ext_flash_read_dive_header2(uint8_t *pHeaderToFill, uint8_t id, _Bool bOffset)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 uint16_t i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 actualAddress = HEADERSTART + (0x800 * id) ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 if(bOffset)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 actualAddress += HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 for(i = 0; i < HEADERSIZE; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 ext_flash_read_block(&pHeaderToFill[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 uint32_t ext_flash_read_dive_raw_with_double_header_1K(uint8_t *data, uint32_t max_size, uint8_t StepBackwards)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797 if(max_size < 0x800)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 uint8_t id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
801 convert_Type dataStart, dataEnd;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
802 uint32_t LengthAll = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804 id = settingsGetPointer()->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 id -= StepBackwards; /* 0-255, auto rollover */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
807 // clear data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
808 for(int i=0;i<0x800;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
809 data[i] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
810
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
811 // copy primary/pre-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
812 actualAddress = HEADERSTART + (0x800 * id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
813 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
814 for(int i = 0; i < HEADERSIZE; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
815 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
816 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
817
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
818 // copy main/secondary/post-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
819 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
820 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
821 for(int i = 0x400; i < HEADERSIZE+0x400; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
822 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
825 // data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 dataStart.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 dataStart.u8bit.byteLow = data[0x402];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829 dataStart.u8bit.byteMidLow = data[0x403];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830 dataStart.u8bit.byteMidHigh = data[0x404];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 dataEnd.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 dataEnd.u8bit.byteLow = data[0x405];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 dataEnd.u8bit.byteMidLow = data[0x406];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 dataEnd.u8bit.byteMidHigh = data[0x407];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 actualPointerSample = dataStart.u32bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838 if(dataEnd.u32bit >= dataStart.u32bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 LengthAll = 1 + dataEnd.u32bit - dataStart.u32bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 LengthAll = 2 + (dataStart.u32bit - SAMPLESTART) + (SAMPLESTOP - dataEnd.u32bit);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 LengthAll += 0x800;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 if(LengthAll > max_size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 return 0x800;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 actualAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850 for(uint32_t i = 0x800; i < LengthAll; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851 ext_flash_read_block(&data[i], EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 return LengthAll;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 void ext_flash_write_dive_raw_with_double_header_1K(uint8_t *data, uint32_t length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 convert_Type dataStart, dataEnd;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 SLogbookHeader headerTemp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861 // set actualPointerSample and get pointer to sample storage and disable flash write protect
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 ext_flash_start_new_dive_log_and_set_actualPointerSample((uint8_t *)&headerTemp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 dataStart.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 dataStart.u8bit.byteLow = headerTemp.pBeginProfileData[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 dataStart.u8bit.byteMidLow = headerTemp.pBeginProfileData[1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867 dataStart.u8bit.byteMidHigh = headerTemp.pBeginProfileData[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869 dataEnd.u32bit = dataStart.u32bit + length - 0x801;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 if(dataEnd.u32bit > SAMPLESTOP)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 dataEnd.u32bit -= SAMPLESTOP + SAMPLESTART - 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 data[0x002] = data[0x402] = dataStart.u8bit.byteLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 data[0x003] = data[0x403] = dataStart.u8bit.byteMidLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875 data[0x004] = data[0x404] = dataStart.u8bit.byteMidHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 data[0x005] = data[0x405] = dataEnd.u8bit.byteLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 data[0x006] = data[0x406] = dataEnd.u8bit.byteMidLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878 data[0x007] = data[0x407] = dataEnd.u8bit.byteMidHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 // set actualPointerHeader to next free header and update lastDiveLogId
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881 ext_flash_create_new_dive_log(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883 // copy header data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884 ef_write_block(data,0x800,EF_HEADER, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
886 // copy sample data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 ef_write_block(&data[0x800], length-0x800, EF_SAMPLE, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889 // update logFlashNextSampleStartAddress
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 settingsGetPointer()->logFlashNextSampleStartAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 // ext_flash_read_header_memory
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896 /// @brief This function returns the entire header space 1:1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 /// @date 04-April-2016
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 /// @param *data 256KB output
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901 void ext_flash_read_header_memory(uint8_t *data)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 actualAddress = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 actualPointerHeader = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906 for(int i=0;i<8;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907 ext_flash_read_block_multi(&data[0x8000 * i], 0x8000, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913 // ext_flash_read_header_memory
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914 /// @brief This function erases and overwrites the entire logbook header block
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 /// @date 04-April-2016
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 /// @param *data 256KB input of header memory 1:1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 void ext_flash_write_header_memory(uint8_t *data)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921 actualAddress = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 actualPointerHeader = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923 ef_write_block(data, 0x40000, EF_HEADER, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 void ext_flash_open_read_sample(uint8_t StepBackwards, uint32_t *totalNumberOfBytes)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 SSettings *settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 uint8_t id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 convert_Type dataStart, dataEnd;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932 uint8_t header1, header2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934 id = settings->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 id -= StepBackwards; /* 0-255, auto rollover */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 #
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 actualPointerHeader = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 /* little endian */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 ext_flash_read_block(&header1, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 ext_flash_read_block(&header2, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 dataStart.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
947 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 dataEnd.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954 actualPointerSample = dataStart.u32bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 if(dataEnd.u32bit >= dataStart.u32bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 LengthLeftSampleRead = 1 + dataEnd.u32bit - dataStart.u32bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958 LengthLeftSampleRead = 2 + (dataStart.u32bit - SAMPLESTART) + (SAMPLESTOP - dataEnd.u32bit);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 *totalNumberOfBytes = LengthLeftSampleRead;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961 actualAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 void ext_flash_read_next_sample_part(uint8_t *pSample, uint8_t length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 for(uint16_t i = 0; i < length; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969 ext_flash_read_block(&pSample[i], EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973 void ext_flash_close_read_sample(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975 actualPointerSample = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 void ext_flash_set_entry_point(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982 entryPoint = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
983 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
984
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
985
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 void ext_flash_reopen_read_sample_at_entry_point(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988 error_led_on();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989 chip_unselect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 actualAddress = entryPoint;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 error_led_off();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998 uint8_t ext_flash_point_to_64k_block_in_headerSpace(uint8_t logId)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000 uint32_t pointerToData = logId * 0x800;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 return pointerToData / 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1003 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 // ext_flash_repair_dive_numbers_starting_count_helper
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009 /// @brief
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010 /// @date 22-June-2016
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 // ===============================================================================
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1013 static uint16_t ext_flash_repair_dive_numbers_starting_count_helper(uint8_t *data, uint8_t *change64k, uint16_t startNumber, uint8_t lastLogId)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015 const uint32_t headerStep = 0x800;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1016 uint8_t actualLogId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1017 uint16_t oldNumber = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1018 uint16_t actualNumber = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1019 SLogbookHeader *ptrLogbookHeader = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1020
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1021 if(startNumber == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1022 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1023
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1024 actualNumber = startNumber - 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1025
282
c7e665e0b08f translate some comments into english
heinrichsweikamp
parents: 268
diff changeset
1026 // where is the oldest dive (Which is now getting startNumber)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1027 // use first header for ease (without HEADER2OFFSET for end of dive header)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1028 // compare for lastLogId to prevent endless loop
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1029
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1030 if(*(uint16_t*)&data[lastLogId * headerStep] != 0xFAFA)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1031 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1032
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1033 actualLogId = lastLogId - 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034 while((*(uint16_t*)&data[actualLogId * headerStep] == 0xFAFA) && (actualLogId != lastLogId))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 actualLogId--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 // now pointing to one behind the last
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040 while(actualLogId != lastLogId)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042 actualLogId++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043 actualNumber++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 ptrLogbookHeader = (SLogbookHeader *)&data[actualLogId * headerStep];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046 oldNumber = ptrLogbookHeader->diveNumber;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047 if(oldNumber != actualNumber)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049 // change64k[ext_flash_point_to_64k_block_in_headerSpace(actualLogId )] = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050 change64k[(actualLogId * 0x800)/0x10000] = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 ptrLogbookHeader->diveNumber = actualNumber;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 ptrLogbookHeader = (SLogbookHeader *)(&data[actualLogId * headerStep] + HEADER2OFFSET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 ptrLogbookHeader->diveNumber = actualNumber;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057 return actualNumber;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061 // ext_flash_repair_SPECIAL_dive_numbers_starting_count_with
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 /// @brief This function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063 /// @date 04-April-2016
282
c7e665e0b08f translate some comments into english
heinrichsweikamp
parents: 268
diff changeset
1064 /// problem (160621): 64K blocks (32 dives) in the new flash memory chip
c7e665e0b08f translate some comments into english
heinrichsweikamp
parents: 268
diff changeset
1065 /// This block needs to be deleted
c7e665e0b08f translate some comments into english
heinrichsweikamp
parents: 268
diff changeset
1066 /// these where only 4KB block before
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067 /// @output endCount, last diveNumber
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 uint16_t ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(uint16_t startCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072 uint32_t logCopyDataPtr = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073 uint8_t *data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074 uint16_t lastCount;
282
c7e665e0b08f translate some comments into english
heinrichsweikamp
parents: 268
diff changeset
1075 uint8_t listOfChanged64kBlocks[8]; // 32 dives each 64K
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077 logCopyDataPtr = getFrame(97);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078 data = (uint8_t *)logCopyDataPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080 for(int i=0;i<8;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081 listOfChanged64kBlocks[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 actualAddress = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085 ext_flash_read_block_multi(data,0x100000,EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 lastCount = ext_flash_repair_dive_numbers_starting_count_helper(data, listOfChanged64kBlocks, startCount, settingsGetPointer()->lastDiveLogId);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 for(int i=0;i<8;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092 if(listOfChanged64kBlocks[i] != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 actualPointerHeader = HEADERSTART + (i * 0x10000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095 ef_write_block(&data[i * 0x10000], 0x10000, EF_HEADER, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099 releaseFrame(97,logCopyDataPtr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 if(settingsGetPointer()->totalDiveCounter < lastCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 settingsGetPointer()->totalDiveCounter = lastCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104 return lastCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1107 /*
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 void OLD_ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(uint16_t startCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 uint16_t counterStorage[256];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 uint8_t start = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 uint32_t logCopyDataPtr = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113 uint8_t *data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114 uint8_t startAbsolute = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 int16_t count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 _Bool repair = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 uint8_t startBackup = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119 SLogbookHeader tempLogbookHeader;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 SLogbookHeader *ptrHeaderInData1a;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1121 SLogbookHeader *ptrHeaderInData1b;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1122 SLogbookHeader *ptrHeaderInData2a;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123 SLogbookHeader *ptrHeaderInData2b;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 logCopyDataPtr = getFrame(97);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 data = (uint8_t *)logCopyDataPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 ptrHeaderInData1a = (SLogbookHeader *)logCopyDataPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128 ptrHeaderInData1b = (SLogbookHeader *)(logCopyDataPtr + HEADER2OFFSET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129 ptrHeaderInData2a = (SLogbookHeader *)(logCopyDataPtr + 0x800);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 ptrHeaderInData2b = (SLogbookHeader *)(logCopyDataPtr + 0x800 + HEADER2OFFSET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132 // get data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133 for(int StepBackwards = 0; StepBackwards < 255; StepBackwards++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1134 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135 logbook_getHeader(StepBackwards, &tempLogbookHeader);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 counterStorage[StepBackwards+1] = tempLogbookHeader.diveNumber;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137 if(tempLogbookHeader.diveHeaderStart == 0xFAFA)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138 start = StepBackwards;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143 if(start == 0xFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146 count = start + 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 startAbsolute = settingsGetPointer()->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1150
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 if(start%2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153 if(counterStorage[start] != startCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155 // clear data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 for(int i=0;i<0x800*2;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157 data[i] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 uint8_t id = settingsGetPointer()->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160 id -= start; // 0-255, auto rollover
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162 // copy primary/pre-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 actualAddress = HEADERSTART + (0x800 * id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165 for(int i = 0; i < HEADERSIZE; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 // copy main/secondary/post-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1172 for(int i = 0x400; i < HEADERSIZE+0x400; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1173 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1174 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176 // repair
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 ptrHeaderInData2a->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 ptrHeaderInData2b->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179 startCount++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 // write
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 actualAddress = HEADERSTART + (0x800 * (id-1));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1183 ef_write_block(data,0x800*2,EF_HEADER, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185 start--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 }
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1187
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188 // for(int count = start; count > -1; count -= 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190 while(count > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 // clear data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 for(int i=0;i<0x1000;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 data[i] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196 repair = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198 startBackup = startAbsolute;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 if(startAbsolute%2) // 0x800 to 0x1000
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202 // copy second pre-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203 actualAddress = HEADERSTART + (0x800 * startAbsolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205 for(int i = 0x800; i < HEADERSIZE+0x800; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209 // copy second post-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210 actualAddress = HEADERSTART + HEADER2OFFSET + (0x800 * startAbsolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 for(int i = 0xC00; i < HEADERSIZE+0xC00; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1215
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216 if(counterStorage[count] != startCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218 ptrHeaderInData2a->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219 ptrHeaderInData2b->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220 repair = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 startCount += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 startAbsolute -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 count -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 if(count > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229 // copy first pre-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230 actualAddress = HEADERSTART + (0x800 * startAbsolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232 for(int i = 0; i < HEADERSIZE; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236 // copy first post-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237 actualAddress = HEADERSTART + (0x800 * startAbsolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239 for(int i = 0x400; i < HEADERSIZE+0x400; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243 if(counterStorage[count] != startCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 ptrHeaderInData1a->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246 ptrHeaderInData1b->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247 repair = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 startCount += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251 startAbsolute -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 count -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257 // copy first pre-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1258 actualAddress = HEADERSTART + (0x800 * startAbsolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260 for(int i = 0; i < HEADERSIZE; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264 // copy first post-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265 actualAddress = HEADERSTART + (0x800 * startAbsolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267 for(int i = 0x400; i < HEADERSIZE+0x400; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271 if(counterStorage[count] != startCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1273 ptrHeaderInData1a->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 ptrHeaderInData1b->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275 repair = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277 startCount += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279 startAbsolute -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280 count -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283 // write
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284 if(repair)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286 actualPointerHeader = HEADERSTART + (0x1000 * startBackup%2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287 ef_write_block(data,0x1000,EF_HEADER, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290 releaseFrame(97,logCopyDataPtr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 settingsGetPointer()->totalDiveCounter = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 }
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1293 */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1295 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1296 // ext_flash_repair_dive_log
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1297 /// @brief This function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1298 /// does set
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1299 /// logFlashNextSampleStartAddress
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1300 /// and
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1301 /// lastDiveLogId
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1302 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1303 void ext_flash_repair_dive_log(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1304 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1305 uint8_t header1, header2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1306 convert_Type dataStart;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1307
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1308 for(int id = 0; id < 255;id++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1309 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1310 actualAddress = HEADERSTART + (0x800 * id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1311 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1312 ext_flash_read_block(&header1, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1313 ext_flash_read_block(&header2, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1314 dataStart.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1315 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1316 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1317 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1318 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1319 if((header1 == 0xFA) && (header2 == 0xFA))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1320 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1321 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1322 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1323 ext_flash_read_block(&header1, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1324 ext_flash_read_block(&header2, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1325 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1326 if((header1 != 0xFA) || (header2 != 0xFA))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1327 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1328 actualPointerSample = dataStart.u32bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1329 actualAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1330 logbook_recover_brokenlog(id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1331 SSettings *settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1332 settings->logFlashNextSampleStartAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1333 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1334 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1335 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1336 ext_flash_find_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1337 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1338
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1339
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1340 static void ext_flash_find_start(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1341 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1342 uint8_t id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1343 uint8_t header1, header2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1344 convert_Type dataStart, dataEnd;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1345
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1346 for(id = 0; id < 255;id++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1347 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1348 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1349 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1350 ext_flash_read_block(&header1, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1351 ext_flash_read_block(&header2, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1352 dataStart.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1353 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1354 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1355 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1356 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1357 if((header1 == 0xFF) && (header2 == 0xFF))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1358 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1359 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1360 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1361 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1362 id--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1363 SSettings *settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1364 settings->lastDiveLogId = id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1365
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1366 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1367 actualPointerHeader = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1368
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1369 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1370
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1371 ext_flash_read_block(&header1, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1372 ext_flash_read_block(&header2, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1373 dataStart.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1374 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1375 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1376 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1377 dataEnd.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1378 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1379 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1380 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1381 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1382
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1383 //Find free space
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1384 if((header1 == 0xFA) && (header2 == 0xFA))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1385 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1386 uint8_t uiRead = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1387 int countFF = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1388 //End of last complete dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1389 actualPointerSample = dataEnd.u32bit ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1390 actualAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1391 //Check if there are samples of dives with less than half a minute
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1392 while(true)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1393 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1394 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1395 ext_flash_read_block(&uiRead, EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1396 if(uiRead == 0xFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1397 countFF++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1398 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1399 countFF = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1400
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1401
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1402
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1403 if(countFF == 10)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1404 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1405 actualAddress -= 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1406 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1407 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1408
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1409 //New page: clear
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1410 if(ext_flash_erase_if_on_page_start())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1411 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1412 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1413 // Set new start address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1414 actualPointerSample = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1415 settings->logFlashNextSampleStartAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1416 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1417 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1418 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1419 settings->logFlashNextSampleStartAddress = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1420 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1421 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1422
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1423
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1424 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1425
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1426 static void ext_flash_disable_protection(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1427 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1428 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1429 extFlashStatusBit8_Type status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1430
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1431 status.uw = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1432
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1433 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1434 write_spi(0x50,RELEASE); // EWSR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1435 write_spi(0x01,HOLDCS); // WRSR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1436 write_spi(status.uw,RELEASE); // new status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1437 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1438 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1439
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1440
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1441 void ext_flash_disable_protection_for_logbook(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1442 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1443 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1444 extFlashStatusBit8_Type status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1445
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1446 status.uw = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1447 status.ub.BlockProtect0 = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1448 status.ub.BlockProtect1 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1449 status.ub.BlockProtect2 = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1450 status.ub.BlockProtect3 = 0; // not set in OSTC3. Why?
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1451
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1452 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1453 write_spi(0x50,RELEASE); // EWSR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1454 write_spi(0x01,HOLDCS); // WRSR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1455 write_spi(status.uw,RELEASE); // new status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1456 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1457 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1458
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1459
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1460 void ext_flash_enable_protection(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1461 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1462 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1463 extFlashStatusBit8_Type status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1464
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1465 status.uw = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1466 status.ub.BlockProtect0 = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1467 status.ub.BlockProtect1 = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1468 status.ub.BlockProtect2 = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1469 status.ub.BlockProtect3 = 1; // not set in OSTC3. Why?
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1470
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1471 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1472 write_spi(0x50,RELEASE); // EWSR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1473 write_spi(0x01,HOLDCS); // WRSR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1474 write_spi(status.uw,RELEASE); // new status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1475 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1476 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1477
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1478
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1479 /*void ext_flash_erase_chip(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1480 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1481 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1482 write_spi(0x06,RELEASE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1483 write_spi(0x60,RELEASE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1484 wait_chip_not_busy();
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1485 }*/
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1486
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1487 void ext_flash_erase_firmware(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1488 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1489 uint32_t size, blocks_64k;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1490
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1491 actualAddress = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1492 size = 1 + FWSTOP - FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1493 blocks_64k = size / 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1494 ef_erase_64K(blocks_64k);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1495 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1496
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1497 void ext_flash_erase_firmware2(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1498 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1499 uint32_t size, blocks_64k;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1500
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1501 actualAddress = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1502 size = 1 + FWSTOP2 - FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1503 blocks_64k = size / 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1504 ef_erase_64K(blocks_64k);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1505 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1506
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1507
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1508
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1509 void ext_flash_erase_logbook(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1510 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1511 uint32_t size, blocks_64k;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1512
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1513 ext_flash_disable_protection_for_logbook();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1514
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1515 actualAddress = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1516 size = 1 + SAMPLESTOP - SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1517 blocks_64k = size / 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1518 ef_erase_64K(blocks_64k);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1519
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1520 actualAddress = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1521 size = 1 + HEADERSTOP - HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1522 blocks_64k = size / 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1523 ef_erase_64K(blocks_64k);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1524
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1525 ext_flash_enable_protection();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1526 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1527
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1528
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1529 static void ext_flash_erase4kB(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1530 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1531 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1532 write_spi(0x06,RELEASE);/* WREN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1533 write_spi(0x20,HOLDCS);/* sector erase cmd */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1534 write_address(RELEASE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1535 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1536
282
c7e665e0b08f translate some comments into english
heinrichsweikamp
parents: 268
diff changeset
1537 /* be careful - might not work with entire family and other products
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1538 * see page 14 of LOGBOOK_V3_S25FS-S_00-271247.pdf
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1539 */
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1540 static void ext_flash_erase32kB(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1541 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1542 uint32_t actualAddress_backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1543
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1544 actualAddress_backup = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1545 actualAddress = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1546 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1547 write_spi(0x06,RELEASE);/* WREN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1548 write_spi(0xD8,HOLDCS);/* sector erase cmd */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1549 write_address(RELEASE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1550 actualAddress = actualAddress_backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1551 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1552
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1553
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1554 static void ext_flash_erase64kB(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1555 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1556 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1557 write_spi(0x06,RELEASE);/* WREN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1558 write_spi(0xD8,HOLDCS);/* sector erase cmd */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1559 write_address(RELEASE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1560 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1561
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1562
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1563 void ext_flash_read_block_start(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1564 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1565 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1566 write_spi(0x03,HOLDCS); /* WREN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1567 write_address(HOLDCS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1568 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1569
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1570 /* 4KB, 32KB, 64 KB, not the upper 16 MB with 4 Byte address at the moment */
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1571 static uint8_t ext_flash_erase_if_on_page_start(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1572 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1573 if(actualAddress < 0x00008000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1574 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1575 /* 4K Byte is 0x1000 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1576 if((actualAddress & 0xFFF) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1577 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1578 ext_flash_erase4kB();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1579 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1580 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1581 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1582 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1583 if(actualAddress < 0x00010000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1584 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1585 /* 32K Byte is only one page */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1586 if(actualAddress == 0x00010000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1587 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1588 ext_flash_erase32kB();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1589 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1590 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1591 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1592 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1593 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1594 /* 64K Byte is 0x10000 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1595 if((actualAddress & 0xFFFF) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1596 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1597 ext_flash_erase64kB();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1598 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1599 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1600 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1601 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1602 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1603
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1604
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1605 static void ext_flash_read_block(uint8_t *getByte, uint8_t type)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1606 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1607 *getByte = read_spi(HOLDCS);/* read data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1608 ext_flash_incf_address(type);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1609 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1610
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1611
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1612 static void ext_flash_read_block_multi(void *getByte, uint32_t size, uint8_t type)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1613 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1614 uint8_t *data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1615 data = getByte;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1616
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1617 for(uint32_t i=0;i<size;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1618 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1619 data[i] = read_spi(HOLDCS);/* read data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1620 ext_flash_incf_address(type);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1621 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1622 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1623
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1624
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1625 static void ext_flash_read_block_stop(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1626 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1627 chip_unselect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1628 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1629
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1630
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1631 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1632
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1633 static void ef_write_block(uint8_t * sendByte, uint32_t length, uint8_t type, uint8_t do_not_erase)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1634 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1635 uint32_t remaining_page_size, remaining_length, remaining_space_to_ring_end;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1636
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1637 if(!length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1638 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1639
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1640 uint32_t ringStart, ringStop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1641
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1642 switch(type)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1643 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1644 case EF_HEADER:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1645 actualAddress = actualPointerHeader;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1646 ringStart = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1647 ringStop = HEADERSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1648 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1649 case EF_SAMPLE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1650 actualAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1651 ringStart = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1652 ringStop = SAMPLESTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1653 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1654 case EF_DEVICEDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1655 actualAddress = actualPointerDevicedata;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1656 ringStart = DDSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1657 ringStop = DDSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1658 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1659 case EF_VPMDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1660 actualAddress = actualPointerVPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1661 ringStart = VPMSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1662 ringStop = VPMSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1663 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1664 case EF_SETTINGS:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1665 actualAddress = actualPointerSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1666 ringStart = SETTINGSSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1667 ringStop = SETTINGSSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1668 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1669 case EF_FIRMWARE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1670 actualAddress = actualPointerFirmware;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1671 ringStart = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1672 ringStop = FWSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1673 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1674 case EF_FIRMWARE2:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1675 actualAddress = actualPointerFirmware2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1676 ringStart = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1677 ringStop = FWSTOP2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1678 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1679 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1680 ringStart = FLASHSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1681 ringStop = FLASHSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1682 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1683 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1684 /* safety */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1685 if(actualAddress < ringStart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1686 actualAddress = ringStart;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1687
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1688 if(do_not_erase == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1689 ext_flash_erase_if_on_page_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1690
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1691 for(uint32_t i=0;i<length;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1692 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1693 ef_hw_rough_delay_us(5);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1694 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1695 write_spi(0x06,RELEASE); /* WREN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1696 write_spi(0x02,HOLDCS); /* write cmd */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1697 write_address(HOLDCS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1698
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1699 remaining_length = length - i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1700 remaining_page_size = actualAddress & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1701 remaining_space_to_ring_end = ringStop - actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1702
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1703 if((remaining_page_size == 0) && (remaining_length >= 256) && (remaining_space_to_ring_end >= 256))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1704 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1705 for(int j=0; j<255; j++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1706 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1707 write_spi(sendByte[i],HOLDCS);/* write data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1708 actualAddress++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1709 i++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1710 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1711 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1712 /* byte with RELEASE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1713 write_spi(sendByte[i],RELEASE);/* write data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1714 actualAddress++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1715 if(actualAddress > ringStop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1716 actualAddress = ringStart;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1717 if(do_not_erase == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1718 ext_flash_erase_if_on_page_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1719 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1720 switch(type)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1721 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1722 case EF_HEADER:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1723 actualPointerHeader = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1724 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1725 case EF_SAMPLE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1726 actualPointerSample = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1727 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1728 case EF_DEVICEDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1729 actualPointerDevicedata = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1730 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1731 case EF_VPMDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1732 actualPointerVPM = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1733 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1734 case EF_SETTINGS:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1735 actualPointerSettings = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1736 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1737 case EF_FIRMWARE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1738 actualPointerFirmware = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1739 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1740 case EF_FIRMWARE2:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1741 actualPointerFirmware2 = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1742 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1743 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1744 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1745 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1746 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1747
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1748
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1749 static _Bool ext_flash_test_remaining_space_of_page_empty(uint32_t pointer, uint16_t length)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1750 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1751 if((pointer & 0xFFF) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1752 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1753
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1754 uint32_t backup = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1755 uint8_t data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1756 uint32_t size_to_page_end;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1757
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1758 size_to_page_end = 0x1000 - (pointer & 0xFFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1759 if(length > size_to_page_end)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1760 length = size_to_page_end;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1761
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1762 actualAddress = pointer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1763 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1764
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1765 for(uint16_t i = 0; i<length; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1766 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1767 ext_flash_read_block(&data, 255); // 255 = ENTIRE FLASH
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1768 if(data != 0xFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1769 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1770 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1771 actualAddress = backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1772 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1773 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1774 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1775 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1776 actualAddress = backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1777 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1778 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1779
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1780
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1781 static void ext_flash_set_to_begin_of_next_page(uint32_t *pointer, uint8_t type)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1782 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1783 uint32_t ringStart, ringStop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1784
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1785 switch(type)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1786 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1787 case EF_HEADER:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1788 ringStart = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1789 ringStop = HEADERSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1790 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1791 case EF_SAMPLE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1792 ringStart = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1793 ringStop = SAMPLESTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1794 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1795 case EF_DEVICEDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1796 ringStart = DDSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1797 ringStop = DDSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1798 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1799 case EF_VPMDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1800 ringStart = VPMSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1801 ringStop = VPMSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1802 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1803 case EF_SETTINGS:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1804 ringStart = SETTINGSSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1805 ringStop = SETTINGSSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1806 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1807 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1808 ringStart = FLASHSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1809 ringStop = FLASHSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1810 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1811 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1812
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1813 *pointer = (*pointer & 0xFFF) + 0x1000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1814
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1815 if((*pointer < ringStart) || (*pointer >= ringStop))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1816 *pointer = ringStart;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1817 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1818
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1819
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1820 static void ef_erase_64K(uint32_t blocks)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1821 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1822 for(uint32_t i = 0; i < blocks; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1823 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1824 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1825 write_spi(0x06,RELEASE);/* WREN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1826 write_spi(0xD8,HOLDCS);/* 64k erase cmd */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1827 write_address(RELEASE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1828 actualAddress += 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1829 HAL_Delay(25);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1830 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1831 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1832
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1833
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1834 static void chip_unselect(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1835 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1836 HAL_GPIO_WritePin(EXTFLASH_CSB_GPIO_PORT,EXTFLASH_CSB_PIN,GPIO_PIN_SET); // chip select
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1837 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1838
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1839 static void chip_select(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1840 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1841 HAL_GPIO_WritePin(EXTFLASH_CSB_GPIO_PORT,EXTFLASH_CSB_PIN,GPIO_PIN_RESET); // chip select
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1842 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1843
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1844 static void error_led_on(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1845 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1846 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_SET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1847 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1848
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1849 static void error_led_off(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1850 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1851 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_RESET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1852 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1853
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1854
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1855 static uint8_t read_spi(uint8_t unselect_CS_afterwards)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1856 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1857 uint8_t byte;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1858
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1859 chip_select();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1860
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1861 if(HAL_SPI_Receive(&hspiDisplay, &byte, 1, 10000) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1862 Error_Handler_extflash();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1863
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1864 while (HAL_SPI_GetState(&hspiDisplay) != HAL_SPI_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1865 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1866 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1867 if(unselect_CS_afterwards)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1868 chip_unselect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1869
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1870 return byte;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1871 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1872
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1873
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1874 static void write_spi(uint8_t data, uint8_t unselect_CS_afterwards)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1875 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1876 chip_select();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1877
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1878 if(HAL_SPI_Transmit(&hspiDisplay, &data, 1, 10000) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1879 Error_Handler_extflash();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1880
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1881 while (HAL_SPI_GetState(&hspiDisplay) != HAL_SPI_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1882 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1883 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1884 if(unselect_CS_afterwards)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1885 chip_unselect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1886 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1887
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1888
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1889 static void write_address(uint8_t unselect_CS_afterwards)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1890 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1891 uint8_t hi, med ,lo;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1892
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1893 hi = (actualAddress >> 16) & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1894 med = (actualAddress >> 8) & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1895 lo = actualAddress & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1896
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1897 write_spi(hi, HOLDCS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1898 write_spi(med, HOLDCS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1899 write_spi(lo, unselect_CS_afterwards);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1900 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1901
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1902
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1903 static void wait_chip_not_busy(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1904 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1905 uint8_t status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1906
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1907 chip_unselect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1908
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1909 write_spi(0x05,HOLDCS); /* RDSR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1910 status = read_spi(HOLDCS);/* read status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1911 while(status & 0x01)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1912 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1913 HAL_Delay(1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1914 status = read_spi(HOLDCS);/* read status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1915 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1916 chip_unselect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1917 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1918
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1919
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1920 static void ext_flash_incf_address(uint8_t type)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1921 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1922 uint32_t ringStart, ringStop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1923
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1924 actualAddress += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1925
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1926 switch(type)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1927 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1928 case EF_HEADER:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1929 ringStart = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1930 ringStop = HEADERSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1931 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1932 case EF_SAMPLE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1933 ringStart = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1934 ringStop = SAMPLESTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1935 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1936 case EF_DEVICEDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1937 ringStart = DDSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1938 ringStop = DDSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1939 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1940 case EF_VPMDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1941 ringStart = VPMSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1942 ringStop = VPMSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1943 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1944 case EF_SETTINGS:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1945 ringStart = SETTINGSSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1946 ringStop = SETTINGSSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1947 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1948 case EF_FIRMWARE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1949 ringStart = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1950 ringStop = FWSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1951 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1952 case EF_FIRMWARE2:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1953 ringStart = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1954 ringStop = FWSTOP2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1955 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1956 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1957 ringStart = FLASHSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1958 ringStop = FLASHSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1959 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1960 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1961
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1962 if((actualAddress < ringStart) || (actualAddress > ringStop))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1963 actualAddress = ringStart;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1964 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1965
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1966
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1967 static void ext_flash_decf_address_ring(uint8_t type)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1968 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1969 uint32_t ringStart, ringStop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1970
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1971 switch(type)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1972 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1973 case EF_HEADER:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1974 ringStart = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1975 ringStop = HEADERSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1976 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1977 case EF_SAMPLE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1978 ringStart = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1979 ringStop = SAMPLESTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1980 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1981 case EF_DEVICEDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1982 ringStart = DDSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1983 ringStop = DDSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1984 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1985 case EF_VPMDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1986 ringStart = VPMSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1987 ringStop = VPMSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1988 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1989 case EF_SETTINGS:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1990 ringStart = SETTINGSSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1991 ringStop = SETTINGSSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1992 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1993 case EF_FIRMWARE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1994 ringStart = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1995 ringStop = FWSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1996 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1997 case EF_FIRMWARE2:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1998 ringStart = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1999 ringStop = FWSTOP2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2000 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2001 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2002 ringStart = FLASHSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2003 ringStop = FLASHSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2004 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2005 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2006
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2007 if((actualAddress <= ringStart) || (actualAddress > ringStop))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2008 actualAddress = ringStop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2009 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2010 actualAddress -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2011 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2012
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2013
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2014 static void ef_hw_rough_delay_us(uint32_t delayUs)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2015 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2016 if(!delayUs)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2017 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2018 delayUs*= 12;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2019 while(delayUs--);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2020 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2021 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2022
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2023 static void Error_Handler_extflash(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2024 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2025 while(1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2026 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2027 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2028 }
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
2029 /*
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2030 uint8_t ext_flash_erase_firmware_if_not_empty(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2031 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2032 const uint8_t TESTSIZE_FW = 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2033
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2034 uint8_t data[TESTSIZE_FW];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2035 uint8_t notEmpty = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2036
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2037 actualAddress = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2038 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2039 for(int i = 0; i < TESTSIZE_FW; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2040 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2041 ext_flash_read_block(&data[i], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2042 if(data[i] != 0xFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2043 notEmpty = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2044 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2045 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2046
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2047 if(notEmpty)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2048 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2049 ext_flash_erase_firmware();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2050 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2051 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2052 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2053 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2054 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2055
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2056 uint8_t ext_flash_erase_firmware2_if_not_empty(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2057 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2058 const uint8_t TESTSIZE_FW = 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2059
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2060 uint8_t data[TESTSIZE_FW];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2061 uint8_t notEmpty = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2062
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2063 actualAddress = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2064 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2065 for(int i = 0; i < TESTSIZE_FW; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2066 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2067 ext_flash_read_block(&data[i], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2068 if(data[i] != 0xFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2069 notEmpty = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2070 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2071 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2072
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2073 if(notEmpty)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2074 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2075 ext_flash_erase_firmware2();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2076 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2077 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2078 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2079 return 0;
225
2bb1db22b5f5 cleanup: random set of cleanups
Jan Mulder <jlmulder@xs4all.nl>
parents: 38
diff changeset
2080 }*/