Skip to content

Commit e1e17a1

Browse files
committed
sync: from 61124bba
1. driver: 1). Fix hw_timer issue, espressif#96; 2). Fix SPI output data error; 3). Fix SPI read data bug; 4). Fix driver lib compile issue; 5). Fix uart flow control issue; 2. lwip: 1). Enable lwip ETHARP_TRUS_IP_MAC; 2). Modify dhcp/dhcps timer from 60 seconds to 1 second; 3. WiFi: 1). Support CSA;
1 parent fdd3346 commit e1e17a1

File tree

18 files changed

+102
-31
lines changed

18 files changed

+102
-31
lines changed

VERSION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
lwip: 6ee4a9b3
2+
driver: 7bee5263

driver_lib/driver/hw_timer.c

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,36 @@ typedef enum { // timer interrupt mode
4949

5050
static void (* user_hw_timer_cb)(void) = NULL;
5151

52+
bool frc1_auto_load = false;
53+
5254
static void hw_timer_isr_cb(void *arg)
5355
{
56+
if(frc1_auto_load == false ) {
57+
RTC_REG_WRITE(FRC1_CTRL_ADDRESS,
58+
DIVDED_BY_16 | TM_EDGE_INT);
59+
}
60+
5461
if (user_hw_timer_cb != NULL) {
5562
(*(user_hw_timer_cb))();
5663
}
5764
}
5865

59-
void hw_timer_arm(uint32 val)
66+
void hw_timer_disarm(void)
6067
{
68+
RTC_REG_WRITE(FRC1_CTRL_ADDRESS,0);
69+
}
70+
71+
void hw_timer_arm(uint32 val ,bool req)
72+
{
73+
frc1_auto_load = req;
74+
if (frc1_auto_load == true) {
75+
RTC_REG_WRITE(FRC1_CTRL_ADDRESS,
76+
FRC1_AUTO_LOAD | DIVDED_BY_16 | FRC1_ENABLE_TIMER | TM_EDGE_INT);
77+
} else {
78+
RTC_REG_WRITE(FRC1_CTRL_ADDRESS,
79+
DIVDED_BY_16 | FRC1_ENABLE_TIMER | TM_EDGE_INT);
80+
}
81+
6182
RTC_REG_WRITE(FRC1_LOAD_ADDRESS, US_TO_RTC_TIMER_TICKS(val));
6283
}
6384

@@ -66,8 +87,9 @@ void hw_timer_set_func(void (* user_hw_timer_cb_set)(void))
6687
user_hw_timer_cb = user_hw_timer_cb_set;
6788
}
6889

69-
void hw_timer_init(uint8 req)
90+
void hw_timer_init(void)
7091
{
92+
#if 0
7193
if (req == 1) {
7294
RTC_REG_WRITE(FRC1_CTRL_ADDRESS,
7395
FRC1_AUTO_LOAD | DIVDED_BY_16 | FRC1_ENABLE_TIMER | TM_EDGE_INT);
@@ -76,6 +98,7 @@ void hw_timer_init(uint8 req)
7698
DIVDED_BY_16 | FRC1_ENABLE_TIMER | TM_EDGE_INT);
7799
}
78100

101+
#endif
79102
_xt_isr_attach(ETS_FRC_TIMER1_INUM, hw_timer_isr_cb, NULL);
80103

81104
TM1_EDGE_INT_ENABLE();
@@ -108,8 +131,8 @@ void hw_test_timer_cb(void)
108131

109132
void user_init(void)
110133
{
111-
hw_timer_init(1);
112-
hw_timer_set_func(hw_test_timer_cb);
134+
hw_timer_init();
135+
hw_timer_set_func(hw_test_timer_cb,1);
113136
hw_timer_arm(100);
114137
}
115138
#endif

driver_lib/driver/spi_interface.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "spi_interface.h"
2323
#include "esp8266/eagle_soc.h"
2424
#include "esp8266/ets_sys.h"
25+
#include "esp8266/pin_mux_register.h"
2526
#include "esp_libc.h"
2627
//*****************************************************************************
2728
//
@@ -123,6 +124,10 @@ void ICACHE_FLASH_ATTR SPIInit(SpiNum spiNum, SpiAttr* pAttr)
123124
// SPI Speed
124125
if (1 < (pAttr->speed)) {
125126
CLEAR_PERI_REG_MASK(SPI_CLOCK(spiNum), SPI_CLK_EQU_SYSCLK);
127+
if (spiNum == SpiNum_HSPI) {
128+
CLEAR_PERI_REG_MASK(PERIPHS_IO_MUX_CONF_U, SPI1_CLK_EQU_SYS_CLK);
129+
}
130+
126131
WRITE_PERI_REG(SPI_CLOCK(spiNum),
127132
((pAttr->speed & SPI_CLKCNT_N) << SPI_CLKCNT_N_S) |
128133
((((pAttr->speed + 1) / 2 - 1) & SPI_CLKCNT_H) << SPI_CLKCNT_H_S) |
@@ -169,6 +174,8 @@ void ICACHE_FLASH_ATTR SPIInit(SpiNum spiNum, SpiAttr* pAttr)
169174

170175
//clear Daul or Quad lines transmission mode
171176
CLEAR_PERI_REG_MASK(SPI_CTRL(spiNum), SPI_QIO_MODE | SPI_DIO_MODE | SPI_DOUT_MODE | SPI_QOUT_MODE);
177+
SET_PERI_REG_MASK(SPI_CTRL(spiNum), SPI_FASTRD_MODE);
178+
172179
}
173180

174181
/**
@@ -258,6 +265,7 @@ int ICACHE_FLASH_ATTR SPIMasterSendData(SpiNum spiNum, SpiData* pInData)
258265
SET_PERI_REG_BITS(SPI_USER1(spiNum), SPI_USR_MOSI_BITLEN, ((pInData->dataLen << 3) - 1), SPI_USR_MOSI_BITLEN_S);
259266
} else {
260267
CLEAR_PERI_REG_MASK(SPI_USER(spiNum), SPI_USR_MOSI);
268+
CLEAR_PERI_REG_MASK(SPI_USER(spiNum), SPI_USR_MISO);
261269
SET_PERI_REG_BITS(SPI_USER1(spiNum), SPI_USR_MOSI_BITLEN,
262270
0, SPI_USR_MOSI_BITLEN_S);
263271
}
@@ -329,9 +337,15 @@ int ICACHE_FLASH_ATTR SPIMasterRecvData(SpiNum spiNum, SpiData* pOutData)
329337
SET_PERI_REG_BITS(SPI_USER1(spiNum), SPI_USR_MISO_BITLEN,
330338
0, SPI_USR_MISO_BITLEN_S);
331339
}
340+
341+
//CLEAR FIFO DATA
342+
int fifo_idx = 0;
343+
do {
344+
WRITE_PERI_REG(SPI_W0(spiNum) + (fifo_idx << 2), 0);
345+
} while (++fifo_idx < (pOutData->dataLen / 4));
346+
332347
// Start send data
333348
SET_PERI_REG_MASK(SPI_CMD(spiNum), SPI_USR);
334-
335349
while (READ_PERI_REG(SPI_CMD(spiNum))&SPI_USR);
336350
// Read data out
337351
do {

driver_lib/driver/uart.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ UART_IntrConfig(UART_Port uart_no, UART_IntrConfTypeDef *pUARTIntrConf)
329329

330330
uint32 reg_val = 0;
331331
UART_ClearIntrStatus(uart_no, UART_INTR_MASK);
332-
reg_val = READ_PERI_REG(UART_CONF1(uart_no)) & ~((UART_RX_FLOW_THRHD << UART_RX_FLOW_THRHD_S) | UART_RX_FLOW_EN) ;
332+
reg_val = READ_PERI_REG(UART_CONF1(uart_no)) & ((UART_RX_FLOW_THRHD << UART_RX_FLOW_THRHD_S) | UART_RX_FLOW_EN) ;
333333

334334
reg_val |= ((pUARTIntrConf->UART_IntrEnMask & UART_RXFIFO_TOUT_INT_ENA) ?
335335
((((pUARTIntrConf->UART_RX_TimeOutIntrThresh)&UART_RX_TOUT_THRHD) << UART_RX_TOUT_THRHD_S) | UART_RX_TOUT_EN) : 0);

driver_lib/include/gpio.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#ifdef __cplusplus
2929
extern "C" {
3030
#endif
31-
31+
#include "esp8266/gpio_register.h"
3232
#define GPIO_Pin_0 (BIT(0)) /* Pin 0 selected */
3333
#define GPIO_Pin_1 (BIT(1)) /* Pin 1 selected */
3434
#define GPIO_Pin_2 (BIT(2)) /* Pin 2 selected */
@@ -190,7 +190,7 @@ typedef struct {
190190
*
191191
* @return the level of GPIO input
192192
*/
193-
#define GPIO_INPUT_GET(gpio_no) ((gpio_input_get()>>gpio_no)&BIT0)
193+
#define GPIO_INPUT_GET(gpio_no) ((gpio_input_get()>>gpio_no)&BIT(0))
194194

195195
/**
196196
* @brief Enable GPIO16 output.

driver_lib/include/hw_timer.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ extern "C" {
4444
/**
4545
* @brief Initialize the hardware ISR timer.
4646
*
47-
* @param uint8 req : 0, not autoload; 1, autoload mode.
47+
* @param null
4848
*
4949
* @return null
5050
*/
51-
void hw_timer_init(uint8 req);
51+
void hw_timer_init(void);
5252

5353
/**
5454
* @brief Set a trigger timer delay to enable this timer.
@@ -57,9 +57,20 @@ void hw_timer_init(uint8 req);
5757
* - In autoload mode, range : 50 ~ 0x7fffff
5858
* - In non-autoload mode, range : 10 ~ 0x7fffff
5959
*
60+
* @param uint8 req : 0, not autoload; 1, autoload mode.
61+
*
62+
* @return null
63+
*/
64+
void hw_timer_arm(uint32 val, bool req);
65+
66+
/**
67+
* @brief disable this timer.
68+
*
69+
* @param null
70+
*
6071
* @return null
6172
*/
62-
void hw_timer_arm(uint32 val);
73+
void hw_timer_disarm(void);
6374

6475
/**
6576
* @brief Set timer callback function.

driver_lib/make_lib.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
1-
#!/bin/bash -x
1+
#!/bin/bash
2+
set -e
23

3-
echo "make_lib.sh version 20160307"
4+
export SDK_PATH=$(dirname $(pwd))
5+
6+
echo "make_lib.sh version 20150924"
47
echo ""
58

9+
if [ $SDK_PATH ]; then
10+
echo "SDK_PATH:"
11+
echo "$SDK_PATH"
12+
echo ""
13+
else
14+
echo "ERROR: Please export SDK_PATH in make_lib.sh firstly, exit!!!"
15+
exit
16+
fi
17+
618
cd $1
719
make clean
8-
make COMPILE=gcc
9-
cp .output/eagle/debug/lib/lib$1.a ../../lib/lib$1.a
10-
xtensa-lx106-elf-strip --strip-unneeded ../../lib/lib$1.a
20+
make
21+
cp .output/eagle/debug/lib/lib$1.a $SDK_PATH/lib/lib$1.a
22+
xtensa-lx106-elf-strip --strip-unneeded $SDK_PATH/lib/lib$1.a
1123
cd ..

include/espressif/esp8266/pin_mux_register.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#ifndef _PIN_MUX_H_
2626
#define _PIN_MUX_H_
27-
27+
#include "eagle_soc.h"
2828
#define PERIPHS_IO_MUX 0x60000800
2929

3030
#define PERIPHS_IO_MUX_FUNC 0x13

include/lwip/lwip/dhcp.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ extern "C" {
1616
#endif
1717

1818
/** period (in seconds) of the application calling dhcp_coarse_tmr() */
19-
#define DHCP_COARSE_TIMER_SECS 60
19+
#define DHCP_COARSE_TIMER_SECS 1
2020
/** period (in milliseconds) of the application calling dhcp_coarse_tmr() */
2121
#define DHCP_COARSE_TIMER_MSECS (DHCP_COARSE_TIMER_SECS * 1000UL)
2222
/** period (in milliseconds) of the application calling dhcp_fine_tmr() */
@@ -46,9 +46,9 @@ struct dhcp
4646
struct pbuf *p_out; /* pbuf of outcoming msg */
4747
struct dhcp_msg *msg_out; /* outgoing msg */
4848
u16_t options_out_len; /* outgoing msg options length */
49-
u16_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
50-
u16_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
51-
u16_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
49+
u32_t request_timeout; /* #ticks with period DHCP_FINE_TIMER_SECS for request timeout */
50+
u32_t t1_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for renewal time */
51+
u32_t t2_timeout; /* #ticks with period DHCP_COARSE_TIMER_SECS for rebind time */
5252
ip_addr_t server_ip_addr; /* dhcp server address that offered this lease */
5353
ip_addr_t offered_ip_addr;
5454
ip_addr_t offered_sn_mask;

include/lwip/lwip/dhcpserver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ typedef struct _list_node{
4848
}list_node;
4949

5050
extern u32_t dhcps_lease_time;
51+
#define DHCPS_COARSE_TIMER_SECS 1
5152
#define DHCPS_LEASE_TIMER dhcps_lease_time //0x05A0
5253
#define DHCPS_MAX_LEASE 0x64
5354
#define BOOTP_BROADCAST 0x8000

include/lwip/lwipopts.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,19 @@
163163
*/
164164
#define IP_REASS_MAX_PBUFS 10
165165

166+
/**
167+
* ETHARP_TRUST_IP_MAC==1: Incoming IP packets cause the ARP table to be
168+
* updated with the source MAC and IP addresses supplied in the packet.
169+
* You may want to disable this if you do not trust LAN peers to have the
170+
* correct addresses, or as a limited approach to attempt to handle
171+
* spoofing. If disabled, lwIP will need to make a new ARP request if
172+
* the peer is not already in the ARP table, adding a little latency.
173+
* The peer *is* in the ARP table if it requested our address before.
174+
* Also notice that this slows down input processing of every IP packet!
175+
*/
176+
#define ETHARP_TRUST_IP_MAC 1
177+
178+
166179
/*
167180
----------------------------------
168181
---------- ICMP options ----------

lib/libdriver.a

18.2 KB
Binary file not shown.

lib/liblwip.a

308 Bytes
Binary file not shown.

lib/libmain.a

40 Bytes
Binary file not shown.

lib/libnet80211.a

4.02 KB
Binary file not shown.

lib/libpp.a

0 Bytes
Binary file not shown.

third_party/lwip/core/dhcp.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,25 +1058,19 @@ dhcp_bind(struct netif *netif)
10581058
/* set renewal period timer */
10591059
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(): t1 renewal timer %"U32_F" secs\n", dhcp->offered_t1_renew));
10601060
timeout = (dhcp->offered_t1_renew + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS;
1061-
if(timeout > 0xffff) {
1062-
timeout = 0xffff;
1063-
}
10641061
dhcp->t1_timeout = (u16_t)timeout;
10651062
if (dhcp->t1_timeout == 0) {
1066-
dhcp->t1_timeout = 1;
1063+
dhcp->t1_timeout = 60;
10671064
}
10681065
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_bind(): set request timeout %"U32_F" msecs\n", dhcp->offered_t1_renew*1000));
10691066
}
10701067
/* set renewal period timer */
10711068
if (dhcp->offered_t2_rebind != 0xffffffffUL) {
10721069
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_bind(): t2 rebind timer %"U32_F" secs\n", dhcp->offered_t2_rebind));
10731070
timeout = (dhcp->offered_t2_rebind + DHCP_COARSE_TIMER_SECS / 2) / DHCP_COARSE_TIMER_SECS;
1074-
if(timeout > 0xffff) {
1075-
timeout = 0xffff;
1076-
}
10771071
dhcp->t2_timeout = (u16_t)timeout;
10781072
if (dhcp->t2_timeout == 0) {
1079-
dhcp->t2_timeout = 1;
1073+
dhcp->t2_timeout = (dhcp->t1_timeout>>2)*7;
10801074
}
10811075
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE | LWIP_DBG_STATE, ("dhcp_bind(): set request timeout %"U32_F" msecs\n", dhcp->offered_t2_rebind*1000));
10821076
}

third_party/lwip/core/dhcpserver.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@ static u8_t parse_options(u8_t *optptr, s16_t len)
576576
///////////////////////////////////////////////////////////////////////////////////
577577
static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
578578
{
579+
u32_t lease_timer = (dhcps_lease_time * 60)/DHCPS_COARSE_TIMER_SECS;
579580
if(memcmp((char *)m->options,
580581
&magic_cookie,
581582
sizeof(magic_cookie)) == 0){
@@ -632,7 +633,7 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
632633
renew = true;
633634
}
634635
client_address.addr = pdhcps_pool->ip.addr;
635-
pdhcps_pool->lease_timer = DHCPS_LEASE_TIMER;
636+
pdhcps_pool->lease_timer = lease_timer;
636637
pnode = pback_node;
637638
goto POOL_CHECK;
638639
} else if (pdhcps_pool->ip.addr == client_address_plus.addr){
@@ -669,7 +670,7 @@ static s16_t parse_msg(struct dhcps_msg *m, u16_t len)
669670
pdhcps_pool = (struct dhcps_pool *)os_zalloc(sizeof(struct dhcps_pool));
670671
pdhcps_pool->ip.addr = client_address.addr;
671672
memcpy(pdhcps_pool->mac, m->chaddr, sizeof(pdhcps_pool->mac));
672-
pdhcps_pool->lease_timer = DHCPS_LEASE_TIMER;
673+
pdhcps_pool->lease_timer = lease_timer;
673674
pnode = (list_node *)os_zalloc(sizeof(list_node ));
674675
pnode->pnode = pdhcps_pool;
675676
pnode->pnext = NULL;

0 commit comments

Comments
 (0)