#include "task_rand.h"
#include "hardware_task.h"
#include "data_channel.h"
#include "float_word.h"

#include <stdio.h>
#include <system.h>

#define REG_SEED_OFFSET 0
#define REG_EXP_MIN_OFFSET 1
#define REG_EXP_MAX_OFFSET 2

rand_config RAND_CONFIG = {
    .base = { .name = "rand",
        .binding = BINDING_SW,
        .software = task_rand_run,
        .configure = task_rand_configure,
        .hardware = HARDWARE_TASK_2_BASE,
        .sources = { 0, 0 },
        .sink = DATA_CHANNEL_2_BASE,
        .cycle_count = 0 },
    .seed = 1.3,
    .abs_min = 0.125,
    .abs_max = 9.0 };

int task_rand_configure( void * data ) {
    rand_config * task = ( rand_config * ) data;
    uint32_t base = task->base.hardware;

    float_word value = { .value = task->seed };
    hardware_task_set_config( base, REG_SEED_OFFSET, value.word );

    return 0;
}

