/****************************************************************************/
/*	Copyright (c) 2009, Bendor Research Pty. Ltd. All rights reserved.		*/
/*	This software is released under the GNU General Public License, version	*/
/*	3, with the exemptions that 1) the header files installed by this 	 	*/
/*	package can be included in closed-source code and 2) the libraries		*/
/*	built by this package can be statically linked into a closed-source 	*/
/*	binary. See the file LICENSE for the details.							*/
/*	This software is provided "AS IS", without any warranty or guarantee.	*/
/*	By using this software you acknowledge that neither Bendor Research nor	*/
/*	any of its personnel or affiliates can be held liable for any damages,	*/
/*	including, but not limited to, loss of business, loss of money, loss of */
/*	life, loss of reputation, arising out of this software being faulty or	*/
/*	not performing as advertised, even if Bendor Research was aware of such	*/
/*	faults in the software. You use this software at your own risk, any and */
/*	all liabilities that arise out of your using this software are strictly	*/
/*	yours.																	*/
/****************************************************************************/

#ifndef _LPCTCL_H
#define _LPCTCL_H

#include <stdio.h>
#include <malloc.h>
#include <unistd.h>
#include <string.h>
#include <tcl.h>

#include "../../include/tools/lpclib.h"

typedef struct {

	LPC				lpc;					// LPC library handle
	Tcl_Interp		*tcl;					// TCL interpreter
	int				ser_slow;				// Slow baud rate
	int				ser_fast;				// Flast baud rate
	char			*ser_user;				// User control callback
	const char		*hex_type;				// Hex file format
	unsigned char	tgt_data[ 512 * 1024 ];	// Memory buffer
	unsigned char	tgt_flag[ 512 * 1024 ];	// Buffer flags
	Tcl_Obj			*tgt_proc;				// Progress TCL procedure name
	Tcl_Obj			*tgt_user;				// Progress TCL procedure first arg
	Tcl_Obj			*tgt_pwrf;				// Target power callback
	Tcl_Obj			*log_proc;				// Log TCL procedure name
	Tcl_Obj			*log_user;				// Log TCL procedure first arg

} LPCTCL;

#define	STAT_VOID		0
#define	STAT_ERASED		1
#define	STAT_CLEAN		2
#define	STAT_DIRTY		3

typedef int (*CMDFUNCPTR)(LPCTCL *, Tcl_Interp *, int, Tcl_Obj * const [] );

typedef struct {

	const char	*name;
	CMDFUNCPTR	func;

} CMDTABLE;

#define	CMDFUNC( name )	\
	int Lpctcl_ ## name \
	( LPCTCL *lib, Tcl_Interp *tcl, int objc, Tcl_Obj * const objv[] )

int		Lpctcl_Init( Tcl_Interp *inter );
int		Lpctcl_Command( const CMDTABLE *table, LPCTCL *lib, Tcl_Interp *tcl,
					   	int objc, Tcl_Obj * const objv[] );
void	Lpctcl_Liberror( Tcl_Interp *tcl, int code );
void	Lpctcl_Progress( LPCTCL *lib, const char * );
void	Lpctcl_Power( int state, void *param );

CMDFUNC( SerialPort );
CMDFUNC( SerialClose );
CMDFUNC( SerialBaud );
CMDFUNC( SerialModem );
CMDFUNC( SerialManual );
CMDFUNC( TargetPower );
CMDFUNC( TargetConnect );
CMDFUNC( TargetFlash );
CMDFUNC( TargetReset );
CMDFUNC( TargetXtal );
CMDFUNC( TargetType );
CMDFUNC( TargetType );
CMDFUNC( TargetSend );
CMDFUNC( TargetRecv );
CMDFUNC( FileInvalid );
CMDFUNC( FileType );
CMDFUNC( FileLoad );
CMDFUNC( FileSave );
CMDFUNC( FileBurn );
CMDFUNC( FileVect );
CMDFUNC( LogProc );
CMDFUNC( LogError );
CMDFUNC( LogOn );
CMDFUNC( LogOff );
CMDFUNC( TargetProgress );

#endif

