来自TI的ek-tm4c123gxl usb-dev-gamepad CCS示例的代码在中断禁用/启用对中将易失性枚举赋值包装到g_iGamepadState。对我来说,它看起来像一个bug;它应该包装发送报告功能USBDHIDGamepadSendReport()以防止中间发送中断。我认为这样可以防止单个存储指令的中断,这将是多余的。
以下是引用枚举的所有代码......
volatile enum {
eStateNotConfigured, // Not yet configured.
eStateIdle, // Connected, not waiting on data to be sent
eStateSuspend, // Suspended
eStateSending // Connected, waiting on data to be sent out
} g_iGamepadState;
...
//*****************************************************************************
//
// Handles asynchronous events from the HID gamepad driver.
//
// \param pvCBData is the event callback pointer provided during
// USBDHIDGamepadInit(). This is a pointer to our gamepad device structure
// (&g_sGamepadDevice).
// \param ui32Event identifies the event we are being called back for.
// \param ui32MsgData is an event-specific value.
// \param pvMsgData is an event-specific pointer.
//
// This function is called by the HID gamepad driver to inform the application
// of particular asynchronous events related to operation of the gamepad HID
// device.
//
// \return Returns 0 in all cases.
//
//*****************************************************************************
uint32_t GamepadHandler(void *pvCBData, uint32_t ui32Event,
uint32_t ui32MsgData, void *pvMsgData) {
switch (ui32Event) {
case USB_EVENT_CONNECTED: {
g_iGamepadState = eStateIdle;
break;
}
case USB_EVENT_DISCONNECTED: {
g_iGamepadState = eStateNotConfigured;
break;
}
case USB_EVENT_TX_COMPLETE: {
g_iGamepadState = eStateIdle;
break;
}
case USB_EVENT_SUSPEND: {
g_iGamepadState = eStateSuspend;
break;
}
case USB_EVENT_RESUME: {
g_iGamepadState = eStateIdle;
break;
}
...
default: {
break;
}
}
return (0);
}
...
int main(void) {
...
// Not configured initially.
g_iGamepadState = eStateNotConfigured;
...
while (1) {
//
// Wait here until USB device is connected to a host.
//
if (g_GamepadState == eStateIdle) {
...
USBDHIDGamepadSendReport(&g_sGamepadDevice, &sReport,
sizeof(sReport));
//
// Now sending data but protect this from an interrupt since
// it can change in interrupt context as well.
//
IntMasterDisable();
g_iGamepadState = eStateSending;
IntMasterEnable();
}
}
}
答案 0 :(得分:0)
来自TI的E2E forum ...
我认为你是对的。这可能是一个错误。
空闲TX事件可能会在发送报告和更改为发送状态枚举之间返回,这将永远不会离开发送状态。这个解释似乎最有效地解释了为什么禁用/启用中断对首先存在。