can: Fix reset mode entry and exit calls

This commit fixes multiple bugs caused by incorrect calls to
can_enter_reset_mode() and can_exit_reset_mode. Example test
scripts also updated to match new runners.
This commit is contained in:
Darian Leung 2019-10-22 18:05:19 +08:00
parent cbe8274651
commit 896ba6a83e
4 changed files with 16 additions and 13 deletions

View File

@ -376,7 +376,8 @@ static void can_intr_handler_err_warn(can_status_reg_t *status, BaseType_t *task
can_alert_handler(CAN_ALERT_ABOVE_ERR_WARN, alert_req);
} else if (p_can_obj->control_flags & CTRL_FLAG_RECOVERING) {
//Bus recovery complete.
can_enter_reset_mode();
esp_err_t err = can_enter_reset_mode();
assert(err == ESP_OK);
//Reset and set flags to the equivalent of the stopped state
CAN_RESET_FLAG(p_can_obj->control_flags, CTRL_FLAG_RECOVERING | CTRL_FLAG_ERR_WARN |
CTRL_FLAG_ERR_PASSIVE | CTRL_FLAG_BUS_OFF |
@ -678,7 +679,7 @@ esp_err_t can_driver_install(const can_general_config_t *g_config, const can_tim
}
periph_module_reset(PERIPH_CAN_MODULE);
periph_module_enable(PERIPH_CAN_MODULE); //Enable APB CLK to CAN peripheral
esp_err_t err = can_exit_reset_mode(); //Must enter reset mode to write to config registers
esp_err_t err = can_enter_reset_mode(); //Must enter reset mode to write to config registers
assert(err == ESP_OK);
can_config_pelican(); //Use PeliCAN addresses
/* Note: REC is allowed to increase even in reset mode. Listen only mode
@ -734,7 +735,7 @@ esp_err_t can_driver_uninstall()
//Check state
CAN_CHECK_FROM_CRIT(p_can_obj != NULL, ESP_ERR_INVALID_STATE);
CAN_CHECK_FROM_CRIT(p_can_obj->control_flags & (CTRL_FLAG_STOPPED | CTRL_FLAG_BUS_OFF), ESP_ERR_INVALID_STATE);
esp_err_t err = can_exit_reset_mode(); //Enter reset mode to stop any CAN bus activity
esp_err_t err = can_enter_reset_mode(); //Enter reset mode to stop any CAN bus activity
assert(err == ESP_OK);
//Clear registers by reading
(void) can_get_interrupt_reason();
@ -773,7 +774,7 @@ esp_err_t can_start()
//Reset RX queue, and RX message count
xQueueReset(p_can_obj->rx_queue);
p_can_obj->rx_msg_count = 0;
esp_err_t err = can_exit_reset_mode(); //Should already be in bus-off mode, set again to make sure
esp_err_t err = can_enter_reset_mode(); //Should already be in bus-off mode, set again to make sure
assert(err == ESP_OK);
//Currently in listen only mode, need to set to mode specified by configuration
@ -803,7 +804,7 @@ esp_err_t can_stop()
CAN_CHECK_FROM_CRIT(!(p_can_obj->control_flags & (CTRL_FLAG_STOPPED | CTRL_FLAG_BUS_OFF)), ESP_ERR_INVALID_STATE);
//Clear interrupts and reset flags
esp_err_t err = can_exit_reset_mode();
esp_err_t err = can_enter_reset_mode();
assert(err == ESP_OK);
(void) can_get_interrupt_reason(); //Read interrupt register to clear interrupts
can_config_mode(CAN_MODE_LISTEN_ONLY); //Set to listen only mode to freeze REC

View File

@ -16,10 +16,11 @@ import IDF
STR_EXPECT = ("CAN Alert and Recovery: Driver installed", "CAN Alert and Recovery: Driver uninstalled")
EXPECT_TIMEOUT = 20
@IDF.idf_example_test(env_tag='Example_CAN')
@IDF.idf_example_test(env_tag='Example_CAN1')
def test_can_alert_and_recovery_example(env, extra_data):
#Get device under test, flash and start example. "dut4" must be defined in EnvConfig
dut = env.get_dut('dut4', 'examples/peripherals/can/can_alert_and_recovery')
# Get device under test, flash and start example. "dut4" must be defined in EnvConfig
dut = env.get_dut('dut1', 'examples/peripherals/can/can_alert_and_recovery')
dut.start_app()
for string in STR_EXPECT:

View File

@ -17,7 +17,7 @@ import IDF
#Define tuple of strings to expect for each DUT.
master_expect = ("CAN Master: Driver installed", "CAN Master: Driver uninstalled")
slave_expect = ("CAN Slave: Driver installed", "CAN Slave: Driver uninstalled")
listen_only_expect = ("CAN Listen Only: Driver installed", "Listen Only: Driver uninstalled")
listen_only_expect = ("CAN Listen Only: Driver installed", "CAN Listen Only: Driver uninstalled")
def dut_thread_callback(**kwargs):
#Parse keyword arguments
@ -34,7 +34,7 @@ def dut_thread_callback(**kwargs):
#Mark thread has run to completion without any exceptions
result[0] = True
@IDF.idf_example_test(env_tag='Example_CAN')
@IDF.idf_example_test(env_tag='Example_CAN2')
def test_can_network_example(env, extra_data):
#Get device under test. "dut1", "dut2", and "dut3" must be properly defined in EnvConfig

View File

@ -16,10 +16,11 @@ import IDF
STR_EXPECT = ("CAN Self Test: Driver installed", "CAN Self Test: Driver uninstalled")
EXPECT_TIMEOUT = 20
@IDF.idf_example_test(env_tag='Example_CAN')
@IDF.idf_example_test(env_tag='Example_CAN1')
def test_can_self_test_example(env, extra_data):
#Get device under test, flash and start example. "dut4" must be defined in EnvConfig
dut = env.get_dut('dut4', 'examples/peripherals/can/can_self_test')
# Get device under test, flash and start example. "dut4" must be defined in EnvConfig
dut = env.get_dut('dut1', 'examples/peripherals/can/can_self_test')
dut.start_app()
for string in STR_EXPECT: