annotate Discovery/Src/externLogbookFlash.c @ 899:2225c467f1e9 Evo_2_23

Added data path and visualization for position data: The GNSS data exchange is now initialized and triggered on a cyclic basis (once a second). RTE verion has been increased because of interface change. For now only the position data is shown in a T7 surface views. The functionality may be switched on/off using the compile switch ENABLE_GNSS.
author Ideenmodellierer
date Mon, 30 Sep 2024 21:56:05 +0200
parents bc6c90e20d9e
children
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 ---------------------------------------------------------*/
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
118
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
119 #ifndef BOOTLOADER_STANDALONE
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
120 static uint32_t entryPoint = 0;
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
121 static uint32_t LengthLeftSampleRead = 0;
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
122 static uint32_t actualPointerDevicedata_Read = DDSTART;
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
123 #endif
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
124
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
125 static uint32_t actualAddress = 0;
423
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
126 static uint32_t preparedPageAddress = 0;
425
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
127 static uint32_t closeSectorAddress = 0;
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
128 static uint32_t actualPointerHeader = 0;
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
129 static uint32_t actualPointerSample = 0;
421
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
130 static uint32_t actualPointerDevicedata = DDSTART;
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
131 static uint32_t actualPointerVPM = 0;
427
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
132 static uint32_t actualPointerSettings = SETTINGSSTART;
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
133 static uint32_t actualPointerFirmware = 0;
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
134 static uint32_t actualPointerFirmware2 = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
135
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
136 /* Private function prototypes -----------------------------------------------*/
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
137 static void chip_unselect(void);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
138 static void chip_select(void);
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
139 #ifndef BOOTLOADER_STANDALONE
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
140 static void error_led_on(void);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
141 static void error_led_off(void);
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
142 static void ext_flash_decf_address_ring(uint8_t type);
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
143 static void ext_flash_disable_protection(void);
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
144 static _Bool ext_flash_test_remaining_space_of_page_empty(uint32_t pointer, uint16_t length);
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
145 static void ext_flash_set_to_begin_of_next_page(uint32_t *pointer, uint8_t type);
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
146 #endif
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
147 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
148 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
149 static void write_address(uint8_t unselect_CS_afterwards);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
150 static void Error_Handler_extflash(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
151 static void wait_chip_not_busy(void);
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
152 static void ext_flash_incf_address(uint8_t type);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
153 //void ext_flash_incf_address_ring(void);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
154
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
155 static void ext_flash_erase4kB(void);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
156 static void ext_flash_erase32kB(void);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
157 static void ext_flash_erase64kB(void);
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
158 static uint8_t ext_flash_erase_if_on_page_start(void);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
159
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
160 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
161
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
162 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
163 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
164 static void ext_flash_read_block_stop(void);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
165
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
166 static void ef_hw_rough_delay_us(uint32_t delayUs);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
167 static void ef_erase_64K(uint32_t blocks);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
168
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
169 #ifndef BOOTLOADER_STANDALONE
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
170 static void ext_flash_overwrite_sample_without_erase(uint8_t *pSample, uint16_t length);
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
171 static void ext_flash_find_start(void);
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
172 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
173
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
174
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
175
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
176 /* Exported functions --------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
177
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
178 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
179 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
180 general32to8_Type lengthTransform;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
181
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
182 lengthTransform.u32 = length1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
183
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
184 actualPointerFirmware = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
185 ef_write_block(lengthTransform.u8,4, EF_FIRMWARE, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
186 ef_write_block(pSample1,length1, EF_FIRMWARE, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
187
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
188 // if(length2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
189 // ef_write_block(pSample2,length2, EF_FIRMWARE, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
190 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
191
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
192 uint8_t ext_flash_read_firmware_version(char *text)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
193 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
194 uint32_t backup = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
195 uint8_t buffer[4];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
196
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
197 // + 4 for length data, see ext_flash_write_firmware
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
198 actualAddress = FWSTART + 4 + 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
199 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
200 ext_flash_read_block(&buffer[0], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
201 ext_flash_read_block(&buffer[1], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
202 ext_flash_read_block(&buffer[2], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
203 ext_flash_read_block(&buffer[3], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
204
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
205 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
206 actualAddress = backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
207
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
208 uint8_t ptr = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
209 text[ptr++] = 'V';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
210 ptr += gfx_number_to_string(2,0,&text[ptr],buffer[0] & 0x3F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
211 text[ptr++] = '.';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
212 ptr += gfx_number_to_string(2,0,&text[ptr],buffer[1] & 0x3F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
213 text[ptr++] = '.';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
214 ptr += gfx_number_to_string(2,0,&text[ptr],buffer[2] & 0x3F);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
215 text[ptr++] = ' ';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
216 if(buffer[3])
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
217 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
218 text[ptr++] = 'b';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
219 text[ptr++] = 'e';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
220 text[ptr++] = 't';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
221 text[ptr++] = 'a';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
222 text[ptr++] = ' ';
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
223 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
224 return ptr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
225 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
226
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
227
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
228 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
229 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
230 uint32_t backup = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
231 general32to8_Type lengthTransform;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
232
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
233 actualAddress = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
234 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
235
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
236 ext_flash_read_block(&lengthTransform.u8[0], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
237 ext_flash_read_block(&lengthTransform.u8[1], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
238 ext_flash_read_block(&lengthTransform.u8[2], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
239 ext_flash_read_block(&lengthTransform.u8[3], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
240
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
241
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
242 if(lengthTransform.u32 == 0xFFFFFFFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
243 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
244 lengthTransform.u32 = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
245 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
246 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
247 if(lengthTransform.u32 > max_length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
248 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
249 lengthTransform.u32 = 0xFF000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
250 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
251 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
252 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
253 for(uint32_t i = 0; i<lengthTransform.u32; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
254 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
255 ext_flash_read_block(&pSample1[i], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
256 }
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
260 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
261
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
262 if(magicByte)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
263 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
264 *magicByte = pSample1[0x10000 + 0x3E]; // 0x3E == 62
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
265 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
266
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
267 actualAddress = backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
268 return lengthTransform.u32;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
269 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
270
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
271
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
272 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
273 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
274 general32to8_Type lengthTransform, offsetTransform;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
275
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
276 lengthTransform.u32 = length1 + length2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
277 offsetTransform.u32 = offset;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
278
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
279 actualPointerFirmware2 = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
280 ef_write_block(lengthTransform.u8,4, EF_FIRMWARE2, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
281 ef_write_block(offsetTransform.u8,4, EF_FIRMWARE2, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
282 ef_write_block(pSample1,length1, EF_FIRMWARE2, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
283 if(length2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
284 ef_write_block(pSample2,length2, EF_FIRMWARE2, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
285 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
286
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
287
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
288 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
289 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
290 uint32_t backup = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
291 uint32_t length1, length2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
292 general32to8_Type lengthTransform, offsetTransform;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
293
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
294 actualAddress = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
295 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
296
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
297 ext_flash_read_block(&lengthTransform.u8[0], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
298 ext_flash_read_block(&lengthTransform.u8[1], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
299 ext_flash_read_block(&lengthTransform.u8[2], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
300 ext_flash_read_block(&lengthTransform.u8[3], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
301
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
302 ext_flash_read_block(&offsetTransform.u8[0], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
303 ext_flash_read_block(&offsetTransform.u8[1], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
304 ext_flash_read_block(&offsetTransform.u8[2], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
305 ext_flash_read_block(&offsetTransform.u8[3], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
306
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
307 *offset = offsetTransform.u32;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
308
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
309 if(lengthTransform.u32 == 0xFFFFFFFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
310 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
311 lengthTransform.u32 = 0xFFFFFFFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
312 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
313 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
314 if(lengthTransform.u32 > max_length1 + max_length2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
315 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
316 lengthTransform.u32 = 0xFF000000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
317 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
318 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
319 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
320 if(lengthTransform.u32 < max_length1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
321 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
322 length1 = lengthTransform.u32;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
323 length2 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
324 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
325 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
326 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
327 length1 = max_length1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
328 length2 = lengthTransform.u32 - max_length1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
329 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
330
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
331 if(pSample1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
332 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
333 for(uint32_t i = 0; i<length1; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
334 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
335 ext_flash_read_block(&pSample1[i], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
336 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
337 if(pSample2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
338 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
339 for(uint32_t i = 0; i<length2; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
340 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
341 ext_flash_read_block(&pSample2[i], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
342 }
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 else if(pSample2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
346 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
347 actualAddress += length1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
348 for(uint32_t i = 0; i<length2; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
349 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
350 ext_flash_read_block(&pSample2[i], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
351 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
352 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
353 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
354 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
355 actualAddress = backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
356 return lengthTransform.u32;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
357 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
358
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
359
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
360 void ext_flash_read_fixed_16_devicedata_blocks_formated_128byte_total(uint8_t *buffer)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
361 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
362 SDeviceLine data[16];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
363 uint8_t tempLengthIngnore;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
364 uint16_t count;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
365 uint8_t transfer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
366
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
367 RTC_DateTypeDef Sdate;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
368 RTC_TimeTypeDef Stime;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
369
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
370 actualAddress = DDSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
371
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
372 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
373 ext_flash_read_block(&tempLengthIngnore, EF_DEVICEDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
374 ext_flash_read_block(&tempLengthIngnore, EF_DEVICEDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
375
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
376 ext_flash_read_block_multi((uint8_t *)data,16*3*4, EF_DEVICEDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
377 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
378
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
379 count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
380 for(int i=0;i<16;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
381 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
382 transfer = (data[i].value_int32 >> 24) & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
383 buffer[count++] = transfer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
384 transfer = (data[i].value_int32 >> 16) & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
385 buffer[count++] = transfer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
386 transfer = (data[i].value_int32 >> 8) & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
387 buffer[count++] = transfer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
388 transfer = (data[i].value_int32) & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
389 buffer[count++] = transfer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
390
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
391 translateDate(data[i].date_rtc_dr, &Sdate);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
392 translateTime(data[i].time_rtc_tr, &Stime);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
393 buffer[count++] = Sdate.Year;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
394 buffer[count++] = Sdate.Month;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
395 buffer[count++] = Sdate.Date;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
396 buffer[count++] = Stime.Hours;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
397 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
398 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
399
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
400
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
401 #ifndef BOOTLOADER_STANDALONE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
402
421
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
403 void ext_flash_write_devicedata(uint8_t resetRing)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
404 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
405 uint8_t *pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
406 const uint16_t length = sizeof(SDevice);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
407 uint8_t length_lo, length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
408 uint8_t dataLength[2] = { 0 };
421
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
409 uint32_t tmpBlockStart;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
410
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
411 ext_flash_disable_protection();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
412
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
413 pData = (uint8_t *)stateDeviceGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
414
421
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
415 /* Reset the Ring to the start address if requested (e.g. because we write the default block during shutdown) */
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
416 if((resetRing) || ((actualPointerDevicedata + length) >= DDSTOP))
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
417 {
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
418 actualPointerDevicedata = DDSTART;
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
419 }
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
420 tmpBlockStart = actualPointerDevicedata;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
421
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
422 length_lo = (uint8_t)(length & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
423 length_hi = (uint8_t)(length >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
424 dataLength[0] = length_lo;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
425 dataLength[1] = length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
426
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
427 ef_write_block(dataLength,2, EF_DEVICEDATA, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
428 ef_write_block(pData,length, EF_DEVICEDATA, 0);
421
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
429
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
430 actualPointerDevicedata_Read = tmpBlockStart;
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
431
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
432 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
433
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
434
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
435 uint16_t ext_flash_read_devicedata(uint8_t *buffer, uint16_t max_length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
436 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
437 uint16_t length;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
438 uint8_t length_lo, length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
439
421
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
440 actualAddress = actualPointerDevicedata_Read;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
441
421
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
442 length = 0;
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
443 length_lo = 0;
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
444 length_hi = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
445 ext_flash_read_block_start();
421
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
446
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
447
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
448 ext_flash_read_block(&length_lo, EF_DEVICEDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
449 ext_flash_read_block(&length_hi, EF_DEVICEDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
450
421
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
451 while ((length_lo != 0xFF) && (length_hi != 0xFF))
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
452 {
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
453 length = (length_hi * 256) + length_lo;
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
454
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
455 if(length > max_length)
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
456 return 0;
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
457
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
458 ext_flash_read_block_multi(buffer,length,EF_DEVICEDATA);
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
459
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
460 ext_flash_read_block(&length_lo, EF_DEVICEDATA); /* check if another devicedata set is available */
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
461 ext_flash_read_block(&length_hi, EF_DEVICEDATA); /* length will be 0xFFFF if a empty memory is read */
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
462 }
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
463 ext_flash_decf_address_ring(EF_DEVICEDATA); /* set pointer back to empty address */
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
464 ext_flash_decf_address_ring(EF_DEVICEDATA);
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
465 ext_flash_read_block_stop();
421
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
466
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
467 if(actualAddress > actualPointerDevicedata) /* the write pointer has not yet been set up probably */
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
468 {
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
469 actualPointerDevicedata = actualAddress;
3f7d80f37bfc Enable sequentionel writing of device data:
ideenmodellierer
parents: 420
diff changeset
470 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
471 return length;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
472 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
473
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
474
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
475 void ext_flash_write_vpm(SVpm *vpmInput)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
476 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
477 uint8_t *pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
478 const uint16_t length = sizeof(SVpm);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
479
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
480 uint8_t length_lo, length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
481 uint8_t dataLength[2] = { 0 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
482
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
483 pData = (uint8_t *)vpmInput;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
484
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
485 actualPointerVPM = VPMSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
486
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
487 length_lo = (uint8_t)(length & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
488 length_hi = (uint8_t)(length >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
489 dataLength[0] = length_lo;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
490 dataLength[1] = length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
491
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
492 ef_write_block(dataLength,2, EF_VPMDATA, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
493 ef_write_block(pData,length, EF_VPMDATA, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
494 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
495
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
496
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
497 int ext_flash_read_vpm(SVpm *vpmOutput)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
498 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
499 uint8_t *pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
500 const uint16_t length = sizeof(SVpm);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
501 uint8_t length_lo, length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
502 int output;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
503
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
504 actualAddress = VPMSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
505
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
506 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
507 ext_flash_read_block(&length_lo, EF_VPMDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
508 ext_flash_read_block(&length_hi, EF_VPMDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
509 if((length_lo == (uint8_t)(length & 0xFF))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
510 &&(length_hi == (uint8_t)(length >> 8)))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
511 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
512 pData = (uint8_t *)vpmOutput;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
513 for(uint16_t i = 0; i < length; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
514 ext_flash_read_block(&pData[i], EF_VPMDATA);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
515 output = length;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
516 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
517 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
518 output = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
519
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
520 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
521 return output;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
522 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
523
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
524 #ifdef DEMOMODE
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
525 void ext_flash_write_settings(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
526 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
527 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
528 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
529 #else
427
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
530 void ext_flash_write_settings(uint8_t resetRing)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
531 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
532 uint8_t *pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
533 const uint16_t length = sizeof(SSettings);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
534 uint8_t length_lo, length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
535 uint8_t dataLength[2] = { 0 };
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
536
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
537 ext_flash_disable_protection();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
538
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
539 if(stateRealGetPointer()->lastKnownBatteryPercentage)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
540 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
541 settingsGetPointer()->lastKnownBatteryPercentage = stateRealGetPointer()->lastKnownBatteryPercentage;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
542 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
543 settingsGetPointer()->backup_localtime_rtc_tr = stateRealGetPointer()->lifeData.timeBinaryFormat;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
544 settingsGetPointer()->backup_localtime_rtc_dr = stateRealGetPointer()->lifeData.dateBinaryFormat;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
545
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
546 pData = (uint8_t *)settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
547
427
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
548 /* Reset the Ring to the start address if requested (e.g. because we write the default block during shutdown) */
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
549 if((resetRing) || ((actualPointerSettings + length) >= SETTINGSSTOP))
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
550 {
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
551 actualPointerSettings = SETTINGSSTART;
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
552 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
553
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
554 length_lo = (uint8_t)(length & 0xFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
555 length_hi = (uint8_t)(length >> 8);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
556 dataLength[0] = length_lo;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
557 dataLength[1] = length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
558
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
559 ef_write_block(dataLength,2, EF_SETTINGS, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
560 ef_write_block(pData,length, EF_SETTINGS, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
561 // ext_flash_enable_protection();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
562 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
563 #endif
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
564
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
565
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
566 /* CHANGES 150929 hw
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
567 * this now allows to read old settings too
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
568 * but make sure that everything is fixed in
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
569 * set_new_settings_missing_in_ext_flash
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
570 * new settings should be fine as they are added
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
571 * and loaded before calling this function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
572 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
573 uint8_t ext_flash_read_settings(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
574 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
575 uint8_t returnValue = HAL_BUSY;
538
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
576 uint8_t exit = 0;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
577 uint8_t *pData;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
578 const uint16_t lengthStandardNow = sizeof(SSettings);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
579 uint8_t length_lo, length_hi;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
580 uint16_t lengthOnEEPROM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
581 uint32_t header;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
582 SSettings *pSettings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
583
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
584 actualAddress = SETTINGSSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
585
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
586 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
587 ext_flash_read_block(&length_lo, EF_SETTINGS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
588 ext_flash_read_block(&length_hi, EF_SETTINGS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
589
538
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
590 while ((length_lo != 0xFF) && (length_hi != 0xFF) && (exit == 0)) /* get the latest stored setting block */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
591 {
427
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
592 lengthOnEEPROM = length_hi * 256;
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
593 lengthOnEEPROM += length_lo;
538
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
594 if(lengthOnEEPROM <= lengthStandardNow) /* EEPROM Header size equal or smaller => settings constant or upgraded */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
595 {
427
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
596 ext_flash_read_block_multi(&header, 4, EF_SETTINGS);
538
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
597 if((header <= pSettings->header) && (header >= pSettings->updateSettingsAllowedFromHeader)) /* check to allow update of header */
427
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
598 {
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
599 returnValue = HAL_OK;
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
600 pSettings->header = header;
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
601 pData = (uint8_t *)pSettings + 4; /* header */
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
602 for(uint16_t i = 0; i < (lengthOnEEPROM-4); i++)
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
603 ext_flash_read_block(&pData[i], EF_SETTINGS);
538
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
604 if(header != pSettings->header) /* setting layout changed => no additional setting sets expected */
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
605 {
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
606 exit = 1;
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
607 }
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
608 }
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
609 else
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
610 {
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
611 returnValue = HAL_ERROR;
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
612 exit = 1;
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
613 }
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
614 }
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
615 else /* size of settings decreased => possible downgrade of firmware */
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
616 {
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
617 ext_flash_read_block_multi(&header, 4, EF_SETTINGS);
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
618
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
619 if(header > 0xFFFF0014) /* verify that new (old) header should be compatible (only less bytes, no change in layout) */
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
620 {
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
621 returnValue = HAL_OK;
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
622 pSettings->header = header;
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
623 pData = (uint8_t *)pSettings + 4; /* header */
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
624 for(uint16_t i = 0; i < (lengthStandardNow-4); i++) /* only read the data fitting into the structure */
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
625 ext_flash_read_block(&pData[i], EF_SETTINGS);
427
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
626 }
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
627 else
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
628 {
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
629 returnValue = HAL_ERROR;
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
630 }
538
b1eee27cd02b BugFix firmware downgrade to version with less settings:
Ideenmodellierer
parents: 466
diff changeset
631 exit = 1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
632 }
427
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
633 ext_flash_read_block(&length_lo, EF_SETTINGS);
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
634 ext_flash_read_block(&length_hi, EF_SETTINGS);
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
635 }
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
636 ext_flash_decf_address_ring(EF_SETTINGS); /* set pointer back to empty address */
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
637 ext_flash_decf_address_ring(EF_SETTINGS);
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
638 ext_flash_read_block_stop();
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
639
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
640 if(actualAddress > actualPointerSettings) /* the write pointer has not yet been set up probably */
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
641 {
b1091e183d52 Activated ringbuffer for settings:
ideenmodellierer
parents: 425
diff changeset
642 actualPointerSettings = actualAddress;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
643 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
644 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
645 return returnValue;
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
649
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
650
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
651 /* ext_flash_start_new_dive_log_and_set_actualPointerSample
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
652 * prepares the write sample pointer
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
653 * to be used by ext_flash_write_sample()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
654 * to be set in the * pHeaderPreDive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
655 * 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
656 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
657 void ext_flash_start_new_dive_log_and_set_actualPointerSample(uint8_t *pHeaderPreDive)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
658 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
659 convert_Type data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
660 SSettings *settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
661
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
662 /* new 5. Jan. 2015 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
663 actualPointerSample = settings->logFlashNextSampleStartAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
664
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
665 if(!ext_flash_test_remaining_space_of_page_empty(actualPointerSample, 4))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
666 ext_flash_set_to_begin_of_next_page(&actualPointerSample, EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
667
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
668 if((actualPointerSample < SAMPLESTART) || (actualPointerSample > SAMPLESTOP))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
669 actualPointerSample = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
670
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
671 data.u32bit = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
672 pHeaderPreDive[2] = data.u8bit.byteLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
673 pHeaderPreDive[3] = data.u8bit.byteMidLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
674 pHeaderPreDive[4] = data.u8bit.byteMidHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
675 /* to start sample writing and header etc. pp. */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
676 ext_flash_disable_protection_for_logbook();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
677 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
678
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
679
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
680 /* ext_flash_create_new_dive_log
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
681 * uses the first header without HEADER2OFFSET
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
682 * for the header it is not important to be complete
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
683 * and can be reconstructed
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
684 * ext_flash_start_new_dive_log_and_set_actualPointerSample()
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
685 * has to be called before to set the actualPointerSample
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
686 * in the header
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
687 * the following func writes to header to the ext_flash
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
688 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
689 void ext_flash_create_new_dive_log(uint8_t *pHeaderPreDive)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
690 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
691 SSettings *settings;
429
7f351c25608a Marked possible code improvment for future activities:
ideenmodellierer
parents: 427
diff changeset
692 uint8_t id;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
693 uint8_t header1, header2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
694
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
695 settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
696 id = settings->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
697
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
698 actualAddress = HEADERSTART + (0x800 * id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
699 ext_flash_read_block_start();
429
7f351c25608a Marked possible code improvment for future activities:
ideenmodellierer
parents: 427
diff changeset
700 ext_flash_read_block(&header1, EF_SAMPLE); /* the sample ring is increased instead of header... not sure if that is planned intention */
7f351c25608a Marked possible code improvment for future activities:
ideenmodellierer
parents: 427
diff changeset
701 ext_flash_read_block(&header2, EF_SAMPLE); /* does not matter because actual address is reset in write_block call */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
702 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
703
429
7f351c25608a Marked possible code improvment for future activities:
ideenmodellierer
parents: 427
diff changeset
704 /* TODO Cleanup_Ref_2: The code below should not be necessary in case of a proper shutdown and startup */
7f351c25608a Marked possible code improvment for future activities:
ideenmodellierer
parents: 427
diff changeset
705 /* the implementation fixes an issue which might happen at Cleanup_Ref_1 (in case of more then 254 dives) */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
706 if((header1 == 0xFA) && (header2 == 0xFA))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
707 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
708 id += 1; /* 0-255, auto rollover */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
709 if(id & 1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
710 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
711 actualAddress = HEADERSTART + (0x800 * id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
712 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
713 ext_flash_read_block(&header1, EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
714 ext_flash_read_block(&header2, EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
715 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
716 if((header1 == 0xFA) && (header2 == 0xFA))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
717 id += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
718 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
719 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
720 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
721 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
722 id = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
723 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
724
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
725 settings->lastDiveLogId = id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
726 actualPointerHeader = HEADERSTART + (0x800 * id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
727
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
728 if(pHeaderPreDive != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
729 ef_write_block(pHeaderPreDive,HEADERSIZE, EF_HEADER, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
730 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
731
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
732
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
733 void ext_flash_close_new_dive_log(uint8_t *pHeaderPostDive )
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
734 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
735 SSettings * settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
736 uint8_t id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
737 convert_Type startAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
738 convert_Type data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
739 uint32_t backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
740
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
741 uint8_t sampleData[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
742 actualAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
743 sampleData[0] = 0xFD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
744 sampleData[1] = 0xFD;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
745 ext_flash_write_sample(sampleData, 2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
746
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
747 /* end of sample data, pointing to the last sample 0xFD
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
748 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
749 actualAddress = actualPointerSample; // change hw 17.09.2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
750 ext_flash_decf_address_ring(EF_SAMPLE); // 17.09.2015: this decf actualAddress only!!
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
751 actualPointerSample = actualAddress; // change hw 17.09.2015
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
752 data.u32bit = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
753
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
754 pHeaderPostDive[5] = data.u8bit.byteLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
755 pHeaderPostDive[6] = data.u8bit.byteMidLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
756 pHeaderPostDive[7] = data.u8bit.byteMidHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
757
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
758 /* take data written before, calculate length and write
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
759 SLogbookHeader has different order: length (byte# 8,9,10) prior to profile version (byte# 11)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
760 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
761 startAddress.u8bit.byteLow = pHeaderPostDive[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
762 startAddress.u8bit.byteMidLow = pHeaderPostDive[3];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
763 startAddress.u8bit.byteMidHigh = pHeaderPostDive[4];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
764 startAddress.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
765
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
766 if(startAddress.u32bit < actualPointerSample)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
767 data.u32bit = 1 + actualPointerSample - startAddress.u32bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
768 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
769 data.u32bit = 2 + (actualPointerSample - SAMPLESTART) + (SAMPLESTOP - startAddress.u32bit);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
770
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
771 pHeaderPostDive[8] = data.u8bit.byteLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
772 pHeaderPostDive[9] = data.u8bit.byteMidLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
773 pHeaderPostDive[10] = data.u8bit.byteMidHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
774
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
775 /* set id and write post-dive-header
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
776 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
777 id = settings->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
778 actualPointerHeader = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
779
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
780 ef_write_block(pHeaderPostDive,HEADERSIZE, EF_HEADER, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
781
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
782 /* write length at beginning of sample
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
783 and write proper beginning for next dive to actualPointerSample
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
784 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
785 backup = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
786 actualPointerSample = startAddress.u32bit; // is still 0xFF
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
787 sampleData[0] = data.u8bit.byteLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
788 sampleData[1] = data.u8bit.byteMidLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
789 sampleData[2] = data.u8bit.byteMidHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
790 ext_flash_overwrite_sample_without_erase(sampleData, 3);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
791
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
792 actualAddress = backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
793 ext_flash_incf_address(EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
794 actualPointerSample = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
795 ext_flash_enable_protection();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
796 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
797
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
798
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
799 void ext_flash_write_sample(uint8_t *pSample, uint16_t length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
800 {
423
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
801 uint32_t actualAdressBackup = 0;
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
802
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
803 ef_write_block(pSample,length, EF_SAMPLE, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
804
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
805 SSettings *settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
806 settings->logFlashNextSampleStartAddress = actualPointerSample;
423
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
807
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
808 if(0xFFFF - (actualAddress & 0x0000FFFF) < 255) /* are we close to a sector border? */
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
809 {
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
810 if (((actualAddress & 0x0000FFFF) != 0) && (preparedPageAddress == 0)) /* only prepare if not already at start of sector */
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
811 {
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
812 actualAdressBackup = actualAddress;
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
813 actualAddress = (actualAddress & 0xFFFF0000) + 0x00010000; /* Set to start of next 64k sector */
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
814 if(actualAddress >= SAMPLESTOP)
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
815 {
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
816 actualAddress = SAMPLESTART;
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
817 }
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
818 preparedPageAddress = actualAddress;
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
819 ext_flash_erase64kB();
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
820 actualAddress = actualAdressBackup;
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
821 }
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
822 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
823 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
824
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
825 static void ext_flash_overwrite_sample_without_erase(uint8_t *pSample, uint16_t length)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
826 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
827 ef_write_block(pSample,length, EF_SAMPLE, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
828 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
829
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
830
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
831 uint8_t ext_flash_count_dive_headers(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
832 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
833 uint8_t id = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
834 uint8_t counter = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
835 uint16_t headerStartData = 0x0000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
836
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
837 id = settingsGetPointer()->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
838
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
839 do
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
840 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
841 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
842 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
843 ext_flash_read_block_multi((uint8_t *)&headerStartData, 2, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
844 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
845 counter++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
846 id -=1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
847 } while((headerStartData == 0xFAFA) && (counter < 255));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
848 return (counter - 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
849 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
850
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
851
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
852 void ext_flash_read_dive_header(uint8_t *pHeaderToFill, uint8_t StepBackwards)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
853 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
854 SSettings *settings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
855 uint8_t id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
856 uint16_t i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
857
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
858 settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
859 id = settings->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
860 id -= StepBackwards; /* 0-255, auto rollover */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
861
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
862 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
863 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
864 for(i = 0; i < HEADERSIZE; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
865 ext_flash_read_block(&pHeaderToFill[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
866 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
867
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
868 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
869
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
870 void ext_flash_read_dive_header2(uint8_t *pHeaderToFill, uint8_t id, _Bool bOffset)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
871 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
872
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
873 uint16_t i;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
874 actualAddress = HEADERSTART + (0x800 * id) ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
875
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
876 if(bOffset)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
877 actualAddress += HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
878 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
879 for(i = 0; i < HEADERSIZE; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
880 ext_flash_read_block(&pHeaderToFill[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
881 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
882 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
883
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
884
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
885 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
886 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
887 if(max_size < 0x800)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
888 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
889
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
890 uint8_t id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
891 convert_Type dataStart, dataEnd;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
892 uint32_t LengthAll = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
893
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
894 id = settingsGetPointer()->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
895 id -= StepBackwards; /* 0-255, auto rollover */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
896
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
897 // clear data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
898 for(int i=0;i<0x800;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
899 data[i] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
900
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
901 // copy primary/pre-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
902 actualAddress = HEADERSTART + (0x800 * id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
903 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
904 for(int i = 0; i < HEADERSIZE; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
905 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
906 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
907
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
908 // copy main/secondary/post-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
909 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
910 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
911 for(int i = 0x400; i < HEADERSIZE+0x400; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
912 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
913 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
914
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
915 // data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
916
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
917 dataStart.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
918 dataStart.u8bit.byteLow = data[0x402];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
919 dataStart.u8bit.byteMidLow = data[0x403];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
920 dataStart.u8bit.byteMidHigh = data[0x404];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
921
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
922 dataEnd.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
923 dataEnd.u8bit.byteLow = data[0x405];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
924 dataEnd.u8bit.byteMidLow = data[0x406];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
925 dataEnd.u8bit.byteMidHigh = data[0x407];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
926
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
927 actualPointerSample = dataStart.u32bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
928 if(dataEnd.u32bit >= dataStart.u32bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
929 LengthAll = 1 + dataEnd.u32bit - dataStart.u32bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
930 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
931 LengthAll = 2 + (dataStart.u32bit - SAMPLESTART) + (SAMPLESTOP - dataEnd.u32bit);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
932
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
933 LengthAll += 0x800;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
934
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
935 if(LengthAll > max_size)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
936 return 0x800;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
937
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
938 actualAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
939 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
940 for(uint32_t i = 0x800; i < LengthAll; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
941 ext_flash_read_block(&data[i], EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
942 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
943 return LengthAll;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
944 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
945
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
946 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
947 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
948 convert_Type dataStart, dataEnd;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
949 SLogbookHeader headerTemp;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
950
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
951 // set actualPointerSample and get pointer to sample storage and disable flash write protect
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
952 ext_flash_start_new_dive_log_and_set_actualPointerSample((uint8_t *)&headerTemp);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
953
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
954 dataStart.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
955 dataStart.u8bit.byteLow = headerTemp.pBeginProfileData[0];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
956 dataStart.u8bit.byteMidLow = headerTemp.pBeginProfileData[1];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
957 dataStart.u8bit.byteMidHigh = headerTemp.pBeginProfileData[2];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
958
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
959 dataEnd.u32bit = dataStart.u32bit + length - 0x801;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
960 if(dataEnd.u32bit > SAMPLESTOP)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
961 dataEnd.u32bit -= SAMPLESTOP + SAMPLESTART - 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
962
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
963 data[0x002] = data[0x402] = dataStart.u8bit.byteLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
964 data[0x003] = data[0x403] = dataStart.u8bit.byteMidLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
965 data[0x004] = data[0x404] = dataStart.u8bit.byteMidHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
966 data[0x005] = data[0x405] = dataEnd.u8bit.byteLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
967 data[0x006] = data[0x406] = dataEnd.u8bit.byteMidLow;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
968 data[0x007] = data[0x407] = dataEnd.u8bit.byteMidHigh;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
969
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
970 // set actualPointerHeader to next free header and update lastDiveLogId
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
971 ext_flash_create_new_dive_log(0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
972
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
973 // copy header data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
974 ef_write_block(data,0x800,EF_HEADER, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
975
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
976 // copy sample data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
977 ef_write_block(&data[0x800], length-0x800, EF_SAMPLE, 1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
978
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
979 // update logFlashNextSampleStartAddress
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
980 settingsGetPointer()->logFlashNextSampleStartAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
981 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
982
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 // ext_flash_read_header_memory
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
986 /// @brief This function returns the entire header space 1:1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
987 /// @date 04-April-2016
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
988 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
989 /// @param *data 256KB output
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
990 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
991 void ext_flash_read_header_memory(uint8_t *data)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
992 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
993 actualAddress = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
994 actualPointerHeader = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
995 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
996 for(int i=0;i<8;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
997 ext_flash_read_block_multi(&data[0x8000 * i], 0x8000, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
998 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
999 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1000
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1001
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1002 // ===============================================================================
463
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1003 // ext_flash_write_header_memory
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1004 /// @brief This function erases and overwrites the entire logbook header block
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1005 /// @date 04-April-2016
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1006 ///
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1007 /// @param *data 256KB input of header memory 1:1
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1008 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1009 void ext_flash_write_header_memory(uint8_t *data)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1010 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1011 actualAddress = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1012 actualPointerHeader = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1013 ef_write_block(data, 0x40000, EF_HEADER, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1014 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1015
463
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1016 void ext_flash_read_sample_memory(uint8_t *data,uint16_t blockId)
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1017 {
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1018 actualAddress = SAMPLESTART;
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1019 actualAddress += blockId * 0x8000; /* add 32k Block offset */
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1020 actualPointerSample = actualAddress;
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1021 ext_flash_read_block_start();
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1022 ext_flash_read_block_multi(data, 0x8000, EF_SAMPLE);
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1023 ext_flash_read_block_stop();
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1024 }
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1025
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1026 void ext_flash_write_sample_memory(uint8_t *data,uint16_t blockId)
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1027 {
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1028 actualAddress = SAMPLESTART;
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1029 actualAddress += blockId * 0x8000; /* add 32k Block offset */
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1030 actualPointerSample = actualAddress;
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1031 ef_write_block(data, 0x8000, EF_SAMPLE,0);
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1032 }
e4f6afd9c96b Added function to transfer sample buffer:
ideenmodellierer
parents: 460
diff changeset
1033
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1034
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1035 void ext_flash_open_read_sample(uint8_t StepBackwards, uint32_t *totalNumberOfBytes)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1036 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1037 SSettings *settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1038 uint8_t id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1039 convert_Type dataStart, dataEnd;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1040 uint8_t header1, header2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1041
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1042 id = settings->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1043 id -= StepBackwards; /* 0-255, auto rollover */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1044 #
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1045 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1046 actualPointerHeader = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1047
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1048 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1049 /* little endian */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1050 ext_flash_read_block(&header1, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1051 ext_flash_read_block(&header2, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1052 dataStart.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1053 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1054 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1055 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1056 dataEnd.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1057 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1058 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1059 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1060 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1061
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1062 actualPointerSample = dataStart.u32bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1063 if(dataEnd.u32bit >= dataStart.u32bit)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1064 LengthLeftSampleRead = 1 + dataEnd.u32bit - dataStart.u32bit;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1065 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1066 LengthLeftSampleRead = 2 + (dataStart.u32bit - SAMPLESTART) + (SAMPLESTOP - dataEnd.u32bit);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1067 *totalNumberOfBytes = LengthLeftSampleRead;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1068
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1069 actualAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1070 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1071 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1072
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1073
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1074 void ext_flash_read_next_sample_part(uint8_t *pSample, uint8_t length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1075 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1076 for(uint16_t i = 0; i < length; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1077 ext_flash_read_block(&pSample[i], EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1078 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1079
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1080
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1081 void ext_flash_close_read_sample(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1082 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1083 actualPointerSample = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1084 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1085 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1086
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1087
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1088 void ext_flash_set_entry_point(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1089 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1090 entryPoint = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1091 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1092
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1093
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1094 void ext_flash_reopen_read_sample_at_entry_point(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1095 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1096 error_led_on();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1097 chip_unselect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1098 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1099
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1100 actualAddress = entryPoint;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1101 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1102 error_led_off();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1103 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1104
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1105 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1106 uint8_t ext_flash_point_to_64k_block_in_headerSpace(uint8_t logId)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1107 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1108 uint32_t pointerToData = logId * 0x800;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1109
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1110 return pointerToData / 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1111 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1112 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1113
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1114
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1115 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1116 // ext_flash_repair_dive_numbers_starting_count_helper
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1117 /// @brief
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1118 /// @date 22-June-2016
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1119
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1120 // ===============================================================================
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1121 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
1122 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1123 const uint32_t headerStep = 0x800;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1124 uint8_t actualLogId = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1125 uint16_t oldNumber = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1126 uint16_t actualNumber = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1127 SLogbookHeader *ptrLogbookHeader = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1128
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1129 if(startNumber == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1130 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1131
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1132 actualNumber = startNumber - 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1133
282
c7e665e0b08f translate some comments into english
heinrichsweikamp
parents: 268
diff changeset
1134 // where is the oldest dive (Which is now getting startNumber)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1135 // use first header for ease (without HEADER2OFFSET for end of dive header)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1136 // compare for lastLogId to prevent endless loop
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1137
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1138 if(*(uint16_t*)&data[lastLogId * headerStep] != 0xFAFA)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1139 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1140
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1141 actualLogId = lastLogId - 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1142 while((*(uint16_t*)&data[actualLogId * headerStep] == 0xFAFA) && (actualLogId != lastLogId))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1143 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1144 actualLogId--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1145 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1146
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1147 // now pointing to one behind the last
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1148 while(actualLogId != lastLogId)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1149 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1150 actualLogId++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1151 actualNumber++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1152 ptrLogbookHeader = (SLogbookHeader *)&data[actualLogId * headerStep];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1153
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1154 oldNumber = ptrLogbookHeader->diveNumber;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1155 if(oldNumber != actualNumber)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1156 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1157 // change64k[ext_flash_point_to_64k_block_in_headerSpace(actualLogId )] = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1158 change64k[(actualLogId * 0x800)/0x10000] = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1159 ptrLogbookHeader->diveNumber = actualNumber;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1160 ptrLogbookHeader = (SLogbookHeader *)(&data[actualLogId * headerStep] + HEADER2OFFSET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1161 ptrLogbookHeader->diveNumber = actualNumber;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1162 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1163 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1164
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1165 return actualNumber;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1166 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1167
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1168 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1169 // ext_flash_repair_SPECIAL_dive_numbers_starting_count_with
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1170 /// @brief This function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1171 /// @date 04-April-2016
282
c7e665e0b08f translate some comments into english
heinrichsweikamp
parents: 268
diff changeset
1172 /// problem (160621): 64K blocks (32 dives) in the new flash memory chip
c7e665e0b08f translate some comments into english
heinrichsweikamp
parents: 268
diff changeset
1173 /// This block needs to be deleted
c7e665e0b08f translate some comments into english
heinrichsweikamp
parents: 268
diff changeset
1174 /// these where only 4KB block before
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1175 /// @output endCount, last diveNumber
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1176
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1177 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1178 uint16_t ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(uint16_t startCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1179 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1180 uint32_t logCopyDataPtr = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1181 uint8_t *data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1182 uint16_t lastCount;
282
c7e665e0b08f translate some comments into english
heinrichsweikamp
parents: 268
diff changeset
1183 uint8_t listOfChanged64kBlocks[8]; // 32 dives each 64K
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1184
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1185 logCopyDataPtr = getFrame(97);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1186 data = (uint8_t *)logCopyDataPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1187
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1188 for(int i=0;i<8;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1189 listOfChanged64kBlocks[i] = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1190
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1191 actualAddress = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1192 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1193 ext_flash_read_block_multi(data,0x100000,EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1194 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1195
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1196 lastCount = ext_flash_repair_dive_numbers_starting_count_helper(data, listOfChanged64kBlocks, startCount, settingsGetPointer()->lastDiveLogId);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1197
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1198 for(int i=0;i<8;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1199 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1200 if(listOfChanged64kBlocks[i] != 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1201 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1202 actualPointerHeader = HEADERSTART + (i * 0x10000);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1203 ef_write_block(&data[i * 0x10000], 0x10000, EF_HEADER, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1204 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1205 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1206
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1207 releaseFrame(97,logCopyDataPtr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1208 if(settingsGetPointer()->totalDiveCounter < lastCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1209 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1210 settingsGetPointer()->totalDiveCounter = lastCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1211 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1212 return lastCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1213 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1214
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1215 /*
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1216 void OLD_ext_flash_repair_SPECIAL_dive_numbers_starting_count_with(uint16_t startCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1217 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1218 uint16_t counterStorage[256];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1219 uint8_t start = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1220 uint32_t logCopyDataPtr = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1221 uint8_t *data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1222 uint8_t startAbsolute = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1223 int16_t count = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1224 _Bool repair = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1225 uint8_t startBackup = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1226
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1227 SLogbookHeader tempLogbookHeader;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1228 SLogbookHeader *ptrHeaderInData1a;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1229 SLogbookHeader *ptrHeaderInData1b;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1230 SLogbookHeader *ptrHeaderInData2a;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1231 SLogbookHeader *ptrHeaderInData2b;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1232
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1233 logCopyDataPtr = getFrame(97);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1234 data = (uint8_t *)logCopyDataPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1235 ptrHeaderInData1a = (SLogbookHeader *)logCopyDataPtr;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1236 ptrHeaderInData1b = (SLogbookHeader *)(logCopyDataPtr + HEADER2OFFSET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1237 ptrHeaderInData2a = (SLogbookHeader *)(logCopyDataPtr + 0x800);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1238 ptrHeaderInData2b = (SLogbookHeader *)(logCopyDataPtr + 0x800 + HEADER2OFFSET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1239
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1240 // get data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1241 for(int StepBackwards = 0; StepBackwards < 255; StepBackwards++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1242 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1243 logbook_getHeader(StepBackwards, &tempLogbookHeader);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1244 counterStorage[StepBackwards+1] = tempLogbookHeader.diveNumber;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1245 if(tempLogbookHeader.diveHeaderStart == 0xFAFA)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1246 start = StepBackwards;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1247 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1248 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1249 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1250
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1251 if(start == 0xFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1252 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1253
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1254 count = start + 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1255 startAbsolute = settingsGetPointer()->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1256
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1257
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1258
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1259 if(start%2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1260 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1261 if(counterStorage[start] != startCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1262 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1263 // clear data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1264 for(int i=0;i<0x800*2;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1265 data[i] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1266
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1267 uint8_t id = settingsGetPointer()->lastDiveLogId;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1268 id -= start; // 0-255, auto rollover
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1269
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1270 // copy primary/pre-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1271 actualAddress = HEADERSTART + (0x800 * id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1272 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1273 for(int i = 0; i < HEADERSIZE; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1274 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1275 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1276
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1277 // copy main/secondary/post-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1278 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1279 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1280 for(int i = 0x400; i < HEADERSIZE+0x400; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1281 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1282 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1283
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1284 // repair
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1285 ptrHeaderInData2a->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1286 ptrHeaderInData2b->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1287 startCount++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1288
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1289 // write
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1290 actualAddress = HEADERSTART + (0x800 * (id-1));
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1291 ef_write_block(data,0x800*2,EF_HEADER, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1292 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1293 start--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1294 }
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1295
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1296 // for(int count = start; count > -1; count -= 2)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1297
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1298 while(count > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1299 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1300 // clear data
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1301 for(int i=0;i<0x1000;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1302 data[i] = 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1303
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1304 repair = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1305
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1306 startBackup = startAbsolute;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1307
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1308 if(startAbsolute%2) // 0x800 to 0x1000
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1309 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1310 // copy second pre-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1311 actualAddress = HEADERSTART + (0x800 * startAbsolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1312 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1313 for(int i = 0x800; i < HEADERSIZE+0x800; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1314 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1315 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1316
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1317 // copy second post-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1318 actualAddress = HEADERSTART + HEADER2OFFSET + (0x800 * startAbsolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1319 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1320 for(int i = 0xC00; i < HEADERSIZE+0xC00; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1321 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1322 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1323
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1324 if(counterStorage[count] != startCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1325 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1326 ptrHeaderInData2a->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1327 ptrHeaderInData2b->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1328 repair = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1329 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1330 startCount += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1331
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1332 startAbsolute -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1333 count -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1334
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1335 if(count > 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1336 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1337 // copy first pre-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1338 actualAddress = HEADERSTART + (0x800 * startAbsolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1339 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1340 for(int i = 0; i < HEADERSIZE; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1341 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1342 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1343
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1344 // copy first post-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1345 actualAddress = HEADERSTART + (0x800 * startAbsolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1346 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1347 for(int i = 0x400; i < HEADERSIZE+0x400; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1348 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1349 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1350
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1351 if(counterStorage[count] != startCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1352 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1353 ptrHeaderInData1a->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1354 ptrHeaderInData1b->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1355 repair = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1356 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1357 startCount += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1358
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1359 startAbsolute -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1360 count -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1361 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1362 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1363 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1364 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1365 // copy first pre-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1366 actualAddress = HEADERSTART + (0x800 * startAbsolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1367 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1368 for(int i = 0; i < HEADERSIZE; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1369 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1370 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1371
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1372 // copy first post-dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1373 actualAddress = HEADERSTART + (0x800 * startAbsolute);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1374 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1375 for(int i = 0x400; i < HEADERSIZE+0x400; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1376 ext_flash_read_block(&data[i], EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1377 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1378
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1379 if(counterStorage[count] != startCount)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1380 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1381 ptrHeaderInData1a->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1382 ptrHeaderInData1b->diveNumber = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1383 repair = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1384 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1385 startCount += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1386
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1387 startAbsolute -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1388 count -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1389 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1390
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1391 // write
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1392 if(repair)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1393 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1394 actualPointerHeader = HEADERSTART + (0x1000 * startBackup%2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1395 ef_write_block(data,0x1000,EF_HEADER, 0);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1396 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1397 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1398 releaseFrame(97,logCopyDataPtr);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1399 settingsGetPointer()->totalDiveCounter = startCount;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1400 }
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1401 */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1402
452
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1403 uint8_t ext_dive_log_consistent(void)
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1404 {
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1405 uint8_t ret = 0;
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1406 uint8_t header1, header2;
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1407 uint8_t id;
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1408 convert_Type dataStart;
557
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1409 convert_Type dataEnd;
452
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1410
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1411 SSettings *settings = settingsGetPointer();
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1412 id = settings->lastDiveLogId;
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1413
557
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1414 if(settings->lastDiveLogId != 0) /* not trust LogID 0 which might be reset by a settings problem */
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1415 { /* ==> Find function will be called restoring the Id belonging to the latest sample */
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1416 actualAddress = HEADERSTART + (0x800 * id);
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1417 ext_flash_read_block_start();
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1418 ext_flash_read_block(&header1, EF_HEADER);
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1419 ext_flash_read_block(&header2, EF_HEADER);
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1420 ext_flash_read_block_stop();
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1421 if((header1 == 0xFA) && (header2 == 0xFA)) /* Header is indicating the start of a dive */
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1422 {
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1423 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1424 ext_flash_read_block_start();
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1425 ext_flash_read_block(&header1, EF_HEADER);
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1426 ext_flash_read_block(&header2, EF_HEADER);
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1427 dataStart.u8bit.byteHigh = 0;
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1428 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER);
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1429 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER);
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1430 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER);
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1431 dataEnd.u8bit.byteHigh = 0;
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1432 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER);
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1433 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER);
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1434 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER);
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1435 ext_flash_read_block_stop();
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1436
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1437 if((header1 == 0xFA) && (header2 == 0xFA)) /* Secondary header was written at the end of a dive */
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1438 {
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1439 if(dataStart.u32bit < dataEnd.u32bit)
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1440 {
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1441 ret = 1; /* => lastDiveLogID points to a valid dive entry */
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1442 }
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1443 else /* check if address wrap is valid */
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1444 {
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1445 if(ext_flash_SampleOverrunValid())
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1446 {
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1447 ret = 1;
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1448 }
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1449 }
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1450 }
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1451 }
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
1452 }
452
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1453 return ret;
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1454 }
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1455
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1456 // ===============================================================================
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1457 // ext_flash_repair_dive_log
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1458 /// @brief This function
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1459 /// does set
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1460 /// logFlashNextSampleStartAddress
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1461 /// and
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1462 /// lastDiveLogId
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1463 ///
452
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
1464
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1465 void ext_flash_repair_dive_log(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1466 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1467 uint8_t header1, header2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1468 convert_Type dataStart;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1469
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1470 for(int id = 0; id < 255;id++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1471 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1472 actualAddress = HEADERSTART + (0x800 * id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1473 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1474 ext_flash_read_block(&header1, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1475 ext_flash_read_block(&header2, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1476 dataStart.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1477 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1478 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1479 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1480 ext_flash_read_block_stop();
425
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
1481 if((header1 == 0xFA) && (header2 == 0xFA)) /* Header is indicating the start of a dive */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1482 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1483 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1484 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1485 ext_flash_read_block(&header1, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1486 ext_flash_read_block(&header2, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1487 ext_flash_read_block_stop();
425
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
1488 if((header1 != 0xFA) || (header2 != 0xFA)) /* Secondary header was not written at the end of a dive */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1489 {
425
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
1490 actualPointerSample = dataStart.u32bit; /* Set datapointer to position stored in header written at beginning of dive */
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1491 actualAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1492 logbook_recover_brokenlog(id);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1493 SSettings *settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1494 settings->logFlashNextSampleStartAddress = actualPointerSample;
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 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1498 ext_flash_find_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1499 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1500
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1501
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1502 static void ext_flash_find_start(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1503 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1504 uint8_t id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1505 uint8_t header1, header2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1506 convert_Type dataStart, dataEnd;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1507
429
7f351c25608a Marked possible code improvment for future activities:
ideenmodellierer
parents: 427
diff changeset
1508 /* TODO Cleanup_Ref_1: cleanup logFlashNextSampleStartAddress and lastDiveLogId */
7f351c25608a Marked possible code improvment for future activities:
ideenmodellierer
parents: 427
diff changeset
1509 /* The implementation below would cause problems in case more then 254 dives would be done. */
7f351c25608a Marked possible code improvment for future activities:
ideenmodellierer
parents: 427
diff changeset
1510 /* This is avoided by Cleanup_Ref2 */
441
9a9e4908ce2e fix potential issue with >255 dives in the logbook
heinrichsweikamp
parents: 429
diff changeset
1511 for(id = 0; id <= 255;id++)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1512 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1513 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1514 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1515 ext_flash_read_block(&header1, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1516 ext_flash_read_block(&header2, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1517 dataStart.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1518 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1519 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1520 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1521 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1522 if((header1 == 0xFF) && (header2 == 0xFF))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1523 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1524 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1525 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1526 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1527 id--;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1528 SSettings *settings = settingsGetPointer();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1529 settings->lastDiveLogId = id;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1530
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1531 actualAddress = HEADERSTART + (0x800 * id) + HEADER2OFFSET;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1532 actualPointerHeader = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1533
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1534 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1535
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1536 ext_flash_read_block(&header1, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1537 ext_flash_read_block(&header2, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1538 dataStart.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1539 ext_flash_read_block(&dataStart.u8bit.byteLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1540 ext_flash_read_block(&dataStart.u8bit.byteMidLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1541 ext_flash_read_block(&dataStart.u8bit.byteMidHigh, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1542 dataEnd.u8bit.byteHigh = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1543 ext_flash_read_block(&dataEnd.u8bit.byteLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1544 ext_flash_read_block(&dataEnd.u8bit.byteMidLow, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1545 ext_flash_read_block(&dataEnd.u8bit.byteMidHigh, EF_HEADER);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1546 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1547
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1548 //Find free space
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1549 if((header1 == 0xFA) && (header2 == 0xFA))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1550 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1551 uint8_t uiRead = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1552 int countFF = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1553 //End of last complete dive
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1554 actualPointerSample = dataEnd.u32bit ;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1555 actualAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1556 //Check if there are samples of dives with less than half a minute
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1557 while(true)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1558 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1559 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1560 ext_flash_read_block(&uiRead, EF_SAMPLE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1561 if(uiRead == 0xFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1562 countFF++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1563 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1564 countFF = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1565
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1566
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1567
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1568 if(countFF == 10)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1569 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1570 actualAddress -= 10;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1571 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1572 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1573
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1574 //New page: clear
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1575 if(ext_flash_erase_if_on_page_start())
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1576 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1577 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1578 // Set new start address
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1579 actualPointerSample = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1580 settings->logFlashNextSampleStartAddress = actualPointerSample;
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 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1584 settings->logFlashNextSampleStartAddress = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1585 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1586 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1587
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1588
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
1589
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1590
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1591 static void ext_flash_disable_protection(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1592 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1593 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1594 extFlashStatusBit8_Type status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1595
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1596 status.uw = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1597
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1598 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1599 write_spi(0x50,RELEASE); // EWSR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1600 write_spi(0x01,HOLDCS); // WRSR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1601 write_spi(status.uw,RELEASE); // new status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1602 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1603 }
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
1604 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1605
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1606 void ext_flash_disable_protection_for_logbook(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1607 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1608 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1609 extFlashStatusBit8_Type status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1610
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1611 status.uw = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1612 status.ub.BlockProtect0 = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1613 status.ub.BlockProtect1 = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1614 status.ub.BlockProtect2 = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1615 status.ub.BlockProtect3 = 0; // not set in OSTC3. Why?
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1616
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1617 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1618 write_spi(0x50,RELEASE); // EWSR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1619 write_spi(0x01,HOLDCS); // WRSR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1620 write_spi(status.uw,RELEASE); // new status
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
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1625 void ext_flash_enable_protection(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1626 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1627 /*
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1628 extFlashStatusBit8_Type status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1629
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1630 status.uw = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1631 status.ub.BlockProtect0 = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1632 status.ub.BlockProtect1 = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1633 status.ub.BlockProtect2 = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1634 status.ub.BlockProtect3 = 1; // not set in OSTC3. Why?
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1635
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1636 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1637 write_spi(0x50,RELEASE); // EWSR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1638 write_spi(0x01,HOLDCS); // WRSR
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1639 write_spi(status.uw,RELEASE); // new status
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1640 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1641 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1642
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1643
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1644 /*void ext_flash_erase_chip(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1645 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1646 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1647 write_spi(0x06,RELEASE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1648 write_spi(0x60,RELEASE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1649 wait_chip_not_busy();
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1650 }*/
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1651
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1652 void ext_flash_erase_firmware(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1653 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1654 uint32_t size, blocks_64k;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1655
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1656 actualAddress = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1657 size = 1 + FWSTOP - FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1658 blocks_64k = size / 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1659 ef_erase_64K(blocks_64k);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1660 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1661
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1662 void ext_flash_erase_firmware2(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1663 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1664 uint32_t size, blocks_64k;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1665
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1666 actualAddress = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1667 size = 1 + FWSTOP2 - FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1668 blocks_64k = size / 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1669 ef_erase_64K(blocks_64k);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1670 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1671
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1672
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1673
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1674 void ext_flash_erase_logbook(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1675 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1676 uint32_t size, blocks_64k;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1677
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1678 ext_flash_disable_protection_for_logbook();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1679
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1680 actualAddress = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1681 size = 1 + SAMPLESTOP - SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1682 blocks_64k = size / 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1683 ef_erase_64K(blocks_64k);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1684
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1685 actualAddress = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1686 size = 1 + HEADERSTOP - HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1687 blocks_64k = size / 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1688 ef_erase_64K(blocks_64k);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1689
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1690 ext_flash_enable_protection();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1691 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1692
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1693
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1694 static void ext_flash_erase4kB(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1695 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1696 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1697 write_spi(0x06,RELEASE);/* WREN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1698 write_spi(0x20,HOLDCS);/* sector erase cmd */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1699 write_address(RELEASE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1700 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1701
282
c7e665e0b08f translate some comments into english
heinrichsweikamp
parents: 268
diff changeset
1702 /* be careful - might not work with entire family and other products
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1703 * see page 14 of LOGBOOK_V3_S25FS-S_00-271247.pdf
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1704 */
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1705 static void ext_flash_erase32kB(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1706 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1707 uint32_t actualAddress_backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1708
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1709 actualAddress_backup = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1710 actualAddress = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1711 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1712 write_spi(0x06,RELEASE);/* WREN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1713 write_spi(0xD8,HOLDCS);/* sector erase cmd */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1714 write_address(RELEASE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1715 actualAddress = actualAddress_backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1716 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1717
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1718
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1719 static void ext_flash_erase64kB(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1720 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1721 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1722 write_spi(0x06,RELEASE);/* WREN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1723 write_spi(0xD8,HOLDCS);/* sector erase cmd */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1724 write_address(RELEASE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1725 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1726
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1727
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1728 void ext_flash_read_block_start(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1729 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1730 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1731 write_spi(0x03,HOLDCS); /* WREN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1732 write_address(HOLDCS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1733 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1734
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1735 /* 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
1736 static uint8_t ext_flash_erase_if_on_page_start(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1737 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1738 if(actualAddress < 0x00008000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1739 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1740 /* 4K Byte is 0x1000 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1741 if((actualAddress & 0xFFF) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1742 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1743 ext_flash_erase4kB();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1744 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1745 }
423
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
1746 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1747 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1748 if(actualAddress < 0x00010000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1749 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1750 /* 32K Byte is only one page */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1751 if(actualAddress == 0x00010000)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1752 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1753 ext_flash_erase32kB();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1754 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1755 }
423
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
1756 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1757 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1758 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1759 /* 64K Byte is 0x10000 */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1760 if((actualAddress & 0xFFFF) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1761 {
423
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
1762 if(preparedPageAddress == actualAddress) /* has page already been prepared before? (at the moment for samples only) */
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
1763 {
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
1764 preparedPageAddress = 0;
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
1765
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
1766 }
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
1767 else
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
1768 {
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
1769 ext_flash_erase64kB();
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
1770 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1771 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1772 }
423
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
1773 }
a560afdaadbf ext_Flash_write_sample erase sector optimization:
ideenmodellierer
parents: 421
diff changeset
1774
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1775 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1776 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1777
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1778
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1779 static void ext_flash_read_block(uint8_t *getByte, uint8_t type)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1780 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1781 *getByte = read_spi(HOLDCS);/* read data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1782 ext_flash_incf_address(type);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1783 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1784
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1785
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1786 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
1787 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1788 uint8_t *data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1789 data = getByte;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1790
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1791 for(uint32_t i=0;i<size;i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1792 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1793 data[i] = read_spi(HOLDCS);/* read data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1794 ext_flash_incf_address(type);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1795 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1796 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1797
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1798
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1799 static void ext_flash_read_block_stop(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1800 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1801 chip_unselect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1802 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1803
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1804
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1805 /* Private functions ---------------------------------------------------------*/
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1806
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1807 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
1808 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1809 uint32_t remaining_page_size, remaining_length, remaining_space_to_ring_end;
420
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1810 uint32_t i=0;
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1811
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1812 if(!length)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1813 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1814
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1815 uint32_t ringStart, ringStop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1816
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1817 switch(type)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1818 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1819 case EF_HEADER:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1820 actualAddress = actualPointerHeader;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1821 ringStart = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1822 ringStop = HEADERSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1823 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1824 case EF_SAMPLE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1825 actualAddress = actualPointerSample;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1826 ringStart = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1827 ringStop = SAMPLESTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1828 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1829 case EF_DEVICEDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1830 actualAddress = actualPointerDevicedata;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1831 ringStart = DDSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1832 ringStop = DDSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1833 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1834 case EF_VPMDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1835 actualAddress = actualPointerVPM;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1836 ringStart = VPMSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1837 ringStop = VPMSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1838 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1839 case EF_SETTINGS:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1840 actualAddress = actualPointerSettings;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1841 ringStart = SETTINGSSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1842 ringStop = SETTINGSSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1843 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1844 case EF_FIRMWARE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1845 actualAddress = actualPointerFirmware;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1846 ringStart = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1847 ringStop = FWSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1848 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1849 case EF_FIRMWARE2:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1850 actualAddress = actualPointerFirmware2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1851 ringStart = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1852 ringStop = FWSTOP2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1853 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1854 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1855 ringStart = FLASHSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1856 ringStop = FLASHSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1857 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1858 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1859 /* safety */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1860 if(actualAddress < ringStart)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1861 actualAddress = ringStart;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1862
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1863 if(do_not_erase == 0)
459
7ac0e76dbd6a Activated reset of sample information within header data at time of sector erasing:
ideenmodellierer
parents: 452
diff changeset
1864 {
466
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
1865 ext_flash_erase_if_on_page_start();
459
7ac0e76dbd6a Activated reset of sample information within header data at time of sector erasing:
ideenmodellierer
parents: 452
diff changeset
1866 }
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1867
420
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1868 while( i<length)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1869 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1870 ef_hw_rough_delay_us(5);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1871 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1872 write_spi(0x06,RELEASE); /* WREN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1873 write_spi(0x02,HOLDCS); /* write cmd */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1874 write_address(HOLDCS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1875
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1876 remaining_length = length - i;
420
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1877 remaining_page_size = 0xFF - (uint8_t)(actualAddress & 0xFF) +1;
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1878 remaining_space_to_ring_end = ringStop - actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1879
420
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1880 if(remaining_length >= 256)
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1881 {
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1882 remaining_length = 255; /* up to 256 bytes may be written in one burst. Last byte is written with release */
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1883 }
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1884 else
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1885 {
420
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1886 remaining_length--; /* last byte needed for release */
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1887 }
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1888 if(remaining_length >= (remaining_page_size) ) /* use 256 byte page and calculate number of bytes left */
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1889 {
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1890 remaining_length = remaining_page_size - 1;
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1891 }
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1892 if( (remaining_space_to_ring_end >= 256))
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1893 {
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1894 for(int j=0; j<remaining_length; j++)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1895 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1896 write_spi(sendByte[i],HOLDCS);/* write data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1897 actualAddress++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1898 i++;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1899 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1900 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1901 /* byte with RELEASE */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1902 write_spi(sendByte[i],RELEASE);/* write data */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1903 actualAddress++;
420
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1904 i++;
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1905
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1906 if(actualAddress > ringStop)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1907 actualAddress = ringStart;
420
2174fb133dbe Optimize ef_write_block function:
ideenmodellierer
parents: 282
diff changeset
1908
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1909 if(do_not_erase == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1910 ext_flash_erase_if_on_page_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1911 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1912 switch(type)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1913 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1914 case EF_HEADER:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1915 actualPointerHeader = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1916 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1917 case EF_SAMPLE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1918 actualPointerSample = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1919 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1920 case EF_DEVICEDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1921 actualPointerDevicedata = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1922 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1923 case EF_VPMDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1924 actualPointerVPM = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1925 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1926 case EF_SETTINGS:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1927 actualPointerSettings = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1928 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1929 case EF_FIRMWARE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1930 actualPointerFirmware = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1931 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1932 case EF_FIRMWARE2:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1933 actualPointerFirmware2 = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1934 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1935 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1936 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1937 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1938 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1939
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
1940 #ifndef BOOTLOADER_STANDALONE
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1941 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
1942 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1943 if((pointer & 0xFFF) == 0)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1944 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1945
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1946 uint32_t backup = actualAddress;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1947 uint8_t data;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1948 uint32_t size_to_page_end;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1949
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1950 size_to_page_end = 0x1000 - (pointer & 0xFFF);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1951 if(length > size_to_page_end)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1952 length = size_to_page_end;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1953
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1954 actualAddress = pointer;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1955 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1956
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1957 for(uint16_t i = 0; i<length; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1958 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1959 ext_flash_read_block(&data, 255); // 255 = ENTIRE FLASH
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1960 if(data != 0xFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1961 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1962 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1963 actualAddress = backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1964 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1965 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1966 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1967 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1968 actualAddress = backup;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1969 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1970 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1971
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1972
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
1973 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
1974 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1975 uint32_t ringStart, ringStop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1976
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1977 switch(type)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1978 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1979 case EF_HEADER:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1980 ringStart = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1981 ringStop = HEADERSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1982 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1983 case EF_SAMPLE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1984 ringStart = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1985 ringStop = SAMPLESTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1986 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1987 case EF_DEVICEDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1988 ringStart = DDSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1989 ringStop = DDSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1990 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1991 case EF_VPMDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1992 ringStart = VPMSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1993 ringStop = VPMSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1994 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1995 case EF_SETTINGS:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1996 ringStart = SETTINGSSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1997 ringStop = SETTINGSSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1998 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
1999 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2000 ringStart = FLASHSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2001 ringStop = FLASHSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2002 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2003 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2004
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2005 *pointer = (*pointer & 0xFFF) + 0x1000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2006
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2007 if((*pointer < ringStart) || (*pointer >= ringStop))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2008 *pointer = ringStart;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2009 }
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
2010 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2011
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2012 static void ef_erase_64K(uint32_t blocks)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2013 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2014 for(uint32_t i = 0; i < blocks; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2015 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2016 wait_chip_not_busy();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2017 write_spi(0x06,RELEASE);/* WREN */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2018 write_spi(0xD8,HOLDCS);/* 64k erase cmd */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2019 write_address(RELEASE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2020 actualAddress += 0x10000;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2021 HAL_Delay(25);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2022 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2023 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2024
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2025
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
2026 static void chip_unselect(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2027 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2028 HAL_GPIO_WritePin(EXTFLASH_CSB_GPIO_PORT,EXTFLASH_CSB_PIN,GPIO_PIN_SET); // chip select
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2029 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2030
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
2031 static void chip_select(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2032 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2033 HAL_GPIO_WritePin(EXTFLASH_CSB_GPIO_PORT,EXTFLASH_CSB_PIN,GPIO_PIN_RESET); // chip select
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2034 }
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
2035 #ifndef BOOTLOADER_STANDALONE
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
2036 static void error_led_on(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2037 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2038 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_SET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2039 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2040
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
2041 static void error_led_off(void)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2042 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2043 HAL_GPIO_WritePin(OSCILLOSCOPE_GPIO_PORT,OSCILLOSCOPE_PIN,GPIO_PIN_RESET);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2044 }
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
2045 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2046
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
2047 static uint8_t read_spi(uint8_t unselect_CS_afterwards)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2048 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2049 uint8_t byte;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2050
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2051 chip_select();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2052
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2053 if(HAL_SPI_Receive(&hspiDisplay, &byte, 1, 10000) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2054 Error_Handler_extflash();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2055
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2056 while (HAL_SPI_GetState(&hspiDisplay) != HAL_SPI_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2057 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2058 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2059 if(unselect_CS_afterwards)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2060 chip_unselect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2061
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2062 return byte;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2063 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2064
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2065
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
2066 static void write_spi(uint8_t data, uint8_t unselect_CS_afterwards)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2067 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2068 chip_select();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2069
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2070 if(HAL_SPI_Transmit(&hspiDisplay, &data, 1, 10000) != HAL_OK)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2071 Error_Handler_extflash();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2072
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2073 while (HAL_SPI_GetState(&hspiDisplay) != HAL_SPI_STATE_READY)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2074 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2075 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2076 if(unselect_CS_afterwards)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2077 chip_unselect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2078 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2079
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2080
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
2081 static void write_address(uint8_t unselect_CS_afterwards)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2082 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2083 uint8_t hi, med ,lo;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2084
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2085 hi = (actualAddress >> 16) & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2086 med = (actualAddress >> 8) & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2087 lo = actualAddress & 0xFF;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2088
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2089 write_spi(hi, HOLDCS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2090 write_spi(med, HOLDCS);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2091 write_spi(lo, unselect_CS_afterwards);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2092 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2093
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2094
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2095 static void wait_chip_not_busy(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2096 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2097 uint8_t status;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2098
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2099 chip_unselect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2100
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2101 write_spi(0x05,HOLDCS); /* RDSR */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2102 status = read_spi(HOLDCS);/* read status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2103 while(status & 0x01)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2104 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2105 HAL_Delay(1);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2106 status = read_spi(HOLDCS);/* read status */
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2107 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2108 chip_unselect();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2109 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2110
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2111
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
2112 static void ext_flash_incf_address(uint8_t type)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2113 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2114 uint32_t ringStart, ringStop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2115
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2116 actualAddress += 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2117
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2118 switch(type)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2119 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2120 case EF_HEADER:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2121 ringStart = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2122 ringStop = HEADERSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2123 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2124 case EF_SAMPLE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2125 ringStart = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2126 ringStop = SAMPLESTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2127 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2128 case EF_DEVICEDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2129 ringStart = DDSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2130 ringStop = DDSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2131 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2132 case EF_VPMDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2133 ringStart = VPMSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2134 ringStop = VPMSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2135 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2136 case EF_SETTINGS:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2137 ringStart = SETTINGSSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2138 ringStop = SETTINGSSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2139 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2140 case EF_FIRMWARE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2141 ringStart = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2142 ringStop = FWSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2143 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2144 case EF_FIRMWARE2:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2145 ringStart = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2146 ringStop = FWSTOP2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2147 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2148 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2149 ringStart = FLASHSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2150 ringStop = FLASHSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2151 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2152 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2153
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2154 if((actualAddress < ringStart) || (actualAddress > ringStop))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2155 actualAddress = ringStart;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2156 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2157
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
2158 #ifndef BOOTLOADER_STANDALONE
268
1b9847d40e81 cleanup: make things static where possible.
Jan Mulder <jlmulder@xs4all.nl>
parents: 225
diff changeset
2159 static void ext_flash_decf_address_ring(uint8_t type)
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2160 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2161 uint32_t ringStart, ringStop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2162
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2163 switch(type)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2164 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2165 case EF_HEADER:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2166 ringStart = HEADERSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2167 ringStop = HEADERSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2168 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2169 case EF_SAMPLE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2170 ringStart = SAMPLESTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2171 ringStop = SAMPLESTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2172 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2173 case EF_DEVICEDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2174 ringStart = DDSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2175 ringStop = DDSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2176 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2177 case EF_VPMDATA:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2178 ringStart = VPMSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2179 ringStop = VPMSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2180 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2181 case EF_SETTINGS:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2182 ringStart = SETTINGSSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2183 ringStop = SETTINGSSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2184 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2185 case EF_FIRMWARE:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2186 ringStart = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2187 ringStop = FWSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2188 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2189 case EF_FIRMWARE2:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2190 ringStart = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2191 ringStop = FWSTOP2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2192 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2193 default:
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2194 ringStart = FLASHSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2195 ringStop = FLASHSTOP;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2196 break;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2197 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2198
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2199 if((actualAddress <= ringStart) || (actualAddress > ringStop))
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2200 actualAddress = ringStop;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2201 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2202 actualAddress -= 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2203 }
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
2204 #endif
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2205
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2206 static void ef_hw_rough_delay_us(uint32_t delayUs)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2207 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2208 if(!delayUs)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2209 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2210 delayUs*= 12;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2211 while(delayUs--);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2212 return;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2213 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2214
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2215 static void Error_Handler_extflash(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2216 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2217 while(1)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2218 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2219 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2220 }
425
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2221
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2222 void ext_flash_CloseSector(void)
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2223 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2224 uint32_t actualAddressBackup = actualAddress;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2225 int i=0;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2226
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2227 if(closeSectorAddress != 0)
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2228 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2229 /* write some dummy bytes to the sector which is currently used for storing samples. This is done to "hide" problem if function is calles again */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2230 actualAddress = closeSectorAddress;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2231
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2232 wait_chip_not_busy();
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2233 write_spi(0x06,RELEASE); /* WREN */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2234 write_spi(0x02,HOLDCS); /* write cmd */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2235 write_address(HOLDCS);
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2236 for(i = 0; i<8; i++)
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2237 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2238 write_spi(0xA5,HOLDCS);/* write data */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2239 actualAddress++;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2240 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2241 /* byte with RELEASE */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2242 write_spi(0xA5,RELEASE);/* write data */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2243 actualAddress = actualAddressBackup;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2244 closeSectorAddress = 0;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2245 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2246 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2247
466
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2248 /* This function validates a potential jump of sample address by checking the last sector for empty memory cells */
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2249 uint8_t ext_flash_SampleOverrunValid(void)
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2250 {
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2251 uint8_t jumpvalid = 1;
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2252 uint32_t curAddress, actualaddrbackup;
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2253 uint8_t tmpBuffer;
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2254 uint8_t emptyCellCnt = 0;
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2255
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2256 actualaddrbackup = actualAddress;
557
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
2257 curAddress = SAMPLESTOP - 20; /* check the last 20 bytes of the last sample sector */
466
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2258 actualAddress = curAddress;
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2259 ext_flash_read_block_start();
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2260 while(actualAddress < SAMPLESTOP)
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2261 {
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2262 tmpBuffer = read_spi(HOLDCS);/* read data */
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2263 if(tmpBuffer == 0xFF)
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2264 {
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2265 emptyCellCnt++;
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2266 }
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2267 actualAddress++;
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2268 }
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2269 ext_flash_read_block_stop();
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2270
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2271 if(emptyCellCnt == 20)
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2272 {
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2273 jumpvalid = 0;
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2274 }
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2275 actualAddress = actualaddrbackup;
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2276 return jumpvalid;
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2277 }
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2278
557
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
2279 uint32_t ext_flash_AnalyseSampleBuffer()
425
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2280 {
557
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
2281 uint8_t sectorState[192]; /* samples are stored in 192 sector / 64k each */
425
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2282 uint32_t curAddress = SAMPLESTART;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2283 uint8_t curSector = 0;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2284 uint8_t samplebuffer[10];
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2285 uint32_t actualAddressBackup = actualAddress;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2286 uint8_t emptyCellCnt = 0;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2287 uint32_t i = 0;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2288 uint8_t startedSectors = 0;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2289 uint8_t lastSectorInuse = 0;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2290
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2291 /* check if a sector is used till its end */
557
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
2292 for(curSector = 0; curSector < 192; curSector++)
425
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2293 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2294 sectorState[curSector] = 0;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2295 emptyCellCnt = 0;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2296 curAddress = SAMPLESTART + (curSector * 0x10000); /* set address to begin of sector and check if it is used */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2297 actualAddress = curAddress;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2298 ext_flash_read_block_start();
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2299 for(uint32_t i=0;i<10;i++)
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2300 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2301 samplebuffer[i] = read_spi(HOLDCS);/* read data */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2302 if(samplebuffer[i] == 0xFF)
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2303 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2304 emptyCellCnt++;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2305 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2306 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2307 ext_flash_read_block_stop();
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2308 if(emptyCellCnt == 10)
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2309 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2310 sectorState[curSector] = SECTOR_NOTUSED;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2311 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2312 emptyCellCnt = 0;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2313 curAddress = SAMPLESTART + (curSector * 0x10000) + 0xFFF5; /* set address to end of sector and check if it is used */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2314 actualAddress = curAddress;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2315 ext_flash_read_block_start();
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2316 for(i=0;i<10;i++)
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2317 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2318 samplebuffer[i] = read_spi(HOLDCS);/* read data */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2319 if(samplebuffer[i] == 0xFF)
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2320 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2321 emptyCellCnt++;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2322 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2323 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2324 ext_flash_read_block_stop();
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2325 if(emptyCellCnt == 10)
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2326 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2327 sectorState[curSector] |= SECTOR_INUSE; /* will become SECTOR_EMPTY if start is NOTUSED */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2328 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2329 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2330
557
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
2331 for(i=0;i<192;i++)
425
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2332 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2333 if( sectorState[i] == SECTOR_INUSE)
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2334 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2335 startedSectors++;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2336 lastSectorInuse = i;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2337 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2338 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2339
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2340 if(startedSectors > 1) /* more than one sector is in used => ring buffer corrupted */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2341 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2342 if(startedSectors == 2) /* only fix issue if only two sectors are in used. Otherwise fixing will cause more worries than help */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2343 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2344 /* the logic behind healing of the problem is that the larger address is the oldest one => restore the largest address */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2345 curAddress = SAMPLESTART + (lastSectorInuse * 0x10000);
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2346 emptyCellCnt = 0;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2347 actualAddress = curAddress;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2348 ext_flash_read_block_start();
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2349 while((emptyCellCnt < 10) && (actualAddress < curAddress + 0x10000))
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2350 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2351 samplebuffer[0] = read_spi(HOLDCS);/* read data */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2352 if(samplebuffer[0] == 0xFF)
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2353 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2354 emptyCellCnt++;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2355 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2356 else
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2357 {
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2358 emptyCellCnt = 0;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2359 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2360 actualAddress++;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2361 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2362 ext_flash_read_block_stop();
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2363 actualAddress -= 10; /* step 10 bytes back to the start of free bytes */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2364 actualPointerSample = actualAddress;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2365
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2366 closeSectorAddress = settingsGetPointer()->logFlashNextSampleStartAddress & 0xFFFF0000;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2367 closeSectorAddress += 0xFFF5; /* to be used once next time a dive is logged. Needed because NextSampleID is derived at every startup */
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2368 settingsGetPointer()->logFlashNextSampleStartAddress = actualPointerSample; /* store new position to be used for next dive */
557
2702bfa7b177 Stabilityfix: Do not trust lastDiveLogID == 0 at startup:
Ideenmodellierer
parents: 538
diff changeset
2369 ext_flash_CloseSector();
425
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2370 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2371 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2372 actualAddress = actualAddressBackup;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2373 return startedSectors;
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2374 }
86fcac4cc43a Added function to analyse the sampel ringbuffer:
ideenmodellierer
parents: 423
diff changeset
2375
466
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2376 uint32_t ext_flash_read_profilelength_small_header(uint32_t smallHeaderAddr)
452
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
2377 {
466
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2378 uint32_t profileLength = 0;
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2379 actualPointerSample = smallHeaderAddr;
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2380 actualAddress = actualPointerSample;
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2381 ext_flash_read_block_start();
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2382 ext_flash_read_next_sample_part((uint8_t*)&profileLength, 3);
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2383 ext_flash_close_read_sample();
538eb1c976e9 Removed invalidate header function because it is no lonnger needed
ideenmodellierer
parents: 463
diff changeset
2384 return profileLength;
452
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
2385 }
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
2386
b90ddf57f7f1 Added compile variant enabling the reset of profile sample information:
ideenmodellierer
parents: 429
diff changeset
2387
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
2388
38
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2389 uint8_t ext_flash_erase_firmware_if_not_empty(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2390 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2391 const uint8_t TESTSIZE_FW = 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2392
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2393 uint8_t data[TESTSIZE_FW];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2394 uint8_t notEmpty = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2395
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2396 actualAddress = FWSTART;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2397 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2398 for(int i = 0; i < TESTSIZE_FW; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2399 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2400 ext_flash_read_block(&data[i], EF_FIRMWARE);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2401 if(data[i] != 0xFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2402 notEmpty = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2403 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2404 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2405
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2406 if(notEmpty)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2407 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2408 ext_flash_erase_firmware();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2409 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2410 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2411 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2412 return 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2413 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2414
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2415 uint8_t ext_flash_erase_firmware2_if_not_empty(void)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2416 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2417 const uint8_t TESTSIZE_FW = 4;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2418
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2419 uint8_t data[TESTSIZE_FW];
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2420 uint8_t notEmpty = 0;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2421
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2422 actualAddress = FWSTART2;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2423 ext_flash_read_block_start();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2424 for(int i = 0; i < TESTSIZE_FW; i++)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2425 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2426 ext_flash_read_block(&data[i], EF_FIRMWARE2);
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2427 if(data[i] != 0xFF)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2428 notEmpty = 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2429 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2430 ext_flash_read_block_stop();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2431
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2432 if(notEmpty)
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2433 {
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2434 ext_flash_erase_firmware2();
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2435 return 1;
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2436 }
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2437 else
5f11787b4f42 include in ostc4 repository
heinrichsweikamp
parents:
diff changeset
2438 return 0;
870
bc6c90e20d9e Instrument code for Bootloader:
Ideenmodellierer
parents: 557
diff changeset
2439 }