LPCOpen Platform
LPCOpen Platform for NXP LPC Microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
HAL_LPC17xx.c
Go to the documentation of this file.
1 /*
2  * @brief HAL USB functions for the LPC17xx microcontrollers
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 #if defined(__LPC17XX__) || defined(__LPC177X_8X__)
33 
34 #include "../HAL_LPC.h"
35 #include "../../../USBTask.h"
36 
37 void HAL_USBInit(uint8_t corenum)
38 {
39 #if defined(__LPC17XX__)
40  LPC_PINCON->PINSEL1 &= ~((3 << 26) | (3 << 28)); /* P0.29 D+, P0.30 D- */
41  LPC_PINCON->PINSEL1 |= ((1 << 26) | (1 << 28)); /* PINSEL1 26.27, 28.29 = 01 */
42 
43 #if defined(USB_CAN_BE_HOST)
44  LPC_PINCON->PINSEL3 &= ~(3 << 6);
45  LPC_PINCON->PINSEL3 |= (2 << 6);
46 #endif
47 
48 #elif defined(__LPC177X_8X__)
49 
50  LPC_IOCON->P0_29 &= ~0x07; /* P0.29 D1+, P0.30 D1- */
51  LPC_IOCON->P0_29 |= 0x1;
52  LPC_IOCON->P0_30 &= ~0x07;
53  LPC_IOCON->P0_30 |= 0x1;
54 #if defined(USB_CAN_BE_DEVICE)
55  LPC_IOCON->P2_9 &= ~0x07; /* USB_SoftConnect */
56  LPC_IOCON->P2_9 |= 0x1;
57 #endif
58 #if defined(USB_CAN_BE_HOST)
59  LPC_IOCON->P1_19 &= ~0x07; /* USB_Power switch */
60  LPC_IOCON->P1_19 |= 0x2;
61 #endif
62 
63 #endif
64 
65  LPC_SC->PCONP |= (1UL << 31); /* USB PCLK -> enable USB Per.*/
66 
67 #if defined(USB_CAN_BE_DEVICE)
68  LPC_USB->USBClkCtrl = 0x12; /* Dev, PortSel, AHB clock enable */
69  while ((LPC_USB->USBClkSt & 0x12) != 0x12) ;
70 
71  HAL_Reset();
72 #endif
73 }
74 
75 void HAL_USBDeInit(uint8_t corenum)
76 {
77  NVIC_DisableIRQ(USB_IRQn); /* disable USB interrupt */
78  LPC_SC->PCONP &= (~(1UL << 31)); /* disable USB Per. */
79 #if defined(__LPC17XX__)
80  LPC_PINCON->PINSEL1 &= ~((3 << 26) | (3 << 28)); /* P0.29 D+, P0.30 D- reset to GPIO function */
81 #elif defined(__LPC177X_8X__)
82  LPC_IOCON->P0_29 &= ~0x07; /* P0.29 D1+, P0.30 D1- reset to GPIO function */
83  LPC_IOCON->P0_30 &= ~0x07;
84 #endif
85 }
86 
87 void HAL_EnableUSBInterrupt(uint8_t corenum)
88 {
89  NVIC_EnableIRQ(USB_IRQn); /* enable USB interrupt */
90 }
91 
92 void HAL_DisableUSBInterrupt(uint8_t corenum)
93 {
94  NVIC_DisableIRQ(USB_IRQn); /* enable USB interrupt */
95 }
96 
97 void HAL_USBConnect(uint8_t corenum, uint32_t con)
98 {
100  #if defined(USB_CAN_BE_DEVICE)
101  HAL17XX_USBConnect(con);
102  #endif
103  }
104 }
105 
106 // TODO moving stuff to approriate places
107 extern void DcdIrqHandler (uint8_t DeviceID);
108 
109 void USB_IRQHandler(void)
110 {
112  #if defined(USB_CAN_BE_HOST)
113  HcdIrqHandler(0);
114  #endif
115  }
116 
118  #if defined(USB_CAN_BE_DEVICE)
119  DcdIrqHandler(0);
120  #endif
121  }
122 }
123 
124 #endif /*__LPC17XX__*/