mbed-os

Fork of mbed-os by erkin yucel

Committer:
elessair
Date:
Sun Oct 23 15:10:02 2016 +0000
Revision:
0:f269e3021894
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
elessair 0:f269e3021894 1 #ifdef REVD
elessair 0:f269e3021894 2 /**
elessair 0:f269e3021894 3 ******************************************************************************
elessair 0:f269e3021894 4 * @file pad.c
elessair 0:f269e3021894 5 * @brief PAD management support code
elessair 0:f269e3021894 6 * @internal
elessair 0:f269e3021894 7 * @author ON Semiconductor
elessair 0:f269e3021894 8 * $Rev: 2848 $
elessair 0:f269e3021894 9 * $Date: 2014-04-01 22:48:18 +0530 (Tue, 01 Apr 2014) $
elessair 0:f269e3021894 10 ******************************************************************************
elessair 0:f269e3021894 11 * Copyright 2016 Semiconductor Components Industries LLC (d/b/a “ON Semiconductor”).
elessair 0:f269e3021894 12 * All rights reserved. This software and/or documentation is licensed by ON Semiconductor
elessair 0:f269e3021894 13 * under limited terms and conditions. The terms and conditions pertaining to the software
elessair 0:f269e3021894 14 * and/or documentation are available at http://www.onsemi.com/site/pdf/ONSEMI_T&C.pdf
elessair 0:f269e3021894 15 * (“ON Semiconductor Standard Terms and Conditions of Sale, Section 8 Software”) and
elessair 0:f269e3021894 16 * if applicable the software license agreement. Do not use this software and/or
elessair 0:f269e3021894 17 * documentation unless you have carefully read and you agree to the limited terms and
elessair 0:f269e3021894 18 * conditions. By using this software and/or documentation, you agree to the limited
elessair 0:f269e3021894 19 * terms and conditions.
elessair 0:f269e3021894 20 *
elessair 0:f269e3021894 21 * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
elessair 0:f269e3021894 22 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
elessair 0:f269e3021894 23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
elessair 0:f269e3021894 24 * ON SEMICONDUCTOR SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL,
elessair 0:f269e3021894 25 * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
elessair 0:f269e3021894 26 * @endinternal
elessair 0:f269e3021894 27 *
elessair 0:f269e3021894 28 * @ingroup pad
elessair 0:f269e3021894 29 *
elessair 0:f269e3021894 30 * @details
elessair 0:f269e3021894 31 */
elessair 0:f269e3021894 32
elessair 0:f269e3021894 33 /*************************************************************************************************
elessair 0:f269e3021894 34 * *
elessair 0:f269e3021894 35 * Header files *
elessair 0:f269e3021894 36 * *
elessair 0:f269e3021894 37 *************************************************************************************************/
elessair 0:f269e3021894 38
elessair 0:f269e3021894 39 #include "memory_map.h"
elessair 0:f269e3021894 40 #include "pad_map.h"
elessair 0:f269e3021894 41 #include "clock.h"
elessair 0:f269e3021894 42
elessair 0:f269e3021894 43 /*************************************************************************************************
elessair 0:f269e3021894 44 * *
elessair 0:f269e3021894 45 * Symbolic Constants *
elessair 0:f269e3021894 46 * *
elessair 0:f269e3021894 47 *************************************************************************************************/
elessair 0:f269e3021894 48 #define PAD_CTRL_OP_DRIVE_STRENGTH_MASK (uint32_t)0x1C
elessair 0:f269e3021894 49 #define PAD_NUM_OF_IO 17
elessair 0:f269e3021894 50 #define PAD_OP_DRIVE_STRGTH_MAX 7
elessair 0:f269e3021894 51 #define PAD_OP_DRIVE_TYPE_MAX 1
elessair 0:f269e3021894 52 #define PAD_OP_PULL_TYPE_MAX 3
elessair 0:f269e3021894 53
elessair 0:f269e3021894 54 #define PAD_REG_ADRS_BYTE_SIZE 4
elessair 0:f269e3021894 55
elessair 0:f269e3021894 56 #define PAD_OP_DRIVE_STRGTH_BIT_POS 2
elessair 0:f269e3021894 57 #define PAD_OP_DRIVE_TYPE_BIT_POS 5
elessair 0:f269e3021894 58 #define PAD_OP_PULL_TYPE_BIT_POS 0
elessair 0:f269e3021894 59
elessair 0:f269e3021894 60 /*************************************************************************************************
elessair 0:f269e3021894 61 * *
elessair 0:f269e3021894 62 * Global variables *
elessair 0:f269e3021894 63 * *
elessair 0:f269e3021894 64 *************************************************************************************************/
elessair 0:f269e3021894 65
elessair 0:f269e3021894 66 /* Peripheral PAD register mutex */
elessair 0:f269e3021894 67 /* sem_pt GlobMutexPadReg; */
elessair 0:f269e3021894 68
elessair 0:f269e3021894 69 /*************************************************************************************************
elessair 0:f269e3021894 70 * *
elessair 0:f269e3021894 71 * Functions *
elessair 0:f269e3021894 72 * *
elessair 0:f269e3021894 73 *************************************************************************************************/
elessair 0:f269e3021894 74
elessair 0:f269e3021894 75 /** Find description at pad.h */
elessair 0:f269e3021894 76 void fPadInit()
elessair 0:f269e3021894 77 {
elessair 0:f269e3021894 78 /** - Enable the clock for PAD peripheral device */
elessair 0:f269e3021894 79 CLOCK_ENABLE(CLOCK_PAD);
elessair 0:f269e3021894 80
elessair 0:f269e3021894 81 /** - Set pad parameters, output drive strength, pull piece control, output drive type */
elessair 0:f269e3021894 82 PADREG->PADIO0.WORD = PAD_OUTPUT_PN_L1_OD; /* UART1 TXD */
elessair 0:f269e3021894 83 PADREG->PADIO1.WORD = PAD_INPUT_PD_L1_PP; /* UART1 RXD */
elessair 0:f269e3021894 84 PADREG->PADIO2.WORD = PAD_INPUT_PD_L1_PP; /* UART1 CTS */
elessair 0:f269e3021894 85 PADREG->PADIO3.WORD = PAD_OUTPUT_PN_L1_OD; /* UART1 RTS */
elessair 0:f269e3021894 86 PADREG->PADIO4.WORD = PAD_UNUSED_PD_L0_PP;
elessair 0:f269e3021894 87 PADREG->PADIO5.WORD = PAD_UNUSED_PD_L0_PP;
elessair 0:f269e3021894 88 PADREG->PADIO6.WORD = PAD_UNUSED_PD_L0_PP;
elessair 0:f269e3021894 89 PADREG->PADIO7.WORD = PAD_UNUSED_PD_L0_PP;
elessair 0:f269e3021894 90 PADREG->PADIO8.WORD = PAD_OUTPUT_PN_L1_OD; /* UART2 TXD */
elessair 0:f269e3021894 91 PADREG->PADIO9.WORD = PAD_INPUT_PD_L1_PP; /* UART2 RXD */
elessair 0:f269e3021894 92 PADREG->PADIO10.WORD = PAD_UNUSED_PD_L0_PP;
elessair 0:f269e3021894 93 PADREG->PADIO11.WORD = PAD_INPUT_PD_L1_PP; /* SWO */
elessair 0:f269e3021894 94 PADREG->PADIO12.WORD = PAD_INPUT_PD_L1_PP; /* SWCLK */
elessair 0:f269e3021894 95 PADREG->PADIO13.WORD = PAD_INPUT_PD_L1_PP; /* SWDIO */
elessair 0:f269e3021894 96 PADREG->PADIO14.WORD = PAD_INPUT_PD_L1_PP;
elessair 0:f269e3021894 97 PADREG->PADIO15.WORD = PAD_UNUSED_PD_L0_PP;
elessair 0:f269e3021894 98 PADREG->PADIO16.WORD = PAD_UNUSED_PD_L0_PP;
elessair 0:f269e3021894 99 PADREG->PADIO17.WORD = PAD_UNUSED_PD_L0_PP;
elessair 0:f269e3021894 100
elessair 0:f269e3021894 101 /** - Disable the clock for PAD peripheral device */
elessair 0:f269e3021894 102 CLOCK_DISABLE(CLOCK_PAD);
elessair 0:f269e3021894 103
elessair 0:f269e3021894 104 }
elessair 0:f269e3021894 105
elessair 0:f269e3021894 106 /** Find description at pad.h */
elessair 0:f269e3021894 107 boolean fPadIOCtrl(uint8_t PadNum, uint8_t OutputDriveStrength, uint8_t OutputDriveType, uint8_t PullType)
elessair 0:f269e3021894 108 {
elessair 0:f269e3021894 109 PadReg_t *PadRegOffset;
elessair 0:f269e3021894 110 /** \verbatim
elessair 0:f269e3021894 111 Table: O/p drive strength
elessair 0:f269e3021894 112
elessair 0:f269e3021894 113 Drive strength 3.3V (min/typ/max) 1V (min/typ/max)
elessair 0:f269e3021894 114 000 1/1.4/2.1 mA 0.043/0.07/0.11 mA
elessair 0:f269e3021894 115 001 2/2.7/4.1 mA 0.086/0.15/0.215 mA
elessair 0:f269e3021894 116 010 4.1/5.3/7.8 mA 0.188/0.3/0.4 mA
elessair 0:f269e3021894 117 011 8.1/10.4/15 8 mA 0.4/0.6/0.81 mA
elessair 0:f269e3021894 118 100 20.8/26/37 mA* 1/1.6/2.2 mA
elessair 0:f269e3021894 119 101 40.5/50/70 mA* 2/3/4.3 mA
elessair 0:f269e3021894 120 11x 57/73/102 mA* 3/4.6/6.2 mA
elessair 0:f269e3021894 121
elessair 0:f269e3021894 122 *Values are only accessible when CDBGPWRUPREQ is high. This limits the maximum output current in functional mode. \endverbatim */
elessair 0:f269e3021894 123
elessair 0:f269e3021894 124
elessair 0:f269e3021894 125 if((PadNum <= PAD_NUM_OF_IO) &&
elessair 0:f269e3021894 126 (OutputDriveStrength <= PAD_OP_DRIVE_STRGTH_MAX) &&
elessair 0:f269e3021894 127 (OutputDriveType <= PAD_OP_DRIVE_TYPE_MAX) && (PullType <= PAD_OP_PULL_TYPE_MAX)) {
elessair 0:f269e3021894 128 /** - Get PAD IO register address for the PAD number */
elessair 0:f269e3021894 129 PadRegOffset = (PadReg_t*)(PADREG_BASE + (PadNum * PAD_REG_ADRS_BYTE_SIZE));
elessair 0:f269e3021894 130
elessair 0:f269e3021894 131 /** - Enable the clock for PAD peripheral device */
elessair 0:f269e3021894 132 CLOCK_ENABLE(CLOCK_PAD);
elessair 0:f269e3021894 133
elessair 0:f269e3021894 134 /** - Set drive type, pulltype & drive strength */
elessair 0:f269e3021894 135 PadRegOffset->PADIO0.WORD = (uint32_t)((PullType << PAD_OP_PULL_TYPE_BIT_POS) |
elessair 0:f269e3021894 136 (OutputDriveStrength << PAD_OP_DRIVE_STRGTH_BIT_POS) |
elessair 0:f269e3021894 137 (OutputDriveType << PAD_OP_DRIVE_TYPE_BIT_POS));
elessair 0:f269e3021894 138
elessair 0:f269e3021894 139 /** - Disable the clock for PAD peripheral device */
elessair 0:f269e3021894 140 CLOCK_DISABLE(CLOCK_PAD);
elessair 0:f269e3021894 141 return True;
elessair 0:f269e3021894 142 }
elessair 0:f269e3021894 143 /* Invalid parameter/s */
elessair 0:f269e3021894 144 return False;
elessair 0:f269e3021894 145 }
elessair 0:f269e3021894 146 #endif /* REVD */