Rewrite from scratch a TCP/IP stack for mbed. So far the following parts are usable: Drivers: - EMAC driver (from CMSIS 2.0) Protocols: - Ethernet protocol - ARP over ethernet for IPv4 - IPv4 over Ethernet - ICMPv4 over IPv4 - UDPv4 over IPv4 APIs: - Sockets for UDPv4 The structure of this stack is designed to be very modular. Each protocol can register one or more protocol to handle its payload, and in each protocol, an API can be hooked (like Sockets for example). This is an early release.
lpc17xx_pinsel.cpp
00001 /* @cond */ 00002 /***********************************************************************//** 00003 * @file lpc17xx_pinsel.c 00004 * @brief Contains all functions support for Pin connect block firmware 00005 * library on LPC17xx 00006 * @version 2.0 00007 * @date 21. May. 2010 00008 * @author NXP MCU SW Application Team 00009 ************************************************************************** 00010 * Software that is described herein is for illustrative purposes only 00011 * which provides customers with programming information regarding the 00012 * products. This software is supplied "AS IS" without any warranties. 00013 * NXP Semiconductors assumes no responsibility or liability for the 00014 * use of the software, conveys no license or title under any patent, 00015 * copyright, or mask work right to the product. NXP Semiconductors 00016 * reserves the right to make changes in the software without 00017 * notification. NXP Semiconductors also make no representation or 00018 * warranty that such application will be suitable for the specified 00019 * use without further testing or modification. 00020 **********************************************************************/ 00021 00022 /* Peripheral group ----------------------------------------------------------- */ 00023 /** @addtogroup PINSEL 00024 * @{ 00025 */ 00026 00027 /* Includes ------------------------------------------------------------------- */ 00028 #include "lpc17xx_pinsel.h" 00029 00030 /* Public Functions ----------------------------------------------------------- */ 00031 00032 static void set_PinFunc ( uint8_t portnum, uint8_t pinnum, uint8_t funcnum); 00033 static void set_ResistorMode ( uint8_t portnum, uint8_t pinnum, uint8_t modenum); 00034 static void set_OpenDrainMode( uint8_t portnum, uint8_t pinnum, uint8_t modenum); 00035 00036 /*********************************************************************//** 00037 * @brief Setup the pin selection function 00038 * @param[in] portnum PORT number, 00039 * should be one of the following: 00040 * - PINSEL_PORT_0 : Port 0 00041 * - PINSEL_PORT_1 : Port 1 00042 * - PINSEL_PORT_2 : Port 2 00043 * - PINSEL_PORT_3 : Port 3 00044 * 00045 * @param[in] pinnum Pin number, 00046 * should be one of the following: 00047 - PINSEL_PIN_0 : Pin 0 00048 - PINSEL_PIN_1 : Pin 1 00049 - PINSEL_PIN_2 : Pin 2 00050 - PINSEL_PIN_3 : Pin 3 00051 - PINSEL_PIN_4 : Pin 4 00052 - PINSEL_PIN_5 : Pin 5 00053 - PINSEL_PIN_6 : Pin 6 00054 - PINSEL_PIN_7 : Pin 7 00055 - PINSEL_PIN_8 : Pin 8 00056 - PINSEL_PIN_9 : Pin 9 00057 - PINSEL_PIN_10 : Pin 10 00058 - PINSEL_PIN_11 : Pin 11 00059 - PINSEL_PIN_12 : Pin 12 00060 - PINSEL_PIN_13 : Pin 13 00061 - PINSEL_PIN_14 : Pin 14 00062 - PINSEL_PIN_15 : Pin 15 00063 - PINSEL_PIN_16 : Pin 16 00064 - PINSEL_PIN_17 : Pin 17 00065 - PINSEL_PIN_18 : Pin 18 00066 - PINSEL_PIN_19 : Pin 19 00067 - PINSEL_PIN_20 : Pin 20 00068 - PINSEL_PIN_21 : Pin 21 00069 - PINSEL_PIN_22 : Pin 22 00070 - PINSEL_PIN_23 : Pin 23 00071 - PINSEL_PIN_24 : Pin 24 00072 - PINSEL_PIN_25 : Pin 25 00073 - PINSEL_PIN_26 : Pin 26 00074 - PINSEL_PIN_27 : Pin 27 00075 - PINSEL_PIN_28 : Pin 28 00076 - PINSEL_PIN_29 : Pin 29 00077 - PINSEL_PIN_30 : Pin 30 00078 - PINSEL_PIN_31 : Pin 31 00079 00080 * @param[in] funcnum Function number, 00081 * should be one of the following: 00082 * - PINSEL_FUNC_0 : default function 00083 * - PINSEL_FUNC_1 : first alternate function 00084 * - PINSEL_FUNC_2 : second alternate function 00085 * - PINSEL_FUNC_3 : third alternate function 00086 * 00087 * @return None 00088 **********************************************************************/ 00089 static void set_PinFunc ( uint8_t portnum, uint8_t pinnum, uint8_t funcnum) 00090 { 00091 uint32_t pinnum_t = pinnum; 00092 uint32_t pinselreg_idx = 2 * portnum; 00093 uint32_t *pPinCon = (uint32_t *)&LPC_PINCON->PINSEL0; 00094 00095 if (pinnum_t >= 16) { 00096 pinnum_t -= 16; 00097 pinselreg_idx++; 00098 } 00099 *(uint32_t *)(pPinCon + pinselreg_idx) &= ~(0x03UL << (pinnum_t * 2)); 00100 *(uint32_t *)(pPinCon + pinselreg_idx) |= ((uint32_t)funcnum) << (pinnum_t * 2); 00101 } 00102 00103 /*********************************************************************//** 00104 * @brief Setup resistor mode for each pin 00105 * @param[in] portnum PORT number, 00106 * should be one of the following: 00107 * - PINSEL_PORT_0 : Port 0 00108 * - PINSEL_PORT_1 : Port 1 00109 * - PINSEL_PORT_2 : Port 2 00110 * - PINSEL_PORT_3 : Port 3 00111 * @param[in] pinnum Pin number, 00112 * should be one of the following: 00113 - PINSEL_PIN_0 : Pin 0 00114 - PINSEL_PIN_1 : Pin 1 00115 - PINSEL_PIN_2 : Pin 2 00116 - PINSEL_PIN_3 : Pin 3 00117 - PINSEL_PIN_4 : Pin 4 00118 - PINSEL_PIN_5 : Pin 5 00119 - PINSEL_PIN_6 : Pin 6 00120 - PINSEL_PIN_7 : Pin 7 00121 - PINSEL_PIN_8 : Pin 8 00122 - PINSEL_PIN_9 : Pin 9 00123 - PINSEL_PIN_10 : Pin 10 00124 - PINSEL_PIN_11 : Pin 11 00125 - PINSEL_PIN_12 : Pin 12 00126 - PINSEL_PIN_13 : Pin 13 00127 - PINSEL_PIN_14 : Pin 14 00128 - PINSEL_PIN_15 : Pin 15 00129 - PINSEL_PIN_16 : Pin 16 00130 - PINSEL_PIN_17 : Pin 17 00131 - PINSEL_PIN_18 : Pin 18 00132 - PINSEL_PIN_19 : Pin 19 00133 - PINSEL_PIN_20 : Pin 20 00134 - PINSEL_PIN_21 : Pin 21 00135 - PINSEL_PIN_22 : Pin 22 00136 - PINSEL_PIN_23 : Pin 23 00137 - PINSEL_PIN_24 : Pin 24 00138 - PINSEL_PIN_25 : Pin 25 00139 - PINSEL_PIN_26 : Pin 26 00140 - PINSEL_PIN_27 : Pin 27 00141 - PINSEL_PIN_28 : Pin 28 00142 - PINSEL_PIN_29 : Pin 29 00143 - PINSEL_PIN_30 : Pin 30 00144 - PINSEL_PIN_31 : Pin 31 00145 00146 * @param[in] modenum: Mode number, 00147 * should be one of the following: 00148 - PINSEL_PINMODE_PULLUP : Internal pull-up resistor 00149 - PINSEL_PINMODE_TRISTATE : Tri-state 00150 - PINSEL_PINMODE_PULLDOWN : Internal pull-down resistor 00151 00152 * @return None 00153 **********************************************************************/ 00154 void set_ResistorMode ( uint8_t portnum, uint8_t pinnum, uint8_t modenum) 00155 { 00156 uint32_t pinnum_t = pinnum; 00157 uint32_t pinmodereg_idx = 2 * portnum; 00158 uint32_t *pPinCon = (uint32_t *)&LPC_PINCON->PINMODE0; 00159 00160 if (pinnum_t >= 16) { 00161 pinnum_t -= 16; 00162 pinmodereg_idx++ ; 00163 } 00164 00165 *(uint32_t *)(pPinCon + pinmodereg_idx) &= ~(0x03UL << (pinnum_t * 2)); 00166 *(uint32_t *)(pPinCon + pinmodereg_idx) |= ((uint32_t)modenum) << (pinnum_t * 2); 00167 } 00168 00169 /*********************************************************************//** 00170 * @brief Setup Open drain mode for each pin 00171 * @param[in] portnum PORT number, 00172 * should be one of the following: 00173 * - PINSEL_PORT_0 : Port 0 00174 * - PINSEL_PORT_1 : Port 1 00175 * - PINSEL_PORT_2 : Port 2 00176 * - PINSEL_PORT_3 : Port 3 00177 * 00178 * @param[in] pinnum Pin number, 00179 * should be one of the following: 00180 - PINSEL_PIN_0 : Pin 0 00181 - PINSEL_PIN_1 : Pin 1 00182 - PINSEL_PIN_2 : Pin 2 00183 - PINSEL_PIN_3 : Pin 3 00184 - PINSEL_PIN_4 : Pin 4 00185 - PINSEL_PIN_5 : Pin 5 00186 - PINSEL_PIN_6 : Pin 6 00187 - PINSEL_PIN_7 : Pin 7 00188 - PINSEL_PIN_8 : Pin 8 00189 - PINSEL_PIN_9 : Pin 9 00190 - PINSEL_PIN_10 : Pin 10 00191 - PINSEL_PIN_11 : Pin 11 00192 - PINSEL_PIN_12 : Pin 12 00193 - PINSEL_PIN_13 : Pin 13 00194 - PINSEL_PIN_14 : Pin 14 00195 - PINSEL_PIN_15 : Pin 15 00196 - PINSEL_PIN_16 : Pin 16 00197 - PINSEL_PIN_17 : Pin 17 00198 - PINSEL_PIN_18 : Pin 18 00199 - PINSEL_PIN_19 : Pin 19 00200 - PINSEL_PIN_20 : Pin 20 00201 - PINSEL_PIN_21 : Pin 21 00202 - PINSEL_PIN_22 : Pin 22 00203 - PINSEL_PIN_23 : Pin 23 00204 - PINSEL_PIN_24 : Pin 24 00205 - PINSEL_PIN_25 : Pin 25 00206 - PINSEL_PIN_26 : Pin 26 00207 - PINSEL_PIN_27 : Pin 27 00208 - PINSEL_PIN_28 : Pin 28 00209 - PINSEL_PIN_29 : Pin 29 00210 - PINSEL_PIN_30 : Pin 30 00211 - PINSEL_PIN_31 : Pin 31 00212 00213 * @param[in] modenum Open drain mode number, 00214 * should be one of the following: 00215 * - PINSEL_PINMODE_NORMAL : Pin is in the normal (not open drain) mode 00216 * - PINSEL_PINMODE_OPENDRAIN : Pin is in the open drain mode 00217 * 00218 * @return None 00219 **********************************************************************/ 00220 void set_OpenDrainMode( uint8_t portnum, uint8_t pinnum, uint8_t modenum) 00221 { 00222 uint32_t *pPinCon = (uint32_t *)&LPC_PINCON->PINMODE_OD0; 00223 00224 if (modenum == PINSEL_PINMODE_OPENDRAIN){ 00225 *(uint32_t *)(pPinCon + portnum) |= (0x01UL << pinnum); 00226 } else { 00227 *(uint32_t *)(pPinCon + portnum) &= ~(0x01UL << pinnum); 00228 } 00229 } 00230 00231 /* End of Public Functions ---------------------------------------------------- */ 00232 00233 /* Public Functions ----------------------------------------------------------- */ 00234 /** @addtogroup PINSEL_Public_Functions 00235 * @{ 00236 */ 00237 /*********************************************************************//** 00238 * @brief Configure trace function 00239 * @param[in] NewState State of the Trace function configuration, 00240 * should be one of the following: 00241 * - ENABLE : Enable Trace Function 00242 * - DISABLE : Disable Trace Function 00243 * 00244 * @return None 00245 **********************************************************************/ 00246 void PINSEL_ConfigTraceFunc(FunctionalState NewState) 00247 { 00248 if (NewState == ENABLE) { 00249 LPC_PINCON->PINSEL10 |= (0x01UL << 3); 00250 } else if (NewState == DISABLE) { 00251 LPC_PINCON->PINSEL10 &= ~(0x01UL << 3); 00252 } 00253 } 00254 00255 /*********************************************************************//** 00256 * @brief Setup I2C0 pins 00257 * @param[in] i2cPinMode I2C pin mode, 00258 * should be one of the following: 00259 * - PINSEL_I2C_Normal_Mode : The standard drive mode 00260 * - PINSEL_I2C_Fast_Mode : Fast Mode Plus drive mode 00261 * 00262 * @param[in] filterSlewRateEnable should be: 00263 * - ENABLE: Enable filter and slew rate. 00264 * - DISABLE: Disable filter and slew rate. 00265 * 00266 * @return None 00267 **********************************************************************/ 00268 void PINSEL_SetI2C0Pins(uint8_t i2cPinMode, FunctionalState filterSlewRateEnable) 00269 { 00270 uint32_t regVal = 0; 00271 00272 if (i2cPinMode == PINSEL_I2C_Fast_Mode){ 00273 regVal = PINSEL_I2CPADCFG_SCLDRV0 | PINSEL_I2CPADCFG_SDADRV0; 00274 } 00275 00276 if (filterSlewRateEnable == DISABLE){ 00277 regVal = PINSEL_I2CPADCFG_SCLI2C0 | PINSEL_I2CPADCFG_SDAI2C0; 00278 } 00279 LPC_PINCON->I2CPADCFG = regVal; 00280 } 00281 00282 00283 /*********************************************************************//** 00284 * @brief Configure Pin corresponding to specified parameters passed 00285 * in the PinCfg 00286 * @param[in] PinCfg Pointer to a PINSEL_CFG_Type structure 00287 * that contains the configuration information for the 00288 * specified pin. 00289 * @return None 00290 **********************************************************************/ 00291 void PINSEL_ConfigPin(PINSEL_CFG_Type *PinCfg) 00292 { 00293 set_PinFunc(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->Funcnum); 00294 set_ResistorMode(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->Pinmode); 00295 set_OpenDrainMode(PinCfg->Portnum, PinCfg->Pinnum, PinCfg->OpenDrain); 00296 } 00297 00298 00299 /** 00300 * @} 00301 */ 00302 00303 /** 00304 * @} 00305 */ 00306 00307 /* --------------------------------- End Of File ------------------------------ */ 00308 /* @endcond */
Generated on Wed Jul 13 2022 06:09:33 by 1.7.2