📄 bb_util.c
字号:
/*
*---------------------------------------------------------------------------
*
* I N T E L P R O P R I E T A R Y
*
* COPYRIGHT (c) 2001 BY INTEL CORPORATION. ALL RIGHTS
* RESERVED. NO PART OF THIS PROGRAM OR PUBLICATION MAY
* BE REPRODUCED, TRANSMITTED, TRANSCRIBED, STORED IN A
* RETRIEVAL SYSTEM, OR TRANSLATED INTO ANY LANGUAGE OR COMPUTER
* LANGUAGE IN ANY FORM OR BY ANY MEANS, ELECTRONIC, MECHANICAL,
* MAGNETIC, OPTICAL, CHEMICAL, MANUAL, OR OTHERWISE, WITHOUT
* THE PRIOR WRITTEN PERMISSION OF :
*
* INTEL CORPORATION
*
* 2200 MISSION COLLEGE BLVD
*
* SANTA CLARA, CALIFORNIA 95052-8119
*
*---------------------------------------------------------------------------
*
*
* AUTHOR: $Author: lagarwal $
* DATE: $Date: 2003/08/06 20:58:19 $
* LAST MODIFIED: $Modtime: 4/03/02 3:20p $
* REV#: $Revision: 1.4 $
* LOGFILE: $Logfile: /Embedded/source/drivers/ixf/bb_util.c $
* WORKFILE: $Workfile: bb_util.c $
*
* --------------------------------------------------------------------------
* Project: ALL
*
* Purpose: Implement error handling & utility portion of driver software
*
* Notes:
* Public Procedures:
*
* Support Functions for Error Handling and DebugCfg Linkage
* bb_Exception Exception Handler
*
* Support Functions for Chip Drivers
* bb_Make16ByteWorkString Build 16-byte J0, J1, J2 Work String
* bb_Make64ByteWorkString Build 64-byte J1 Work String
* bb_InsertCRC7 Calculate & insert Tx CRC7 byte
*
* Support Functions - used only for UNIT-TEST (Use printf and putchar)
* bb_HexDump Dump bytes in hex
* bb_PrintReg Print 8-bit reg
*
* --------------------------------------------------------------------------
*/
#include "common_types.h"
#include "common_def.h"
/***********************************************************************
* Max limits
**********************************************************************/
#define bb_BUFF_LEN 256 /* Buf Len for formatted print line */
#define bb_MAX_MSG_LEN (bb_BUFF_LEN - 2) /* leave room for \n and \0 */
/***********************************************************************
* Useful common suppport functions provided for specific chip drivers
**********************************************************************/
/***********************************************************************
* Procedure Name: bb_Make16ByteWorkString
*
* Description: Build 16-byte J0, J1, J2 Work String:
* 0, Jn string, Pad of 0's
*
* Conditions for Use:
* pWorkString != NULL
*
* Notes:
* WorkString is printable; i.e. there will always be a 0 at end,
* even if max length.
*
* End
**********************************************************************/
uchar* bb_Make16ByteWorkString /* Build 16-byte J0, J1, J2 Work String:
0, Jn string, Pad of 0's;
Return -> Work String */
(char* pString) /* -> J0, J1, J2 null-terminated string */
/* Note:
if pString = NULL, WorkString = 0's */
{
static uchar WorkString[18]; /* Leave room for null terminator */
uchar* pWorkString = WorkString;
int Len;
char Zero=0;
if (pString == 0)
pString = &Zero; /* If pString = NULL, make WorkString = 0's */
*pWorkString++ = 0; /* Put 0 at start of string */
Len = 15;
while (Len-- > 0) /* move rest of string, up to max of 15 bytes */
{
if ((*pWorkString++ = (uchar)*pString++) == 0)
/* move string byte or null-term */
break; /* if moved null-term - done with user's string */
}
while (Len-- > 0)
*pWorkString++ = 0; /* pad rest of work string, with 0's */
*pWorkString = 0; /* Add null terminator after workstring,
to make printable */
return WorkString;
} /* end bb_Make16ByteWorkString */
/***********************************************************************/
/***********************************************************************
* Procedure Name: bb_Make64ByteWorkString
*
* Description: Build 64-byte J1 Work String:
* J1 string, Pad of 0's
*
* Conditions for Use:
* pWorkString != NULL
*
* Notes:
* WorkString is printable; i.e. there will always be a 0 at end,
* even if max length.
*
* End
**********************************************************************/
uchar* bb_Make64ByteWorkString /* Build 64-byte J1 Work String:
J1 string, Pad of 0's */
(char* pString) /* -> J1 null-terminated string */
/* Note:
if pString = NULL, WorkString = 0's */
{
static uchar WorkString[66]; /* Leave room for null terminator */
uchar* pWorkString = WorkString;
int Len;
char Zero=0;
if (pString == 0)
pString = &Zero; /* If pString = NULL, make WorkString = 0's */
Len = 64;
while (Len-- > 0) /* move string, up to max of 64 bytes */
{
if ((*pWorkString++ = (char)*pString++) == 0)
/* move string byte or null-term */
break; /* if moved null-term - done with user's string */
}
while (Len-- > 0)
*pWorkString++ = 0; /* pad rest of work string, with 0's */
*pWorkString = 0; /* Add null terminator after workstring,
to make printable */
return WorkString;
} /* end bb_Make64ByteWorkString */
/***********************************************************************/
/***********************************************************************
* Procedure Name: bb_InsertCRC7
*
* Description: Calculate & insert CRC7 byte,
* at start of work string
*
* Conditions for Use:
* Work string is exactly 16 bytes, with dummy byte at start.
*
* End
**********************************************************************/
void bb_InsertCRC7 /* Calculate & insert CRC7 byte,
at start of work string */
(uchar* pWorkString) /* -> Work String, from function above, with
dummy byte at start of string, for CRC7 */
{
typedef struct _bits
{
unsigned b0 : 1;
unsigned b1 : 1;
unsigned b2 : 1;
unsigned b3 : 1;
unsigned b4 : 1;
unsigned b5 : 1;
unsigned b6 : 1;
unsigned b7 : 1;
} BITS;
int i;
BITS crc, xd, j;
uchar *pCrc, *pXd;
uchar *p;
p = pWorkString; /* -> first byte of Work String */
*p = 0x80; /* Initialize CRC7 byte in string */
pCrc = (uchar *) &crc; /* get around type checking */
pXd = (uchar *) &xd; /* or using a using a Union */
*pXd = *pCrc = 0; /* Initialize CRC7 byte */
for (i = 0; i < 16; i++, p++)
{
#if(0) /* Replace this */
memcpy (&j, p, 1); /* sizeof (j) is 1 byte */
#endif
*((uchar*)&j) = *p;
*pXd = (uchar) (*p ^ *pCrc);
crc.b7 = xd.b7 ^ xd.b6 ^ xd.b3;
crc.b6 = xd.b6 ^ xd.b5 ^ xd.b2;
crc.b5 = xd.b5 ^ xd.b4 ^ xd.b1;
crc.b4 = xd.b4 ^ xd.b3 ^ j.b0;
crc.b3 = xd.b6 ^ xd.b2;
crc.b2 = xd.b5 ^ xd.b1;
crc.b1 = xd.b7 ^ xd.b4 ^ j.b0;
}
*pCrc = (uchar) (*pCrc >> 1);
*pCrc |= 0x80; /* Set MSB to identify CRC7 byte*/
*pWorkString = *pCrc; /* Insert CRC7 at start of Work String */
} /* end bb_InsertCRC7 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -