📄 boardid.c
字号:
/******************************************************************************
*
/*******************************************************************************
*
* Motorola Inc.
* (c) Copyright 2000 Motorola, Inc.
* ALL RIGHTS RESERVED.
*
********************************************************************************
*
* FILE NAME: boardId.c
*
*******************************************************************************/
#include "types.h"
#include "arch.h"
#include "periph.h"
#include "occs.h"
#include "gpio.h"
#include "qtimer.h"
#include "boardId.h"
#define MTREVM_TIM_AR_LEN 5
inline static int GetPinID(char uni3, int port)
{
return (((uni3==BOARDID_PRIMARY_UNI3) ? (ioctl( port, GPIO_READ_DATA, NULL) & BIT_7) \
: (ioctl( port, GPIO_READ_DATA, NULL) & BIT_7)));
}
#if 0
/* initialization */
qt_sState tmrSTR = {
/* Mode = */ qtCount,
/* InputSource = */ qtPrescalerDiv128,
/* InputPolarity = */ qtNormal,
/* SecondaryInputSource = */ 0,
/* CountFrequency = */ qtRepeatedly,
/* CountLength = */ qtPastCompare,
/* CountDirection = */ qtUp,
/* OutputMode = */ qtAssertWhileActive,
/* OutputPolarity = */ qtNormal,
/* OutputDisabled = */ true,
/* Master = */ false,
/* OutputOnMaster = */ false,
/* CoChannelInitialize = */ false,
/* AssertWhenForced = */ false,
/* CaptureMode = */ qtDisabled,
/* CompareValue1 = */ 0,
/* CompareValue2 = */ 0,
/* InitialLoadValue = */ 0,
/* CallbackOnCompare = */ { 0, 0 },
/* CallbackOnOverflow = */ { 0, 0 },
/* CallbackOnInputEdge = */ { 0, 0 }
};
#endif
void boardId(const char uni3name, boardId_sBoardId *pParams)
{
/* Initialization of the timer driver*/
unsigned int i,j,q,tim_str,tim,dtim2,dtim1;
unsigned int tim_ar[MTREVM_TIM_AR_LEN];
unsigned int data[3];
unsigned int timeout,brdide_evm_jitter,brd_strb_max,brd_strb_min;
int stat;
int portID;
long busclk;
UInt32 QtInputFrequency;
int tmp;
stat=BOARDID_STAT_OK;
/* timer initialization */
ioctl(QTIMER_A0, QT_WRITE_CONTROL_REG, 0x3e00);
QtInputFrequency = ioctl(OCCS, OCCS_GET_IPBUS_FREQ, 8000000L);
busclk=QtInputFrequency/100000l; /* busclk = IPbusclk [100kHz] */
/* setup of varibles based on IP bus frequency */
timeout=120*busclk;
brd_strb_min=(15*busclk)/100;
brd_strb_max=(19*busclk)/100;
brdide_evm_jitter=(busclk/100)+1;
/* Initialization of the input pin driver*/
portID = ( uni3name == BOARDID_PRIMARY_UNI3 ? (int)(GPIO_D) : (int)(GPIO_B));
/* Setup of the pin */
ioctl(portID ,GPIO_SETAS_INPUT,BIT_7);
ioctl(portID, GPIO_PULLUP_DISABLE,BIT_7);
ioctl(portID,GPIO_SETAS_GPIO,BIT_7);
/* Identification routine begin */
/* EVM MOTOR board identification routine begin */
ioctl(QTIMER_A0,QT_WRITE_COUNTER_REG,0); /* timer is cleared due to possible timer overrun */
tim_str=ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0);
/* Wait for the first edge on the pin */
tmp = GetPinID(uni3name,portID);
while( (!tmp) && (stat==BOARDID_STAT_OK) )
{ /* wait for pin comes high */
if((tim_str+timeout)<ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0))
{
stat=BOARDID_STAT_TIOUT;
}
}
/* Catch time for MTREVM_TIM_AR_LEN pulses */
for(i=0;(i<MTREVM_TIM_AR_LEN)&&(stat==BOARDID_STAT_OK);i++)
{
j=GetPinID(uni3name,portID);
ioctl(QTIMER_A0,QT_WRITE_COUNTER_REG,0); /* timer is cleared due to possible timer overrun */
tim=ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0);
while( (j==GetPinID(uni3name,portID)) && (stat==BOARDID_STAT_OK) )
{
/* did not get any input edge within timeout window */
if((tim+timeout)<ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0))
{
stat=BOARDID_STAT_TIOUT;
}
}
tim_ar[i]=ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0)-tim;
tim+=tim_ar[i];
/* if input pulse is shorter then expected MTREVM identification signal */
/* then write wrong data to indicate different type of the board */
if(tim_ar[i]<brd_strb_max) tim_ar[MTREVM_TIM_AR_LEN-4]+=2*brd_strb_max;
}
/* test of the catched times to identify EVM MOTOR board */
if( (tim_ar[MTREVM_TIM_AR_LEN-4]<(tim_ar[MTREVM_TIM_AR_LEN-2]+brdide_evm_jitter))&&
(tim_ar[MTREVM_TIM_AR_LEN-4]>(tim_ar[MTREVM_TIM_AR_LEN-2]-brdide_evm_jitter))&&
(tim_ar[MTREVM_TIM_AR_LEN-3]<(tim_ar[MTREVM_TIM_AR_LEN-1]+brdide_evm_jitter))&&
(tim_ar[MTREVM_TIM_AR_LEN-3]>(tim_ar[MTREVM_TIM_AR_LEN-1]-brdide_evm_jitter))&&
(stat==BOARDID_STAT_OK) )
{
/* EVM Motor board identified */
data[0]=BOARDID_MTR_EVM;
data[1]=0;
data[2]=BOARDID_STAT_OK;
stat=BOARDID_STAT_OK;
goto FINAL_STAGE;
}
/* MCU coded identification routine begin */
/* This part try to receive MCU coded identification message */
/* Used for High Voltage AC/BLDC Power Stage (PS), High Voltage SR PS */
/* Low Voltage AC/BLDC PS, Low Voltage SR PS, Optoisolation Board .... */
data[0]=data[1]=data[2]=0;
q=0;
ioctl(QTIMER_A0,QT_WRITE_COUNTER_REG,0); /* timer is cleared due to possible timer overrun */
tim=ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0);
while( (!(GetPinID(uni3name,portID))) && (stat==BOARDID_STAT_OK) )
{ /* wait for pin comes high */
if((ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0)-tim)>timeout)
{
stat=BOARDID_STAT_TIOUT;
}
}
while( (GetPinID(uni3name,portID)) && (stat==BOARDID_STAT_OK) )
{ /* wait for pin comes low */
if((ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0)-tim)>timeout)
{
stat=BOARDID_STAT_TIOUT;
}
}
/* start bit waiting cycle */
while( (!q) && (stat==BOARDID_STAT_OK) )
{
ioctl(QTIMER_A0,QT_WRITE_COUNTER_REG,0); /* timer is cleared due to possible timer overrun */
tim_str=tim=ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0);
j=GetPinID(uni3name,portID);
while( (j==GetPinID(uni3name,portID)) && (stat==BOARDID_STAT_OK) )
{
/* did not get any input edge within timeout window */
if((ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0)-tim)>timeout)
{
stat=BOARDID_STAT_TIOUT;
}
}
dtim1=ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0)-tim;
tim+=dtim1;
j=GetPinID(uni3name,portID);
while( (j==GetPinID(uni3name,portID)) && (stat==BOARDID_STAT_OK) )
{
/* did not get any input edge within timeout window */
if((ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0)-tim)>timeout)
{
stat=BOARDID_STAT_TIOUT;
}
}
dtim2=ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0)-tim;
tim+=dtim2;
/* did not get valid start bit within timeout window */
if((tim-tim_str)>timeout)
{
stat=BOARDID_STAT_ERROR;
}
if((dtim1>=brd_strb_min)&&(dtim1<=brd_strb_max)&&(dtim2>=brd_strb_min)&&(dtim2<=brd_strb_max)) q++;
}
/* 3 identification bytes receive cycle */
ioctl(QTIMER_A0,QT_WRITE_COUNTER_REG,0); /* timer is cleared due to possible timer overrun */
tim=ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0);
i=q=0;
while( (i<3) && (stat==BOARDID_STAT_OK) )
{
j=GetPinID(uni3name,portID);
while( (j==GetPinID(uni3name,portID)) && (stat==BOARDID_STAT_OK) )
{
/* did not get any input edge within timeout window */
if((ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0)-tim)>timeout)
{
stat=BOARDID_STAT_TIOUT;
}
}
dtim1=ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0)-tim;
tim+=dtim1;
j=GetPinID(uni3name,portID);
while( (j==GetPinID(uni3name,portID)) && (stat==BOARDID_STAT_OK) )
{
/* did not get any input edge within timeout window */
if((ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0)-tim)>timeout)
{
stat=BOARDID_STAT_TIOUT;
}
}
dtim2=ioctl(QTIMER_A0,QT_READ_COUNTER_REG,0)-tim;
tim+=dtim2;
data[i]>>=1;
data[i]+=(dtim1>dtim2)?0x80:0x0;
if(++q>=8)
{
q=0;
i++;
}
}
/* Identification routine end */
FINAL_STAGE:
if(stat==BOARDID_STAT_OK)
{
/* decode received message and fill the structure */
pParams->brd1IDcode=data[0]&0x0F;
pParams->brd1special=(data[0]&0x80)?BOARDID_BRD_STANDARD:BOARDID_BRD_SPECIAL;
pParams->brd1power=(data[0]&0x70)>>4;
pParams->brd2IDcode=data[1]&0x0F;
pParams->brd2special=(data[1]&0x80)?BOARDID_BRD_STANDARD:BOARDID_BRD_SPECIAL;
pParams->brd2Scode=(data[1]&0x70)>>4;
pParams->stat1=data[2];
}
else
{
/* clear structure if any problem occuered */
pParams->brd1IDcode=0;
pParams->brd1special=0;
pParams->brd1power=0;
pParams->brd2IDcode=0;
pParams->brd2special=0;
pParams->brd2Scode=0;
pParams->stat1=0;
}
pParams->stat2=stat;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -