• AVR Freaks

Helpful ReplyHot!How to initialize the TCPIP Stack with custom settings

Author
jgvicke
Super Member
  • Total Posts : 458
  • Reward points : 0
  • Joined: 2010/09/28 20:18:24
  • Location: 0
  • Status: offline
2015/10/30 19:22:46 (permalink)
0

How to initialize the TCPIP Stack with custom settings

When using the Harmony TCPIP stack, the MHC will generate everything needed to initialize the stack with settings from the MHC. I want to be able to launch the stack from user settings stored in external flash. I am currently doing that by creating a dynamic init function in system_init.c like this:
 
SYS_MODULE_OBJ TCPIP_STACK_DynamicInit()
{
    TCPIP_STACK_INIT tcpipInit;
    TCPIP_NETWORK_CONFIG TCPIP_Config;

    tcpipInit.moduleInit.sys.powerState = SYS_MODULE_POWER_RUN_FULL;
    Settings_GetTCPIP_Config(&TCPIP_Config);
    tcpipInit.pNetConf = &TCPIP_Config;
    tcpipInit.nNets = 1;
    tcpipInit.pModConfig = TCPIP_STACK_MODULE_CONFIG_TBL;
    tcpipInit.nModules = sizeof (TCPIP_STACK_MODULE_CONFIG_TBL) / sizeof (*TCPIP_STACK_MODULE_CONFIG_TBL);

    return TCPIP_STACK_Initialize(0, &tcpipInit.moduleInit);
}

 
My function Settings_GetTCPIP_Config(&TCPIP_Config); pulls settings from the external flash and passes it to the init function. This is working, but it is not very clean. Every time I generate code, it tries to overwrite this since it is in one of the auto generated files. I would move it into app.c or somewhere else, but this function relies on other items generated in the same file as const arrays:
 

//<editor-fold defaultstate="collapsed" desc="TCPIP Stack Initialization Data">

/*** ARP Service Initialization Data ***/
const TCPIP_ARP_MODULE_CONFIG tcpipARPInitData =
{
    .cacheEntries = TCPIP_ARP_CACHE_ENTRIES,
    .deleteOld = TCPIP_ARP_CACHE_DELETE_OLD,
    .entrySolvedTmo = TCPIP_ARP_CACHE_SOLVED_ENTRY_TMO,
    .entryPendingTmo = TCPIP_ARP_CACHE_PENDING_ENTRY_TMO,
    .entryRetryTmo = TCPIP_ARP_CACHE_PENDING_RETRY_TMO,
    .permQuota = TCPIP_ARP_CACHE_PERMANENT_QUOTA,
    .purgeThres = TCPIP_ARP_CACHE_PURGE_THRESHOLD,
    .purgeQuanta = TCPIP_ARP_CACHE_PURGE_QUANTA,
    .retries = TCPIP_ARP_CACHE_ENTRY_RETRIES,
    .gratProbeCount = TCPIP_ARP_GRATUITOUS_PROBE_COUNT,
};


/*** Announce Discovery Initialization Data ***/
const TCPIP_ANNOUNCE_MODULE_CONFIG tcpipAnnounceInitData =
{
};

/*** UDP Sockets Initialization Data ***/
const TCPIP_UDP_MODULE_CONFIG tcpipUDPInitData =
{
    .nSockets = TCPIP_UDP_MAX_SOCKETS,
    .sktTxBuffSize = TCPIP_UDP_SOCKET_DEFAULT_TX_SIZE,
    .poolBuffers = TCPIP_UDP_SOCKET_POOL_BUFFERS,
    .poolBufferSize = TCPIP_UDP_SOCKET_POOL_BUFFER_SIZE,
};

/*** TCP Sockets Initialization Data ***/
const TCPIP_TCP_MODULE_CONFIG tcpipTCPInitData =
{
    .nSockets = TCPIP_TCP_MAX_SOCKETS,
    .sktTxBuffSize = TCPIP_TCP_SOCKET_DEFAULT_TX_SIZE,
    .sktRxBuffSize = TCPIP_TCP_SOCKET_DEFAULT_RX_SIZE,
};

/*** HTTP Server Initialization Data ***/
const TCPIP_HTTP_MODULE_CONFIG tcpipHTTPInitData =
{
    .nConnections = TCPIP_HTTP_MAX_CONNECTIONS,
    .nTlsConnections = TCPIP_HTTP_MAX_TLS_CONNECTIONS,
    .dataLen = TCPIP_HTTP_MAX_DATA_LEN,
    .sktTxBuffSize = TCPIP_HTTP_SKT_TX_BUFF_SIZE,
    .sktRxBuffSize = TCPIP_HTTP_SKT_RX_BUFF_SIZE,
    .tlsSktTxBuffSize = TCPIP_HTTP_TLS_SKT_TX_BUFF_SIZE,
    .tlsSktRxBuffSize = TCPIP_HTTP_TLS_SKT_RX_BUFF_SIZE,
    .configFlags = TCPIP_HTTP_CONFIG_FLAGS,
};

/*** SNTP Client Initialization Data ***/
const TCPIP_SNTP_MODULE_CONFIG tcpipSNTPInitData =
{
    .ntp_server = TCPIP_NTP_SERVER,
    .ntp_interface = TCPIP_NTP_DEFAULT_IF,
    .ntp_connection_type = TCPIP_NTP_DEFAULT_CONNECTION_TYPE,
    .ntp_reply_timeout = TCPIP_NTP_REPLY_TIMEOUT,
    .ntp_stamp_timeout = TCPIP_NTP_TIME_STAMP_TMO,
    .ntp_success_interval = TCPIP_NTP_QUERY_INTERVAL,
    .ntp_error_interval = TCPIP_NTP_FAST_QUERY_INTERVAL,
};


/*** DHCP client Initialization Data ***/
const TCPIP_DHCP_MODULE_CONFIG tcpipDHCPInitData =
{
    .dhcpEnable = TCPIP_DHCP_CLIENT_ENABLED,
    .dhcpTmo = TCPIP_DHCP_TIMEOUT,
    .dhcpCliPort = TCPIP_DHCP_CLIENT_CONNECT_PORT,
    .dhcpSrvPort = TCPIP_DHCP_SERVER_LISTEN_PORT,

};



/*** NBNS Server Initialization Data ***/
const TCPIP_NBNS_MODULE_CONFIG tcpipNBNSInitData =
{
};

/*** ETH MAC Initialization Data ***/
const TCPIP_MODULE_MAC_PIC32INT_CONFIG tcpipMACPIC32INTInitData =
{
    .nTxDescriptors = TCPIP_EMAC_TX_DESCRIPTORS,
    .rxBuffSize = TCPIP_EMAC_RX_BUFF_SIZE,
    .nRxDescriptors = TCPIP_EMAC_RX_DESCRIPTORS,
    .nRxDedicatedBuffers = TCPIP_EMAC_RX_DEDICATED_BUFFERS,
    .nRxInitBuffers = TCPIP_EMAC_RX_INIT_BUFFERS,
    .rxLowThreshold = TCPIP_EMAC_RX_LOW_THRESHOLD,
    .rxLowFill = TCPIP_EMAC_RX_LOW_FILL,
    .ethFlags = TCPIP_EMAC_ETH_OPEN_FLAGS,
    .phyFlags = TCPIP_EMAC_PHY_CONFIG_FLAGS,
    .linkInitDelay = TCPIP_EMAC_PHY_LINK_INIT_DELAY,
    .phyAddress = TCPIP_EMAC_PHY_ADDRESS,
    .pPhyObject = &DRV_ETHPHY_OBJECT_SMSC_LAN9303,
    .pPhyBase = &DRV_ETHPHY_OBJECT_BASE_Default,
};



/*** Zeroconfig initialization data ***/
const ZCLL_MODULE_CONFIG tcpipZCLLInitData =
{
};




/*** DNS Client Initialization Data ***/
const TCPIP_DNS_CLIENT_MODULE_CONFIG tcpipDNSClientInitData =
{
    .deleteOldLease = TCPIP_DNS_CLIENT_DELETE_OLD_ENTRIES,
    .cacheEntries = TCPIP_DNS_CLIENT_CACHE_ENTRIES,
    .entrySolvedTmo = TCPIP_DNS_CLIENT_CACHE_ENTRY_TMO,
    .IPv4EntriesPerDNSName = TCPIP_DNS_CLIENT_CACHE_PER_IPV4_ADDRESS,
    .dnsIpAddressType = TCPIP_DNS_CLIENT_OPEN_ADDRESS_TYPE,
    .IPv6EntriesPerDNSName = TCPIP_DNS_CLIENT_CACHE_PER_IPV6_ADDRESS,
};




const TCPIP_NETWORK_CONFIG __attribute__((unused)) TCPIP_HOSTS_CONFIGURATION[] =
{
/*** Network Configuration Index 0 ***/
    {
        TCPIP_NETWORK_DEFAULT_INTERFACE_NAME, // interface
        TCPIP_NETWORK_DEFAULT_HOST_NAME, // hostName
        TCPIP_NETWORK_DEFAULT_MAC_ADDR, // macAddr
        TCPIP_NETWORK_DEFAULT_IP_ADDRESS, // ipAddr
        TCPIP_NETWORK_DEFAULT_IP_MASK, // ipMask
        TCPIP_NETWORK_DEFAULT_GATEWAY, // gateway
        TCPIP_NETWORK_DEFAULT_DNS, // priDNS
        TCPIP_NETWORK_DEFAULT_SECOND_DNS, // secondDNS
        TCPIP_NETWORK_DEFAULT_POWER_MODE, // powerMode
        TCPIP_NETWORK_DEFAULT_INTERFACE_FLAGS, // startFlags
       &TCPIP_NETWORK_DEFAULT_MAC_DRIVER, // pMacObject
    },
};

const TCPIP_STACK_MODULE_CONFIG TCPIP_STACK_MODULE_CONFIG_TBL [] =
{
    {TCPIP_MODULE_IPV4, 0},
    {TCPIP_MODULE_ICMP, 0}, // TCPIP_MODULE_ICMP
    {TCPIP_MODULE_ARP, &tcpipARPInitData}, // TCPIP_MODULE_ARP
    {TCPIP_MODULE_UDP, &tcpipUDPInitData}, // TCPIP_MODULE_UDP,
    {TCPIP_MODULE_TCP, &tcpipTCPInitData}, // TCPIP_MODULE_TCP,
    {TCPIP_MODULE_DHCP_CLIENT, &tcpipDHCPInitData}, // TCPIP_MODULE_DHCP_CLIENT,
    {TCPIP_MODULE_ANNOUNCE, &tcpipAnnounceInitData}, // TCPIP_MODULE_ANNOUNCE,
    {TCPIP_MODULE_DNS_CLIENT,&tcpipDNSClientInitData}, // TCPIP_MODULE_DNS_CLIENT,
    {TCPIP_MODULE_NBNS, &tcpipNBNSInitData}, // TCPIP_MODULE_NBNS
    {TCPIP_MODULE_SNTP, &tcpipSNTPInitData}, // TCPIP_MODULE_SNTP,

    {TCPIP_MODULE_HTTP_SERVER, &tcpipHTTPInitData}, // TCPIP_MODULE_HTTP_SERVER,
    {TCPIP_MODULE_ZCLL, 0}, // TCPIP_MODULE_ZCLL,
    // MAC modules
    {TCPIP_MODULE_MAC_PIC32INT, &tcpipMACPIC32INTInitData}, // TCPIP_MODULE_MAC_PIC32INT
};

 
Is there anyway to access these items from outside of system_init.c without modifying the file (which would try to be overwritten every time the code is regenerated?
 
Specifically the problem seems to be this array: TCPIP_STACK_MODULE_CONFIG_TBL
 
I tried putting something like this:
extern const TCPIP_STACK_MODULE_CONFIG TCPIP_STACK_MODULE_CONFIG_TBL [];
 
But that doesn't compile. Any ideas to try would be appreciated.
 
Thanks,
John Vickers
post edited by jgvicke - 2015/10/30 19:25:18

PIC32 Helpful Tools I have made:
https://rebrand.ly/PIC32MZ144PinMapping
https://rebrand.ly/PIC32MX100PinMapping

Feel free to email me if you have any suggestions for any of these tools.
#1
jdeguire
Super Member
  • Total Posts : 582
  • Reward points : 0
  • Joined: 2012/01/13 07:48:44
  • Location: United States
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2015/11/02 07:16:42 (permalink)
0
I had the same issue since we wanted to be able to read the IP address and other options from an external EEPROM.  The only way I could get Harmony to do what I wanted was to modify the template files used to generate the initialization code.  Most of the TCPIP Stack initialization stuff is generated from /framework/tcpip/config/tcpip_stack.c.ftl, so you can modify that and the MHC will input your modified code when it re-generates your project. 
 
The system_init.c file and its friends are generated from files in /utilities/mhc/templates.  The FTL files in there reference other files in the Harmony tree, such as the TCPIP one I mentioned earlier.
 
It would be nice to have some support for this out of the box, though.
#2
jgvicke
Super Member
  • Total Posts : 458
  • Reward points : 0
  • Joined: 2010/09/28 20:18:24
  • Location: 0
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2015/11/02 10:01:34 (permalink)
0
Yeah, that is the method I am using as well. It would be nice if there was some way to have the compiler and MHC use replacement files in the project folder instead of changing the framework files directly so other projects can't reference the same framework set.
 
John Vickers

PIC32 Helpful Tools I have made:
https://rebrand.ly/PIC32MZ144PinMapping
https://rebrand.ly/PIC32MX100PinMapping

Feel free to email me if you have any suggestions for any of these tools.
#3
rainad
Moderator
  • Total Posts : 1387
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2015/11/02 13:05:57 (permalink)
0
Nothing wrong with declaration:
extern const TCPIP_STACK_MODULE_CONFIG TCPIP_STACK_MODULE_CONFIG_TBL [];
But obviously the compiler cannot guess the array size just from a pointer.
Use another extern, like:
extern int nConfigModules;
to store the array number of elements and then call TCPIP_STACK_Initialize();
 
#4
jgvicke
Super Member
  • Total Posts : 458
  • Reward points : 0
  • Joined: 2010/09/28 20:18:24
  • Location: 0
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2015/11/02 13:11:33 (permalink)
0
I could do that, but it gets back to hard coding something that could be changed by the MHC. Pretty much anything I have thought of to do requires linking into the ftl files to insert a custom function into the generated code every time.
 
John Vickers

PIC32 Helpful Tools I have made:
https://rebrand.ly/PIC32MZ144PinMapping
https://rebrand.ly/PIC32MX100PinMapping

Feel free to email me if you have any suggestions for any of these tools.
#5
jdeguire
Super Member
  • Total Posts : 582
  • Reward points : 0
  • Joined: 2012/01/13 07:48:44
  • Location: United States
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2015/11/03 06:46:34 (permalink)
3 (1)
I mention this in another topic, but one thing that makes the stack very difficult to configure at runtime is that most of the configuration functions (starting DHCP, setting IP addresses, etc.) will fail if the stack is in some "INIT" state.  This is the state the stack is put in immediately after calling TCPIP_STACK_Initialize(), so we cannot initialize the stack and then tweak the settings we need to tweak immediately after.  If we could do that, then it'd be far easier to configure that stack based on our EEPROM data and we wouldn't have to modify the MHC template files.
 
I don't quite get why I cannot change settings when the stack is not fully running as that seems like the best time to change settings.  I certainly want to avoid changing stuff while the stack is fully up and running.  One solution would be for the Harmony stack to have one extra "CONFIG" state that lasts between the call to TCPIP_STACK_Initialize() and the first call to TCPIP_STACK_Task().  This CONFIG state would let us tweak any settings that need tweaking at startup and then the stack can move on and prevent us from changing settings afterward.  Again, this would be far preferable to having to modify Harmony templates to do what we want.
#6
rainad
Moderator
  • Total Posts : 1387
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2015/11/03 07:24:22 (permalink)
0
jgvicke
 
I tried putting something like this:
extern const TCPIP_STACK_MODULE_CONFIG TCPIP_STACK_MODULE_CONFIG_TBL [];
But that doesn't compile. Any ideas to try would be appreciated.




This is the issue that I've replied to.
You could do as mentioned and then use the TCPIP_STACK_Initialize() call in your app.c file with the TCPIP_NETWORK_CONFIGURATION of your choice (restored from some storage, etc.)
Of course you have to comment the TCPIP_STACK_Initialize() call in the system_init.c.
But when you regenerate the project, the merge tool will show you that difference and you can chose to keep your changes. It's not something major, IMO. There are so many things that the app might want to do differently, that probably you'll never have all the possibilities addressed by MHC.
#7
rainad
Moderator
  • Total Posts : 1387
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2015/11/03 07:35:55 (permalink)
0
jdeguire
most of the configuration functions will fail if the stack is in some "INIT" state.  This is the state the stack is put in immediately after calling TCPIP_STACK_Initialize(), so we cannot initialize the stack and then tweak the settings we need to tweak immediately after.

This is the purpose of the TCPIP_STACK_Initialize(), to initialize the stack with the passed in parameters. Until the moment the stack reaches a stable state (is in the init phase) you cannot mess with the parameters.
It is assumed that the init parameters are valid and needed, not only passed in just to be changed immediately.
If those parameters are not good, then use the right parameters from the beginning.
There's going to exist a configuration save/restore system service that all the middleware/modules will be able to use and it will address your problems. But it's not available yet.
For now the idea is to change the parameters, etc. in your app code. But some changes are needed in the system init, true. And that could be annoying, yes, when you continuously re-generate the project. But the merge tool should do this job fairly straightforward.
 
#8
moser
Super Member
  • Total Posts : 581
  • Reward points : 0
  • Joined: 2015/06/16 02:53:47
  • Location: Germany
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2015/11/03 08:35:59 (permalink) ☄ Helpfulby jgvicke 2015/11/03 09:12:01
3 (1)
I have the same problem, and I can get the right settings for the network only some time after SYS_Initialize().
 
rainadThis is the purpose of the TCPIP_STACK_Initialize(), to initialize the stack with the passed in parameters. Until the moment the stack reaches a stable state (is in the init phase) you cannot mess with the parameters.

If this is true, then the documentation is wrong. The documentation states that the predonditions for various functions like TCPIP_STACK_NetDown() and TCPIP_STACK_NetUp(netH, pUsrConfig) are only:
real Harmony HelpPreconditions
TCPIP stack should have been initialized by TCPIP_STACK_Initialize()

If you really need to wait until the stack reaches a stable state, this should have been in the prequisites, for example:
fictional Harmony HelpPreconditions
TCPIP stack should have been initialized by TCPIP_STACK_Initialize() and TCPIP_STACK_Status() should return [...some value...]

 
 
Instead of such a configuration save/restore system service which you have mentioned I'd like to suggest a more simple and more versatile usable solution:
 
It would be nice if you would add an option in the MHC for each network configuration or for all network configurations together to enable or disable automatically turning up the network interface at start-up.
 
If you disable it, the application would still get an initialized TCP/IP stack with loaded modules. And (after waiting till initialization is finished) the application would only have to call TCPIP_STACK_NetUp() on its own. TCPIP_STACK_NetUp() allows the application to provide most of the required parameters (including hostname, IPv4/v6 addresses, mask, DNS, gateway, DHCP mode, ...) before any network is up. And the application could even change some other TCPIP module settings before doing this.
#9
rainad
Moderator
  • Total Posts : 1387
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2015/11/03 09:07:25 (permalink)
0
Hi moser,
 
Thanks for catching this: yes, the documentation (the header file) doesn't explicitly state the requirement for the TCPIP_STACK_Status() to return SYS_STATUS_READY before any stack operation are allowed. This should be stronger stated since it's true for any operation, in fact. I'll make a request to add it to the header file so it will be there in the next release.
 
Regarding the save/restore and the stack initialization sequence I think it's a good suggestion.
To do it with TCPIP_STACK_NetUp() it will probably require some changes in the code and I have to analyze it.
But until then, we could add a quick MHC flag, so that it doesn't call the TCPIP_STACK_Initialize() and lets the app. do it with whatever parameters it sees fit.
#10
jdeguire
Super Member
  • Total Posts : 582
  • Reward points : 0
  • Joined: 2012/01/13 07:48:44
  • Location: United States
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2015/11/03 10:13:57 (permalink)
0
rainad
This is the purpose of the TCPIP_STACK_Initialize(), to initialize the stack with the passed in parameters. Until the moment the stack reaches a stable state (is in the init phase) you cannot mess with the parameters.
It is assumed that the init parameters are valid and needed, not only passed in just to be changed immediately.
If those parameters are not good, then use the right parameters from the beginning.
There's going to exist a configuration save/restore system service that all the middleware/modules will be able to use and it will address your problems. But it's not available yet.
For now the idea is to change the parameters, etc. in your app code. But some changes are needed in the system init, true. And that could be annoying, yes, when you continuously re-generate the project. But the merge tool should do this job fairly straightforward.
 

 
I agree that we should just be passing in the correct parameters in the first place; however, the issue is that the layout of system_init.c makes this very difficult, if not impossible, to do in its stock state.  The TCP/IP Stack is certainly a complex library and so unfortunately the initialization structures for the stack are equally complex.  Also, they are all "const" and so cannot be modified anyway.  I suppose I could just copy them and modify my copy, except that the structures that are actually present are going to depend on what stack modules are enabled.  Even if I will only ever enable a fixed set of modules, they're not declared "extern" in any headers, which I assume was intentional.  Even if I just made my own "extern" declarations for them, I cannot know that the generated names for these structures will remain the same in the next version of Harmony.  Even if they remain the same forever, then it still does not matter because the code in system_init.c is going to initialize the stack with the "const" structures in system_init.c anyway thus ignoring my now copied and modified structures.  Of course I could just comment out the call to TCPIP_STACK_Initialize() in system_init.c and call it ourselves, though it is easy to accidentally merge over our own changes when running the MHC and thus we're back to modifying the FTL templates anyway to prevent that.
 
Basically, the challenge is being able to provide our own settings while still maintaining the flexibility provided by Harmony and the MHC (and despite my griping here I actually do like Harmony and especially the MHC).
 
It would be silly of us to think that the MHC should be able to handle every scenario under the sun, but I do think that getting the right parameters to the stack is harder that it should be.
 
Here's what I ended up doing to make the code do what I want:
 
1.  I modified the file at /framework/tcpip/config/tcpip_stack.c.ftl to add a function pointer to system_init.c that takes the same parameters as TCPIP_STACK_Initialize() and returns the same value.  If this pointer is non-NULL, then this is called instead of TCPIP_STACK_Initialize() and it is the job of the pointed-to function to handle all of the initialization.
2.  I removed the "const" qualifier from TCPIP_STACK_MODULE_CONFIG_TBL and from TCPIP_HOSTS_CONFIGURATION so that my pointed-to function can modify them.
3.  My pointed-to function reads our settings from our EEPROM device and modifies TCPIP_HOSTS_CONFIGURATION with the desired IP address.  It also loops through the TCPIP_STACK_MODULE_CONFIG_TBL looking for the DHCP client settings (denoted by the TCPIP_MODULE_DHCP_CLIENT enum).  If found, it makes a copy of the referenced TCPIP_DHCP_MODULE_CONFIG structure, modifies the copy, and then points the table at the new copy.
4.  My pointed-to init function finally calls TCPIP_STACK_Initialize() itself with the modified init parameters and returns the value from it.
 
This sequence seems to work fine and I am totally OK with doing it.  It would be nice, however, if Harmony supported a similar scheme (non-const MODULE_CONFIG and HOST_CONFIG items and an initialization function pointer) natively.  Also, some helper functions for navigating the giant config structures, such as ones to help access the default IP address or look a particular module config in the config table, would be very helpful.
 
The save/restore config service sounds intriguing, though I must admit that the storage part is already solved for us on our end.  I'll certainly check it out when it is available, though.
post edited by jdeguire - 2015/11/03 10:16:52
#11
jdeguire
Super Member
  • Total Posts : 582
  • Reward points : 0
  • Joined: 2012/01/13 07:48:44
  • Location: United States
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2015/11/03 10:15:29 (permalink)
0
rainad
But until then, we could add a quick MHC flag, so that it doesn't call the TCPIP_STACK_Initialize() and lets the app. do it with whatever parameters it sees fit.

Actually, that would do the business right there.  If the flag is set, then please also make TCPIP_HOSTS_CONFIGURATION and TCPIP_STACK_MODULE_CONFIG_TBL structure non-const so that we can modify them with our settings.
 
Edit:  There is no harm in leaving all of the module-specific structures as "const" since we can just copy those and the big config table will essentially tell us what modules are available.
post edited by jdeguire - 2015/11/03 10:21:00
#12
rainad
Moderator
  • Total Posts : 1387
  • Reward points : 0
  • Joined: 2009/05/01 13:39:25
  • Location: 0
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2015/11/03 13:06:56 (permalink)
4 (2)
OK, I'll make the request to add this MHC configuration flag and hopefully it will be there in the next release.
Problem is that if it's needed for TCP/IP, the same could be claimed for any module. Probably a more generic approach would be nice.
 
#13
jdeguire
Super Member
  • Total Posts : 582
  • Reward points : 0
  • Joined: 2012/01/13 07:48:44
  • Location: United States
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2015/11/03 15:00:15 (permalink)
0
That'd be great!  Oh, and of course we'll want to custom initialize all the things! Smile: Smile
 
The MHC internals are pretty well documented in the giant PDF, so in the worst case we could probably just add whatever options we need ourselves (I actually added an option to prevent the MHC from including a "main.c" since we use a C++ main file).  That's pretty cool and one reason why I quite like the MHC.  Of course, having such options available in the stock configuration does make it simpler to update Harmony to newer versions since there's less modified code to port over.
#14
rjc101
Super Member
  • Total Posts : 133
  • Reward points : 0
  • Joined: 2016/07/08 14:56:34
  • Location: 0
  • Status: online
Re: How to initialize the TCPIP Stack with custom settings 2020/06/29 09:54:26 (permalink)
0
Apologies for digging up this old thread, but has a "clean" way be incorporated in Harmony 3 to delay the starting of the TCPIP stack *after* my app has had a chance to load the system config needed to initialise the stack?
 
Under H2 I just removed the TCPIP_STACK_Initialize from the generated files, and tweaked the const variables to non const as described above.  I'm re-working a project to use Harmony 3 and I can't see from the documentation if there is a way to do this.  It would be nice to be able to do this in a clean way that isn't impacted by future net module updates.
 
For reasons I can't explain here, one reason I do this is I have to set the MAC address to a config specific one before any data is transmitted, if I don't the connected switch port may disable the port.  
#15
jdeguire
Super Member
  • Total Posts : 582
  • Reward points : 0
  • Joined: 2012/01/13 07:48:44
  • Location: United States
  • Status: offline
Re: How to initialize the TCPIP Stack with custom settings 2020/06/29 11:13:51 (permalink) ☄ Helpfulby rjc101 2020/06/29 11:17:50
0
Yup, Harmony 3 makes this MUCH easier to do.
 
Find the TCP/IP CORE settings node in the project graph of the Harmony 3 Configurator and select the "Enable Stack Initialization Callback" option that shows up on the right-side pane.  If you don't see this, then you probably need to update your stack using the Harmony 3 Content Manager or Downloader. 
 
In your firmware, you define a function with the name given in the H3C.  This function takes a const struct TCPIP_STACK_INIT** as a parameter, so your function will create your own initialization and update the handle to point to your init struct.  You return 0 if you are ready to go, greater than 0 if you need more time to set up, or less than 0 to indicate an error and that the stack should abort initialization.
#16
rjc101
Super Member
  • Total Posts : 133
  • Reward points : 0
  • Joined: 2016/07/08 14:56:34
  • Location: 0
  • Status: online
Re: How to initialize the TCPIP Stack with custom settings 2020/06/29 11:19:41 (permalink)
0
Interesting, thanks for that, I’ll take a look. I couldn’t find that in the documentation, I’ll take a look at the code.
#17
Jump to:
© 2020 APG vNext Commercial Version 4.5