diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-05-03 00:18:14 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2016-05-03 00:18:14 +0300 |
commit | 3d830415bc81d1a9ec9640c1a4d52a5281cfd84e (patch) | |
tree | 8caf82352bd7d13b36b152d5015ed8090d644a51 /esp8266 | |
parent | 7b7c99fec11685d598fbda71784dddc8ba4cf108 (diff) | |
download | micropython-3d830415bc81d1a9ec9640c1a4d52a5281cfd84e.tar.gz micropython-3d830415bc81d1a9ec9640c1a4d52a5281cfd84e.zip |
esp8266/esp_mphal: Add ets_esf_free_bufs(), etc. functions.
Returning free number of various WiFi driver packet buffers.
Diffstat (limited to 'esp8266')
-rw-r--r-- | esp8266/esp_mphal.c | 22 | ||||
-rw-r--r-- | esp8266/esp_mphal.h | 3 |
2 files changed, 25 insertions, 0 deletions
diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c index 53c03f62da..25f1a9322f 100644 --- a/esp8266/esp_mphal.c +++ b/esp8266/esp_mphal.c @@ -234,3 +234,25 @@ void mp_hal_pin_config_od(mp_hal_pin_obj_t pin_id) { GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << pin->phys_port)); ETS_GPIO_INTR_ENABLE(); } + +// Get pointer to esf_buf bookkeeping structure +void *ets_get_esf_buf_ctlblk(void) { + // Get literal ptr before start of esf_rx_buf_alloc func + extern void *esf_rx_buf_alloc(); + return ((void**)esf_rx_buf_alloc)[-1]; +} + +// Get number of esf_buf free buffers of given type, as encoded by index +// idx 0 corresponds to buf types 1, 2; 1 - 4; 2 - 5; 3 - 7; 4 - 8 +// Only following buf types appear to be used: +// 1 - tx buffer, 5 - management frame tx buffer; 8 - rx buffer +int ets_esf_free_bufs(int idx) { + uint32_t *p = ets_get_esf_buf_ctlblk(); + uint32_t *b = (uint32_t*)p[idx]; + int cnt = 0; + while (b) { + b = (uint32_t*)b[0x20 / 4]; + cnt++; + } + return cnt; +} diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h index 2de5fcc512..13b1c8fdf0 100644 --- a/esp8266/esp_mphal.h +++ b/esp8266/esp_mphal.h @@ -77,4 +77,7 @@ void mp_hal_pin_config_od(mp_hal_pin_obj_t pin); #define mp_hal_pin_read(p) pin_get(p) #define mp_hal_pin_write(p, v) pin_set((p), (v)) +void *ets_get_esf_buf_ctlblk(void); +int ets_esf_free_bufs(int idx); + #endif // _INCLUDED_MPHAL_H_ |