| 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
MassStorage_ucosiii.c
Go to the documentation of this file.
1 /*
2 * @brief USB Mass Storage device task implementation module uCOS-III version
3 *
4 * Main source file for the MassStorage demo. This file contains the main tasks of
5 * the demo and is responsible for the initial application hardware configuration.
6 *
7 * @note
8 * Copyright(C) NXP Semiconductors, 2012
9 * All rights reserved.
10 *
11 * @par
12 * Software that is described herein is for illustrative purposes only
13 * which provides customers with programming information regarding the
14 * LPC products. This software is supplied "AS IS" without any warranties of
15 * any kind, and NXP Semiconductors and its licensor disclaim any and
16 * all warranties, express or implied, including all implied warranties of
17 * merchantability, fitness for a particular purpose and non-infringement of
18 * intellectual property rights. NXP Semiconductors assumes no responsibility
19 * or liability for the use of the software, conveys no license or rights under any
20 * patent, copyright, mask work right, or any other intellectual property rights in
21 * or to any products. NXP Semiconductors reserves the right to make changes
22 * in the software without notification. NXP Semiconductors also makes no
23 * representation or warranty that such application will be suitable for the
24 * specified use without further testing or modification.
25 *
26 * @par
27 * Permission to use, copy, modify, and distribute this software and its
28 * documentation is hereby granted, under NXP Semiconductors' and its
29 * licensor's relevant copyrights in the software, without fee, provided that it
30 * is used in conjunction with NXP Semiconductors microcontrollers. This
31 * copyright, permission, and disclaimer notice must appear in all copies of
32 * this code.
33 */
34
35 #include "lpc43xx_dualcore_config.h"
36 #include "MassStorage.h"
37
38 /* FreeRTOS headers */
39 #include "os.h"
40 #include "cpu.h"
41 #include "os_cfg_app.h"
42
43 /*****************************************************************************
44 * Private types/enumerations/variables
45 ****************************************************************************/
46 #define USBMSDEV_STACK_SZ (1024)
47 #define USBMSDEV_STACK_SZ_FULL 90u
48 #define USBMSDEV_STACK_SZ_LIMIT (USBMSDEV_STACK_SZ * (100u - USBMSDEV_STACK_SZ_FULL)) / 100u
49
50 static OS_TCB mem_tcb;
51 static CPU_STK mem_stack[USBMSDEV_STACK_SZ];
52
57 static USB_ClassInfo_MS_Device_t Disk_MS_Interface = {
58 .Config = {
59 .InterfaceNumber = 0,
60
61 .DataINEndpointNumber = MASS_STORAGE_IN_EPNUM,
62 .DataINEndpointSize = MASS_STORAGE_IO_EPSIZE,
63 .DataINEndpointDoubleBank = false,
64
65 .DataOUTEndpointNumber = MASS_STORAGE_OUT_EPNUM,
66 .DataOUTEndpointSize = MASS_STORAGE_IO_EPSIZE,
67 .DataOUTEndpointDoubleBank = false,
68
69 .TotalLUNs = TOTAL_LUNS,
70 },
71 };
72
76 static void usb_msdev_func(void)
77 {
78 MS_Device_USBTask(&Disk_MS_Interface);
79 USB_USBTask();
80 }
81
82 /* Task that waits for event from USB device, invokes the USBTask
83 * whenever it receives one
84 */
85 static void usb_msdev_task(void *arg)
86 {
87 OS_ERR ucErr;
88 CPU_TS ucos_timeout;
89
90 while (1) {
91 OSTaskSemPend(100, OS_OPT_PEND_BLOCKING, &ucos_timeout, &ucErr);
92 usb_msdev_func();
93 }
94 }
95
96 /*****************************************************************************
97 * Public types/enumerations/variables
98 ****************************************************************************/
99
100 /*****************************************************************************
101 * Private functions
102 ****************************************************************************/
103
104 /*****************************************************************************
105 * Public functions
106 ****************************************************************************/
107
108 /* Initialize USB device stack function */
109 void USBDEV_Init(void)
110 {
111 USB_Init();
112 NVIC_SetPriority(USB0_IRQn, IRQ_PRIO_USBDEV);
113 }
114
115 /* USB Device connect event callback function */
116 void EVENT_USB_Device_Connect(void)
117 {}
118
119 /* USB Device disconnect event callback function */
120 void EVENT_USB_Device_Disconnect(void)
121 {}
122
123 /* USB Device configuration change event callback function */
124 void EVENT_USB_Device_ConfigurationChanged(void)
125 {
126 bool ConfigSuccess = true;
127
128 ConfigSuccess &= MS_Device_ConfigureEndpoints(&Disk_MS_Interface);
129 }
130
131 /* USB Device control request receive event callback function */
132 void EVENT_USB_Device_ControlRequest(void)
133 {
134 MS_Device_ProcessControlRequest(&Disk_MS_Interface);
135 }
136
137 /* Mass Storage class driver callback function */
138 bool CALLBACK_MS_Device_SCSICommandReceived(USB_ClassInfo_MS_Device_t *const MSInterfaceInfo)
139 {
140 bool CommandSuccess;
141
142 CommandSuccess = SCSI_DecodeSCSICommand(MSInterfaceInfo);
143 return CommandSuccess;
144 }
145
157 void EVENT_USB_Device_TransferComplete(int logicalEP, int xfer_in)
158 {
159 OS_ERR ucErr;
160 OSTaskSemPost(&mem_tcb, OS_OPT_POST_NONE, &ucErr);
161 if (ucErr != OS_ERR_NONE) {
162 DEBUGSTR("OSTaskSemPost failure!\r\n");
163 //while (1);
164 }
165
166 }
167
168 /* uCOS-III USB device task */
169 void usb_device_tasks(void)
170 {
171 OS_ERR ret;
172
173 /* Start USB event Task */
174 OSTaskCreate (
175 &mem_tcb,
176 "USB Task",
177 usb_msdev_task,
178 (void *) 1,
179 TASK_PRIO_USBDEVICE,
180 mem_stack,
181 //USBMSDEV_STACK_SZ_LIMIT,
182 32,
183 USBMSDEV_STACK_SZ,
184 0,
185 0,
186 (void *)0,
187 (OS_OPT)(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
188 (OS_ERR *)&ret);
189 if (ret != OS_ERR_NONE) {
190 DEBUGSTR("Unable to create USB task!\r\n");
191 while (1);
192 }
193 }