FreeMaster Pipe Example

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

FreeMaster Pipe Example

Jump to solution
1,189 Views
baiRB
Contributor I

I'm using FreeMaster to be my runtime debuging tool, I need a function: the target can put out some log(string type) when I debug the target. so I read the FreeMaster User Manual . PIPE Maybe can be done ,but I don't know how to use this function,can give me an example?  

I'm using the S32k1 series . please

0 Kudos
1 Solution
1,169 Views
iulian_stan
NXP Employee
NXP Employee

Hi @baiRB,

There is an example application available in FreeMASTER Communication driver folder.

  • First you need to find this folder in one of the following locations:
    • C:\NXP\FreeMASTER_Serial_Communication_Driver_V2.0, or
    • C:\NXP\{S32DS.x.y}\S32DS\software\FreeMASTER_Serial_Communication_Driver_V2_0

         where S32DS.x.y is your Design Studio version.

  • Next, go to  \examples\SCI_driver_examples\Common\freemaster_example.c and serach for 
    FMSTR_PipeOpen function calls.

On a high level you use FMSTR_PipeOpen to create a Pipe with unique ID, assign pipe message handler and assign read and write buffers ex:

FMSTR_HPIPE hpipe;
static unsigned char pipe1_rxb[10];
static unsigned char pipe1_txb[100];
hpipe = FMSTR_PipeOpen(1, my_pipe_handler,
        (FMSTR_ADDR)pipe1_rxb, sizeof(pipe1_rxb),
        (FMSTR_ADDR)pipe1_txb, sizeof(pipe1_txb));

and inside your pipe handler you read incoming data, process it and return an output:

static void my_pipe_handler(FMSTR_HPIPE hpipe)
{
    static const char* names[10] =
    {
            "zero", "one", "two", "three", "four",
            "five", "six", "seven", "eight", "nine"
    };

    static char buff[4];
    char* n;
    char c;

    /* This simple handler translates the digits into number names.
     * Other characters are just echoed back.  */
    while(FMSTR_PipeRead(hpipe, (FMSTR_ADDR)buff, 1, 0))
    {
        c = buff[0];

        if(c >= '0' && c <= '9')
        {
            /* A tiny strlen */
            n = (char*) names[c-'0'];
            FMSTR_PipeWrite(hpipe, (FMSTR_ADDR)n, my_strlen(n), 0);
        }
        else
        {
            /* Echo */
            FMSTR_PipeWrite(hpipe, (FMSTR_ADDR)buff, 1, 0);
        }
    }
}

this is a default example that reads digits from the host and returns their numeric representation (1one, 2→two etc.).

One last detail - do not forget to add corresponding configuration to freemaster_cfg.h

/*****************************************************************************
* Pipes as data streaming over FreeMASTER protocol
******************************************************************************/

#define FMSTR_USE_PIPES        3   /* Enable/Disable pipes */
#define FMSTR_MAX_PIPES_COUNT  3   /* 3 pipes for demo purposes */

Hope it helps,
Iulian

View solution in original post

0 Kudos
1 Reply
1,170 Views
iulian_stan
NXP Employee
NXP Employee

Hi @baiRB,

There is an example application available in FreeMASTER Communication driver folder.

  • First you need to find this folder in one of the following locations:
    • C:\NXP\FreeMASTER_Serial_Communication_Driver_V2.0, or
    • C:\NXP\{S32DS.x.y}\S32DS\software\FreeMASTER_Serial_Communication_Driver_V2_0

         where S32DS.x.y is your Design Studio version.

  • Next, go to  \examples\SCI_driver_examples\Common\freemaster_example.c and serach for 
    FMSTR_PipeOpen function calls.

On a high level you use FMSTR_PipeOpen to create a Pipe with unique ID, assign pipe message handler and assign read and write buffers ex:

FMSTR_HPIPE hpipe;
static unsigned char pipe1_rxb[10];
static unsigned char pipe1_txb[100];
hpipe = FMSTR_PipeOpen(1, my_pipe_handler,
        (FMSTR_ADDR)pipe1_rxb, sizeof(pipe1_rxb),
        (FMSTR_ADDR)pipe1_txb, sizeof(pipe1_txb));

and inside your pipe handler you read incoming data, process it and return an output:

static void my_pipe_handler(FMSTR_HPIPE hpipe)
{
    static const char* names[10] =
    {
            "zero", "one", "two", "three", "four",
            "five", "six", "seven", "eight", "nine"
    };

    static char buff[4];
    char* n;
    char c;

    /* This simple handler translates the digits into number names.
     * Other characters are just echoed back.  */
    while(FMSTR_PipeRead(hpipe, (FMSTR_ADDR)buff, 1, 0))
    {
        c = buff[0];

        if(c >= '0' && c <= '9')
        {
            /* A tiny strlen */
            n = (char*) names[c-'0'];
            FMSTR_PipeWrite(hpipe, (FMSTR_ADDR)n, my_strlen(n), 0);
        }
        else
        {
            /* Echo */
            FMSTR_PipeWrite(hpipe, (FMSTR_ADDR)buff, 1, 0);
        }
    }
}

this is a default example that reads digits from the host and returns their numeric representation (1one, 2→two etc.).

One last detail - do not forget to add corresponding configuration to freemaster_cfg.h

/*****************************************************************************
* Pipes as data streaming over FreeMASTER protocol
******************************************************************************/

#define FMSTR_USE_PIPES        3   /* Enable/Disable pipes */
#define FMSTR_MAX_PIPES_COUNT  3   /* 3 pipes for demo purposes */

Hope it helps,
Iulian

0 Kudos