1 /*
2  * Copyright (C) 2015-2021 Alibaba Group Holding Limited
3  */
4 
5 #include <stdlib.h>
6 
7 #include "aos/kernel.h"
8 #include "k_config.h"
9 
10 #define SEED_MAGIC 0x123
11 
12 extern void hal_reboot(void);
13 
aos_reboot(void)14 void aos_reboot(void)
15 {
16     hal_reboot();
17 }
18 
aos_get_hz(void)19 int32_t aos_get_hz(void)
20 {
21     return RHINO_CONFIG_TICKS_PER_SECOND;
22 }
23 
aos_version_str_get(char * buf,size_t len)24 aos_status_t aos_version_str_get(char *buf, size_t len)
25 {
26     const char *ver_str = SYSINFO_KERNEL_VERSION;
27 
28     if (buf == NULL) {
29         return -EINVAL;
30     }
31 
32     if (len <= strlen(ver_str)) {
33         return -EINVAL;
34     }
35 
36     memcpy(buf, ver_str, strlen(ver_str));
37     return 0;
38 }
39 
40 #if !defined (ENABLE_RNG) && defined (AOS_COMP_KV)
41 #include "aos/kv.h"
42 #endif
43 
aos_srand(uint32_t seed)44 void aos_srand(uint32_t seed)
45 {
46 #if !defined (ENABLE_RNG) && defined (AOS_COMP_KV)
47     int           ret        = 0;
48     int           seed_len   = 0;
49     uint32_t      seed_val   = 0;
50     static char  *g_seed_key = "seed_key";
51 
52     seed_len = sizeof(seed_val);
53     ret = aos_kv_get(g_seed_key, &seed_val, &seed_len);
54     if (ret) {
55         seed_val = SEED_MAGIC;
56     }
57     seed_val += seed;
58     srand(seed_val);
59 
60     seed_val = rand();
61     ret = aos_kv_set(g_seed_key, &seed_val, sizeof(seed_val), 1);
62     if (ret) {
63         printf("aos_kv_set error, return :%d\r\n", ret);
64     }
65 #else
66     srand(seed);
67 #endif
68 }
69 
aos_rand(void)70 int32_t aos_rand(void)
71 {
72     return rand();
73 }
74