Skip to content

Commit 33e0887

Browse files
committed
Release merge for v1.03 for MLA v2016-04-27:
* Added required user defined callback for internal flash physical layer: DRV_FILEIO_INTERNAL_FLASH_CONFIG_UNLOCK_VERIFICATION_FUNCTION. This function should validate that the system parameters are valid for flash writes on the device on the board (Vdd, clock speeds, etc. are all in valid range for self writes). * migrated from system_config.h to direct include of fileio_config.h
1 parent ec02cd6 commit 33e0887

File tree

10 files changed

+112
-121
lines changed

10 files changed

+112
-121
lines changed

doc/help_mla_fileio.jar

-469 Bytes
Binary file not shown.

doc/help_mla_fileio.pdf

-3.07 KB
Binary file not shown.

drivers/internal_flash/internal_flash.c

Lines changed: 20 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -676,74 +676,34 @@ void EraseBlock(const uint8_t* dest)
676676
}
677677

678678

679-
//------------------------------------------------------------------------------
680-
#if defined(__XC16__)
681-
#pragma message "Double click this message and read inline code comments. For production designs, recommend adding application specific robustness features here."
682-
#else
683-
#warning "Double click this message and read inline code comments. For production designs, recommend adding application specific robustness features here."
679+
680+
#ifndef DRV_FILEIO_INTERNAL_FLASH_CONFIG_UNLOCK_VERIFICATION_FUNCTION
681+
#error "User must define the DRV_FILEIO_INTERNAL_FLASH_CONFIG_UNLOCK_VERIFICATION_FUNCTION macro in the fileio_config.h file. Click this message for more details in comments."
682+
/* The DRV_FILEIO_INTERNAL_FLASH_CONFIG_UNLOCK_VERIFICATION_FUNCTION macro
683+
* is used to verify that the system is in a condition where a self write
684+
* is valid. This could include checks for system voltage levels, clocking
685+
* vs voltage, address checking for write locations, etc. The prototype of
686+
* the function that this micro should point to is the following:
687+
* bool functionName(void);
688+
* The functions should return true if the self write is allowed and false
689+
* if the self write is not allowed.
690+
*/
684691
#endif
685-
//Function: void UnlockAndActivate(uint8_t UnlockKey)
686-
//Description: Activates and initiates a flash memory self erase or program
687-
//operation. Useful for writing to the MSD drive volume.
688-
//Note: Self erase/writes to flash memory could potentially corrupt the
689-
//firmware of the application, if the unlock sequence is ever executed
690-
//unintentionally, or if the table pointer is pointing to an invalid
691-
//range (not inside the MSD volume range). Therefore, in order to ensure
692-
//a fully reliable design that is suitable for mass production, it is strongly
693-
//recommended to implement several robustness checks prior to actually
694-
//performing any self erase/program unlock sequence. See additional inline
695-
//code comments.
692+
693+
bool DRV_FILEIO_INTERNAL_FLASH_CONFIG_UNLOCK_VERIFICATION_FUNCTION(void);
694+
695+
696696
//------------------------------------------------------------------------------
697697
void UnlockAndActivate(uint8_t UnlockKey)
698698
{
699699
#if defined(__XC8) || defined(__18CXX)
700700
uint8_t InterruptEnableSave;
701701
#endif
702702

703-
//Should verify that the voltage on Vdd/Vddcore is high enough to meet
704-
//the datasheet minimum voltage vs. frequency graph for the device.
705-
//If the microcontroller is "overclocked" (ex: by running at maximum rated
706-
//frequency, but then not suppling enough voltage to meet the datasheet
707-
//voltage vs. frequency graph), errant code execution could occur. It is
708-
//therefore strongly recommended to check the voltage prior to performing a
709-
//flash self erase/write unlock sequence. If the voltage is too low to meet
710-
//the voltage vs. frequency graph in the datasheet, the firmware should not
711-
//inititate a self erase/program operation, and instead it should either:
712-
//1. Clock switch to a lower frequency that does meet the voltage/frequency graph. Or,
713-
//2. Put the microcontroller to Sleep mode.
714-
715-
//The method used to measure Vdd and/or Vddcore will depend upon the
716-
//microcontroller model and the module features available in the device, but
717-
//several options are available on many of the microcontrollers, ex:
718-
//1. HLVD module
719-
//2. WDTCON<LVDSTAT> indicator bit
720-
//3. Perform ADC operation, with the VBG channel selected, using Vdd/Vss as
721-
// references to the ADC. Then perform math operations to calculate the Vdd.
722-
// On some micros, the ADC can also measure the Vddcore voltage, allowing
723-
// the firmware to calculate the absolute Vddcore voltage, if it has already
724-
// calculated and knows the ADC reference voltage.
725-
//4. Use integrated general purpose comparator(s) to sense Vdd/Vddcore voltage
726-
// is above proper threshold.
727-
//5. If the micrcontroller implements a user adjustable BOR circuit, enable
728-
// it and set the trip point high enough to avoid overclocking altogether.
729-
730-
//Example psuedo code. Exact implementation will be application specific.
731-
//Please implement appropriate code that best meets your application requirements.
732-
//if(GetVddcoreVoltage() < MIN_ALLOWED_VOLTAGE)
733-
//{
734-
// ClockSwitchToSafeFrequencyForGivenVoltage(); //Or even better, go to sleep mode.
735-
// return;
736-
//}
737-
738-
739-
//Should also verify the TBLPTR is pointing to a valid range (part of the MSD
740-
//volume, and not a part of the application firmware space).
741-
//Example code for PIC18 (commented out since the actual address range is
742-
//application specific):
743-
//if((TBLPTR > MSD_VOLUME_MAX_ADDRESS) || (TBLPTR < MSD_VOLUME_START_ADDRESS))
744-
//{
745-
// return;
746-
//}
703+
if(DRV_FILEIO_INTERNAL_FLASH_CONFIG_UNLOCK_VERIFICATION_FUNCTION() == false)
704+
{
705+
return;
706+
}
747707

748708
//Verify the UnlockKey is the correct value, to make sure this function is
749709
//getting executed intentionally, from a calling function that knew it

drivers/internal_flash/internal_flash.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ please contact mla_licensing@microchip.com
2121

2222
#include "fileio_config.h"
2323
#include <fileio.h>
24+
#include <fileio_media.h>
2425

2526
uint8_t FILEIO_InternalFlash_MediaDetect(void* config);
2627
FILEIO_MEDIA_INFORMATION * FILEIO_InternalFlash_MediaInitialize(void* config);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// DOM-IGNORE-BEGIN
2+
/*******************************************************************************
3+
Copyright 2016 Microchip Technology Inc. (www.microchip.com)
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
To request to license the code under the MLA license (www.microchip.com/mla_license),
18+
please contact mla_licensing@microchip.com
19+
*******************************************************************************/
20+
//DOM-IGNORE-END
21+
22+
// Macro maps to a user function that will determine if the system parameters are valid for a self write
23+
// for the processor on the board. Returns true if the write can continue and false if it should not.
24+
#define DRV_FILEIO_INTERNAL_FLASH_CONFIG_UNLOCK_VERIFICATION_FUNCTION() true
25+
26+
27+

drivers/sd_spi/sd_spi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ please contact mla_licensing@microchip.com
2727
#include <stdint.h>
2828
#include <stdbool.h>
2929

30+
#include <fileio_media.h>
3031

3132
/*****************************************************************************/
3233
/* Custom structures and definitions */

inc/fileio.h

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ please contact mla_licensing@microchip.com
2626
#include <stdint.h>
2727
#include <stdbool.h>
2828
#include <stddef.h>
29-
#include "system_config.h"
29+
#include "fileio_config.h"
3030
#include "system.h"
3131

32+
#include <fileio_media.h>
33+
3234

3335
/*******************************************************************/
3436
/* Structures and defines */
@@ -176,33 +178,6 @@ typedef enum
176178
FILEIO_GET_PROPERTIES_STILL_WORKING = 0xFF
177179
} FILEIO_DRIVE_ERRORS;
178180

179-
// Enumeration to define media error types
180-
typedef enum
181-
{
182-
MEDIA_NO_ERROR, // No errors
183-
MEDIA_DEVICE_NOT_PRESENT, // The requested device is not present
184-
MEDIA_CANNOT_INITIALIZE // Cannot initialize media
185-
} FILEIO_MEDIA_ERRORS;
186-
187-
// Media information flags. The driver's MediaInitialize function will return a pointer to one of these structures.
188-
typedef struct
189-
{
190-
FILEIO_MEDIA_ERRORS errorCode; // The status of the intialization FILEIO_MEDIA_ERRORS
191-
// Flags
192-
union
193-
{
194-
uint8_t value;
195-
struct
196-
{
197-
uint8_t sectorSize : 1; // The sector size parameter is valid.
198-
uint8_t maxLUN : 1; // The max LUN parameter is valid.
199-
} bits;
200-
} validityFlags;
201-
202-
uint16_t sectorSize; // The sector size of the target device.
203-
uint8_t maxLUN; // The maximum Logical Unit Number of the device.
204-
} FILEIO_MEDIA_INFORMATION;
205-
206181
/***************************************************************************
207182
Function:
208183
void (*FILEIO_DRIVER_IOInitialize)(void * mediaConfig);

inc/fileio_lfn.h

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ please contact mla_licensing@microchip.com
2929
#include "system_config.h"
3030
#include "system.h"
3131

32+
#include <fileio_media.h>
33+
3234

3335
/*******************************************************************/
3436
/* Structures and defines */
@@ -178,32 +180,6 @@ typedef enum
178180
FILEIO_GET_PROPERTIES_STILL_WORKING = 0xFF
179181
} FILEIO_DRIVE_ERRORS;
180182

181-
// Enumeration to define media error types
182-
typedef enum
183-
{
184-
MEDIA_NO_ERROR, // No errors
185-
MEDIA_DEVICE_NOT_PRESENT, // The requested device is not present
186-
MEDIA_CANNOT_INITIALIZE // Cannot initialize media
187-
} FILEIO_MEDIA_ERRORS;
188-
189-
// Media information flags. The driver's MediaInitialize function will return a pointer to one of these structures.
190-
typedef struct
191-
{
192-
FILEIO_MEDIA_ERRORS errorCode; // The status of the intialization FILEIO_MEDIA_ERRORS
193-
// Flags
194-
union
195-
{
196-
uint8_t value;
197-
struct
198-
{
199-
uint8_t sectorSize : 1; // The sector size parameter is valid.
200-
uint8_t maxLUN : 1; // The max LUN parameter is valid.
201-
} bits;
202-
} validityFlags;
203-
204-
uint16_t sectorSize; // The sector size of the target device.
205-
uint8_t maxLUN; // The maximum Logical Unit Number of the device.
206-
} FILEIO_MEDIA_INFORMATION;
207183

208184
/***************************************************************************
209185
Function:

inc/fileio_media.h

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// DOM-IGNORE-BEGIN
2+
/*******************************************************************************
3+
Copyright 2015 Microchip Technology Inc. (www.microchip.com)
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
17+
To request to license the code under the MLA license (www.microchip.com/mla_license),
18+
please contact mla_licensing@microchip.com
19+
*******************************************************************************/
20+
//DOM-IGNORE-END
21+
22+
#ifndef _FILEIO_MEDIA_H
23+
#define _FILEIO_MEDIA_H
24+
25+
// Enumeration to define media error types
26+
typedef enum
27+
{
28+
MEDIA_NO_ERROR, // No errors
29+
MEDIA_DEVICE_NOT_PRESENT, // The requested device is not present
30+
MEDIA_CANNOT_INITIALIZE // Cannot initialize media
31+
} FILEIO_MEDIA_ERRORS;
32+
33+
// Media information flags. The driver's MediaInitialize function will return a pointer to one of these structures.
34+
typedef struct
35+
{
36+
FILEIO_MEDIA_ERRORS errorCode; // The status of the initialization FILEIO_MEDIA_ERRORS
37+
// Flags
38+
union
39+
{
40+
uint8_t value;
41+
struct
42+
{
43+
uint8_t sectorSize : 1; // The sector size parameter is valid.
44+
uint8_t maxLUN : 1; // The max LUN parameter is valid.
45+
} bits;
46+
} validityFlags;
47+
48+
uint16_t sectorSize; // The sector size of the target device.
49+
uint8_t maxLUN; // The maximum Logical Unit Number of the device.
50+
} FILEIO_MEDIA_INFORMATION;
51+
52+
#endif

src/fileio.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ please contact mla_licensing@microchip.com
1919
*******************************************************************************/
2020
//DOM-IGNORE-END
2121

22-
#include <system_config.h>
22+
#include <fileio_config.h>
2323
#include <system.h>
2424
#include <fileio.h>
2525
#include "fileio_private.h"
@@ -798,7 +798,6 @@ void FILEIO_FormatShortFileName (const char * fileName, FILEIO_OBJECT * filePtr)
798798
}
799799
}
800800

801-
802801
int FILEIO_Open (FILEIO_OBJECT * filePtr, const char * fileName, uint16_t mode)
803802
{
804803
FILEIO_ERROR_TYPE error;
@@ -811,11 +810,11 @@ int FILEIO_Open (FILEIO_OBJECT * filePtr, const char * fileName, uint16_t mode)
811810
uint16_t currentClusterOffset = 0;
812811

813812
fileName = FILEIO_CacheDirectory (&directory, fileName, false);
814-
813+
815814
if (fileName == NULL)
816815
{
817816
return FILEIO_RESULT_FAILURE;
818-
}
817+
}
819818

820819
currentCluster = directory.cluster;
821820

@@ -939,7 +938,7 @@ int FILEIO_Open (FILEIO_OBJECT * filePtr, const char * fileName, uint16_t mode)
939938
}
940939
}
941940

942-
// Check to ensure no errors occured
941+
// Check to ensure no errors occurred
943942
if (error != FILEIO_ERROR_NONE)
944943
{
945944
directory.drive->error = error;
@@ -1061,7 +1060,7 @@ const char * FILEIO_CacheDirectory (FILEIO_DIRECTORY * dir, const char * path, b
10611060
#endif
10621061

10631062
// Find the next forward slash (indicates part of the path is a directory)
1064-
while ((i = FILEIO_FindNextDelimiter(path)) != -1)
1063+
while ((i = FILEIO_FindNextDelimiter(path)) != ((uint16_t)-1))
10651064
{
10661065
// If someone terminated a directory path with a delimiter, break out of the loop
10671066
if (*(path + i) == FILEIO_CONFIG_DELIMITER)
@@ -1126,7 +1125,7 @@ uint16_t FILEIO_FindNextDelimiter(const char * path)
11261125

11271126
if (c == 0)
11281127
{
1129-
return -1;
1128+
return ((uint16_t)-1);
11301129
}
11311130
else
11321131
{

0 commit comments

Comments
 (0)