LCOV - code coverage report
Current view: top level - drivers/net/bnxt/tf_core - rand.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 9 0.0 %
Date: 2024-01-22 15:35:40 Functions: 0 3 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2019-2023 Broadcom
       3                 :            :  * All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : /* Random Number Functions */
       7                 :            : 
       8                 :            : #include <stdio.h>
       9                 :            : #include <stdint.h>
      10                 :            : #include "rand.h"
      11                 :            : 
      12                 :            : #define TF_RAND_LFSR_INIT_VALUE 0xACE1u
      13                 :            : 
      14                 :            : uint16_t lfsr = TF_RAND_LFSR_INIT_VALUE;
      15                 :            : uint32_t bit;
      16                 :            : 
      17                 :            : /**
      18                 :            :  * Generates a 16 bit pseudo random number
      19                 :            :  *
      20                 :            :  * Returns:
      21                 :            :  *   uint16_t number
      22                 :            :  */
      23                 :          0 : uint16_t rand16(void)
      24                 :            : {
      25                 :          0 :         bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5)) & 1;
      26                 :          0 :         return lfsr = (lfsr >> 1) | (bit << 15);
      27                 :            : }
      28                 :            : 
      29                 :            : /**
      30                 :            :  * Generates a 32 bit pseudo random number
      31                 :            :  *
      32                 :            :  * Returns:
      33                 :            :  *   uint32_t number
      34                 :            :  */
      35                 :          0 : uint32_t rand32(void)
      36                 :            : {
      37                 :          0 :         return (rand16() << 16) | rand16();
      38                 :            : }
      39                 :            : 
      40                 :            : /**
      41                 :            :  * Resets the seed used by the pseudo random number generator
      42                 :            :  */
      43                 :          0 : void rand_init(void)
      44                 :            : {
      45                 :          0 :         lfsr = TF_RAND_LFSR_INIT_VALUE;
      46                 :          0 :         bit = 0;
      47                 :          0 : }

Generated by: LCOV version 1.14