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 <zephyr/kernel.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /**
34  * @name Reset cause flags
35  * @anchor reset_cause
36  * @{
37  */
38 /** External pin */
39 #define RESET_PIN				BIT(0)
40 /** Software reset */
41 #define RESET_SOFTWARE				BIT(1)
42 /** Brownout (drop in voltage) */
43 #define RESET_BROWNOUT				BIT(2)
44 /** Power-on reset (POR) */
45 #define RESET_POR				BIT(3)
46 /** Watchdog timer expiration */
47 #define RESET_WATCHDOG				BIT(4)
48 /** Debug event */
49 #define RESET_DEBUG				BIT(5)
50 /** Security violation */
51 #define RESET_SECURITY				BIT(6)
52 /** Waking up from low power mode */
53 #define RESET_LOW_POWER_WAKE			BIT(7)
54 /** CPU lock-up detected */
55 #define RESET_CPU_LOCKUP			BIT(8)
56 /** Parity error */
57 #define RESET_PARITY				BIT(9)
58 /** PLL error */
59 #define RESET_PLL				BIT(10)
60 /** Clock error */
61 #define RESET_CLOCK				BIT(11)
62 /** Hardware reset */
63 #define RESET_HARDWARE				BIT(12)
64 /** User reset */
65 #define RESET_USER				BIT(13)
66 /** Temperature reset */
67 #define RESET_TEMPERATURE			BIT(14)
68 /**
69  * @}
70  */
71 
72 /**
73  * @brief Copy the device id to a buffer
74  *
75  * This routine copies "length" number of bytes of the device ID to the buffer.
76  * If the device ID is smaller then length, the rest of the buffer is left unchanged.
77  * The ID depends on the hardware and is not guaranteed unique.
78  *
79  * Drivers are responsible for ensuring that the ID data structure is a
80  * sequence of bytes.  The returned ID value is not supposed to be interpreted
81  * based on vendor-specific assumptions of byte order. It should express the
82  * identifier as a raw byte sequence, doing any endian conversion necessary so
83  * that a hex representation of the bytes produces the intended serial number.
84  *
85  * @param buffer  Buffer to write the ID to.
86  * @param length  Max length of the buffer.
87  *
88  * @retval size of the device ID copied.
89  * @retval -ENOSYS if there is no implementation for the particular device.
90  * @retval any negative value on driver specific errors.
91  */
92 __syscall ssize_t hwinfo_get_device_id(uint8_t *buffer, size_t length);
93 
94 ssize_t z_impl_hwinfo_get_device_id(uint8_t *buffer, size_t length);
95 
96 /**
97  * @brief      Retrieve cause of device reset.
98  *
99  * @param      cause  OR'd @ref reset_cause "reset cause" flags
100  *
101  * This routine retrieves the flags that indicate why the device was reset.
102  *
103  * On some platforms the reset cause flags accumulate between successive resets
104  * and this routine may return multiple flags indicating all reset causes
105  * since the device was powered on. If you need to retrieve the cause only for
106  * the most recent reset call `hwinfo_clear_reset_cause` after calling this
107  * routine to clear the hardware flags before the next reset event.
108  *
109  * Successive calls to this routine will return the same value, unless
110  * `hwinfo_clear_reset_cause` has been called.
111  *
112  * @retval zero if successful.
113  * @retval -ENOSYS if there is no implementation for the particular device.
114  * @retval any negative value on driver specific errors.
115  */
116 __syscall int hwinfo_get_reset_cause(uint32_t *cause);
117 
118 int z_impl_hwinfo_get_reset_cause(uint32_t *cause);
119 
120 /**
121  * @brief      Clear cause of device reset.
122  *
123  * Clears reset cause flags.
124  *
125  * @retval zero if successful.
126  * @retval -ENOSYS if there is no implementation for the particular device.
127  * @retval any negative value on driver specific errors.
128  */
129 __syscall int hwinfo_clear_reset_cause(void);
130 
131 int z_impl_hwinfo_clear_reset_cause(void);
132 
133 /**
134  * @brief      Get supported reset cause flags
135  *
136  * @param      supported  OR'd @ref reset_cause "reset cause" flags that are supported
137  *
138  * Retrieves all `reset_cause` flags that are supported by this device.
139  *
140  * @retval zero if successful.
141  * @retval -ENOSYS if there is no implementation for the particular device.
142  * @retval any negative value on driver specific errors.
143  */
144 __syscall int hwinfo_get_supported_reset_cause(uint32_t *supported);
145 
146 int z_impl_hwinfo_get_supported_reset_cause(uint32_t *supported);
147 
148 /**
149  * @}
150  */
151 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 #include <syscalls/hwinfo.h>
157 
158 #endif /* ZEPHYR_INCLUDE_DRIVERS_HWINFO_H_ */
159