LPCOpen Platform
v1.03
LPCOpen Platform for NXP LPC Microcontrollers
Main Page
Modules
Data Structures
Files
Related Pages
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Groups
Pages
fs_usb.c
Go to the documentation of this file.
1
/*
2
* @brief USB Mass Storage Chan FATFS simple abstraction layer
3
*
4
* @note
5
* Copyright(C) NXP Semiconductors, 2012
6
* All rights reserved.
7
*
8
* @par
9
* Software that is described herein is for illustrative purposes only
10
* which provides customers with programming information regarding the
11
* LPC products. This software is supplied "AS IS" without any warranties of
12
* any kind, and NXP Semiconductors and its licensor disclaim any and
13
* all warranties, express or implied, including all implied warranties of
14
* merchantability, fitness for a particular purpose and non-infringement of
15
* intellectual property rights. NXP Semiconductors assumes no responsibility
16
* or liability for the use of the software, conveys no license or rights under any
17
* patent, copyright, mask work right, or any other intellectual property rights in
18
* or to any products. NXP Semiconductors reserves the right to make changes
19
* in the software without notification. NXP Semiconductors also makes no
20
* representation or warranty that such application will be suitable for the
21
* specified use without further testing or modification.
22
*
23
* @par
24
* Permission to use, copy, modify, and distribute this software and its
25
* documentation is hereby granted, under NXP Semiconductors' and its
26
* licensor's relevant copyrights in the software, without fee, provided that it
27
* is used in conjunction with NXP Semiconductors microcontrollers. This
28
* copyright, permission, and disclaimer notice must appear in all copies of
29
* this code.
30
*/
31
32
#include "
fsusb_cfg.h
"
33
#include "board.h"
34
#include "chip.h"
35
36
/*****************************************************************************
37
* Private types/enumerations/variables
38
****************************************************************************/
39
40
/* Disk Status */
41
static
volatile
DSTATUS
Stat
=
STA_NOINIT
;
42
43
/* 100Hz decrement timer stopped at zero (disk_timerproc()) */
44
static
volatile
WORD
Timer2
;
45
46
static
DISK_HANDLE_T
*
hDisk
;
47
48
/*****************************************************************************
49
* Public types/enumerations/variables
50
****************************************************************************/
51
52
/*****************************************************************************
53
* Private functions
54
****************************************************************************/
55
56
/*****************************************************************************
57
* Public functions
58
****************************************************************************/
59
60
/* Initialize Disk Drive */
61
DSTATUS
disk_initialize
(
BYTE
drv)
62
{
63
if
(drv) {
64
return
STA_NOINIT
;
/* Supports only single drive */
65
}
66
/* if (Stat & STA_NODISK) return Stat; */
/* No card in the socket */
67
68
if
(
Stat
!=
STA_NOINIT
) {
69
return
Stat
;
/* card is already enumerated */
70
71
}
72
73
#if !_FS_READONLY
74
FSUSB_InitRealTimeClock
();
75
#endif
76
77
/* Initialize the Card Data Strucutre */
78
hDisk =
FSUSB_DiskInit
();
79
80
/* Reset */
81
Stat
=
STA_NOINIT
;
82
83
FSUSB_DiskInsertWait
(hDisk);
/* Wait for card to be inserted */
84
85
/* Enumerate the card once detected. Note this function may block for a little while. */
86
if
(!
FSUSB_DiskAcquire
(hDisk)) {
87
DEBUGOUT
(
"Disk Enumeration failed...\r\n"
);
88
return
Stat
;
89
}
90
91
Stat
&= ~
STA_NOINIT
;
92
return
Stat
;
93
94
}
95
96
/* Disk Drive miscellaneous Functions */
97
DRESULT
disk_ioctl
(
BYTE
drv,
BYTE
ctrl,
void
*buff)
98
{
99
DRESULT
res;
100
101
if
(drv) {
102
return
RES_PARERR
;
103
}
104
if
(
Stat
&
STA_NOINIT
) {
105
return
RES_NOTRDY
;
106
}
107
108
res =
RES_ERROR
;
109
110
switch
(ctrl) {
111
case
CTRL_SYNC
:
/* Make sure that no pending write process */
112
if
(
FSUSB_DiskReadyWait
(hDisk, 50)) {
113
res =
RES_OK
;
114
}
115
break
;
116
117
case
GET_SECTOR_COUNT
:
/* Get number of sectors on the disk (DWORD) */
118
*(
DWORD
*) buff =
FSUSB_DiskGetSectorCnt
(hDisk);
119
res =
RES_OK
;
120
break
;
121
122
case
GET_SECTOR_SIZE
:
/* Get R/W sector size (WORD) */
123
*(
WORD
*) buff =
FSUSB_DiskGetSectorSz
(hDisk);
124
res =
RES_OK
;
125
break
;
126
127
case
GET_BLOCK_SIZE
:
/* Get erase block size in unit of sector (DWORD) */
128
*(
DWORD
*) buff =
FSUSB_DiskGetBlockSz
(hDisk);
129
res =
RES_OK
;
130
break
;
131
132
default
:
133
res =
RES_PARERR
;
134
break
;
135
}
136
137
return
res;
138
}
139
140
/* Read Sector(s) */
141
DRESULT
disk_read
(
BYTE
drv,
BYTE
*buff,
DWORD
sector,
BYTE
count)
142
{
143
if
(drv || !count) {
144
return
RES_PARERR
;
145
}
146
if
(
Stat
&
STA_NOINIT
) {
147
return
RES_NOTRDY
;
148
}
149
150
if
(
FSUSB_DiskReadSectors
(hDisk, buff, sector, count)) {
151
return
RES_OK
;
152
}
153
154
return
RES_ERROR
;
155
}
156
157
/* Get Disk Status */
158
DSTATUS
disk_status
(
BYTE
drv)
159
{
160
if
(drv) {
161
return
STA_NOINIT
;
/* Supports only single drive */
162
}
163
return
Stat
;
164
}
165
166
/* Write Sector(s) */
167
DRESULT
disk_write
(
BYTE
drv,
const
BYTE
*buff,
DWORD
sector,
BYTE
count)
168
{
169
170
if
(drv || !count) {
171
return
RES_PARERR
;
172
}
173
if
(
Stat
&
STA_NOINIT
) {
174
return
RES_NOTRDY
;
175
}
176
177
if
(
FSUSB_DiskWriteSectors
(hDisk, (
void
*) buff, sector, count)) {
178
return
RES_OK
;
179
}
180
181
return
RES_ERROR
;
182
}
software
filesystems
fatfslpc
fs_usb.c
Generated on Fri May 10 2013 10:42:10 for LPCOpen Platform by
1.8.2