mirror of
https://github.com/jerryscript-project/jerryscript.git
synced 2025-12-15 16:29:21 +00:00
add wait for stm, move fake_exit to peripheraks
This commit is contained in:
parent
7077e42c85
commit
8094de86d1
@ -150,7 +150,7 @@ DEFINES_JERRY = -DMEM_HEAP_CHUNK_SIZE=256 -DMEM_HEAP_AREA_SIZE=32768 -DMEM_STATS
|
||||
SOURCES_JERRY = \
|
||||
$(sort \
|
||||
$(wildcard ./src/libruntime/*.c) \
|
||||
$(wildcard ./src/libperipherals/actuators.c) \
|
||||
$(wildcard ./src/libperipherals/*.c) \
|
||||
$(wildcard ./src/libjsparser/*.c) \
|
||||
$(wildcard ./src/libecmaobjects/*.c) \
|
||||
$(wildcard ./src/libecmaoperations/*.c) \
|
||||
|
||||
@ -13,38 +13,66 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#ifdef __TARGET_MCU
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f4xx_gpio.h"
|
||||
#include "stm32f4xx_rcc.h"
|
||||
#endif
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
|
||||
#include "actuators.h"
|
||||
#include "jerry-libc.h"
|
||||
|
||||
void
|
||||
led_toggle (uint32_t led_id)
|
||||
{
|
||||
__printf ("led_toggle: %d\n", led_id);
|
||||
}
|
||||
|
||||
void
|
||||
led_on (uint32_t led_id)
|
||||
{
|
||||
__printf ("led_on: %d\n", led_id);
|
||||
}
|
||||
|
||||
void
|
||||
led_off (uint32_t led_id)
|
||||
{
|
||||
__printf ("led_off: %d\n", led_id);
|
||||
}
|
||||
|
||||
void
|
||||
led_blink_once (uint32_t led_id)
|
||||
{
|
||||
#ifdef __HOST
|
||||
__printf ("led_blink_once: %d\n", led_id);
|
||||
#endif
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
blink_once (led_id);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
|
||||
void
|
||||
blink_once (uint32_t led)
|
||||
{
|
||||
uint32_t pin = led;
|
||||
uint32_t mode = (uint32_t)GPIO_Mode_OUT << (pin * 2);
|
||||
uint32_t speed = (uint32_t)GPIO_Speed_100MHz << (pin * 2);
|
||||
uint32_t type = (uint32_t)GPIO_OType_PP << pin;
|
||||
uint32_t pullup = (uint32_t)GPIO_PuPd_NOPULL << (pin * 2);
|
||||
|
||||
uint32_t mode = (uint32_t) GPIO_Mode_OUT << (pin * 2);
|
||||
uint32_t speed = (uint32_t) GPIO_Speed_100MHz << (pin * 2);
|
||||
uint32_t type = (uint32_t) GPIO_OType_PP << pin;
|
||||
uint32_t pullup = (uint32_t) GPIO_PuPd_NOPULL << (pin * 2);
|
||||
|
||||
TODO (INITIALIZE ONCE);
|
||||
//
|
||||
|
||||
// Initialise the peripheral clock.
|
||||
//
|
||||
RCC->AHB1ENR |= RCC_AHB1Periph_GPIOD;
|
||||
//
|
||||
|
||||
// Initilaise the GPIO port.
|
||||
//
|
||||
volatile GPIO_TypeDef* gpio = GPIOD;
|
||||
|
||||
gpio->MODER |= mode;
|
||||
@ -54,44 +82,27 @@ blink_once (uint32_t led)
|
||||
//
|
||||
// Toggle the selected LED indefinitely.
|
||||
//
|
||||
int index;
|
||||
|
||||
volatile int index;
|
||||
|
||||
int dot = 600000;
|
||||
int dash = dot * 3;
|
||||
|
||||
|
||||
while (1)
|
||||
{
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin);
|
||||
for (index = 0; index < dot; index++);
|
||||
gpio->BSRRH = (uint16_t) (1 << pin);
|
||||
for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin);
|
||||
for (index = 0; index < dot; index++);
|
||||
gpio->BSRRH = (uint16_t) (1 << pin);
|
||||
for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin);
|
||||
for (index = 0; index < dot; index++);
|
||||
gpio->BSRRH = (uint16_t) (1 << pin);
|
||||
for (index = 0; index < dash; index++);
|
||||
|
||||
for (index = 0; index < dash * 7; index++);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void led_toggle(uint32_t led_id)
|
||||
{
|
||||
__printf("led_toggle: %d\n", led_id);
|
||||
}
|
||||
|
||||
void led_on(uint32_t led_id)
|
||||
{
|
||||
__printf("led_on: %d\n", led_id);
|
||||
}
|
||||
|
||||
void led_off(uint32_t led_id)
|
||||
{
|
||||
__printf("led_off: %d\n", led_id);
|
||||
}
|
||||
|
||||
void led_blink_once(uint32_t led_id)
|
||||
{
|
||||
#ifdef __HOST
|
||||
__printf("led_blink_once: %d\n", led_id);
|
||||
#endif
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
blink_once(led_id);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
@ -18,17 +18,14 @@
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
// STM32 F4
|
||||
#define LED_GREEN 12
|
||||
#define LED_ORANGE 13
|
||||
#define LED_RED 14
|
||||
#define LED_BLUE 15
|
||||
|
||||
void led_toggle(uint32_t);
|
||||
void led_on(uint32_t);
|
||||
void led_off(uint32_t);
|
||||
void led_blink_once(uint32_t);
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
void blink_once (uint32_t);
|
||||
#endif
|
||||
|
||||
#endif /* ACTUATORS_H */
|
||||
|
||||
|
||||
@ -13,4 +13,121 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f4xx_gpio.h"
|
||||
#include "stm32f4xx_rcc.h"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#ifdef __HOST
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
// STM32 F4
|
||||
#define LED_GREEN 12
|
||||
#define LED_ORANGE 13
|
||||
#define LED_RED 14
|
||||
#define LED_BLUE 15
|
||||
|
||||
#endif
|
||||
|
||||
#include "common-io.h"
|
||||
#include "jerry-libc.h"
|
||||
|
||||
int
|
||||
digital_read (uint32_t arg1 __unused, uint32_t arg2 __unused)
|
||||
{
|
||||
JERRY_UNIMPLEMENTED ();
|
||||
}
|
||||
|
||||
void
|
||||
digital_write (uint32_t arg1 __unused, uint32_t arg2 __unused)
|
||||
{
|
||||
JERRY_UNIMPLEMENTED ();
|
||||
}
|
||||
|
||||
int
|
||||
analog_read (uint32_t arg1 __unused, uint32_t arg2 __unused)
|
||||
{
|
||||
JERRY_UNIMPLEMENTED ();
|
||||
}
|
||||
|
||||
void
|
||||
analog_write (uint32_t arg1 __unused, uint32_t arg2 __unused)
|
||||
{
|
||||
JERRY_UNIMPLEMENTED ();
|
||||
}
|
||||
|
||||
void
|
||||
wait_ms (uint32_t time_ms)
|
||||
{
|
||||
#ifdef __HOST
|
||||
// 1 millisecond = 1,000,000 Nanoseconds
|
||||
#define NANO_SECOND_MULTIPLIER 1000000
|
||||
__printf ("wait_ms: %d\n", time_ms);
|
||||
// const long interval_ms = time_ms * NANO_SECOND_MULTIPLIER;
|
||||
//
|
||||
// timespec sleep_value = {0};
|
||||
// sleep_value.tv_nsec = interval_ms;
|
||||
// nanosleep (&sleep_value, NULL);
|
||||
#endif
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
volatile uint32_t index;
|
||||
for (index = 0; index < time_ms; index++);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
void
|
||||
fake_exit (void)
|
||||
{
|
||||
uint32_t pin = LED_ORANGE;
|
||||
uint32_t mode = (uint32_t)GPIO_Mode_OUT << (pin * 2);
|
||||
uint32_t speed = (uint32_t)GPIO_Speed_100MHz << (pin * 2);
|
||||
uint32_t type = (uint32_t)GPIO_OType_PP << pin;
|
||||
uint32_t pullup = (uint32_t)GPIO_PuPd_NOPULL << (pin * 2);
|
||||
//
|
||||
// Initialise the peripheral clock.
|
||||
//
|
||||
RCC->AHB1ENR |= RCC_AHB1Periph_GPIOD;
|
||||
//
|
||||
// Initilaise the GPIO port.
|
||||
//
|
||||
volatile GPIO_TypeDef* gpio = GPIOD;
|
||||
|
||||
gpio->MODER |= mode;
|
||||
gpio->OSPEEDR |= speed;
|
||||
gpio->OTYPER |= type;
|
||||
gpio->PUPDR |= pullup;
|
||||
//
|
||||
// Toggle the selected LED indefinitely.
|
||||
//
|
||||
volatile int index;
|
||||
|
||||
// SOS
|
||||
|
||||
int dot = 600000;
|
||||
int dash = dot * 3;
|
||||
|
||||
while (1)
|
||||
{
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin);
|
||||
|
||||
for (index = 0; index < dash * 7; index++);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -16,11 +16,20 @@
|
||||
#ifndef COMMON_IO_H
|
||||
#define COMMON_IO_H
|
||||
|
||||
int digital_read(int, int);
|
||||
void digital_write(int, int);
|
||||
#include "globals.h"
|
||||
|
||||
int analog_read(int, int);
|
||||
void analog_write(int, int);
|
||||
int digital_read(uint32_t, uint32_t);
|
||||
void digital_write(uint32_t, uint32_t);
|
||||
|
||||
int analog_read(uint32_t, uint32_t);
|
||||
void analog_write(uint32_t, uint32_t);
|
||||
|
||||
void wait_ms(uint32_t);
|
||||
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
void fake_exit(void);
|
||||
#endif
|
||||
|
||||
#endif /* COMMON_IO_H */
|
||||
|
||||
|
||||
@ -13,4 +13,4 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
|
||||
#include "sensors.h"
|
||||
@ -16,6 +16,7 @@
|
||||
#ifndef SENSORS_H
|
||||
#define SENSORS_H
|
||||
|
||||
#include "globals.h"
|
||||
|
||||
#endif /* SENSORS_H */
|
||||
|
||||
|
||||
74
src/main.c
74
src/main.c
@ -14,19 +14,7 @@
|
||||
*/
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wpedantic"
|
||||
#pragma GCC diagnostic ignored "-Wsign-conversion"
|
||||
#include "stm32f4xx.h"
|
||||
#include "stm32f4xx_gpio.h"
|
||||
#include "stm32f4xx_rcc.h"
|
||||
#pragma GCC diagnostic pop
|
||||
|
||||
#define LED_GREEN 12
|
||||
#define LED_ORANGE 13
|
||||
#define LED_RED 14
|
||||
#define LED_BLUE 15
|
||||
#include "common-io.h"
|
||||
#include "generated.h"
|
||||
#endif
|
||||
|
||||
@ -158,64 +146,12 @@ main (int argc __unused,
|
||||
|
||||
return 0;
|
||||
}
|
||||
#elif !defined(__HOST) && defined(__TARGET_MCU)
|
||||
void fake_exit(void);
|
||||
|
||||
void
|
||||
fake_exit (void)
|
||||
{
|
||||
uint32_t pin = LED_ORANGE;
|
||||
uint32_t mode = (uint32_t)GPIO_Mode_OUT << (pin * 2);
|
||||
uint32_t speed = (uint32_t)GPIO_Speed_100MHz << (pin * 2);
|
||||
uint32_t type = (uint32_t)GPIO_OType_PP << pin;
|
||||
uint32_t pullup = (uint32_t)GPIO_PuPd_NOPULL << (pin * 2);
|
||||
//
|
||||
// Initialise the peripheral clock.
|
||||
//
|
||||
RCC->AHB1ENR |= RCC_AHB1Periph_GPIOD;
|
||||
//
|
||||
// Initilaise the GPIO port.
|
||||
//
|
||||
volatile GPIO_TypeDef* gpio = GPIOD;
|
||||
|
||||
gpio->MODER |= mode;
|
||||
gpio->OSPEEDR |= speed;
|
||||
gpio->OTYPER |= type;
|
||||
gpio->PUPDR |= pullup;
|
||||
//
|
||||
// Toggle the selected LED indefinitely.
|
||||
//
|
||||
volatile int index;
|
||||
|
||||
// SOS
|
||||
|
||||
int dot = 600000;
|
||||
int dash = dot * 3;
|
||||
|
||||
while (1)
|
||||
{
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dash; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin); for (index = 0; index < dash; index++);
|
||||
gpio->BSRRL = (uint16_t) (1 << pin); for (index = 0; index < dot; index++); gpio->BSRRH = (uint16_t) (1 << pin);
|
||||
|
||||
for (index = 0; index < dash * 7; index++);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __TARGET_MCU
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
//fake_exit();
|
||||
|
||||
const char *source_p = generated_source;
|
||||
const size_t source_size = sizeof(generated_source);
|
||||
|
||||
@ -226,6 +162,4 @@ main(void)
|
||||
|
||||
JERRY_UNREACHABLE();
|
||||
}
|
||||
#else /* !__HOST && !__TARGET_MCU */
|
||||
# error "!__HOST && !__TARGET_MCU"
|
||||
#endif /* !__HOST && !__TARGET_MCU */
|
||||
#endif
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user