#include "driver.h"
#include <linux/types.h>
#include <stdio.h>
#include <string.h>
#include "com_gpio.h"
#include "hal_interface_api.h"
#include "linux/fcntl.h"
#include "time.h"
#include <unistd.h>

#define DEV_NAME	"/dev/platform"

int stm32_reset_mcu(void)
{
	int fd;
	int ret;
	
	fd = open(DEV_NAME, O_RDWR);
	if(fd == -1)
	{
		printf("Open %s failed!\n", DEV_NAME);
	}

	ret = ioctl(fd, RESET_MCU, NULL);
	if(ret == -1)
	{
		printf("Reset MCU failed!\n");
	}
	close(fd);

	return ret;
}

uint32_t stm32_generate_random32bit(void)
{
	int fd;
	int ret;
	platform_arg_t args;
	
	fd = open(DEV_NAME, O_RDWR);
	if(fd == -1)
	{
		printf("Open %s failed!\n", DEV_NAME);
	}

	ret = ioctl(fd, GET_32BIT_RANDOM, &args);
	if(ret == -1)
	{
		printf("Get random failed!\n");
	}
	close(fd);

	return args.random_32bit;
}