Files

203 lines
6.5 KiB
C
Raw Permalink Normal View History

2026-03-31 13:10:37 +02:00
/* ###################################################################
** THIS COMPONENT MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
** Filename : Tx1.c
** Project : Landungsbruecke_KDS_v2.0.0
** Processor : MK20DN512VLL10
** Component : RingBuffer
** Version : Component 01.025, Driver 01.00, CPU db: 3.00.000
** Compiler : GNU C Compiler
** Date/Time : 2015-01-09, 16:27, # CodeGen: 0
** Abstract :
** This component implements a ring buffer for different integer data type.
** Settings :
** Component name : Tx1
** Buffer Size : 1
** Contents :
** Clear - void Tx1_Clear(void);
** Put - byte Tx1_Put(Tx1_ElementType elem);
** Get - byte Tx1_Get(Tx1_ElementType *elemP);
** NofElements - Tx1_BufSizeType Tx1_NofElements(void);
** NofFreeElements - Tx1_BufSizeType Tx1_NofFreeElements(void);
** Init - void Tx1_Init(void);
**
** License : Open Source (LGPL)
** Copyright : (c) Copyright Erich Styger, 2014, all rights reserved.
** Web: http://www.mcuoneclipse.com
** This an open source software of an embedded component for Processor Expert.
** This is a free software and is opened for education, research and commercial developments under license policy of following terms:
** * This is a free software and there is NO WARRANTY.
** * No restriction on use. You can use, modify and redistribute it for personal, non-profit or commercial product UNDER YOUR RESPONSIBILITY.
** * Redistributions of source code must retain the above copyright notice.
** ###################################################################*/
/*!
** @file Tx1.c
** @version 01.00
** @brief
** This component implements a ring buffer for different integer data type.
*/
/*!
** @addtogroup Tx1_module Tx1 module documentation
** @{
*/
/* MODULE Tx1. */
#include "Tx1.h"
#if Tx1_IS_REENTRANT
#define Tx1_DEFINE_CRITICAL() CS1_CriticalVariable()
#define Tx1_ENTER_CRITICAL() CS1_EnterCritical()
#define Tx1_EXIT_CRITICAL() CS1_ExitCritical()
#else
#define Tx1_DEFINE_CRITICAL() /* nothing */
#define Tx1_ENTER_CRITICAL() /* nothing */
#define Tx1_EXIT_CRITICAL() /* nothing */
#endif
static Tx1_ElementType Tx1_buffer[Tx1_BUF_SIZE]; /* ring buffer */
static Tx1_BufSizeType Tx1_inIdx; /* input index */
static Tx1_BufSizeType Tx1_outIdx; /* output index */
static Tx1_BufSizeType Tx1_inSize; /* size data in buffer */
/*
** ===================================================================
** Method : Tx1_Put (component RingBuffer)
** Description :
** Puts a new element into the buffer
** Parameters :
** NAME - DESCRIPTION
** elem - New element to be put into the buffer
** Returns :
** --- - Error code
** ===================================================================
*/
byte Tx1_Put(Tx1_ElementType elem)
{
byte res = ERR_OK;
Tx1_DEFINE_CRITICAL();
Tx1_ENTER_CRITICAL();
if(Tx1_inSize==Tx1_BUF_SIZE) {
res = ERR_TXFULL;
} else {
Tx1_buffer[Tx1_inIdx] = elem;
Tx1_inSize++;
Tx1_inIdx++;
if(Tx1_inIdx==Tx1_BUF_SIZE) {
Tx1_inIdx = 0;
}
}
Tx1_EXIT_CRITICAL();
return res;
}
/*
** ===================================================================
** Method : Tx1_Get (component RingBuffer)
** Description :
** Removes an element from the buffer
** Parameters :
** NAME - DESCRIPTION
** * elemP - Pointer to where to store the received
** element
** Returns :
** --- - Error code
** ===================================================================
*/
byte Tx1_Get(Tx1_ElementType *elemP)
{
byte res = ERR_OK;
Tx1_DEFINE_CRITICAL();
Tx1_ENTER_CRITICAL();
if(Tx1_inSize==0) {
res = ERR_RXEMPTY;
} else {
*elemP = Tx1_buffer[Tx1_outIdx];
Tx1_inSize--;
Tx1_outIdx++;
if(Tx1_outIdx==Tx1_BUF_SIZE) {
Tx1_outIdx = 0;
}
}
Tx1_EXIT_CRITICAL();
return res;
}
/*
** ===================================================================
** Method : Tx1_NofElements (component RingBuffer)
** Description :
** Returns the actual number of elements in the buffer.
** Parameters : None
** Returns :
** --- - Number of elements in the buffer.
** ===================================================================
*/
Tx1_BufSizeType Tx1_NofElements(void)
{
return Tx1_inSize;
}
/*
** ===================================================================
** Method : Tx1_NofFreeElements (component RingBuffer)
** Description :
** Returns the actual number of free elements/space in the
** buffer.
** Parameters : None
** Returns :
** --- - Number of elements in the buffer.
** ===================================================================
*/
Tx1_BufSizeType Tx1_NofFreeElements(void)
{
return (Tx1_BufSizeType)(Tx1_BUF_SIZE-Tx1_inSize);
}
/*
** ===================================================================
** Method : Tx1_Init (component RingBuffer)
** Description :
** Initializes the data structure
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void Tx1_Init(void)
{
Tx1_inIdx = 0;
Tx1_outIdx = 0;
Tx1_inSize = 0;
}
/*
** ===================================================================
** Method : Tx1_Clear (component RingBuffer)
** Description :
** Clear (empty) the ring buffer.
** Parameters : None
** Returns : Nothing
** ===================================================================
*/
void Tx1_Clear(void)
{
Tx1_DEFINE_CRITICAL();
Tx1_ENTER_CRITICAL();
Tx1_Init();
Tx1_EXIT_CRITICAL();
}
/* END Tx1. */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.4 [05.11]
** for the Freescale Kinetis series of microcontrollers.
**
** ###################################################################
*/