ARM Technical Support Knowledge Articles

How do I dynamically update compile-time options in MDK-Professional Middleware before service initialization?

Applies to: Embedded Software

Scenario

When using the MDK-Professional Middleware, I can configure service settings by using header files and corresponding wizard at compile time. Sometimes, no Application Program Interfaces (APIs) are provided to change them at runtime. How do I configure those options dynamically before initialization? 

Suppose that you use the File Transfer Protocol (FTP) Client Service of Network middleware. You can use the macro FTP_CLIENT_PASSIVE_MODE_ONLY in the Net_Config_FTP_Client.h header file to select the Active Mode or Passive Mode of the FTP Client:

//   <q>Passive mode (PASV)

//   <i>The client initiates a data connection to the server.

//   <i>Default: Not passive (Active)

#define FTP_CLIENT_PASSIVE_MODE 0

To search the macro FTP_CLIENT_PASSIVE_MODE_ONLY in files, press Ctrl+Shift+F in uVision. You can find that the macro FTP_CLIENT_PASSIVE_MODE_ONLY is used as the initial value of a constant configuration structure in the net_config.h header file, as shown in the following code:
 
#if (FTP_CLIENT_ENABLE)
  FTPC_CFG ftpc_config = {
    FTP_CLIENT_TOUT,
    FTP_CLIENT_PASSIVE_MODE
  };
#endif

To further understand the configuration structure, you can search the user-defined type FTPC_CFG, and find the following definition:

/// FTP Client Configuration info

typedef struct ftpc_cfg {

  uint8_t DefTout;                      ///< Default inactivity timeout

  bool    PasvMode;                     ///< FTP Passive Mode used

} const FTPC_CFG;

The code uses ftpc_config to pass settings to the middleware library before initializing the FTP Client. According to the definition, ftpc_config is treated as a constant object stored in read-only memory by default. To dynamically set the configuration before service initialization, you can use a scatter file to place ftpc_config in RAM. In doing so, you can make ftpc_config writable at runtime. 

Note: Settings statically configured in header files can be dynamically updated only before the service initialization. After the service initialization, the settings are treated as constant until the service is stopped. If you fail to do this, the services delivered by middleware are not guaranteed. 

Answer

To dynamically set the configuration before service initialization, perform the following steps:

  1. Open a default scatter file for modification using uVision:

a. Start uVision.

b. Open the Options for Target dialog box.

c. Click the Linker tab.

d. Deselect the Use Memory Layout from Dialog option.

e. Click Edit to open a default scatter file for further modification. 

    A scatter file might be similar to the following one:

    LR_IROM1 0x08000000 0x00040000  {    ; load region size_region

      ...

      RW_IRAM1 0x20000000 0x00010000  {  ; RW data

       .ANY (+RW +ZI)

      }

      ...

    }

  2. Place ftpc_config in a specified execution region in RAM, by using the :gdef: prefix.  For example, you can place ftpc_config in the execution region RW_IRAM1 as follows:

                                                               
    LR_IROM1 0x08000000 0x00040000  {    ; oad region size_region
      ...
      RW_IRAM1 0x20000000 0x00010000  {  ; RW data
       * (:gdef:ftpc_config)             ; put ftpc_config to the SRAM range  
       .ANY (+RW +ZI)
      }
      ...
    }
 
  3. Add necessary header files to your target source code, and declare a reference to the configuration structure for further use. For example:
 
    #include <rl_net_lib.h>
    ...
    extern FTPC_CFG ftpc_config;
 
  4. Create a function to configure the options before the service initialization. For example:
 
    void set_passive_mode(bool bIsPassive)
    {
        (*(bool *)&(ftpc_config.PasvMode)) = bIsPassive;
  }
 
After those steps, you can change the middleware service options dynamically before service initialization. Note that this causes some overhead in RAM expense. 

Related Information

Rate this article

[Bad]
|
|
[Good]
Disagree? Move your mouse over the bar and click

Did you find this article helpful? Yes No

How can we improve this article?

Link to this article
Copyright © 2011 ARM Limited. All rights reserved. External (Open), Non-Confidential