title: Understanding a function definition in a header file
body: <p>I am porting a software written to a specific microcontroller to another microcontroller but I have a problem in C language. </p>
  
  <p>I would like to draw attention to the below mentioned functions defined inside <a href="https://drive.google.com/file/d/0BwMfDD5kcvwscXE2UmF1YXlSdmM/view?usp=sharing" rel="nofollow">hal_spi_rf_trxeb.c</a> file.  Although I searched within the file I was not able to find the full function description for the following functions.</p>
  
  <ol>
  <li><p><code>TRXEM_SPI_WAIT_DONE()</code></p></li>
  <li><p><code>TRXEM_SPI_RX()</code></p></li>
  <li><p><code>TRXEM_SPI_WAIT_DONE()</code></p></li>
  <li><p><code>TRXEM_SPI_WAIT_TX_DONE()</code></p></li>
  <li><p><code>TRXEM_SPI_RX()</code></p></li>
  <li><p><code>TRXEM_SPI_WAIT_MISO_LOW(x)</code></p></li>
  </ol>
  
  <p>After a bit more searching I figured that these functions exist in the header file itself.  More specifically <a href="https://drive.google.com/file/d/0BwMfDD5kcvwsQzR2eEZZYTBfTDA/view?usp=sharing" rel="nofollow"><code>inhal_spi_rf_trxeb.h</code></a> file.</p>
  
  <pre><code>    /******************************************************************************
   * @fn          trx16BitRegAccess
   *
   * @brief       This function performs a read or write in the extended adress
   *              space of CC112X.
   *
   * input parameters
   *
   * @param       accessType - Specifies if this is a read or write and if it's
   *                           a single or burst access. Bitmask made up of
   *                           RADIO_BURST_ACCESS/RADIO_SINGLE_ACCESS/
   *                           RADIO_WRITE_ACCESS/RADIO_READ_ACCESS.
   * @param       extAddr - Extended register space address = 0x2F.
   * @param       regAddr - Register address in the extended address space.
   * @param       *pData  - Pointer to data array for communication
   * @param       len     - Length of bytes to be read/written from/to radio
   *
   * output parameters
   *
   * @return      rfStatus_t
   */
  rfStatus_t trx16BitRegAccess(uint8 accessType, uint8 extAddr, uint8 regAddr, uint8 *pData, uint8 len)
  {
    uint8 readValue;
  
    &lt;span style="background-color:#ff0000;"&gt;TRXEM_SPI_BEGIN();&lt;/span&gt;
    while(TRXEM_PORT_IN &amp; TRXEM_SPI_MISO_PIN);
    /* send extended address byte with access type bits set */
   &lt;span style="background-color:#ff0000;"&gt; TRXEM_SPI_TX&lt;/span&gt;(accessType|extAddr);
    TRXEM_SPI_WAIT_DONE();
    /* Storing chip status */
    readValue = TRXEM_SPI_RX();
    TRXEM_SPI_TX(regAddr);
    TRXEM_SPI_WAIT_DONE();
    /* Communicate len number of bytes */
    trxReadWriteBurstSingle(accessType|extAddr,pData,len);
  </code></pre>
  
  <p><code>hal_spi_rf_trxeb.h</code> claims to have the function I was searching in the form of a macro. Those macros are shown below.</p>
  
  <pre><code>/******************************************************************************
   * MACROS
   */
  
  /* Macros for Tranceivers(TRX) */
  #define TRXEM_SPI_BEGIN()              st( TRXEM_PORT_OUT &amp;= ~TRXEM_SPI_SC_N_PIN; NOP(); )
  #define TRXEM_SPI_TX(x)                st( UCB0IFG &amp;= ~UCRXIFG; UCB0TXBUF= (x); )
  #define TRXEM_SPI_WAIT_DONE()          st( while(!(UCB0IFG &amp; UCRXIFG)); )
  #define TRXEM_SPI_WAIT_TX_DONE()       st( while(!(UCB0IFG &amp; UCTXIFG)); )
  #define TRXEM_SPI_RX()                 UCB0RXBUF
  #define TRXEM_SPI_WAIT_MISO_LOW(x)     st( uint8 count = 200; \
                                             while(TRXEM_PORT_IN &amp; TRXEM_SPI_MISO_PIN) \
                                             { \
                                                __delay_cycles(5000); \
                                                count--; \
                                                if (count == 0) break; \
                                             } \
                                             if(count&gt;0) (x) = 1; \
                                             else (x) = 0; )
  </code></pre>
  
  <h3>Questions</h3>
  
  <ul>
  <li><p>I do not understand how these macros work.</p></li>
  <li><p>Could someone please tell me how a function has been defined in the header file?</p></li>
  <li><p>How can a function be defined in the header file itself?</p></li>
  <li><p>What does the function <code>st()</code> do?</p></li>
  </ul>
  
  <p>Should you require, the whole project can be downloaded by <a href="https://drive.google.com/file/d/0BwMfDD5kcvwsWmxGZ1BuUHpteTg/view?usp=sharing" rel="nofollow">this link</a>.</p>
  
  <p>For more information you may view the linked header and source (<code>.h</code> and <code>.c</code>) files.</p>