Import of the watch repository from Pebble

This commit is contained in:
Matthieu Jeanson 2024-12-12 16:43:03 -08:00 committed by Katharine Berry
commit 3b92768480
10334 changed files with 2564465 additions and 0 deletions

View file

@ -0,0 +1,22 @@
# Copyright © 2016 Intel Corporation
#
# 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.
ifdef V
$(info Compiling application)
endif
# Adding path for jerry script APIs
ZEPHYRINCLUDE += -I$(JERRY_INCLUDE)
obj-y += main-zephyr.o getline-zephyr.o

View file

@ -0,0 +1,57 @@
/* Copyright (c) 2016 Linaro
*
* 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 <zephyr.h>
#include <uart.h>
#include <drivers/console/uart_console.h>
#include "getline-zephyr.h"
/* While app processes one input line, Zephyr will have another line
buffer to accumulate more console input. */
static struct uart_console_input line_bufs[2];
static struct nano_fifo free_queue;
static struct nano_fifo used_queue;
char *zephyr_getline(void)
{
static struct uart_console_input *cmd;
/* Recycle cmd buffer returned previous time */
if (cmd != NULL)
{
nano_fifo_put(&free_queue, cmd);
}
cmd = nano_fifo_get(&used_queue, TICKS_UNLIMITED);
return cmd->line;
}
void zephyr_getline_init(void)
{
int i;
nano_fifo_init(&used_queue);
nano_fifo_init(&free_queue);
for (i = 0; i < sizeof(line_bufs) / sizeof(*line_bufs); i++)
{
nano_fifo_put(&free_queue, &line_bufs[i]);
}
/* Zephyr UART handler takes an empty buffer from free_queue,
stores UART input in it until EOL, and then puts it into
used_queue. */
uart_register_input(&free_queue, &used_queue, NULL);
}

View file

@ -0,0 +1,17 @@
/* Copyright (c) 2016 Linaro
*
* 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.
*/
void zephyr_getline_init(void);
char *zephyr_getline(void);

View file

@ -0,0 +1,48 @@
/* Copyright 2016 Intel Corporation
*
* 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 <stdarg.h>
#include "jerry-port.h"
/**
* Provide console message implementation for the engine.
*/
void
jerry_port_console (const char *format, /**< format string */
...) /**< parameters */
{
va_list args;
va_start (args, format);
vfprintf (stdout, format, args);
va_end (args);
} /* jerry_port_console */
/**
* Provide log message implementation for the engine.
*/
void
jerry_port_log (jerry_log_level_t level, /**< log level */
const char *format, /**< format string */
...) /**< parameters */
{
(void) level; /* ignore log level */
va_list args;
va_start (args, format);
vfprintf (stderr, format, args);
va_end (args);
} /* jerry_port_log */

View file

@ -0,0 +1,97 @@
/* Copyright 2016 Intel Corporation
*
* 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 <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <zephyr.h>
#include <misc/printk.h>
#include <misc/shell.h>
#include "getline-zephyr.h"
#include "jerry-api.h"
static jerry_value_t print_function;
static int shell_cmd_handler (char *source_buffer)
{
jerry_value_t ret_val;
ret_val = jerry_eval ((jerry_char_t *) source_buffer,
strlen (source_buffer),
false);
if (jerry_value_has_error_flag (ret_val))
{
/* User-friendly error messages require at least "cp" JerryScript
profile. Include a message prefix in case "cp_minimal" profile
is used. */
printf ("Error executing statement: ");
/* Clear error flag, otherwise print call below won't produce any
output. */
jerry_value_clear_error_flag (&ret_val);
}
if (!jerry_value_has_error_flag (print_function))
{
jerry_value_t ret_val_print = jerry_call_function (print_function,
jerry_create_undefined (),
&ret_val,
1);
jerry_release_value (ret_val_print);
}
jerry_release_value (ret_val);
return 0;
} /* shell_cmd_handler */
void main (void)
{
uint32_t zephyr_ver = sys_kernel_version_get ();
printf ("JerryScript build: " __DATE__ " " __TIME__ "\n");
printf ("JerryScript API %d.%d\n", JERRY_API_MAJOR_VERSION, JERRY_API_MINOR_VERSION);
printf ("Zephyr version %d.%d.%d\n", (int)SYS_KERNEL_VER_MAJOR (zephyr_ver),
(int)SYS_KERNEL_VER_MINOR (zephyr_ver),
(int)SYS_KERNEL_VER_PATCHLEVEL (zephyr_ver));
zephyr_getline_init ();
jerry_init (JERRY_INIT_EMPTY);
jerry_value_t global_obj_val = jerry_get_global_object ();
jerry_value_t print_func_name_val = jerry_create_string ((jerry_char_t *) "print");
print_function = jerry_get_property (global_obj_val, print_func_name_val);
jerry_release_value (print_func_name_val);
jerry_release_value (global_obj_val);
if (jerry_value_has_error_flag (print_function))
{
printf ("Error: could not look up print function, expression results won't be printed\n");
}
while (1)
{
char *s;
printf("js> ");
fflush(stdout);
s = zephyr_getline ();
if (*s)
{
shell_cmd_handler (s);
}
}
/* As we never retturn from REPL above, don't call jerry_cleanup() here. */
} /* main */