Files
jerryscript/targets/mbed/source/main.cpp
T
Daniel Balla 4690d128b3 Add info to documentation about random numbers, initialize srand (#2056)
Issue #2053 has highlighted the fact that random numbers are always generated with the same seed.
An example of generating different random numbers, other than the original seed, has been added to the documentation.
Furthermore srand initialization has been added to jerry-main, and targets.
Update test-common.h with srand call.

JerryScript-DCO-1.0-Signed-off-by: Daniel Balla dballa@inf.u-szeged.hu
2017-11-03 15:31:57 +01:00

74 lines
1.9 KiB
C++

/* Copyright JS Foundation and other contributors, http://js.foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "mbed-drivers/mbed.h"
#include "jerry-core/include/jerryscript.h"
#include "jerry_run.h"
#include "jerry-targetjs.h"
static Serial pc (USBTX, USBRX); //tx, rx
static int jerry_task_init (void)
{
srand ((unsigned) jerry_port_get_current_time ());
int retcode;
DECLARE_JS_CODES;
/* run main.js */
retcode = js_entry (js_codes[0].source, js_codes[0].length);
if (retcode != 0)
{
printf ("js_entry failed code(%d) [%s]\r\n", retcode, js_codes[0].name);
js_exit ();
return -1;
}
/* run rest of the js files */
for (int src = 1; js_codes[src].source; src++)
{
retcode = js_eval (js_codes[src].source, js_codes[src].length);
if (retcode != 0)
{
printf ("js_eval failed code(%d) [%s]\r\n", retcode, js_codes[src].name);
js_exit ();
return -2;
}
}
return 0;
}
static void jerry_loop (void)
{
static uint32_t _jcount = 0;
js_loop (_jcount++);
}
void app_start (int, char**)
{
/* set 9600 baud rate for stdout */
pc.baud (9600);
printf ("\r\nJerryScript in mbed\r\n");
printf ("Version: \t%d.%d\n\n", JERRY_API_MAJOR_VERSION, JERRY_API_MINOR_VERSION);
if (jerry_task_init () == 0)
{
minar::Scheduler::postCallback(jerry_loop).period(minar::milliseconds(100));
}
}