void serial_test( void ) { cyg_io_handle_t ser_handle; cyg_ser_cfg_t *cfg=&test_configs[0]; cyg_ser_cfg_t new_cfg; int count = sizeof(test_configs) / sizeof(cyg_ser_cfg_t); int i; test_open_ser(&ser_handle); // We need the filter for this test. test_ping(ser_handle); // Choose the configuration with the fastest baud rate, to be most // provocative. Start at 1 coz cfg already points at 0 for (i=1; i<count; i++) { if (cfg->baud_rate < test_configs[i].baud_rate) cfg=&test_configs[i]; } // Set flow control from configuration // Choose software first #ifdef CYGOPT_IO_SERIAL_FLOW_CONTROL_SOFTWARE CYG_TEST_INFO("Setting software flow control"); new_cfg = *cfg; new_cfg.flags |= CYGNUM_SERIAL_FLOW_XONXOFF_RX | CYGNUM_SERIAL_FLOW_XONXOFF_TX; if (ENOERR == change_config(ser_handle, &new_cfg)) run_tests( ser_handle ); #endif // hardware flow control #ifdef CYGOPT_IO_SERIAL_FLOW_CONTROL_HW CYG_TEST_INFO("Setting RTS/CTS hardware flow control"); new_cfg = *cfg; new_cfg.flags |= CYGNUM_SERIAL_FLOW_RTSCTS_RX|CYGNUM_SERIAL_FLOW_RTSCTS_TX; if (ENOERR == change_config(ser_handle, &new_cfg)) run_tests( ser_handle ); CYG_TEST_INFO("Setting DSR/DTR hardware flow control"); new_cfg = *cfg; new_cfg.flags |= CYGNUM_SERIAL_FLOW_DSRDTR_RX|CYGNUM_SERIAL_FLOW_DSRDTR_TX; if (ENOERR == change_config(ser_handle, &new_cfg)) run_tests( ser_handle ); #endif CYG_TEST_PASS_FINISH("flow2 test OK"); }
//--------------------------------------------------------------------------- // Serial test main function. void serial_test( void ) { char test_msg1[]="This is a test message!\n"; char test_msg2[]="$O5468697320697320612074657374206d657373616765210d0a#12"; cyg_uint32 msglen; cyg_io_handle_t ser_handle; test_open_ser(&ser_handle); CYG_TEST_INFO("Writing a raw string to the serial device..."); msglen = strlen(&test_msg1[0]); Tcyg_io_write(ser_handle, &test_msg1[0], &msglen); CYG_TEST_INFO("Writing a GDB encoded string to the serial device..."); msglen = strlen(&test_msg2[0]); Tcyg_io_write(ser_handle, &test_msg2[0], &msglen); CYG_TEST_PASS_FINISH("serial2 test OK"); }
void serial_api_test(int dummy) { cyg_io_handle_t handle; int res; cyg_uint32 len; unsigned char buffer[16]; // Always return... if (dummy) return; CYG_TEST_FAIL_FINISH("Not reached"); test_open_ser(&handle); // read & write res = cyg_io_read(handle, &buffer[0], &len); res = cyg_io_write(handle, &buffer[0], &len); // cyg_io_get_config cyg_io_get_config(handle, CYG_IO_GET_CONFIG_SERIAL_INFO, &buffer[0], &len); cyg_io_get_config(handle, CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN, &buffer[0], &len); cyg_io_get_config(handle, CYG_IO_GET_CONFIG_SERIAL_INPUT_FLUSH, &buffer[0], &len); cyg_io_get_config(handle, CYG_IO_GET_CONFIG_SERIAL_ABORT, &buffer[0], &len); cyg_io_get_config(handle, CYG_IO_GET_CONFIG_SERIAL_OUTPUT_FLUSH, &buffer[0], &len); // cyg_io_set_config cyg_io_set_config(handle, CYG_IO_SET_CONFIG_SERIAL_INFO, &buffer[0], &len); }