/*********************************************************************
 *                  Flowcode CAL IO File
 *
 * File: PIC_CAL_IO.c
 *
 * (c) 2011 Matrix Multimedia Ltd.
 * http://www.matrixmultimedia.com
 *
 * Software License Agreement
 *
 * The software supplied herewith by Matrix Multimedia Ltd (the
 * “Company”) for its Flowcode graphical programming language is
 * intended and supplied to you, the Company’s customer, for use
 * solely and exclusively on the Company's products. The software
 * is owned by the Company, and is protected under applicable
 * copyright laws. All rights are reserved. Any use in violation
 * of the foregoing restrictions may subject the user to criminal
 * sanctions under applicable laws, as well as to civil liability
 * for the breach of the terms and conditions of this licence.
 *
 * THIS SOFTWARE IS PROVIDED IN AN “AS IS” CONDITION. NO WARRANTIES,
 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
 * TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
 * PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE COMPANY SHALL NOT,
 * IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
 * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 *
 * Changelog:
 *
 *  date  | by | description
 * -------+----+-----------------------------------------------------
 * 010911 | SK | Created
 * 050911 | BR | Added 10F and 12F compatible I/O functions
 *
 *
 */

#include "PIC_CAL_IO.h"

#ifdef MX_10F_TRIS

	MX_UINT8 tvar = 255;

	void FC_CAL_Port_Out_DDR_10F_x (MX_UINT8 OutMask, MX_UINT8 OutValue)
	{
		tvar = tvar & (~OutMask);
		asm("movf(_tvar),w");
		asm("TRIS 6");

		GPIO = (GPIO & ~OutMask) | (OutValue & OutMask);
	}

	inline MX_UINT8 FC_CAL_Port_In_DDR_10F_x (MX_UINT8 InMask, MX_UINT8 Shift)
	{
		tvar = tvar | InMask;
		asm("movf(_tvar),w");
		asm("TRIS 6");

		return (GPIO & InMask) >> Shift;
	}

#else

	void FC_CAL_Port_Out__x (MX_UINT8* Port, MX_UINT8 OutMask, MX_UINT8 OutValue)
	{
		*Port = (*Port & ~OutMask) | (OutValue & OutMask);
	}


	void FC_CAL_Port_Out_DDR__x (MX_UINT8* Port, MX_UINT8* Tris, MX_UINT8 OutMask, MX_UINT8 OutValue)
	{
		*Tris = *Tris & (~OutMask);
		*Port = (*Port & ~OutMask) | (OutValue & OutMask);
	}


	MX_UINT8 FC_CAL_Port_In__x (MX_UINT8* Port, MX_UINT8 InMask, MX_UINT8 Shift)
	{
		return (*Port & InMask) >> Shift;
	}


	inline MX_UINT8 FC_CAL_Port_In_DDR__x (volatile MX_UINT8* Port,volatile MX_UINT8* Tris, MX_UINT8 InMask, MX_UINT8 Shift)
	{
		*Tris = *Tris | InMask;
		return (*Port & InMask) >> Shift;
	}

#endif

