最近调试了TPS6594-Q1的Wdg功能,上篇说了Wdg的禁用功能,这篇先说一下Wdg在Q&A模式下获取Answer的方法;
前提:
我没有自己去修改Question的配置,都是用的默认配置,所以看具体情况;话不多说,看代码
uint8_t appPmicGetWdgAnswer(uint8_t wdgQuestionVal, uint8_t wdgAnswerX)
{
uint8_t i = 0;
uint8_t tempVal[2];
uint8_t tempData[8];
uint8_t wdgAnswer = 0;
switch(wdgAnswerX)
{
case 0:
tempVal[0] = 0;
tempVal[1] = 0;
break;
case 1:
tempVal[0] = 1;
tempVal[1] = 0;
break;
case 2:
tempVal[0] = 0;
tempVal[1] = 1;
break;
case 3:
tempVal[0] = 1;
tempVal[1] = 1;
break;
default:
break;
}
for(i = 0; i < 4; i++)
{
tempData[i] = (wdgQuestionVal >> i) & 0x01;
}
wdgAnswer = wdgAnswer | ((tempData[3] ^ tempVal[1]) ^ tempData[0]);
wdgAnswer = wdgAnswer | (((tempData[1] ^ tempData[2]) ^ tempData[0] ^ tempVal[1]) << 1);
wdgAnswer = wdgAnswer | (((tempData[1] ^ tempData[3]) ^ tempData[0] ^ tempVal[1]) << 2);
wdgAnswer = wdgAnswer | (((tempData[0] ^ tempData[3]) ^ tempData[2] ^ tempVal[1]) << 3);
wdgAnswer = wdgAnswer | ((tempData[1] ^ tempVal[0]) << 4);
wdgAnswer = wdgAnswer | ((tempData[3] ^ tempVal[0]) << 5);
wdgAnswer = wdgAnswer | ((tempData[0] ^ tempVal[0]) << 6);
wdgAnswer = wdgAnswer | ((tempData[2] ^ tempVal[0]) << 7);
appLogPrintf("wdgAnswer = %x\r\n", wdgAnswer);
return wdgAnswer;
}
根据手册,将question值和Answer count值输入即可得出Answer值;
根据手册,一个wdg周期,我们需要按时序分别输入Answer3,Answer2,Answer1,Answer0;所以我们一个周期需要调用这个函数4次,4次的参数分别为:(wdgQuestionVal,wdgAnswer3),(wdgQuestionVal,wdgAnswer2),(wdgQuestionVal,wdgAnswer1),(wdgQuestionVal,wdgAnswer0);
不好意思,表述能力有点差,凑合看,如果能帮到您的话点个赞,有什么疑问可以留言。
声明:有任何版权问题请联系我。