Преглед изворни кода

fix:随机获取有点问题

alienwalker пре 4 година
родитељ
комит
2d31b9935a
2 измењених фајлова са 13 додато и 9 уклоњено
  1. 7 6
      application/src/luat_crypto_air105.c
  2. 6 3
      bsp/common/include/bsp_common.h

+ 7 - 6
application/src/luat_crypto_air105.c

@@ -27,13 +27,14 @@
 
 int luat_crypto_trng(char* buff, size_t len) {
     size_t t = 0;
-    char tmp[4];
+    uint32_t tmp[4];
     while (len > t) {
-        RNG_GetData((uint32_t*)tmp);
-        for (; t < len; t++)
-        {
-            buff[t] = (char)tmp[t % 4];
-        }
+        RNG_GetData(tmp);
+        BytesPutLe32(&buff[t], tmp[0]);
+        BytesPutLe32(&buff[t + 4], tmp[1]);
+        BytesPutLe32(&buff[t + 8], tmp[2]);
+        BytesPutLe32(&buff[t + 12], tmp[3]);
+        t += 16;
     }
     return 0;
 }

+ 6 - 3
bsp/common/include/bsp_common.h

@@ -161,14 +161,16 @@ enum
 	USER_EVENT_ID_START = 0xf1000000,
 	INVALID_EVENT_ID = 0xffffffff,
 
-	NW_EVENT_CONNECTED = 0,
-	NW_EVENT_REMOTE_CLOSE,
+	NW_EVENT_SENT = 0,
 	NW_EVENT_RECV,
 	NW_EVENT_ERR,
-	NW_EVENT_SENT,
+	NW_EVENT_CONNECTED,
+	NW_EVENT_REMOTE_CLOSE,
 	NW_EVENT_ACCEPT,
 	NW_EVENT_CLOSE_OK,
 
+
+
 };
 
 #define INVALID_HANDLE_VALUE  ((void *)0xffffffff)
@@ -518,6 +520,7 @@ double BytesGetDoubleFromBuf(Buffer_Struct *Buf);
 void BytesPutDoubleToBuf(Buffer_Struct *Buf, double v);
 /*************************************************************************/
 
+extern uint64_t GetSysTickMS();
 
 #define malloc OS_Malloc
 #define free OS_Free