1 /**
2  * @file
3  *
4  * @brief Public APIs to get device Information.
5  */
6 
7 /*
8  * Copyright (c) 2018 Alexander Wachter
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  */
12 
13 #ifndef ZEPHYR_INCLUDE_DRIVERS_HWINFO_H_
14 #define ZEPHYR_INCLUDE_DRIVERS_HWINFO_H_
15 
16 /**
17  * @brief Hardware Information Interface
18  * @defgroup hwinfo_interface Hardware Info Interface
19  * @ingroup io_interfaces
20  * @{
21  */
22 
23 #include <zephyr/types.h>
24 #include <sys/types.h>
25 #include <stddef.h>
26 #include <errno.h>
27 #include <kernel.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #define RESET_PIN				BIT(0)
34 #define RESET_SOFTWARE				BIT(1)
35 #define RESET_BROWNOUT				BIT(2)
36 #define RESET_POR				BIT(3)
37 #define RESET_WATCHDOG				BIT(4)
38 #define RESET_DEBUG				BIT(5)
39 #define RESET_SECURITY				BIT(6)
40 #define RESET_LOW_POWER_WAKE			BIT(7)
41 #define RESET_CPU_LOCKUP			BIT(8)
42 #define RESET_PARITY				BIT(9)
43 #define RESET_PLL				BIT(10)
44 #define RESET_CLOCK				BIT(11)
45 
46 /**
47  * @brief Copy the device id to a buffer
48  *
49  * This routine copies "length" number of bytes of the device ID to the buffer.
50  * If the device ID is smaller then length, the rest of the buffer is left unchanged.
51  * The ID depends on the hardware and is not guaranteed unique.
52  *
53  * Drivers are responsible for ensuring that the ID data structure is a
54  * sequence of bytes.  The returned ID value is not supposed to be interpreted
55  * based on vendor-specific assumptions of byte order. It should express the
56  * identifier as a raw byte sequence, doing any endian conversion necessary so
57  * that a hex representation of the bytes produces the intended serial number.
58  *
59  * @param buffer  Buffer to write the ID to.
60  * @param length  Max length of the buffer.
61  *
62  * @retval size of the device ID copied.
63  * @retval -ENOTSUP if there is no implementation for the particular device.
64  * @retval any negative value on driver specific errors.
65  */
66 __syscall ssize_t hwinfo_get_device_id(uint8_t *buffer, size_t length);
67 
68 ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length);
69 
70 /**
71  * @brief      Retrieve cause of device reset.
72  *
73  * @param      cause  OR'd `reset_cause` flags
74  *
75  * This routine retrieves the flags that indicate why the device was reset.
76  *
77  * On some platforms the reset cause flags accumulate between successive resets
78  * and this routine may return multiple flags indicating all reset causes
79  * since the device was powered on. If you need to retrieve the cause only for
80  * the most recent reset call `hwinfo_clear_reset_cause` after calling this
81  * routine to clear the hardware flags before the next reset event.
82  *
83  * Successive calls to this routine will return the same value, unless
84  * `hwinfo_clear_reset_cause` has been called.
85  *
86  * @retval zero if successful.
87  * @retval -ENOTSUP if there is no implementation for the particular device.
88  * @retval any negative value on driver specific errors.
89  */
90 __syscall int hwinfo_get_reset_cause(uint32_t *cause);
91 
92 int z_impl_hwinfo_get_reset_cause(uint32_t *cause);
93 
94 /**
95  * @brief      Clear cause of device reset.
96  *
97  * Clears reset cause flags.
98  *
99  * @retval zero if successful.
100  * @retval -ENOTSUP if there is no implementation for the particular device.
101  * @retval any negative value on driver specific errors.
102  */
103 __syscall int hwinfo_clear_reset_cause(void);
104 
105 int z_impl_hwinfo_clear_reset_cause(void);
106 
107 /**
108  * @brief      Get supported reset cause flags
109  *
110  * @param      supported  OR'd `reset_cause` flags that are supported
111  *
112  * Retrieves all `reset_cause` flags that are supported by this device.
113  *
114  * @retval zero if successful.
115  * @retval -ENOTSUP if there is no implementation for the particular device.
116  * @retval any negative value on driver specific errors.
117  */
118 __syscall int hwinfo_get_supported_reset_cause(uint32_t *supported);
119 
120 int z_impl_hwinfo_get_supported_reset_cause(uint32_t *supported);
121 
122 /**
123  * @}
124  */
125 
126 #ifdef __cplusplus
127 }
128 #endif
129 
130 #include <syscalls/hwinfo.h>
131 
132 #endif /* ZEPHYR_INCLUDE_DRIVERS_HWINFO_H_ */
133