📄 bmi.c
字号:
}
A_MEMCPY(param, data, sizeof(*param));
BMI_DEBUG_PRINTF(ATH_LOG_INF,"BMI Execute: Exit (param: %d)\n", *param);
return A_OK;
}
A_STATUS
BMISetAppStart(HIF_DEVICE *device,
A_UINT32 address)
{
A_UINT32 cid;
A_STATUS status;
A_UINT32 offset;
A_UCHAR data[sizeof(cid) + sizeof(address)];
if (bmiDone) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"Command disallowed\n");
return A_ERROR;
}
BMI_DEBUG_PRINTF(ATH_LOG_INF,
"BMI Set App Start: Enter (device: 0x%p, address: 0x%x)\n",
device, address);
cid = BMI_SET_APP_START;
offset = 0;
A_MEMCPY(&data[offset], &cid, sizeof(cid));
offset += sizeof(cid);
A_MEMCPY(&data[offset], &address, sizeof(address));
offset += sizeof(address);
status = bmiBufferSend(device, data, offset);
if (status != A_OK) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"Unable to write to the device\n");
return A_ERROR;
}
BMI_DEBUG_PRINTF(ATH_LOG_INF,"BMI Set App Start: Exit\n");
return A_OK;
}
A_STATUS
BMIReadSOCRegister(HIF_DEVICE *device,
A_UINT32 address,
A_UINT32 *param)
{
A_UINT32 cid;
A_STATUS status;
A_UINT32 offset;
A_UCHAR data[sizeof(cid) + sizeof(address)];
if (bmiDone) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"Command disallowed\n");
return A_ERROR;
}
BMI_DEBUG_PRINTF(ATH_LOG_INF,
"BMI Read SOC Register: Enter (device: 0x%p, address: 0x%x)\n",
device, address);
cid = BMI_READ_SOC_REGISTER;
offset = 0;
A_MEMCPY(&data[offset], &cid, sizeof(cid));
offset += sizeof(cid);
A_MEMCPY(&data[offset], &address, sizeof(address));
offset += sizeof(address);
status = bmiBufferSend(device, data, offset);
if (status != A_OK) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"Unable to write to the device\n");
return A_ERROR;
}
status = bmiBufferReceive(device, data, sizeof(*param));
if (status != A_OK) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"Unable to read from the device\n");
return A_ERROR;
}
A_MEMCPY(param, data, sizeof(*param));
BMI_DEBUG_PRINTF(ATH_LOG_INF,"BMI Read SOC Register: Exit (value: %d)\n", *param);
return A_OK;
}
A_STATUS
BMIWriteSOCRegister(HIF_DEVICE *device,
A_UINT32 address,
A_UINT32 param)
{
A_UINT32 cid;
A_STATUS status;
A_UINT32 offset;
A_UCHAR data[sizeof(cid) + sizeof(address) + sizeof(param)];
if (bmiDone) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"Command disallowed\n");
return A_ERROR;
}
BMI_DEBUG_PRINTF(ATH_LOG_INF,
"BMI Write SOC Register: Enter (device: 0x%p, address: 0x%x, param: %d)\n",
device, address, param);
cid = BMI_WRITE_SOC_REGISTER;
offset = 0;
A_MEMCPY(&data[offset], &cid, sizeof(cid));
offset += sizeof(cid);
A_MEMCPY(&data[offset], &address, sizeof(address));
offset += sizeof(address);
A_MEMCPY(&data[offset], ¶m, sizeof(param));
offset += sizeof(param);
status = bmiBufferSend(device, data, offset);
if (status != A_OK) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"Unable to write to the device\n");
return A_ERROR;
}
BMI_DEBUG_PRINTF(ATH_LOG_INF,"BMI Read SOC Register: Exit\n");
return A_OK;
}
/* BMI Access routines */
A_STATUS
bmiBufferSend(HIF_DEVICE *device,
A_UCHAR *buffer,
A_UINT32 length)
{
A_STATUS status;
A_UINT32 timeout;
A_UINT32 address;
#ifdef ONLY_16BIT
A_UINT16 cmdCredits;
#else
A_UCHAR cmdCredits;
#endif
HIF_REQUEST request;
/* Read the counter register to get the command credits */
HIF_FRAME_REQUEST(&request, HIF_READ, HIF_EXTENDED_IO, HIF_SYNCHRONOUS,
HIF_BYTE_BASIS, HIF_FIXED_ADDRESS);
address = COUNT_DEC_ADDRESS + (HTC_MAILBOX_NUM_MAX + ENDPOINT1) * 4;
status = HIFReadWrite(device, address, (A_UCHAR *)&cmdCredits,
sizeof(cmdCredits), &request, NULL);
if (status != A_OK) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"Unable to decrement the command credit count register\n");
return A_ERROR;
}
timeout = BMI_COMMUNICATION_TIMEOUT;
while(timeout--) {
if (cmdCredits == 1) {
HIF_FRAME_REQUEST(&request, HIF_WRITE, HIF_EXTENDED_IO,
HIF_SYNCHRONOUS, HIF_BYTE_BASIS,
HIF_INCREMENTAL_ADDRESS);
address = HIF_MBOX_START_ADDR(ENDPOINT1);
status = HIFReadWrite(device, address, buffer, length,
&request, NULL);
if (status != A_OK) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"Unable to send the BMI data to the device\n");
return A_ERROR;
}
break;
}
HIF_FRAME_REQUEST(&request, HIF_READ, HIF_EXTENDED_IO, HIF_SYNCHRONOUS,
HIF_BYTE_BASIS, HIF_FIXED_ADDRESS);
address = COUNT_DEC_ADDRESS + (HTC_MAILBOX_NUM_MAX + ENDPOINT1) * 4;
status = HIFReadWrite(device, address, (A_UCHAR *)&cmdCredits,
sizeof(cmdCredits), &request, NULL);
if (status != A_OK) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"Unable to decrement the command credit count register\n");
return A_ERROR;
}
status = A_ERROR;
A_MDELAY(1);
}
if (status != A_OK) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"BMI Communication timeout\n");
}
return status;
}
A_STATUS
bmiBufferReceive(HIF_DEVICE *device,
A_UCHAR *buffer,
A_UINT32 length)
{
A_STATUS status;
A_UINT32 address;
A_UINT32 timeout;
#ifdef ONLY_16BIT
A_UINT16 cmdCredits;
#else
A_UCHAR cmdCredits;
#endif
HIF_REQUEST request;
HIF_FRAME_REQUEST(&request, HIF_READ, HIF_EXTENDED_IO, HIF_SYNCHRONOUS,
HIF_BYTE_BASIS, HIF_FIXED_ADDRESS);
address = COUNT_ADDRESS + (HTC_MAILBOX_NUM_MAX + ENDPOINT1) * 1;
status = HIFReadWrite(device, address, (A_UCHAR *)&cmdCredits,
sizeof(cmdCredits), &request, NULL);
if (status != A_OK) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"Unable to decrement the command credit count register\n");
return A_ERROR;
}
timeout = BMI_COMMUNICATION_TIMEOUT;
while(timeout--) {
if (cmdCredits == 1) {
HIF_FRAME_REQUEST(&request, HIF_READ, HIF_EXTENDED_IO,
HIF_SYNCHRONOUS, HIF_BYTE_BASIS,
HIF_FIXED_ADDRESS);
address = HIF_MBOX_END_ADDR(ENDPOINT1);
status = HIFReadWrite(device, address, buffer, length,
&request, NULL);
if (status != A_OK) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"Unable to read the BMI data from the device\n");
return A_ERROR;
}
break;
}
HIF_FRAME_REQUEST(&request, HIF_READ, HIF_EXTENDED_IO, HIF_SYNCHRONOUS,
HIF_BYTE_BASIS, HIF_FIXED_ADDRESS);
address = COUNT_ADDRESS + (HTC_MAILBOX_NUM_MAX + ENDPOINT1) * 1;
status = HIFReadWrite(device, address, (A_UCHAR *)&cmdCredits,
sizeof(cmdCredits), &request, NULL);
if (status != A_OK) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"Unable to decrement the command credit count register\n");
return A_ERROR;
}
status = A_ERROR;
A_MDELAY(1);
}
if (status != A_OK) {
BMI_DEBUG_PRINTF(ATH_LOG_ERR,"BMI Communication timeout\n");
}
return status;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -