Hi Chris / Tom
To close this thread I have the following code example for Tom and results of some tests on the M52259 (with and without HW RD support).
1) Using the internal random number generator to define each new client port number there is (obviously) no problem.
2) Using the following code the results on the M52235 (RND disabled and this code used instead) the randomness is adequate for the task in hand - both for power cycle (the internal RAM is in fact very random on power up in this chip - absolutely no obvious patterns) and for warm restarts.
extern void fnInitialiseRND(unsigned short *usSeedValue){ if ((*usSeedValue = *ptrSeed) == 0) { // we hope that the content of the random seed is random after a power up *usSeedValue = 0x127b; // we must not set a zero - so we set a fixed value } // after a reset it should be well random since it will contain the value at the reset time *ptrSeed = fnRandom(); // ensure that the seed value is modified between resets} This routine is called when the board is initialised.
*usSeedValue is a pointer to the seed used in a pseudo-random number generator (we use a 16 bit one - there are many examples and they are only a few lines code in length).
ptrSeed is a global pointer to an otherwise unused 16 bit ram location in internal SRAM. We actually put it on the very top of stack when the system is initialised and it is never overwritten by any other code (nor BSP initialisation) - the linker doesn't in fact know of its existence. This RAM location has a 'random' value after power up so the seed to the pseudo-random number generator is also 'random'.
Note that a seed of 0x0000 is illegal and, should it ever 'randomly' occur, a different fixed value is seeded (as protection).
The first use of the pseudo-random number generator which has now been seeded is to generate a new value for our 'random' seed. This means that when the board is reset its new 'random' seed value is again different but still 'random' in nature.
As I test I got the board to get the present data and time for a known time server (time-a.nist.gov 129.6.15.28 NIST, Gaithersburg, Maryland). I noted the port number that the client used (it randomly gets a new one on each use [every new TCP connection] using the pseudo-random generator in the dynamic port range 49152...6553) and verified that it was truely 'random' in nature after each power cycle and each warm reset, thus confirming the suitability of this method for this application.
Finally I did a test where I forced the same port number to be used, repeating at about 10s intervals.
I think the server designers have also been reading some of the discussions that Chris has referenced because this server actually accepted each one with no complaints.....!
Regards
Mark
www.uTasker.com
- OS, TCP/IP stack, USB, device drivers and simulator for M5221X, M5222X, M5223X, M5225X. One package does them all - "Embedding it better..."