typedef void (pfExtFunc)(void args); typedef struct tagExtFuncNode { uint32 intId; /*…
- User
typedef void (*pfExtFunc)(void args); typedef struct tagExtFuncNode { uint32 intId; / 中断ID / pfExtFunc func; / 注册回调函数 */ char funcName; / 函数名称 */ void args; / 回调函数入参 */ struct tagExtFuncNode next; / next节点 */ } stExtFuncNode; void RegExtFuncToInt(eINT_ID intId, pfExtFunc func, void *args, const char *funcName) { if (intId >= INT_COUNT) { return; } stExtFuncNode newNode = (stExtFuncNode)calloc(1, sizeof(stExtFuncNode)); newNode->intId = intId; newNode->func = func; strcpy(newNode->funcName, funcName); newNode->args = args; newNode->next = g_extFuncList[intId].head; g_extFuncList[intId].head = newNode; return; }
- Assistant
The function
RegExtFuncToIntis used to register a callback function to a specified interrupt ID. The function takes the following arguments:intId: The interrupt ID.func: A pointer to the callback function.args: Arguments to be passed to the callback function.funcName: The name of the callback function.
The function first checks if the interrupt ID is within the valid range (
INT_COUNT). If it is outside the range, the function returns without registering the callback function.If the interrupt ID is valid, the function dynamically allocates memory for a new
stExtFuncNodestructure usingcalloc. The interrupt ID, callback function, function name, arguments, andnextpointer are set in the new structure.The
nextpointer of the new node is then set to point to the current head of the list for the specified interrupt ID. Finally, the new node becomes the new head of the list for that interrupt ID.Note that
g_extFuncListis assumed to be a global array of structures, where each structure represents a linked list of callback functions for a specific interrupt ID.The function does not return a value.