<commit_before>/*--------------------------------------------------------------------------
File   : serialintrf.h

Author : <NAME>          				Nov. 25, 2011

Desc   : Generic serial data transfer interface class
		 This class is used to implement serial communication interfaces
		 such as I2C, UART, etc...  Not limited to wired or
		 physical interface.  It could be soft interface as well such
		 as SLIP protocol or any mean of transferring data between 2
		 entities.

Copyright (c) 2011, I-SYST inc., all rights reserved

Permission to use, copy, modify, and distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright
notice and this permission notice appear in all copies, and none of the
names : I-SYST or its contributors may be used to endorse or
promote products derived from this software without specific prior written
permission.

For info or contributing contact : hnhoan at i-syst dot com

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

----------------------------------------------------------------------------
Modified by          Date              Description

----------------------------------------------------------------------------*/
#ifndef __SERIALINTRF_H__
#define __SERIALINTRF_H__

#include <stdint.h>
#include <stdbool.h>
#include "atomic.h"

/*
 * Serial interface event types
 */
typedef enum {
	SERINTRF_EVT_RX_TIMEOUT,	// Rx timeout
	SERINTRF_EVT_RXDATA,		// Data received
	SERINTRF_EVT_TX_TIMEOUT,	// Tx timeout
	SERINTRF_EVT_TX_READY,		// Ready to transmit
	SERINTRF_EVT_STATECHG,		// State changed. State data is device dependent.
								// To be interpreted by implementation
} SERINTRF_EVT;

/*
 * Serial Interface forward data structure type definition.
 * This structure is the base object.  Pointer to an instance of this is passed
 * to all function calls.  See structure definition bellow for more details
 */
typedef struct _serialintrf_dev SERINTRFDEV;


/**
 * @brief
 *
 * Event handler callback. This is normally being called within interrupts, avoid blocking
 *
 * @param 	pDev 	: Device handle
 * 			EvtId 	: Event code
 *  		pBuffer : In/Out Buffer containing data
 * 					  on SERINTRF_EVT_RX_TIMEOUT & SERINTRF_EVT_RXDATA, pBuffer contains data received. If
 * 					  driver implements CFIFO, this parameter is NULL with BufferLen indicating total data
 * 					  in fifo.
 * 					  on SERINTRF_EVT_TX_READY, pBuffer contains data to be transmit with max length
 * 					  BufferLen. If driver implements CFIFO, this parameter is NULL and BufferLen
 * 					  indicates amount of data stored in fifo
 * 					  on SERINTRF_EVT_STATECHG, pBuffer contains state data. This is implementation specific
 * 					  for example UART implementation would contains line state info.
 *
 * 			BufferLen : Max buffer length.  See above description
 *
 * @return number of bytes processed.  Implementation specific
 */
typedef int (*SERINTRFEVCB)(SERINTRFDEV *pDev, SERINTRF_EVT EvtId, uint8_t *pBuffer, int BufferLen);

#pragma pack(push, 4)

/*
 * Serial interface data structure.  This structure is the actual interface for both C++ & C code
 * It is used to provide C compatibility instead of using C++ interface which is only for C++
 */
struct _serialintrf_dev {
	void *pDevData;			// Private device interface implementation data
	int	IntPrio;			// Interrupt priority.  Value is implementation specific
	SERINTRFEVCB EvtCB;		// Interrupt based event callback function pointer. Must be set to NULL if not used
	volatile bool Busy;		// Busy flag to be set check and set at start and reset at end of transmission

	// Bellow are all mandatory functions to implement
	// On init, all implementation must fill these function, no NULL allowed<commit_msg>Add FIFO_FULL events<commit_after>/*--------------------------------------------------------------------------
File   : serialintrf.h

Author : <NAME>          				Nov. 25, 2011

Desc   : Generic serial data transfer interface class
		 This class is used to implement serial communication interfaces
		 such as I2C, UART, etc...  Not limited to wired or
		 physical interface.  It could be soft interface as well such
		 as SLIP protocol or any mean of transferring data between 2
		 entities.

Copyright (c) 2011, I-SYST inc., all rights reserved

Permission to use, copy, modify, and distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright
notice and this permission notice appear in all copies, and none of the
names : I-SYST or its contributors may be used to endorse or
promote products derived from this software without specific prior written
permission.

For info or contributing contact : hnhoan at i-syst dot com

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

----------------------------------------------------------------------------
Modified by          Date              Description

----------------------------------------------------------------------------*/
#ifndef __SERIALINTRF_H__
#define __SERIALINTRF_H__

#include <stdint.h>
#include <stdbool.h>
#include "atomic.h"

/*
 * Serial interface event types
 */
typedef enum {
	SERINTRF_EVT_RX_TIMEOUT,    // Rx timeout
	SERINTRF_EVT_RX_DATA,       // Data received
	SERINTRF_EVT_RX_FIFO_FULL,  // Receive fifo full, fifo will be pushed out
                                // if handler does not process fifo (returns 0)
	SERINTRF_EVT_TX_TIMEOUT,    // Tx timeout
	SERINTRF_EVT_TX_READY,      // Ready to transmit
	SERINTRF_EVT_TX_FIFO_FULL,  // Transmit fifo full, fifo will be pushed out
                                // if handler does not process fifo (returns 0)
	SERINTRF_EVT_STATECHG,      // State changed. State data is device dependent.
                                // To be interpreted by implementation
} SERINTRF_EVT;

/*
 * Serial Interface forward data structure type definition.
 * This structure is the base object.  Pointer to an instance of this is passed
 * to all function calls.  See structure definition bellow for more details
 */
typedef struct _serialintrf_dev SERINTRFDEV;


/**
 * @brief
 *
 * Event handler callback. This is normally being called within interrupts, avoid blocking
 *
 * @param 	pDev 	: Device handle
 * 			EvtId 	: Event code
 *  		pBuffer : In/Out Buffer containing data
 * 					  on SERINTRF_EVT_RX_TIMEOUT & SERINTRF_EVT_RXDATA, pBuffer contains data received. If
 * 					  driver implements CFIFO, this parameter is NULL with BufferLen indicating total data
 * 					  in fifo.
 * 					  on SERINTRF_EVT_TX_READY, pBuffer contains data to be transmit with max length
 * 					  BufferLen. If driver implements CFIFO, this parameter is NULL and BufferLen
 * 					  indicates amount of data stored in fifo
 * 					  on SERINTRF_EVT_STATECHG, pBuffer contains state data. This is implementation specific
 * 					  for example UART implementation would contains line state info.
 *
 * 			BufferLen : Max buffer length.  See above description
 *
 * @return number of bytes processed.  Implementation specific
 *         in case of FIFO_FULL events,  fifo will be pushed out if return value is zero
 */
typedef int (*SERINTRFEVCB)(SERINTRFDEV *pDev, SERINTRF_EVT EvtId, uint8_t *pBuffer, int BufferLen);

#pragma pack(push, 4)

/*
 * Serial interface data structure.  This structure is the actual interface for both C++ & C code
 * It is used to provide C compatibility instead of using C++ interface which is only for C++
 */
struct _serialintrf_dev {
	void *pDevData;			// Private device interface implementation data
	int	IntPrio;			// Interrupt priority.  Value is implementation specific
	SERINTRFEVCB EvtCB;		// Interrupt based event callback function pointer. Must be set to NULL if not used
	volatile bool Busy;		// Busy flag to be set check and set at start and reset at end of transmission

	// Bellow are all mandatory functions to implement
	// On init, all implementation must fill these function, no NULL allowed
{'fraction_non_alphanumeric': 0.09658421672555949, 'fraction_numerical': 0.0032123353678123997, 'mean_word_length': 2.8787375415282392, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4400964', 'n_tokens_mistral': 2693, 'n_tokens_neox': 2418, 'n_words': 1158}