目錄
安安
最近使用TI C2000系列為控制器時,為了講求執行時的效率,除了有限的精簡source code之外,還要再擠出更多速度,可以從Compiler 或Linker下手。{alertSuccess}
這份文件就講述TI的編譯器有哪些選項可以最佳化你的程式碼,當然TI的Toolchain也是從GNU Toolchain修改而來,因此大致看完文件也可以理解Source Code在編譯的時候有哪些參數可以調整,滿有趣的。
編譯器最佳化指南
在TI官方提供的的文件中,有一份Compiler Optimize Guide的文件,說明如何使用這份文件說明編譯器最佳化的重要性不只在編譯器最佳化,更要針對編譯器最佳化進行編譯器最佳化{alertSuccess}
這份文件就講述TI的編譯器有哪些選項可以最佳化你的程式碼,當然TI的Toolchain也是從GNU Toolchain修改而來,因此大致看完文件也可以理解Source Code在編譯的時候有哪些參數可以調整,滿有趣的。
{getButton} $text={下載設計圖檔} $icon={download} $color={0xe1ba31}原始碼範例
用Template內建的code block功能看起來像這樣PMBUS_STACK_FILENUM(1) #define PMBUS_STACK_TARGET_ADDRESS 0U #define PMBUS_STACK_TARGET_MASK 0x7FU //***************************************************************************** // // PMBusStack_initModule // //***************************************************************************** bool PMBusStack_initModule(PMBus_StackHandle handle, const uint32_t moduleBase, uint16_t *buffer) { // // Locals // bool status = false; // // Set the module base address // PMBusStackObject_setModuleBase(handle, moduleBase); // // Assign the buffer pointer to the object, set the current pointer to // the head of the buffer // PMBusStackObject_setBufferPointer(handle, buffer); PMBusStackObject_setCurrentPositionPointer(handle, buffer); // // Reset the PMBUS Module // PMBus_disableModule(PMBusStackObject_getModuleBase(handle)); // // Take the PMBUS out of reset // PMBus_enableModule(PMBusStackObject_getModuleBase(handle)); // // Initialize depending upon whether in target or controller mode // if(PMBusStackObject_getMode(handle) == PMBUS_STACK_MODE_TARGET) { // // Initialize the target module // PMBus_initTargetMode(PMBusStackObject_getModuleBase(handle), PMBusStackObject_getTargetAddress(handle), PMBusStackObject_getTargetAddressMask(handle)); // // Configure the target module (writes to the PMBSC register) // PMBus_configTarget(PMBUSA_BASE, (PMBUS_TARGET_ENABLE_PEC_PROCESSING | PMBUS_TARGET_AUTO_ACK_4_BYTES)); // // Enable interrupts // //I2C - AAS, FIFO Interrupts RX & TX , STOP PMBus_enableInterrupt(PMBusStackObject_getModuleBase(handle), (PMBUS_INT_DATA_READY | PMBUS_INT_DATA_REQUEST | PMBUS_INT_EOM)); // // Reset the state machine // PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_IDLE); PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE); status = true; } else // (PMBusStackObject_getMode(handle) == PMBUS_STACK_MODE_CONTROLLER) { // // Zero out the target address and set the mask to 0x7F // (the mask is N/A in controller mode) // PMBusStackObject_setTargetAddress(handle, PMBUS_STACK_TARGET_ADDRESS); PMBusStackObject_setTargetAddressMask(handle, PMBUS_STACK_TARGET_MASK); // // Initialize the controller module // PMBus_initControllerMode(PMBusStackObject_getModuleBase(handle)); // // Enable interrupts // PMBus_enableInterrupt(PMBusStackObject_getModuleBase(handle), (PMBUS_INT_DATA_READY | PMBUS_INT_DATA_REQUEST | PMBUS_INT_EOM | PMBUS_INT_ALERT)); // // Reset the state machine // PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_IDLE); PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE); status = true; } return(status); }{codeBox}用CHATGPT建議的方式看起來像這樣
PMBUS_STACK_FILENUM(1)
#define PMBUS_STACK_TARGET_ADDRESS 0U
#define PMBUS_STACK_TARGET_MASK 0x7FU
//*****************************************************************************
//
// PMBusStack_initModule
//
//*****************************************************************************
bool PMBusStack_initModule(PMBus_StackHandle handle, const uint32_t moduleBase,
uint16_t *buffer)
{
//
// Locals
//
bool status = false;
//
// Set the module base address
//
PMBusStackObject_setModuleBase(handle, moduleBase);
//
// Assign the buffer pointer to the object, set the current pointer to
// the head of the buffer
//
PMBusStackObject_setBufferPointer(handle, buffer);
PMBusStackObject_setCurrentPositionPointer(handle, buffer);
//
// Reset the PMBUS Module
//
PMBus_disableModule(PMBusStackObject_getModuleBase(handle));
//
// Take the PMBUS out of reset
//
PMBus_enableModule(PMBusStackObject_getModuleBase(handle));
//
// Initialize depending upon whether in target or controller mode
//
if(PMBusStackObject_getMode(handle) == PMBUS_STACK_MODE_TARGET)
{
//
// Initialize the target module
//
PMBus_initTargetMode(PMBusStackObject_getModuleBase(handle),
PMBusStackObject_getTargetAddress(handle),
PMBusStackObject_getTargetAddressMask(handle));
//
// Configure the target module (writes to the PMBSC register)
//
PMBus_configTarget(PMBUSA_BASE, (PMBUS_TARGET_ENABLE_PEC_PROCESSING |
PMBUS_TARGET_AUTO_ACK_4_BYTES));
//
// Enable interrupts
//
//I2C - AAS, FIFO Interrupts RX & TX , STOP
PMBus_enableInterrupt(PMBusStackObject_getModuleBase(handle),
(PMBUS_INT_DATA_READY | PMBUS_INT_DATA_REQUEST |
PMBUS_INT_EOM));
//
// Reset the state machine
//
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_IDLE);
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
status = true;
}
else // (PMBusStackObject_getMode(handle) == PMBUS_STACK_MODE_CONTROLLER)
{
//
// Zero out the target address and set the mask to 0x7F
// (the mask is N/A in controller mode)
//
PMBusStackObject_setTargetAddress(handle, PMBUS_STACK_TARGET_ADDRESS);
PMBusStackObject_setTargetAddressMask(handle, PMBUS_STACK_TARGET_MASK);
//
// Initialize the controller module
//
PMBus_initControllerMode(PMBusStackObject_getModuleBase(handle));
//
// Enable interrupts
//
PMBus_enableInterrupt(PMBusStackObject_getModuleBase(handle),
(PMBUS_INT_DATA_READY | PMBUS_INT_DATA_REQUEST |
PMBUS_INT_EOM | PMBUS_INT_ALERT));
//
// Reset the state machine
//
PMBusStackObject_setCurrentState(handle, PMBUS_STACK_STATE_IDLE);
PMBusStackObject_setNextState(handle, PMBUS_STACK_STATE_IDLE);
status = true;
}
return(status);
}
張貼留言
留個言吧