mbed library sources. Supersedes mbed-src.
Fork of mbed-dev by
targets/TARGET_NUVOTON/TARGET_M451/device/StdDriver/m451_crc.c@149:156823d33999, 2016-10-28 (annotated)
- Committer:
- <>
- Date:
- Fri Oct 28 11:17:30 2016 +0100
- Revision:
- 149:156823d33999
This updates the lib to the mbed lib v128
NOTE: This release includes a restructuring of the file and directory locations and thus some
include paths in your code may need updating accordingly.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 149:156823d33999 | 1 | /**************************************************************************//** |
<> | 149:156823d33999 | 2 | * @file crc.c |
<> | 149:156823d33999 | 3 | * @version V3.00 |
<> | 149:156823d33999 | 4 | * $Revision: 7 $ |
<> | 149:156823d33999 | 5 | * $Date: 15/08/11 10:26a $ |
<> | 149:156823d33999 | 6 | * @brief M451 series CRC driver source file |
<> | 149:156823d33999 | 7 | * |
<> | 149:156823d33999 | 8 | * @note |
<> | 149:156823d33999 | 9 | * Copyright (C) 2013~2015 Nuvoton Technology Corp. All rights reserved. |
<> | 149:156823d33999 | 10 | *****************************************************************************/ |
<> | 149:156823d33999 | 11 | #include "M451Series.h" |
<> | 149:156823d33999 | 12 | |
<> | 149:156823d33999 | 13 | |
<> | 149:156823d33999 | 14 | /** @addtogroup Standard_Driver Standard Driver |
<> | 149:156823d33999 | 15 | @{ |
<> | 149:156823d33999 | 16 | */ |
<> | 149:156823d33999 | 17 | |
<> | 149:156823d33999 | 18 | /** @addtogroup CRC_Driver CRC Driver |
<> | 149:156823d33999 | 19 | @{ |
<> | 149:156823d33999 | 20 | */ |
<> | 149:156823d33999 | 21 | |
<> | 149:156823d33999 | 22 | /** @addtogroup CRC_EXPORTED_FUNCTIONS CRC Exported Functions |
<> | 149:156823d33999 | 23 | @{ |
<> | 149:156823d33999 | 24 | */ |
<> | 149:156823d33999 | 25 | |
<> | 149:156823d33999 | 26 | /** |
<> | 149:156823d33999 | 27 | * @brief CRC Open |
<> | 149:156823d33999 | 28 | * |
<> | 149:156823d33999 | 29 | * @param[in] u32Mode CRC operation polynomial mode. Valid values are: |
<> | 149:156823d33999 | 30 | * - \ref CRC_CCITT |
<> | 149:156823d33999 | 31 | * - \ref CRC_8 |
<> | 149:156823d33999 | 32 | * - \ref CRC_16 |
<> | 149:156823d33999 | 33 | * - \ref CRC_32 |
<> | 149:156823d33999 | 34 | * @param[in] u32Attribute CRC operation data attribute. Valid values are combined with: |
<> | 149:156823d33999 | 35 | * - \ref CRC_CHECKSUM_COM |
<> | 149:156823d33999 | 36 | * - \ref CRC_CHECKSUM_RVS |
<> | 149:156823d33999 | 37 | * - \ref CRC_WDATA_COM |
<> | 149:156823d33999 | 38 | * - \ref CRC_WDATA_RVS |
<> | 149:156823d33999 | 39 | * @param[in] u32Seed Seed value. |
<> | 149:156823d33999 | 40 | * @param[in] u32DataLen CPU Write Data Length. Valid values are: |
<> | 149:156823d33999 | 41 | * - \ref CRC_CPU_WDATA_8 |
<> | 149:156823d33999 | 42 | * - \ref CRC_CPU_WDATA_16 |
<> | 149:156823d33999 | 43 | * - \ref CRC_CPU_WDATA_32 |
<> | 149:156823d33999 | 44 | * |
<> | 149:156823d33999 | 45 | * @return None |
<> | 149:156823d33999 | 46 | * |
<> | 149:156823d33999 | 47 | * @details This function will enable the CRC controller by specify CRC operation mode, attribute, initial seed and write data length. \n |
<> | 149:156823d33999 | 48 | * After that, user can start to perform CRC calculate by calling CRC_WRITE_DATA macro or CRC_DAT register directly. |
<> | 149:156823d33999 | 49 | */ |
<> | 149:156823d33999 | 50 | void CRC_Open(uint32_t u32Mode, uint32_t u32Attribute, uint32_t u32Seed, uint32_t u32DataLen) |
<> | 149:156823d33999 | 51 | { |
<> | 149:156823d33999 | 52 | CRC->SEED = u32Seed; |
<> | 149:156823d33999 | 53 | CRC->CTL = u32Mode | u32Attribute | u32DataLen | CRC_CTL_CRCEN_Msk; |
<> | 149:156823d33999 | 54 | |
<> | 149:156823d33999 | 55 | /* Setting CRCRST bit will reload the initial seed value(CRC_SEED register) to CRC controller */ |
<> | 149:156823d33999 | 56 | CRC->CTL |= CRC_CTL_CRCRST_Msk; |
<> | 149:156823d33999 | 57 | } |
<> | 149:156823d33999 | 58 | |
<> | 149:156823d33999 | 59 | /** |
<> | 149:156823d33999 | 60 | * @brief Get CRC Checksum |
<> | 149:156823d33999 | 61 | * |
<> | 149:156823d33999 | 62 | * @param[in] None |
<> | 149:156823d33999 | 63 | * |
<> | 149:156823d33999 | 64 | * @return Checksum Result |
<> | 149:156823d33999 | 65 | * |
<> | 149:156823d33999 | 66 | * @details This macro gets the CRC checksum result by current CRC polynomial mode. |
<> | 149:156823d33999 | 67 | */ |
<> | 149:156823d33999 | 68 | uint32_t CRC_GetChecksum(void) |
<> | 149:156823d33999 | 69 | { |
<> | 149:156823d33999 | 70 | switch(CRC->CTL & CRC_CTL_CRCMODE_Msk) |
<> | 149:156823d33999 | 71 | { |
<> | 149:156823d33999 | 72 | case CRC_CCITT: |
<> | 149:156823d33999 | 73 | case CRC_16: |
<> | 149:156823d33999 | 74 | return (CRC->CHECKSUM & 0xFFFF); |
<> | 149:156823d33999 | 75 | |
<> | 149:156823d33999 | 76 | case CRC_32: |
<> | 149:156823d33999 | 77 | return (CRC->CHECKSUM); |
<> | 149:156823d33999 | 78 | |
<> | 149:156823d33999 | 79 | case CRC_8: |
<> | 149:156823d33999 | 80 | return (CRC->CHECKSUM & 0xFF); |
<> | 149:156823d33999 | 81 | |
<> | 149:156823d33999 | 82 | default: |
<> | 149:156823d33999 | 83 | return 0; |
<> | 149:156823d33999 | 84 | } |
<> | 149:156823d33999 | 85 | } |
<> | 149:156823d33999 | 86 | |
<> | 149:156823d33999 | 87 | /*@}*/ /* end of group CRC_EXPORTED_FUNCTIONS */ |
<> | 149:156823d33999 | 88 | |
<> | 149:156823d33999 | 89 | /*@}*/ /* end of group CRC_Driver */ |
<> | 149:156823d33999 | 90 | |
<> | 149:156823d33999 | 91 | /*@}*/ /* end of group Standard_Driver */ |
<> | 149:156823d33999 | 92 | |
<> | 149:156823d33999 | 93 | /*** (C) COPYRIGHT 2013~2015 Nuvoton Technology Corp. ***/ |