diff --git a/src/generated.h b/src/generated.h index 24d92e696..96f3a0d3a 100644 --- a/src/generated.h +++ b/src/generated.h @@ -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" + ; diff --git a/src/libcoreint/opcodes.c b/src/libcoreint/opcodes.c index edc27460a..e60762bf4 100644 --- a/src/libcoreint/opcodes.c +++ b/src/libcoreint/opcodes.c @@ -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); diff --git a/src/libperipherals/actuators.c b/src/libperipherals/actuators.c index fcbb5af97..818a498d0 100644 --- a/src/libperipherals/actuators.c +++ b/src/libperipherals/actuators.c @@ -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 }