DRIVER_API_RC tst_gpio_srv_test_single_edge(cfw_client_t *gpio_client, unsigned int service_id, unsigned int input_pin, unsigned int output_pin) { cfw_service_conn_t *gpio_service_conn = NULL; if (!cfw_service_registered(service_id)) { cu_print("soc gpio register failed\n"); return DRV_RC_FAIL; } cfw_open_service_conn(gpio_client, service_id, &gpio_service_conn); SRV_WAIT((!gpio_service_conn), 1000); CU_ASSERT("TST_GPIO open service failed", (gpio_service_conn)); if(gpio_service_conn == NULL) { return DRV_RC_FAIL; } TEST_GPIO(configure, "TST_GPIO config failed", gpio_service_conn, output_pin, 1, "cfg_output single edge"); // ******************************** // * Test rising edge * // ******************************** TEST_GPIO(set_state, "TST_GPIO set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1 re"); TEST_GPIO(listen, "TST_GPIO listen failed (re)", gpio_service_conn, input_pin, RISING_EDGE, DEB_OFF, "listen re"); tst_gpio_event = 0; TEST_GPIO(set_state, "TST_GPIO set 2 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0 re"); // Check no event CU_ASSERT("TST_GPIO RE irq wrong detected", (tst_gpio_event == 0)); if(tst_gpio_event) { return DRV_RC_FAIL; } // Check GPIO port value TEST_GPIO(get_state, "TST_GPIO get 1 failed (re)", gpio_service_conn, "get_output 1 re"); CU_ASSERT("TST_GPIO RE wrong port state detected (should be LOW)", (!(tst_gpio_get_value & (1<<input_pin)))); if(tst_gpio_get_value & (1<<input_pin)) { return DRV_RC_FAIL; } TEST_GPIO(set_state, "TST_GPIO set 3 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1 re"); // Check event CU_ASSERT("TST_GPIO RE irq RE not detected", (tst_gpio_event == 1)); if(tst_gpio_event != 1) { return DRV_RC_FAIL; } // Check GPIO port value TEST_GPIO(get_state, "TST_GPIO get 2 failed (re)", gpio_service_conn, "get_output 2 re"); CU_ASSERT("TST_GPIO RE wrong port state detected (should be HIGH)", (tst_gpio_get_value & (1<<input_pin))); if(!(tst_gpio_get_value & (1<<input_pin))) { return DRV_RC_FAIL; } TEST_GPIO(unlisten, "TST_GPIO unlisten failed (re)", gpio_service_conn, input_pin, "unlisten re"); // ******************************** // * Test falling edge * // ******************************** TEST_GPIO(set_state, "TST_GPIO set 1 failed (fe)", gpio_service_conn, output_pin, 0, "set_output 1 fe"); TEST_GPIO(listen, "TST_GPIO listen failed (fe)", gpio_service_conn, input_pin, FALLING_EDGE, DEB_OFF, "listen fe"); tst_gpio_event = 0; // Check no event TEST_GPIO(set_state, "TST_GPIO set 2 failed (fe)", gpio_service_conn, output_pin, 1, "set_output 0 fe"); CU_ASSERT("TST_GPIO FE irq wrong detected", (tst_gpio_event == 0)); if(tst_gpio_event) { return DRV_RC_FAIL; } // Check GPIO port value TEST_GPIO(get_state, "TST_GPIO get 1 failed (fe)", gpio_service_conn, "get_output 1 fe"); CU_ASSERT("TST_GPIO FE wrong port state detected (should be HIGH)", (tst_gpio_get_value & (1<<input_pin))); if(!(tst_gpio_get_value & (1<<input_pin))) { return DRV_RC_FAIL; } // Check event TEST_GPIO(set_state, "TST_GPIO set 3 failed (fe)", gpio_service_conn, output_pin, 0, "set_output 1 fe"); CU_ASSERT("TST_GPIO FE irq not detected", (tst_gpio_event == 1)); if(tst_gpio_event != 1) { return DRV_RC_FAIL; } // Check GPIO port value TEST_GPIO(get_state, "TST_GPIO get 2 failed (fe)", gpio_service_conn, "get_output 2 fe"); CU_ASSERT("TST_GPIO FE wrong port state detected (should be LOW)", (!(tst_gpio_get_value & (1<<input_pin)))); if(tst_gpio_get_value & (1<<input_pin)) { return DRV_RC_FAIL; } TEST_GPIO(unlisten, "TST_GPIO unlisten failed (fe)", gpio_service_conn, input_pin, "unlisten fe"); // Deconfigure output pin TEST_GPIO(set_state, "TST_GPIO set deconfig failed", gpio_service_conn, output_pin, 0, "set_output 0"); TEST_GPIO(configure, "TST_GPIO end config failed", gpio_service_conn, output_pin, 0, "cfg_input single edge"); cu_print("GPIO single edge test done\n"); return DRV_RC_OK; }
int press_simulation(unsigned int service_id, unsigned int input_pin, unsigned int output_pin) { cfw_service_conn_t *gpio_service_conn = NULL; cfw_client_t *gpio_client = cfw_client_init( get_test_queue(), pwrbtn_tst_handle_msg, NULL); if (!cfw_service_registered(service_id)) { cu_print("TST_PWRBTN: ss gpio service not registered\n"); return DRV_RC_FAIL; } cfw_open_service_conn(gpio_client, service_id, &gpio_service_conn); SRV_WAIT((!gpio_service_conn), 2000); CU_ASSERT("TST_PWRBTN: can not open ss gpio service", (gpio_service_conn)); if (gpio_service_conn == NULL) { return DRV_RC_FAIL; } /* The configuration put the pin to 0 => the pin have to be set to 1 * before first press simulation */ TEST_PWRBTN(configure, "TST_PWRBTN: gpio configuration failed", gpio_service_conn, output_pin, 1, "SS pin 2 output"); SRV_WAIT((!tst_pwrbtn_configure), 2000); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait state response */ SRV_WAIT((!tst_pwrbtn_set_state), 2000); /* wait 3s */ local_task_sleep_ms(3000); tst_step = VERY_SH_PRESS; cu_print("Start pattern with press_duration = 700ms\n"); TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(700); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_very_short), 2000); /* wait 3s */ local_task_sleep_ms(3000); cu_print("Start pattern with press_duration = 2500ms\n"); tst_step = SH_PRESS; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(2500); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_short), 2000); /* wait 3s */ local_task_sleep_ms(3000); cu_print("Start pattern with press_duration = 4000ms\n"); tst_step = SINGLE_PRESS; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(4000); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_single), 2000); /* wait 3s */ local_task_sleep_ms(3000); cu_print("Start pattern with press_duration = 7000ms\n"); tst_step = L_PRESS; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(7000); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_long), 2000); /* wait 3s */ local_task_sleep_ms(3000); cu_print("Start pattern with press_duration = 12000ms\n"); tst_step = VERY_L_PRESS; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(12000); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait 3s */ local_task_sleep_ms(3000); /* Start failed double press pattern : very_short_press + 550 ms delay max + short_press */ cu_print("Start double pattern press failed...\n"); tst_step = DBLE_PRESS_FAIL_1; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(700); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_double_fail_1), 2000); /* wait between the very short press */ local_task_sleep_ms(550); tst_step = DBLE_PRESS_FAIL_2; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(2700); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_double_fail_2), 2000); /* wait 3s */ local_task_sleep_ms(3000); cu_print("Start too short pattern with duration = 300ms\n"); tst_step = TOO_SHORT_PRESS; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(300); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_double_fail_2), 2000); /* wait 3s */ local_task_sleep_ms(3000); /* Start double press pattern : very_short_press + 350 ms delay max + very_short_press */ cu_print("Start double pattern press...\n"); tst_step = DBLE_PRESS; TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(700); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait between the very short press */ local_task_sleep_ms(350); TEST_PWRBTN(set_state, "TST_PWRBTN: set 0 failed (re)", gpio_service_conn, output_pin, 0, "set_output 0"); local_task_sleep_ms(900); TEST_PWRBTN(set_state, "TST_PWRBTN: set 1 failed (re)", gpio_service_conn, output_pin, 1, "set_output 1"); /* wait pattern detection */ SRV_WAIT((!tst_double), 2000); /* wait 2s */ local_task_sleep_ms(2000); cfw_close_service_conn(gpio_service_conn, NULL); return DRV_RC_OK; }