LCOV - code coverage report
Current view: top level - zephyr/drivers - hwinfo.h Hit Total Coverage
Test: new.info Lines: 21 21 100.0 %
Date: 2024-12-22 00:14:23

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

Generated by: LCOV version 1.14