mbed.h library with any bug fixes AV finds.

Dependents:   micromouse4_encoder_testing PID_Test Lab1_Test WorkingPID ... more

Committer:
aravindsv
Date:
Mon Nov 02 03:07:12 2015 +0000
Revision:
1:ebce2ad32f95
Parent:
0:ba7650f404af
Changed the RCC timeout value to 500 ms, so total code startup time before program starts running is ~1s. Hopefully no side-effects from lower startup timeouts

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aravindsv 0:ba7650f404af 1 /*******************************************************************************
aravindsv 0:ba7650f404af 2 * Copyright (C) 2015 Maxim Integrated Products, Inc., All Rights Reserved.
aravindsv 0:ba7650f404af 3 *
aravindsv 0:ba7650f404af 4 * Permission is hereby granted, free of charge, to any person obtaining a
aravindsv 0:ba7650f404af 5 * copy of this software and associated documentation files (the "Software"),
aravindsv 0:ba7650f404af 6 * to deal in the Software without restriction, including without limitation
aravindsv 0:ba7650f404af 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
aravindsv 0:ba7650f404af 8 * and/or sell copies of the Software, and to permit persons to whom the
aravindsv 0:ba7650f404af 9 * Software is furnished to do so, subject to the following conditions:
aravindsv 0:ba7650f404af 10 *
aravindsv 0:ba7650f404af 11 * The above copyright notice and this permission notice shall be included
aravindsv 0:ba7650f404af 12 * in all copies or substantial portions of the Software.
aravindsv 0:ba7650f404af 13 *
aravindsv 0:ba7650f404af 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
aravindsv 0:ba7650f404af 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
aravindsv 0:ba7650f404af 16 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
aravindsv 0:ba7650f404af 17 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES
aravindsv 0:ba7650f404af 18 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
aravindsv 0:ba7650f404af 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
aravindsv 0:ba7650f404af 20 * OTHER DEALINGS IN THE SOFTWARE.
aravindsv 0:ba7650f404af 21 *
aravindsv 0:ba7650f404af 22 * Except as contained in this notice, the name of Maxim Integrated
aravindsv 0:ba7650f404af 23 * Products, Inc. shall not be used except as stated in the Maxim Integrated
aravindsv 0:ba7650f404af 24 * Products, Inc. Branding Policy.
aravindsv 0:ba7650f404af 25 *
aravindsv 0:ba7650f404af 26 * The mere transfer of this software does not imply any licenses
aravindsv 0:ba7650f404af 27 * of trade secrets, proprietary technology, copyrights, patents,
aravindsv 0:ba7650f404af 28 * trademarks, maskwork rights, or any other form of intellectual
aravindsv 0:ba7650f404af 29 * property whatsoever. Maxim Integrated Products, Inc. retains all
aravindsv 0:ba7650f404af 30 * ownership rights.
aravindsv 0:ba7650f404af 31 *******************************************************************************
aravindsv 0:ba7650f404af 32 */
aravindsv 0:ba7650f404af 33
aravindsv 0:ba7650f404af 34 #include "mbed_assert.h"
aravindsv 0:ba7650f404af 35 #include "pinmap.h"
aravindsv 0:ba7650f404af 36 #include "objects.h"
aravindsv 0:ba7650f404af 37 #include "gpio_regs.h"
aravindsv 0:ba7650f404af 38 #include "ioman_regs.h"
aravindsv 0:ba7650f404af 39
aravindsv 0:ba7650f404af 40 void pin_function(PinName name, int function)
aravindsv 0:ba7650f404af 41 {
aravindsv 0:ba7650f404af 42 MBED_ASSERT(name != (PinName)NC);
aravindsv 0:ba7650f404af 43
aravindsv 0:ba7650f404af 44 if ((function >= 0) && (function <= 0xF)) {
aravindsv 0:ba7650f404af 45 unsigned int port = PINNAME_TO_PORT(name);
aravindsv 0:ba7650f404af 46 unsigned int pin = PINNAME_TO_PIN(name);
aravindsv 0:ba7650f404af 47 uint32_t temp = MXC_GPIO->func_sel[port] & ~(0xF << (pin*4));
aravindsv 0:ba7650f404af 48 MXC_GPIO->func_sel[port] = temp | ((uint32_t)function << (pin*4));
aravindsv 0:ba7650f404af 49 } else {
aravindsv 0:ba7650f404af 50 /* Assume this is a pointer to a pin function object */
aravindsv 0:ba7650f404af 51 pin_function_t *obj = (pin_function_t*)function;
aravindsv 0:ba7650f404af 52
aravindsv 0:ba7650f404af 53 if ((*obj->reg_ack & obj->ack_mask) != obj->req_val) {
aravindsv 0:ba7650f404af 54 /* Request pin mapping */
aravindsv 0:ba7650f404af 55 *obj->reg_req |= obj->req_val;
aravindsv 0:ba7650f404af 56
aravindsv 0:ba7650f404af 57 /* Check for acknowledgment */
aravindsv 0:ba7650f404af 58 MBED_ASSERT((*obj->reg_ack & obj->ack_mask) == obj->req_val);
aravindsv 0:ba7650f404af 59 }
aravindsv 0:ba7650f404af 60 }
aravindsv 0:ba7650f404af 61 }
aravindsv 0:ba7650f404af 62
aravindsv 0:ba7650f404af 63 void pin_mode(PinName name, PinMode mode)
aravindsv 0:ba7650f404af 64 {
aravindsv 0:ba7650f404af 65 MBED_ASSERT(name != (PinName)NC);
aravindsv 0:ba7650f404af 66 unsigned int port = PINNAME_TO_PORT(name);
aravindsv 0:ba7650f404af 67 unsigned int pin = PINNAME_TO_PIN(name);
aravindsv 0:ba7650f404af 68
aravindsv 0:ba7650f404af 69 /* Must set mode while retaining direction */
aravindsv 0:ba7650f404af 70
aravindsv 0:ba7650f404af 71 /* Get the current direction */
aravindsv 0:ba7650f404af 72 uint32_t out_mode = MXC_GPIO->out_mode[port];
aravindsv 0:ba7650f404af 73 uint32_t curr_mode = (out_mode >> (pin*4)) & 0xF;
aravindsv 0:ba7650f404af 74 PinDirection dir = PIN_OUTPUT;
aravindsv 0:ba7650f404af 75 if ((curr_mode == MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP) || (curr_mode == MXC_V_GPIO_OUT_MODE_HIGH_Z)) {
aravindsv 0:ba7650f404af 76 dir = PIN_INPUT;
aravindsv 0:ba7650f404af 77 }
aravindsv 0:ba7650f404af 78
aravindsv 0:ba7650f404af 79 /* Set mode based on current direction */
aravindsv 0:ba7650f404af 80 uint32_t new_mode;
aravindsv 0:ba7650f404af 81 if (dir == PIN_OUTPUT) {
aravindsv 0:ba7650f404af 82 // PullUp = not valid,
aravindsv 0:ba7650f404af 83 // OpenDrain = MXC_V_GPIO_OUT_MODE_OD,
aravindsv 0:ba7650f404af 84 // PullNone = MXC_V_GPIO_OUT_MODE_NORMAL,
aravindsv 0:ba7650f404af 85 if (mode == OpenDrain) {
aravindsv 0:ba7650f404af 86 new_mode = MXC_V_GPIO_OUT_MODE_OPEN_DRAIN;
aravindsv 0:ba7650f404af 87 } else {
aravindsv 0:ba7650f404af 88 new_mode = MXC_V_GPIO_OUT_MODE_NORMAL_DRIVE;
aravindsv 0:ba7650f404af 89 }
aravindsv 0:ba7650f404af 90 } else {
aravindsv 0:ba7650f404af 91 // PullUp = MXC_V_GPIO_OUT_MODE_HIZPU,
aravindsv 0:ba7650f404af 92 // OpenDrain = not valid,
aravindsv 0:ba7650f404af 93 // PullNone = MXC_V_GPIO_OUT_MODE_HIZ,
aravindsv 0:ba7650f404af 94 if (mode == PullUp) {
aravindsv 0:ba7650f404af 95 new_mode = MXC_V_GPIO_OUT_MODE_HIGH_Z_WEAK_PULLUP;
aravindsv 0:ba7650f404af 96 } else {
aravindsv 0:ba7650f404af 97 new_mode = MXC_V_GPIO_OUT_MODE_HIGH_Z;
aravindsv 0:ba7650f404af 98 }
aravindsv 0:ba7650f404af 99 }
aravindsv 0:ba7650f404af 100
aravindsv 0:ba7650f404af 101 /* Set new mode */
aravindsv 0:ba7650f404af 102 out_mode &= ~(0xF << (pin*4));
aravindsv 0:ba7650f404af 103 out_mode |= (new_mode << (pin*4));
aravindsv 0:ba7650f404af 104 MXC_GPIO->out_mode[port] = out_mode;
aravindsv 0:ba7650f404af 105 }