static int jsp_new_connection(struct connection *connection) { struct telnet_connection *telnet_connection = malloc(sizeof(struct telnet_connection)); struct jsp_service *jsp_service = connection->service->priv; connection->priv = telnet_connection; /* initialize telnet connection information */ telnet_connection->closed = 0; telnet_connection->line_size = 0; telnet_connection->line_cursor = 0; telnet_connection->option_size = 0; telnet_connection->state = TELNET_STATE_DATA; /* negotiate telnet options */ telnet_write(connection, negotiate, strlen(negotiate)); /* print connection banner */ if (jsp_service->banner) { telnet_write(connection, jsp_service->banner, strlen(jsp_service->banner)); telnet_write(connection, "\r\n", 2); } jsp_service->connection = connection; int retval = target_register_timer_callback(&jsp_poll_read, 1, 1, jsp_service); if (ERROR_OK != retval) return retval; return ERROR_OK; }
static int stlink_usb_trace_enable(void *handle) { int res; struct stlink_usb_handle_s *h = handle; assert(handle != NULL); if (h->version.jtag >= STLINK_TRACE_MIN_VERSION) { uint32_t trace_hz; res = stlink_configure_target_trace_port(handle); if (res != ERROR_OK) LOG_ERROR("Unable to configure tracing on target\n"); trace_hz = h->trace.prescale > 0 ? h->trace.source_hz / (h->trace.prescale + 1) : h->trace.source_hz; stlink_usb_init_buffer(handle, h->rx_ep, 10); h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND; h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_START_TRACE_RX; h_u16_to_le(h->cmdbuf+h->cmdidx, (uint16_t)STLINK_TRACE_SIZE); h->cmdidx += 2; h_u32_to_le(h->cmdbuf+h->cmdidx, trace_hz); h->cmdidx += 4; res = stlink_usb_xfer(handle, h->databuf, 2); if (res == ERROR_OK) { h->trace.enabled = true; LOG_DEBUG("Tracing: recording at %" PRIu32 "Hz\n", trace_hz); /* We need the trace read function to be called at a * high-enough frequency to ensure reasonable * "timeliness" in processing ITM/DWT data. * TODO: An alternative could be using the asynchronous * features of the libusb-1.0 API to queue up one or more * reads in advance and requeue them once they are * completed. */ target_register_timer_callback(stlink_usb_trace_read_callback, 1, 1, handle); } } else { LOG_ERROR("Tracing is not supported by this version."); res = ERROR_FAIL; } return res; }
int armv7m_trace_tpiu_config(struct target *target) { struct armv7m_common *armv7m = target_to_armv7m(target); struct armv7m_trace_config *trace_config = &armv7m->trace_config; int prescaler; int retval; target_unregister_timer_callback(armv7m_poll_trace, target); retval = adapter_config_trace(trace_config->config_type == INTERNAL, trace_config->pin_protocol, trace_config->port_size, &trace_config->trace_freq); if (retval != ERROR_OK) return retval; if (!trace_config->trace_freq) { LOG_ERROR("Trace port frequency is 0, can't enable TPIU"); return ERROR_FAIL; } prescaler = trace_config->traceclkin_freq / trace_config->trace_freq; if (trace_config->traceclkin_freq % trace_config->trace_freq) { prescaler++; int trace_freq = trace_config->traceclkin_freq / prescaler; LOG_INFO("Can not obtain %u trace port frequency from %u TRACECLKIN frequency, using %u instead", trace_config->trace_freq, trace_config->traceclkin_freq, trace_freq); trace_config->trace_freq = trace_freq; retval = adapter_config_trace(trace_config->config_type == INTERNAL, trace_config->pin_protocol, trace_config->port_size, &trace_config->trace_freq); if (retval != ERROR_OK) return retval; } retval = target_write_u32(target, TPIU_CSPSR, 1 << trace_config->port_size); if (retval != ERROR_OK) return retval; retval = target_write_u32(target, TPIU_ACPR, prescaler - 1); if (retval != ERROR_OK) return retval; retval = target_write_u32(target, TPIU_SPPR, trace_config->pin_protocol); if (retval != ERROR_OK) return retval; uint32_t ffcr; retval = target_read_u32(target, TPIU_FFCR, &ffcr); if (retval != ERROR_OK) return retval; if (trace_config->formatter) ffcr |= (1 << 1); else ffcr &= ~(1 << 1); retval = target_write_u32(target, TPIU_FFCR, ffcr); if (retval != ERROR_OK) return retval; if (trace_config->config_type == INTERNAL) target_register_timer_callback(armv7m_poll_trace, 1, 1, target); target_call_event_callbacks(target, TARGET_EVENT_TRACE_CONFIG); return ERROR_OK; }