comparison gsm-fw/services/ffs/rand.c @ 219:2beb88a3d528

gsm-fw links with FFS included
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Mon, 06 Jan 2014 20:24:53 +0000
parents
children
comparison
equal deleted inserted replaced
218:fee45482aa2a 219:2beb88a3d528
1 /*
2 * This version of rand() has been lifted from Ancient UNIX, and modified
3 * to match the version used in TI's TCS211 GSM firmware, as revealed by
4 * disassembly of rand.obj in the rts16le_flash.lib binary library used
5 * by that semi-src package. TI's version (most likely from their compiler
6 * tools group, rather than the GSM fw group, but who knows) uses the
7 * same trivial implementation of rand() as the original Ancient UNIX libc,
8 * but with one change: TI's return value is right-shifted by 16 bits
9 * compared to what the Ancient UNIX rand() would have returned.
10 * The caller thus gets back only 15 pseudo-random bits rather than 31,
11 * but then the lower bits of the original rand() return value are
12 * known to be pretty bad.
13 *
14 * rand() is used by some FFS code in reclaim.c. If we don't provide our
15 * own version of rand() and let the linker pull the version from newlib,
16 * the link fails because the latter uses malloc. This ancient implementation
17 * of rand() is quite poor, but my plan is to look into possibly adopting
18 * some better PRNG after we get the basic TI GSM firmware reintegrated.
19 */
20
21 static long randx = 1;
22
23 srand(x)
24 unsigned x;
25 {
26 randx = x;
27 }
28
29 rand()
30 {
31 return ((randx = randx * 1103515245 + 12345) & 0x7fffffff) >> 16;
32 }