/*
 *
 *  ALL03
 *
 *  26.07.2002
 *
 *  by Fabio Sturman
 *
 *  fabio.sturman@tiscali.it
 *
 *  all03.h
 *
 *  all03.c include file
 *
 */

/* Copyright (c) 2002 Fabio Sturman (fabio.sturman@tiscali.it)
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef ALL03_INCLUDE
#define ALL03_INCLUDE

#define ALL03_BASE 0x2e0

#define ALL03_VOP_ID 0xe5       /* 10.2 .. 25.5 step 0.1  */
#define ALL03_VHH_ID 0xe6       /*  5.1 .. 15.3 step 0.06 */
#define ALL03_VCC_ID 0xe7       /*  0.0 ..  5.2 step 0.04 */
#define ALL03_TTL_ID 0xe0       /* e0, e1, e2, e3, e4 ttl i/o lsb(e0)=pin1  MSB(e4)=pin40 */
                          /* to read pin write 1 to it */
#define ALL03_VOP_EN_ID 0xe8    /* e8, e9, ea, eb, ec 1 enables VOP to pin */
#define ALL03_VHH_EN_ID 0xf0    /* f0, f1, f2, f3, f4 1 enables VOP to pin */

#define ALL03_VCC_EN_ID 0xed    /* ed, ee 1 enables VCC to pin */
#define ALL03_VHH_EN_C_ID 0xf5  /* f5, f6 1 enables VHH through 22ohm to pin */
#define ALL03_OTHER_EN_ID 0xef


#define ALL03_DELTA_VOP 0.1
#define ALL03_MIN_VOP 10.2
#define ALL03_MAX_VOP 25.5

#define ALL03_DELTA_VHH 0.06
#define ALL03_MIN_VHH 5.1
#define ALL03_MAX_VHH 15.3

#define ALL03_DELTA_VCC 0.04
#define ALL03_MIN_VCC 0
#define ALL03_MAX_VCC 10.2

#define ALL03_MIN_PIN      1
#define ALL03_MAX_PIN      40

#define ALL03_LOW  0
#define ALL03_HIGH 1


#define all03_clear_busy_led() all03_set_vcc(0.0)

#define all03_set_vcc_27()     all03_set_vcc_pin(27,1)
#define all03_set_vcc_dip14()  all03_set_vcc_pin(27,1)

#define all03_set_vcc_28()     all03_set_vcc_pin(28,1)
#define all03_set_vcc_dip_16() all03_set_vcc_pin(28,1)

#define all03_set_vcc_29()     all03_set_vcc_pin(29,1)
#define all03_set_vcc_dip_18() all03_set_vcc_pin(29,1)

#define all03_set_vcc_30()     all03_set_vcc_pin(30,1)
#define all03_set_vcc_dip_20() all03_set_vcc_pin(30,1)

#define all03_set_vcc_32()     all03_set_vcc_pin(32,1)
#define all03_set_vcc_dip_24() all03_set_vcc_pin(32,1)

#define all03_set_vcc_34()     all03_set_vcc_pin(34,1)
#define all03_set_vcc_dip_28() all03_set_vcc_pin(34,1)

#define all03_set_vcc_40()     all03_set_vcc_pin(40,1)
#define all03_set_vcc_dip_40() all03_set_vcc_pin(40,1)


void all03_wr_id(unsigned char id);
void all03_wr_data(unsigned char data);
unsigned char all03_rd_data(void);
void all03_wr(unsigned char id, unsigned char data);
unsigned char all03_rd(unsigned char id);
void all03_set_vop(float v);
void all03_set_vhh(float v);
void all03_set_vcc(float v);
void all03_init_h(void);
void all03_wr_pin(int pin, int state);
int all03_rd_pin(int pin);
void all03_wr_vcc_pin(int pin, int state);
void all03_wr_vhh_pin(int pin, int state);
void all03_wr_vop_pin(int pin, int state);
void all03_wr_vhh_c_pin(int pin, int state);
void all03_set_gnd_20(void);
void all03_set_gnd_11_30(void);

unsigned char all03_rd_ttl_buf(int i);
void all03_wr_ttl_buf(int i, unsigned char b);
unsigned char all03_rd_vop_en_buf(int i);
void all03_wr_vop_en_buf(int i, unsigned char b);
unsigned char all03_rd_vhh_en_buf(int i);
void all03_wr_vhh_en_buf(int i, unsigned char b);
unsigned char all03_rd_vcc_en_buf(int i);
void all03_wr_vcc_en_buf(int i, unsigned char b);
unsigned char all03_rd_vhh_en_c_buf(int i);
void all03_wr_vhh_en_c_buf(int i, unsigned char b);
unsigned char all03_rd_vhh_buf(void);
void all03_wr_vhh_buf(unsigned char b);
unsigned char all03_rd_vcc_buf(void);
void all03_wr_vcc_buf(unsigned char b);
unsigned char all03_rd_vop_buf(void);
void all03_wr_vop_buf(unsigned char b);
unsigned char all03_rd_other_en_buf(void);
void all03_wr_other_en_buf(unsigned char b);
unsigned char all03_rd_id_f7_buf(void);
void all03_wr_id_f7_buf(unsigned char b);

int all03_is_ttl_pin(int pin);
int all03_is_vcc_pin(int pin);
int all03_is_vhh_pin(int pin);
int all03_is_vop_pin(int pin);
int all03_is_vhh_c_pin(int pin);

void all03_set_vcc_pin(int pin, int state);
void all03_set_vhh_pin(int pin, int state);
void all03_set_vhh_c_pin(int pin, int state);
void all03_set_vop_pin(int pin, int state);


void all03_set_vop24_7(int state);
void all03_set_vop24_25(int state);
void all03_select_f_osc(int val);
void all03_set_osc_2_3(int state);
void all03_set_osc_18_19(int state);

char all03_dec_to_hex(int dec);
int all03_hex_to_dec(char h);
unsigned char all03_reverse_bits(unsigned char by);
void all03_wr_led_good(int state);
int all03_test_base_address(void);
unsigned short int all03_get_base_address(void);
void all03_set_base_address(unsigned short int ba);

/* all text i/o */
void all03_msg(char *ts);
int all03_msg_rv(char *ts, char *ats);
void all03_edit_base(void);
void all03_dump(void);

#endif
