/*
 * Copyright (C) 2022 EXOLIGENT (www.exoligent.com)
 * Author: Maxime Coroyer <maxime.coroyer@exoligent.com>
 */

#ifndef __FIP_H__
#define __FIP_H__

#include "libpowerfip.h"

#define FIP_VAR_COUNT_MAX 500
struct gw_fip {
    int dev_idx;
    /* node configuration */
    uint8_t addr;
    uint8_t seg;
    uint8_t frm_type;
    uint8_t bitrate;
    uint32_t tr_ustime;
    uint32_t ts_ustime;
    /* variables configuration */
    struct pwrfip_var_cfg cfg_varlist[FIP_VAR_COUNT_MAX];
    int cfg_varcnt;
    /* device object */
    struct pwrfip_dev *dev; /* pci device handle */
    /* node object */
    struct pwrfip_node *n;
    /* aele object */
    struct pwrfip_aele *al;
    /* consumed variables list */
    struct pwrfip_var *cons_varlist[FIP_VAR_COUNT_MAX];
    int cons_varcnt;
    /* produced variables list */
    struct pwrfip_var *prod_varlist[FIP_VAR_COUNT_MAX];
    int prod_varcnt;
    /* synchronization variables list */
    struct pwrfip_var *sync_varlist[FIP_VAR_COUNT_MAX];
    int sync_varcnt;
};

#define PWRFIP_BITRATE_RANGE (_PWRFIP_BITRATE_MAX - _PWRFIP_BITRATE_MIN)
extern const char *bitrate[PWRFIP_BITRATE_RANGE];
extern const uint32_t tr_ustime[PWRFIP_BITRATE_RANGE];
extern const uint32_t ts_ustime[PWRFIP_BITRATE_RANGE];

/* global handlers */
void fip_id_sync_handler(struct pwrfip_node *node,
        struct pwrfip_var *var, struct pwrfip_event *evt);
void fip_error_handler(struct pwrfip_node *node,
        enum pwrfip_error_code code);
void fip_reset_handler(struct pwrfip_node *node);
/* utility */
void print_node_infos(struct pwrfip_node *node);
#endif
