Fix random number generation on ESP8266

This patch uses the onboard RTC for generating random seed. It also improves the print handler to support float values.
The rom segment is slightly increased to fit to the latest master.

JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
Robert Fancsik 2018-01-02 13:51:36 +01:00 committed by yichoi
parent c3c0bb8ddc
commit 543f75a6c3
4 changed files with 17 additions and 11 deletions

View File

@ -1,4 +1,5 @@
function sysloop(ticknow) {
blink();
};
print("Random generated number: ", Math.random());
print("main js OK");

View File

@ -26,7 +26,7 @@ MEMORY
dport0_0_seg : org = 0x3FF00000, len = 0x10
dram0_0_seg : org = 0x3FFE8000, len = 0x18000
iram1_0_seg : org = 0x40100000, len = 0x8000
irom0_0_seg : org = 0x40220000, len = 0x6C000
irom0_0_seg : org = 0x40220000, len = 0x7C000
}
INCLUDE ../ld/eagle.app.v6.common.ld

View File

@ -73,9 +73,20 @@ DELCARE_HANDLER(print) {
printf("%s ", buffer);
free (buffer);
}
else
else if (jerry_value_is_number (args_p[cc]))
{
printf ("(%d) ", args_p[cc]);
double number = jerry_get_number_value (args_p[cc]);
if ((int) number == number)
{
printf ("%d", (int) number);
}
else
{
char buff[50];
sprintf(buff, "%.10f", number);
printf("%s", buff);
}
}
}
printf ("\r\n");

View File

@ -56,14 +56,8 @@ jerry_port_fatal (jerry_fatal_code_t code)
double
jerry_port_get_current_time (void)
{
struct timeval tv;
if (gettimeofday (&tv, NULL) != 0)
{
return 0;
}
return ((double) tv.tv_sec) * 1000.0 + ((double) tv.tv_usec) / 1000.0;
uint32_t rtc_time = system_rtc_clock_cali_proc();
return (double) rtc_time;
} /* jerry_port_get_current_time */
/**