zephyr/drivers/entropy/entropy_rv32m1_trng.c
Kumar Gala a1b77fd589 zephyr: replace zephyr integer types with C99 types
git grep -l 'u\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/u\(8\|16\|32\|64\)_t/uint\1_t/g"
	git grep -l 's\(8\|16\|32\|64\)_t' | \
		xargs sed -i "s/s\(8\|16\|32\|64\)_t/int\1_t/g"

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2020-06-08 08:23:57 -05:00

65 lines
1.4 KiB
C

/*
* Copyright 2019 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT openisa_rv32m1_trng
#include <device.h>
#include <drivers/entropy.h>
#include <random/rand32.h>
#include <init.h>
#include "fsl_trng.h"
struct rv32m1_entropy_config {
TRNG_Type *base;
};
static int entropy_rv32m1_trng_get_entropy(struct device *dev, uint8_t *buffer,
uint16_t length)
{
const struct rv32m1_entropy_config *config = dev->config_info;
status_t status;
ARG_UNUSED(dev);
status = TRNG_GetRandomData(config->base, buffer, length);
__ASSERT_NO_MSG(!status);
return 0;
}
static const struct entropy_driver_api entropy_rv32m1_trng_api_funcs = {
.get_entropy = entropy_rv32m1_trng_get_entropy
};
static struct rv32m1_entropy_config entropy_rv32m1_config = {
.base = (TRNG_Type *)DT_INST_REG_ADDR(0)
};
static int entropy_rv32m1_trng_init(struct device *);
DEVICE_AND_API_INIT(entropy_rv32m1_trng, DT_INST_LABEL(0),
entropy_rv32m1_trng_init, NULL, &entropy_rv32m1_config,
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEVICE,
&entropy_rv32m1_trng_api_funcs);
static int entropy_rv32m1_trng_init(struct device *dev)
{
const struct rv32m1_entropy_config *config = dev->config_info;
trng_config_t conf;
status_t status;
ARG_UNUSED(dev);
status = TRNG_GetDefaultConfig(&conf);
__ASSERT_NO_MSG(!status);
status = TRNG_Init(config->base, &conf);
__ASSERT_NO_MSG(!status);
return 0;
}