drivers, wiznet5k: Make DNS service use HAL sys tick.
This commit is contained in:
parent
9091e84454
commit
cdd40f149a
@ -121,7 +121,8 @@ uint8_t* pDNSMSG; // DNS message buffer
|
||||
uint8_t DNS_SOCKET; // SOCKET number for DNS
|
||||
uint16_t DNS_MSGID; // DNS message ID
|
||||
|
||||
uint32_t dns_1s_tick; // SecTick counter for DNS process timeout
|
||||
extern uint32_t HAL_GetTick(void);
|
||||
uint32_t hal_sys_tick;
|
||||
|
||||
/* converts uint16_t from network buffer to a host byte order integer. */
|
||||
uint16_t get16(uint8_t * s)
|
||||
@ -341,7 +342,7 @@ int8_t parseDNSMSG(struct dhdr * pdhdr, uint8_t * pbuf, uint8_t * ip_from_dns)
|
||||
uint8_t * cp;
|
||||
|
||||
msg = pbuf;
|
||||
memset(pdhdr, 0, sizeof(pdhdr));
|
||||
memset(pdhdr, 0, sizeof(*pdhdr));
|
||||
|
||||
pdhdr->id = get16(&msg[0]);
|
||||
tmp = get16(&msg[2]);
|
||||
@ -453,7 +454,7 @@ int16_t dns_makequery(uint16_t op, char * name, uint8_t * buf, uint16_t len)
|
||||
if (len == 0) break;
|
||||
|
||||
/* Copy component up to (but not including) dot */
|
||||
strncpy((char *)cp, dname, len);
|
||||
memcpy(cp, dname, len);
|
||||
cp += len;
|
||||
if (cp1 == NULL)
|
||||
{
|
||||
@ -483,9 +484,10 @@ int8_t check_DNS_timeout(void)
|
||||
{
|
||||
static uint8_t retry_count;
|
||||
|
||||
if(dns_1s_tick >= DNS_WAIT_TIME)
|
||||
uint32_t tick = HAL_GetTick();
|
||||
if(tick - hal_sys_tick >= DNS_WAIT_TIME * 1000)
|
||||
{
|
||||
dns_1s_tick = 0;
|
||||
hal_sys_tick = tick;
|
||||
if(retry_count >= MAX_DNS_RETRY) {
|
||||
retry_count = 0;
|
||||
return -1; // timeout occurred
|
||||
@ -515,6 +517,8 @@ int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns)
|
||||
uint8_t ip[4];
|
||||
uint16_t len, port;
|
||||
int8_t ret_check_timeout;
|
||||
|
||||
hal_sys_tick = HAL_GetTick();
|
||||
|
||||
// Socket open
|
||||
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)
|
||||
// 0 > : failed / 1 - success
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* DNS TIMER HANDLER */
|
||||
void DNS_time_handler(void)
|
||||
{
|
||||
dns_1s_tick++;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -65,10 +65,10 @@
|
||||
* @todo SHOULD BE defined it equal as or greater than your Domain name length + null character(1)
|
||||
* @note SHOULD BE careful to stack overflow because it is allocated 1.5 times as MAX_DOMAIN_NAME in stack.
|
||||
*/
|
||||
#define MAX_DOMAIN_NAME 16 // for example "www.google.com"
|
||||
#define MAX_DOMAIN_NAME 32 // for example "www.google.com"
|
||||
|
||||
#define MAX_DNS_RETRY 2 ///< Requery Count
|
||||
#define DNS_WAIT_TIME 3 ///< Wait response time. unit 1s.
|
||||
#define DNS_WAIT_TIME 4 ///< Wait response time. unit 1s.
|
||||
|
||||
#define IPPORT_DOMAIN 53 ///< DNS server port number
|
||||
|
||||
@ -93,10 +93,4 @@ void DNS_init(uint8_t s, uint8_t * buf);
|
||||
*/
|
||||
int8_t DNS_run(uint8_t * dns_ip, uint8_t * name, uint8_t * ip_from_dns);
|
||||
|
||||
/*
|
||||
* @brief DNS 1s Tick Timer handler
|
||||
* @note SHOULD BE register to your system 1s Tick timer handler
|
||||
*/
|
||||
void DNS_time_handler(void);
|
||||
|
||||
#endif /* _DNS_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user