Let me open with the statement that I am not a C++/C programmer. The environment that I am programming in is ARMbasic, an embedded BASIC targeted toward ARM-based micro-controllers. So why am I posting herein? Well, the ARMbasic environment makes use of a tool borrowed from your folk's environment - CPP. The build details are:
Expand|Select|Wrap|Line Numbers
- C:\Program Files\Coridium>cpp --version
- cpp (GCC) 3.2.3 (mingw special 20030504-1)
- Copyright (C) 2002 Free Software Foundation, Inc.
My question is this: Is there a way to get a proprocessor macro to expand to multiple lines of code?
Scenario: I have a function created where the internal Analog to Digital Converter is queried and the integer result is returned. On the target that I am programming (an NXP 2103 micro), the ADC converter is able to run at 4.5 MHZ (or less) - this equates to approx 3us if coded in ASM. If coded in C (by the ARMbasic developer), the read time is ~5us. With my ARMbasic function, due to system overhead, etc., my function is taking 11us. This is acceptable in most cases, but I have a peer that is needing higher throughput.
If I manually code my ADC reads in-line, via 2 POKES, 2 PEEKS and 1 conditional loop per ADC read, I can get the acquisition time down to 8us. The target, in this case of helping my peer out, is to get the code down to <=10us. So, the problem is solvable by manually coding in a bunch of in-line pokes/peeks. However, with the Preprocessor, it seems that I could substitute in-line code vs. the function calls by simply #define-ing a new in-line ADC input routine:
==================================================
CURRENT IMPLEMENTATION
==================================================
Current Function:
Expand|Select|Wrap|Line Numbers
- Function AD (channel as integer) as integer
- CALL POKE (AD_ADCR, ((1 << channel) + AD_ENABLE))
- CALL POKE (AD_ADCR, ((1 << channel) + AD_START))
- DO
- UNTIL (PEEK(AD_ADGDR) AND $80000000) // wait for the conversion
- RETURN (PEEK(AD_ADGDR) AND $FFFF)>>6
- ENDFUNCTION
Expand|Select|Wrap|Line Numbers
- blah = AD(ch) // <<<<< this is 11us with above function
DESIRED IMPLEMENTATION
==================================================
Desired Inline Macro:
Expand|Select|Wrap|Line Numbers
- #begin ADC_INLINE (channel,variable)
- CALL POKE (AD_ADCR, ((1 << channel) + AD_ENABLE))
- CALL POKE (AD_ADCR, ((1 << channel) + AD_START))
- DO
- UNTIL (PEEK(AD_ADGDR) AND $80000000) // wait for the conversion
- variable = (PEEK(AD_ADGDR) AND $FFFF)>>6
- #end
Expand|Select|Wrap|Line Numbers
- ADC_INLINE (6, blah) // <<< this should yield target speed
ARMbasic doesn't allow multiple commands on a single line of code - i.e. 1 command per line, period. If I correctly understand the many CPP guidance texts that I have read, I take it that multi-line macro definitions, when 'expanded' will actually concatenate the multi-line definition to a single line, with new-line operators embedded therein - this is my root issue...
Is there a means to easily get CPP to expand a macro definition, with passed argument substitution, to multiple lines, exactly as defined in the Macro Def?
I have searched high and low, and have come up empty handed (actually dirty handed, as I have found a couple of solutions, but those solutions require skill sets that I do not possess).
The most attractive solution is a patch to CPP that has a #begin/#end macro definition construct/directive. It is located here.
A viable alternate solution seems to be located here.
The problem with both of these approaches is that I simply do not possess the tools or skill sets to take this source and compile it for use on a win32 platform...
So, my plea is this: Can someone point me toward either a win32 CPP binary that has the desired construct built-in already, or advise, in a rather detailed fashion (TIA) how one could use GNU CPP, in it's native form, to expand a macro definition to multiple lines, with parameter replacement and without extra syntax being added or definition syntax being altered? Please.
Thanks for taking the time to read my diatribe.
-Tod Wulff