Part Number: CC2640R2F
Tool/software: TI C/C++ Compiler
the code block not to be optimized:
GPIO_setOutputEnableDio(IOID_8, GPIO_OUTPUT_ENABLE); //HWREGBITW( GPIO_BASE + GPIO_O_DOE31_0, IOID_8 ) = GPIO_OUTPUT_ENABLE; //
GPIO_setOutputEnableDio(IOID_8, GPIO_OUTPUT_DISABLE);//HWREGBITW( GPIO_BASE + GPIO_O_DOE31_0, IOID_8 ) = GPIO_OUTPUT_DISABLE; //
IOCIOInputSet(IOID_8, IOC_INPUT_ENABLE); //gpioEnableInputBuf(Board_DIO8);
scifTaskData.task0.output.buzz = GPIO_readDio(IOID_8); //gpioGetInputValue(Board_DIO8; output.buzz);
//GPIO_clearDio(IOID_8); //gpioClearOutput(Board_DIO8);
IOCIOInputSet(IOID_8, IOC_INPUT_DISABLE); //gpioDisableInputBuf(Board_DIO8);
if the project optimization is set to none, the code work as expected. with any optimization , the code does not work as expected. it seems the 1st line of the first 2 lines was optimized off, but this 2 lines are critical for the code to work,as the 1st line is to charge a capacitor and the 2nd line is to discharge the capacitor, so that a great change of a serial resistor could be detected.
and optimization for code size is prefered, so only need to prevent the compiler from optimizing several lines of code.
the related functions defined in the sdk:
__STATIC_INLINE void
GPIO_setOutputEnableDio( uint32_t dioNumber, uint32_t outputEnableValue )
{
// Check the arguments.
ASSERT( dioNumberLegal( dioNumber ));
ASSERT(( outputEnableValue == GPIO_OUTPUT_DISABLE ) ||
( outputEnableValue == GPIO_OUTPUT_ENABLE ) );
// Update the output enable bit for the specified DIO.
HWREGBITW( GPIO_BASE + GPIO_O_DOE31_0, dioNumber ) = outputEnableValue;
}
__STATIC_INLINE void
GPIO_setOutputEnableDio( uint32_t dioNumber, uint32_t outputEnableValue )
{
// Check the arguments.
ASSERT( dioNumberLegal( dioNumber ));
ASSERT(( outputEnableValue == GPIO_OUTPUT_DISABLE ) ||
( outputEnableValue == GPIO_OUTPUT_ENABLE ) );
// Update the output enable bit for the specified DIO.
HWREGBITW( GPIO_BASE + GPIO_O_DOE31_0, dioNumber ) = outputEnableValue;
}