add blink_toggle_once
This commit is contained in:
+1
-1
@@ -110,7 +110,7 @@ CFLAGS_CORTEXM4 ?= -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m -mthumb \
|
|||||||
# Common
|
# Common
|
||||||
#
|
#
|
||||||
|
|
||||||
CFLAGS_COMMON ?= $(INCLUDES) -std=c99 -fsanitize=address -fdiagnostics-color=always
|
CFLAGS_COMMON ?= $(INCLUDES) -std=c99 #-fsanitize=address -fdiagnostics-color=always
|
||||||
|
|
||||||
LDFLAGS ?=
|
LDFLAGS ?=
|
||||||
|
|
||||||
|
|||||||
+2
-13
@@ -15,17 +15,6 @@
|
|||||||
|
|
||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
|
|
||||||
static const char* generated_source __unused = ""
|
static const char* generated_source = ""
|
||||||
"while (true) {\n"
|
"LEDToggle (14);\n"
|
||||||
"LEDToggle (LED3);\n"
|
|
||||||
"LEDToggle (LED6);\n"
|
|
||||||
"LEDToggle (LED7);\n"
|
|
||||||
"LEDToggle (LED4);\n"
|
|
||||||
"LEDToggle (LED10);\n"
|
|
||||||
"LEDToggle (LED8);\n"
|
|
||||||
"LEDToggle (LED9);\n"
|
|
||||||
"LEDToggle (LED5);\n"
|
|
||||||
"\n"
|
|
||||||
"wait(500);\n"
|
|
||||||
"}\n"
|
|
||||||
;
|
;
|
||||||
|
|||||||
@@ -25,6 +25,10 @@
|
|||||||
#include "mem-heap.h"
|
#include "mem-heap.h"
|
||||||
#include "opcodes.h"
|
#include "opcodes.h"
|
||||||
|
|
||||||
|
#include "actuators.h"
|
||||||
|
#include "common-io.h"
|
||||||
|
#include "sensors.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Note:
|
* Note:
|
||||||
* The note describes exception handling in opcode handlers that perform operations,
|
* The note describes exception handling in opcode handlers that perform operations,
|
||||||
@@ -416,7 +420,10 @@ OP_UNIMPLEMENTED_LIST(DEFINE_UNIMPLEMENTED_OP);
|
|||||||
|
|
||||||
ecma_completion_value_t
|
ecma_completion_value_t
|
||||||
opfunc_call_1 (OPCODE opdata __unused, struct __int_data *int_data)
|
opfunc_call_1 (OPCODE opdata __unused, struct __int_data *int_data)
|
||||||
{
|
{
|
||||||
|
ecma_completion_value_t ret_value;
|
||||||
|
ret_value = ecma_make_empty_completion_value ();
|
||||||
|
|
||||||
#ifdef __HOST
|
#ifdef __HOST
|
||||||
__printf ("%d::op_call_1:idx:%d:%d\t",
|
__printf ("%d::op_call_1:idx:%d:%d\t",
|
||||||
int_data->pos,
|
int_data->pos,
|
||||||
@@ -432,11 +439,21 @@ opfunc_call_1 (OPCODE opdata __unused, struct __int_data *int_data)
|
|||||||
#ifdef __HOST
|
#ifdef __HOST
|
||||||
__printf("%s\n", str_value.str_p);
|
__printf("%s\n", str_value.str_p);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (!__strcmp ((const char*)str_value.str_p, "LEDToggle"))
|
||||||
|
{
|
||||||
|
TRY_CATCH (cond_value, get_variable_value (int_data, opdata.data.call_1.arg1_lit_idx, false), ret_value);
|
||||||
|
JERRY_ASSERT(cond_value.value.value_type == ECMA_TYPE_NUMBER );
|
||||||
|
ecma_number_t * num_p = (ecma_number_t*)ecma_get_pointer(cond_value.value.value);
|
||||||
|
uint32_t int_num = (uint32_t)*num_p;
|
||||||
|
led_blink_once (int_num);
|
||||||
|
ret_value = ecma_make_empty_completion_value ();
|
||||||
|
FINALIZE (cond_value);
|
||||||
|
}
|
||||||
|
|
||||||
free_string_literal_copy( &str_value);
|
free_string_literal_copy (&str_value);
|
||||||
|
|
||||||
// FIXME
|
return ret_value;
|
||||||
return ecma_make_empty_completion_value();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -13,20 +13,83 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
#include "actuators.h"
|
#include "actuators.h"
|
||||||
#include "jerry-libc.h"
|
#include "jerry-libc.h"
|
||||||
|
|
||||||
void led_toggle(int led_id)
|
#ifdef __TARGET_MCU
|
||||||
|
|
||||||
|
void
|
||||||
|
blink_once (uint32_t led)
|
||||||
{
|
{
|
||||||
__printf("led_toogle: %d", led_id);
|
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);
|
||||||
|
|
||||||
|
TODO (INITIALIZE ONCE);
|
||||||
|
//
|
||||||
|
// 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.
|
||||||
|
//
|
||||||
|
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++);
|
||||||
|
|
||||||
|
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(int led_id)
|
void led_on(uint32_t led_id)
|
||||||
{
|
{
|
||||||
__printf("led_on: %d", led_id);
|
__printf("led_on: %d\n", led_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
void led_off(int led_id)
|
void led_off(uint32_t led_id)
|
||||||
{
|
{
|
||||||
__printf("led_off: %d", 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
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,15 +16,19 @@
|
|||||||
#ifndef ACTUATORS_H
|
#ifndef ACTUATORS_H
|
||||||
#define ACTUATORS_H
|
#define ACTUATORS_H
|
||||||
|
|
||||||
|
#include "globals.h"
|
||||||
|
|
||||||
// STM32 F4
|
// STM32 F4
|
||||||
#define LED_GREEN 12
|
#define LED_GREEN 12
|
||||||
#define LED_ORANGE 13
|
#define LED_ORANGE 13
|
||||||
#define LED_RED 14
|
#define LED_RED 14
|
||||||
#define LED_BLUE 15
|
#define LED_BLUE 15
|
||||||
|
|
||||||
void led_toggle(int);
|
void led_toggle(uint32_t);
|
||||||
void led_on(int);
|
void led_on(uint32_t);
|
||||||
void led_off(int);
|
void led_off(uint32_t);
|
||||||
|
void led_blink_once(uint32_t);
|
||||||
|
void blink_once (uint32_t);
|
||||||
|
|
||||||
#endif /* ACTUATORS_H */
|
#endif /* ACTUATORS_H */
|
||||||
|
|
||||||
|
|||||||
+5
-2
@@ -154,7 +154,7 @@ void fake_exit(void);
|
|||||||
void
|
void
|
||||||
fake_exit (void)
|
fake_exit (void)
|
||||||
{
|
{
|
||||||
uint32_t pin = LED_RED;
|
uint32_t pin = LED_ORANGE;
|
||||||
uint32_t mode = (uint32_t)GPIO_Mode_OUT << (pin * 2);
|
uint32_t mode = (uint32_t)GPIO_Mode_OUT << (pin * 2);
|
||||||
uint32_t speed = (uint32_t)GPIO_Speed_100MHz << (pin * 2);
|
uint32_t speed = (uint32_t)GPIO_Speed_100MHz << (pin * 2);
|
||||||
uint32_t type = (uint32_t)GPIO_OType_PP << pin;
|
uint32_t type = (uint32_t)GPIO_OType_PP << pin;
|
||||||
@@ -175,7 +175,7 @@ fake_exit (void)
|
|||||||
//
|
//
|
||||||
// Toggle the selected LED indefinitely.
|
// Toggle the selected LED indefinitely.
|
||||||
//
|
//
|
||||||
int index;
|
volatile int index;
|
||||||
|
|
||||||
// SOS
|
// SOS
|
||||||
|
|
||||||
@@ -203,6 +203,9 @@ fake_exit (void)
|
|||||||
int
|
int
|
||||||
main(void)
|
main(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
//fake_exit();
|
||||||
|
|
||||||
const char *source_p = generated_source;
|
const char *source_p = generated_source;
|
||||||
const size_t source_size = sizeof(generated_source);
|
const size_t source_size = sizeof(generated_source);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user