<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Preprocessor gurus help requested!</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/27003/preprocessor-gurus-help-requested</link><description> 
Hello preprocessor masters/gurus, 

 
I am trying to make a piece of software as easily configurable as
possible, by only indicting which port/pin combination controls the
hardware: 

 
// SPI master/slave arbitration
#define SPI_MASTER_IO_PORT 0
#define</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Preprocessor gurus help requested!</title><link>https://community.arm.com/thread/90295?ContentTypeID=1</link><pubDate>Fri, 12 Mar 2010 01:49:39 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:91086cc1-0d4a-4ba0-907a-5df3f024f8aa</guid><dc:creator>Tamir Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
So the final macros look like this:&lt;/p&gt;

&lt;pre&gt;
// SPI master/slave arbitration
#define SPI_MASTER_IO_PORT                      0
#define SPI_MASTER_IO_PIN                       19

#define SPI_MASTER_DISPLAY_PORT         0
#define SPI_MASTER_DISPLAY_PIN          5

#define FIO_PORT_PIN_TEMP(x)            FIO##x##PIN
#define FIO_PORT_PIN(x)                         FIO_PORT_PIN_TEMP(x)
#define FIO_PORT_CLR_TEMP(x)            FIO##x##CLR
#define FIO_PORT_CLR(x)                         FIO_PORT_CLR_TEMP(x)
#define FIO_PORT_SET_TEMP(x)            FIO##x##SET
#define FIO_PORT_SET(x)                         FIO_PORT_SET_TEMP(x)

#define SPI_MASTER_REQUEST_IO_IS_MASTER                   ( ( (FIO_PORT_PIN(SPI_MASTER_IO_PORT)&amp;gt;&amp;gt;SPI_MASTER_IO_PIN)&amp;amp;1) == 0)
#define SPI_MASTER_REQUEST_IO_NOT_MASTER                  ( ( (FIO_PORT_PIN(SPI_MASTER_IO_PORT)&amp;gt;&amp;gt;SPI_MASTER_IO_PIN)&amp;amp;1) == 1)
#define SPI_MASTER_REQUEST_IO_BIT_SET                     FIO_PORT_CLR(SPI_MASTER_IO_PORT) |= (1&amp;lt;&amp;lt;SPI_MASTER_IO_PIN) ;
#define SPI_MASTER_REQUEST_IO_BIT_RESET                   FIO_PORT_SET(SPI_MASTER_IO_PORT) |= (1&amp;lt;&amp;lt;SPI_MASTER_IO_PIN) ;

#define SPI_MASTER_REQUEST_DISPLAY_BIT_IS_MASTER  ( ( (FIO_PORT_PIN(SPI_MASTER_DISPLAY_PORT)&amp;gt;&amp;gt;SPI_MASTER_DISPLAY_PIN)&amp;amp;1) == 0)
#define SPI_MASTER_REQUEST_DISPLAY_BIT_NOT_MASTER ( ( (FIO_PORT_PIN(SPI_MASTER_DISPLAY_PORT)&amp;gt;&amp;gt;SPI_MASTER_DISPLAY_PIN)&amp;amp;1) == 1)
#define SPI_MASTER_REQUEST_DISPLAY_BIT_SET        FIO_PORT_CLR(SPI_MASTER_DISPLAY_PORT) |= (1&amp;lt;&amp;lt;SPI_MASTER_DISPLAY_PIN) ;
#define SPI_MASTER_REQUEST_DISPLAY_BIT_RESET      FIO_PORT_SET(SPI_MASTER_DISPLAY_PORT) |= (1&amp;lt;&amp;lt;SPI_MASTER_DISPLAY_PIN) ;
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Preprocessor gurus help requested!</title><link>https://community.arm.com/thread/57881?ContentTypeID=1</link><pubDate>Fri, 12 Mar 2010 01:25:29 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:98244f8f-0d20-4905-bc7d-5719f2573ef1</guid><dc:creator>Tamir Michael</dc:creator><description>&lt;p&gt;&lt;p&gt;
Ah, it is good to have colleagues and the internet/google! here is
the solution:&lt;/p&gt;

&lt;pre&gt;
#define FIO_PORT_PIN_TEMP(x)                               FIO##x##PIN
#define FIO_PORT_PIN(x)                         FIO_PORT_PIN_TEMP(x)
&lt;/pre&gt;

&lt;p&gt;
logic:&lt;/p&gt;

&lt;pre&gt;
Macros that call other macros that stringify or concatenate.
If an argument is stringified or concatenated, the prescan does not occur. If you want to expand a macro, then stringify or concatenate its expansion, you can do that by causing one macro to call another macro that does the stringification or concatenation. For instance, if you have
          #define AFTERX(x) X_ ## x
          #define XAFTERX(x) AFTERX(x)
          #define TABLESIZE 1024
          #define BUFSIZE TABLESIZE

then AFTERX(BUFSIZE) expands to X_BUFSIZE, and XAFTERX(BUFSIZE) expands to X_1024. (Not to X_TABLESIZE. Prescan always does a complete expansion.)
&lt;/pre&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>