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