1
0
forked from fsfw/fsfw

updating code from Flying Laptop

This is the framework of Flying Laptop OBSW version A.13.0.
This commit is contained in:
2018-07-12 16:29:32 +02:00
parent 1d22a6c97e
commit 575f70ba03
395 changed files with 12807 additions and 8404 deletions

View File

@ -1,10 +1,3 @@
/*
* LocalPool.h
*
* Created on: 11.02.2015
* Author: baetz
*/
#ifndef FRAMEWORK_STORAGEMANAGER_LOCALPOOL_H_
#define FRAMEWORK_STORAGEMANAGER_LOCALPOOL_H_
@ -20,9 +13,9 @@
#include <framework/objectmanager/SystemObject.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/storagemanager/StorageManagerIF.h>
#include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/internalError/InternalErrorReporterIF.h>
#include <string.h>
//TODO: Debugging.. remove!
//#include <config/objects/translateObjects.h>
/**
* @brief The LocalPool class provides an intermediate data storage with
@ -118,22 +111,6 @@ private:
* @return Returns the position of the data in store.
*/
uint32_t getRawPosition(store_address_t packet_id);
/**
* With this helper method, a free element of \c size is reserved.
*
* @param size The minimum packet size that shall be reserved.
* @return Returns the storage identifier within the storage or
* StorageManagerIF::INVALID_ADDRESS (in raw).
*/
/**
* With this helper method, a free element of \c size is reserved.
* @param size The minimum packet size that shall be reserved.
* @param[out] address Storage ID of the reserved data.
* @return - #RETURN_OK on success,
* - the return codes of #getPoolIndex or #findEmpty otherwise.
*/
ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address);
protected:
/**
* @brief This is a helper method to find an empty element in a given pool.
* @details The method searches size_list for the first empty element, so
@ -143,7 +120,18 @@ protected:
* @return - #RETURN_OK on success,
* - #DATA_STORAGE_FULL if the store is full
*/
virtual ReturnValue_t findEmpty(uint16_t pool_index, uint16_t* element);
ReturnValue_t findEmpty(uint16_t pool_index, uint16_t* element);
protected:
/**
* With this helper method, a free element of \c size is reserved.
* @param size The minimum packet size that shall be reserved.
* @param[out] address Storage ID of the reserved data.
* @return - #RETURN_OK on success,
* - the return codes of #getPoolIndex or #findEmpty otherwise.
*/
virtual ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address, bool ignoreFault);
InternalErrorReporterIF *internalErrorReporter;
public:
/**
* @brief This is the default constructor for a pool manager instance.
@ -172,10 +160,17 @@ public:
*/
virtual ~LocalPool(void);
ReturnValue_t addData(store_address_t* storageId, const uint8_t * data,
uint32_t size);
uint32_t size, bool ignoreFault = false);
/**
* With this helper method, a free element of \c size is reserved.
*
* @param size The minimum packet size that shall be reserved.
* @return Returns the storage identifier within the storage or
* StorageManagerIF::INVALID_ADDRESS (in raw).
*/
ReturnValue_t getFreeElement(store_address_t* storageId,
const uint32_t size, uint8_t** p_data);
const uint32_t size, uint8_t** p_data, bool ignoreFault = false);
ReturnValue_t getData(store_address_t packet_id, const uint8_t** packet_ptr,
uint32_t* size);
ReturnValue_t modifyData(store_address_t packet_id, uint8_t** packet_ptr,
@ -245,11 +240,12 @@ inline uint32_t LocalPool<NUMBER_OF_POOLS>::getRawPosition(
template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::reserveSpace(
const uint32_t size, store_address_t* address) {
const uint32_t size, store_address_t* address, bool ignoreFault) {
ReturnValue_t status = getPoolIndex(size, &address->pool_index);
if (status != RETURN_OK) {
error << "LocalPool( " << std::hex << getObjectId() << std::dec
<< " )::reserveSpace: Packet too large." << std::endl;
return status;
}
status = findEmpty(address->pool_index, &address->packet_index);
while (status != RETURN_OK && spillsToHigherPools) {
@ -261,11 +257,17 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::reserveSpace(
status = findEmpty(address->pool_index, &address->packet_index);
}
if (status == RETURN_OK) {
// debug << "LocalPool( " << translateObject(getObjectId()) << " )::reserveSpace: Empty position found: Position: Pool: " << address->pool_index << " Index: " << address->packet_index << std::endl;
// if (getObjectId() == objects::IPC_STORE && address->pool_index >= 3) {
// debug << "Reserve: Pool: " << std::dec << address->pool_index << " Index: " << address->packet_index << std::endl;
// }
size_list[address->pool_index][address->packet_index] = size;
} else {
error << "LocalPool( " << std::hex << getObjectId() << std::dec
<< " )::reserveSpace: Packet store is full." << std::endl;
if (!ignoreFault) {
internalErrorReporter->storeFull();
}
// error << "LocalPool( " << std::hex << getObjectId() << std::dec
// << " )::reserveSpace: Packet store is full." << std::endl;
}
return status;
}
@ -274,7 +276,7 @@ template<uint8_t NUMBER_OF_POOLS>
inline LocalPool<NUMBER_OF_POOLS>::LocalPool(object_id_t setObjectId,
const uint16_t element_sizes[NUMBER_OF_POOLS],
const uint16_t n_elements[NUMBER_OF_POOLS], bool registered, bool spillsToHigherPools) :
SystemObject(setObjectId, registered), spillsToHigherPools(spillsToHigherPools) {
SystemObject(setObjectId, registered), spillsToHigherPools(spillsToHigherPools), internalErrorReporter(NULL) {
for (uint16_t n = 0; n < NUMBER_OF_POOLS; n++) {
this->element_sizes[n] = element_sizes[n];
this->n_elements[n] = n_elements[n];
@ -295,8 +297,8 @@ inline LocalPool<NUMBER_OF_POOLS>::~LocalPool(void) {
template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::addData(
store_address_t* storageId, const uint8_t* data, uint32_t size) {
ReturnValue_t status = reserveSpace(size, storageId);
store_address_t* storageId, const uint8_t* data, uint32_t size, bool ignoreFault) {
ReturnValue_t status = reserveSpace(size, storageId, ignoreFault);
if (status == RETURN_OK) {
write(*storageId, data, size);
}
@ -305,8 +307,8 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::addData(
template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::getFreeElement(
store_address_t* storageId, const uint32_t size, uint8_t** p_data) {
ReturnValue_t status = reserveSpace(size, storageId);
store_address_t* storageId, const uint32_t size, uint8_t** p_data, bool ignoreFault) {
ReturnValue_t status = reserveSpace(size, storageId, ignoreFault);
if (status == RETURN_OK) {
*p_data = &store[storageId->pool_index][getRawPosition(*storageId)];
} else {
@ -328,19 +330,20 @@ template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::modifyData(store_address_t packet_id,
uint8_t** packet_ptr, uint32_t* size) {
ReturnValue_t status = RETURN_FAILED;
if ((packet_id.packet_index < n_elements[packet_id.pool_index])
&& (packet_id.pool_index < NUMBER_OF_POOLS)) {
if (size_list[packet_id.pool_index][packet_id.packet_index]
!= STORAGE_FREE) {
uint32_t packet_position = getRawPosition(packet_id);
*packet_ptr = &store[packet_id.pool_index][packet_position];
*size = size_list[packet_id.pool_index][packet_id.packet_index];
status = RETURN_OK;
} else {
status = DATA_DOES_NOT_EXIST;
}
if (packet_id.pool_index >= NUMBER_OF_POOLS) {
return ILLEGAL_STORAGE_ID;
}
if ((packet_id.packet_index >= n_elements[packet_id.pool_index])) {
return ILLEGAL_STORAGE_ID;
}
if (size_list[packet_id.pool_index][packet_id.packet_index]
!= STORAGE_FREE) {
uint32_t packet_position = getRawPosition(packet_id);
*packet_ptr = &store[packet_id.pool_index][packet_position];
*size = size_list[packet_id.pool_index][packet_id.packet_index];
status = RETURN_OK;
} else {
status = ILLEGAL_STORAGE_ID;
status = DATA_DOES_NOT_EXIST;
}
return status;
}
@ -348,7 +351,10 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::modifyData(store_address_t pack
template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::deleteData(
store_address_t packet_id) {
// debug << "LocalPool( " << translateObject(getObjectId()) << " )::deleteData from store " << packet_id.pool_index << ". id is " << packet_id.packet_index << std::endl;
// if (getObjectId() == objects::IPC_STORE && packet_id.pool_index >= 3) {
// debug << "Delete: Pool: " << std::dec << packet_id.pool_index << " Index: " << packet_id.packet_index << std::endl;
// }
ReturnValue_t status = RETURN_OK;
uint32_t page_size = getPageSize(packet_id.pool_index);
if ((page_size != 0)
@ -359,7 +365,7 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::deleteData(
//Set free list
size_list[packet_id.pool_index][packet_id.packet_index] = STORAGE_FREE;
} else {
//packet_index is too large
//pool_index or packet_index is too large
error << "LocalPool:deleteData failed." << std::endl;
status = ILLEGAL_STORAGE_ID;
}
@ -382,7 +388,7 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::deleteData(uint8_t* ptr,
//Not sure if new allocates all stores in order. so better be careful.
if ((store[n] <= ptr) && (&store[n][n_elements[n]*element_sizes[n]]) > ptr) {
localId.pool_index = n;
uint32_t deltaAddress = (uint32_t) ptr - (uint32_t) store[n];
uint32_t deltaAddress = ptr - store[n];
//Getting any data from the right "block" is ok. This is necessary, as IF's sometimes don't point to the first element of an object.
localId.packet_index = deltaAddress / element_sizes[n];
result = deleteData(localId);
@ -404,6 +410,11 @@ inline ReturnValue_t LocalPool<NUMBER_OF_POOLS>::initialize() {
if (result != RETURN_OK) {
return result;
}
internalErrorReporter = objectManager->get<InternalErrorReporterIF>(objects::INTERNAL_ERROR_REPORTER);
if (internalErrorReporter == NULL){
return RETURN_FAILED;
}
//Check if any pool size is large than the maximum allowed.
for (uint8_t count = 0; count < NUMBER_OF_POOLS; count++) {
if (element_sizes[count] >= STORAGE_FREE) {

View File

@ -1,22 +0,0 @@
#!/bin/bash
#
# OSAL makefile
#
# Created on: Mar 04, 2010
# Author: ziemke
# Author: Claas Ziemke
# Copyright 2010, Claas Ziemke <claas.ziemke@gmx.net>
#
BASEDIR=../../
include $(BASEDIR)options.mk
OBJ = $(BUILDDIR)/TmTcStorage.o
all: $(OBJ)
$(BUILDDIR)/%.o: %.cpp %.h
$(CPP) $(CFLAGS) $(DEFINES) $(CCOPT) ${INCLUDE} -c $< -o $@
clean:
$(RM) *.o *.gcno *.gcda

View File

@ -11,8 +11,9 @@
#define POOLMANAGER_H_
#include <framework/osal/OSAL.h>
#include <framework/storagemanager/LocalPool.h>
#include <framework/ipc/MutexIF.h>
#include <framework/ipc/MutexFactory.h>
/**
* @brief The PoolManager class provides an intermediate data storage with
@ -27,12 +28,13 @@ protected:
* Overwritten for thread safety.
* Locks during execution.
*/
ReturnValue_t findEmpty( uint16_t pool_index, uint16_t* element );
virtual ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address, bool ignoreFault);
/**
* \brief The mutex is created in the constructor and makes access mutual exclusive.
* \details Locking and unlocking is done during searching for free slots and deleting existing slots.
*/
MutexId_t* mutex;
MutexIF* mutex;
public:
PoolManager( object_id_t setObjectId, const uint16_t element_sizes[NUMBER_OF_POOLS], const uint16_t n_elements[NUMBER_OF_POOLS] );
/**
@ -47,16 +49,15 @@ public:
};
template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::findEmpty(uint16_t pool_index,
uint16_t* element) {
ReturnValue_t mutexStatus = OSAL::lockMutex( mutex, OSAL::NO_TIMEOUT );
inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::reserveSpace(const uint32_t size, store_address_t* address, bool ignoreFault) {
ReturnValue_t mutexStatus = mutex->lockMutex(MutexIF::NO_TIMEOUT);
ReturnValue_t status = this->DATA_STORAGE_FULL;
if ( mutexStatus == this->RETURN_OK ) {
status = LocalPool<NUMBER_OF_POOLS>::findEmpty(pool_index, element);
status = LocalPool<NUMBER_OF_POOLS>::reserveSpace(size,address,ignoreFault);
} else {
error << "PoolManager::findEmpty: Mutex could not be acquired. Error code: " << status << std::endl;
error << "PoolManager::findEmpty: Mutex could not be acquired. Error code: " << mutexStatus << std::endl;
}
mutexStatus = OSAL::unlockMutex( mutex );
mutexStatus = mutex->lockMutex(MutexIF::NO_TIMEOUT);
if (mutexStatus != this->RETURN_OK) {
return mutexStatus;
} else {
@ -68,31 +69,26 @@ template<uint8_t NUMBER_OF_POOLS>
inline PoolManager<NUMBER_OF_POOLS>::PoolManager(object_id_t setObjectId,
const uint16_t element_sizes[NUMBER_OF_POOLS],
const uint16_t n_elements[NUMBER_OF_POOLS]) : LocalPool<NUMBER_OF_POOLS>(setObjectId, element_sizes, n_elements, true) {
mutex = new MutexId_t;
ReturnValue_t result = OSAL::createMutex( OSAL::buildName('M','T','X','1'), ( mutex ) );
if (result != this->RETURN_OK) {
error << "PoolManager( " << std::hex << this->getObjectId() << std::dec << " )::ctor: Creating mutex failed." << std::endl;
}
mutex = MutexFactory::instance()->createMutex();
}
template<uint8_t NUMBER_OF_POOLS>
inline PoolManager<NUMBER_OF_POOLS>::~PoolManager(void) {
OSAL::deleteMutex( mutex );
delete mutex;
MutexFactory::instance()->deleteMutex(mutex);
}
template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(
store_address_t packet_id) {
// debug << "PoolManager( " << translateObject(getObjectId()) << " )::deleteData from store " << packet_id.pool_index << ". id is " << packet_id.packet_index << std::endl;
ReturnValue_t mutexStatus = OSAL::lockMutex( mutex, OSAL::NO_TIMEOUT );
ReturnValue_t mutexStatus = mutex->lockMutex(MutexIF::NO_TIMEOUT);
ReturnValue_t status = this->RETURN_OK;
if ( mutexStatus == this->RETURN_OK ) {
LocalPool<NUMBER_OF_POOLS>::deleteData(packet_id);
} else {
error << "PoolManager:deleteData: Mutex could not be acquired. Error code: " << status << std::endl;
}
mutexStatus = OSAL::unlockMutex( mutex );
mutexStatus = mutex->lockMutex(MutexIF::NO_TIMEOUT);
if (mutexStatus != this->RETURN_OK) {
return mutexStatus;
} else {
@ -103,14 +99,14 @@ inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(
template<uint8_t NUMBER_OF_POOLS>
inline ReturnValue_t PoolManager<NUMBER_OF_POOLS>::deleteData(uint8_t* buffer, uint32_t size,
store_address_t* storeId) {
ReturnValue_t mutexStatus = OSAL::lockMutex( mutex, OSAL::NO_TIMEOUT );
ReturnValue_t mutexStatus = mutex->lockMutex(MutexIF::NO_TIMEOUT);
ReturnValue_t status = this->RETURN_OK;
if ( mutexStatus == this->RETURN_OK ) {
LocalPool<NUMBER_OF_POOLS>::deleteData(buffer, size, storeId);
} else {
error << "PoolManager:deleteData: Mutex could not be acquired. Error code: " << status << std::endl;
}
mutexStatus = OSAL::unlockMutex( mutex );
mutexStatus = mutex->lockMutex(MutexIF::NO_TIMEOUT);
if (mutexStatus != this->RETURN_OK) {
return mutexStatus;
} else {

View File

@ -5,8 +5,6 @@
#include <framework/returnvalues/HasReturnvaluesIF.h>
#include <stddef.h>
//TODO: Check setting and returning of store sizes.
/**
* This union defines the type that identifies where a data packet is stored in the store.
* It comprises of a raw part to read it as raw value and a structured part to use it in
@ -67,7 +65,7 @@ union store_address_t {
*/
class StorageManagerIF : public HasReturnvaluesIF {
public:
static const uint8_t INTERFACE_ID = STORAGE_MANAGER_IF; //!< The unique ID for return codes for this interface.
static const uint8_t INTERFACE_ID = CLASS_ID::STORAGE_MANAGER_IF; //!< The unique ID for return codes for this interface.
static const ReturnValue_t DATA_TOO_LARGE = MAKE_RETURN_CODE(1); //!< This return code indicates that the data to be stored is too large for the store.
static const ReturnValue_t DATA_STORAGE_FULL = MAKE_RETURN_CODE(2); //!< This return code indicates that a data storage is full.
static const ReturnValue_t ILLEGAL_STORAGE_ID = MAKE_RETURN_CODE(3); //!< This return code indicates that data was requested with an illegal storage ID.
@ -96,7 +94,7 @@ public:
* @li RETURN_FAILED if data could not be added.
* storageId is unchanged then.
*/
virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t * data, uint32_t size) = 0;
virtual ReturnValue_t addData(store_address_t* storageId, const uint8_t * data, uint32_t size, bool ignoreFault = false) = 0;
/**
* @brief With deleteData, the storageManager frees the memory region
* identified by packet_id.
@ -146,7 +144,7 @@ public:
* @li RETURN_FAILED if data could not be added.
* storageId is unchanged then.
*/
virtual ReturnValue_t getFreeElement(store_address_t* storageId, const uint32_t size, uint8_t** p_data ) = 0;
virtual ReturnValue_t getFreeElement(store_address_t* storageId, const uint32_t size, uint8_t** p_data, bool ignoreFault = false ) = 0;
/**
* Clears the whole store.
* Use with care!