mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2025-12-30 18:41:11 +00:00
twinkie: clean-up disabled SNIFFER_HEADER_V2 code
Remove all the CONFIG_USBC_SNIFFER_HEADER_V2 code, it was not fully satisfactory and we have a better alternative. Signed-off-by: Vincent Palatin <vpalatin@chromium.org> BRANCH=twinkie BUG=none TEST=make BOARD=twinkie Change-Id: I26d3396b2933be5276f916e3ac60c96347cb67f6 Reviewed-on: https://chromium-review.googlesource.com/743015 Commit-Ready: Vincent Palatin <vpalatin@chromium.org> Tested-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
committed by
chrome-bot
parent
b9e95e9692
commit
7b8fb2ad2a
@@ -28,13 +28,6 @@
|
||||
#define CONFIG_USB_PD_TCPM_STUB
|
||||
#define CONFIG_USB_PD_VBUS_DETECT_GPIO
|
||||
#define CONFIG_PD_USE_DAC_AS_REF
|
||||
/*
|
||||
* use #define CONFIG_USBC_SNIFFER_HEADER_V1
|
||||
* if you do not want twinkie to send out vbus info;
|
||||
* use #define CONFIG_USBC_SNIFFER_HEADER_V2
|
||||
* if you want twinkie to send out vbus info.
|
||||
*/
|
||||
#define CONFIG_USBC_SNIFFER_HEADER_V1
|
||||
#define CONFIG_HW_CRC
|
||||
|
||||
#ifndef HAS_TASK_PD_C0 /* PD sniffer mode */
|
||||
|
||||
@@ -21,22 +21,10 @@
|
||||
#include "util.h"
|
||||
#include "ina2xx.h"
|
||||
|
||||
#ifdef CONFIG_USBC_SNIFFER_HEADER_V2
|
||||
struct sniffer_sample_header {
|
||||
uint16_t seq;
|
||||
uint16_t tstamp;
|
||||
uint16_t vbus_value; /* can be voltage or current */
|
||||
int16_t sample_tstamp;
|
||||
};
|
||||
#endif
|
||||
/* Size of one USB packet buffer */
|
||||
#define EP_BUF_SIZE 64
|
||||
|
||||
#ifdef CONFIG_USBC_SNIFFER_HEADER_V2
|
||||
#define EP_PACKET_HEADER_SIZE (sizeof(struct sniffer_sample_header))
|
||||
#else
|
||||
#define EP_PACKET_HEADER_SIZE 4
|
||||
#endif
|
||||
/* Size of the payload (packet minus the header) */
|
||||
#define EP_PAYLOAD_SIZE (EP_BUF_SIZE - EP_PACKET_HEADER_SIZE)
|
||||
|
||||
@@ -58,108 +46,11 @@ static uint16_t sample_tstamp[4];
|
||||
/* sequence number of the beginning of DMA buffers */
|
||||
static uint16_t sample_seq[4];
|
||||
|
||||
#ifdef CONFIG_USBC_SNIFFER_HEADER_V2
|
||||
/* after how long the deferred reads will wake up for the next read */
|
||||
#define DEFERRED_READ_TIME_US 8000
|
||||
#define VBUS_ARRAY_SIZE 8
|
||||
/* vbus voltage information: the voltage value and the timestamp offset */
|
||||
struct vbus_vol_info {
|
||||
uint16_t vol;
|
||||
uint16_t tstamp; /* the average time of before read and after read*/
|
||||
};
|
||||
|
||||
/* vbus current information: the voltage value and the timestamp offset */
|
||||
struct vbus_curr_info {
|
||||
int16_t curr;
|
||||
uint16_t tstamp; /* the average time of before read and after read*/
|
||||
};
|
||||
|
||||
/* an array-implemented circular queue to hold multiple vbus values */
|
||||
static struct vbus_vol_info vbus_vol_array[VBUS_ARRAY_SIZE];
|
||||
static uint32_t vbus_vol_head;
|
||||
static uint32_t vbus_vol_tail;
|
||||
|
||||
static struct vbus_curr_info vbus_curr_array[VBUS_ARRAY_SIZE];
|
||||
static uint32_t vbus_curr_head;
|
||||
static uint32_t vbus_curr_tail;
|
||||
|
||||
/* whether the sniffer task have started sending packet */
|
||||
static int flag_started;
|
||||
#endif
|
||||
|
||||
/* Bulk endpoint double buffer */
|
||||
static usb_uint ep_buf[2][EP_BUF_SIZE / 2] __usb_ram;
|
||||
/* USB Buffers not used, ready to be filled */
|
||||
static volatile uint32_t free_usb = 3;
|
||||
|
||||
#ifdef CONFIG_USBC_SNIFFER_HEADER_V2
|
||||
static void vbus_vol_read_deferred(void);
|
||||
DECLARE_DEFERRED(vbus_vol_read_deferred);
|
||||
|
||||
static void vbus_curr_read_deferred(void);
|
||||
DECLARE_DEFERRED(vbus_curr_read_deferred);
|
||||
|
||||
static void vbus_vol_read_deferred(void)
|
||||
{
|
||||
/* read may be interrupted, use average of start & end as the tstamp */
|
||||
/* Unit: ms */
|
||||
uint16_t tstamp_bf;
|
||||
uint16_t tstamp_af;
|
||||
/* Unit: mV */
|
||||
uint16_t vol;
|
||||
uint16_t temp_tail;
|
||||
|
||||
if (flag_started == 0 || (flag_started == 1 &&
|
||||
((vbus_vol_tail - vbus_vol_head) < VBUS_ARRAY_SIZE))) {
|
||||
/* if sniffer isn't started, always write to the first position */
|
||||
temp_tail = (flag_started == 0) ?
|
||||
0 : (vbus_vol_tail & (VBUS_ARRAY_SIZE - 1));
|
||||
tstamp_bf = __hw_clock_source_read();
|
||||
vol = ((ina2xx_read(0, INA2XX_REG_BUS_VOLT)*5) >> 2); /* *125/100 */
|
||||
tstamp_af = __hw_clock_source_read();
|
||||
if (tstamp_bf > tstamp_af)
|
||||
vbus_vol_array[temp_tail].tstamp =
|
||||
((tstamp_bf + tstamp_af + 0xFFFF)>>1) & 0xFFFF;
|
||||
else
|
||||
vbus_vol_array[temp_tail].tstamp = (tstamp_bf + tstamp_af)>>1;
|
||||
vbus_vol_array[temp_tail].vol = vol;
|
||||
vbus_vol_tail = (flag_started == 0) ? 1 : vbus_vol_tail + 1;
|
||||
}
|
||||
|
||||
hook_call_deferred(&vbus_vol_read_deferred_data, DEFERRED_READ_TIME_US);
|
||||
}
|
||||
|
||||
static void vbus_curr_read_deferred(void)
|
||||
{
|
||||
/* Unit: ms */
|
||||
uint16_t tstamp_bf;
|
||||
uint16_t tstamp_af;
|
||||
/* Unit: mA */
|
||||
uint16_t curr;
|
||||
uint16_t temp_tail;
|
||||
|
||||
if (flag_started == 0 || (flag_started == 1 &&
|
||||
((vbus_curr_tail - vbus_curr_head) < VBUS_ARRAY_SIZE))) {
|
||||
/* if sniffer isn't started, always write to the first position */
|
||||
temp_tail = (flag_started == 0) ?
|
||||
0 : vbus_curr_tail & (VBUS_ARRAY_SIZE - 1);
|
||||
tstamp_bf = __hw_clock_source_read();
|
||||
curr = ina2xx_read(0, INA2XX_REG_CURRENT);
|
||||
tstamp_af = __hw_clock_source_read();
|
||||
if (tstamp_bf > tstamp_af)
|
||||
vbus_curr_array[temp_tail].tstamp =
|
||||
((tstamp_bf + tstamp_af + 0xFFFF)>>1) & 0xFFFF;
|
||||
else
|
||||
vbus_curr_array[temp_tail].tstamp = (tstamp_bf + tstamp_af)>>1;
|
||||
vbus_curr_array[temp_tail].curr = curr;
|
||||
vbus_curr_tail = (flag_started == 0) ? 1 : vbus_curr_tail + 1;
|
||||
}
|
||||
|
||||
hook_call_deferred(&vbus_curr_read_deferred_data,
|
||||
DEFERRED_READ_TIME_US);
|
||||
}
|
||||
#endif
|
||||
|
||||
static inline void led_set_activity(int ch)
|
||||
{
|
||||
static int accumul[2];
|
||||
@@ -364,19 +255,6 @@ static void rx_timer_init(int tim_id, timer_ctlr_t *tim, int ch_idx, int up_idx)
|
||||
|
||||
void sniffer_init(void)
|
||||
{
|
||||
#ifdef CONFIG_USBC_SNIFFER_HEADER_V2
|
||||
vbus_vol_head = 0;
|
||||
vbus_vol_tail = 0;
|
||||
vbus_curr_head = 0;
|
||||
vbus_curr_tail = 0;
|
||||
|
||||
/* whether the sniffer task have started sending packet */
|
||||
flag_started = 0;
|
||||
|
||||
hook_call_deferred(&vbus_vol_read_deferred_data, 0);
|
||||
hook_call_deferred(&vbus_curr_read_deferred_data, 0);
|
||||
#endif
|
||||
|
||||
/* remap TIM1 CH1/2/3 to DMA channel 6 */
|
||||
STM32_SYSCFG_CFGR1 |= 1 << 28;
|
||||
|
||||
@@ -418,16 +296,6 @@ void sniffer_task(void)
|
||||
int d = 0; /* current DMA buffer index */
|
||||
int off = 0; /* DMA buffer offset */
|
||||
|
||||
#ifdef CONFIG_USBC_SNIFFER_HEADER_V2
|
||||
int ch; /* sniffer channel */
|
||||
uint16_t vol = 0; /* voltage */
|
||||
uint16_t vol_tstamp; /* timestamp in us */
|
||||
uint16_t curr = 0; /* current */
|
||||
uint16_t curr_tstamp;
|
||||
uint16_t temp_vol_head;
|
||||
uint16_t temp_curr_head;
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
/* Wait for a new buffer of samples or a new USB free buffer */
|
||||
task_wait_event(-1);
|
||||
@@ -443,32 +311,6 @@ void sniffer_task(void)
|
||||
ep_buf[u][0] = sample_seq[d >> 3] | (d & 7);
|
||||
ep_buf[u][1] = sample_tstamp[d >> 3];
|
||||
|
||||
#ifdef CONFIG_USBC_SNIFFER_HEADER_V2
|
||||
flag_started = 1;
|
||||
ch = get_channel(ep_buf[u][0]);
|
||||
if (SNIFFER_CHANNEL_CC1 == ch) {
|
||||
if (vbus_vol_tail - vbus_vol_head > 0) {
|
||||
/* get a value from the queue */
|
||||
temp_vol_head = vbus_vol_head & (VBUS_ARRAY_SIZE - 1);
|
||||
vol = vbus_vol_array[temp_vol_head].vol;
|
||||
vol_tstamp = vbus_vol_array[temp_vol_head].tstamp;
|
||||
++vbus_vol_head;
|
||||
}
|
||||
ep_buf[u][2] = vol; /* use previous values if queue empty*/
|
||||
ep_buf[u][3] = vol_tstamp - ep_buf[u][1];
|
||||
|
||||
} else if (SNIFFER_CHANNEL_CC2 == ch) {
|
||||
if (vbus_curr_tail - vbus_curr_head > 0) {
|
||||
temp_curr_head = vbus_curr_head & (VBUS_ARRAY_SIZE - 1);
|
||||
curr = vbus_curr_array[temp_curr_head].curr;
|
||||
curr_tstamp = vbus_curr_array[temp_curr_head].tstamp;
|
||||
++vbus_curr_head;
|
||||
}
|
||||
ep_buf[u][2] = curr;
|
||||
ep_buf[u][3] = curr_tstamp - ep_buf[u][1];
|
||||
}
|
||||
#endif
|
||||
|
||||
memcpy_to_usbram(
|
||||
((void *)usb_sram_addr(ep_buf[u]
|
||||
+ (EP_PACKET_HEADER_SIZE>>1))),
|
||||
|
||||
@@ -2666,14 +2666,6 @@
|
||||
*/
|
||||
#undef CONFIG_USBC_SS_MUX_DFP_ONLY
|
||||
|
||||
/* Sniffer header version
|
||||
* Version 1: [timestamp:2B, sequence number:2B]
|
||||
* Version 2: [timestamp:2B, sequence number:2B,
|
||||
* Vbus value: 2B, vbus timestamp offset: 2B]
|
||||
*/
|
||||
#undef CONFIG_USBC_SNIFFER_HEADER_V1
|
||||
#undef CONFIG_USBC_SNIFFER_HEADER_V2
|
||||
|
||||
/* Support v1.1 type-C connection state machine */
|
||||
#undef CONFIG_USBC_BACKWARDS_COMPATIBLE_DFP
|
||||
|
||||
|
||||
Reference in New Issue
Block a user