Kinetis Bootloader  2.0.0
Common bootloader for Kinetis devices
disk.h
1 /*
2  * Copyright (c) 2015, Freescale Semiconductor, Inc.
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * o Redistributions of source code must retain the above copyright notice, this list
9  * of conditions and the following disclaimer.
10  *
11  * o Redistributions in binary form must reproduce the above copyright notice, this
12  * list of conditions and the following disclaimer in the documentation and/or
13  * other materials provided with the distribution.
14  *
15  * o Neither the name of Freescale Semiconductor, Inc. nor the names of its
16  * contributors may be used to endorse or promote products derived from this
17  * software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
20  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
23  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
24  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
26  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #ifndef __USB_DISK_H__
32 #define __USB_DISK_H__ 1
33 
34 #include "usb_device_config.h"
35 #include "usb.h"
36 #include "usb_device.h"
37 #include "usb_device_class.h"
38 #include "usb_device_msc.h"
39 #include "usb_device_ch9.h"
40 #include "usb_descriptor.h"
41 #include "flash/fsl_flash.h"
42 #include "executable_image.h"
43 /*******************************************************************************
44  * Definitions
45  ******************************************************************************/
46 #if defined(USB_DEVICE_CONFIG_EHCI) && (USB_DEVICE_CONFIG_EHCI > 0)
47 #define CONTROLLER_ID kUSB_ControllerEhci0
48 #endif
49 #if defined(USB_DEVICE_CONFIG_KHCI) && (USB_DEVICE_CONFIG_KHCI > 0)
50 #define CONTROLLER_ID kUSB_ControllerKhci0
51 #endif
52 
53 #define USB_DEVICE_INTERRUPT_PRIORITY (4)
54 
55 /* Length of Each Logical Address Block */
56 #define LENGTH_OF_EACH_LBA (512)
57 /* total number of logical blocks present */
58 #define TOTAL_LOGICAL_ADDRESS_BLOCKS_NORMAL (48)
59 /* Net Disk Size , default disk is 48*512, that is 24kByte, however , the disk reconnised by that PC only has 4k Byte,
60  * This is caused by that the file system also need memory*/
61 #define DISK_SIZE_NORMAL (TOTAL_LOGICAL_ADDRESS_BLOCKS_NORMAL * LENGTH_OF_EACH_LBA)
62 
63 #define LOGICAL_UNIT_SUPPORTED (1U)
64 
65 #define USB_DEVICE_MSC_WRITE_BUFF_NUM 2
66 #define USB_DEVICE_MSC_WRITE_BUFF_SIZE 512
67 #define USB_DEVICE_MSC_READ_BUFF_SIZE 512
68 #define MSD_FLASH_BASE IMAGE_START_ADDRESS
69 
70 // Program Flash block information
71 #define P_FLASH_BASE 0x00000000
72 #define P_FLASH_SIZE (FSL_FEATURE_FLASH_PFLASH_BLOCK_SIZE * FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT)
73 #define P_BLOCK_NUM FSL_FEATURE_FLASH_PFLASH_BLOCK_COUNT
74 #define P_SECTOR_SIZE FSL_FEATURE_FLASH_PFLASH_BLOCK_SECTOR_SIZE
75 
76 typedef struct _usb_msc_struct
77 {
78  usb_device_handle deviceHandle;
79  class_handle_t mscHandle;
80  uint8_t storageDisk[DISK_SIZE_NORMAL];
81  uint8_t diskLock;
82  uint8_t read_write_error;
83  uint8_t currentConfiguration;
84  uint8_t currentInterfaceAlternateSetting[USB_MSC_INTERFACE_COUNT];
85  uint8_t speed;
86  uint8_t attach;
88 
89 extern flash_config_t s_flashInstance;
90 
91 /*******************************************************************************
92  * API
93  ******************************************************************************/
94 #if defined(__cplusplus)
95 extern "C" {
96 #endif /* __cplusplus */
97 
98 void disk_init(void);
99 
100 #if defined(__cplusplus)
101 }
102 #endif /* __cplusplus */
103 
104 #endif
Definition: msc_disk.h:185
Flash driver state information.
Definition: src/drivers/flash/fsl_flash.h:443