Code covered by the BSD License  

Highlights from
Task execution profiling kit for Real-Time Workshop targets

image thumbnail

Task execution profiling kit for Real-Time Workshop targets

by

 

20 Oct 2006 (Updated )

A set of tools and examples to implement task execution profiling for a Real-Time Workshop target

create_serial_driver_blocks
function create_serial_driver_blocks
%CREATE_SERIAL_DRIVER_BLOCKS creates a device driver block for serial receive
%
%   CREATE_SERIAL_DRIVER_BLOCKS uses the Legacy Code Tool to create Simulink
%   device driver blocks for serial receive and serial transmit. The datatypes
%   used in this function are appropriate for a 16-bit processor; if device
%   drivers for a processor with a different word size are required, this
%   function can easily be edited.
%
%   See also LEGACY_CODE

%   Copyright 2006 The MathWorks, Inc.
%   $Revision:$  $Date:$
    
    
    [rx_block, tx_block] = local_create_s_functions;
    local_apply_rx_mask(rx_block);
    local_apply_tx_mask(tx_block);
    
    
%LOCAL_CREATE_S_FUNCTIONS creates s-functions for the serial blocks
function [rx_block, tx_block] = local_create_s_functions
    
    s(1:2) = legacy_code('initialize');

    % u1 -> num bytes to read
    % p1 -> max num bytes to read
    % y1 -> received data
    % y2 -> num bytes received
    s(1).SFunctionName = 'sfun_serial_rx';
    s(1).OutputFcnSpec = 'serial_read_string(uint8 y1[p1], uint16 y2, uint16 p1, uint16 u1)';
    s(1).HeaderFiles = {'serial_io.h'};
    s(1).SourceFiles = {'serial_io.c'};

    % u1 -> data to transmit
    % u2 -> num bytes to transmit
    % y1 -> num bytes transmitted
    s(2).SFunctionName = 'sfun_serial_tx';
    s(2).OutputFcnSpec = 'uint16 y1 = serial_send_string(uint8 u1[p1], uint16 p1)';
    s(2).HeaderFiles = {'serial_io.h'};
    s(2).SourceFiles = {'serial_io.c'};

    legacy_code_sfcn_cmex_generate(s);
    legacy_code_compile(s);
    legacy_code_sfcn_tlc_generate(s);

    
    legacy_code_slblock_generate(s(1));    
    rx_block = gcb;
    
    legacy_code_slblock_generate(s(2));    
    tx_block = gcb;
    
    
%LOCAL_APPLY_RX_MASK configures the serial receive block's mask dialog
function local_apply_rx_mask(rx_block)

    blkDescription = sprintf([...
        'Receive bytes over a serial interface. The block input specifies '...
        'the requested number of bytes to read; the first block output is the data '...
        'returned by the last read and the second block output is the actual '...
        'number of bytes read.'...
        'If the number of bytes available is smaller than the number of '...
        'bytes requested then the actual number of bytes read is equal to '...
        'the number of bytes available.\n\n'...
        'You must specify the maximum number of bytes to read. This maximum '...
        'number of bytes is used to set the width of the data output port.\n\n'...
        'This block was generated automatically by running the function '...
        mfilename '.']);
    
    set_param(rx_block,'MaskDescription', blkDescription);
    set_param(rx_block,'MaskPromptString','Maximum number of bytes to read:')
    set_param(rx_block,'MaskStyleString','edit')
    set_param(rx_block,'MaskTunableValueString','on')
    set_param(rx_block,'MaskCallbackString',';')
    set_param(rx_block,'MaskEnableString','on')
    set_param(rx_block,'MaskVisibilityString','on')
    set_param(rx_block,'MaskTooltipString','on')
    set_param(rx_block,'MaskValueString','1')
    set_param(rx_block,'Parameters','max_length')
    set_param(rx_block,'MaskVariables','max_length=@1')
    set_param(rx_block,'MaskDisplay','text(0.5, 0.5, ''Serial\nReceive'',''horizontalAlignment'',''center''); port_label(''output'',1,''Data'')')
    
    
    
%LOCAL_APPLY_TX_MASK configures the serial transmit block's mask dialog
function local_apply_tx_mask(tx_block)

    blkDescription = sprintf([...
        'Transmit bytes over a serial interface. The first block input contains '...
        'the data to send and the second block input is the requested '...
        'number of bytes to send. The block output is the number of bytes '...
        'actually sent.\n\n'...
        'This block was generated automatically by running the function '...
        mfilename '.']);
    
    displayCmd = [...
        'text(0.5, 0.5, ''Serial\nTransmit'',''horizontalAlignment'','...
        '''center''); port_label(''input'',1,''Data'')'...
    ];
    
    set_param(tx_block,'MaskDescription', blkDescription);
    set_param(tx_block,'MaskPromptString','Maximum number of bytes to send:');
    set_param(tx_block,'MaskStyleString','edit')
    set_param(tx_block,'MaskTunableValueString','on')
    set_param(tx_block,'MaskCallbackString',';')
    set_param(tx_block,'MaskEnableString','on')
    set_param(tx_block,'MaskVisibilityString','on')
    set_param(tx_block,'MaskTooltipString','on')
    set_param(tx_block,'MaskValueString','8')
    set_param(tx_block,'Parameters','max_length')
    set_param(tx_block,'MaskVariables','max_length=@1')
    set_param(tx_block,'MaskDisplay',displayCmd);

Contact us