Skip to content

Commit a29e9ff

Browse files
Merge pull request #5 from TimerOverflow/20200907
20200907
2 parents 3d83a64 + bdd6d57 commit a29e9ff

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

crc16.c

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,20 @@
66
/*********************************************************************************/
77
#include "crc16.h"
88
/*********************************************************************************/
9-
#if(AVR_CRC16_REVISION_DATE != 20190905)
9+
#if(AVR_CRC16_REVISION_DATE != 20200907)
1010
#error wrong include file. (crc16.h)
1111
#endif
1212
/*********************************************************************************/
1313
/** Global variable **/
1414

1515

1616
/* CRC16 Table High byte */
17-
const unsigned char CRC16Hi[] =
17+
#if(__CRC16_TARGET_IAR_AVR__ == true)
18+
#include <ina90.h>
19+
const tU8 __flash CRC16Hi[] =
20+
#else
21+
const tU8 CRC16Hi[] =
22+
#endif
1823
{
1924
0x00, 0xC1, 0x81, 0x40, 0x01, 0xC0, 0x80, 0x41,
2025
0x01, 0xC0, 0x80, 0x41, 0x00, 0xC1, 0x81, 0x40,
@@ -51,7 +56,11 @@ const unsigned char CRC16Hi[] =
5156
};
5257

5358
/* CRC16 Table Low byte */
54-
const unsigned char CRC16Lo[] =
59+
#if(__CRC16_TARGET_IAR_AVR__ == true)
60+
const tU8 __flash CRC16Lo[] =
61+
#else
62+
const tU8 CRC16Lo[] =
63+
#endif
5564
{
5665
0x00, 0xC0, 0xC1, 0x01, 0xC3, 0x03, 0x02, 0xC2,
5766
0xC6, 0x06, 0x07, 0xC7, 0x05, 0xC5, 0xC4, 0x04,
@@ -87,26 +96,25 @@ const unsigned char CRC16Lo[] =
8796
0x82, 0x42, 0x43, 0x83, 0x41, 0x81, 0x80, 0x40
8897
};
8998
/*********************************************************************************/
90-
tU16 Crc16Check(char *BufCurPos, char *BufOffSet, char *BufEnd, tU16 Length)
99+
tU16 Crc16Check(tU8 *BufCurPos, tU8 *BufOffSet, tU8 *BufEnd, tU16 Length)
91100
{
92-
unsigned char CRCHi ;
93-
unsigned char CRCLo ;
94-
tU16 Index ;
101+
tU8 CRCHi, CRCLo;
102+
tU16 Index;
95103

96-
CRCHi = 0xFF ;
97-
CRCLo = 0xFF ;
98-
while(Length--)
104+
CRCHi = 0xFF;
105+
CRCLo = 0xFF;
106+
while(Length--)
99107
{
100-
Index = CRCHi ^ *BufCurPos++;
108+
Index = CRCHi ^ *BufCurPos;
101109
CRCHi = CRCLo ^ CRC16Hi[Index];
102110
CRCLo = CRC16Lo[Index];
103111

104-
if(BufCurPos > BufEnd)
112+
if(++BufCurPos > BufEnd)
105113
{
106114
BufCurPos = BufOffSet;
107115
}
108-
}
116+
}
109117

110-
return ((tU16) CRCHi << 8 | CRCLo);
118+
return (tU16) (CRCHi << 8) + CRCLo;
111119
}
112120
/*********************************************************************************/

crc16.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,33 @@
99
/*********************************************************************************/
1010
#include "SysTypedef.h"
1111
/*********************************************************************************/
12-
#define AVR_CRC16_REVISION_DATE 20190905
12+
#define AVR_CRC16_REVISION_DATE 20200907
1313
/*********************************************************************************/
1414
/** REVISION HISTORY **/
1515
/*
16-
2019. 09. 05. - SysTypedef 적용.
16+
2020. 09. 07. - __CRC16_TARGET_IAR_AVR__ 추가. AVR 타겟일 경우 crc테이블을 플래쉬 메모리에 할당.
17+
Jeong Hyun Gu
18+
19+
2019. 10. 07. - 'SysTypedef.h' 적용.
1720
Jeong Hyun Gu
1821
1922
2018. 05. 02. - CRC16 테이블 변수 타입 변경.
2023
Jeong Hyun Gu
2124
2225
2016. 11. 08. - revision valid check 추가.
23-
Jung Hyun Gu
26+
Jeong Hyun Gu
2427
2528
2016. 10. 28. - 초기버전.
26-
Jung Hyun Gu
29+
Jeong Hyun Gu
2730
*/
2831
/*********************************************************************************/
2932
/**Define**/
3033

34+
#define true 1
35+
#define false 0
36+
#define null 0
37+
38+
#define __CRC16_TARGET_IAR_AVR__ true
3139

3240
/*********************************************************************************/
3341
/**Enum**/
@@ -42,7 +50,7 @@
4250
/*********************************************************************************/
4351
/**Function**/
4452

45-
tU16 Crc16Check(char *BufCurPos, char *BufOffSet, char *BufEnd, tU16 Length);
53+
tU16 Crc16Check(tU8 *BufCurPos, tU8 *BufOffSet, tU8 *BufEnd, tU16 Length);
4654

4755
/*********************************************************************************/
4856
#endif //__CRC16_H__

0 commit comments

Comments
 (0)