LPCOpen Platform  v1.03
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(__LPC175X_6X__) || defined(__LPC177X_8X__) || defined(__LPC407X_8X__)
33 
34 #include "../HAL.h"
35 #include "../../USBTask.h"
36 
37 void HAL_USBInit(uint8_t corenum)
38 {
39  /* Enable PLL1 for 48MHz output */
41 #if defined(__LPC175X_6X__)
42  while ((Chip_Clock_GetPLLStatus(SYSCTL_USB_PLL) & SYSCTL_PLL1STS_LOCKED) == 0);
43 #else
45 #endif
46 
47  Chip_IOCON_PinMux(LPC_IOCON, 0, 29, IOCON_MODE_INACT, IOCON_FUNC1); /* P0.29 D1+, P0.30 D1- */
49 
50  #if defined(USB_CAN_BE_HOST)
51  Chip_IOCON_PinMux(LPC_IOCON, 1, 19, IOCON_MODE_INACT, IOCON_FUNC2); /* USB_Power switch */
52 #endif
53 
54 #if defined(USB_CAN_BE_DEVICE)
55  Chip_IOCON_PinMux(LPC_IOCON, 2, 9, IOCON_MODE_INACT, IOCON_FUNC1); /* USB_SoftConnect */
56 #endif
57 
58  LPC_SYSCTL->PCONP |= (1UL << 31); /* USB PCLK -> enable USB Per.*/
59 
60 #if defined(USB_CAN_BE_DEVICE)
61  LPC_USB->USBClkCtrl = 0x12; /* Dev, PortSel, AHB clock enable */
62  while ((LPC_USB->USBClkSt & 0x12) != 0x12) ;
63 
64  HAL_Reset(corenum);
65 #endif
66 }
67 
68 void HAL_USBDeInit(uint8_t corenum, uint8_t mode)
69 {
70  NVIC_DisableIRQ(USB_IRQn); /* disable USB interrupt */
71  LPC_SYSCTL->PCONP &= (~(1UL << 31)); /* disable USB Per. */
72  Chip_IOCON_PinMux(LPC_IOCON, 0, 29, IOCON_MODE_INACT, IOCON_FUNC0); /* P0.29 D+, P0.30 D- reset to GPIO function */
74  /* Disable PLL1 to save power */
76 }
77 
78 void HAL_EnableUSBInterrupt(uint8_t corenum)
79 {
80  NVIC_EnableIRQ(USB_IRQn); /* enable USB interrupt */
81 }
82 
83 void HAL_DisableUSBInterrupt(uint8_t corenum)
84 {
85  NVIC_DisableIRQ(USB_IRQn); /* enable USB interrupt */
86 }
87 
88 void HAL_USBConnect(uint8_t corenum, uint32_t con)
89 {
90  if (USB_CurrentMode[corenum] == USB_MODE_Device) {
91 #if defined(USB_CAN_BE_DEVICE)
92  HAL17XX_USBConnect(con);
93 #endif
94  }
95 }
96 
97 // TODO moving stuff to approriate places
98 extern void DcdIrqHandler (uint8_t DeviceID);
99 
100 void USB_IRQHandler(void)
101 {
102  if (USB_CurrentMode[0] == USB_MODE_Host) {
103  #if defined(USB_CAN_BE_HOST)
104  HcdIrqHandler(0);
105  #endif
106  }
107 
108  if (USB_CurrentMode[0] == USB_MODE_Device) {
109  #if defined(USB_CAN_BE_DEVICE)
110  DcdIrqHandler(0);
111  #endif
112  }
113 }
114 
115 #endif /*__LPC17XX__ || __LPC40XX__*/