fixed led processing and wait

This commit is contained in:
e.gavrin 2014-07-25 17:47:09 +04:00
parent 5da1df37de
commit 43a8bbd576
3 changed files with 67 additions and 11 deletions

View File

@ -15,9 +15,21 @@
#include "globals.h"
static const char* generated_source = ""
"LEDToggle (12);\n"
"LEDToggle (13);\n"
"LEDToggle (14);\n"
"LEDToggle (15);\n"
;
static const char* generated_source = ""
"var tmp, a, b = 1, c = 2, d, e = 3, g = 4;\n"
"var count = 10000*10000;\n"
"for (var i = 0; i < count; i += 1)\n"
"{\n"
" tmp = b * c;\n"
" a = tmp + g;\n"
" d = tmp * e;\n"
"\n"
" if (i % 1000 == 0) \n"
" { \n"
" LEDToggle (12);\n"
" LEDToggle (13);\n"
" LEDToggle (14);\n"
" LEDToggle (15);\n"
" }\n"
"}\n"
;

View File

@ -410,6 +410,39 @@ opfunc_call_1 (OPCODE opdata __unused, struct __int_data *int_data)
#endif
if (!__strcmp ((const char*)str_value.str_p, "LEDToggle"))
{
ECMA_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_toggle (int_num);
ret_value = ecma_make_empty_completion_value ();
ECMA_FINALIZE (cond_value);
}
if (!__strcmp ((const char*)str_value.str_p, "LEDOn"))
{
ECMA_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_on (int_num);
ret_value = ecma_make_empty_completion_value ();
ECMA_FINALIZE (cond_value);
}
if (!__strcmp ((const char*)str_value.str_p, "LEDOff"))
{
ECMA_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_off (int_num);
ret_value = ecma_make_empty_completion_value ();
ECMA_FINALIZE (cond_value);
}
if (!__strcmp ((const char*)str_value.str_p, "LEDOnce"))
{
ECMA_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 );
@ -419,6 +452,17 @@ opfunc_call_1 (OPCODE opdata __unused, struct __int_data *int_data)
ret_value = ecma_make_empty_completion_value ();
ECMA_FINALIZE (cond_value);
}
if (!__strcmp ((const char*)str_value.str_p, "wait"))
{
ECMA_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;
wait_ms (int_num);
ret_value = ecma_make_empty_completion_value ();
ECMA_FINALIZE (cond_value);
}
free_string_literal_copy (&str_value);

View File

@ -36,9 +36,9 @@ led_toggle (uint32_t led_id)
#ifdef __TARGET_MCU
init_led (led_id);
init_led (led_id);
GPIOD->ODR ^= (uint16_t) (1 << led_id);
GPIOD->ODR ^= (uint16_t) (1 << led_id);
#endif
}
@ -54,6 +54,7 @@ led_on (uint32_t led_id)
init_led (led_id);
GPIOD->BSRRH = (uint16_t) (1 << led_id);
GPIOD->BSRRL = (uint16_t) (1 << led_id);
#endif
}
@ -67,6 +68,7 @@ led_off (uint32_t led_id)
#ifdef __TARGET_MCU
init_led (led_id);
GPIOD->BSRRL = (uint16_t) (1 << led_id);
GPIOD->BSRRH = (uint16_t) (1 << led_id);
#endif
}
@ -81,13 +83,11 @@ led_blink_once (uint32_t led_id)
#ifdef __TARGET_MCU
init_led (led_id);
uint32_t dot = 600000 * 3;
uint32_t dot = 300000;
GPIOD->BSRRL = (uint16_t) (1 << led_id);
wait_ms (dot);
GPIOD->BSRRH = (uint16_t) (1 << led_id);
wait_ms (dot);
#endif
}