next up previous
Next: Tutorial 2 Up: Tutorial 1 Previous: Getting started

Explanation of the Program on the DSK-board

In this section the working of the program running on the DSK is explained along its listing:

#include <stdio.h>              /* fprintf(), puts()   */
#include <stdlib.h>             /* abort()             */
#include <rtdx.h>               /* RTDX                */
#include "target.h"             /* TARGET_INITIALIZE() */


typedef enum {FALSE,TRUE} BOOL;

/* Declare and initialize the channels
* input channel called "ichan"
* output channel called "ochan"
*/

RTDX_CreateInputChannel(ichan);
RTDX_CreateOutputChannel(ochan);

In this initial part the C standard header files 'stdio.h' and 'stdlib.h' are loaded as well as the header file 'rtdx.h' for the RTDX-connection. The header file 'target.h' supplies a macro 'TARGET_INITIALIZE()', which sets the IER and the CSR to enable interrupts. Next an input channel 'ichan' and an output channel 'ochan' is created with the two macros 'RTDX_CreateInputChannel' and 'RTDX_CreateOutputChannel'. Attention: the channel names don't have quotes since they are macro arguments!

struct tagData {
    int  recvd;                 /* Data received */
#ifdef HSRTDX
    // Silicon HSRTDX workaround...
    // - User must define extra 32bit word AFTER all
    //    Host-to-target receive buffers & align on
    //    32bit boundaries.
#ifdef _TMS320C6X
    unsigned dummy;
#elif defined(__TMS320C55X__)
    unsigned long dummy;
#else
#error "Unknown how to use Dummy word for this target."
#endif
#endif
} data;

In this part the structure 'tagData' is defined as well as the variable data of type tagData. In data.recvd one dataset received by the input channel is stored. The rest of the structure compensates for an eventual silicon error ('HSRTDX').

void main( void )
{
    /* Target Specific Initialization */
    TARGET_INITIALIZE();
    
    /* Enable the channels */
    RTDX_enableInput(&ichan);
    RTDX_enableOutput(&ochan);

In the main-routine first the interrupt is enabled via the macro 'TARGET_INITIALIZE' (see above). Then the input channel 'ichan' and the output channel 'ochan' are enabled, so that bi-directional data transfer between host and board is possible.

    printf("Ready to receive messages from the host ...\n");

    do {
        unsigned len_rcvd;
        /* Initialize data received to validate change */
        data.recvd = 0;
        
        /* Request an integer from the host */
        len_rcvd = RTDX_read( &ichan, &data.recvd, sizeof(data.recvd));
        if( len_rcvd != sizeof(data.recvd) ) {
            fprintf(stderr, "\nError: RTDX_read() failed!\n");
            abort();
        }
        
        /* Display what was read in the stdout window */
        fprintf(stdout, "Value %i was read from the host\n", data.recvd);
        RTDX_write( &ochan, &data.recvd, sizeof(data.recvd) );
    } while(data.recvd != 100);

This part is the core of the 'Tutorial 1'-program: 100 integers (32bit each) are received from the host and reflected back to the host. In detail: after printing a message to the console that it now is ready to receive data from the host and send it back to the host, data are actually received in 'data.recvd' using 'RTDX_read' and then reflected by 'RTDX_write'. This takes place in a do-loop that will exit after 100 data have been read. Received data are displayed on the console. If the number of address units received by RTDX-read is not equal to the size of data.recvd as determined by the sizeof-function, an error message will be displayed.

    /* wait until writing has finished */
    while ( RTDX_writing != NULL ) { }
    
    /* Disable the channels */
    RTDX_disableInput(&ichan);
    RTDX_disableOutput(&ochan);
    
    puts("\nApplication Completed ");

Wait until all writing in the output channel has finished. Then disable the input and output channel and send a message to the console that the application is completed.


next up previous
Next: Tutorial 2 Up: Tutorial 1 Previous: Getting started
H. Rogalla 2005-12-07