add blink_toggle_once

This commit is contained in:
e.gavrin 2014-07-24 19:27:19 +04:00
parent 89834cd616
commit c2f82eefc0
6 changed files with 105 additions and 29 deletions

View File

@ -110,7 +110,7 @@ CFLAGS_CORTEXM4 ?= -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m -mthumb \
# Common
#
CFLAGS_COMMON ?= $(INCLUDES) -std=c99 -fsanitize=address -fdiagnostics-color=always
CFLAGS_COMMON ?= $(INCLUDES) -std=c99 #-fsanitize=address -fdiagnostics-color=always
LDFLAGS ?=

View File

@ -15,17 +15,6 @@
#include "globals.h"
static const char* generated_source __unused = ""
"while (true) {\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"
static const char* generated_source = ""
"LEDToggle (14);\n"
;

View File

@ -25,6 +25,10 @@
#include "mem-heap.h"
#include "opcodes.h"
#include "actuators.h"
#include "common-io.h"
#include "sensors.h"
/**
* Note:
* 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
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
__printf ("%d::op_call_1:idx:%d:%d\t",
int_data->pos,
@ -432,11 +439,21 @@ opfunc_call_1 (OPCODE opdata __unused, struct __int_data *int_data)
#ifdef __HOST
__printf("%s\n", str_value.str_p);
#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 ecma_make_empty_completion_value();
return ret_value;
}
/**

View File

@ -13,20 +13,83 @@
* 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 "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
}

View File

@ -16,15 +16,19 @@
#ifndef ACTUATORS_H
#define ACTUATORS_H
#include "globals.h"
// STM32 F4
#define LED_GREEN 12
#define LED_ORANGE 13
#define LED_RED 14
#define LED_BLUE 15
void led_toggle(int);
void led_on(int);
void led_off(int);
void led_toggle(uint32_t);
void led_on(uint32_t);
void led_off(uint32_t);
void led_blink_once(uint32_t);
void blink_once (uint32_t);
#endif /* ACTUATORS_H */

View File

@ -154,7 +154,7 @@ void fake_exit(void);
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 speed = (uint32_t)GPIO_Speed_100MHz << (pin * 2);
uint32_t type = (uint32_t)GPIO_OType_PP << pin;
@ -175,7 +175,7 @@ fake_exit (void)
//
// Toggle the selected LED indefinitely.
//
int index;
volatile int index;
// SOS
@ -203,6 +203,9 @@ fake_exit (void)
int
main(void)
{
//fake_exit();
const char *source_p = generated_source;
const size_t source_size = sizeof(generated_source);