Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: azonenberg/starshipraider
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 103378d6fd9f
Choose a base ref
...
head repository: azonenberg/starshipraider
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 6b7d6eb21134
Choose a head ref
  • 1 commit
  • 12 files changed
  • 1 contributor

Commits on Apr 18, 2020

  1. Copy the full SHA
    6b7d6eb View commit details
117 changes: 117 additions & 0 deletions firmware/BLONDEL/afe-characterization/CharacterDevice.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/***********************************************************************************************************************
* *
* STARSHIPRAIDER v0.1 *
* *
* Copyright (c) 2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "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 AUTHORS BE HELD 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. *
* *
***********************************************************************************************************************/

#ifndef characterdevice_h
#define characterdevice_h

#include "FIFO.h"

/**
@file
@author Andrew D. Zonenberg
@brief Abstract character device base class
*/
class CharacterDevice
{
public:
CharacterDevice()
{}

//Overrides
virtual void PrintBinary(char ch) =0;

//Convenience wrappers
public:
void PrintText(char ch)
{
if(ch == '\n')
PrintBinary('\r');
PrintBinary(ch);
}

void Write16(uint16_t n)
{ Write((const char*)&n, 2); }

void Write32(uint32_t n)
{ Write((const char*)&n, 4); }

uint32_t BlockingRead32()
{
uint32_t tmp;
BlockingRead((char*)&tmp, 4);
return tmp;
}

uint16_t BlockingRead16()
{
uint16_t tmp;
BlockingRead((char*)&tmp, 2);
return tmp;
}

bool HasInput()
{ return !m_rxFifo.IsEmpty(); }


char BlockingRead()
{
//block until at least one byte is ready
while(m_rxFifo.IsEmpty())
{}

return m_rxFifo.Pop();
}

void BlockingRead(char* data, uint32_t len)
{
for(uint32_t i=0; i<len; i++)
data[i] = BlockingRead();
}

void Write(const char* data, uint32_t len)
{
for(uint32_t i=0; i<len; i++)
PrintBinary(data[i]);
}

void PrintString(const char* str)
{
while(*str)
PrintText(*(str++));
}

//Interrupt handlers
void OnIRQRxData(char ch)
{ m_rxFifo.Push(ch); }

protected:
FIFO<char, 32> m_rxFifo;
};

#endif
142 changes: 142 additions & 0 deletions firmware/BLONDEL/afe-characterization/FIFO.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/***********************************************************************************************************************
* *
* STARSHIPRAIDER v0.1 *
* *
* Copyright (c) 2020 Andrew D. Zonenberg *
* All rights reserved. *
* *
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the *
* following conditions are met: *
* *
* * Redistributions of source code must retain the above copyright notice, this list of conditions, and the *
* following disclaimer. *
* *
* * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the *
* following disclaimer in the documentation and/or other materials provided with the distribution. *
* *
* * Neither the name of the author nor the names of any contributors may be used to endorse or promote products *
* derived from this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE AUTHORS "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 AUTHORS BE HELD 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. *
* *
***********************************************************************************************************************/

#ifndef fifo_h
#define fifo_h

/**
@file
@author Andrew D. Zonenberg
@brief Declaration of Fifo class
*/

/**
@brief A circular buffer based FIFO interlocked for safe use across interrupt domains
*/
template<class objtype, uint32_t depth>
class FIFO
{
public:

/**
@brief Creates a new FIFO
*/
FIFO()
: m_wptr(0)
, m_rptr(0)
, m_empty(true)
{}

/**
@brief Adds a new item to the FIFO.
Pushing when the FIFO is full is a legal no-op.
*/
void Push(objtype item)
{
uint32_t sr = EnterCriticalSection();

if(!InternalIsFull())
{
m_storage[m_wptr] = item;
m_wptr ++;
m_empty = false;
}

if(m_wptr == depth)
m_wptr = 0;

LeaveCriticalSection(sr);
}

/**
@brief Removes an item from the FIFO and returns it.
Popping an empty FIFO is a legal no-op with an undefined return value.
*/
objtype Pop()
{
uint32_t sr = EnterCriticalSection();

objtype ret = m_storage[m_rptr];

if(!IsEmpty())
{
m_rptr ++;

if(m_rptr == depth)
m_rptr = 0;

if(m_rptr == m_wptr)
m_empty = true;
}

LeaveCriticalSection(sr);

return ret;
}

/**
@brief Checks if the FIFO is empty
*/
bool IsEmpty()
{
return m_empty;
}

/**
@brief Checks if the FIFO is full
*/
bool IsFull()
{
uint32_t sr = EnterCriticalSection();
bool full = InternalIsFull();
LeaveCriticalSection(sr);
return full;
}

protected:

/**
@brief Checks if the FIFO is full without any interlocks.
*/
bool InternalIsFull()
{
if(m_empty)
return false;
return (m_wptr == m_rptr);
}

objtype m_storage[depth];
uint32_t m_wptr;
uint32_t m_rptr;
bool m_empty;
};

#endif
2 changes: 1 addition & 1 deletion firmware/BLONDEL/afe-characterization/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CFLAGS=-g -mcpu=cortex-m0
CXXFLAGS=$(CFLAGS) --std=c++17 -fno-exceptions -fno-rtti -g
CXXFLAGS=$(CFLAGS) --std=c++17 -fno-exceptions -fno-rtti -g --specs=nano.specs
CC=arm-none-eabi-gcc
CXX=arm-none-eabi-g++
all:
Loading