// Pad physical properties configuration functions
// ***********************************************
// Most pads in Tortola have some controlled physical properties, suce as slew rate,
// scmidht trigger, pull/keep etc. for a complete list of contolablle features per pad, see:
// 
// /vobs/vb_tortola/tortola_designdir/tortola/tool_/rabbit/Tortola_pins.xls
//
// the efines naming convention is config_<property>_<value>(PAD).
// controllable properties and coresponding function names are:
// 
// config_slew_rate_to_fast(PAD)       (high freq. designs)
// config_slew_rate_to_slow(PAD)       (Neptune pads compatible)
// config_loopback_enable(PAD)
// config_loopback_disable(PAD)
// config_drive_to_max(PAD)
// config_drive_to_high(PAD)
// config_drive_to_nominal(PAD)
// config_pull_select(PAD)             (pull up or down)
// config_keep_select(PAD)             (keeper selected)
// config_pull_keep_enable(PAD)        (integration level option bits to select PU/D or keeper)
// config_pull_keep_diable(PAD)        
// config_open_drain_enable(PAD)       (output is open drain)
// config_open_drain_disable(PAD)      (output is CMOS)
// config_schmidt_trigger_enable(PAD)  (schmidt trigger)
// config_schmidt_trigger_disable(PAD) (CMOS)
//
// contact: giladb, RM96492, FIL

#ifndef PAD_SETTING_H
#define PAD_SETTING_H

#include "functions.h"

#define config_slew_rate_to_fast(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00000001); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00000400); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00100000); \

#define config_slew_rate_to_slow(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00000001); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00000400); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00100000); \

#define config_loopback_enable(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00000100); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00080000); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x20000000); \

#define config_loopback_disable(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00000100); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00080000); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x20000000); \

#define config_drive_to_max(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00000004); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00001000); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00400000); \

#define config_drive_to_high(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xfffffff2, 0x00000006 ); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffff08ff, 0x00001800 ); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xff2fffff, 0x00600000 ); \

#define config_drive_to_nominal(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00000006); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00001800); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00600000); \

#define config_pull_select(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00000080); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00020000); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x08000000); \

#define config_keep_select(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00000080); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00020000); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x08000000); \

#define config_pull_keep_enable(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00000100); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00040000); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x10000000); \

#define config_pull_keep_disable(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00000100); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00040000); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x10000000); \

#define config_open_drain_enable(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00000008); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00002000); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00800000); \

#define config_open_drain_disable(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00000008); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00002000); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00800000); \

#define config_schmidt_trigger_enable(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00000010); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x00004000); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0xffffffff, 0x01000000); \

#define config_schmidt_trigger_disable(pad) \
if (pad ## _BYTE_IN_SW_PAD == 0) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00000010); \
if (pad ## _BYTE_IN_SW_PAD == 1) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x00004000); \
if (pad ## _BYTE_IN_SW_PAD == 2) \
    reg32_write_mask(pad ## _SW_PAD_REG, 0x00000000, 0x01000000); \

#endif //PAD_SETTING_H
