Mouse code for the MacroRat
mbed-dev/targets/TARGET_NUVOTON/TARGET_M451/device/StdDriver/m451_sc.c@18:6a4db94011d3, 2017-05-14 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sun May 14 23:18:57 2017 +0000
- Revision:
- 18:6a4db94011d3
Publishing again
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /**************************************************************************//** |
sahilmgandhi | 18:6a4db94011d3 | 2 | * @file sc.c |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @version V3.00 |
sahilmgandhi | 18:6a4db94011d3 | 4 | * $Revision: 9 $ |
sahilmgandhi | 18:6a4db94011d3 | 5 | * $Date: 15/08/11 10:26a $ |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @brief M451 series Smartcard(SC) driver source file |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * @note |
sahilmgandhi | 18:6a4db94011d3 | 9 | * Copyright (C) 2013~2015 Nuvoton Technology Corp. All rights reserved. |
sahilmgandhi | 18:6a4db94011d3 | 10 | *****************************************************************************/ |
sahilmgandhi | 18:6a4db94011d3 | 11 | #include "M451Series.h" |
sahilmgandhi | 18:6a4db94011d3 | 12 | |
sahilmgandhi | 18:6a4db94011d3 | 13 | // Below are variables used locally by SC driver and does not want to parse by doxygen unless HIDDEN_SYMBOLS is defined |
sahilmgandhi | 18:6a4db94011d3 | 14 | /// @cond HIDDEN_SYMBOLS |
sahilmgandhi | 18:6a4db94011d3 | 15 | static uint32_t u32CardStateIgnore[SC_INTERFACE_NUM] = {0}; |
sahilmgandhi | 18:6a4db94011d3 | 16 | |
sahilmgandhi | 18:6a4db94011d3 | 17 | /// @endcond HIDDEN_SYMBOLS |
sahilmgandhi | 18:6a4db94011d3 | 18 | |
sahilmgandhi | 18:6a4db94011d3 | 19 | /** @addtogroup Standard_Driver Standard Driver |
sahilmgandhi | 18:6a4db94011d3 | 20 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 21 | */ |
sahilmgandhi | 18:6a4db94011d3 | 22 | |
sahilmgandhi | 18:6a4db94011d3 | 23 | /** @addtogroup SC_Driver SC Driver |
sahilmgandhi | 18:6a4db94011d3 | 24 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 25 | */ |
sahilmgandhi | 18:6a4db94011d3 | 26 | |
sahilmgandhi | 18:6a4db94011d3 | 27 | |
sahilmgandhi | 18:6a4db94011d3 | 28 | /** @addtogroup SC_EXPORTED_FUNCTIONS SC Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 29 | @{ |
sahilmgandhi | 18:6a4db94011d3 | 30 | */ |
sahilmgandhi | 18:6a4db94011d3 | 31 | |
sahilmgandhi | 18:6a4db94011d3 | 32 | /** |
sahilmgandhi | 18:6a4db94011d3 | 33 | * @brief This function indicates specified smartcard slot status. |
sahilmgandhi | 18:6a4db94011d3 | 34 | * @param[in] sc The pointer of smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 35 | * @retval TRUE Card insert. |
sahilmgandhi | 18:6a4db94011d3 | 36 | * @retval FALSE Card remove. |
sahilmgandhi | 18:6a4db94011d3 | 37 | * @details This function is used to check if specified smart card slot is presented. |
sahilmgandhi | 18:6a4db94011d3 | 38 | */ |
sahilmgandhi | 18:6a4db94011d3 | 39 | uint32_t SC_IsCardInserted(SC_T *sc) |
sahilmgandhi | 18:6a4db94011d3 | 40 | { |
sahilmgandhi | 18:6a4db94011d3 | 41 | // put conditions into two variable to remove IAR compilation warning |
sahilmgandhi | 18:6a4db94011d3 | 42 | uint32_t cond1 = ((sc->STATUS & SC_STATUS_CDPINSTS_Msk) >> SC_STATUS_CDPINSTS_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 43 | uint32_t cond2 = ((sc->CTL & SC_CTL_CDLV_Msk) >> SC_CTL_CDLV_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 44 | |
sahilmgandhi | 18:6a4db94011d3 | 45 | if(sc == SC0 && u32CardStateIgnore[0] == 1) |
sahilmgandhi | 18:6a4db94011d3 | 46 | return TRUE; |
sahilmgandhi | 18:6a4db94011d3 | 47 | #if 0 /* M451 series has only one SC interface */ |
sahilmgandhi | 18:6a4db94011d3 | 48 | else if(sc == SC1 && u32CardStateIgnore[1] == 1) |
sahilmgandhi | 18:6a4db94011d3 | 49 | return TRUE; |
sahilmgandhi | 18:6a4db94011d3 | 50 | else if(sc == SC2 && u32CardStateIgnore[2] == 1) |
sahilmgandhi | 18:6a4db94011d3 | 51 | return TRUE; |
sahilmgandhi | 18:6a4db94011d3 | 52 | else if(sc == SC3 && u32CardStateIgnore[3] == 1) |
sahilmgandhi | 18:6a4db94011d3 | 53 | return TRUE; |
sahilmgandhi | 18:6a4db94011d3 | 54 | else if(sc == SC4 && u32CardStateIgnore[4] == 1) |
sahilmgandhi | 18:6a4db94011d3 | 55 | return TRUE; |
sahilmgandhi | 18:6a4db94011d3 | 56 | else if(sc == SC5 && u32CardStateIgnore[5] == 1) |
sahilmgandhi | 18:6a4db94011d3 | 57 | return TRUE; |
sahilmgandhi | 18:6a4db94011d3 | 58 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 59 | else if(cond1 != cond2) |
sahilmgandhi | 18:6a4db94011d3 | 60 | return FALSE; |
sahilmgandhi | 18:6a4db94011d3 | 61 | else |
sahilmgandhi | 18:6a4db94011d3 | 62 | return TRUE; |
sahilmgandhi | 18:6a4db94011d3 | 63 | } |
sahilmgandhi | 18:6a4db94011d3 | 64 | |
sahilmgandhi | 18:6a4db94011d3 | 65 | /** |
sahilmgandhi | 18:6a4db94011d3 | 66 | * @brief Reset the Tx/Rx FIFO. |
sahilmgandhi | 18:6a4db94011d3 | 67 | * @param[in] sc The pointer of smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 68 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 69 | * @details This function reset both transmit and receive FIFO of specified smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 70 | */ |
sahilmgandhi | 18:6a4db94011d3 | 71 | void SC_ClearFIFO(SC_T *sc) |
sahilmgandhi | 18:6a4db94011d3 | 72 | { |
sahilmgandhi | 18:6a4db94011d3 | 73 | sc->ALTCTL |= (SC_ALTCTL_TXRST_Msk | SC_ALTCTL_RXRST_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 74 | } |
sahilmgandhi | 18:6a4db94011d3 | 75 | |
sahilmgandhi | 18:6a4db94011d3 | 76 | /** |
sahilmgandhi | 18:6a4db94011d3 | 77 | * @brief This function disable specified smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 78 | * @param[in] sc The pointer of smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 79 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 80 | * @details SC will force all transition to IDLE state. |
sahilmgandhi | 18:6a4db94011d3 | 81 | */ |
sahilmgandhi | 18:6a4db94011d3 | 82 | void SC_Close(SC_T *sc) |
sahilmgandhi | 18:6a4db94011d3 | 83 | { |
sahilmgandhi | 18:6a4db94011d3 | 84 | sc->INTEN = 0; |
sahilmgandhi | 18:6a4db94011d3 | 85 | sc->PINCTL = 0; |
sahilmgandhi | 18:6a4db94011d3 | 86 | sc->ALTCTL = 0; |
sahilmgandhi | 18:6a4db94011d3 | 87 | sc->CTL = 0; |
sahilmgandhi | 18:6a4db94011d3 | 88 | } |
sahilmgandhi | 18:6a4db94011d3 | 89 | |
sahilmgandhi | 18:6a4db94011d3 | 90 | /** |
sahilmgandhi | 18:6a4db94011d3 | 91 | * @brief This function initialized smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 92 | * @param[in] sc The pointer of smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 93 | * @param[in] u32CD Card detect polarity, select the CD pin state which indicates card insert. Could be: |
sahilmgandhi | 18:6a4db94011d3 | 94 | * -\ref SC_PIN_STATE_HIGH. |
sahilmgandhi | 18:6a4db94011d3 | 95 | * -\ref SC_PIN_STATE_LOW. |
sahilmgandhi | 18:6a4db94011d3 | 96 | * -\ref SC_PIN_STATE_IGNORE, no card detect pin, always assumes card present. |
sahilmgandhi | 18:6a4db94011d3 | 97 | * @param[in] u32PWR Power on polarity, select the PWR pin state which could set smartcard VCC to high level. Could be: |
sahilmgandhi | 18:6a4db94011d3 | 98 | * -\ref SC_PIN_STATE_HIGH. |
sahilmgandhi | 18:6a4db94011d3 | 99 | * -\ref SC_PIN_STATE_LOW. |
sahilmgandhi | 18:6a4db94011d3 | 100 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 101 | * @details Initialization process configures smartcard and enables engine clock. |
sahilmgandhi | 18:6a4db94011d3 | 102 | */ |
sahilmgandhi | 18:6a4db94011d3 | 103 | void SC_Open(SC_T *sc, uint32_t u32CD, uint32_t u32PWR) |
sahilmgandhi | 18:6a4db94011d3 | 104 | { |
sahilmgandhi | 18:6a4db94011d3 | 105 | uint32_t u32Reg = 0, u32Intf; |
sahilmgandhi | 18:6a4db94011d3 | 106 | |
sahilmgandhi | 18:6a4db94011d3 | 107 | if(sc == SC0) |
sahilmgandhi | 18:6a4db94011d3 | 108 | u32Intf = 0; |
sahilmgandhi | 18:6a4db94011d3 | 109 | #if 0 /* M451 series has only one SC interface */ |
sahilmgandhi | 18:6a4db94011d3 | 110 | else if(sc == SC1) |
sahilmgandhi | 18:6a4db94011d3 | 111 | u32Intf = 1; |
sahilmgandhi | 18:6a4db94011d3 | 112 | else if(sc == SC2) |
sahilmgandhi | 18:6a4db94011d3 | 113 | u32Intf = 2; |
sahilmgandhi | 18:6a4db94011d3 | 114 | else if(sc == SC3) |
sahilmgandhi | 18:6a4db94011d3 | 115 | u32Intf = 3; |
sahilmgandhi | 18:6a4db94011d3 | 116 | else if(sc == SC4) |
sahilmgandhi | 18:6a4db94011d3 | 117 | u32Intf = 4; |
sahilmgandhi | 18:6a4db94011d3 | 118 | else if(sc == SC5) |
sahilmgandhi | 18:6a4db94011d3 | 119 | u32Intf = 5; |
sahilmgandhi | 18:6a4db94011d3 | 120 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 121 | else |
sahilmgandhi | 18:6a4db94011d3 | 122 | return ; |
sahilmgandhi | 18:6a4db94011d3 | 123 | |
sahilmgandhi | 18:6a4db94011d3 | 124 | if(u32CD != SC_PIN_STATE_IGNORE) { |
sahilmgandhi | 18:6a4db94011d3 | 125 | u32Reg = u32CD ? 0: SC_CTL_CDLV_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 126 | u32CardStateIgnore[u32Intf] = 0; |
sahilmgandhi | 18:6a4db94011d3 | 127 | } else { |
sahilmgandhi | 18:6a4db94011d3 | 128 | u32CardStateIgnore[u32Intf] = 1; |
sahilmgandhi | 18:6a4db94011d3 | 129 | } |
sahilmgandhi | 18:6a4db94011d3 | 130 | while(sc->PINCTL & SC_PINCTL_SYNC_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 131 | sc->PINCTL = u32PWR ? 0 : SC_PINCTL_PWRINV_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 132 | while(sc->CTL & SC_CTL_SYNC_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 133 | sc->CTL = SC_CTL_SCEN_Msk | u32Reg; |
sahilmgandhi | 18:6a4db94011d3 | 134 | } |
sahilmgandhi | 18:6a4db94011d3 | 135 | |
sahilmgandhi | 18:6a4db94011d3 | 136 | /** |
sahilmgandhi | 18:6a4db94011d3 | 137 | * @brief This function reset specified smartcard module to its default state for activate smartcard. |
sahilmgandhi | 18:6a4db94011d3 | 138 | * @param[in] sc The pointer of smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 139 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 140 | * @details Reset the Tx/Rx FIFO & clock & initial default parameter. |
sahilmgandhi | 18:6a4db94011d3 | 141 | */ |
sahilmgandhi | 18:6a4db94011d3 | 142 | void SC_ResetReader(SC_T *sc) |
sahilmgandhi | 18:6a4db94011d3 | 143 | { |
sahilmgandhi | 18:6a4db94011d3 | 144 | uint32_t u32Intf; |
sahilmgandhi | 18:6a4db94011d3 | 145 | |
sahilmgandhi | 18:6a4db94011d3 | 146 | if(sc == SC0) |
sahilmgandhi | 18:6a4db94011d3 | 147 | u32Intf = 0; |
sahilmgandhi | 18:6a4db94011d3 | 148 | #if 0 /* M451 series has only one SC interface */ |
sahilmgandhi | 18:6a4db94011d3 | 149 | else if(sc == SC1) |
sahilmgandhi | 18:6a4db94011d3 | 150 | u32Intf = 1; |
sahilmgandhi | 18:6a4db94011d3 | 151 | else if(sc == SC2) |
sahilmgandhi | 18:6a4db94011d3 | 152 | u32Intf = 2; |
sahilmgandhi | 18:6a4db94011d3 | 153 | else if(sc == SC3) |
sahilmgandhi | 18:6a4db94011d3 | 154 | u32Intf = 3; |
sahilmgandhi | 18:6a4db94011d3 | 155 | else if(sc == SC4) |
sahilmgandhi | 18:6a4db94011d3 | 156 | u32Intf = 4; |
sahilmgandhi | 18:6a4db94011d3 | 157 | else if(sc == SC5) |
sahilmgandhi | 18:6a4db94011d3 | 158 | u32Intf = 5; |
sahilmgandhi | 18:6a4db94011d3 | 159 | #endif |
sahilmgandhi | 18:6a4db94011d3 | 160 | else |
sahilmgandhi | 18:6a4db94011d3 | 161 | return ; |
sahilmgandhi | 18:6a4db94011d3 | 162 | |
sahilmgandhi | 18:6a4db94011d3 | 163 | // Reset FIFO, enable auto de-activation while card removal |
sahilmgandhi | 18:6a4db94011d3 | 164 | sc->ALTCTL |= (SC_ALTCTL_TXRST_Msk | SC_ALTCTL_RXRST_Msk | SC_ALTCTL_ADACEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 165 | // Set Rx trigger level to 1 character, longest card detect debounce period, disable error retry (EMV ATR does not use error retry) |
sahilmgandhi | 18:6a4db94011d3 | 166 | while(sc->CTL & SC_CTL_SYNC_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 167 | sc->CTL &= ~(SC_CTL_RXTRGLV_Msk | SC_CTL_CDDBSEL_Msk | SC_CTL_TXRTY_Msk | SC_CTL_RXRTY_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 168 | // Enable auto convention, and all three smartcard internal timers |
sahilmgandhi | 18:6a4db94011d3 | 169 | sc->CTL |= SC_CTL_AUTOCEN_Msk | SC_CTL_TMRSEL_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 170 | // Disable Rx timeout |
sahilmgandhi | 18:6a4db94011d3 | 171 | sc->RXTOUT = 0; |
sahilmgandhi | 18:6a4db94011d3 | 172 | // 372 clocks per ETU by default |
sahilmgandhi | 18:6a4db94011d3 | 173 | sc->ETUCTL = 371; |
sahilmgandhi | 18:6a4db94011d3 | 174 | |
sahilmgandhi | 18:6a4db94011d3 | 175 | /* Enable necessary interrupt for smartcard operation */ |
sahilmgandhi | 18:6a4db94011d3 | 176 | if(u32CardStateIgnore[u32Intf]) // Do not enable card detect interrupt if card present state ignore |
sahilmgandhi | 18:6a4db94011d3 | 177 | sc->INTEN = (SC_INTEN_RDAIEN_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 178 | SC_INTEN_TERRIEN_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 179 | SC_INTEN_TMR0IEN_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 180 | SC_INTEN_TMR1IEN_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 181 | SC_INTEN_TMR2IEN_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 182 | SC_INTEN_BGTIEN_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 183 | SC_INTEN_ACERRIEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 184 | else |
sahilmgandhi | 18:6a4db94011d3 | 185 | sc->INTEN = (SC_INTEN_RDAIEN_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 186 | SC_INTEN_TERRIEN_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 187 | SC_INTEN_TMR0IEN_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 188 | SC_INTEN_TMR1IEN_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 189 | SC_INTEN_TMR2IEN_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 190 | SC_INTEN_BGTIEN_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 191 | SC_INTEN_ACERRIEN_Msk | |
sahilmgandhi | 18:6a4db94011d3 | 192 | SC_INTEN_CDIEN_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 193 | |
sahilmgandhi | 18:6a4db94011d3 | 194 | return; |
sahilmgandhi | 18:6a4db94011d3 | 195 | } |
sahilmgandhi | 18:6a4db94011d3 | 196 | |
sahilmgandhi | 18:6a4db94011d3 | 197 | /** |
sahilmgandhi | 18:6a4db94011d3 | 198 | * @brief Set Block Guard Time. |
sahilmgandhi | 18:6a4db94011d3 | 199 | * @param[in] sc The pointer of smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 200 | * @param[in] u32BGT Block guard time using ETU as unit, valid range are between 1 ~ 32. |
sahilmgandhi | 18:6a4db94011d3 | 201 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 202 | * @details This function block guard time (BGT) of specified smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 203 | */ |
sahilmgandhi | 18:6a4db94011d3 | 204 | void SC_SetBlockGuardTime(SC_T *sc, uint32_t u32BGT) |
sahilmgandhi | 18:6a4db94011d3 | 205 | { |
sahilmgandhi | 18:6a4db94011d3 | 206 | sc->CTL = (sc->CTL & ~SC_CTL_BGT_Msk) | ((u32BGT - 1) << SC_CTL_BGT_Pos); |
sahilmgandhi | 18:6a4db94011d3 | 207 | } |
sahilmgandhi | 18:6a4db94011d3 | 208 | |
sahilmgandhi | 18:6a4db94011d3 | 209 | /** |
sahilmgandhi | 18:6a4db94011d3 | 210 | * @brief Set character guard time. |
sahilmgandhi | 18:6a4db94011d3 | 211 | * @param[in] sc The pointer of smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 212 | * @param[in] u32CGT Character guard time using ETU as unit, valid range are between 11 ~ 267. |
sahilmgandhi | 18:6a4db94011d3 | 213 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 214 | * @details This function character guard time (CGT) of specified smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 215 | * @note Before using this API, user should set the correct stop bit length first. |
sahilmgandhi | 18:6a4db94011d3 | 216 | */ |
sahilmgandhi | 18:6a4db94011d3 | 217 | void SC_SetCharGuardTime(SC_T *sc, uint32_t u32CGT) |
sahilmgandhi | 18:6a4db94011d3 | 218 | { |
sahilmgandhi | 18:6a4db94011d3 | 219 | u32CGT -= sc->CTL & SC_CTL_NSB_Msk ? 11 : 12; |
sahilmgandhi | 18:6a4db94011d3 | 220 | sc->EGT = u32CGT; |
sahilmgandhi | 18:6a4db94011d3 | 221 | } |
sahilmgandhi | 18:6a4db94011d3 | 222 | |
sahilmgandhi | 18:6a4db94011d3 | 223 | /** |
sahilmgandhi | 18:6a4db94011d3 | 224 | * @brief Stop all Timer counting. |
sahilmgandhi | 18:6a4db94011d3 | 225 | * @param[in] sc The pointer of smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 226 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 227 | * @details This function stop all smartcard timer of specified smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 228 | * @note This function stop the timers within smartcard module, \b not timer module. |
sahilmgandhi | 18:6a4db94011d3 | 229 | */ |
sahilmgandhi | 18:6a4db94011d3 | 230 | void SC_StopAllTimer(SC_T *sc) |
sahilmgandhi | 18:6a4db94011d3 | 231 | { |
sahilmgandhi | 18:6a4db94011d3 | 232 | sc->ALTCTL &= ~(SC_ALTCTL_CNTEN0_Msk | SC_ALTCTL_CNTEN1_Msk | SC_ALTCTL_CNTEN2_Msk); |
sahilmgandhi | 18:6a4db94011d3 | 233 | } |
sahilmgandhi | 18:6a4db94011d3 | 234 | |
sahilmgandhi | 18:6a4db94011d3 | 235 | /** |
sahilmgandhi | 18:6a4db94011d3 | 236 | * @brief This function configure and start a smartcard timer of specified smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 237 | * @param[in] sc The pointer of smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 238 | * @param[in] u32TimerNum Timer(s) to start. Valid values are 0, 1, 2. |
sahilmgandhi | 18:6a4db94011d3 | 239 | * @param[in] u32Mode Timer operating mode, valid values are: |
sahilmgandhi | 18:6a4db94011d3 | 240 | * - \ref SC_TMR_MODE_0 |
sahilmgandhi | 18:6a4db94011d3 | 241 | * - \ref SC_TMR_MODE_1 |
sahilmgandhi | 18:6a4db94011d3 | 242 | * - \ref SC_TMR_MODE_2 |
sahilmgandhi | 18:6a4db94011d3 | 243 | * - \ref SC_TMR_MODE_3 |
sahilmgandhi | 18:6a4db94011d3 | 244 | * - \ref SC_TMR_MODE_4 |
sahilmgandhi | 18:6a4db94011d3 | 245 | * - \ref SC_TMR_MODE_5 |
sahilmgandhi | 18:6a4db94011d3 | 246 | * - \ref SC_TMR_MODE_6 |
sahilmgandhi | 18:6a4db94011d3 | 247 | * - \ref SC_TMR_MODE_7 |
sahilmgandhi | 18:6a4db94011d3 | 248 | * - \ref SC_TMR_MODE_8 |
sahilmgandhi | 18:6a4db94011d3 | 249 | * - \ref SC_TMR_MODE_F |
sahilmgandhi | 18:6a4db94011d3 | 250 | * @param[in] u32ETUCount Timer timeout duration, ETU based. For timer 0, valid range are between 1~0x1000000ETUs. |
sahilmgandhi | 18:6a4db94011d3 | 251 | * For timer 1 and timer 2, valid range are between 1 ~ 0x100 ETUs. |
sahilmgandhi | 18:6a4db94011d3 | 252 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 253 | * @details Enable Timer starting, counter will count when condition match. |
sahilmgandhi | 18:6a4db94011d3 | 254 | * @note This function start the timer within smartcard module, \b not timer module. |
sahilmgandhi | 18:6a4db94011d3 | 255 | * @note Depend on the timer operating mode, timer may not start counting immediately. |
sahilmgandhi | 18:6a4db94011d3 | 256 | */ |
sahilmgandhi | 18:6a4db94011d3 | 257 | void SC_StartTimer(SC_T *sc, uint32_t u32TimerNum, uint32_t u32Mode, uint32_t u32ETUCount) |
sahilmgandhi | 18:6a4db94011d3 | 258 | { |
sahilmgandhi | 18:6a4db94011d3 | 259 | uint32_t reg = u32Mode | (SC_TMRCTL0_CNT_Msk & (u32ETUCount - 1)); |
sahilmgandhi | 18:6a4db94011d3 | 260 | |
sahilmgandhi | 18:6a4db94011d3 | 261 | if(u32TimerNum == 0) { |
sahilmgandhi | 18:6a4db94011d3 | 262 | sc->TMRCTL0 = reg; |
sahilmgandhi | 18:6a4db94011d3 | 263 | sc->ALTCTL |= SC_ALTCTL_CNTEN0_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 264 | } else if(u32TimerNum == 1) { |
sahilmgandhi | 18:6a4db94011d3 | 265 | sc->TMRCTL1 = reg; |
sahilmgandhi | 18:6a4db94011d3 | 266 | sc->ALTCTL |= SC_ALTCTL_CNTEN1_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 267 | } else { // timer 2 |
sahilmgandhi | 18:6a4db94011d3 | 268 | sc->TMRCTL2 = reg; |
sahilmgandhi | 18:6a4db94011d3 | 269 | sc->ALTCTL |= SC_ALTCTL_CNTEN2_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 270 | } |
sahilmgandhi | 18:6a4db94011d3 | 271 | } |
sahilmgandhi | 18:6a4db94011d3 | 272 | |
sahilmgandhi | 18:6a4db94011d3 | 273 | /** |
sahilmgandhi | 18:6a4db94011d3 | 274 | * @brief Stop Timer counting. |
sahilmgandhi | 18:6a4db94011d3 | 275 | * @param[in] sc The pointer of smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 276 | * @param[in] u32TimerNum Timer(s) to stop. Valid values are 0, 1, 2. |
sahilmgandhi | 18:6a4db94011d3 | 277 | * @return None |
sahilmgandhi | 18:6a4db94011d3 | 278 | * @details This function stop a smartcard timer of specified smartcard module. |
sahilmgandhi | 18:6a4db94011d3 | 279 | * @note This function stop the timer within smartcard module, \b not timer module. |
sahilmgandhi | 18:6a4db94011d3 | 280 | */ |
sahilmgandhi | 18:6a4db94011d3 | 281 | void SC_StopTimer(SC_T *sc, uint32_t u32TimerNum) |
sahilmgandhi | 18:6a4db94011d3 | 282 | { |
sahilmgandhi | 18:6a4db94011d3 | 283 | if(u32TimerNum == 0) |
sahilmgandhi | 18:6a4db94011d3 | 284 | sc->ALTCTL &= ~SC_ALTCTL_CNTEN0_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 285 | else if(u32TimerNum == 1) |
sahilmgandhi | 18:6a4db94011d3 | 286 | sc->ALTCTL &= ~SC_ALTCTL_CNTEN1_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 287 | else // timer 2 |
sahilmgandhi | 18:6a4db94011d3 | 288 | sc->ALTCTL &= ~SC_ALTCTL_CNTEN2_Msk; |
sahilmgandhi | 18:6a4db94011d3 | 289 | } |
sahilmgandhi | 18:6a4db94011d3 | 290 | |
sahilmgandhi | 18:6a4db94011d3 | 291 | |
sahilmgandhi | 18:6a4db94011d3 | 292 | |
sahilmgandhi | 18:6a4db94011d3 | 293 | /*@}*/ /* end of group SC_EXPORTED_FUNCTIONS */ |
sahilmgandhi | 18:6a4db94011d3 | 294 | |
sahilmgandhi | 18:6a4db94011d3 | 295 | /*@}*/ /* end of group SC_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 296 | |
sahilmgandhi | 18:6a4db94011d3 | 297 | /*@}*/ /* end of group Standard_Driver */ |
sahilmgandhi | 18:6a4db94011d3 | 298 | |
sahilmgandhi | 18:6a4db94011d3 | 299 | /*** (C) COPYRIGHT 2013~2015 Nuvoton Technology Corp. ***/ |