<commit_before>//************************************************************************
//*	HardwareSerial.h
//*
//*	Arduino Library for PIC32
//*		Copyright (c) 2010, 2011 by <NAME>
//************************************************************************
//*	this code is best viewed with tabs set to 4 spaces
//************************************************************************
//*	Edit History
//************************************************************************
//*	Oct 12,	2010	Got MPLAB X working on MacOSX 1.6 for the first time
//*	May 25, 2011	<MLS> Added support for Uart2 on UNO32
//*	Jun 24,	2011	<MLS> Adding USB support fore Serial.xxx
//*	Jun 29,	2011	<MLS> USB support only compiles if enabled
//*	Aug 26,	2011	<MLS> Microchip starter kits w/USB now default to USB serial
//*	Sep  1,	2011	<MLS> Issue #111, #ifdefs around <plib.h>, it was being included twice
//*	Sep  2,	2011	<MLS> Issue #111, changed include <plib.h> to include <p32xxxx.h>
//************************************************************************
/*
  HardwareSerial.h - Hardware serial library for Wiring
  Copyright (c) 2006 <NAME>.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library 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
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef HardwareSerial_h
#define HardwareSerial_h
#define __LANGUAGE_C__

#include <inttypes.h>
#ifndef _P32XXXX_H
	#include <p32xxxx.h>
#endif

#ifdef __cplusplus
	#include "Print.h"
#endif


#if defined(_BOARD_UBW32_MX460_) || defined(_BOARD_UBW32_MX795_)
//	#define _USE_USB_FOR_SERIAL_
#endif
#if defined(_BOARD_CEREBOT_32MX4_) || defined(_BOARD_CEREBOT_32MX7_)
//	#define _USE_USB_FOR_SERIAL_
#endif
#if defined(_BOARD_CUI32_)
//	#define _USE_USB_FOR_SERIAL_
#endif
#if defined(_BOARD_PIC32_ETHERNET_STARTER_KIT_) || defined(_BOARD_PIC32_USB_STARTER_KIT_)
//	#define _USE_USB_FOR_SERIAL_
#endif
#if defined(_BOARD_MIKROE_MIKROMEDIA_)
//	#define _USE_USB_FOR_SERIAL_
#endif



//#undef _UART3A
//#undef _UART3B

//************************************************************************
//*	this defines which serial ports are present
enum 
{
	kSerialPort_dummy	=	0,
#if defined (_UART1) && !defined(_UART1A)
	kSerialPort_1,
#endif

#if defined (_UART1A)
	kSerialPort_1A,
#endif

#if defined (_UART1B)
	kSerialPort_1B,
#endif

#if defined (_UART2) && !defined(_UART2A)
	kSerialPort_2,
#endif

#if defined (_UART2A)
	kSerialPort_2A,
#endif

#if defined (_UART2B)
	kSerialPort_2B,
#endif
	
#if defined (_UART3) && !defined(_UART3A)
	kSerialPort_3,
#endif

#if defined (_UART3A)
	kSerialPort_3A,
#endif

#if defined (_UART3B)
	kSerialPort_3B,
#endif

#if defined (_UART4) 
	kSerialPort_4,
#endif

#if defined (_UART5) 
	kSerialPort_5,
#endif

#if defined (_UART6) 
	kSerialPort_6,
#endif

	kSerialPort_extra

};

#define	kSerialPort_Count	(kSerialPort_extra - 1)

//************************************************************************


// Define constants and variables for buffering incoming serial data.  We're
// using a ring buffer, in which rx_buffer_head is the index of the
// location to which to write the next incoming character and rx_buffer_tail
// is the index of the location from which to read.
#define RX_BUFFER_SIZE 128

typedef struct 
{
	unsigned char buffer[RX_BUFFER_SIZE];
	int head;
	int tail;
} ring_buffer;

#ifdef __cplusplus

//*******************************************************************************************
class HardwareSerial : public Print
{
	private:
		ring_buffer				*_rx_buffer;
		uint8_t					_uartNumber;
		//*	pic32 registers
		volatile uint32_t		*_UxBRG;
		volatile uint32_t		*_UxMODE;
		volatile uint32_t		*_UxSTA;
		volatile uint32_t		*_UxTXREG;

	public:
		HardwareSerial(	uint8_t					uartNumber,
						ring_buffer				*rx_buffer,
						volatile uint32_t		*uxbrg_reg,
						volatile uint32_t		*uxmode_reg,
						volatile uint32_t		*uxsta_reg,
						volatile uint32_t		*uxtxreg_reg
						);

		void	begin(long baudRate);
		void	end();
		int		peek();
		uint8_t	available(void);
		int		read(void);
		void	flush(void);
		virtual	void	write(uint8_t);<commit_msg>Issue #140, HardwareSerial not derived from Stream<commit_after>//************************************************************************
//*	HardwareSerial.h
//*
//*	Arduino Library for PIC32
//*		Copyright (c) 2010, 2011 by <NAME>
//************************************************************************
//*	this code is best viewed with tabs set to 4 spaces
//************************************************************************
//*	Edit History
//************************************************************************
//*	Oct 12,	2010	Got MPLAB X working on MacOSX 1.6 for the first time
//*	May 25, 2011	<MLS> Added support for Uart2 on UNO32
//*	Jun 24,	2011	<MLS> Adding USB support fore Serial.xxx
//*	Jun 29,	2011	<MLS> USB support only compiles if enabled
//*	Aug 26,	2011	<MLS> Microchip starter kits w/USB now default to USB serial
//*	Sep  1,	2011	<MLS> Issue #111, #ifdefs around <plib.h>, it was being included twice
//*	Sep  2,	2011	<MLS> Issue #111, changed include <plib.h> to include <p32xxxx.h>
//*	Nov  1,	2011	<MLS> Issue #140, HardwareSerial not derived from Stream 
//*	Nov  1,	2011	<MLS> Also fixed some other compatibilty issues
//************************************************************************
/*
  HardwareSerial.h - Hardware serial library for Wiring
  Copyright (c) 2006 <NAME>.  All right reserved.

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library 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
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef HardwareSerial_h
#define HardwareSerial_h
#define __LANGUAGE_C__

#include <inttypes.h>
#ifndef _P32XXXX_H
	#include <p32xxxx.h>
#endif

#ifdef __cplusplus
	#include "Print.h"
	#include "Stream.h"
#endif


#if defined(_BOARD_UBW32_MX460_) || defined(_BOARD_UBW32_MX795_)
//	#define _USE_USB_FOR_SERIAL_
#endif
#if defined(_BOARD_CEREBOT_32MX4_) || defined(_BOARD_CEREBOT_32MX7_)
//	#define _USE_USB_FOR_SERIAL_
#endif
#if defined(_BOARD_CUI32_)
//	#define _USE_USB_FOR_SERIAL_
#endif
#if defined(_BOARD_PIC32_ETHERNET_STARTER_KIT_) || defined(_BOARD_PIC32_USB_STARTER_KIT_)
//	#define _USE_USB_FOR_SERIAL_
#endif
#if defined(_BOARD_MIKROE_MIKROMEDIA_)
//	#define _USE_USB_FOR_SERIAL_
#endif



//#undef _UART3A
//#undef _UART3B

//************************************************************************
//*	this defines which serial ports are present
enum 
{
	kSerialPort_dummy	=	0,
#if defined (_UART1) && !defined(_UART1A)
	kSerialPort_1,
#endif

#if defined (_UART1A)
	kSerialPort_1A,
#endif

#if defined (_UART1B)
	kSerialPort_1B,
#endif

#if defined (_UART2) && !defined(_UART2A)
	kSerialPort_2,
#endif

#if defined (_UART2A)
	kSerialPort_2A,
#endif

#if defined (_UART2B)
	kSerialPort_2B,
#endif
	
#if defined (_UART3) && !defined(_UART3A)
	kSerialPort_3,
#endif

#if defined (_UART3A)
	kSerialPort_3A,
#endif

#if defined (_UART3B)
	kSerialPort_3B,
#endif

#if defined (_UART4) 
	kSerialPort_4,
#endif

#if defined (_UART5) 
	kSerialPort_5,
#endif

#if defined (_UART6) 
	kSerialPort_6,
#endif

	kSerialPort_extra

};

#define	kSerialPort_Count	(kSerialPort_extra - 1)

//************************************************************************


// Define constants and variables for buffering incoming serial data.  We're
// using a ring buffer, in which rx_buffer_head is the index of the
// location to which to write the next incoming character and rx_buffer_tail
// is the index of the location from which to read.
#define RX_BUFFER_SIZE 128

typedef struct 
{
	unsigned char buffer[RX_BUFFER_SIZE];
	int head;
	int tail;
} ring_buffer;

#ifdef __cplusplus

//*******************************************************************************************
//class HardwareSerial : public Print
class HardwareSerial : public Stream
{
	private:
		ring_buffer				*_rx_buffer;
		uint8_t					_uartNumber;
		//*	pic32 registers
		volatile uint32_t		*_UxBRG;
		volatile uint32_t		*_UxMODE;
		volatile uint32_t		*_UxSTA;
		volatile uint32_t		*_UxTXREG;

	public:
		HardwareSerial(	uint8_t					uartNumber,
						ring_buffer				*rx_buffer,
						volatile uint32_t		*uxbrg_reg,
						volatile uint32_t		*uxmode_reg,
						volatile uint32_t		*uxsta_reg,
						volatile uint32_t		*uxtxreg_reg
						);

		void	begin(unsigned long baudRate);
		void	end();
		virtual int 	available(void);
		virtual	int		peek();
		virtual	int		read(void);
		virtual	void	flush(void);
		virtual	void	write(uint8_t);
{'fraction_non_alphanumeric': 0.20124031007751939, 'fraction_numerical': 0.03524547803617571, 'mean_word_length': 4.807923169267707, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5206278', 'n_tokens_mistral': 3608, 'n_tokens_neox': 3142, 'n_words': 995}