From 592f66e1cada732c9a8a7729e0f6ed389db13195 Mon Sep 17 00:00:00 2001 From: sago35 Date: Mon, 1 Aug 2022 17:36:29 +0900 Subject: [PATCH] rtl8720dn: add Rpc_tcpip_adapter_init_with_timeout() --- examples/rtl8720dn/wioterminal.go | 2 +- rtl8720dn/rtl8720dn.go | 33 ++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/examples/rtl8720dn/wioterminal.go b/examples/rtl8720dn/wioterminal.go index ad56b87..0695f2f 100644 --- a/examples/rtl8720dn/wioterminal.go +++ b/examples/rtl8720dn/wioterminal.go @@ -47,7 +47,7 @@ func Setup() (*rtl8720dn.RTL8720DN, error) { rtl := rtl8720dn.New(uart) rtl.Debug(debug) - _, err := rtl.Rpc_tcpip_adapter_init() + _, err := rtl.Rpc_tcpip_adapter_init_with_timeout(10 * time.Second) if err != nil { return nil, err } diff --git a/rtl8720dn/rtl8720dn.go b/rtl8720dn/rtl8720dn.go index e24e841..53a411f 100644 --- a/rtl8720dn/rtl8720dn.go +++ b/rtl8720dn/rtl8720dn.go @@ -1,6 +1,10 @@ package rtl8720dn -import "io" +import ( + "fmt" + "io" + "time" +) const maxUartRecvSize = 128 @@ -38,6 +42,33 @@ func New(r io.ReadWriter) *RTL8720DN { return ret } +func (r *RTL8720DN) Rpc_tcpip_adapter_init_with_timeout(d time.Duration) (int32, error) { + timeout := make(chan bool) + go func() { + time.Sleep(d) + timeout <- true + }() + + var ret int32 + var err error + done := make(chan bool) + go func() { + ret, err = r.Rpc_tcpip_adapter_init() + done <- true + }() + + select { + case <-timeout: + return ret, fmt.Errorf("Rpc_tcpip_adapter_init: timeout") + case <-done: + if err != nil { + return ret, err + } + } + + return ret, nil +} + func (r *RTL8720DN) SetSeq(s uint64) { r.seq = s }