📄 halcrc.c
字号:
/* ============================================================================ Project Name : jayaCard Module Name : proto/hal/simu/halcrc.c Version : $Id: halcrc.c,v 1.7 2004/01/11 09:56:33 dgil Exp $ Description: CRC calculus The Original Code is jayaCard code. The Initial Developer of the Original Code is Gilles Dumortier. Portions created by the Initial Developer are Copyright (C) 2002-2004 the Initial Developer. All Rights Reserved. Contributor(s): This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see http://www.gnu.org/licenses/gpl.html History Rev Description 011903 dgil wrote it from scratch ============================================================================*/#include "precomp.h"/* ========================================================================= Local ========================================================================= */jword __simu_crc;/* ========================================================================= __hal_tcl_init_crc() initialise the T=CL CRC to begin a calculation. use tcl_type { TCL_TYPEA; TCL_TYPEB } to initialise the correct CRC. ========================================================================= */void __hal_tcl_init_crc(void){ if (tcl_type==TCL_TYPEA) { __simu_crc = 0x6363; } else { __simu_crc = 0xFFFF; } /* LOG2("HAL_CRC", "Init with %.4X (%s)", __simu_crc, tcl_type == TCL_TYPEA ? "Type A" : "Type B" ); */}/* ========================================================================= __hal_crc_init() initialise the system CRC to begin a calculation. ========================================================================= */void __hal_crc_init(void){ __simu_crc = 0x6363;}/* ========================================================================= __simu_calculate_crc() ========================================================================= */void __simu_calculate_crc(jbyte by){ /* LOG1("HAL_CRC", "Calculate CRC on byte %.2x", by ); */ by = (by^(jbyte)(__simu_crc & 0x00FF)); by = (by^(by<<4)); __simu_crc = (__simu_crc >> 8)^((jword)by << 8)^((jword)by<<3)^((jword)by>>4); /* LOG1("HAL_CRC", "New CRC value %.4x", __simu_crc ); */}/* ========================================================================= __simu_tcl_locrc() ========================================================================= */jbyte __simu_tcl_locrc(void){ if (tcl_type==TCL_TYPEA) { return LOBYTE(__simu_crc); } else { return LOBYTE(~__simu_crc); }}/* ========================================================================= __simu_tcl_hicrc() ========================================================================= */jbyte __simu_tcl_hicrc(void){ if (tcl_type==TCL_TYPEA) { return HIBYTE(__simu_crc); } else { return HIBYTE(~__simu_crc); }}/* ========================================================================= __simu_crc_lo() ========================================================================= */jbyte __simu_crc_lo(void){ return LOBYTE(__simu_crc);}/* ========================================================================= __simu_crc_hi() ========================================================================= */jbyte __simu_crc_hi(void){ return HIBYTE(__simu_crc);}/* ========================================================================= That's all folks ! ========================================================================= */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -