LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
MassStorage_freertos.c
Go to the documentation of this file.
1 /*
2  * @brief USB Mass Storage device task implementation module FreeRTOS 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 "MassStorage_freertos.h"
36 
37 /*****************************************************************************
38  * Private types/enumerations/variables
39  ****************************************************************************/
40 
46  .Config = {
47  .InterfaceNumber = 0,
48 
49  .DataINEndpointNumber = MASS_STORAGE_IN_EPNUM,
50  .DataINEndpointSize = MASS_STORAGE_IO_EPSIZE,
51  .DataINEndpointDoubleBank = false,
52 
53  .DataOUTEndpointNumber = MASS_STORAGE_OUT_EPNUM,
54  .DataOUTEndpointSize = MASS_STORAGE_IO_EPSIZE,
55  .DataOUTEndpointDoubleBank = false,
56 
57  .TotalLUNs = TOTAL_LUNS,
58  },
59 };
60 
61 static xSemaphoreHandle usb_dev_event;
62 
66 static void usb_msdev_func(void)
67 {
68  MS_Device_USBTask(&Disk_MS_Interface);
69  USB_USBTask();
70 }
71 
72 /* Task that waits for event from USB device, invokes the USBTask
73  * whenever it receives one
74  */
75 static void usb_msdev_task(void *arg)
76 {
77  vSemaphoreCreateBinary(usb_dev_event);
78  if (usb_dev_event == NULL) {
79  DEBUGSTR("Unable to create semaphore!\r\n");
80  while (1) ;
81  }
82  while (1) {
83  xSemaphoreTake(usb_dev_event, 100);
85  }
86 }
87 
88 /*****************************************************************************
89  * Public types/enumerations/variables
90  ****************************************************************************/
91 
92 /*****************************************************************************
93  * Private functions
94  ****************************************************************************/
95 
96 /*****************************************************************************
97  * Public functions
98  ****************************************************************************/
99 
100 /* Initialize USB device stack function */
101 void USBDEV_Init(void)
102 {
103  USB_Init();
104  NVIC_SetPriority(USB0_IRQn, IRQ_PRIO_USBDEV);
105 }
106 
107 /* USB Device connect event callback function */
109 {}
110 
111 /* USB Device disconnect event callback function */
113 {}
114 
115 /* USB Device configuration change event callback function */
117 {
118  bool ConfigSuccess = true;
119 
120  ConfigSuccess &= MS_Device_ConfigureEndpoints(&Disk_MS_Interface);
121 }
122 
123 /* USB Device control request receive event callback function */
125 {
126  MS_Device_ProcessControlRequest(&Disk_MS_Interface);
127 }
128 
129 /* Mass Storage class driver callback function */
131 {
132  bool CommandSuccess;
133 
134  CommandSuccess = SCSI_DecodeSCSICommand(MSInterfaceInfo);
135  return CommandSuccess;
136 }
137 
149 void EVENT_USB_Device_TransferComplete(int logicalEP, int xfer_in)
150 {
151  portBASE_TYPE wake = pdFALSE;
152  if (usb_dev_event) {
153  xSemaphoreGiveFromISR(usb_dev_event, &wake);
154  }
155  portEND_SWITCHING_ISR(wake);
156 }
157 
158 /* FreeRTOS USB device task */
160 {
161  /* Start Blinky event Task */
162  xTaskCreate(usb_msdev_task, (signed char *) "USB Task",
164  (xTaskHandle *) NULL);
165 }