The application discloses an RTOS task hook type
adaptation method based on a compiling period static trampoline
function table, and comprises the following steps: S1, a compiling period presetting stage; S2, a running period binding stage; S3, a running period calling stage; and S4, a running period canceling stage. According to the application, a static trampoline function is pre-generated in the compiling period, all codes are solidified to a read-only Flash area after being compiled, and any code does not need to be generated in the
running time, so that the contradiction between the
running time code generation and the MCU hardware characteristics is fundamentally solved, the
system complexity and the Flash occupation are reduced, a one-to-one mapping relationship between a user hook function and the trampoline function is established through a bidirectional binding table, and when being canceled, the corresponding slot can be reversely positioned only through the user hook
function pointer, the whole hook
list does not need to be traversed, the
time complexity is O (n), the real-
time loss of a traditional dynamic link table scheme is eliminated, and the resource leakage and the hook residual problem are avoided.