Skip to content

Commit

Permalink
Submission of UartFramer component (#1261)
Browse files Browse the repository at this point in the history
* Changed PrmBuffer m_data to m_bufferData for VxWorks

* More m_data instances

* VxWorks and virtual destructors

* Added Vxworks fatal handler compile

* Fixed active component schematron

* Changed ActiveTextLogger to use Fw::Logger to avoid VxWorks mushing of output

* Importing TlmPacketizer

* fix(BufferManager): size checking logic and assert cleanup

* fix: change U64 to POINTER_CAST

* TlmPacketizer unit tests pass

* Adding codegen for packets

* More work on packet generator

* Fixing generated pathnames

* Fixes to topology for TlmPacketizer and TlmPacketizer name updates

* Typo

* Fix TlmPacketizer unit tests after name change

* Additional fixes to packet telemetry script and packet contents

* ran tlm_packet_gen.py through black formatter

* Added spellcheck words

* Added join() for pktTlm

* Fix to ai_parser.py formatting

* More spell check exclusions

* Updated headers and const

* Code copied in

* Starting on SDD

* new image path

* More SDD

* SDD done

* Unit tests complete

* sdd typo

Co-authored-by: Kyle Botteon <botteon@jpl.nasa.gov>
  • Loading branch information
timcanham and Kyle Botteon authored Feb 8, 2022
1 parent 5bab3f2 commit 72bc851
Show file tree
Hide file tree
Showing 16 changed files with 2,086 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/excludes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ignore$
\.xls$
\.xlsx$
\.xsd$
\.vsdx$
^Autocoders/Python/test/.*\.xml$
^Autocoders/Python/test/param1/test/ut/Tester\.hpp$
^config/PolyDbImplCfg\.hpp$
Expand Down
1 change: 1 addition & 0 deletions Drv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LinuxGpioDriver/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LinuxSerialDriver/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LinuxSpiDriver/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/LinuxI2cDriver/")
add_fprime_subdirectory("${CMAKE_CURRENT_LIST_DIR}/UartFramer/")

# IP Socket is only supported for Linux, Darwin, VxWorks
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux" OR ${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" OR ${CMAKE_SYSTEM_NAME} STREQUAL "VxWorks")
Expand Down
26 changes: 26 additions & 0 deletions Drv/UartFramer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
####
# F prime CMakeLists.txt:
#
# SOURCE_FILES: combined list of source and autocoding diles
# MOD_DEPS: (optional) module dependencies
#
####
set(MOD_DEPS Os)

set(SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/UartFramer.fpp"
"${CMAKE_CURRENT_LIST_DIR}/UartFramer.cpp"
)
register_fprime_module()

## UTs ###
# Note: this UT expects user input
set(UT_MOD_DEPS
Os
)
set(UT_SOURCE_FILES
"${CMAKE_CURRENT_LIST_DIR}/UartFramer.fpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/TestMain.cpp"
"${CMAKE_CURRENT_LIST_DIR}/test/ut/Tester.cpp"
)
register_fprime_ut()
106 changes: 106 additions & 0 deletions Drv/UartFramer/UartFramer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
// ======================================================================
// \title UartFramer.cpp
// \author tcanham
// \brief cpp file for UartFramer component implementation class
//
// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================


#include <Drv/UartFramer/UartFramer.hpp>
#include "Fw/Types/BasicTypes.hpp"
#include "Fw/Types/Assert.hpp"

namespace Drv {

// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------

UartFramer ::
UartFramer(
const char *const compName
) : UartFramerComponentBase(compName), m_size(0)
{

}

void UartFramer ::
init(
const NATIVE_INT_TYPE instance
)
{
UartFramerComponentBase::init(instance);
}

UartFramer ::
~UartFramer()
{

}

void UartFramer::allocate(NATIVE_UINT_TYPE number, NATIVE_UINT_TYPE size) {

FW_ASSERT(size > 0, size);
this->m_size = size;

Fw::Buffer buff;
// request a buffer and pass it on to the UART for each requested
for (NATIVE_UINT_TYPE buffNum = 0; buffNum < number; buffNum++) {
buff = this->DeframerAllocate_out(0,this->m_size);
FW_ASSERT(buff.getSize() == size,buff.getSize(),size);
FW_ASSERT(buff.getData());
this->readBufferSend_out(0,buff);
}

}

// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

Drv::SendStatus UartFramer ::
Framer_handler(
const NATIVE_INT_TYPE portNum,
Fw::Buffer &sendBuffer
)
{
this->serialSend_out(0,sendBuffer);
this->FramerDeallocate_out(0,sendBuffer);
// no status from send, so return OK
return Drv::SendStatus::SEND_OK;
}

void UartFramer ::
serialRecv_handler(
const NATIVE_INT_TYPE portNum,
Fw::Buffer &serBuffer,
Drv::SerialReadStatus &status
)
{

Drv::RecvStatus outStat = Drv::RecvStatus::RECV_OK;
// Check the UART status
if (status != Drv::SerialReadStatus::SER_OK) {
outStat = Drv::RecvStatus::RECV_ERROR;
}

// Forward buffer to deframer
this->Deframer_out(0,serBuffer,outStat);

// allocate a replacement buffer and send it to
// the UART driver
Fw::Buffer newBuff = this->DeframerAllocate_out(0,this->m_size);
if (newBuff.getSize() != this->m_size) {
this->log_WARNING_HI_BuffErr();
} else {
this->readBufferSend_out(0,newBuff);
}

}

} // end namespace Drv
62 changes: 62 additions & 0 deletions Drv/UartFramer/UartFramer.fpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
module Drv {

passive component UartFramer {

# ----------------------------------------------------------------------
# Ports for UART
# ----------------------------------------------------------------------

@ port to send a buffer for reads to the UART driver
output port readBufferSend: Fw.BufferSend

@ send a UART buffer
output port serialSend: Drv.SerialWrite

@ receive a buffer from the UART - one of the above
sync input port serialRecv: Drv.SerialRead

# ----------------------------------------------------------------------
# Ports for Framer/Deframer
# ----------------------------------------------------------------------

@ Buffer from Framer
sync input port Framer: Drv.ByteStreamSend

@ Buffer to Deframer
output port Deframer: Drv.ByteStreamRecv

# ----------------------------------------------------------------------
# Ports to get buffers
# ----------------------------------------------------------------------

@ Allocation output port - will be sent to Deframer for deallocation
output port DeframerAllocate: Fw.BufferGet

@ Deallocation output port - deallocation of Framer buffers
output port FramerDeallocate: Fw.BufferSend


# ----------------------------------------------------------------------
# Special F Prime ports
# ----------------------------------------------------------------------

event port Log

text event port LogText

time get port Time

# ----------------------------------------------------------------------
# Events
# ----------------------------------------------------------------------

@ UART open error
event BuffErr() \
severity warning high \
id 0 \
format "Couldn't get UART buffer" \
throttle 5

}

}
86 changes: 86 additions & 0 deletions Drv/UartFramer/UartFramer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// ======================================================================
// \title UartFramer.hpp
// \author tcanham
// \brief hpp file for UartFramer component implementation class
//
// \copyright
// Copyright 2009-2015, by the California Institute of Technology.
// ALL RIGHTS RESERVED. United States Government Sponsorship
// acknowledged.
//
// ======================================================================

#ifndef UartFramer_HPP
#define UartFramer_HPP

#include "Drv/UartFramer/UartFramerComponentAc.hpp"

namespace Drv {

class UartFramer :
public UartFramerComponentBase
{

public:

// ----------------------------------------------------------------------
// Construction, initialization, and destruction
// ----------------------------------------------------------------------

//! Construct object UartFramer
//!
UartFramer(
const char *const compName /*!< The component name*/
);

//! Initialize object UartFramer
//!
void init(
const NATIVE_INT_TYPE instance = 0 /*!< The instance number*/
);

//! Destroy object UartFramer
//!
~UartFramer();


//! Allocate pool of buffers for UART receive - BufferManager and UART
// instances must be connected and ready. BufferManager should have at least
// number+1 buffers allocated
void allocate(NATIVE_UINT_TYPE number, NATIVE_UINT_TYPE size);

PRIVATE:

// ----------------------------------------------------------------------
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

//! Handler implementation for Framer
//!
Drv::SendStatus Framer_handler(
const NATIVE_INT_TYPE portNum, /*!< The port number*/
Fw::Buffer &sendBuffer
);

//! Handler implementation for serialRecv
//!
void serialRecv_handler(
const NATIVE_INT_TYPE portNum, /*!< The port number*/
Fw::Buffer &serBuffer, /*!<
Buffer containing data
*/
Drv::SerialReadStatus &status /*!<
Status of read
*/
);

// Private data members

NATIVE_UINT_TYPE m_size; //!< size of UART buffers


};

} // end namespace Drv

#endif
Binary file added Drv/UartFramer/docs/UartFramer.vsdx
Binary file not shown.
Loading

0 comments on commit 72bc851

Please sign in to comment.