library ieee; use ieee.std_logic_1164.all; --use ieee.math_real.all; use ieee.numeric_std.all; package generics is constant synthesis : boolean := true -- synthesis translate_off and false -- synthesis translate_on ; function sim_cond(cond : boolean) return boolean; function istr(v : integer) return string; function as_std_logic(v : boolean) return std_logic; function rot_l(v : std_logic_vector; n : integer := 1) return std_logic_vector; function rot_r(v : std_logic_vector; n : integer := 1) return std_logic_vector; function sh_l(v : std_logic_vector; n : integer := 1) return std_logic_vector; function sh_r(v : std_logic_vector; n : integer := 1) return std_logic_vector; function log2_int(v : integer) return integer; function log2(v : integer) return integer; function is_log2(v : integer) return boolean; function binary_flatten(v : std_logic_vector; n : integer) return std_logic_vector; function min(a : integer; b : integer) return integer; function max(a : integer; b : integer) return integer; function find_first_bit(v : std_logic_vector) return integer; function mask_first_bit(v : std_logic_vector) return std_logic_vector; function next_multiple(v : integer; m : integer) return integer; function reverse_vector(inp : std_logic_vector) return std_logic_vector; function reorder_vector(inp : std_logic_vector) return std_logic_vector; function htonl(inp : std_logic_vector) return std_logic_vector; function ntohl(inp : std_logic_vector) return std_logic_vector; function vector_all_valid(i : std_logic_vector) return boolean; function to_integer(i : std_logic) return integer; function integer_reverse_bits(i : integer; bits : integer) return integer; function dbg_collapse16(d : in std_logic_vector) return std_logic_vector; function bram_we_width(aw : integer) return integer; function chr(sl: std_logic) return character; function chr(i : integer) return character; function chr(b : boolean) return character; function vector_to_string(v : std_logic_vector) return string; function vector_to_hex_string(v : std_logic_vector) return string; function to_std_logic_vector(v : integer; size : integer) return std_logic_vector; function popcnt(v : std_logic_vector) return integer; function popcnt(v : integer; bits : integer) return integer; function popcnt_x(v : std_logic_vector) return integer; function maxlen_lfsr_advance(reg : std_logic_vector) return std_logic_vector; function random_vector(len : integer; seed : integer) return std_logic_vector; function random(max : integer; seed : integer) return integer; function reverse_any_vector(a : in std_logic_vector) return std_logic_vector; function sel(cond : boolean; if_true : integer; if_false : integer) return integer; function sel(cond : boolean; if_true : std_logic_vector; if_false : std_logic_vector) return std_logic_vector; function sel(cond : boolean; if_true : std_logic; if_false : std_logic) return std_logic; function sel(cond : boolean; if_true : string; if_false : string) return string; procedure clkp(signal clk : in std_logic; n : in integer); function vector_mux(sel : std_logic_vector; i1 : std_logic_vector; i2 : std_logic_vector) return std_logic_vector; function div_ceil(a : integer; b : integer) return integer; function int_strlen(vv : integer) return natural; end generics; package body generics is function chr(b : boolean) return character is begin if b then return 't'; end if; return 'f'; end function; function chr(i : integer) return character is variable s : string(1 to 10) := "0123456789"; begin if i < 10 then return s(i + 1); else return 'X'; end if; end function; function istr(v : integer) return string is begin return integer'image(v); end function; function as_std_logic(v : boolean) return std_logic is begin if v then return '1'; end if; return '0'; end function; function int_strlen(vv : integer) return natural is variable ret : natural := 0; variable v : integer := vv; begin if v < 0 then ret := ret + 1; v := -v; end if; while v >= 10 loop v := v / 10; ret := ret + 1; end loop; return ret + 1; end function; function rot_l(v : std_logic_vector; n : integer := 1) return std_logic_vector is begin return std_logic_vector(rotate_left(unsigned(v), n)); end function; function rot_r(v : std_logic_vector; n : integer := 1) return std_logic_vector is begin return std_logic_vector(rotate_right(unsigned(v), n)); end function; function sh_l(v : std_logic_vector; n : integer := 1) return std_logic_vector is begin return std_logic_vector(shift_left(unsigned(v), n)); end function; function sh_r(v : std_logic_vector; n : integer := 1) return std_logic_vector is begin return std_logic_vector(shift_right(unsigned(v), n)); end function; function log2(v : integer) return integer is begin return log2_int(v); end function; function is_log2(v : integer) return boolean is begin return 2 ** log2(v) = v; end function; function to_integer(i : std_logic) return integer is begin if i = '1' then return 1; elsif i = '0' then return 0; else return -1; end if; end function; function dbg_collapse16(d : in std_logic_vector) return std_logic_vector is variable ret : std_logic_vector(0 to 15); variable oi : integer; begin oi := 0; ret := (others => '0'); for i in d'range loop ret(oi) := ret(oi) xor d(i); if oi < 15 then oi := oi + 1; else oi := 0; end if; end loop; return ret; end function; function random(max : integer; seed : integer) return integer is begin if max = 0 then return 0; end if; return to_integer(unsigned(random_vector(log2_int(max) + 1, seed))) mod max; end function; function sel(cond : boolean; if_true : std_logic; if_false : std_logic) return std_logic is begin if cond then return if_true; end if; return if_false; end function; function sel(cond : boolean; if_true : string; if_false : string) return string is begin if cond then return if_true; else return if_false; end if; end function; function div_ceil(a : integer; b : integer) return integer is begin return a / b + sel(a mod b /= 0, 1, 0); end function;
/*
    ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

        http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
*/

/**
 * @file    nullstreams.c
 * @brief   Null streams code.
 *
 * @addtogroup HAL_NULL_STREAMS
 * @details A null streams.
 * @{
 */

#include "hal.h"
#include "nullstreams.h"

/*===========================================================================*/
/* Driver local definitions.                                                 */
/*===========================================================================*/

/*===========================================================================*/
/* Driver exported variables.                                                */
/*===========================================================================*/

/*===========================================================================*/
/* Driver local variables.                                                   */
/*===========================================================================*/

/*===========================================================================*/
/* Driver local functions.                                                   */
/*===========================================================================*/

static size_t writes(void *ip, const uint8_t *bp, size_t n) {

  (void)ip;
  (void)bp;

  return n;
}

static size_t reads(void *ip, uint8_t *bp, size_t n) {

  (void)ip;
  (void)bp;
  (void)n;

  return 0;
}

static msg_t put(void *ip, uint8_t b) {

  (void)ip;
  (void)b;

  return MSG_OK;
}

static msg_t get(void *ip) {

  (void)ip;

  return 4;
}

static const struct NullStreamVMT vmt = {(size_t)0, writes, reads, put, get};

/*===========================================================================*/
/* Driver exported functions.                                                */
/*===========================================================================*/

/**
 * @brief   Null stream object initialization.
 *
 * @param[out] nsp      pointer to the @p NullStream object to be initialized
 */
void nullObjectInit(NullStream *nsp) {

  nsp->vmt = &vmt;
}

/** @} */