Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 8c99657

Browse files
committed
ksz8851: debug spurious interrupts (WIP)
1 parent 7d95ed6 commit 8c99657

File tree

5 files changed

+123
-17
lines changed

5 files changed

+123
-17
lines changed

drivers/ksz8851/ksz8851.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,16 @@ static IRAM_ATTR void ksz8851ProcessInterrupt(void) {
173173
evt |= KSZ8851_RX_INT;
174174
}
175175

176+
if ( ! evt ) {
177+
evt |= KSZ8851_OTHER_INT;
178+
}
179+
176180
ksz8851_regwr(REG_INT_STATUS, 0xFFFF);
177181

178182
/* Notify upper layer*/
179183
if((evt_cb_func != NULL) && evt)
180184
{
181-
evt_cb_func(evt);
185+
evt_cb_func(evt, isr);
182186
}
183187
else
184188
{

drivers/ksz8851/ksz8851.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef __KSZ8851_H__
22
#define __KSZ8851_H__
33

4-
typedef void (*ksz8851_evt_cb_t)(uint32_t);
4+
typedef void (*ksz8851_evt_cb_t)(uint32_t, uint16_t);
55

66
uint16_t IRAM_ATTR ksz8851_regrd(uint16_t reg);
77
void IRAM_ATTR ksz8851_regwr(uint16_t reg, uint16_t wrdata);
@@ -49,6 +49,7 @@ extern uint8_t ethernet_mac[ETH_MAC_SIZE];
4949
#define KSZ8851_RX_INT (0x0001)
5050
#define KSZ8851_LINK_CHG_INT (0x0002)
5151
#define KSZ8851_OVERRUN_INT (0x0004)
52+
#define KSZ8851_OTHER_INT (0x0008)
5253

5354
/* Register definitions */
5455
/*
@@ -273,6 +274,8 @@ extern uint8_t ethernet_mac[ETH_MAC_SIZE];
273274
#define INT_RX_SPI_ERROR 0x0002 /* Enable receive SPI bus error interrupt */
274275
#define RX_WOL_DELAY_ENERGY 0x0001 /* Enable delay generate WOL on energy detect */
275276
#define INT_MASK ( INT_RX | INT_PHY | INT_RX_OVERRUN )
277+
//#define INT_MASK (INT_PHY | INT_TX | INT_RX | INT_RX_OVERRUN | INT_TX_STOPPED | INT_RX_STOPPED | INT_TX_SPACE | INT_RX_WOL_FRAME | INT_RX_WOL_MAGIC | INT_RX_WOL_LINKUP | INT_RX_WOL_ENERGY | INT_RX_SPI_ERROR )
278+
//#define INT_MASK (INT_PHY | INT_TX | INT_RX | INT_RX_OVERRUN | INT_TX_STOPPED | INT_RX_STOPPED | INT_TX_SPACE | INT_RX_SPI_ERROR )
276279

277280
#define REG_INT_STATUS 0x92 /* ISR */
278281

esp32/mods/modeth.c

Lines changed: 106 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
* DEFINE CONSTANTS
5151
*****************************************************************************/
5252
#define ETHERNET_TASK_STACK_SIZE 3072
53-
#define ETHERNET_TASK_PRIORITY 12
53+
#define ETHERNET_TASK_PRIORITY 24 // 12
5454
#define ETHERNET_CHECK_LINK_PERIOD_MS 2000
5555
#define ETHERNET_CMD_QUEUE_SIZE 100
5656

@@ -66,9 +66,9 @@
6666
*****************************************************************************/
6767
static void TASK_ETHERNET (void *pvParameters);
6868
static mp_obj_t eth_init_helper(eth_obj_t *self, const mp_arg_val_t *args);
69-
static IRAM_ATTR void ksz8851_evt_callback(uint32_t ksz8851_evt);
69+
static IRAM_ATTR void ksz8851_evt_callback(uint32_t ksz8851_evt, uint16_t isr);
7070
static void process_tx(uint8_t* buff, uint16_t len);
71-
static void process_rx(void);
71+
static uint32_t process_rx(void);
7272
static void eth_validate_hostname (const char *hostname);
7373
static esp_err_t modeth_event_handler(void *ctx, system_event_t *event);
7474

@@ -195,9 +195,10 @@ static void process_tx(uint8_t* buff, uint16_t len)
195195
ksz8851EndPacketSend();
196196
}
197197
}
198-
static void process_rx(void)
198+
static uint32_t process_rx(void)
199199
{
200200
uint32_t len, frameCnt;
201+
uint32_t totalLen = 0;
201202

202203
frameCnt = (ksz8851_regrd(REG_RX_FRAME_CNT_THRES) & RX_FRAME_CNT_MASK) >> 8;
203204
MSG("TE process_rx f:%u\n", frameCnt);
@@ -206,16 +207,20 @@ static void process_rx(void)
206207
ksz8851RetrievePacketData(modeth_rxBuff, &len);
207208
if(len)
208209
{
210+
totalLen += len;
209211
tcpip_adapter_eth_input(modeth_rxBuff, len, NULL);
210212
}
211213
frameCnt--;
212214
}
213215
MSG("TE process_rx len:%u\n", totalLen);
216+
return totalLen;
214217
}
215-
static IRAM_ATTR void ksz8851_evt_callback(uint32_t ksz8851_evt)
218+
static IRAM_ATTR void ksz8851_evt_callback(uint32_t ksz8851_evt, uint16_t isr)
216219
{
217220
modeth_cmd_ctx_t ctx;
221+
ctx.isr = isr;
218222
portBASE_TYPE tmp = pdFALSE;
223+
bool sent = false;
219224

220225
if(ksz8851_evt & KSZ8851_LINK_CHG_INT)
221226
{
@@ -227,20 +232,29 @@ static IRAM_ATTR void ksz8851_evt_callback(uint32_t ksz8851_evt)
227232
xTaskNotifyFromISR(ethernetTaskHandle, 0, eIncrement, NULL);
228233
}
229234
xQueueSendToFrontFromISR(eth_cmdQueue, &ctx, &tmp);
235+
sent = true;
230236
}
231237

232238
if(ksz8851_evt & KSZ8851_RX_INT)
233239
{
234240
ctx.cmd = ETH_CMD_RX;
235241
ctx.buf = NULL;
236242
xQueueSendFromISR(eth_cmdQueue, &ctx, &tmp);
243+
sent = true;
237244
}
238245

239246
if(ksz8851_evt & KSZ8851_OVERRUN_INT)
240247
{
241248
ctx.cmd = ETH_CMD_OVERRUN;
242249
ctx.buf = NULL;
243250
xQueueSendToFrontFromISR(eth_cmdQueue, &ctx, &tmp);
251+
sent = true;
252+
}
253+
254+
if ( ! sent ){
255+
ctx.cmd = ETH_CMD_OTHER;
256+
ctx.buf = NULL;
257+
xQueueSendFromISR(eth_cmdQueue, &ctx, &tmp);
244258
}
245259

246260
if( tmp == pdTRUE )
@@ -251,13 +265,22 @@ static IRAM_ATTR void ksz8851_evt_callback(uint32_t ksz8851_evt)
251265
}
252266
}
253267

268+
// void printTaskStatus(){
269+
// UBaseType_t numTasks = uxTaskGetNumberOfTasks();
270+
// char* taskStatusWriteBuffer = (char*) heap_caps_malloc(sizeof(char) * 40 * numTasks, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
271+
// vTaskGetRunTimeStats(taskStatusWriteBuffer);
272+
// MSG("TE vTaskGetRunTimeStats:\n%s\n", taskStatusWriteBuffer);
273+
// heap_caps_free(taskStatusWriteBuffer);
274+
// }
275+
254276
static void TASK_ETHERNET (void *pvParameters) {
255277
MSG("TE\n");
256278

257279
static uint32_t thread_notification;
258280
system_event_t evt;
259281
modeth_cmd_ctx_t queue_entry;
260282
uint8_t timeout = 0;
283+
uint8_t max_timeout = 50; // 5
261284

262285
// Block task till notification is recieved
263286
thread_notification = ulTaskNotifyTake(pdTRUE, portMAX_DELAY);
@@ -301,8 +324,69 @@ static void TASK_ETHERNET (void *pvParameters) {
301324
evt.event_id = SYSTEM_EVENT_ETH_START;
302325
esp_event_send(&evt);
303326

327+
// MSG("TE for ls=%u 10M=%u 100M=%u\n", get_eth_link_speed(), ETH_SPEED_MODE_10M, ETH_SPEED_MODE_100M);
328+
UBaseType_t stack_high = uxTaskGetStackHighWaterMark(NULL);
329+
MSG("TE stack_high=%u\n", stack_high);
330+
331+
uint16_t ct = 0;
332+
uint16_t ctTX = 0;
333+
uint16_t ctRX = 0;
334+
uint16_t totalTX = 0;
335+
uint16_t totalRX = 0;
336+
bool printStat = false;
337+
uint16_t interrupt_pin_value = pin_get_value(KSZ8851_INT_PIN);
338+
//uint16_t interrupt_value = ksz8851_regrd(REG_INT_STATUS);
339+
304340
for(;;)
305341
{
342+
UBaseType_t stack_high_new = uxTaskGetStackHighWaterMark(NULL);
343+
uint16_t interrupt_pin_value_new = pin_get_value(KSZ8851_INT_PIN);
344+
//uint16_t interrupt_value_new = ksz8851_regrd(REG_INT_STATUS);
345+
346+
if (stack_high_new > stack_high) {
347+
stack_high = stack_high_new;
348+
printStat = true;
349+
}
350+
if (interrupt_pin_value_new != interrupt_pin_value ) {
351+
interrupt_pin_value = interrupt_pin_value_new;
352+
printStat = true;
353+
}
354+
//if ( interrupt_value_new != interrupt_value ) {
355+
// interrupt_value = interrupt_value_new;
356+
// printStat = true;
357+
//}
358+
if (ct % 100 == 0){
359+
printStat = true;
360+
}
361+
if (printStat){
362+
MSG("TE ct=%u stack:%u queue:%u tx:%u/%u rx:%u/%u ksz8851:%u 0x%x\n",
363+
ct, stack_high, uxQueueMessagesWaiting( eth_cmdQueue ),
364+
ctTX, totalTX, ctRX, totalRX,
365+
ksz8851GetLinkStatus(), interrupt_pin_value );
366+
// if (ct % 1000 == 0)
367+
// printTaskStatus();
368+
369+
// spi_op
370+
// ksz8851GetLinkStatus
371+
// ksz8851PowerDownMode
372+
// pi_setbits(REG_PORT_LINK_MD, PORT_POWER_SAVE_MODE);
373+
// ksz8851BeginPacketSend
374+
375+
printStat = false;
376+
377+
// UBaseType_t numTasks = uxTaskGetNumberOfTasks();
378+
379+
// TaskStatus_t* taskStatus = (TaskStatus_t*) heap_caps_malloc(sizeof(TaskStatus_t) * numTasks, MALLOC_CAP_INTERNAL | MALLOC_CAP_8BIT);
380+
// UBaseType_t totalRuntime = 0;
381+
// UBaseType_t numTasksGotten = uxTaskGetSystemState(taskStatus, numTasks, &totalRuntime);
382+
// MSG("TE uxTaskGetSystemState: %u, %u, %u\n", numTasks, numTasksGotten, totalRuntime);
383+
// heap_caps_free(taskStatus);
384+
385+
}
386+
387+
388+
ct++;
389+
306390
if(!eth_obj.link_status && (xEventGroupGetBits(eth_event_group) & ETHERNET_EVT_STARTED))
307391
{
308392
// block till link is up again
@@ -326,15 +410,27 @@ static void TASK_ETHERNET (void *pvParameters) {
326410

327411
if (xQueueReceive(eth_cmdQueue, &queue_entry, 200 / portTICK_PERIOD_MS) == pdTRUE)
328412
{
413+
// UBaseType_t numWait = uxQueueMessagesWaiting( eth_cmdQueue );
414+
// if (numWait){
415+
// MSG("TE msg waiting:%u\n", numWait);
416+
// //printTaskStatus();
417+
// }
418+
MSG("TE ct=%u cmd:0x%x isr:0x%x queue:%u ksz8851:%u 0x%x\n",
419+
ct, queue_entry.cmd, (queue_entry.cmd == ETH_CMD_TX)?0:queue_entry.isr, uxQueueMessagesWaiting( eth_cmdQueue ),
420+
ksz8851GetLinkStatus(), interrupt_pin_value );
421+
329422
switch(queue_entry.cmd)
330423
{
331424
case ETH_CMD_TX:
332425
//MSG("TE TX %u\n", queue_entry.len);
426+
ctTX++;
427+
totalTX += queue_entry.len;
333428
process_tx(queue_entry.buf, queue_entry.len);
334429
break;
335430
case ETH_CMD_RX:
336-
process_rx();
337431
//MSG("TE RX {0x%x}\n", queue_entry.isr);
432+
ctRX++;
433+
totalRX += process_rx();
338434
// Clear Intr status bits
339435
ksz8851_regwr(REG_INT_STATUS, INT_MASK);
340436
break;
@@ -375,13 +471,14 @@ static void TASK_ETHERNET (void *pvParameters) {
375471
timeout = 0;
376472
// Checking if interrupt line is locked up in Low state
377473
//TODO: This workaround should be removed once the lockup is resolved
378-
while((!pin_get_value(KSZ8851_INT_PIN)) && timeout < 5)
474+
while((!pin_get_value(KSZ8851_INT_PIN)) && timeout < max_timeout)
379475
{
380476
MSG("TE TO %u\n", timeout);
381-
vTaskDelay(1 / portTICK_PERIOD_MS);
477+
478+
vTaskDelay(10 / portTICK_PERIOD_MS);
382479
timeout++;
383480
}
384-
if(timeout >= 5)
481+
if(timeout >= max_timeout)
385482
{
386483
MSG("TE Force Int\n");
387484
xQueueReset(eth_cmdQueue);

esp32/mods/modeth.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ typedef enum
3939
ETH_CMD_TX = 0,
4040
ETH_CMD_RX,
4141
ETH_CMD_OVERRUN,
42-
ETH_CMD_CHK_LINK
42+
ETH_CMD_CHK_LINK,
43+
ETH_CMD_OTHER
4344
}modeth_cmd_t;
4445

4546
typedef struct
4647
{
4748
modeth_cmd_t cmd;
4849
uint8_t* buf;
4950
uint16_t len;
51+
uint16_t isr;
5052
}modeth_cmd_ctx_t;
5153

5254
#endif

esp32/pygate/lora_pkt_fwd/jitqueue.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Maintainer: Michael Coracin
3434
/* --- PRIVATE CONSTANTS & TYPES -------------------------------------------- */
3535
#define TX_START_DELAY 1500 /* microseconds */
3636
/* TODO: get this value from HAL? */
37-
#define TX_MARGIN_DELAY 1000 /* Packet overlap margin in microseconds */
37+
#define TX_MARGIN_DELAY 1000000 /* Packet overlap margin in microseconds */
3838
/* TODO: How much margin should we take? */
3939
#define TX_JIT_DELAY 50000 /* Pre-delay to program packet for TX in microseconds */
4040
#define TX_MAX_ADVANCE_DELAY ((JIT_NUM_BEACON_IN_QUEUE + 1) * 128 * 1E6) /* Maximum advance delay accepted for a TX packet, compared to current time */
@@ -175,7 +175,7 @@ enum jit_error_e jit_enqueue(struct jit_queue_s *queue, struct timeval *time, st
175175
packet->tx_mode = TIMESTAMPED;
176176

177177
/* Search for the ASAP timestamp to be given to the packet */
178-
asap_count_us = time_us + 1E6; /* TODO: Take 1 second margin, to be refined */
178+
asap_count_us = time_us + 1E6; /*FIXME:this is a double literal*/ /* TODO: Take 1 second margin, to be refined */
179179
if (queue->num_pkt == 0) {
180180
/* If the jit queue is empty, we can insert this packet */
181181
MSG_DEBUG(DEBUG_JIT, "DEBUG: insert IMMEDIATE downlink, first in JiT queue (count_us=%u)\n", asap_count_us);
@@ -230,9 +230,9 @@ enum jit_error_e jit_enqueue(struct jit_queue_s *queue, struct timeval *time, st
230230
* t_packet < t_current + TX_START_DELAY + MARGIN
231231
*/
232232
if (packet->count_us <= time_us + TX_START_DELAY + TX_MARGIN_DELAY + TX_JIT_DELAY) {
233-
MSG_DEBUG(DEBUG_JIT_ERROR, "ERROR: Packet REJECTED, already too late to send it (current=%u, packet=%u, type=%d)\n", time_us, packet->count_us, pkt_type);
234-
pthread_mutex_unlock(&mx_jit_queue);
235-
return JIT_ERROR_TOO_LATE;
233+
MSG_DEBUG(DEBUG_JIT_ERROR, "IGNORED: not REJECTED, already too late to send it (current=%u, packet=%u, type=%d)\n", time_us, packet->count_us, pkt_type);
234+
// pthread_mutex_unlock(&mx_jit_queue);
235+
// return JIT_ERROR_TOO_LATE;
236236
}
237237

238238
/* Check criteria_2: Does packet timestamp seem plausible compared to current time

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy