Skip to content

Commit d4fc79a

Browse files
committed
Trunk Build 670
1 parent 3883dae commit d4fc79a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3374
-73
lines changed

Diff for: core/driver/blockio.c

+40-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@
2828
The OS block device implementations operate on sectors. The core does I/O
2929
in terms of logical blocks: this module translates from logical blocks to
3030
sectors.
31+
32+
If bBlockIoRetries is greater than 0 for the current volume, then this
33+
module will retry block device calls on failure up to the configured number
34+
of times. This behavior caters to the type of unreliable hardware and
35+
drivers that are sometimes found in the IoT world, where one operation may
36+
fail but the next may still succeed.
3137
*/
3238
#include <redfs.h>
3339
#include <redcore.h>
@@ -52,7 +58,7 @@ REDSTATUS RedIoRead(
5258
uint32_t ulBlockCount,
5359
void *pBuffer)
5460
{
55-
REDSTATUS ret;
61+
REDSTATUS ret = 0;
5662

5763
if( (bVolNum >= REDCONF_VOLUME_COUNT)
5864
|| (ulBlockStart >= gaRedVolume[bVolNum].ulBlockCount)
@@ -68,11 +74,20 @@ REDSTATUS RedIoRead(
6874
uint8_t bSectorShift = gaRedVolume[bVolNum].bBlockSectorShift;
6975
uint64_t ullSectorStart = (uint64_t)ulBlockStart << bSectorShift;
7076
uint32_t ulSectorCount = ulBlockCount << bSectorShift;
77+
uint8_t bRetryIdx;
7178

7279
REDASSERT(bSectorShift < 32U);
7380
REDASSERT((ulSectorCount >> bSectorShift) == ulBlockCount);
7481

75-
ret = RedOsBDevRead(bVolNum, ullSectorStart, ulSectorCount, pBuffer);
82+
for(bRetryIdx = 0U; bRetryIdx <= gpRedVolConf->bBlockIoRetries; bRetryIdx++)
83+
{
84+
ret = RedOsBDevRead(bVolNum, ullSectorStart, ulSectorCount, pBuffer);
85+
86+
if(ret == 0)
87+
{
88+
break;
89+
}
90+
}
7691
}
7792

7893
CRITICAL_ASSERT(ret == 0);
@@ -101,7 +116,7 @@ REDSTATUS RedIoWrite(
101116
uint32_t ulBlockCount,
102117
const void *pBuffer)
103118
{
104-
REDSTATUS ret;
119+
REDSTATUS ret = 0;
105120

106121
if( (bVolNum >= REDCONF_VOLUME_COUNT)
107122
|| (ulBlockStart >= gaRedVolume[bVolNum].ulBlockCount)
@@ -117,11 +132,20 @@ REDSTATUS RedIoWrite(
117132
uint8_t bSectorShift = gaRedVolume[bVolNum].bBlockSectorShift;
118133
uint64_t ullSectorStart = (uint64_t)ulBlockStart << bSectorShift;
119134
uint32_t ulSectorCount = ulBlockCount << bSectorShift;
135+
uint8_t bRetryIdx;
120136

121137
REDASSERT(bSectorShift < 32U);
122138
REDASSERT((ulSectorCount >> bSectorShift) == ulBlockCount);
123139

124-
ret = RedOsBDevWrite(bVolNum, ullSectorStart, ulSectorCount, pBuffer);
140+
for(bRetryIdx = 0U; bRetryIdx <= gpRedVolConf->bBlockIoRetries; bRetryIdx++)
141+
{
142+
ret = RedOsBDevWrite(bVolNum, ullSectorStart, ulSectorCount, pBuffer);
143+
144+
if(ret == 0)
145+
{
146+
break;
147+
}
148+
}
125149
}
126150

127151
CRITICAL_ASSERT(ret == 0);
@@ -144,7 +168,7 @@ REDSTATUS RedIoWrite(
144168
REDSTATUS RedIoFlush(
145169
uint8_t bVolNum)
146170
{
147-
REDSTATUS ret;
171+
REDSTATUS ret = 0;
148172

149173
if(bVolNum >= REDCONF_VOLUME_COUNT)
150174
{
@@ -153,7 +177,17 @@ REDSTATUS RedIoFlush(
153177
}
154178
else
155179
{
156-
ret = RedOsBDevFlush(bVolNum);
180+
uint8_t bRetryIdx;
181+
182+
for(bRetryIdx = 0U; bRetryIdx <= gpRedVolConf->bBlockIoRetries; bRetryIdx++)
183+
{
184+
ret = RedOsBDevFlush(bVolNum);
185+
186+
if(ret == 0)
187+
{
188+
break;
189+
}
190+
}
157191
}
158192

159193
CRITICAL_ASSERT(ret == 0);

Diff for: core/driver/buffer.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ REDSTATUS RedBufferGet(
311311
mounted; that condition is expected and should
312312
not result in an assertion.
313313
*/
314-
CRITICAL_ASSERT((uFlags & BFLAG_META_MASTER) != 0U);
314+
CRITICAL_ASSERT((uFlags & BFLAG_META_MASTER) == BFLAG_META_MASTER);
315315
ret = -RED_EIO;
316316
}
317317
}

Diff for: doc/release_notes.md

+24
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,30 @@ recent releases and a list of known issues.
55

66
## Release History and Changes
77

8+
### Reliance Edge v1.0.2, February 2016
9+
10+
#### Common Code Changes
11+
- A new per-volume configuration option has been added: users can specify a
12+
number of times to retry a block device read, write or flush operation before
13+
returning a failure. The configuration tool has been updated to version 1.0.2
14+
with this change.
15+
- This added a new field to the volume configuration in to redconf.c: existing
16+
redconf.c files from v1.0.1 and earlier must be updated to work with v1.0.2.
17+
Open redconf.h and redconf.c with the configuration tool, enable
18+
"Retry block device I/O on failure" for any volumes if desired, and save the
19+
redconf files.
20+
21+
#### FreeRTOS Port Changes
22+
- Added support for the STM32 HAL SD card driver in the FreeRTOS block device
23+
interface. Two boards are supported out-of-the-box: the STM324xG-EVAL and the
24+
STM32F746NG-Discovery. A sample project is included for the STM324xG-EVAL.
25+
26+
#### MQX Port Changes
27+
- Fixed a bug which prevented Reliance Edge from compiling if the File System
28+
Essentials API was selected in the configuration.
29+
- Fixed a bug which would have returned an uninitialized value from
30+
`RedOsBDevFlush()` for block devices that support flushing.
31+
832
### Reliance Edge v1.0.1, October 2015
933

1034
- Added MQX RTOS support in the commercial kit, with example projects for

Diff for: doc/release_notes.txt

+28
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,34 @@ course of recent releases and a list of known issues.
99

1010
Release History and Changes
1111

12+
Reliance Edge v1.0.2, February 2016
13+
14+
Common Code Changes
15+
16+
- A new per-volume configuration option has been added: users can
17+
specify a number of times to retry a block device read, write or
18+
flush operation before returning a failure. The configuration tool
19+
has been updated to version 1.0.2 with this change.
20+
- This added a new field to the volume configuration in to redconf.c:
21+
existing redconf.c files from v1.0.1 and earlier must be updated to
22+
work with v1.0.2. Open redconf.h and redconf.c with the
23+
configuration tool, enable "Retry block device I/O on failure" for
24+
any volumes if desired, and save the redconf files.
25+
26+
FreeRTOS Port Changes
27+
28+
- Added support for the STM32 HAL SD card driver in the FreeRTOS block
29+
device interface. Two boards are supported out-of-the-box: the
30+
STM324xG-EVAL and the STM32F746NG-Discovery. A sample project is
31+
included for the STM324xG-EVAL.
32+
33+
MQX Port Changes
34+
35+
- Fixed a bug which prevented Reliance Edge from compiling if the File
36+
System Essentials API was selected in the configuration.
37+
- Fixed a bug which would have returned an uninitialized value from
38+
RedOsBDevFlush() for block devices that support flushing.
39+
1240
Reliance Edge v1.0.1, October 2015
1341

1442
- Added MQX RTOS support in the commercial kit, with example projects

Diff for: include/redver.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
3434
<!-- This macro is updated automatically: do not edit! -->
3535
*/
36-
#define RED_BUILD_NUMBER "668"
36+
#define RED_BUILD_NUMBER "670"
3737

3838
#define RED_KIT_GPL 0U /* Open source GPL kit. */
3939
#define RED_KIT_COMMERCIAL 1U /* Commercially-licensed kit. */
@@ -48,7 +48,7 @@
4848

4949
/** @brief Version number to display in output.
5050
*/
51-
#define RED_VERSION "v1.0.1"
51+
#define RED_VERSION "v1.0.2"
5252

5353

5454
/** @brief On-disk version number.

Diff for: include/redvolume.h

+7
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ typedef struct
6262
*/
6363
uint32_t ulInodeCount;
6464

65+
/** This is the maximum number of times a block device I/O operation will
66+
be retried. If a block device read, write, or flush fails, Reliance
67+
Edge will try again up to this number of times until the operation is
68+
successful. Set this to 0 to disable retries.
69+
*/
70+
uint8_t bBlockIoRetries;
71+
6572
#if REDCONF_API_POSIX == 1
6673
/** The path prefix for the volume; for example, "VOL1:", "FlashDisk", etc.
6774
*/

Diff for: os/freertos/include/redosdeviations.h

+86-7
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@
3636
#endif
3737

3838

39-
#if REDCONF_ASSERTS == 1
40-
#if REDCONF_OUTPUT == 1
39+
#if (REDCONF_ASSERTS == 1) && (REDCONF_OUTPUT == 1)
4140
/** Print a formatted message for an assertion.
4241
4342
Usages of this macro deviate from MISRA C:2012 Rule 21.6 (required). Using
@@ -50,11 +49,8 @@
5049
As Rule 21.6 is required, a separate deviation record is required.
5150
*/
5251
#define PRINT_ASSERT(file, line) \
53-
(void)printf("Assertion failed in \"%s\" at line %u\n\r", ((file) == NULL) ? "" : (file), (unsigned)(line))
54-
#else
55-
#define PRINT_ASSERT(file, line) do { (void)(file); (void)(line); } while(false)
56-
#endif /* REDCONF_OUTPUT == 1 */
57-
#endif /* REDCONF_ASSERTS == 1 */
52+
printf("Assertion failed in \"%s\" at line %u\n\r", ((file) == NULL) ? "" : (file), (unsigned)(line))
53+
#endif
5854

5955

6056
/** Cast a value to unsigned long.
@@ -161,5 +157,88 @@
161157
#endif
162158

163159

160+
/** Ignore the return value of a function (cast to void)
161+
162+
Usages of this macro deviate from MISRA C:2012 Directive 4.7, which states
163+
that error information must be checked immediately after a function returns
164+
potential error information.
165+
166+
If asserts and output are enabled, then this macro is used to document that
167+
the return value of printf() is ignored. A failure of printf() does not
168+
impact the filesystem core, nor is there anything the filesystem can do to
169+
respond to such an error (especially since it occurs within an assert).
170+
Thus, the most reasonable action is to ignore the error.
171+
172+
In the STM32 SDIO block device implementation, errors are also ignored in an
173+
IRQ interrupt handler. This is the most reasonable action to take for two
174+
reasons: (a) it would be dangerous to spend processor time responding to the
175+
error inside the IRQ handler; (b) it has been verified that the same error
176+
is propegated to the DiskRead/Write method, which does return the error to
177+
the core.
178+
179+
In the Atmel SD/MMC block device implementation, error information from
180+
sd_mmc_read_capacity() is ignored. This is a reasonable action because all
181+
of the possible error conditions were eliminated by a previous check.
182+
sd_mmc_read_capacity() fails under the same conditions as
183+
sd_mmc_test_unit_ready(), which was checked ealier in the same function.
184+
185+
In the mutex module, error information returned from the mutex release
186+
function is ignored when asserts are disabled. This is a reasonable action
187+
because the mutex release function (xSemaphoreGive) is documented only to
188+
fail if the mutex was not obtained correctly, which can be demonstrably
189+
avoided.
190+
191+
As Directive 4.7 is required, a separate deviation record is required.
192+
*/
193+
#define IGNORE_ERRORS(fn) ((void) (fn))
194+
195+
196+
/** @brief Determine whether a pointer is aligned on a 32-bit boundary.
197+
198+
This is used to determine whether a data buffer meets the requirements of
199+
the underlying block device implementation. When transferring data via
200+
DMA (Direct Memory Access) on an STM32 device, the data buffer must be cast
201+
as a uint32 pointer, and unexpected behavior may occur if the buffer is not
202+
aligned correctly.
203+
204+
There is no way to perform this check without deviating from MISRA C rules
205+
against casting pointers to integer types. Usage of this macro deviates
206+
from MISRA C:2012 Rule 11.4 (advisory). The main rationale the rule cites
207+
against converting pointers to integers is that the chosen integer type may
208+
not be able to represent the pointer; this is a non-issue here since we use
209+
uintptr_t. The text says the rule still applies when using uintptr_t due to
210+
concern about unaligned pointers, but that is not an issue here since the
211+
integer value of the pointer is not saved and not converted back into a
212+
pointer and dereferenced. The result of casting a pointer to a sufficiently
213+
large integer is implementation-defined, but macros similar to this one have
214+
been used by Datalight for a long time in a wide variety of environments and
215+
they have always worked as expected.
216+
217+
This deviation only occurs when using the STM32 SDIO block device
218+
implementation.
219+
220+
As Rule 11.4 is advisory, a deviation record is not required. This notice
221+
is the only record of deviation.
222+
*/
223+
#define IS_UINT32_ALIGNED_PTR(ptr) (((uintptr_t)(ptr) & (sizeof(uint32_t) - 1U)) == 0U)
224+
225+
226+
/** @brief Cast a 32-bit aligned void pointer to a uint32 pointer.
227+
228+
Usages of this macro deviate from MISRA C:2012 Rule 11.5 (advisory). A
229+
cast from a void pointer to an object pointer is discouraged because of
230+
potential alignment issues. However, this macro is only used to cast
231+
pointers that have already been tested to be 32-bit aligned, so the
232+
operation will be safe.
233+
234+
This deviation only occurs when using the STM32 SDIO block device
235+
implementation.
236+
237+
As rule 11.5 is advisory, a deviation record is not required. This notice
238+
is the only record of the deviation.
239+
*/
240+
#define CAST_UINT32_PTR(ptr) ((uint32_t *) (ptr))
241+
242+
164243
#endif
165244

Diff for: os/freertos/services/osassert.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ void RedOsAssertFail(
4343
const char *pszFileName,
4444
uint32_t ulLineNum)
4545
{
46-
PRINT_ASSERT(pszFileName, ulLineNum);
46+
#if REDCONF_OUTPUT == 1
47+
IGNORE_ERRORS(PRINT_ASSERT(pszFileName, ulLineNum));
48+
#endif
4749

4850
while(true)
4951
{

0 commit comments

Comments
 (0)