gpt4 book ai didi

c - TI 游戏 handle 示例项目中的这个中断禁用/启用对有什么作用吗?

转载 作者:行者123 更新时间:2023-11-30 16:50:31 25 4
gpt4 key购买 nike

此代码来自 TI 的 ek-tm4c123gxl usb-dev-gamepad CCS 示例,将 volatile 枚举分配给 g_iGamepadState 包装在中断禁用/启用对中。对我来说,它看起来像一个错误;它应该包装发送报告函数 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();
}
}
}

最佳答案

来自 TI 的 E2E forum ...

I think you are correct. This may be a bug.

空闲 TX 事件有可能在发送报告和更改为发送状态枚举之间返回,这样就永远不会离开发送状态。对于为什么禁用/启用中断对首先存在的原因,这个解释似乎最有意义。

关于c - TI 游戏 handle 示例项目中的这个中断禁用/启用对有什么作用吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42183106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com