Denislam Valeev / Mbed OS Nucleo_rtos_basic
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MbedCRC.cpp Source File

MbedCRC.cpp

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2018 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include <stddef.h>
00018 #include "drivers/TableCRC.h"
00019 #include "drivers/MbedCRC.h"
00020 
00021 namespace mbed {
00022 /** \addtogroup drivers */
00023 /** @{*/
00024 
00025 /* Default values for different types of polynomials
00026 */
00027 template <uint32_t polynomial, uint8_t width>
00028 MbedCRC<polynomial, width>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
00029         _initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder), _crc_table(NULL)
00030 {
00031     mbed_crc_ctor();
00032 }
00033 
00034 template<>
00035 MbedCRC<POLY_32BIT_ANSI, 32>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
00036         _initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
00037         _crc_table((uint32_t *)Table_CRC_32bit_ANSI)
00038 {
00039     mbed_crc_ctor();
00040 }
00041 
00042 template<>
00043 MbedCRC<POLY_8BIT_CCITT, 8>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
00044         _initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
00045         _crc_table((uint32_t *)Table_CRC_8bit_CCITT)
00046 {
00047     mbed_crc_ctor();
00048 }
00049 
00050 template<>
00051 MbedCRC<POLY_7BIT_SD, 7>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
00052         _initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
00053         _crc_table((uint32_t *)Table_CRC_7Bit_SD)
00054 {
00055     mbed_crc_ctor();
00056 }
00057 
00058 template<>
00059 MbedCRC<POLY_16BIT_CCITT, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
00060         _initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
00061         _crc_table((uint32_t *)Table_CRC_16bit_CCITT)
00062 {
00063 }
00064 
00065 template<>
00066 MbedCRC<POLY_16BIT_IBM, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
00067         _initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
00068         _crc_table((uint32_t *)Table_CRC_16bit_IBM)
00069 {
00070     mbed_crc_ctor();
00071 }
00072 
00073 template<>
00074 MbedCRC<POLY_32BIT_ANSI, 32>::MbedCRC():
00075     _initial_value(~(0x0)), _final_xor(~(0x0)), _reflect_data(true), _reflect_remainder(true),
00076     _crc_table((uint32_t *)Table_CRC_32bit_ANSI)
00077 {
00078     mbed_crc_ctor();
00079 }
00080 
00081 template<>
00082 MbedCRC<POLY_16BIT_IBM, 16>::MbedCRC():
00083     _initial_value(0), _final_xor(0), _reflect_data(true), _reflect_remainder(true),
00084     _crc_table((uint32_t *)Table_CRC_16bit_IBM)
00085 {
00086     mbed_crc_ctor();
00087 }
00088 
00089 template<>
00090 MbedCRC<POLY_16BIT_CCITT, 16>::MbedCRC():
00091     _initial_value(~(0x0)), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
00092     _crc_table((uint32_t *)Table_CRC_16bit_CCITT)
00093 {
00094     mbed_crc_ctor();
00095 }
00096 
00097 template<>
00098 MbedCRC<POLY_7BIT_SD, 7>::MbedCRC():
00099     _initial_value(0), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
00100     _crc_table((uint32_t *)Table_CRC_7Bit_SD)
00101 {
00102     mbed_crc_ctor();
00103 }
00104 
00105 template<>
00106 MbedCRC<POLY_8BIT_CCITT, 8>::MbedCRC():
00107     _initial_value(0), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
00108     _crc_table((uint32_t *)Table_CRC_8bit_CCITT)
00109 {
00110     mbed_crc_ctor();
00111 }
00112 
00113 /** @}*/
00114 } // namespace mbed
00115