Skip to content

Commit cdd40f1

Browse files
committed
drivers, wiznet5k: Make DNS service use HAL sys tick.
1 parent 9091e84 commit cdd40f1

File tree

2 files changed

+11
-23
lines changed

2 files changed

+11
-23
lines changed

drivers/wiznet5k/internet/dns/dns.c

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ uint8_t* pDNSMSG; // DNS message buffer
121121
uint8_t DNS_SOCKET; // SOCKET number for DNS
122122
uint16_t DNS_MSGID; // DNS message ID
123123

124-
uint32_t dns_1s_tick; // SecTick counter for DNS process timeout
124+
extern uint32_t HAL_GetTick(void);
125+
uint32_t hal_sys_tick;
125126

126127
/* converts uint16_t from network buffer to a host byte order integer. */
127128
uint16_t get16(uint8_t * s)
@@ -341,7 +342,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
341342
uint8_t * cp;
342343

343344
msg = pbuf;
344-
memset(pdhdr, 0, sizeof(pdhdr));
345+
memset(pdhdr, 0, sizeof(*pdhdr));
345346

346347
pdhdr->id = get16(&msg[0]);
347348
tmp = get16(&msg[2]);
@@ -453,7 +454,7 @@ int16_t dns_makequery(uint16_t op, char * name, uint8_t * buf, uint16_t len)
453454
if (len == 0) break;
454455

455456
/* Copy component up to (but not including) dot */
456-
strncpy((char *)cp, dname, len);
457+
memcpy(cp, dname, len);
457458
cp += len;
458459
if (cp1 == NULL)
459460
{
@@ -483,9 +484,10 @@ int8_t check_DNS_timeout(void)
483484
{
484485
static uint8_t retry_count;
485486

486-
if(dns_1s_tick >= DNS_WAIT_TIME)
487+
uint32_t tick = HAL_GetTick();
488+
if(tick - hal_sys_tick >= DNS_WAIT_TIME * 1000)
487489
{
488-
dns_1s_tick = 0;
490+
hal_sys_tick = tick;
489491
if(retry_count >= MAX_DNS_RETRY) {
490492
retry_count = 0;
491493
return -1; // timeout occurred
@@ -515,6 +517,8 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
515517
uint8_t ip[4];
516518
uint16_t len, port;
517519
int8_t ret_check_timeout;
520+
521+
hal_sys_tick = HAL_GetTick();
518522

519523
// Socket open
520524
socket(DNS_SOCKET, Sn_MR_UDP, 0, 0);
@@ -560,13 +564,3 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
560564
// 0 > : failed / 1 - success
561565
return ret;
562566
}
563-
564-
565-
/* DNS TIMER HANDLER */
566-
void DNS_time_handler(void)
567-
{
568-
dns_1s_tick++;
569-
}
570-
571-
572-

drivers/wiznet5k/internet/dns/dns.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@
6565
* @todo SHOULD BE defined it equal as or greater than your Domain name length + null character(1)
6666
* @note SHOULD BE careful to stack overflow because it is allocated 1.5 times as MAX_DOMAIN_NAME in stack.
6767
*/
68-
#define MAX_DOMAIN_NAME 16 // for example "www.google.com"
68+
#define MAX_DOMAIN_NAME 32 // for example "www.google.com"
6969

7070
#define MAX_DNS_RETRY 2 ///< Requery Count
71-
#define DNS_WAIT_TIME 3 ///< Wait response time. unit 1s.
71+
#define DNS_WAIT_TIME 4 ///< Wait response time. unit 1s.
7272

7373
#define IPPORT_DOMAIN 53 ///< DNS server port number
7474

@@ -93,10 +93,4 @@ void DNS_init(uint8_t s, uint8_t * buf);
9393
*/
9494
int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns);
9595

96-
/*
97-
* @brief DNS 1s Tick Timer handler
98-
* @note SHOULD BE register to your system 1s Tick timer handler
99-
*/
100-
void DNS_time_handler(void);
101-
10296
#endif /* _DNS_H_ */

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