Skip to content

Commit af09822

Browse files
author
deepikabhavnani
committed
Moved specialized functions to CPP file
Template specialized functions are moved to cpp file, to add MbedCRC.h in mbed.h. Else linker shall multiple definition error.
1 parent 8e53711 commit af09822

File tree

3 files changed

+116
-89
lines changed

3 files changed

+116
-89
lines changed

drivers/MbedCRC.cpp

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2018 ARM Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <stddef.h>
18+
#include "drivers/TableCRC.h"
19+
#include "drivers/MbedCRC.h"
20+
21+
namespace mbed {
22+
/** \addtogroup drivers */
23+
/** @{*/
24+
25+
/* Default values for different types of polynomials
26+
*/
27+
template <uint32_t polynomial, uint8_t width>
28+
MbedCRC<polynomial, width>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
29+
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder), _crc_table(NULL)
30+
{
31+
mbed_crc_ctor();
32+
}
33+
34+
template<>
35+
MbedCRC<POLY_32BIT_ANSI, 32>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
36+
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
37+
_crc_table((uint32_t *)Table_CRC_32bit_ANSI)
38+
{
39+
mbed_crc_ctor();
40+
}
41+
42+
template<>
43+
MbedCRC<POLY_8BIT_CCITT, 8>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
44+
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
45+
_crc_table((uint32_t *)Table_CRC_8bit_CCITT)
46+
{
47+
mbed_crc_ctor();
48+
}
49+
50+
template<>
51+
MbedCRC<POLY_7BIT_SD, 7>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
52+
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
53+
_crc_table((uint32_t *)Table_CRC_7Bit_SD)
54+
{
55+
mbed_crc_ctor();
56+
}
57+
58+
template<>
59+
MbedCRC<POLY_16BIT_CCITT, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
60+
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
61+
_crc_table((uint32_t *)Table_CRC_16bit_CCITT)
62+
{
63+
}
64+
65+
template<>
66+
MbedCRC<POLY_16BIT_IBM, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
67+
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
68+
_crc_table((uint32_t *)Table_CRC_16bit_IBM)
69+
{
70+
mbed_crc_ctor();
71+
}
72+
73+
template<>
74+
MbedCRC<POLY_32BIT_ANSI, 32>::MbedCRC():
75+
_initial_value(~(0x0)), _final_xor(~(0x0)), _reflect_data(true), _reflect_remainder(true),
76+
_crc_table((uint32_t *)Table_CRC_32bit_ANSI)
77+
{
78+
mbed_crc_ctor();
79+
}
80+
81+
template<>
82+
MbedCRC<POLY_16BIT_IBM, 16>::MbedCRC():
83+
_initial_value(0), _final_xor(0), _reflect_data(true), _reflect_remainder(true),
84+
_crc_table((uint32_t *)Table_CRC_16bit_IBM)
85+
{
86+
mbed_crc_ctor();
87+
}
88+
89+
template<>
90+
MbedCRC<POLY_16BIT_CCITT, 16>::MbedCRC():
91+
_initial_value(~(0x0)), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
92+
_crc_table((uint32_t *)Table_CRC_16bit_CCITT)
93+
{
94+
mbed_crc_ctor();
95+
}
96+
97+
template<>
98+
MbedCRC<POLY_7BIT_SD, 7>::MbedCRC():
99+
_initial_value(0), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
100+
_crc_table((uint32_t *)Table_CRC_7Bit_SD)
101+
{
102+
mbed_crc_ctor();
103+
}
104+
105+
template<>
106+
MbedCRC<POLY_8BIT_CCITT, 8>::MbedCRC():
107+
_initial_value(0), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
108+
_crc_table((uint32_t *)Table_CRC_8bit_CCITT)
109+
{
110+
mbed_crc_ctor();
111+
}
112+
113+
/** @}*/
114+
} // namespace mbed
115+

drivers/MbedCRC.h

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -404,94 +404,6 @@ class MbedCRC
404404
}
405405
};
406406

407-
/* Default values for different types of polynomials
408-
*/
409-
template <uint32_t polynomial, uint8_t width>
410-
MbedCRC<polynomial, width>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
411-
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder), _crc_table(NULL)
412-
{
413-
mbed_crc_ctor();
414-
}
415-
416-
template<>
417-
MbedCRC<POLY_32BIT_ANSI, 32>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
418-
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
419-
_crc_table((uint32_t *)Table_CRC_32bit_ANSI)
420-
{
421-
mbed_crc_ctor();
422-
}
423-
424-
template<>
425-
MbedCRC<POLY_8BIT_CCITT, 8>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
426-
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
427-
_crc_table((uint32_t *)Table_CRC_8bit_CCITT)
428-
{
429-
mbed_crc_ctor();
430-
}
431-
432-
template<>
433-
MbedCRC<POLY_7BIT_SD, 7>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
434-
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
435-
_crc_table((uint32_t *)Table_CRC_7Bit_SD)
436-
{
437-
mbed_crc_ctor();
438-
}
439-
440-
template<>
441-
MbedCRC<POLY_16BIT_CCITT, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
442-
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
443-
_crc_table((uint32_t *)Table_CRC_16bit_CCITT)
444-
{
445-
}
446-
447-
template<>
448-
MbedCRC<POLY_16BIT_IBM, 16>::MbedCRC(uint32_t initial_xor, uint32_t final_xor, bool reflect_data, bool reflect_remainder):
449-
_initial_value(initial_xor), _final_xor(final_xor), _reflect_data(reflect_data), _reflect_remainder(reflect_remainder),
450-
_crc_table((uint32_t *)Table_CRC_16bit_IBM)
451-
{
452-
mbed_crc_ctor();
453-
}
454-
455-
template<>
456-
MbedCRC<POLY_32BIT_ANSI, 32>::MbedCRC():
457-
_initial_value(~(0x0)), _final_xor(~(0x0)), _reflect_data(true), _reflect_remainder(true),
458-
_crc_table((uint32_t *)Table_CRC_32bit_ANSI)
459-
{
460-
mbed_crc_ctor();
461-
}
462-
463-
template<>
464-
MbedCRC<POLY_16BIT_IBM, 16>::MbedCRC():
465-
_initial_value(0), _final_xor(0), _reflect_data(true), _reflect_remainder(true),
466-
_crc_table((uint32_t *)Table_CRC_16bit_IBM)
467-
{
468-
mbed_crc_ctor();
469-
}
470-
471-
template<>
472-
MbedCRC<POLY_16BIT_CCITT, 16>::MbedCRC():
473-
_initial_value(~(0x0)), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
474-
_crc_table((uint32_t *)Table_CRC_16bit_CCITT)
475-
{
476-
mbed_crc_ctor();
477-
}
478-
479-
template<>
480-
MbedCRC<POLY_7BIT_SD, 7>::MbedCRC():
481-
_initial_value(0), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
482-
_crc_table((uint32_t *)Table_CRC_7Bit_SD)
483-
{
484-
mbed_crc_ctor();
485-
}
486-
487-
template<>
488-
MbedCRC<POLY_8BIT_CCITT, 8>::MbedCRC():
489-
_initial_value(0), _final_xor(0), _reflect_data(false), _reflect_remainder(false),
490-
_crc_table((uint32_t *)Table_CRC_8bit_CCITT)
491-
{
492-
mbed_crc_ctor();
493-
}
494-
495407
#if defined ( __CC_ARM )
496408
#elif defined ( __GNUC__ )
497409
#pragma GCC diagnostic pop

mbed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
#include "drivers/RawSerial.h"
7171
#include "drivers/UARTSerial.h"
7272
#include "drivers/FlashIAP.h"
73-
#include "drivers/TableCRC.h"
73+
#include "drivers/MbedCRC.h"
7474

7575
// mbed Internal components
7676
#include "drivers/Timer.h"

0 commit comments

Comments
 (0)