/****************************************************************************/
/* Copyright 2013 MBARI.                                                    */
/* MBARI Proprietary Information. All rights reserved.                      */
/****************************************************************************/

#include "p24Fxxxx.h"
#include "GenericTypeDefs.h"
#include "port.h"
#include "debug.h"
#include "../sensorNodeMain/serial.h"

#ifdef DEBUG_PORT

void	debugInit(void)
{
    serSetConfig(DEBUG_PORT, 9600, D8_NONE, S_1);
    serXcvrSet(DEBUG_PORT, 1);
    serPutString(DEBUG_PORT, "Debug on\r\n");
}

static void debugPutNibble(UCHAR c)
{
    BYTE nib = c & 0xf;

    serPutByte(DEBUG_PORT, (nib > 9) ? nib + 'A' - 10 : nib + '0');
}

void debugFrame(volatile UCHAR *bufp, USHORT buflen)
{
    int	i;

    serXcvrSet(DEBUG_PORT, 1);

    for (i = 0; i < buflen; i++)
    {
	debugPutNibble((bufp[i] >> 4) & 0xf);
	debugPutNibble(bufp[i] & 0xf);
	serPutByte(DEBUG_PORT, ' ');
    }
}

#endif
