# HG changeset patch # User Alexis Jeandet # Date 2018-09-25 13:38:11 # Node ID 75028d90a6e75baf1aa7527b97013591d9fafd98 # Parent 88d90c878c97d96c81adf5afa487e2404da77988 # Parent 8059ee986796ceb1b8413a9989b49da6cc516a6f Fusion avec No PWD scrub with FPU diff --git a/.hgsub b/.hgsub --- a/.hgsub +++ b/.hgsub @@ -1,4 +1,4 @@ -header/lfr_common_headers = https://hephaistos.lpp.polytechnique.fr/rhodecode/HG_REPOSITORIES/LPP/INSTRUMENTATION/SOLO_LFR/lfr_common_headers +header/lfr_common_headers = https://hephaistos.lpp.polytechnique.fr/rhodecode/HG_REPOSITORIES/LPP/INSTRUMENTATION/USERS/JEANDET/lfr_common_headers LFR_basic-parameters = https://hephaistos.lpp.polytechnique.fr/rhodecode/HG_REPOSITORIES/LPP/INSTRUMENTATION/USERS/CHUST/LFR_basic-parameters diff --git a/.hgsubstate b/.hgsubstate --- a/.hgsubstate +++ b/.hgsubstate @@ -1,2 +1,2 @@ 3081d1f9bb20b2b64a192585337a292a9804e0c5 LFR_basic-parameters -e904b329ff977514bf36af92617afefd22fd06ab header/lfr_common_headers +f5b83fb540b1cfd5d87c68621fb53f238eb623ae header/lfr_common_headers diff --git a/.hgtags b/.hgtags new file mode 100644 --- /dev/null +++ b/.hgtags @@ -0,0 +1,4 @@ +3236b2a1a6a04bc11754d3f995873876b5046183 3.2.0.17 +ad411bb94578a052d1b4aa6b4c8a769fe2711072 3.2.0.18 +a9b894b0ab6a8fa48f50ce3dd7200406b83e2a62 3.2.0.19 +bd1252670981361939ed2a1c3febc94247019956 3.2.0.20 diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,5 +10,5 @@ set(LFR_BP_SRC ${CMAKE_CURRENT_SOURCE_DI SET(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}/sparc") +add_subdirectory(libgcov) add_subdirectory(src) -#add_subdirectory(timegen) diff --git a/EQM/header/grspw.h b/EQM/header/grspw.h --- a/EQM/header/grspw.h +++ b/EQM/header/grspw.h @@ -1,3 +1,27 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #ifndef GRSPW_H_INCLUDED #define GRSPW_H_INCLUDED diff --git a/header/fsw_misc.h b/header/fsw_misc.h --- a/header/fsw_misc.h +++ b/header/fsw_misc.h @@ -10,30 +10,16 @@ #include "fsw_spacewire.h" #include "lfr_cpu_usage_report.h" -#define LFR_RESET_CAUSE_UNKNOWN_CAUSE 0 #define WATCHDOG_LOOP_PRINTF 10 #define WATCHDOG_LOOP_DEBUG 3 -#define DUMB_MESSAGE_NB 15 #define NB_RTEMS_EVENTS 32 #define EVENT_12 12 #define EVENT_13 13 #define EVENT_14 14 -#define DUMB_MESSAGE_0 "in DUMB *** default" #define DUMB_MESSAGE_1 "in DUMB *** timecode_irq_handler" -#define DUMB_MESSAGE_2 "in DUMB *** f3 buffer changed" -#define DUMB_MESSAGE_3 "in DUMB *** in SMIQ *** Error sending event to AVF0" -#define DUMB_MESSAGE_4 "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ" -#define DUMB_MESSAGE_5 "in DUMB *** waveforms_simulator_isr" -#define DUMB_MESSAGE_6 "VHDL SM *** two buffers f0 ready" -#define DUMB_MESSAGE_7 "ready for dump" -#define DUMB_MESSAGE_8 "VHDL ERR *** spectral matrix" -#define DUMB_MESSAGE_9 "tick" -#define DUMB_MESSAGE_10 "VHDL ERR *** waveform picker" -#define DUMB_MESSAGE_11 "VHDL ERR *** unexpected ready matrix values" #define DUMB_MESSAGE_12 "WATCHDOG timer" #define DUMB_MESSAGE_13 "TIMECODE timer" -#define DUMB_MESSAGE_14 "TIMECODE ISR" enum lfr_reset_cause_t{ UNKNOWN_CAUSE, @@ -136,12 +122,13 @@ rtems_task load_task( rtems_task_argumen rtems_task hous_task( rtems_task_argument argument ); rtems_task avgv_task( rtems_task_argument argument ); rtems_task dumb_task( rtems_task_argument unused ); +rtems_task scrubbing_task( rtems_task_argument unused ); +rtems_task calibration_sweep_task( rtems_task_argument unused ); void init_housekeeping_parameters( void ); void increment_seq_counter(unsigned short *packetSequenceControl); void getTime( unsigned char *time); unsigned long long int getTimeAsUnsignedLongLongInt( ); -void send_dumb_hk( void ); void get_temperatures( unsigned char *temperatures ); void get_v_e1_e2_f3( unsigned char *spacecraft_potential ); void get_cpu_load( unsigned char *resource_statistics ); diff --git a/header/lfr_cpu_usage_report.h b/header/lfr_cpu_usage_report.h --- a/header/lfr_cpu_usage_report.h +++ b/header/lfr_cpu_usage_report.h @@ -29,8 +29,9 @@ unsigned char lfr_rtems_cpu_usage_report( void ); +#define CONST_10 10 #define CONST_100 100 +#define CONST_255 255 #define CONST_1000 1000 -#define CONST_100000 100000 #endif // LFR_CPU_USAGE_REPORT_H diff --git a/header/processing/fsw_processing.h b/header/processing/fsw_processing.h --- a/header/processing/fsw_processing.h +++ b/header/processing/fsw_processing.h @@ -15,15 +15,6 @@ #define MAX_SRC_DATA 780 // MAX size is 26 bins * 30 Bytes [TM_LFR_SCIENCE_BURST_BP2_F1] #define MAX_SRC_DATA_WITH_SPARE 143 // 13 bins * 11 Bytes -#define NODE_0 0 -#define NODE_1 1 -#define NODE_2 2 -#define NODE_3 3 -#define NODE_4 4 -#define NODE_5 5 -#define NODE_6 6 -#define NODE_7 7 - typedef struct ring_node_asm { struct ring_node_asm *next; diff --git a/header/tc_handler.h b/header/tc_handler.h --- a/header/tc_handler.h +++ b/header/tc_handler.h @@ -37,6 +37,8 @@ #define CAL_NB_PTS 256 #define CAL_DATA_MASK 0xfff #define CAL_F_DIVISOR 38 // 25 MHz => 160 256 (39 - 1) +#define CAL_F_DIVISOR_MIN 38 +#define CAL_F_DIVISOR_MAX (38*2*2*2*2) // INTERLEAVED MODE #define CAL_FS_INTER 240384.615 #define CAL_NB_PTS_INTER 384 diff --git a/header/tc_load_dump_parameters.h b/header/tc_load_dump_parameters.h --- a/header/tc_load_dump_parameters.h +++ b/header/tc_load_dump_parameters.h @@ -19,16 +19,6 @@ #define DELTAF_F0 96. #define DELTAF_F1 16. #define DELTAF_F2 1. -#define DELTAF_DIV 2. - -#define BIT_RW1_F1 0x80 -#define BIT_RW1_F2 0x40 -#define BIT_RW2_F1 0x20 -#define BIT_RW2_F2 0x10 -#define BIT_RW3_F1 0x08 -#define BIT_RW3_F2 0x04 -#define BIT_RW4_F1 0x02 -#define BIT_RW4_F2 0x01 #define WHEEL_1 1 #define WHEEL_2 2 diff --git a/header/wf_handler.h b/header/wf_handler.h --- a/header/wf_handler.h +++ b/header/wf_handler.h @@ -24,7 +24,6 @@ #define FREQ_F0 24576. #define FREQ_F1 4096. #define FREQ_F2 256. -#define FREQ_F3 16. #define DELTAT_F0 2731 // (2048. / 24576. / 2.) * 65536. = 2730.667; #define DELTAT_F1 16384 // (2048. / 4096. / 2.) * 65536. = 16384; diff --git a/libgcov/CMakeLists.txt b/libgcov/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/libgcov/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.6) +project(libgcov C) +include(sparc-rtems) +include(cppcheck) + +set(LIB_GCOV_SOURCES + gcov-io.c + gcov-io.h + gcov-iov.h + libgcov.c +) + +add_library(gcov STATIC ${LIB_GCOV_SOURCES}) + +add_custom_target(gcovr + COMMAND gcovr --exclude='.*gcov.*' --gcov-executable=${rtems_dir}/bin/sparc-rtems-gcov --object-directory ${CMAKE_BINARY_DIR} -r ${CMAKE_SOURCE_DIR} --html --html-details -o ${CMAKE_CURRENT_BINARY_DIR}/gcov.html && xdg-open ${CMAKE_CURRENT_BINARY_DIR}/gcov.html + ) diff --git a/libgcov/build_gcov_files.py b/libgcov/build_gcov_files.py new file mode 100644 --- /dev/null +++ b/libgcov/build_gcov_files.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +__author__ = "Alexis Jeandet" +__copyright__ = "Copyright 2018, Laboratory of Plasma Physics" +__credits__ = [] +__license__ = "GPLv2" +__version__ = "1.0.0" +__maintainer__ = "Alexis Jeandet" +__email__ = "alexis.jeandet@member.fsf.org" +__status__ = "Development" + +import time +import sys +import os +import serial +import argparse +from datetime import datetime + +parser = argparse.ArgumentParser() +parser.add_argument("-f", "--gcov-file", help="Gcov output file generated by record_lfr_console.py") +args = parser.parse_args() + + + +def main(): + with open(args.gcov_file,'r') as gcov: + files = [] + for line in gcov.readlines(): + head,dest_file,data = line.split(',') + if dest_file not in files: + files.append(dest_file) + if head == '_GCOV_': + print(f"Writing {dest_file}\n") + with open(dest_file,'wb') as gcda_file: + gcda_file.write(bytes([int(''.join(value),16) for value in zip(data[::2],data[1::2]) ])) + else: + raise + + +if __name__ == "__main__": + main() diff --git a/libgcov/gcov-io.c b/libgcov/gcov-io.c new file mode 100644 --- /dev/null +++ b/libgcov/gcov-io.c @@ -0,0 +1,488 @@ +/* Test for GCC >= 3.4.4 && <= 4.4.6 */ +//#if ( ( __GNUC__ > 3 ) || \ +// ( __GNUC__ == 3 && __GNUC_MINOR__ > 4 )|| \ +// ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ >= 4 ) ) && \ +// ( ( __GNUC__ < 4 ) || \ +// ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )|| \ +// ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ <= 6 ) ) +/* + * ===================================================================================== + * + * Filename: gcov-io.c + * + * Description: This is the I/O file for embedded systems + * + * Version: 1.0 + * Created: 03/04/08 09:51:59 + * Revision: none + * Compiler: gcc + * + * Author: Aitor Viana Sanchez (avs), aitor.viana.sanchez@esa.int + * Company: European Space Agency (ESA-ESTEC) + * + * ===================================================================================== + */ + +/* File format for coverage information + Copyright (C) 1996, 1997, 1998, 2000, 2002, + 2003 Free Software Foundation, Inc. + Contributed by Bob Manson . + Completely remangled by Nathan Sidwell . + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 2, or (at your option) any later + version. + + GCC is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING. If not, write to the Free + Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ + +#include +#include /* for atexit() */ +#include +#include "gcov-io.h" + +/* Routines declared in gcov-io.h. This file should be #included by + another source file, after having #included gcov-io.h. */ + + +/* This function shall be defined somewhere else */ +//int send_data(unsigned char * buffer, unsigned int size); + +/*----------------------------------------------------------------------------- + * PRIVATE INTERFACE + *-----------------------------------------------------------------------------*/ + +static void gcov_write_block (unsigned); +static gcov_unsigned_t *gcov_write_words (unsigned); +GCOV_LINKAGE int gcov_send (void); +GCOV_LINKAGE int gcov_close(void); + +extern struct gcov_info * gcov_list; +extern gcov_unsigned_t gcov_crc32; + +int dev_id = 0; + +/* + * === FUNCTION ====================================================================== + * Name: from_file + * Description: This function just return the given parameter + * ===================================================================================== + */ +static inline gcov_unsigned_t from_file (gcov_unsigned_t value) +{ + return value; +} + +/* + * === FUNCTION ====================================================================== + * Name: gcov_version + * Description: This function returns TRUE (1) if the gcov version is the + * version expected. The function returns FALSE (0) in any other case. + * ===================================================================================== + */ +static int gcov_version (struct gcov_info *ptr, gcov_unsigned_t version) +{ + if (version != GCOV_VERSION) + { + char v[4], e[4]; + + GCOV_UNSIGNED2STRING (v, version); + GCOV_UNSIGNED2STRING (e, GCOV_VERSION); + + printf ("profiling:%s:Version mismatch - expected %.4s got %.4s\n", + ptr->filename, e, v); + + return 0; + } + return 1; +} + + +/*----------------------------------------------------------------------------- + * PUBLIC INTERFACE + *-----------------------------------------------------------------------------*/ + +/* Dump the coverage counts. We merge with existing counts when + possible, to avoid growing the .da files ad infinitum. We use this + program's checksum to make sure we only accumulate whole program + statistics to the correct summary. An object file might be embedded + in two separate programs, and we must keep the two program + summaries separate. */ + +/* + * === FUNCTION ====================================================================== + * Name: gcov_exit + * Description: This function dumps the coverage couns. The merging with + * existing counts is not done in embedded systems. + * ===================================================================================== + */ +void gcov_exit (void) +{ + struct gcov_info *gi_ptr; + struct gcov_summary this_program; + struct gcov_summary all; + struct gcov_ctr_summary *cs_ptr; + const struct gcov_ctr_info *ci_ptr; + unsigned t_ix; + gcov_unsigned_t c_num; + unsigned long coreId = 0; + + /* retrieve the id of the CPU the program is running on */ + #ifdef LEON3 + __asm__ __volatile__("rd %%asr17,%0\n\t" + "srl %0,28,%0" : + "=&r" (coreId) : ); + #endif + + printf("_GCOVEXIT_BEGIN_,core%d\n", coreId); /* see also _GCOVEXIT_END_ */ + + if(gcov_list == (void*)0x0) + printf("%s: gcov_list == NULL\n", __func__); + + memset (&all, 0, sizeof (all)); + /* Find the totals for this execution. */ + memset (&this_program, 0, sizeof (this_program)); + for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next) + { + + ci_ptr = gi_ptr->counts; + for (t_ix = 0; t_ix < GCOV_COUNTERS_SUMMABLE; t_ix++) + { + if (!((1 << t_ix) & gi_ptr->ctr_mask)) + continue; + + cs_ptr = &this_program.ctrs[t_ix]; + cs_ptr->num += ci_ptr->num; + for (c_num = 0; c_num < ci_ptr->num; c_num++) + { + cs_ptr->sum_all += ci_ptr->values[c_num]; + if (cs_ptr->run_max < ci_ptr->values[c_num]) + cs_ptr->run_max = ci_ptr->values[c_num]; + } + ci_ptr++; + } + } + /* Now merge each file. */ + for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next) + { + + struct gcov_summary program; + gcov_type *values[GCOV_COUNTERS]; + const struct gcov_fn_info *fi_ptr; + unsigned fi_stride; + unsigned c_ix, f_ix, n_counts; + + c_ix = 0; + for (t_ix = 0; t_ix < GCOV_COUNTERS; t_ix++) + if ((1 << t_ix) & gi_ptr->ctr_mask) + { + values[c_ix] = gi_ptr->counts[c_ix].values; + c_ix++; + } + + /* Calculate the function_info stride. This depends on the + number of counter types being measured. */ + fi_stride = sizeof (struct gcov_fn_info) + c_ix * sizeof (unsigned); + if (__alignof__ (struct gcov_fn_info) > sizeof (unsigned)) + { + fi_stride += __alignof__ (struct gcov_fn_info) - 1; + fi_stride &= ~(__alignof__ (struct gcov_fn_info) - 1); + } + + if (!gcov_open (gi_ptr->filename)) + { + printf ("profiling:%s:Cannot open\n", gi_ptr->filename); + continue; + } + + program.checksum = gcov_crc32; + + /* Write out the data. */ + gcov_write_tag_length (GCOV_DATA_MAGIC, GCOV_VERSION); + gcov_write_unsigned (gi_ptr->stamp); + + /* Write execution counts for each function. */ + for (f_ix = 0; f_ix < gi_ptr->n_functions; f_ix++) + { + fi_ptr = (const struct gcov_fn_info *) + ((const char *) gi_ptr->functions + f_ix * fi_stride); + + /* Announce function. */ + gcov_write_tag_length (GCOV_TAG_FUNCTION, GCOV_TAG_FUNCTION_LENGTH); + gcov_write_unsigned (fi_ptr->ident); + gcov_write_unsigned (fi_ptr->checksum); + + c_ix = 0; + for (t_ix = 0; t_ix < GCOV_COUNTERS; t_ix++) + { + gcov_type *c_ptr; + + if (!((1 << t_ix) & gi_ptr->ctr_mask)) + continue; + + n_counts = fi_ptr->n_ctrs[c_ix]; + + gcov_write_tag_length (GCOV_TAG_FOR_COUNTER (t_ix), + GCOV_TAG_COUNTER_LENGTH (n_counts)); + c_ptr = values[c_ix]; + while (n_counts--) + gcov_write_counter (*c_ptr++); + + values[c_ix] = c_ptr; + c_ix++; + } + } + + gcov_send(); + gcov_close(); + + } + + printf("_GCOVEXIT_END_,core%d\n", coreId); +} + + +/* Called before fork or exec - write out profile information gathered so + far and reset it to zero. This avoids duplication or loss of the + profile information gathered so far. */ + + void +__gcov_flush (void) +{ + const struct gcov_info *gi_ptr; + + gcov_exit (); + for (gi_ptr = gcov_list; gi_ptr; gi_ptr = gi_ptr->next) + { + unsigned t_ix; + const struct gcov_ctr_info *ci_ptr; + + for (t_ix = 0, ci_ptr = gi_ptr->counts; t_ix != GCOV_COUNTERS; t_ix++) + if ((1 << t_ix) & gi_ptr->ctr_mask) + { + memset (ci_ptr->values, 0, sizeof (gcov_type) * ci_ptr->num); + ci_ptr++; + } + } +} + + + +/* Open a gcov file. NAME is the name of the file to open and MODE + indicates whether a new file should be created, or an existing file + opened for modification. If MODE is >= 0 an existing file will be + opened, if possible, and if MODE is <= 0, a new file will be + created. Use MODE=0 to attempt to reopen an existing file and then + fall back on creating a new one. Return zero on failure, >0 on + opening an existing file and <0 on creating a new one. */ +GCOV_LINKAGE int gcov_open(const char *name) +{ + // gcov_var.start is cleared in the gcov_close function. + // If this variable is not cleared...ERROR + if( gcov_var.start != 0 ) + return 0; + + // Clear everything + gcov_var.start = 0; + gcov_var.offset = gcov_var.length = 0; + gcov_var.overread = -1u; + gcov_var.error = 0; + + + // copy the filename in the gcov_var structure + strcpy(gcov_var.filename, name); + + + // return 1 means everything is OK + return 1; +} + +/* Close the current gcov file. Flushes data to disk. Returns nonzero + on failure or error flag set. */ + +GCOV_LINKAGE int gcov_send (void) +{ + /*printf("%s: file %s\n", __func__, gcov_var.filename);*/ + if (gcov_var.offset) + gcov_write_block (gcov_var.offset); + + gcov_var.length = 0; + return gcov_var.error; +} + +GCOV_LINKAGE int gcov_close(void) +{ + memset(gcov_var.filename, 0, strlen(gcov_var.filename)); + + // Clear the start variable because will be tested in the gcov_open + // function + gcov_var.start = 0; + + // Return the error, not sure whether the error is modifed. + return gcov_var.error; +} + + +static void gcov_write_block (unsigned size) { + unsigned char *buffer = (unsigned char*) gcov_var.buffer; + unsigned int i; + + printf("_GCOV_,%s,", gcov_var.filename); + /* to speed up the printing process, we display bytes 4 by 4 */ + for(i = 0; i < size; i++) { + printf("%02X%02X%02X%02X", (unsigned int)(buffer[0]), + (unsigned int)(buffer[1]), + (unsigned int)(buffer[2]), + (unsigned int)(buffer[3])); + + buffer += sizeof(gcov_unsigned_t); + } + printf("\n"); + + gcov_var.start += size; + gcov_var.offset -= size; +} + +/* Allocate space to write BYTES bytes to the gcov file. Return a + pointer to those bytes, or NULL on failure. */ + +static gcov_unsigned_t *gcov_write_words (unsigned words) { + gcov_unsigned_t *result; + + GCOV_CHECK_WRITING (); + if (gcov_var.offset >= GCOV_BLOCK_SIZE) + { + gcov_write_block (GCOV_BLOCK_SIZE); + if (gcov_var.offset) + { + GCOV_CHECK (gcov_var.offset == 1); + memcpy (gcov_var.buffer, gcov_var.buffer + GCOV_BLOCK_SIZE, 4); + } + } + result = &gcov_var.buffer[gcov_var.offset]; + gcov_var.offset += words; + + return result; +} + +/* Write unsigned VALUE to coverage file. Sets error flag + appropriately. */ + + GCOV_LINKAGE void +gcov_write_unsigned (gcov_unsigned_t value) +{ + gcov_unsigned_t *buffer = gcov_write_words (1); + + buffer[0] = value; +} + +/* Write counter VALUE to coverage file. Sets error flag + appropriately. */ + + GCOV_LINKAGE void +gcov_write_counter (gcov_type value) +{ + gcov_unsigned_t *buffer = gcov_write_words (2); + + buffer[0] = (gcov_unsigned_t) value; + if (sizeof (value) > sizeof (gcov_unsigned_t)) + buffer[1] = (gcov_unsigned_t) (value >> 32); + else + buffer[1] = 0; + +} + +/* Write a tag TAG and length LENGTH. */ + + GCOV_LINKAGE void +gcov_write_tag_length (gcov_unsigned_t tag, gcov_unsigned_t length) +{ + gcov_unsigned_t *buffer = gcov_write_words (2); + + buffer[0] = tag; + buffer[1] = length; +} + +/* Write a summary structure to the gcov file. Return nonzero on + overflow. */ + + GCOV_LINKAGE void +gcov_write_summary (gcov_unsigned_t tag, const struct gcov_summary *summary) +{ + unsigned ix; + const struct gcov_ctr_summary *csum; + + gcov_write_tag_length (tag, GCOV_TAG_SUMMARY_LENGTH); + gcov_write_unsigned (summary->checksum); + for (csum = summary->ctrs, ix = GCOV_COUNTERS_SUMMABLE; ix--; csum++) + { + gcov_write_unsigned (csum->num); + gcov_write_unsigned (csum->runs); + gcov_write_counter (csum->sum_all); + gcov_write_counter (csum->run_max); + gcov_write_counter (csum->sum_max); + } +} + + GCOV_LINKAGE gcov_type +gcov_read_counter (void) +{ + return 0; +} + +/* Add a new object file onto the bb chain. Invoked automatically + when running an object file's global ctors. */ + + void +__gcov_init (struct gcov_info *info) +{ + if (!info->version) + return; + if (gcov_version (info, info->version)) + { + const char *ptr = info->filename; + gcov_unsigned_t crc32 = gcov_crc32; + + /* Added by LESIA*/ + printf("Covered file: %s\n", info->filename); + /* End of Added by LESIA*/ + + do + { + unsigned ix; + gcov_unsigned_t value = *ptr << 24; + + for (ix = 8; ix--; value <<= 1) + { + gcov_unsigned_t feedback; + + feedback = (value ^ crc32) & 0x80000000 ? 0x04c11db7 : 0; + crc32 <<= 1; + crc32 ^= feedback; + } + } + while (*ptr++); + + gcov_crc32 = crc32; + + if (!gcov_list) + atexit (gcov_exit); + + info->next = gcov_list; + gcov_list = info; + } + else + printf("%s: Version mismatch\n", "WARNING"); + info->version = 0; +} +//#endif /* __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ */ diff --git a/libgcov/gcov-io.h b/libgcov/gcov-io.h new file mode 100644 --- /dev/null +++ b/libgcov/gcov-io.h @@ -0,0 +1,485 @@ +/* Test for GCC >= 3.4.4 && <= 4.4.6 */ +//#if ( ( __GNUC__ > 3 ) || \ +// ( __GNUC__ == 3 && __GNUC_MINOR__ > 4 )|| \ +// ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ >= 4 ) ) && \ +// ( ( __GNUC__ < 4 ) || \ +// ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )|| \ +// ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ <= 6 ) ) +//#include +//#include +/* File format for coverage information + Copyright (C) 1996, 1997, 1998, 2000, 2002, + 2003, 2004 Free Software Foundation, Inc. + Contributed by Bob Manson . + Completely remangled by Nathan Sidwell . + + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it under + the terms of the GNU General Public License as published by the Free + Software Foundation; either version 2, or (at your option) any later + version. + + GCC is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + for more details. + + You should have received a copy of the GNU General Public License + along with GCC; see the file COPYING. If not, write to the Free + Software Foundation, 59 Temple Place - Suite 330, Boston, MA + 02111-1307, USA. */ + +/* As a special exception, if you link this library with other files, + some of which are compiled with GCC, to produce an executable, + this library does not by itself cause the resulting executable + to be covered by the GNU General Public License. + This exception does not however invalidate any other reasons why + the executable file might be covered by the GNU General Public License. */ + +/* Coverage information is held in two files. A notes file, which is + generated by the compiler, and a data file, which is generated + by the program under test. Both files use a similar structure. We + do not attempt to make these files backwards compatible with + previous versions, as you only need coverage information when + developing a program. We do hold version information, so that + mismatches can be detected, and we use a format that allows tools + to skip information they do not understand or are not interested + in. + + Numbers are recorded in the 32 bit unsigned binary form of the + endianness of the machine generating the file. 64 bit numbers are + stored as two 32 bit numbers, the low part first. Strings are + padded with 1 to 4 NUL bytes, to bring the length up to a multiple + of 4. The number of 4 bytes is stored, followed by the padded + string. Zero length and NULL strings are simply stored as + a length of zero (they have no trailing NUL or padding). + +int32: byte3 byte2 byte1 byte0 | byte0 byte1 byte2 byte3 +int64: int32:low int32:high +string: int32:0 | int32:length char* char:0 padding +padding: | char:0 | char:0 char:0 | char:0 char:0 char:0 +item: int32 | int64 | string + +The basic format of the files is + +file : int32:magic int32:version int32:stamp record* + +The magic ident is different for the notes and the data files. The +magic ident is used to determine the endianness of the file, when +reading. The version is the same for both files and is derived +from gcc's version number. The stamp value is used to synchronize +note and data files and to synchronize merging within a data +file. It need not be an absolute time stamp, merely a ticker that +increments fast enough and cycles slow enough to distinguish +different compile/run/compile cycles. + +Although the ident and version are formally 32 bit numbers, they +are derived from 4 character ASCII strings. The version number +consists of the single character major version number, a two +character minor version number (leading zero for versions less than +10), and a single character indicating the status of the release. +That will be 'e' experimental, 'p' prerelease and 'r' for release. +Because, by good fortune, these are in alphabetical order, string +collating can be used to compare version strings. Be aware that +the 'e' designation will (naturally) be unstable and might be +incompatible with itself. For gcc 3.4 experimental, it would be +'304e' (0x33303465). When the major version reaches 10, the +letters A-Z will be used. Assuming minor increments releases every +6 months, we have to make a major increment every 50 years. +Assuming major increments releases every 5 years, we're ok for the +next 155 years -- good enough for me. + +A record has a tag, length and variable amount of data. + +record: header data +header: int32:tag int32:length +data: item* + +Records are not nested, but there is a record hierarchy. Tag +numbers reflect this hierarchy. Tags are unique across note and +data files. Some record types have a varying amount of data. The +LENGTH is the number of 4bytes that follow and is usually used to +determine how much data. The tag value is split into 4 8-bit +fields, one for each of four possible levels. The most significant +is allocated first. Unused levels are zero. Active levels are +odd-valued, so that the LSB of the level is one. A sub-level +incorporates the values of its superlevels. This formatting allows +you to determine the tag hierarchy, without understanding the tags +themselves, and is similar to the standard section numbering used +in technical documents. Level values [1..3f] are used for common +tags, values [41..9f] for the notes file and [a1..ff] for the data +file. + +The basic block graph file contains the following records +note: unit function-graph* +unit: header int32:checksum string:source +function-graph: announce_function basic_blocks {arcs | lines}* +announce_function: header int32:ident int32:checksum +string:name string:source int32:lineno +basic_block: header int32:flags* +arcs: header int32:block_no arc* +arc: int32:dest_block int32:flags +lines: header int32:block_no line* +int32:0 string:NULL +line: int32:line_no | int32:0 string:filename + +The BASIC_BLOCK record holds per-bb flags. The number of blocks +can be inferred from its data length. There is one ARCS record per +basic block. The number of arcs from a bb is implicit from the +data length. It enumerates the destination bb and per-arc flags. +There is one LINES record per basic block, it enumerates the source +lines which belong to that basic block. Source file names are +introduced by a line number of 0, following lines are from the new +source file. The initial source file for the function is NULL, but +the current source file should be remembered from one LINES record +to the next. The end of a block is indicated by an empty filename +- this does not reset the current source file. Note there is no +ordering of the ARCS and LINES records: they may be in any order, + interleaved in any manner. The current filename follows the order + the LINES records are stored in the file, *not* the ordering of the + blocks they are for. + + The data file contains the following records. + data: {unit function-data* summary:object summary:program*}* + unit: header int32:checksum + function-data: announce_function arc_counts + announce_function: header int32:ident int32:checksum + arc_counts: header int64:count* + summary: int32:checksum {count-summary}GCOV_COUNTERS + count-summary: int32:num int32:runs int64:sum + int64:max int64:sum_max + + The ANNOUNCE_FUNCTION record is the same as that in the note file, + but without the source location. The ARC_COUNTS gives the counter + values for those arcs that are instrumented. The SUMMARY records + give information about the whole object file and about the whole + program. The checksum is used for whole program summaries, and + disambiguates different programs which include the same + instrumented object file. There may be several program summaries, + each with a unique checksum. The object summary's checksum is zero. + Note that the data file might contain information from several runs + concatenated, or the data might be merged. + + This file is included by both the compiler, gcov tools and the + runtime support library libgcov. IN_LIBGCOV and IN_GCOV are used to + distinguish which case is which. If IN_LIBGCOV is nonzero, + libgcov is being built. If IN_GCOV is nonzero, the gcov tools are + being built. Otherwise the compiler is being built. IN_GCOV may be + positive or negative. If positive, we are compiling a tool that + requires additional functions (see the code for knowledge of what + those functions are). */ + +#ifndef GCC_GCOV_IO_H +#define GCC_GCOV_IO_H + + typedef unsigned int gcov_unsigned_t; + typedef unsigned int gcov_position_t; + + typedef unsigned long long gcov_type; + + /* No tengo ni idea de que es el SETLKW, asi que de momento el target + * no tiene de eso */ + + //#if defined (TARGET_HAS_F_SETLKW) + //#define GCOV_LOCKED 1 + //#else +#define GCOV_LOCKED 0 + //#endif + //#endif + + + + /* In gcov we want function linkage to be static. In the compiler we want + it extern, so that they can be accessed from elsewhere. In libgcov we + need these functions to be extern, so prefix them with __gcov. In + libgcov they must also be hidden so that the instance in the executable + is not also used in a DSO. */ + +#define gcov_var __gcov_var +#define gcov_open __gcov_open +#define gcov_close __gcov_close +#define gcov_write_tag_length __gcov_write_tag_length +#define gcov_position __gcov_position +#define gcov_seek __gcov_seek +#define gcov_rewrite __gcov_rewrite +#define gcov_is_error __gcov_is_error +#define gcov_is_eof __gcov_is_eof +#define gcov_write_unsigned __gcov_write_unsigned +#define gcov_write_counter __gcov_write_counter +#define gcov_write_summary __gcov_write_summary +#define gcov_read_unsigned __gcov_read_unsigned +#define gcov_read_counter __gcov_read_counter +#define gcov_read_summary __gcov_read_summary + + /* Esto no tengo ni repajolera idea de para que vale */ + + /* Poison these, so they don't accidentally slip in. */ + //#pragma GCC poison gcov_write_string gcov_write_tag gcov_write_length + //#pragma GCC poison gcov_read_string gcov_sync gcov_time gcov_magic + +#ifdef HAVE_GAS_HIDDEN +#define ATTRIBUTE_HIDDEN __attribute__ ((__visibility__ ("hidden"))) +#else +#define ATTRIBUTE_HIDDEN +#endif + +#ifndef GCOV_LINKAGE +#define GCOV_LINKAGE extern + //#define GCOV_LINKAGE +#endif + + /* File suffixes. */ +#define GCOV_DATA_SUFFIX ".gcda" +#define GCOV_NOTE_SUFFIX ".gcno" + + /* File magic. Must not be palindromes. */ +#define GCOV_DATA_MAGIC ((gcov_unsigned_t)0x67636461) /* "gcda" */ +#define GCOV_NOTE_MAGIC ((gcov_unsigned_t)0x67636e6f) /* "gcno" */ + + /* gcov-iov.h is automatically generated by the makefile from + version.c, it looks like +#define GCOV_VERSION ((gcov_unsigned_t)0x89abcdef) +*/ +#include "gcov-iov.h" + + /* Convert a magic or version number to a 4 character string. */ +#define GCOV_UNSIGNED2STRING(ARRAY,VALUE) \ + ((ARRAY)[0] = (char)((VALUE) >> 24), \ + (ARRAY)[1] = (char)((VALUE) >> 16), \ + (ARRAY)[2] = (char)((VALUE) >> 8), \ + (ARRAY)[3] = (char)((VALUE) >> 0)) + + /* The record tags. Values [1..3f] are for tags which may be in either + file. Values [41..9f] for those in the note file and [a1..ff] for + the data file. */ + +#define GCOV_TAG_FUNCTION ((gcov_unsigned_t)0x01000000) +#define GCOV_TAG_FUNCTION_LENGTH (2) +#define GCOV_TAG_BLOCKS ((gcov_unsigned_t)0x01410000) +#define GCOV_TAG_BLOCKS_LENGTH(NUM) (NUM) +#define GCOV_TAG_BLOCKS_NUM(LENGTH) (LENGTH) +#define GCOV_TAG_ARCS ((gcov_unsigned_t)0x01430000) +#define GCOV_TAG_ARCS_LENGTH(NUM) (1 + (NUM) * 2) +#define GCOV_TAG_ARCS_NUM(LENGTH) (((LENGTH) - 1) / 2) +#define GCOV_TAG_LINES ((gcov_unsigned_t)0x01450000) +#define GCOV_TAG_COUNTER_BASE ((gcov_unsigned_t)0x01a10000) +#define GCOV_TAG_COUNTER_LENGTH(NUM) ((NUM) * 2) +#define GCOV_TAG_COUNTER_NUM(LENGTH) ((LENGTH) / 2) +#define GCOV_TAG_OBJECT_SUMMARY ((gcov_unsigned_t)0xa1000000) +#define GCOV_TAG_PROGRAM_SUMMARY ((gcov_unsigned_t)0xa3000000) +#define GCOV_TAG_SUMMARY_LENGTH \ + (1 + GCOV_COUNTERS_SUMMABLE * (2 + 3 * 2)) + + /* Counters that are collected. */ +#define GCOV_COUNTER_ARCS 0 /* Arc transitions. */ +#define GCOV_COUNTERS_SUMMABLE 1 /* Counters which can be + summaried. */ +#define GCOV_FIRST_VALUE_COUNTER 1 /* The first of counters used for value + profiling. They must form a consecutive + interval and their order must match + the order of HIST_TYPEs in + value-prof.h. */ +#define GCOV_COUNTER_V_INTERVAL 1 /* Histogram of value inside an interval. */ +#define GCOV_COUNTER_V_POW2 2 /* Histogram of exact power2 logarithm + of a value. */ +#define GCOV_COUNTER_V_SINGLE 3 /* The most common value of expression. */ +#define GCOV_COUNTER_V_DELTA 4 /* The most common difference between + consecutive values of expression. */ +#define GCOV_LAST_VALUE_COUNTER 4 /* The last of counters used for value + profiling. */ +#define GCOV_COUNTERS 5 + + /* Number of counters used for value profiling. */ +#define GCOV_N_VALUE_COUNTERS \ + (GCOV_LAST_VALUE_COUNTER - GCOV_FIRST_VALUE_COUNTER + 1) + + /* A list of human readable names of the counters */ +#define GCOV_COUNTER_NAMES {"arcs", "interval", "pow2", "single", "delta"} + + /* Names of merge functions for counters. */ +#define GCOV_MERGE_FUNCTIONS {"__gcov_merge_add", \ + "__gcov_merge_add", \ + "__gcov_merge_add", \ + "__gcov_merge_single", \ + "__gcov_merge_delta"} + + /* Convert a counter index to a tag. */ +#define GCOV_TAG_FOR_COUNTER(COUNT) \ + (GCOV_TAG_COUNTER_BASE + ((gcov_unsigned_t)(COUNT) << 17)) + /* Convert a tag to a counter. */ +#define GCOV_COUNTER_FOR_TAG(TAG) \ + ((unsigned)(((TAG) - GCOV_TAG_COUNTER_BASE) >> 17)) + /* Check whether a tag is a counter tag. */ +#define GCOV_TAG_IS_COUNTER(TAG) \ + (!((TAG) & 0xFFFF) && GCOV_COUNTER_FOR_TAG (TAG) < GCOV_COUNTERS) + + /* The tag level mask has 1's in the position of the inner levels, & + the lsb of the current level, and zero on the current and outer + levels. */ +#define GCOV_TAG_MASK(TAG) (((TAG) - 1) ^ (TAG)) + + /* Return nonzero if SUB is an immediate subtag of TAG. */ +#define GCOV_TAG_IS_SUBTAG(TAG,SUB) \ + (GCOV_TAG_MASK (TAG) >> 8 == GCOV_TAG_MASK (SUB) \ + && !(((SUB) ^ (TAG)) & ~GCOV_TAG_MASK(TAG))) + + /* Return nonzero if SUB is at a sublevel to TAG. */ +#define GCOV_TAG_IS_SUBLEVEL(TAG,SUB) \ + (GCOV_TAG_MASK (TAG) > GCOV_TAG_MASK (SUB)) + + /* Basic block flags. */ +#define GCOV_BLOCK_UNEXPECTED (1 << 1) + + /* Arc flags. */ +#define GCOV_ARC_ON_TREE (1 << 0) +#define GCOV_ARC_FAKE (1 << 1) +#define GCOV_ARC_FALLTHROUGH (1 << 2) + + /* Structured records. */ + + /* Cumulative counter data. */ + struct gcov_ctr_summary +{ + gcov_unsigned_t num; /* number of counters. */ + gcov_unsigned_t runs; /* number of program runs */ + gcov_type sum_all; /* sum of all counters accumulated. */ + gcov_type run_max; /* maximum value on a single run. */ + gcov_type sum_max; /* sum of individual run max values. */ +}; + + +/* Object & program summary record. */ +struct gcov_summary +{ + gcov_unsigned_t checksum; /* checksum of program */ + struct gcov_ctr_summary ctrs[GCOV_COUNTERS_SUMMABLE]; +}; + +/* Structures embedded in coveraged program. The structures generated + by write_profile must match these. */ + +/* Information about a single function. This uses the trailing array + idiom. The number of counters is determined from the counter_mask + in gcov_info. We hold an array of function info, so have to + explicitly calculate the correct array stride. */ +struct gcov_fn_info +{ + gcov_unsigned_t ident; /* unique ident of function */ + gcov_unsigned_t checksum; /* function checksum */ + unsigned n_ctrs[0]; /* instrumented counters */ +}; + +/* Type of function used to merge counters. */ +typedef void (*gcov_merge_fn) (gcov_type *, gcov_unsigned_t); + +/* Information about counters. */ +struct gcov_ctr_info +{ + gcov_unsigned_t num; /* number of counters. */ + gcov_type *values; /* their values. */ + gcov_merge_fn merge; /* The function used to merge them. */ +}; + +/* Information about a single object file. */ +struct gcov_info +{ + gcov_unsigned_t version; /* expected version number */ + struct gcov_info *next; /* link to next, used by libgcov */ + + gcov_unsigned_t stamp; /* uniquifying time stamp */ + const char *filename; /* output file name */ + + unsigned n_functions; /* number of functions */ + const struct gcov_fn_info *functions; /* table of functions */ + + unsigned ctr_mask; /* mask of counters instrumented. */ + struct gcov_ctr_info counts[0]; /* count data. The number of bits + set in the ctr_mask field + determines how big this array + is. */ +}; + +/* Register a new object file module. */ +extern void __gcov_init (struct gcov_info *) ATTRIBUTE_HIDDEN; + +/* Called before fork, to avoid double counting. */ +extern void __gcov_flush (void) ATTRIBUTE_HIDDEN; + +/* The merge function that just sums the counters. */ +extern void __gcov_merge_add (gcov_type *, unsigned) ATTRIBUTE_HIDDEN; + +/* The merge function to choose the most common value. */ +extern void __gcov_merge_single (gcov_type *, unsigned) ATTRIBUTE_HIDDEN; + +/* The merge function to choose the most common difference between + consecutive values. */ +extern void __gcov_merge_delta (gcov_type *, unsigned) ATTRIBUTE_HIDDEN; + +/* Optimum number of gcov_unsigned_t's read from or written to disk. */ +// We limit GCOV_BLOCK_SIZE to 512 unsigned long because post processing with +// DOS batch cannot handle command lines bigger than 8191 characters, knowing +// that for each char, we print 4 characters (e.g "\x00") +#define GCOV_BLOCK_SIZE (1 << 11) +#define MAXFILENAME (1024) + +GCOV_LINKAGE struct gcov_var +{ + // FILE *file; + char filename[MAXFILENAME]; + gcov_position_t start; /* Position of first byte of block */ + unsigned offset; /* Read/write position within the block. */ + unsigned length; /* Read limit in the block. */ + unsigned overread; /* Number of words overread. */ + int error; /* < 0 overflow, > 0 disk error. */ + /* Holds one block plus 4 bytes, thus all coverage reads & writes + fit within this buffer and we always can transfer GCOV_BLOCK_SIZE + to and from the disk. libgcov never backtracks and only writes 4 + or 8 byte objects. */ + gcov_unsigned_t buffer[GCOV_BLOCK_SIZE + 1]; +} gcov_var ATTRIBUTE_HIDDEN; + +#if 1 +/* Functions for reading and writing gcov files. In libgcov you can + open the file for reading then writing. Elsewhere you can open the + file either for reading or for writing. When reading a file you may + use the gcov_read_* functions, gcov_sync, gcov_position, & + gcov_error. When writing a file you may use the gcov_write + functions, gcov_seek & gcov_error. When a file is to be rewritten + you use the functions for reading, then gcov_rewrite then the + functions for writing. Your file may become corrupted if you break + these invariants. */ +GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN; +GCOV_LINKAGE int gcov_close (void) ATTRIBUTE_HIDDEN; + +/* Available everywhere. */ +/* static gcov_position_t gcov_position (void); + * static int gcov_is_error (void); + * static int gcov_is_eof (void); + */ + +GCOV_LINKAGE gcov_unsigned_t gcov_read_unsigned (void) ATTRIBUTE_HIDDEN; +GCOV_LINKAGE gcov_type gcov_read_counter (void) ATTRIBUTE_HIDDEN; +GCOV_LINKAGE void gcov_read_summary (struct gcov_summary *) ATTRIBUTE_HIDDEN; +#endif +/* Available only in libgcov */ +GCOV_LINKAGE void gcov_write_counter (gcov_type) ATTRIBUTE_HIDDEN; +GCOV_LINKAGE void gcov_write_tag_length (gcov_unsigned_t, + gcov_unsigned_t) ATTRIBUTE_HIDDEN; +GCOV_LINKAGE void gcov_write_summary (gcov_unsigned_t /*tag*/, + const struct gcov_summary *) ATTRIBUTE_HIDDEN; + +/* Available outside gcov */ +GCOV_LINKAGE void gcov_write_unsigned (gcov_unsigned_t) ATTRIBUTE_HIDDEN; + +/* Make sure the library is used correctly. */ +#if ENABLE_CHECKING +#define GCOV_CHECK(expr) ((expr) ? (void)0 : (void)abort ()) +#else +#define GCOV_CHECK(expr) +#endif +#define GCOV_CHECK_READING() GCOV_CHECK(gcov_var.mode > 0) +#define GCOV_CHECK_WRITING() GCOV_CHECK(gcov_var.mode < 0) + +#endif /* GCC_GCOV_IO_H */ +//#endif /* __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ */ diff --git a/libgcov/gcov-iov.h b/libgcov/gcov-iov.h new file mode 100644 --- /dev/null +++ b/libgcov/gcov-iov.h @@ -0,0 +1,13 @@ +/* Generated by the program `C:\home\obswteam\workspace\sparc-gcov-master\tools\version\gcov-iov.exe' + from `4.4 (4 4) and (*)'. */ +#if ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 ) +#define GCOV_VERSION ((gcov_unsigned_t)0x3330342a) /* type 'gcov-iov 3.4 ""' */ +#endif /* __GNUC__ __GNUC_MINOR__ */ + +#if ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 ) +#define GCOV_VERSION ((gcov_unsigned_t)0x3430342a) /* type 'gcov-iov 4.4 ""' */ +#endif /* __GNUC__ __GNUC_MINOR__ */ + +#if ( __GNUC__ > 4 ) +#define GCOV_VERSION ((gcov_unsigned_t)0x3430342a) /* type 'gcov-iov 4.4 ""' */ +#endif /* __GNUC__ __GNUC_MINOR__ */ diff --git a/libgcov/libgcov.c b/libgcov/libgcov.c new file mode 100644 --- /dev/null +++ b/libgcov/libgcov.c @@ -0,0 +1,134 @@ +/* Test for GCC >= 3.4.4 && <= 4.4.6 */ +/*#if ( ( __GNUC__ > 3 ) || \ + ( __GNUC__ == 3 && __GNUC_MINOR__ > 4 )|| \ + ( __GNUC__ == 3 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ >= 4 ) ) && \ + ( ( __GNUC__ < 4 ) || \ + ( __GNUC__ == 4 && __GNUC_MINOR__ < 4 )|| \ + ( __GNUC__ == 4 && __GNUC_MINOR__ == 4 && __GNUC_PATCHLEVEL__ <= 6 ) ) + */ +/* Routines required for instrumenting a program. */ +/* Compile this one with gcc. */ +/* Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, + 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + +This file is part of GCC. + +GCC is free software; you can redistribute it and/or modify it under +the terms of the GNU General Public License as published by the Free +Software Foundation; either version 2, or (at your option) any later +version. + +In addition to the permissions in the GNU General Public License, the +Free Software Foundation gives you unlimited permission to link the +compiled version of this file into combinations with other programs, +and to distribute those combinations without any restriction coming +from the use of this file. (The General Public License restrictions +do apply in other respects; for example, they cover modification of +the file, and distribution when not linked into a combine +executable.) + +GCC is distributed in the hope that it will be useful, but WITHOUT ANY +WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +for more details. + +You should have received a copy of the GNU General Public License +along with GCC; see the file COPYING. If not, write to the Free +Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. */ + +#define GCOV_LINKAGE /* nothing */ + +#include "gcov-io.h" + +/* Chain of per-object gcov structures. */ +struct gcov_info *gcov_list; + +/* A program checksum allows us to distinguish program data for an + object file included in multiple programs. */ +gcov_unsigned_t gcov_crc32; + +/* The profile merging function that just adds the counters. It is given + an array COUNTERS of N_COUNTERS old counters and it reads the same number + of counters from the gcov file. */ +void +__gcov_merge_add (gcov_type *counters, unsigned n_counters) +{ + for (; n_counters; counters++, n_counters--) + *counters += gcov_read_counter (); +} +/* The profile merging function for choosing the most common value. + It is given an array COUNTERS of N_COUNTERS old counters and it + reads the same number of counters from the gcov file. The counters + are split into 3-tuples where the members of the tuple have + meanings: + + -- the stored candidate on the most common value of the measured entity + -- counter + -- total number of evaluations of the value */ +void +__gcov_merge_single (gcov_type *counters, unsigned n_counters) +{ + unsigned i, n_measures; + gcov_type value, counter, all; + + GCOV_CHECK (!(n_counters % 3)); + n_measures = n_counters / 3; + for (i = 0; i < n_measures; i++, counters += 3) + { + value = gcov_read_counter (); + counter = gcov_read_counter (); + all = gcov_read_counter (); + + if (counters[0] == value) + counters[1] += counter; + else if (counter > counters[1]) + { + counters[0] = value; + counters[1] = counter - counters[1]; + } + else + counters[1] -= counter; + counters[2] += all; + } +} + +/* The profile merging function for choosing the most common + difference between two consecutive evaluations of the value. It is + given an array COUNTERS of N_COUNTERS old counters and it reads the + same number of counters from the gcov file. The counters are split + into 4-tuples where the members of the tuple have meanings: + + -- the last value of the measured entity + -- the stored candidate on the most common difference + -- counter + -- total number of evaluations of the value */ + +void +__gcov_merge_delta (gcov_type *counters, unsigned n_counters) +{ + unsigned i, n_measures; + gcov_type last, value, counter, all; + + GCOV_CHECK (!(n_counters % 4)); + n_measures = n_counters / 4; + for (i = 0; i < n_measures; i++, counters += 4) + { + last = gcov_read_counter (); + value = gcov_read_counter (); + counter = gcov_read_counter (); + all = gcov_read_counter (); + + if (counters[1] == value) + counters[2] += counter; + else if (counter > counters[2]) + { + counters[1] = value; + counters[2] = counter - counters[2]; + } + else + counters[2] -= counter; + counters[3] += all; + } +} +//#endif /* __GNUC__ __GNUC_MINOR__ __GNUC_PATCHLEVEL__ */ diff --git a/libgcov/record_lfr_console.py b/libgcov/record_lfr_console.py new file mode 100644 --- /dev/null +++ b/libgcov/record_lfr_console.py @@ -0,0 +1,40 @@ +#!/usr/bin/env python3 + +__author__ = "Alexis Jeandet" +__copyright__ = "Copyright 2018, Laboratory of Plasma Physics" +__credits__ = [] +__license__ = "GPLv2" +__version__ = "1.0.0" +__maintainer__ = "Alexis Jeandet" +__email__ = "alexis.jeandet@member.fsf.org" +__status__ = "Development" + +import time +import sys +import os +import serial +import argparse +from datetime import datetime + +parser = argparse.ArgumentParser() +parser.add_argument("-p", "--port", help="Serial port") +parser.add_argument("-s", "--speed", help="Baud rate") +args = parser.parse_args() + + + +def main(): + with open('gcov_out_'+str(datetime.now())+'.txt','w') as gcov: + with open('console_'+str(datetime.now())+'.txt','w') as console: + with serial.Serial(args.port, args.speed, timeout=None) as ser: + line = ser.readline().decode() + while '_GCOVEXIT_BEGIN_' not in line: + console.write(line) + line = ser.readline().decode() + line = ser.readline().decode() + while '_GCOVEXIT_END_' not in line: + gcov.write(line) + line = ser.readline().decode() + +if __name__ == "__main__": + main() diff --git a/sparc/sparc-rtems.cmake b/sparc/sparc-rtems.cmake --- a/sparc/sparc-rtems.cmake +++ b/sparc/sparc-rtems.cmake @@ -7,12 +7,19 @@ set(CMAKE_LINKER ${rtems_dir}/bin/sparc SET(CMAKE_EXE_LINKER_FLAGS "-static") option(fix-b2bst "Activate -mfix-b2bst switch to mitigate \"LEON3FT Stale Cache Entry After Store with Data Tag Parity Error\" errata, GRLIB-TN-0009" ON) +option(Coverage "Enables code coverage" OFF) + + +set(CMAKE_C_FLAGS_RELEASE "-O3") +set(CMAKE_C_FLAGS_DEBUG "-O0") + + if(fix-b2bst) - set(CMAKE_C_FLAGS_RELEASE "-O3 -mfix-b2bst") -else() - set(CMAKE_C_FLAGS_RELEASE "-O3") + set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mfix-b2bst") + set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mfix-b2bst") endif() + set(CMAKE_C_LINK_EXECUTABLE " -Xlinker -Map=.map -o ") include_directories("${rtems_dir}/sparc-rtems/leon3/lib/include") @@ -23,3 +30,10 @@ function (check_b2bst target bin) COMMAND ${rtems_dir}/bin/sparc-rtems-objdump -d ${bin}/${target} | ${CMAKE_SOURCE_DIR}/sparc/leon3ft-b2bst-scan.tcl ) endfunction() + +function (build_srec target bin rev) + add_custom_command(TARGET ${target} + POST_BUILD + COMMAND ${rtems_dir}/bin/sparc-rtems-objcopy -j .data -F srec ${bin}/${target} RpwLfrApp_XXXX_data_rev-${rev}.srec && ${rtems_dir}/bin/sparc-rtems-objcopy -j .text -F srec ${bin}/${target} RpwLfrApp_XXXX_text_rev-${rev}.srec + ) +endfunction() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -60,11 +60,12 @@ option(FSW_vhdl_dev "?" OFF) option(FSW_lpp_dpu_destid "Set to debug at LPP" OFF) option(FSW_debug_watchdog "Enable debug watchdog" OFF) option(FSW_debug_tch "?" OFF) +option(FSW_Instrument_Scrubbing "Enable scrubbing counter" OFF) set(SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE) set(SW_VERSION_N2 "2" CACHE STRING "Choose N2 FSW Version." FORCE) set(SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE) -set(SW_VERSION_N4 "15" CACHE STRING "Choose N4 FSW Version." FORCE) +set(SW_VERSION_N4 "20" CACHE STRING "Choose N4 FSW Version." FORCE) if(FSW_verbose) add_definitions(-DPRINT_MESSAGES_ON_CONSOLE) @@ -94,6 +95,8 @@ if(FSW_debug_tch) add_definitions(-DDEBUG_TCH) endif() + + add_definitions(-DMSB_FIRST_TCH) add_definitions(-DSWVERSION=-1-0) @@ -104,9 +107,24 @@ add_definitions(-DSW_VERSION_N4=${SW_VER add_executable(fsw ${SOURCES}) +if(FSW_Instrument_Scrubbing) + add_definitions(-DENABLE_SCRUBBING_COUNTER) +endif() + +if(Coverage) + target_link_libraries(fsw gcov) + SET_TARGET_PROPERTIES(fsw PROPERTIES COMPILE_FLAGS "-fprofile-arcs -ftest-coverage") +endif() + + if(fix-b2bst) check_b2bst(fsw ${CMAKE_CURRENT_BINARY_DIR}) endif() +if(NOT FSW_lpp_dpu_destid) + build_srec(fsw ${CMAKE_CURRENT_BINARY_DIR} "${SW_VERSION_N1}-${SW_VERSION_N2}-${SW_VERSION_N3}-${SW_VERSION_N4}") +endif() + + add_test_cppcheck(fsw STYLE UNUSED_FUNCTIONS POSSIBLE_ERROR MISSING_INCLUDE) diff --git a/src/fsw_globals.c b/src/fsw_globals.c --- a/src/fsw_globals.c +++ b/src/fsw_globals.c @@ -1,3 +1,26 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ /** Global variables of the LFR flight software. * * @file @@ -22,13 +45,13 @@ #include "fsw_params.h" #include "fsw_params_wf_handler.h" -#define NB_OF_TASKS 20 + #define NB_OF_MISC_NAMES 5 // RTEMS GLOBAL VARIABLES rtems_name misc_name[NB_OF_MISC_NAMES] = {0}; -rtems_name Task_name[NB_OF_TASKS] = {0}; /* array of task names */ -rtems_id Task_id[NB_OF_TASKS] = {0}; /* array of task ids */ +rtems_name Task_name[CONFIGURE_MAXIMUM_TASKS-1] = {0}; /* array of task names */ +rtems_id Task_id[CONFIGURE_MAXIMUM_TASKS-1] = {0}; /* array of task ids */ rtems_name timecode_timer_name = 0; rtems_id timecode_timer_id = RTEMS_ID_NONE; rtems_name name_hk_rate_monotonic = 0; // name of the HK rate monotonic diff --git a/src/fsw_init.c b/src/fsw_init.c --- a/src/fsw_init.c +++ b/src/fsw_init.c @@ -1,3 +1,27 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + /** This is the RTEMS initialization module. * * @file @@ -9,11 +33,8 @@ * */ -//************************* -// GPL reminder to be added -//************************* +#include -#include /* configuration information */ @@ -23,43 +44,26 @@ /* configuration information */ -#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER -#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER - -#define CONFIGURE_MAXIMUM_TASKS 21 // number of tasks concurrently active including INIT -#define CONFIGURE_RTEMS_INIT_TASKS_TABLE -#define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) -#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 -#define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100 -#define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT) -#define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT) -#define CONFIGURE_MAXIMUM_DRIVERS 16 -#define CONFIGURE_MAXIMUM_PERIODS 6 // [hous] [load] [avgv] -#define CONFIGURE_MAXIMUM_TIMERS 6 // [spiq] [link] [spacewire_reset_link] -#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5 -#ifdef PRINT_STACK_REPORT - #define CONFIGURE_STACK_CHECKER_ENABLED -#endif +#include #include /* If --drvmgr was enabled during the configuration of the RTEMS kernel */ #ifdef RTEMS_DRVMGR_STARTUP -#ifdef LEON3 -/* Add Timer and UART Driver */ + #ifdef LEON3 + /* Add Timer and UART Driver */ -#ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER -#define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER -#endif + #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER + #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER + #endif -#ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER -#define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART -#endif + #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER + #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART + #endif -#endif -#define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */ - -#include + #endif + #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */ + #include #endif #include "fsw_init.h" @@ -376,6 +380,8 @@ void create_names( void ) // create all Task_name[TASKID_PRC1] = rtems_build_name( 'P', 'R', 'C', '1' ); Task_name[TASKID_AVF2] = rtems_build_name( 'A', 'V', 'F', '2' ); Task_name[TASKID_PRC2] = rtems_build_name( 'P', 'R', 'C', '2' ); + Task_name[TASKID_SCRB] = rtems_build_name( 'S', 'C', 'R', 'B' ); + Task_name[TASKID_CALI] = rtems_build_name( 'C', 'A', 'L', 'I' ); // rate monotonic period names name_hk_rate_monotonic = rtems_build_name( 'H', 'O', 'U', 'S' ); @@ -561,6 +567,14 @@ int create_all_tasks( void ) // create a RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB] ); } + if (status == RTEMS_SUCCESSFUL) // SCRUBBING TASK + { + status = rtems_task_create( + Task_name[TASKID_SCRB], TASK_PRIORITY_SCRB, RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_SCRB] + ); + } if (status == RTEMS_SUCCESSFUL) // HOUS { status = rtems_task_create( @@ -577,6 +591,14 @@ int create_all_tasks( void ) // create a RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_AVGV] ); } + if (status == RTEMS_SUCCESSFUL) // CALI + { + status = rtems_task_create( + Task_name[TASKID_CALI], TASK_PRIORITY_CALI, RTEMS_MINIMUM_STACK_SIZE, + RTEMS_DEFAULT_MODES, + RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_CALI] + ); + } return status; } @@ -746,6 +768,13 @@ int start_all_tasks( void ) // start all BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n") } } + if (status == RTEMS_SUCCESSFUL) // SCRUBBING + { + status = rtems_task_start( Task_id[TASKID_SCRB], scrubbing_task, 1 ); + if (status!=RTEMS_SUCCESSFUL) { + BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n") + } + } if (status == RTEMS_SUCCESSFUL) // LOAD { status = rtems_task_start( Task_id[TASKID_LOAD], load_task, 1 ); @@ -753,11 +782,18 @@ int start_all_tasks( void ) // start all BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n") } } + if (status == RTEMS_SUCCESSFUL) // CALI + { + status = rtems_task_start( Task_id[TASKID_CALI], calibration_sweep_task, 1 ); + if (status!=RTEMS_SUCCESSFUL) { + BOOT_PRINTF("in INIT *** Error starting TASK_LOAD\n") + } + } return status; } -rtems_status_code create_message_queues( void ) // create the two message queues used in the software +rtems_status_code create_message_queues( void ) // create the five message queues used in the software { rtems_status_code status_recv; rtems_status_code status_send; @@ -917,6 +953,11 @@ rtems_status_code get_message_queue_id_p return status; } +/** + * @brief update_queue_max_count returns max(fifo_size_max, pending_messages + 1) + * @param queue_id + * @param fifo_size_max + */ void update_queue_max_count( rtems_id queue_id, unsigned char*fifo_size_max ) { u_int32_t count; @@ -941,6 +982,20 @@ void update_queue_max_count( rtems_id qu } } +/** + * @brief init_ring initializes given ring buffer + * @param ring array of nodes to initialize + * @param nbNodes number of node in the ring buffer + * @param buffer memory space given to the ring buffer + * @param bufferSize size of the whole ring buffer memory space + * + * @details This function creates a circular buffer from a given number of nodes and a given memory space. It first sets all nodes attributes to thier defaults values + * and associates a portion of the given memory space with each node. Then it connects each nodes to build a circular buffer. + * + * Each node capacity will be bufferSize/nbNodes. + * + * https://en.wikipedia.org/wiki/Circular_buffer + */ void init_ring(ring_node ring[], unsigned char nbNodes, volatile int buffer[], unsigned int bufferSize ) { unsigned char i; diff --git a/src/fsw_misc.c b/src/fsw_misc.c --- a/src/fsw_misc.c +++ b/src/fsw_misc.c @@ -1,3 +1,27 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + /** General usage functions and RTEMS tasks. * * @file @@ -85,7 +109,7 @@ void timer_set_clock_divider(unsigned ch gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz } -// WATCHDOG +// WATCHDOG, this ISR should never be triggered. rtems_isr watchdog_isr( rtems_vector_number vector ) { @@ -183,8 +207,11 @@ void set_apbuart_scaler_reload_register( BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value) } -//************ -// RTEMS TASKS +/** + * @brief load_task starts and keeps the watchdog alive. + * @param argument + * @return + */ rtems_task load_task(rtems_task_argument argument) { @@ -233,6 +260,11 @@ rtems_task load_task(rtems_task_argument } } +/** + * @brief hous_task produces and sends HK each seconds + * @param argument + * @return + */ rtems_task hous_task(rtems_task_argument argument) { rtems_status_code status; @@ -347,6 +379,12 @@ rtems_task hous_task(rtems_task_argument return; } +/** + * @brief filter is a Direct-Form-II filter implementation, mostly used to filter electric field for HK + * @param x, new sample + * @param ctx, filter context, used to store previous input and output samples + * @return a new filtered sample + */ int filter( int x, filter_ctx* ctx ) { static const int b[NB_COEFFS][NB_COEFFS]={ {B00, B01, B02}, {B10, B11, B12}, {B20, B21, B22} }; @@ -376,6 +414,11 @@ int filter( int x, filter_ctx* ctx ) return x; } +/** + * @brief avgv_task pruduces HK rate elctrical field from F3 data + * @param argument + * @return + */ rtems_task avgv_task(rtems_task_argument argument) { #define MOVING_AVERAGE 16 @@ -521,6 +564,74 @@ rtems_task dumb_task( rtems_task_argumen } } +rtems_task scrubbing_task( rtems_task_argument unused ) +{ + /** This RTEMS taks is used to avoid entering IDLE task and also scrub memory to increase scubbing frequency. + * + * @param unused is the starting argument of the RTEMS task + * + * The scrubbing reads continuously memory when no other tasks are ready. + * + */ + + BOOT_PRINTF("in SCRUBBING *** \n"); + volatile int i=0; + volatile float valuef = 1.; + volatile uint32_t* RAM=(uint32_t*)0x40000000; + volatile uint32_t value; +#ifdef ENABLE_SCRUBBING_COUNTER + housekeeping_packet.lfr_fpga_version[BYTE_0] = 0; +#endif + while(1){ + i=(i+1)%(1024*1024); + valuef += 10.f*(float)RAM[i]; +#ifdef ENABLE_SCRUBBING_COUNTER + if(i==0) + { + housekeeping_packet.lfr_fpga_version[BYTE_0] += 1; + } +#endif + } +} + +rtems_task calibration_sweep_task( rtems_task_argument unused ) +{ + /** This RTEMS taks is used to change calibration signal smapling frequency between snapshots. + * + * @param unused is the starting argument of the RTEMS task + * + * If calibration is enabled, this task will divide by two the calibration signal smapling frequency between snapshots. + * When minimum sampling frequency is reach it will jump to maximum sampling frequency to loop indefinitely. + * + */ + rtems_event_set event_out; + BOOT_PRINTF("in calibration sweep *** \n"); + rtems_interval ticks_per_seconds = rtems_clock_get_ticks_per_second(); + while(1){ + // Waiting for next F0 snapshot + rtems_event_receive(RTEMS_EVENT_CAL_SWEEP_WAKE, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); + if(time_management_regs->calDACCtrl & BIT_CAL_ENABLE) + { + unsigned int delta_snapshot; + delta_snapshot = (parameter_dump_packet.sy_lfr_n_swf_p[0] * CONST_256) + + parameter_dump_packet.sy_lfr_n_swf_p[1]; + // We are woken almost in the center of a snapshot -> let's wait for sy_lfr_n_swf_p / 2 + rtems_task_wake_after( ticks_per_seconds * delta_snapshot / 2); + if(time_management_regs->calDivisor >= CAL_F_DIVISOR_MAX){ + time_management_regs->calDivisor = CAL_F_DIVISOR_MIN; + } + else{ + time_management_regs->calDivisor *= 2; + } + } + + + + } + +} + + //***************************** // init housekeeping parameters @@ -633,64 +744,6 @@ unsigned long long int getTimeAsUnsigned return time; } -void send_dumb_hk( void ) -{ - Packet_TM_LFR_HK_t dummy_hk_packet; - unsigned char *parameters; - unsigned int i; - rtems_id queue_id; - - queue_id = RTEMS_ID_NONE; - - dummy_hk_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; - dummy_hk_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; - dummy_hk_packet.reserved = DEFAULT_RESERVED; - dummy_hk_packet.userApplication = CCSDS_USER_APP; - dummy_hk_packet.packetID[0] = (unsigned char) (APID_TM_HK >> SHIFT_1_BYTE); - dummy_hk_packet.packetID[1] = (unsigned char) (APID_TM_HK); - dummy_hk_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; - dummy_hk_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; - dummy_hk_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_HK >> SHIFT_1_BYTE); - dummy_hk_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_HK ); - dummy_hk_packet.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; - dummy_hk_packet.serviceType = TM_TYPE_HK; - dummy_hk_packet.serviceSubType = TM_SUBTYPE_HK; - dummy_hk_packet.destinationID = TM_DESTINATION_ID_GROUND; - dummy_hk_packet.time[0] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_3_BYTES); - dummy_hk_packet.time[1] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_2_BYTES); - dummy_hk_packet.time[BYTE_2] = (unsigned char) (time_management_regs->coarse_time >> SHIFT_1_BYTE); - dummy_hk_packet.time[BYTE_3] = (unsigned char) (time_management_regs->coarse_time); - dummy_hk_packet.time[BYTE_4] = (unsigned char) (time_management_regs->fine_time >> SHIFT_1_BYTE); - dummy_hk_packet.time[BYTE_5] = (unsigned char) (time_management_regs->fine_time); - dummy_hk_packet.sid = SID_HK; - - // init status word - dummy_hk_packet.lfr_status_word[0] = INT8_ALL_F; - dummy_hk_packet.lfr_status_word[1] = INT8_ALL_F; - // init software version - dummy_hk_packet.lfr_sw_version[0] = SW_VERSION_N1; - dummy_hk_packet.lfr_sw_version[1] = SW_VERSION_N2; - dummy_hk_packet.lfr_sw_version[BYTE_2] = SW_VERSION_N3; - dummy_hk_packet.lfr_sw_version[BYTE_3] = SW_VERSION_N4; - // init fpga version - parameters = (unsigned char *) (REGS_ADDR_WAVEFORM_PICKER + APB_OFFSET_VHDL_REV); - dummy_hk_packet.lfr_fpga_version[BYTE_0] = parameters[BYTE_1]; // n1 - dummy_hk_packet.lfr_fpga_version[BYTE_1] = parameters[BYTE_2]; // n2 - dummy_hk_packet.lfr_fpga_version[BYTE_2] = parameters[BYTE_3]; // n3 - - parameters = (unsigned char *) &dummy_hk_packet.hk_lfr_cpu_load; - - for (i=0; i<(BYTE_POS_HK_REACTION_WHEELS_FREQUENCY - BYTE_POS_HK_LFR_CPU_LOAD); i++) - { - parameters[i] = INT8_ALL_F; - } - - get_message_queue_id_send( &queue_id ); - - rtems_message_queue_send( queue_id, &dummy_hk_packet, - PACKET_LENGTH_HK + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); -} - void get_temperatures( unsigned char *temperatures ) { unsigned char* temp_scm_ptr; @@ -732,24 +785,41 @@ void get_v_e1_e2_f3( unsigned char *spac spacecraft_potential[BYTE_5] = e2_ptr[1]; } +/** + * @brief get_cpu_load, computes CPU load, CPU load average and CPU load max + * @param resource_statistics stores: + * - CPU load at index 0 + * - CPU load max at index 1 + * - CPU load average at index 2 + * + * The CPU load average is computed on the last 60 values with a simple moving average. + */ void get_cpu_load( unsigned char *resource_statistics ) { +#define LOAD_AVG_SIZE 60 + static unsigned char cpu_load_hist[LOAD_AVG_SIZE]={0}; + static char old_avg_pos=0; + static unsigned int cpu_load_avg; unsigned char cpu_load; cpu_load = lfr_rtems_cpu_usage_report(); // HK_LFR_CPU_LOAD - resource_statistics[0] = cpu_load; + resource_statistics[BYTE_0] = cpu_load; // HK_LFR_CPU_LOAD_MAX - if (cpu_load > resource_statistics[1]) + if (cpu_load > resource_statistics[BYTE_1]) { - resource_statistics[1] = cpu_load; + resource_statistics[BYTE_1] = cpu_load; } + cpu_load_avg = cpu_load_avg - (unsigned int)cpu_load_hist[(int)old_avg_pos] + (unsigned int)cpu_load; + cpu_load_hist[(int)old_avg_pos] = cpu_load; + old_avg_pos += 1; + old_avg_pos %= LOAD_AVG_SIZE; // CPU_LOAD_AVE - resource_statistics[BYTE_2] = 0; - + resource_statistics[BYTE_2] = (unsigned char)(cpu_load_avg / LOAD_AVG_SIZE); +// this will change the way LFR compute usage #ifndef PRINT_TASK_STATISTICS rtems_cpu_usage_reset(); #endif @@ -840,6 +910,7 @@ void increment_hk_counter( unsigned char *counter = *counter + delta; } +// Low severity error counters update void hk_lfr_le_update( void ) { static hk_lfr_le_t old_hk_lfr_le = {0}; @@ -910,6 +981,7 @@ void hk_lfr_le_update( void ) housekeeping_packet.hk_lfr_le_cnt[1] = (unsigned char) (counter & BYTE1_MASK); } +// Medium severity error counters update void hk_lfr_me_update( void ) { static hk_lfr_me_t old_hk_lfr_me = {0}; @@ -942,6 +1014,7 @@ void hk_lfr_me_update( void ) housekeeping_packet.hk_lfr_me_cnt[1] = (unsigned char) (counter & BYTE1_MASK); } +// High severity error counters update void hk_lfr_le_me_he_update() { diff --git a/src/fsw_spacewire.c b/src/fsw_spacewire.c --- a/src/fsw_spacewire.c +++ b/src/fsw_spacewire.c @@ -1,3 +1,27 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + /** Functions related to the SpaceWire interface. * * @file @@ -281,11 +305,11 @@ rtems_task send_task( rtems_task_argumen { spw_send_waveform_CWF( incomingRingNodePtr, &headerCWF ); } - else if ( (sid==SID_NORM_SWF_F0) || (sid== SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) ) + else if ( (sid==SID_NORM_SWF_F0) || (sid==SID_NORM_SWF_F1) || (sid==SID_NORM_SWF_F2) ) { spw_send_waveform_SWF( incomingRingNodePtr, &headerSWF ); } - else if ( (sid==SID_NORM_CWF_F3) ) + else if (sid==SID_NORM_CWF_F3) { spw_send_waveform_CWF3_light( incomingRingNodePtr, &headerCWF ); } @@ -301,7 +325,7 @@ rtems_task send_task( rtems_task_argumen { spw_send_asm_f2( incomingRingNodePtr, &headerASM ); } - else if ( sid==TM_CODE_K_DUMP ) + else if (sid==TM_CODE_K_DUMP) { spw_send_k_dump( incomingRingNodePtr ); } @@ -620,23 +644,6 @@ void spacewire_read_statistics( void ) // clear the counters status = ioctl( fdSPW, SPACEWIRE_IOCTRL_CLR_STATISTICS ); -// typedef struct { -// unsigned int tx_link_err; // NOT IN HK -// unsigned int rx_rmap_header_crc_err; // NOT IN HK -// unsigned int rx_rmap_data_crc_err; // NOT IN HK -// unsigned int rx_eep_err; -// unsigned int rx_truncated; -// unsigned int parity_err; -// unsigned int escape_err; -// unsigned int credit_err; -// unsigned int write_sync_err; -// unsigned int disconnect_err; -// unsigned int early_ep; -// unsigned int invalid_address; -// unsigned int packets_sent; -// unsigned int packets_received; -// } spw_stats; - // rx_eep_err grspw_stats.rx_eep_err = grspw_stats.rx_eep_err + current.rx_eep_err; // rx_truncated @@ -685,23 +692,6 @@ void spacewire_get_last_error( void ) coarseTime = time_management_regs->coarse_time; fineTime = time_management_regs->fine_time; - // typedef struct { - // unsigned int tx_link_err; // NOT IN HK - // unsigned int rx_rmap_header_crc_err; // NOT IN HK - // unsigned int rx_rmap_data_crc_err; // NOT IN HK - // unsigned int rx_eep_err; - // unsigned int rx_truncated; - // unsigned int parity_err; - // unsigned int escape_err; - // unsigned int credit_err; - // unsigned int write_sync_err; - // unsigned int disconnect_err; - // unsigned int early_ep; - // unsigned int invalid_address; - // unsigned int packets_sent; - // unsigned int packets_received; - // } spw_stats; - // tx_link_err *** no code associated to this field // rx_rmap_header_crc_err *** LE *** in HK if (previous.rx_rmap_header_crc_err != current.rx_rmap_header_crc_err) @@ -1539,6 +1529,11 @@ void spw_send_asm_f1( ring_node *ring_no } } +/** + * @brief spw_send_asm_f2 Sends an ASM packet at F2 over spacewire + * @param ring_node_to_send node pointing to the actual buffer to send + * @param header + */ void spw_send_asm_f2( ring_node *ring_node_to_send, Header_TM_LFR_SCIENCE_ASM_t *header ) { @@ -1606,6 +1601,10 @@ void spw_send_asm_f2( ring_node *ring_no } } +/** + * @brief spw_send_k_dump Sends k coefficients dump packet over spacewire + * @param ring_node_to_send node pointing to the actual buffer to send + */ void spw_send_k_dump( ring_node *ring_node_to_send ) { rtems_status_code status; diff --git a/src/lfr_cpu_usage_report.c b/src/lfr_cpu_usage_report.c --- a/src/lfr_cpu_usage_report.c +++ b/src/lfr_cpu_usage_report.c @@ -12,10 +12,14 @@ */ #include "lfr_cpu_usage_report.h" +#include "fsw_params.h" + +extern rtems_id Task_id[]; unsigned char lfr_rtems_cpu_usage_report( void ) { uint32_t api_index; + uint32_t information_index; Thread_Control *the_thread; Objects_Information *information; uint32_t ival; @@ -24,8 +28,9 @@ unsigned char lfr_rtems_cpu_usage_report Timestamp_Control uptime; Timestamp_Control total; Timestamp_Control ran; + #else - uint32_t total_units = 0; + #error "Can't compute CPU usage using ticks on LFR" #endif unsigned char cpu_load; @@ -33,33 +38,6 @@ unsigned char lfr_rtems_cpu_usage_report ival = 0; cpu_load = 0; - /* - * When not using nanosecond CPU usage resolution, we have to count - * the number of "ticks" we gave credit for to give the user a rough - * guideline as to what each number means proportionally. - */ -#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ - _TOD_Get_uptime( &uptime ); - _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total ); -#else - for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) { - if ( !_Objects_Information_table[ api_index ] ) { } - else - { - information = _Objects_Information_table[ api_index ][ 1 ]; - if ( information != NULL ) - { - for ( i=1 ; i <= information->maximum ; i++ ) { - the_thread = (Thread_Control *)information->local_table[ i ]; - - if ( the_thread != NULL ) { - total_units += the_thread->cpu_time_used; } - } - } - } - } -#endif - for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) { if ( !_Objects_Information_table[ api_index ] ) { } @@ -68,50 +46,23 @@ unsigned char lfr_rtems_cpu_usage_report information = _Objects_Information_table[ api_index ][ 1 ]; if ( information != NULL ) { - the_thread = (Thread_Control *)information->local_table[ 1 ]; - - if ( the_thread == NULL ) { } - else + for(information_index=1;information_index<=information->maximum;information_index++) { - #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ - /* - * If this is the currently executing thread, account for time - * since the last context switch. - */ - ran = the_thread->cpu_time_used; - if ( _Thread_Executing->Object.id == the_thread->Object.id ) + the_thread = (Thread_Control *)information->local_table[ information_index ]; + + if ( the_thread == NULL) { } + else if(the_thread->Object.id == Task_id[TASKID_SCRB]) // Only measure scrubbing task load, CPU load is 100%-Scrubbing { - Timestamp_Control used; - _Timestamp_Subtract( - &_Thread_Time_of_last_context_switch, &uptime, &used - ); - _Timestamp_Add_to( &ran, &used ); + _TOD_Get_uptime( &uptime ); + _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total ); + ran = the_thread->cpu_time_used; + _Timestamp_Divide( &ran, &total, &ival, &fval); + cpu_load = (unsigned char)(CONST_255 - ((ival*CONST_10+fval/CONST_100)*CONST_256/CONST_1000)); } - _Timestamp_Divide( &ran, &total, &ival, &fval ); - - #else - if (total_units != 0) - { - uint64_t ival_64; - - ival_64 = the_thread->cpu_time_used; - ival_64 *= CONST_100000; - ival = ival_64 / total_units; - } - else - { - ival = 0; - } - - fval = ival % CONST_1000; - ival /= CONST_1000; - #endif } } } } - cpu_load = (unsigned char) (CONST_100 - ival); - return cpu_load; } diff --git a/src/processing/avf0_prc0.c b/src/processing/avf0_prc0.c --- a/src/processing/avf0_prc0.c +++ b/src/processing/avf0_prc0.c @@ -1,3 +1,27 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + /** Functions related to data processing. * * @file diff --git a/src/processing/avf1_prc1.c b/src/processing/avf1_prc1.c --- a/src/processing/avf1_prc1.c +++ b/src/processing/avf1_prc1.c @@ -1,3 +1,27 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + /** Functions related to data processing. * * @file diff --git a/src/processing/avf2_prc2.c b/src/processing/avf2_prc2.c --- a/src/processing/avf2_prc2.c +++ b/src/processing/avf2_prc2.c @@ -1,3 +1,27 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + /** Functions related to data processing. * * @file diff --git a/src/processing/fsw_processing.c b/src/processing/fsw_processing.c --- a/src/processing/fsw_processing.c +++ b/src/processing/fsw_processing.c @@ -1,3 +1,27 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + /** Functions related to data processing. * * @file @@ -583,6 +607,12 @@ unsigned char getSID( rtems_event_set ev return sid; } +/** + * @brief extractReImVectors converts a given ASM component from interleaved to split representation + * @param inputASM + * @param outputASM + * @param asmComponent + */ void extractReImVectors( float *inputASM, float *outputASM, unsigned int asmComponent ) { unsigned int i; @@ -597,6 +627,12 @@ void extractReImVectors( float *inputASM } } +/** + * @brief copyReVectors copies real part of a given ASM from inputASM to outputASM + * @param inputASM + * @param outputASM + * @param asmComponent + */ void copyReVectors( float *inputASM, float *outputASM, unsigned int asmComponent ) { unsigned int i; @@ -608,6 +644,13 @@ void copyReVectors( float *inputASM, flo } } +/** + * @brief ASM_patch, converts ASM from interleaved to split representation + * @param inputASM + * @param outputASM + * @note inputASM and outputASM must be different, in other words this function can't do in place convertion + * @see extractReImVectors + */ void ASM_patch( float *inputASM, float *outputASM ) { extractReImVectors( inputASM, outputASM, ASM_COMP_B1B2); // b1b2 @@ -718,6 +761,14 @@ int getFBinMask( int index, unsigned cha return fbin; } +/** + * @brief isPolluted returns MATRIX_IS_POLLUTED if there is any overlap between t0:t1 and tbad0:tbad1 ranges + * @param t0 Start acquisition time + * @param t1 End of acquisition time + * @param tbad0 Start time of poluting signal + * @param tbad1 End time of poluting signal + * @return + */ unsigned char isPolluted( u_int64_t t0, u_int64_t t1, u_int64_t tbad0, u_int64_t tbad1 ) { unsigned char polluted; @@ -735,6 +786,13 @@ unsigned char isPolluted( u_int64_t t0, return polluted; } +/** + * @brief acquisitionTimeIsValid checks if the given acquisition time is poluted by PAS + * @param coarseTime Coarse acquisition time of the given SM + * @param fineTime Fine acquisition time of the given ASM + * @param channel Frequency channel to check, will impact SM time footprint + * @return MATRIX_IS_POLLUTED if there is any time overlap between SM and PAS poluting signal + */ unsigned char acquisitionTimeIsValid( unsigned int coarseTime, unsigned int fineTime, unsigned char channel) { u_int64_t t0; diff --git a/src/tc_acceptance.c b/src/tc_acceptance.c --- a/src/tc_acceptance.c +++ b/src/tc_acceptance.c @@ -1,3 +1,26 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ /** Functions related to TeleCommand acceptance. * * @file diff --git a/src/tc_handler.c b/src/tc_handler.c --- a/src/tc_handler.c +++ b/src/tc_handler.c @@ -1,3 +1,26 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ /** Functions and tasks related to TeleCommand handling. * * @file diff --git a/src/tc_load_dump_parameters.c b/src/tc_load_dump_parameters.c --- a/src/tc_load_dump_parameters.c +++ b/src/tc_load_dump_parameters.c @@ -1,3 +1,27 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + /** Functions to load and dump parameters in the LFR registers. * * @file @@ -445,7 +469,6 @@ int action_dump_kcoefficients(ccsdsTelec { kcoefficients_dump_1.kcoeff_blks[ (freq*KCOEFF_BLK_SIZE) + 1] = freq; bin = freq; -// printKCoefficients( freq, bin, k_coeff_intercalib_f0_norm); for ( coeff=0; coeffpacketLength[1]; TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0]; TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1]; -// TM.rcv_crc[0] = packetDataField[ packetLength - 1 ]; -// TM.rcv_crc[1] = packetDataField[ packetLength ]; TM.rcv_crc[0] = packetDataField[ estimatedPacketLength - 1 ]; TM.rcv_crc[1] = packetDataField[ estimatedPacketLength ]; TM.computed_crc[0] = computed_CRC[0]; diff --git a/src/wf_handler.c b/src/wf_handler.c --- a/src/wf_handler.c +++ b/src/wf_handler.c @@ -1,3 +1,27 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + /** Functions and tasks related to waveform packet generation. * * @file @@ -204,6 +228,7 @@ inline void waveform_isr_normal_sbm1_sbm } // send an event to the WFRM task for resynchro activities status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_SWF_RESYNCH ); + status = rtems_event_send( Task_id[TASKID_CALI], RTEMS_EVENT_CAL_SWEEP_WAKE ); } //*** @@ -841,11 +866,9 @@ void build_snapshot_from_ring( ring_node node = 0; while ( node < nb_ring_nodes) { - //PRINTF1("%d ... ", node); bufferAcquisitionTime_asLong = get_acquisition_time( (unsigned char *) &ring_node_to_send->coarseTime ); if (bufferAcquisitionTime_asLong <= acquisitionTime_asLong) { - //PRINTF1("buffer found with acquisition time = %llx\n", bufferAcquisitionTime_asLong); node = nb_ring_nodes; } else @@ -858,7 +881,6 @@ void build_snapshot_from_ring( ring_node // (5) compute the number of samples to take in the current buffer sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> SHIFT_2_BYTES; nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong; - //PRINTF2("sampleOffset_asLong = %lld, nbSamplesPart1_asLong = %lld\n", sampleOffset_asLong, nbSamplesPart1_asLong); // (6) compute the final acquisition time acquisitionTime_asLong = bufferAcquisitionTime_asLong + @@ -881,7 +903,7 @@ void build_snapshot_from_ring( ring_node timeCharPtr = (unsigned char*) &ring_node_to_send->coarseTime; ptr2[0] = ptr2[0] | (timeCharPtr[0] & SYNC_BIT); // [1000 0000] - if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) ) + if ( (nbSamplesPart1_asLong > NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) ) { nbSamplesPart1_asLong = 0; } @@ -1341,3 +1363,4 @@ void increment_seq_counter_source_id( un // RESTORE THE MODE OF THE CALLING TASK status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, ¤t_mode_set ); } + diff --git a/testbenches/fsw_matrices_handling/functions.h b/testbenches/fsw_matrices_handling/functions.h --- a/testbenches/fsw_matrices_handling/functions.h +++ b/testbenches/fsw_matrices_handling/functions.h @@ -1,9 +1,32 @@ +/*------------------------------------------------------------------------------ +-- Solar Orbiter's Low Frequency Receiver Flight Software (LFR FSW), +-- This file is a part of the LFR FSW +-- Copyright (C) 2012-2018, Plasma Physics Laboratory - CNRS +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 2 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program; if not, write to the Free Software +-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +-------------------------------------------------------------------------------*/ +/*-- Author : Paul Leroy +-- Contact : Alexis Jeandet +-- Mail : alexis.jeandet@lpp.polytechnique.fr +----------------------------------------------------------------------------*/ + #define NB_VALUES_PER_SM 25 #define NB_BINS_PER_SM 128 #define NB_BINS_COMPRESSED_SM_F0 11 #define ASM_F0_INDICE_START 17 // 88 bins -#define ASM_F0_INDICE_STOP 104 // 2 packets of 44 bins #define NB_BINS_TO_AVERAGE_ASM_F0 8 void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider ) diff --git a/timegen/CMakeLists.txt b/timegen/CMakeLists.txt deleted file mode 100644 --- a/timegen/CMakeLists.txt +++ /dev/null @@ -1,88 +0,0 @@ -cmake_minimum_required (VERSION 2.6) -project (timegen) - -include(sparc-rtems) - -include_directories("./src" - "./header" - "./header/processing" - "./src/LFR_basic-parameters") - -set(SOURCES src/tc_handler.c - src/fsw_misc.c - src/fsw_init.c - src/fsw_globals.c - src/fsw_spacewire.c - src/tc_acceptance.c - ../LFR_basic-parameters/basic_parameters.c - header/tc_handler.h - header/grlib_regs.h - header/fsw_params.h - header/fsw_misc.h - header/fsw_init.h - header/ccsds_types.h - header/fsw_spacewire.h - header/tc_acceptance.h - header/fsw_params_nb_bytes.h - header/fsw_params_processing.h - header/fsw_params_wf_handler.h - header/lfr_cpu_usage_report.h - ../LFR_basic-parameters/basic_parameters.h - ../LFR_basic-parameters/basic_parameters_params.h - header/TC_types.h - ) - - -option(timegen_verbose "Enable verbose Timegen" ON) -option(timegen_boot_messages "Enable Timegen boot messages" ON) -option(timegen_debug_messages "Enable Timegen debug messages" ON) -option(timegen_cpu_usage_report "Enable Timegen cpu usage report" OFF) -option(timegen_stack_report "Enable Timegen stack report" OFF) -option(timegen_vhdl_dev "?" OFF) -option(timegen_lpp_dpu_destid "Set to debug at LPP" ON) -option(timegen_debug_watchdog "Enable debug watchdog" OFF) -option(timegen_debug_tch "?" OFF) - -set(TIMEGEN_SW_VERSION_N1 "3" CACHE STRING "Choose N1 FSW Version." FORCE) -set(TIMEGEN_SW_VERSION_N2 "1" CACHE STRING "Choose N2 FSW Version." FORCE) -set(TIMEGEN_SW_VERSION_N3 "0" CACHE STRING "Choose N3 FSW Version." FORCE) -set(TIMEGEN_SW_VERSION_N4 "4" CACHE STRING "Choose N4 FSW Version." FORCE) - - -if (timegen_verbose) - add_definitions(-DPRINT_MESSAGES_ON_CONSOLE) -endif() -if (timegen_boot_messages) - add_definitions(-DBOOT_MESSAGES) -endif() -if (timegen_debug_messages) - add_definitions(-DDEBUG_MESSAGES) -endif() -if (timegen_cpu_usage_report) - add_definitions(-DPRINT_TASK_STATISTICS) -endif() -if (timegen_stack_report) - add_definitions(-DPRINT_STACK_REPORT) -endif() -if (timegen_vhdl_dev) - add_definitions(-DVHDL_DEV) -endif() -if (timegen_lpp_dpu_destid) - add_definitions(-DLPP_DPU_DESTID) -endif() -if (timegen_debug_watchdog) - add_definitions(-DDEBUG_WATCHDOG) -endif() -if (timegen_debug_tch) - add_definitions(-DDEBUG_TCH) -endif() - -add_definitions(-DMSB_FIRST_TCH) - -add_definitions(-DSWVERSION=-1-0) -add_definitions(-DSW_VERSION_N1=${TIMEGEN_SW_VERSION_N1}) -add_definitions(-DSW_VERSION_N2=${TIMEGEN_SW_VERSION_N2}) -add_definitions(-DSW_VERSION_N3=${TIMEGEN_SW_VERSION_N3}) -add_definitions(-DSW_VERSION_N4=${TIMEGEN_SW_VERSION_N4}) - -add_executable(timegen ${SOURCES}) diff --git a/timegen/block diagram.odg b/timegen/block diagram.odg deleted file mode 100644 index 1cc44703ad1c913fd2d8558c55fad134bae2ec21..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 GIT binary patch literal 0 Hc$@ - -#define PROTOCOLE_IDENTIFIER 0x02 - -// PACKET ID -#define TC_LFR_PACKET_ID 0x1ccc // PID 76 CAT 12 - -#define PACKET_LENGTH_TC_LFR_RESET (12 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_LFR_LOAD_COMMON_PAR (14 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_LFR_LOAD_NORMAL_PAR (22 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_LFR_LOAD_BURST_PAR (14 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_LFR_LOAD_SBM1_PAR (14 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_LFR_LOAD_SBM2_PAR (14 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_LFR_DUMP_PAR (12 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_LFR_ENTER_MODE (20 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_LFR_UPDATE_INFO (46 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_LFR_ENABLE_CALIBRATION (12 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_LFR_DISABLE_CALIBRATION (12 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_LFR_UPDATE_TIME (18 - CCSDS_TC_TM_PACKET_OFFSET) - -// TC TYPES -#define TC_TYPE_DEFAULT 181 -#define TC_TYPE_LFR_UPDATE_TIME 9 - -// TC SUBTYPES -#define TC_SUBTYPE_RESET 1 -#define TC_SUBTYPE_LOAD_COMMON_PAR 11 -#define TC_SUBTYPE_LOAD_NORMAL_PAR 13 -#define TC_SUBTYPE_LOAD_BURST_PAR 19 -#define TC_SUBTYPE_LOAD_SBM1_PAR 25 -#define TC_SUBTYPE_LOAD_SBM2_PAR 27 -#define TC_SUBTYPE_DUMP_PAR 31 -#define TC_SUBTYPE_ENTER_MODE 41 -#define TC_SUBTYPE_UPDATE_INFO 51 -#define TC_SUBTYPE_ENABLE_CALIBRATION 61 -#define TC_SUBTYPE_DISABLE_CALIBRATION 63 -#define TC_SUBTYPE_UPDATE_TIME 129 - -// OTHER CONSTANTS -#define TC_LFR_PACKET_SEQUENCE_CONTROL 0xc000 // PID 76 CAT 12 -#define TC_LFR_DATA_FIELD_HEADER0 0x19 -#define TC_LFR_LOAD_COMMON_PAR_SPARE 0x00 - -struct Packet_TC_LFR_RESET_str -{ // the CCSDS header is added by LPPMON - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char ccsdsSecHeaderFlag_pusVersion_ack; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char sourceID; - unsigned char crc[2]; -}; -typedef struct Packet_TC_LFR_RESET_str Packet_TC_LFR_RESET_t; - -struct Packet_TC_LFR_ENTER_MODE_str -{ // the CCSDS header is added by LPPMON - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char ccsdsSecHeaderFlag_pusVersion_ack; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char sourceID; - unsigned char spare; - unsigned char mode; - unsigned char enterModeTime[6]; - unsigned char crc[2]; -}; -typedef struct Packet_TC_LFR_ENTER_MODE_str Packet_TC_LFR_ENTER_MODE_t; - -struct Packet_TC_LFR_UPDATE_INFO_str -{ // the CCSDS header is added by LPPMON - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char ccsdsSecHeaderFlag_pusVersion_ack; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char sourceID; - unsigned char set1; - unsigned char set2; - unsigned char set3_bias_setting_set1[6]; - unsigned char set3_bias_setting_set2[6]; - unsigned char set3_bias_voltage[4]; - unsigned char set4[8]; - unsigned char set5; - unsigned char set6; - unsigned char set7[8]; - unsigned char crc[2]; -}; -typedef struct Packet_TC_LFR_UPDATE_INFO_str Packet_TC_LFR_UPDATE_INFO_t; - -struct Packet_TC_LFR_DUMP_PAR_str -{ // the CCSDS header is added by LPPMON - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char ccsdsSecHeaderFlag_pusVersion_ack; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char sourceID; - unsigned char crc[2]; - -}; -typedef struct Packet_TC_LFR_DUMP_PAR_str Packet_TC_LFR_DUMP_PAR_t; - -struct Packet_TC_LFR_LOAD_COMMON_PAR_str -{ // the CCSDS header is added by LPPMON - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char ccsdsSecHeaderFlag_pusVersion_ack; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char sourceID; - unsigned char spare; - unsigned char bw_sp0_sp1_r0_r1; - unsigned char crc[2]; - -}; -typedef struct Packet_TC_LFR_LOAD_COMMON_PAR_str Packet_TC_LFR_LOAD_COMMON_PAR_t; - -struct Packet_TC_LFR_LOAD_NORMAL_PAR_str -{ // the CCSDS header is added by LPPMON - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char ccsdsSecHeaderFlag_pusVersion_ack; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char sourceID; - unsigned char sy_lfr_n_swf_l[2]; - unsigned char sy_lfr_n_swf_p[2]; - unsigned char sy_lfr_n_asm_p[2]; - unsigned char sy_lfr_n_bp_p0; - unsigned char sy_lfr_n_bp_p1; - unsigned char sy_lfr_n_cwf_long_f3; - unsigned char lfr_normal_parameters_spare; - unsigned char crc[2]; -}; -typedef struct Packet_TC_LFR_LOAD_NORMAL_PAR_str Packet_TC_LFR_LOAD_NORMAL_PAR_t; - -struct Packet_TC_LFR_LOAD_BURST_SBM1_SBM2_PAR_str -{ // the CCSDS header is added by LPPMON - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char ccsdsSecHeaderFlag_pusVersion_ack; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char sourceID; - unsigned char sy_lfr_bp_p0; - unsigned char sy_lfr_bp_p1; - unsigned char crc[2]; -}; -typedef struct Packet_TC_LFR_LOAD_BURST_SBM1_SBM2_PAR_str Packet_TC_LFR_LOAD_BURST_SBM1_SBM2_PAR_t; - -struct Packet_TC_LFR_ENABLE_DISABLE_CALIBRATION_str -{ // the CCSDS header is added by LPPMON - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char ccsdsSecHeaderFlag_pusVersion_ack; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char sourceID; - unsigned char crc[2]; -}; -typedef struct Packet_TC_LFR_ENABLE_DISABLE_CALIBRATION_str Packet_TC_LFR_ENABLE_DISABLE_CALIBRATION_t; - -struct Packet_TC_LFR_UPDATE_TIME_str -{ // the CCSDS header is added by LPPMON - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char ccsdsSecHeaderFlag_pusVersion_ack; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char sourceID; - unsigned char cp_rpw_time[6]; - unsigned char crc[2]; -}; -typedef struct Packet_TC_LFR_UPDATE_TIME_str Packet_TC_LFR_UPDATE_TIME_t; - -struct Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_str -{ - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - // - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char ccsdsSecHeaderFlag_pusVersion_ack; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char sourceID; - unsigned char cp_rpw_time[6]; - unsigned char crc[2]; -}; -typedef struct Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_str Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_t; - -#endif // TC_TYPES_H diff --git a/timegen/header/ccsds_types.h b/timegen/header/ccsds_types.h deleted file mode 100644 --- a/timegen/header/ccsds_types.h +++ /dev/null @@ -1,665 +0,0 @@ -#ifndef CCSDS_TYPES_H_INCLUDED -#define CCSDS_TYPES_H_INCLUDED - -#include "fsw_params_processing.h" - -#define CCSDS_PROTOCOLE_EXTRA_BYTES 4 -#define CCSDS_TC_TM_PACKET_OFFSET 7 -#define CCSDS_TELEMETRY_HEADER_LENGTH 16+4 -#define CCSDS_TM_PKT_MAX_SIZE 4412 -#define CCSDS_TELECOMMAND_HEADER_LENGTH 10+4 -#define CCSDS_TC_PKT_MAX_SIZE 256 -#define CCSDS_TC_PKT_MIN_SIZE 16 -#define CCSDS_PROCESS_ID 76 -#define CCSDS_PACKET_CATEGORY 12 -#define CCSDS_NODE_ADDRESS 0xfe -#define CCSDS_USER_APP 0x00 - -#define DEFAULT_SPARE1_PUSVERSION_SPARE2 0x10 -#define DEFAULT_RESERVED 0x00 -#define DEFAULT_HKBIA 0x1e // 0001 1110 - -// PACKET ID -#define APID_TM_TC_EXE 0x0cc1 // PID 76 CAT 1 -#define APID_TM_HK 0x0cc4 // PID 76 CAT 4 -#define APID_TM_PARAMETER_DUMP 0x0cc9 // PID 76 CAT 9 -#define APID_TM_SCIENCE_NORMAL_BURST 0x0ccc // PID 76 CAT 12 -#define APID_TM_SCIENCE_SBM1_SBM2 0x0cfc // PID 79 CAT 12 -#define TM_PACKET_PID_DEFAULT 76 -#define TM_PACKET_PID_BURST_SBM1_SBM2 79 -#define TM_PACKET_CAT_TC_EXE 1 -#define TM_PACKET_CAT_HK 4 -#define TM_PACKET_CAT_PARAMETER_DUMP 9 -#define TM_PACKET_CAT_SCIENCE 12 -#define TC_PACKET_CAT 12 - -// PACKET SEQUENCE CONTROL -#define TM_PACKET_SEQ_CTRL_CONTINUATION 0x00 // [0000 0000] -#define TM_PACKET_SEQ_CTRL_FIRST 0x40 // [0100 0000] -#define TM_PACKET_SEQ_CTRL_LAST 0x80 // [1000 0000] -#define TM_PACKET_SEQ_CTRL_STANDALONE 0xc0 // [1100 0000] -#define TM_PACKET_SEQ_CNT_DEFAULT 0x00 // [0000 0000] - -// DESTINATION ID -#define TM_DESTINATION_ID_GROUND 0 -#define TM_DESTINATION_ID_MISSION_TIMELINE 110 -#define TM_DESTINATION_ID_TC_SEQUENCES 111 -#define TM_DESTINATION_ID_RECOVERY_ACTION_COMMAND 112 -#define TM_DESTINATION_ID_BACKUP_MISSION_TIMELINE 113 -#define TM_DESTINATION_ID_DIRECT_CMD 120 -#define TM_DESTINATION_ID_SPARE_GRD_SRC1 121 -#define TM_DESTINATION_ID_SPARE_GRD_SRC2 122 -#define TM_DESTINATION_ID_OBCP 15 -#define TM_DESTINATION_ID_SYSTEM_CONTROL 14 -#define TM_DESTINATION_ID_AOCS 11 - -#define CCSDS_DESTINATION_ID 0x01 -#define CCSDS_PROTOCOLE_ID 0x02 -#define CCSDS_RESERVED 0x00 -#define CCSDS_USER_APP 0x00 - -#define SIZE_TM_LFR_TC_EXE_NOT_IMPLEMENTED 24 -#define SIZE_TM_LFR_TC_EXE_CORRUPTED 32 -#define SIZE_HK_PARAMETERS 112 - -// TC TYPES -#define TC_TYPE_GEN 181 -#define TC_TYPE_TIME 9 - -// TC SUBTYPES -#define TC_SUBTYPE_RESET 1 -#define TC_SUBTYPE_LOAD_COMM 11 -#define TC_SUBTYPE_LOAD_NORM 13 -#define TC_SUBTYPE_LOAD_BURST 19 -#define TC_SUBTYPE_LOAD_SBM1 25 -#define TC_SUBTYPE_LOAD_SBM2 27 -#define TC_SUBTYPE_DUMP 31 -#define TC_SUBTYPE_ENTER 41 -#define TC_SUBTYPE_UPDT_INFO 51 -#define TC_SUBTYPE_EN_CAL 61 -#define TC_SUBTYPE_DIS_CAL 63 -#define TC_SUBTYPE_UPDT_TIME 129 - -// TC LEN -#define TC_LEN_RESET 12 -#define TC_LEN_LOAD_COMM 14 -#define TC_LEN_LOAD_NORM 22 -#define TC_LEN_LOAD_BURST 14 -#define TC_LEN_LOAD_SBM1 14 -#define TC_LEN_LOAD_SBM2 14 -#define TC_LEN_DUMP 12 -#define TC_LEN_ENTER 20 -#define TC_LEN_UPDT_INFO 46 -#define TC_LEN_EN_CAL 12 -#define TC_LEN_DIS_CAL 12 -#define TC_LEN_UPDT_TIME 18 - -// TM TYPES -#define TM_TYPE_TC_EXE 1 -#define TM_TYPE_HK 3 -#define TM_TYPE_PARAMETER_DUMP 3 -#define TM_TYPE_LFR_SCIENCE 21 - -// TM SUBTYPES -#define TM_SUBTYPE_EXE_OK 7 -#define TM_SUBTYPE_EXE_NOK 8 -#define TM_SUBTYPE_HK 25 -#define TM_SUBTYPE_PARAMETER_DUMP 25 -#define TM_SUBTYPE_SCIENCE 3 -#define TM_SUBTYPE_LFR_SCIENCE 3 - -// FAILURE CODES -#define ILLEGAL_APID 0 -#define WRONG_LEN_PKT 1 -#define INCOR_CHECKSUM 2 -#define ILL_TYPE 3 -#define ILL_SUBTYPE 4 -#define WRONG_APP_DATA 5 // 0x00 0x05 -#define TC_NOT_EXE 42000 // 0xa4 0x10 -#define WRONG_SRC_ID 42001 // 0xa4 0x11 -#define FUNCT_NOT_IMPL 42002 // 0xa4 0x12 -#define FAIL_DETECTED 42003 // 0xa4 0x13 -#define NOT_ALLOWED 42004 // 0xa4 0x14 -#define CORRUPTED 42005 // 0xa4 0x15 -#define CCSDS_TM_VALID 7 - -// TC SID -#define SID_TC_GROUND 0 -#define SID_TC_MISSION_TIMELINE 110 -#define SID_TC_TC_SEQUENCES 111 -#define SID_TC_RECOVERY_ACTION_CMD 112 -#define SID_TC_BACKUP_MISSION_TIMELINE 113 -#define SID_TC_DIRECT_CMD 120 -#define SID_TC_SPARE_GRD_SRC1 121 -#define SID_TC_SPARE_GRD_SRC2 122 -#define SID_TC_OBCP 15 -#define SID_TC_SYSTEM_CONTROL 14 -#define SID_TC_AOCS 11 -#define SID_TC_RPW_INTERNAL 254 - -enum apid_destid{ - GROUND, - MISSION_TIMELINE, - TC_SEQUENCES, - RECOVERY_ACTION_CMD, - BACKUP_MISSION_TIMELINE, - DIRECT_CMD, - SPARE_GRD_SRC1, - SPARE_GRD_SRC2, - OBCP, - SYSTEM_CONTROL, - AOCS, - RPW_INTERNAL -}; -// SEQUENCE COUNTERS -#define SEQ_CNT_MAX 16383 -#define SEQ_CNT_NB_DEST_ID 12 - -// TM SID -#define SID_HK 1 -#define SID_PARAMETER_DUMP 10 - -#define SID_NORM_SWF_F0 3 -#define SID_NORM_SWF_F1 4 -#define SID_NORM_SWF_F2 5 -#define SID_NORM_CWF_F3 1 -#define SID_BURST_CWF_F2 2 -#define SID_SBM1_CWF_F1 24 -#define SID_SBM2_CWF_F2 25 -#define SID_NORM_ASM_F0 11 -#define SID_NORM_ASM_F1 12 -#define SID_NORM_ASM_F2 13 -#define SID_NORM_BP1_F0 14 -#define SID_NORM_BP1_F1 15 -#define SID_NORM_BP1_F2 16 -#define SID_NORM_BP2_F0 19 -#define SID_NORM_BP2_F1 20 -#define SID_NORM_BP2_F2 21 -#define SID_BURST_BP1_F0 17 -#define SID_BURST_BP2_F0 22 -#define SID_BURST_BP1_F1 18 -#define SID_BURST_BP2_F1 23 -#define SID_SBM1_BP1_F0 28 -#define SID_SBM1_BP2_F0 31 -#define SID_SBM2_BP1_F0 29 -#define SID_SBM2_BP2_F0 32 -#define SID_SBM2_BP1_F1 30 -#define SID_SBM2_BP2_F1 33 -#define SID_NORM_CWF_LONG_F3 34 - -// LENGTH (BYTES) -#define LENGTH_TM_LFR_TC_EXE_MAX 32 -#define LENGTH_TM_LFR_HK 126 - -// HEADER_LENGTH -#define TM_HEADER_LEN 16 -#define HEADER_LENGTH_TM_LFR_SCIENCE_ASM 28 -// PACKET_LENGTH -#define PACKET_LENGTH_TC_EXE_SUCCESS (20 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_EXE_INCONSISTENT (26 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE (26 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED (24 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_EXE_ERROR (24 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TC_EXE_CORRUPTED (32 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_HK (124 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_PARAMETER_DUMP (36 - CCSDS_TC_TM_PACKET_OFFSET) -#define PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0 (2228 - CCSDS_TC_TM_PACKET_OFFSET) // 44 * 25 * 2 + 28 -#define PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1 (2628 - CCSDS_TC_TM_PACKET_OFFSET) // 52 * 25 * 2 + 28 -#define PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2 (2428 - CCSDS_TC_TM_PACKET_OFFSET) // 48 * 25 * 2 + 28 -#define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 (126 - CCSDS_TC_TM_PACKET_OFFSET) // 11 * 9 + 27 (1 spare bit in the header) -#define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 (356 - CCSDS_TC_TM_PACKET_OFFSET) // 11 * 30 + 26 -#define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 (144 - CCSDS_TC_TM_PACKET_OFFSET) // 13 * 9 + 27 (1 spare bit in the header) -#define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 (416 - CCSDS_TC_TM_PACKET_OFFSET) // 13 * 30 + 26 -#define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 (134 - CCSDS_TC_TM_PACKET_OFFSET) // 12 * 9 + 26 -#define PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 (386 - CCSDS_TC_TM_PACKET_OFFSET) // 12 * 30 + 26 -#define PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 (224 - CCSDS_TC_TM_PACKET_OFFSET) // 22 * 9 + 26 -#define PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 (686 - CCSDS_TC_TM_PACKET_OFFSET) // 22 * 30 + 26 -#define PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 (260 - CCSDS_TC_TM_PACKET_OFFSET) // 26 * 9 + 26 -#define PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 (806 - CCSDS_TC_TM_PACKET_OFFSET) // 26 * 30 + 26 - -#define PACKET_LENGTH_DELTA 11 // 7 + 4 - -#define SPARE1_PUSVERSION_SPARE2 0x10 - -// R1 -#define TM_LEN_SCI_SWF_340 4101 // 340 * 12 + 10 + 12 - 1 -#define TM_LEN_SCI_SWF_8 117 // 8 * 12 + 10 + 12 - 1 -#define TM_LEN_SCI_CWF_340 4099 // 340 * 12 + 10 + 10 - 1 -#define TM_LEN_SCI_CWF_8 115 // 8 * 12 + 10 + 10 - 1 -#define TM_LEN_SCI_CWF3_LIGHT_340 2059 // 340 * 6 + 10 + 10 - 1 -#define TM_LEN_SCI_CWF3_LIGHT_8 67 // 8 * 6 + 10 + 10 - 1 -// R2 -#define TM_LEN_SCI_SWF_304 3669 // 304 * 12 + 10 + 12 - 1 -#define TM_LEN_SCI_SWF_224 2709 // 224 * 12 + 10 + 12 - 1 -#define TM_LEN_SCI_CWF_336 4051 // 336 * 12 + 10 + 10 - 1 -#define TM_LEN_SCI_CWF_672 4051 // 672 * 6 + 10 + 10 - 1 -// -#define DEFAULT_PKTCNT 0x07 -#define BLK_NR_304 0x0130 -#define BLK_NR_224 0x00e0 -#define BLK_NR_CWF 0x0150 // 336 -#define BLK_NR_CWF_SHORT_F3 0x02a0 // 672 - -enum TM_TYPE{ - TM_LFR_TC_EXE_OK, - TM_LFR_TC_EXE_ERR, - TM_LFR_HK, - TM_LFR_SCI, - TM_LFR_SCI_SBM, - TM_LFR_PAR_DUMP -}; - -typedef struct { - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - // PACKET HEADER - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char spare1_pusVersion_spare2; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char destinationID; - unsigned char time[6]; - // - unsigned char telecommand_pkt_id[2]; - unsigned char pkt_seq_control[2]; -} Packet_TM_LFR_TC_EXE_SUCCESS_t; - -typedef struct { - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - // PACKET HEADER - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char spare1_pusVersion_spare2; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char destinationID; - unsigned char time[6]; - // - unsigned char tc_failure_code[2]; - unsigned char telecommand_pkt_id[2]; - unsigned char pkt_seq_control[2]; - unsigned char tc_service; - unsigned char tc_subtype; - unsigned char byte_position; - unsigned char rcv_value; -} Packet_TM_LFR_TC_EXE_INCONSISTENT_t; - -typedef struct { - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - // PACKET HEADER - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char spare1_pusVersion_spare2; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char destinationID; - unsigned char time[6]; - // - unsigned char tc_failure_code[2]; - unsigned char telecommand_pkt_id[2]; - unsigned char pkt_seq_control[2]; - unsigned char tc_service; - unsigned char tc_subtype; - unsigned char lfr_status_word[2]; -} Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t; - -typedef struct { - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - // PACKET HEADER - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char spare1_pusVersion_spare2; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char destinationID; - unsigned char time[6]; - // - unsigned char tc_failure_code[2]; - unsigned char telecommand_pkt_id[2]; - unsigned char pkt_seq_control[2]; - unsigned char tc_service; - unsigned char tc_subtype; -} Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t; - -typedef struct { - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - // PACKET HEADER - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char spare1_pusVersion_spare2; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char destinationID; - unsigned char time[6]; - // - unsigned char tc_failure_code[2]; - unsigned char telecommand_pkt_id[2]; - unsigned char pkt_seq_control[2]; - unsigned char tc_service; - unsigned char tc_subtype; -} Packet_TM_LFR_TC_EXE_ERROR_t; - -typedef struct { - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - // PACKET HEADER - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char spare1_pusVersion_spare2; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char destinationID; - unsigned char time[6]; - // - unsigned char tc_failure_code[2]; - unsigned char telecommand_pkt_id[2]; - unsigned char pkt_seq_control[2]; - unsigned char tc_service; - unsigned char tc_subtype; - unsigned char pkt_len_rcv_value[2]; - unsigned char pkt_datafieldsize_cnt[2]; - unsigned char rcv_crc[2]; - unsigned char computed_crc[2]; -} Packet_TM_LFR_TC_EXE_CORRUPTED_t; - -typedef struct { - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char spare1_pusVersion_spare2; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char destinationID; - unsigned char time[6]; - // AUXILIARY HEADER - unsigned char sid; - unsigned char hkBIA; - unsigned char pktCnt; - unsigned char pktNr; - unsigned char acquisitionTime[6]; - unsigned char blkNr[2]; -} Header_TM_LFR_SCIENCE_SWF_t; - -typedef struct { - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char spare1_pusVersion_spare2; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char destinationID; - unsigned char time[6]; - // AUXILIARY DATA HEADER - unsigned char sid; - unsigned char hkBIA; - unsigned char acquisitionTime[6]; - unsigned char blkNr[2]; -} Header_TM_LFR_SCIENCE_CWF_t; - -typedef struct { - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char spare1_pusVersion_spare2; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char destinationID; - unsigned char time[6]; - // AUXILIARY HEADER - unsigned char sid; - unsigned char biaStatusInfo; - unsigned char pa_lfr_pkt_cnt_asm; - unsigned char pa_lfr_pkt_nr_asm; - unsigned char acquisitionTime[6]; - unsigned char pa_lfr_asm_blk_nr[2]; -} Header_TM_LFR_SCIENCE_ASM_t; - -typedef struct { - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char spare1_pusVersion_spare2; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char destinationID; - unsigned char time[6]; - // AUXILIARY HEADER - unsigned char sid; - unsigned char biaStatusInfo; - unsigned char acquisitionTime[6]; - unsigned char source_data_spare; - unsigned char pa_lfr_bp_blk_nr[2]; -} Header_TM_LFR_SCIENCE_BP_with_spare_t; - -typedef struct { - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char spare1_pusVersion_spare2; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char destinationID; - unsigned char time[6]; - // AUXILIARY HEADER - unsigned char sid; - unsigned char biaStatusInfo; - unsigned char acquisitionTime[6]; - unsigned char pa_lfr_bp_blk_nr[2]; -} Header_TM_LFR_SCIENCE_BP_t; - -typedef struct { - //targetLogicalAddress is removed by the grspw module - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char headerFlag_pusVersion_Ack; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char sourceID; - unsigned char dataAndCRC[CCSDS_TC_PKT_MAX_SIZE-10]; -} ccsdsTelecommandPacket_t; - -typedef struct { - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - unsigned char spare1_pusVersion_spare2; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char destinationID; - unsigned char time[6]; - unsigned char sid; - - //************** - // HK PARAMETERS - unsigned char lfr_status_word[2]; - unsigned char lfr_sw_version[4]; - unsigned char lfr_fpga_version[3]; - // ressource statistics - unsigned char hk_lfr_cpu_load; - unsigned char hk_lfr_cpu_load_max; - unsigned char hk_lfr_cpu_load_aver; - // tc statistics - unsigned char hk_lfr_update_info_tc_cnt[2]; - unsigned char hk_lfr_update_time_tc_cnt[2]; - unsigned char hk_lfr_exe_tc_cnt[2]; - unsigned char hk_lfr_rej_tc_cnt[2]; - unsigned char hk_lfr_last_exe_tc_id[2]; - unsigned char hk_lfr_last_exe_tc_type[2]; - unsigned char hk_lfr_last_exe_tc_subtype[2]; - unsigned char hk_lfr_last_exe_tc_time[6]; - unsigned char hk_lfr_last_rej_tc_id[2]; - unsigned char hk_lfr_last_rej_tc_type[2]; - unsigned char hk_lfr_last_rej_tc_subtype[2]; - unsigned char hk_lfr_last_rej_tc_time[6]; - // anomaly statistics - unsigned char hk_lfr_le_cnt[2]; - unsigned char hk_lfr_me_cnt[2]; - unsigned char hk_lfr_he_cnt[2]; - unsigned char hk_lfr_last_er_rid[2]; - unsigned char hk_lfr_last_er_code; - unsigned char hk_lfr_last_er_time[6]; - // vhdl_blk_status - unsigned char hk_lfr_vhdl_aa_sm; - unsigned char hk_lfr_vhdl_fft_sr; - unsigned char hk_lfr_vhdl_cic_hk; - unsigned char hk_lfr_vhdl_iir_cal; - // spacewire_if_statistics - unsigned char hk_lfr_dpu_spw_pkt_rcv_cnt[2]; - unsigned char hk_lfr_dpu_spw_pkt_sent_cnt[2]; - unsigned char hk_lfr_dpu_spw_tick_out_cnt; - unsigned char hk_lfr_dpu_spw_last_timc; - // ahb error statistics - unsigned char hk_lfr_last_fail_addr[4]; - // temperatures - unsigned char hk_lfr_temp_scm[2]; - unsigned char hk_lfr_temp_pcb[2]; - unsigned char hk_lfr_temp_fpga[2]; - // spacecraft potential - unsigned char hk_lfr_sc_v_f3[2]; - unsigned char hk_lfr_sc_e1_f3[2]; - unsigned char hk_lfr_sc_e2_f3[2]; - // error counters - unsigned char hk_lfr_dpu_spw_parity; - unsigned char hk_lfr_dpu_spw_disconnect; - unsigned char hk_lfr_dpu_spw_escape; - unsigned char hk_lfr_dpu_spw_credit; - unsigned char hk_lfr_dpu_spw_write_sync; - unsigned char hk_lfr_dpu_spw_rx_ahb; - unsigned char hk_lfr_dpu_spw_tx_ahb; - unsigned char hk_lfr_dpu_spw_early_eop; - unsigned char hk_lfr_dpu_spw_invalid_addr; - unsigned char hk_lfr_dpu_spw_eep; - unsigned char hk_lfr_dpu_spw_rx_too_big; - // timecode - unsigned char hk_lfr_timecode_erroneous; - unsigned char hk_lfr_timecode_missing; - unsigned char hk_lfr_timecode_invalid; - // time - unsigned char hk_lfr_time_timecode_it; - unsigned char hk_lfr_time_not_synchro; - unsigned char hk_lfr_time_timecode_ctr; - // hk_lfr_buffer_dpu_ - unsigned char hk_lfr_buffer_dpu_tc_fifo; - unsigned char hk_lfr_buffer_dpu_tm_fifo; - // hk_lfr_ahb_ - unsigned char hk_lfr_ahb_correctable; - unsigned char hk_lfr_ahb_uncorrectable; - // spare - unsigned char parameters_spare; -} Packet_TM_LFR_HK_t; - -typedef struct { - unsigned char targetLogicalAddress; - unsigned char protocolIdentifier; - unsigned char reserved; - unsigned char userApplication; - unsigned char packetID[2]; - unsigned char packetSequenceControl[2]; - unsigned char packetLength[2]; - // DATA FIELD HEADER - unsigned char spare1_pusVersion_spare2; - unsigned char serviceType; - unsigned char serviceSubType; - unsigned char destinationID; - unsigned char time[6]; - unsigned char sid; - - //****************** - // COMMON PARAMETERS - unsigned char unused0; - unsigned char bw_sp0_sp1_r0_r1; - - //****************** - // NORMAL PARAMETERS - unsigned char sy_lfr_n_swf_l[2]; - unsigned char sy_lfr_n_swf_p[2]; - unsigned char sy_lfr_n_asm_p[2]; - unsigned char sy_lfr_n_bp_p0; - unsigned char sy_lfr_n_bp_p1; - unsigned char sy_lfr_n_cwf_long_f3; - unsigned char lfr_normal_parameters_spare; - - //***************** - // BURST PARAMETERS - unsigned char sy_lfr_b_bp_p0; - unsigned char sy_lfr_b_bp_p1; - - //**************** - // SBM1 PARAMETERS - unsigned char sy_lfr_s1_bp_p0; - unsigned char sy_lfr_s1_bp_p1; - - //**************** - // SBM2 PARAMETERS - unsigned char sy_lfr_s2_bp_p0; - unsigned char sy_lfr_s2_bp_p1; - - // SPARE - unsigned char source_data_spare; -} Packet_TM_LFR_PARAMETER_DUMP_t; - - -#endif // CCSDS_TYPES_H_INCLUDED diff --git a/timegen/header/fsw_init.h b/timegen/header/fsw_init.h deleted file mode 100644 --- a/timegen/header/fsw_init.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef FSW_INIT_H_INCLUDED -#define FSW_INIT_H_INCLUDED - -#include -#include - -#include "fsw_params.h" -#include "fsw_misc.h" - -#include "tc_handler.h" -#include "fsw_spacewire.h" - -extern rtems_name Task_name[20]; /* array of task names */ -extern rtems_id Task_id[20]; /* array of task ids */ - -// RTEMS TASKS -rtems_task Init( rtems_task_argument argument); - -// OTHER functions -void create_names( void ); -int create_all_tasks( void ); -int start_all_tasks( void ); -// -rtems_status_code create_message_queues( void ); -rtems_status_code get_message_queue_id_send( rtems_id *queue_id ); -rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ); -// -int start_recv_send_tasks( void ); -// -void init_local_mode_parameters( void ); -void reset_local_time( void ); - -extern void rtems_cpu_usage_report( void ); -extern void rtems_cpu_usage_reset( void ); -extern void rtems_stack_checker_report_usage( void ); - -extern int sched_yield( void ); - -#endif // FSW_INIT_H_INCLUDED diff --git a/timegen/header/fsw_misc.h b/timegen/header/fsw_misc.h deleted file mode 100644 --- a/timegen/header/fsw_misc.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef FSW_MISC_H_INCLUDED -#define FSW_MISC_H_INCLUDED - -#include -#include -#include - -#include "fsw_params.h" -#include "fsw_spacewire.h" -#include "lfr_cpu_usage_report.h" - -rtems_name name_hk_rate_monotonic; // name of the HK rate monotonic -rtems_id HK_id; // id of the HK rate monotonic period - -void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, - unsigned char interrupt_level, rtems_isr (*timer_isr)() ); -void timer_start( gptimer_regs_t *gptimer_regs, unsigned char timer ); -void timer_stop( gptimer_regs_t *gptimer_regs, unsigned char timer ); -void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider); - -// SERIAL LINK -int send_console_outputs_on_apbuart_port( void ); -int enable_apbuart_transmitter( void ); -void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value); - -// RTEMS TASKS -rtems_task stat_task( rtems_task_argument argument ); -rtems_task hous_task( rtems_task_argument argument ); -rtems_task dumb_task( rtems_task_argument unused ); - -void init_housekeeping_parameters( void ); -void increment_seq_counter(unsigned short *packetSequenceControl); -void getTime( unsigned char *time); -unsigned long long int getTimeAsUnsignedLongLongInt( ); -void send_dumb_hk( void ); -void get_v_e1_e2_f3 (unsigned char *spacecraft_potential); -void get_cpu_load( unsigned char *resource_statistics ); - -extern int sched_yield( void ); -extern void rtems_cpu_usage_reset(); -extern ring_node *current_ring_node_f3; -extern ring_node *ring_node_to_send_cwf_f3; -extern unsigned short sequenceCounterHK; - -#endif // FSW_MISC_H_INCLUDED diff --git a/timegen/header/fsw_params.h b/timegen/header/fsw_params.h deleted file mode 100644 --- a/timegen/header/fsw_params.h +++ /dev/null @@ -1,255 +0,0 @@ -#ifndef FSW_PARAMS_H_INCLUDED -#define FSW_PARAMS_H_INCLUDED - -#include "grlib_regs.h" -#include "fsw_params_processing.h" -#include "fsw_params_nb_bytes.h" -#include "tm_byte_positions.h" -#include "ccsds_types.h" - -#define GRSPW_DEVICE_NAME "/dev/grspw0" -#define UART_DEVICE_NAME "/dev/console" - -typedef struct ring_node -{ - struct ring_node *previous; - int buffer_address; - struct ring_node *next; - unsigned int status; -} ring_node; - -//************************ -// flight software version -// this parameters is handled by the Qt project options - -#define NB_PACKETS_PER_GROUP_OF_CWF 8 // 8 packets containing 336 blk -#define NB_PACKETS_PER_GROUP_OF_CWF_LIGHT 4 // 4 packets containing 672 blk -#define NB_SAMPLES_PER_SNAPSHOT 2688 // 336 * 8 = 672 * 4 = 2688 -#define TIME_OFFSET 2 -#define TIME_OFFSET_IN_BYTES 8 -#define WAVEFORM_EXTENDED_HEADER_OFFSET 22 -#define NB_BYTES_SWF_BLK (2 * 6) -#define NB_WORDS_SWF_BLK 3 -#define NB_BYTES_CWF3_LIGHT_BLK 6 -#define WFRM_INDEX_OF_LAST_PACKET 6 // waveforms are transmitted in groups of 2048 blocks, 6 packets of 340 and 1 of 8 -#define NB_RING_NODES_F0 3 // AT LEAST 3 -#define NB_RING_NODES_F1 5 // AT LEAST 3 -#define NB_RING_NODES_F2 5 // AT LEAST 3 -#define NB_RING_NODES_F3 3 // AT LEAST 3 - -//********** -// LFR MODES -#define LFR_MODE_STANDBY 0 -#define LFR_MODE_NORMAL 1 -#define LFR_MODE_BURST 2 -#define LFR_MODE_SBM1 3 -#define LFR_MODE_SBM2 4 - -#define TDS_MODE_LFM 5 -#define TDS_MODE_STANDBY 0 -#define TDS_MODE_NORMAL 1 -#define TDS_MODE_BURST 2 -#define TDS_MODE_SBM1 3 -#define TDS_MODE_SBM2 4 - -#define THR_MODE_STANDBY 0 -#define THR_MODE_NORMAL 1 -#define THR_MODE_BURST 2 - -#define RTEMS_EVENT_MODE_STANDBY RTEMS_EVENT_0 -#define RTEMS_EVENT_MODE_NORMAL RTEMS_EVENT_1 -#define RTEMS_EVENT_MODE_BURST RTEMS_EVENT_2 -#define RTEMS_EVENT_MODE_SBM1 RTEMS_EVENT_3 -#define RTEMS_EVENT_MODE_SBM2 RTEMS_EVENT_4 -#define RTEMS_EVENT_MODE_SBM2_WFRM RTEMS_EVENT_5 -#define RTEMS_EVENT_NORM_BP1_F0 RTEMS_EVENT_6 -#define RTEMS_EVENT_NORM_BP2_F0 RTEMS_EVENT_7 -#define RTEMS_EVENT_NORM_ASM_F0 RTEMS_EVENT_8 // ASM only in NORM mode -#define RTEMS_EVENT_NORM_BP1_F1 RTEMS_EVENT_9 -#define RTEMS_EVENT_NORM_BP2_F1 RTEMS_EVENT_10 -#define RTEMS_EVENT_NORM_ASM_F1 RTEMS_EVENT_11 // ASM only in NORM mode -#define RTEMS_EVENT_NORM_BP1_F2 RTEMS_EVENT_12 -#define RTEMS_EVENT_NORM_BP2_F2 RTEMS_EVENT_13 -#define RTEMS_EVENT_NORM_ASM_F2 RTEMS_EVENT_14 // ASM only in NORM mode -#define RTEMS_EVENT_SBM_BP1_F0 RTEMS_EVENT_15 -#define RTEMS_EVENT_SBM_BP2_F0 RTEMS_EVENT_16 -#define RTEMS_EVENT_SBM_BP1_F1 RTEMS_EVENT_17 -#define RTEMS_EVENT_SBM_BP2_F1 RTEMS_EVENT_18 -#define RTEMS_EVENT_BURST_BP1_F0 RTEMS_EVENT_19 -#define RTEMS_EVENT_BURST_BP2_F0 RTEMS_EVENT_20 -#define RTEMS_EVENT_BURST_BP1_F1 RTEMS_EVENT_21 -#define RTEMS_EVENT_BURST_BP2_F1 RTEMS_EVENT_22 - -//**************************** -// LFR DEFAULT MODE PARAMETERS -// COMMON -#define DEFAULT_SY_LFR_COMMON0 0x00 -#define DEFAULT_SY_LFR_COMMON1 0x10 // default value 0 0 0 1 0 0 0 0 -// NORM -#define DFLT_SY_LFR_N_SWF_L 2048 // nb sample -#define DFLT_SY_LFR_N_SWF_P 300 // sec -#define DFLT_SY_LFR_N_ASM_P 3600 // sec -#define DFLT_SY_LFR_N_BP_P0 4 // sec -#define DFLT_SY_LFR_N_BP_P1 20 // sec -#define DFLT_SY_LFR_N_CWF_LONG_F3 0 // 0 => production of light continuous waveforms at f3 -#define MIN_DELTA_SNAPSHOT 16 // sec -// BURST -#define DEFAULT_SY_LFR_B_BP_P0 1 // sec -#define DEFAULT_SY_LFR_B_BP_P1 5 // sec -// SBM1 -#define DEFAULT_SY_LFR_S1_BP_P0 1 // sec -#define DEFAULT_SY_LFR_S1_BP_P1 1 // sec -// SBM2 -#define DEFAULT_SY_LFR_S2_BP_P0 1 // sec -#define DEFAULT_SY_LFR_S2_BP_P1 5 // sec -// ADDITIONAL PARAMETERS -#define TIME_BETWEEN_TWO_SWF_PACKETS 30 // nb x 10 ms => 300 ms -#define TIME_BETWEEN_TWO_CWF3_PACKETS 1000 // nb x 10 ms => 10 s -// STATUS WORD -#define DEFAULT_STATUS_WORD_BYTE0 0x0d // [0000] [1] [101] mode 4 bits / SPW enabled 1 bit / state is run 3 bits -#define DEFAULT_STATUS_WORD_BYTE1 0x00 -// -#define SY_LFR_DPU_CONNECT_TIMEOUT 100 // 100 * 10 ms = 1 s -#define SY_LFR_DPU_CONNECT_ATTEMPT 3 -//**************************** - -//***************************** -// APB REGISTERS BASE ADDRESSES -#define REGS_ADDR_APBUART 0x80000100 -#define REGS_ADDR_GPTIMER 0x80000300 -#define REGS_ADDR_GRSPW 0x80000500 -#define REGS_ADDR_TIME_MANAGEMENT 0x80000600 -#define REGS_ADDR_GRGPIO 0x80000b00 - -#define REGS_ADDR_SPECTRAL_MATRIX 0x80000f00 -#define REGS_ADDR_WAVEFORM_PICKER 0x80000f50 -#define REGS_ADDR_VHDL_VERSION 0x80000ff0 - -#define APBUART_CTRL_REG_MASK_DB 0xfffff7ff -#define APBUART_CTRL_REG_MASK_TE 0x00000002 -#define APBUART_SCALER_RELOAD_VALUE 0x00000050 // 25 MHz => about 38400 (0x50) - -//********** -// IRQ LINES -#define IRQ_SM_SIMULATOR 9 -#define IRQ_SPARC_SM_SIMULATOR 0x19 // see sparcv8.pdf p.76 for interrupt levels -#define IRQ_WAVEFORM_PICKER 14 -#define IRQ_SPARC_WAVEFORM_PICKER 0x1e // see sparcv8.pdf p.76 for interrupt levels -#define IRQ_SPECTRAL_MATRIX 6 -#define IRQ_SPARC_SPECTRAL_MATRIX 0x16 // see sparcv8.pdf p.76 for interrupt levels - -//***** -// TIME -#define CLKDIV_SM_SIMULATOR (10416 - 1) // 10 ms => nominal is 1/96 = 0.010416667, 10417 - 1 = 10416 -#define TIMER_SM_SIMULATOR 1 -#define HK_PERIOD 100 // 100 * 10ms => 1s -#define SY_LFR_TIME_SYN_TIMEOUT_in_ms 2000 -#define SY_LFR_TIME_SYN_TIMEOUT_in_ticks 200 // 200 * 10 ms = 2 s - -//********** -// LPP CODES -#define LFR_SUCCESSFUL 0 -#define LFR_DEFAULT 1 -#define LFR_EXE_ERROR 2 - -//****** -// RTEMS -#define TASKID_RECV 1 -#define TASKID_ACTN 2 -#define TASKID_SPIQ 3 -#define TASKID_STAT 4 -#define TASKID_AVF0 5 -#define TASKID_SWBD 6 -#define TASKID_WFRM 7 -#define TASKID_DUMB 8 -#define TASKID_HOUS 9 -#define TASKID_PRC0 10 -#define TASKID_CWF3 11 -#define TASKID_CWF2 12 -#define TASKID_CWF1 13 -#define TASKID_SEND 14 -#define TASKID_WTDG 15 -#define TASKID_AVF1 16 -#define TASKID_PRC1 17 -#define TASKID_AVF2 18 -#define TASKID_PRC2 19 - -#define TASK_PRIORITY_SPIQ 5 -#define TASK_PRIORITY_WTDG 20 -#define TASK_PRIORITY_HOUS 30 -#define TASK_PRIORITY_CWF1 35 // CWF1 and CWF2 are never running together -#define TASK_PRIORITY_CWF2 35 // -#define TASK_PRIORITY_SWBD 37 // SWBD has a lower priority than WFRM, this is to extract the snapshot before sending it -#define TASK_PRIORITY_WFRM 40 -#define TASK_PRIORITY_CWF3 40 // there is a printf in this function, be careful with its priority wrt CWF1 -#define TASK_PRIORITY_SEND 45 -#define TASK_PRIORITY_RECV 50 -#define TASK_PRIORITY_ACTN 50 -#define TASK_PRIORITY_AVF0 60 -#define TASK_PRIORITY_AVF1 70 -#define TASK_PRIORITY_PRC0 100 -#define TASK_PRIORITY_PRC1 100 -#define TASK_PRIORITY_AVF2 110 -#define TASK_PRIORITY_PRC2 110 -#define TASK_PRIORITY_STAT 200 -#define TASK_PRIORITY_DUMB 200 - -#define MSG_QUEUE_COUNT_RECV 10 -#define MSG_QUEUE_COUNT_SEND 50 -#define MSG_QUEUE_COUNT_PRC0 10 -#define MSG_QUEUE_COUNT_PRC1 10 -#define MSG_QUEUE_COUNT_PRC2 5 -#define MSG_QUEUE_SIZE_SEND 810 // 806 + 4 => TM_LFR_SCIENCE_BURST_BP2_F1 -#define ACTION_MSG_SPW_IOCTL_SEND_SIZE 24 // hlen *hdr dlen *data sent options -#define MSG_QUEUE_SIZE_PRC0 20 // two pointers and one rtems_event + 2 integers -#define MSG_QUEUE_SIZE_PRC1 20 // two pointers and one rtems_event + 2 integers -#define MSG_QUEUE_SIZE_PRC2 20 // two pointers and one rtems_event + 2 integers - -#define QUEUE_RECV 0 -#define QUEUE_SEND 1 -#define QUEUE_PRC0 2 -#define QUEUE_PRC1 3 -#define QUEUE_PRC2 4 - -//******* -// MACROS -#ifdef PRINT_MESSAGES_ON_CONSOLE -#define PRINTF(x) printf(x); -#define PRINTF1(x,y) printf(x,y); -#define PRINTF2(x,y,z) printf(x,y,z); -#else -#define PRINTF(x) ; -#define PRINTF1(x,y) ; -#define PRINTF2(x,y,z) ; -#endif - -#ifdef BOOT_MESSAGES -#define BOOT_PRINTF(x) printf(x); -#define BOOT_PRINTF1(x,y) printf(x,y); -#define BOOT_PRINTF2(x,y,z) printf(x,y,z); -#else -#define BOOT_PRINTF(x) ; -#define BOOT_PRINTF1(x,y) ; -#define BOOT_PRINTF2(x,y,z) ; -#endif - -#ifdef DEBUG_MESSAGES -#define DEBUG_PRINTF(x) printf(x); -#define DEBUG_PRINTF1(x,y) printf(x,y); -#define DEBUG_PRINTF2(x,y,z) printf(x,y,z); -#else -#define DEBUG_PRINTF(x) ; -#define DEBUG_PRINTF1(x,y) ; -#define DEBUG_PRINTF2(x,y,z) ; -#endif - -#define CPU_USAGE_REPORT_PERIOD 6 // * 10 s = period - -struct param_local_str{ - unsigned int local_sbm1_nb_cwf_sent; - unsigned int local_sbm1_nb_cwf_max; - unsigned int local_sbm2_nb_cwf_sent; - unsigned int local_sbm2_nb_cwf_max; -}; - -#endif // FSW_PARAMS_H_INCLUDED diff --git a/timegen/header/fsw_params_nb_bytes.h b/timegen/header/fsw_params_nb_bytes.h deleted file mode 100644 --- a/timegen/header/fsw_params_nb_bytes.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef TM_BYTE_POSITIONS_H -#define TM_BYTE_POSITIONS_H - -// SEQUENCE_CNT -#define PACKET_POS_SEQUENCE_CNT 6 // 4 + 2 - -// TC_LFR_LOAD_COMMON_PAR - -// TC_LFR_LOAD_NORMAL_PAR -#define DATAFIELD_POS_SY_LFR_N_SWF_L 0 -#define DATAFIELD_POS_SY_LFR_N_SWF_P 2 -#define DATAFIELD_POS_SY_LFR_N_ASM_P 4 -#define DATAFIELD_POS_SY_LFR_N_BP_P0 6 -#define DATAFIELD_POS_SY_LFR_N_BP_P1 7 -#define DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 8 - -// TC_LFR_LOAD_BURST_PAR -#define DATAFIELD_POS_SY_LFR_B_BP_P0 0 -#define DATAFIELD_POS_SY_LFR_B_BP_P1 1 - -// TC_LFR_LOAD_SBM1_PAR -#define DATAFIELD_POS_SY_LFR_S1_BP_P0 0 -#define DATAFIELD_POS_SY_LFR_S1_BP_P1 1 - -// TC_LFR_LOAD_SBM2_PAR -#define DATAFIELD_POS_SY_LFR_S2_BP_P0 0 -#define DATAFIELD_POS_SY_LFR_S2_BP_P1 1 - -// TC_LFR_UPDATE_INFO -#define BYTE_POS_UPDATE_INFO_PARAMETERS_SET5 34 -#define BYTE_POS_UPDATE_INFO_PARAMETERS_SET6 35 - -// TC_LFR_ENTER_MODE -#define BYTE_POS_CP_MODE_LFR_SET 11 -#define BYTE_POS_CP_LFR_ENTER_MODE_TIME 12 - -#endif // TM_BYTE_POSITIONS_H diff --git a/timegen/header/fsw_params_processing.h b/timegen/header/fsw_params_processing.h deleted file mode 100644 --- a/timegen/header/fsw_params_processing.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef FSW_PARAMS_PROCESSING_H -#define FSW_PARAMS_PROCESSING_H - -#define NB_BINS_PER_SM 128 -#define NB_VALUES_PER_SM 25 -#define TOTAL_SIZE_SM 3200 // 25 * 128 = 0xC80 -#define TOTAL_SIZE_NORM_BP1_F0 99 // 11 * 9 = 99 -#define TOTAL_SIZE_NORM_BP1_F1 117 // 13 * 9 = 117 -#define TOTAL_SIZE_NORM_BP1_F2 108 // 12 * 9 = 108 -#define TOTAL_SIZE_SBM1_BP1_F0 198 // 22 * 9 = 198 -// -#define NB_RING_NODES_SM_F0 12 // AT LEAST 3 -#define NB_RING_NODES_ASM_BURST_SBM_F0 10 // AT LEAST 3 -#define NB_RING_NODES_ASM_NORM_F0 10 // AT LEAST 3 -#define NB_RING_NODES_SM_F1 3 // AT LEAST 3 -#define NB_RING_NODES_ASM_BURST_SBM_F1 5 // AT LEAST 3 -#define NB_RING_NODES_ASM_NORM_F1 5 // AT LEAST 3 -#define NB_RING_NODES_SM_F2 3 // AT LEAST 3 -#define NB_RING_NODES_ASM_BURST_SBM_F2 3 // AT LEAST 3 -#define NB_RING_NODES_ASM_NORM_F2 3 // AT LEAST 3 -// -#define NB_BINS_PER_ASM_F0 88 -#define NB_BINS_PER_PKT_ASM_F0 44 -#define TOTAL_SIZE_ASM_F0_IN_BYTES 4400 // 25 * 88 * 2 -#define ASM_F0_INDICE_START 17 // 88 bins -#define ASM_F0_INDICE_STOP 104 // 2 packets of 44 bins -// -#define NB_BINS_PER_ASM_F1 104 -#define NB_BINS_PER_PKT_ASM_F1 52 -#define TOTAL_SIZE_ASM_F1_IN_BYTES 5200 // 25 * 104 * 2 -#define ASM_F1_INDICE_START 6 // 104 bins -#define ASM_F1_INDICE_STOP 109 // 2 packets of 52 bins -// -#define NB_BINS_PER_ASM_F2 96 -#define NB_BINS_PER_PKT_ASM_F2 48 -#define TOTAL_SIZE_ASM_F2_IN_BYTES 4800 // 25 * 96 * 2 -#define ASM_F2_INDICE_START 7 // 96 bins -#define ASM_F2_INDICE_STOP 102 // 2 packets of 48 bins -// -#define NB_BINS_COMPRESSED_SM_F0 11 -#define NB_BINS_COMPRESSED_SM_F1 13 -#define NB_BINS_COMPRESSED_SM_F2 12 -#define NB_BINS_COMPRESSED_SM_SBM_F0 22 -#define NB_BINS_COMPRESSED_SM_SBM_F1 26 -#define NB_BINS_COMPRESSED_SM_SBM_F2 24 -// -#define NB_BYTES_PER_BP1 9 -// -#define NB_BINS_TO_AVERAGE_ASM_F0 8 -#define NB_BINS_TO_AVERAGE_ASM_F1 8 -#define NB_BINS_TO_AVERAGE_ASM_F2 8 -#define NB_BINS_TO_AVERAGE_ASM_SBM_F0 4 -#define NB_BINS_TO_AVERAGE_ASM_SBM_F1 4 -#define NB_BINS_TO_AVERAGE_ASM_SBM_F2 4 -// -#define TOTAL_SIZE_COMPRESSED_ASM_NORM_F0 275 // 11 * 25 WORDS -#define TOTAL_SIZE_COMPRESSED_ASM_NORM_F1 325 // 13 * 25 WORDS -#define TOTAL_SIZE_COMPRESSED_ASM_NORM_F2 300 // 12 * 25 WORDS -#define TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 550 // 22 * 25 WORDS -#define TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 650 // 26 * 25 WORDS -#define TOTAL_SIZE_COMPRESSED_ASM_SBM_F2 600 // 24 * 25 WORDS -#define TOTAL_SIZE_BP1_NORM_F0 99 // 9 * 11 UNSIGNED CHAR -#define TOTAL_SIZE_BP1_SBM_F0 198 // 9 * 22 UNSIGNED CHAR -// GENERAL -#define NB_SM_BEFORE_AVF0 8 // must be 8 due to the SM_average() function -#define NB_SM_BEFORE_AVF1 8 // must be 8 due to the SM_average() function -#define NB_SM_BEFORE_AVF2 1 // must be 1 due to the SM_average_f2() function - -#endif // FSW_PARAMS_PROCESSING_H - diff --git a/timegen/header/fsw_params_wf_handler.h b/timegen/header/fsw_params_wf_handler.h deleted file mode 100644 --- a/timegen/header/fsw_params_wf_handler.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef FSW_PARAMS_WF_HANDLER_H -#define FSW_PARAMS_WF_HANDLER_H - -#define WFRM_BUFFER 8128 // (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET + 62 - // (2688 * 3 ) + 2 + 62 = 8128 = 0X1FC0 - // 8128 * 4 = 32512 = 0x7F00 - -#endif // FSW_PARAMS_WF_HANDLER_H diff --git a/timegen/header/fsw_spacewire.h b/timegen/header/fsw_spacewire.h deleted file mode 100644 --- a/timegen/header/fsw_spacewire.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef FSW_SPACEWIRE_H_INCLUDED -#define FSW_SPACEWIRE_H_INCLUDED - -#include -#include - -#include // for O_RDWR -#include // for the read call -#include // for the ioctl call -#include - -#include "fsw_params.h" -#include "tc_handler.h" -#include "TC_types.h" - -extern spw_stats spacewire_stats; -extern spw_stats spacewire_stats_backup; -extern rtems_id rtems_task_id_updt; - -void resetLocalCoarseTime(); -void setLocalCoarseTime( unsigned int value ); -unsigned int getLocalCoarseTime(); -void incrementLocalCoarseTime(); - -// TC_LFR_UPDATE_TIME -void initLookUpTableForCRC( void ); -void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData); -unsigned int Crc_opt( unsigned char D, unsigned int Chk); -void updateTimePacket(unsigned int time, Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_t *packet); - -// RTEMS TASK -rtems_task spiq_task( rtems_task_argument argument ); -rtems_task recv_task( rtems_task_argument unused ); -rtems_task send_task( rtems_task_argument argument ); -rtems_task wtdg_task( rtems_task_argument argument ); -rtems_task updt_task( rtems_task_argument unused ); - -int spacewire_open_link( void ); -int spacewire_start_link( int fd ); -int spacewire_stop_and_start_link( int fd ); -int spacewire_configure_link(int fd ); -int spacewire_reset_link( void ); -void spacewire_set_NP( unsigned char val, unsigned int regAddr ); // No Port force -void spacewire_set_RE( unsigned char val, unsigned int regAddr ); // RMAP Enable -void spacewire_compute_stats_offsets( void ); -void spacewire_update_statistics( void ); - -void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ); -rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data ); - -void (*grspw_timecode_callback) ( void *pDev, void *regs, int minor, unsigned int tc ); - -#endif // FSW_SPACEWIRE_H_INCLUDED diff --git a/timegen/header/grlib_regs.h b/timegen/header/grlib_regs.h deleted file mode 100644 --- a/timegen/header/grlib_regs.h +++ /dev/null @@ -1,109 +0,0 @@ -#ifndef GRLIB_REGS_H_INCLUDED -#define GRLIB_REGS_H_INCLUDED - -#define NB_GPTIMER 3 - -struct apbuart_regs_str{ - volatile unsigned int data; - volatile unsigned int status; - volatile unsigned int ctrl; - volatile unsigned int scaler; - volatile unsigned int fifoDebug; -}; - -struct grgpio_regs_str{ - volatile int io_port_data_register; - int io_port_output_register; - int io_port_direction_register; - int interrupt_mak_register; - int interrupt_polarity_register; - int interrupt_edge_register; - int bypass_register; - int reserved; - // 0x20-0x3c interrupt map register(s) -}; - -typedef struct { - volatile unsigned int counter; - volatile unsigned int reload; - volatile unsigned int ctrl; - volatile unsigned int unused; -} timer_regs_t; - -typedef struct { - volatile unsigned int scaler_value; - volatile unsigned int scaler_reload; - volatile unsigned int conf; - volatile unsigned int unused0; - timer_regs_t timer[NB_GPTIMER]; -} gptimer_regs_t; - -typedef struct { - volatile int ctrl; // bit 0 forces the load of the coarse_time_load value and resets the fine_time - volatile int coarse_time_load; - volatile int coarse_time; - volatile int fine_time; -} time_management_regs_t; - -typedef struct { - volatile int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW - volatile int burst_enable; // 0x04 01 *** burst f2, f1, f0 enable f3, f2, f1, f0 - volatile int addr_data_f0; // 0x08 10 *** - volatile int addr_data_f1; // 0x0c 11 *** - volatile int addr_data_f2; // 0x10 100 *** - volatile int addr_data_f3; // 0x14 101 *** - volatile int status; // 0x18 110 *** - volatile int delta_snapshot; // 0x1c 111 *** - volatile int delta_f2_f1; // 0x20 0000 *** - volatile int delta_f2_f0; // 0x24 0001 *** - volatile int nb_burst_available;// 0x28 0010 *** - volatile int nb_snapshot_param; // 0x2c 0011 *** -} waveform_picker_regs_t; - -typedef struct{ - int data_shaping; // 0x00 00 *** R1 R0 SP1 SP0 BW - int run_burst_enable; // 0x04 01 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ] - int addr_data_f0; // 0x08 - int addr_data_f1; // 0x0c - int addr_data_f2; // 0x10 - int addr_data_f3; // 0x14 - volatile int status; // 0x18 - int delta_snapshot; // 0x1c - int delta_f0; // 0x20 - int delta_f0_2; // 0x24 - int delta_f1; // 0x28 - int delta_f2; // 0x2c - int nb_data_by_buffer; // 0x30 - int snapshot_param; // 0x34 - int start_date; // 0x38 - int nb_word_in_buffer; // 0x3c -} waveform_picker_regs_new_t; - -typedef struct { - volatile int config; // 0x00 - volatile int status; // 0x04 - volatile int f0_0_address; // 0x08 - volatile int f0_1_address; // 0x0C - // - volatile int f1_0_address; // 0x10 - volatile int f1_1_address; // 0x14 - volatile int f2_0_address; // 0x18 - volatile int f2_1_address; // 0x1C - // - volatile unsigned int f0_0_coarse_time; // 0x20 - volatile unsigned int f0_0_fine_time; // 0x24 - volatile unsigned int f0_1_coarse_time; // 0x28 - volatile unsigned int f0_1_fine_time; // 0x2C - // - volatile unsigned int f1_0_coarse_time; // 0x30 - volatile unsigned int f1_0_fine_time; // 0x34 - volatile unsigned int f1_1_coarse_time; // 0x38 - volatile unsigned int f1_1_time_time; // 0x3C - // - volatile unsigned int f2_0_coarse_time; // 0x40 - volatile unsigned int f2_0_fine_time; // 0x44 - volatile unsigned int f2_1_coarse_time; // 0x48 - volatile unsigned int f2_1_fine_time; // 0x4C -} spectral_matrix_regs_t; - -#endif // GRLIB_REGS_H_INCLUDED diff --git a/timegen/header/lfr_cpu_usage_report.h b/timegen/header/lfr_cpu_usage_report.h deleted file mode 100644 --- a/timegen/header/lfr_cpu_usage_report.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef LFR_CPU_USAGE_REPORT_H -#define LFR_CPU_USAGE_REPORT_H - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ - #include -#endif - -#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ - extern Timestamp_Control CPU_usage_Uptime_at_last_reset; -#else - extern uint32_t CPU_usage_Ticks_at_last_reset; -#endif - -unsigned char lfr_rtems_cpu_usage_report( void ); - -#endif // LFR_CPU_USAGE_REPORT_H diff --git a/timegen/header/processing/avf0_prc0.h b/timegen/header/processing/avf0_prc0.h deleted file mode 100644 --- a/timegen/header/processing/avf0_prc0.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef AVF0_PRC0_H_INCLUDED -#define AVF0_PRC0_H_INCLUDED - -#include "fsw_processing.h" -#include "basic_parameters.h" - -typedef struct { - unsigned int norm_bp1; - unsigned int norm_bp2; - unsigned int norm_asm; - unsigned int burst_sbm_bp1; - unsigned int burst_sbm_bp2; - unsigned int burst_bp1; - unsigned int burst_bp2; - unsigned int sbm1_bp1; - unsigned int sbm1_bp2; - unsigned int sbm2_bp1; - unsigned int sbm2_bp2; -} nb_sm_before_bp_asm_f0; - -//************ -// RTEMS TASKS -rtems_task avf0_task( rtems_task_argument lfrRequestedMode ); -rtems_task prc0_task( rtems_task_argument lfrRequestedMode ); - -//********** -// FUNCTIONS - -void reset_nb_sm_f0( unsigned char lfrMode ); - -//******* -// EXTERN -extern ring_node_sm *ring_node_for_averaging_sm_f0; -extern rtems_status_code get_message_queue_id_prc0( rtems_id *queue_id ); - -#endif // AVF0_PRC0_H_INCLUDED diff --git a/timegen/header/processing/avf1_prc1.h b/timegen/header/processing/avf1_prc1.h deleted file mode 100644 --- a/timegen/header/processing/avf1_prc1.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef AVF1_PRC1_H -#define AVF1_PRC1_H - -#include "fsw_processing.h" - -typedef struct { - unsigned int norm_bp1; - unsigned int norm_bp2; - unsigned int norm_asm; - unsigned int burst_sbm_bp1; - unsigned int burst_sbm_bp2; - unsigned int burst_bp1; - unsigned int burst_bp2; - unsigned int sbm2_bp1; - unsigned int sbm2_bp2; -} nb_sm_before_bp_asm_f1; - -//************ -// RTEMS TASKS -rtems_task avf1_task( rtems_task_argument lfrRequestedMode ); -rtems_task prc1_task( rtems_task_argument lfrRequestedMode ); - -//********** -// FUNCTIONS - -void reset_nb_sm_f1( unsigned char lfrMode ); - -//******* -// EXTERN -extern struct ring_node_sm *ring_node_for_averaging_sm_f1; -extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id ); - -#endif // AVF1_PRC1_H diff --git a/timegen/header/processing/avf2_prc2.h b/timegen/header/processing/avf2_prc2.h deleted file mode 100644 --- a/timegen/header/processing/avf2_prc2.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef AVF2_PRC2_H -#define AVF2_PRC2_H - -#include "fsw_processing.h" - -typedef struct { - unsigned int norm_bp1; - unsigned int norm_bp2; - unsigned int norm_asm; -} nb_sm_before_bp_asm_f2; - -//************ -// RTEMS TASKS -rtems_task avf2_task( rtems_task_argument lfrRequestedMode ); -rtems_task prc2_task( rtems_task_argument lfrRequestedMode ); - -//********** -// FUNCTIONS - -void reset_nb_sm_f2( void ); -void SM_average_f2( float *averaged_spec_mat_f2, ring_node_sm *ring_node, unsigned int nbAverageNormF2 ); - -//******* -// EXTERN -extern struct ring_node_sm *ring_node_for_averaging_sm_f2; -extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id ); - -#endif // AVF2_PRC2_H diff --git a/timegen/header/processing/fsw_processing.h b/timegen/header/processing/fsw_processing.h deleted file mode 100644 --- a/timegen/header/processing/fsw_processing.h +++ /dev/null @@ -1,243 +0,0 @@ -#ifndef FSW_PROCESSING_H_INCLUDED -#define FSW_PROCESSING_H_INCLUDED - -#include -#include -#include -#include // abs() is in the stdlib -#include // printf() -#include - -#include "fsw_params.h" -#include "fsw_spacewire.h" - -typedef struct ring_node_sm -{ - struct ring_node_sm *previous; - struct ring_node_sm *next; - int buffer_address; - unsigned int status; - unsigned int coarseTime; - unsigned int fineTime; -} ring_node_sm; - -typedef struct ring_node_asm -{ - struct ring_node_asm *next; - float matrix[ TOTAL_SIZE_SM ]; - unsigned int status; -} ring_node_asm; - -typedef struct -{ - Header_TM_LFR_SCIENCE_BP_t header; - unsigned char data[ 30 * 22 ]; // MAX size is 22 * 30 [TM_LFR_SCIENCE_BURST_BP2_F1] -} bp_packet; - -typedef struct -{ - Header_TM_LFR_SCIENCE_BP_with_spare_t header; - unsigned char data[ 9 * 13 ]; // only for TM_LFR_SCIENCE_NORMAL_BP1_F0 and F1 -} bp_packet_with_spare; - -typedef struct -{ - ring_node_asm *norm; - ring_node_asm *burst_sbm; - rtems_event_set event; - unsigned int coarseTime; - unsigned int fineTime; -} asm_msg; - -extern volatile int sm_f0[ ]; -extern volatile int sm_f1[ ]; -extern volatile int sm_f2[ ]; - -// parameters -extern struct param_local_str param_local; - -// registers -extern time_management_regs_t *time_management_regs; -extern spectral_matrix_regs_t *spectral_matrix_regs; - -extern rtems_name misc_name[5]; -extern rtems_id Task_id[20]; /* array of task ids */ - -// ISR -rtems_isr spectral_matrices_isr( rtems_vector_number vector ); -rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector ); - -//****************** -// Spectral Matrices -void reset_nb_sm( void ); -// SM -void SM_init_rings( void ); -void SM_reset_current_ring_nodes( void ); -void SM_generic_init_ring(ring_node_sm *ring, unsigned char nbNodes, volatile int sm_f[] ); -// ASM -void ASM_generic_init_ring(ring_node_asm *ring, unsigned char nbNodes ); -void ASM_init_header( Header_TM_LFR_SCIENCE_ASM_t *header); -void ASM_send(Header_TM_LFR_SCIENCE_ASM_t *header, char *spectral_matrix, - unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send, rtems_id queue_id); - -//***************** -// Basic Parameters - -void BP_reset_current_ring_nodes( void ); -void BP_init_header( Header_TM_LFR_SCIENCE_BP_t *header, - unsigned int apid, unsigned char sid, - unsigned int packetLength , unsigned char blkNr); -void BP_init_header_with_spare( Header_TM_LFR_SCIENCE_BP_with_spare_t *header, - unsigned int apid, unsigned char sid, - unsigned int packetLength, unsigned char blkNr ); -void BP_send( char *data, - rtems_id queue_id , - unsigned int nbBytesToSend , unsigned int sid ); - -//****************** -// general functions -void reset_spectral_matrix_regs( void ); -void set_time(unsigned char *time, unsigned char *timeInBuffer ); -unsigned long long int get_acquisition_time( unsigned char *timePtr ); -void close_matrix_actions(unsigned int *nb_sm, unsigned int nb_sm_before_avf, rtems_id avf_task_id, - ring_node_sm *node_for_averaging, ring_node_sm *ringNode, unsigned long long int time); -unsigned char getSID( rtems_event_set event ); - -extern rtems_status_code get_message_queue_id_prc1( rtems_id *queue_id ); -extern rtems_status_code get_message_queue_id_prc2( rtems_id *queue_id ); - -//*************************************** -// DEFINITIONS OF STATIC INLINE FUNCTIONS -static inline void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM, - ring_node_sm *ring_node_tab[], - unsigned int nbAverageNORM, unsigned int nbAverageSBM ); -static inline void ASM_reorganize_and_divide(float *averaged_spec_mat, float *averaged_spec_mat_reorganized, - float divider ); -static inline void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat, - float divider, - unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage , unsigned char ASMIndexStart); -static inline void ASM_convert(volatile float *input_matrix, char *output_matrix); - -void SM_average( float *averaged_spec_mat_NORM, float *averaged_spec_mat_SBM, - ring_node_sm *ring_node_tab[], - unsigned int nbAverageNORM, unsigned int nbAverageSBM ) -{ - float sum; - unsigned int i; - - for(i=0; ibuffer_address) ) [ i ] - + ( (int *) (ring_node_tab[1]->buffer_address) ) [ i ] - + ( (int *) (ring_node_tab[2]->buffer_address) ) [ i ] - + ( (int *) (ring_node_tab[3]->buffer_address) ) [ i ] - + ( (int *) (ring_node_tab[4]->buffer_address) ) [ i ] - + ( (int *) (ring_node_tab[5]->buffer_address) ) [ i ] - + ( (int *) (ring_node_tab[6]->buffer_address) ) [ i ] - + ( (int *) (ring_node_tab[7]->buffer_address) ) [ i ]; - - if ( (nbAverageNORM == 0) && (nbAverageSBM == 0) ) - { - averaged_spec_mat_NORM[ i ] = sum; - averaged_spec_mat_SBM[ i ] = sum; - } - else if ( (nbAverageNORM != 0) && (nbAverageSBM != 0) ) - { - averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum ); - averaged_spec_mat_SBM[ i ] = ( averaged_spec_mat_SBM[ i ] + sum ); - } - else if ( (nbAverageNORM != 0) && (nbAverageSBM == 0) ) - { - averaged_spec_mat_NORM[ i ] = ( averaged_spec_mat_NORM[ i ] + sum ); - averaged_spec_mat_SBM[ i ] = sum; - } - else - { - PRINTF2("ERR *** in SM_average *** unexpected parameters %d %d\n", nbAverageNORM, nbAverageSBM) - } - } -} - -void ASM_reorganize_and_divide( float *averaged_spec_mat, float *averaged_spec_mat_reorganized, float divider ) -{ - int frequencyBin; - int asmComponent; - unsigned int offsetAveragedSpecMatReorganized; - unsigned int offsetAveragedSpecMat; - - for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++) - { - for( frequencyBin = 0; frequencyBin < NB_BINS_PER_SM; frequencyBin++ ) - { - offsetAveragedSpecMatReorganized = - frequencyBin * NB_VALUES_PER_SM - + asmComponent; - offsetAveragedSpecMat = - asmComponent * NB_BINS_PER_SM - + frequencyBin; - averaged_spec_mat_reorganized[offsetAveragedSpecMatReorganized ] = - averaged_spec_mat[ offsetAveragedSpecMat ] / divider; - } - } -} - -void ASM_compress_reorganize_and_divide(float *averaged_spec_mat, float *compressed_spec_mat , float divider, - unsigned char nbBinsCompressedMatrix, unsigned char nbBinsToAverage, unsigned char ASMIndexStart ) -{ - int frequencyBin; - int asmComponent; - int offsetASM; - int offsetCompressed; - int k; - - // build data - for (asmComponent = 0; asmComponent < NB_VALUES_PER_SM; asmComponent++) - { - for( frequencyBin = 0; frequencyBin < nbBinsCompressedMatrix; frequencyBin++ ) - { - offsetCompressed = // NO TIME OFFSET - frequencyBin * NB_VALUES_PER_SM - + asmComponent; - offsetASM = // NO TIME OFFSET - asmComponent * NB_BINS_PER_SM - + ASMIndexStart - + frequencyBin * nbBinsToAverage; - compressed_spec_mat[ offsetCompressed ] = 0; - for ( k = 0; k < nbBinsToAverage; k++ ) - { - compressed_spec_mat[offsetCompressed ] = - ( compressed_spec_mat[ offsetCompressed ] - + averaged_spec_mat[ offsetASM + k ] ) / (divider * nbBinsToAverage); - } - } - } -} - -void ASM_convert( volatile float *input_matrix, char *output_matrix) -{ - unsigned int frequencyBin; - unsigned int asmComponent; - char * pt_char_input; - char * pt_char_output; - unsigned int offsetInput; - unsigned int offsetOutput; - - pt_char_input = (char*) &input_matrix; - pt_char_output = (char*) &output_matrix; - - // convert all other data - for( frequencyBin=0; frequencyBin -#include - -#include "tc_load_dump_parameters.h" -#include "tc_acceptance.h" -#include "tm_lfr_tc_exe.h" -#include "wf_handler.h" -#include "fsw_processing.h" - -#include "lfr_cpu_usage_report.h" - -// MODE PARAMETERS -extern unsigned int maxCount; - -//**** -// ISR -rtems_isr commutation_isr1( rtems_vector_number vector ); -rtems_isr commutation_isr2( rtems_vector_number vector ); - -void reset_transitionCoarseTime( void ); -void set_transitionCoarseTime( unsigned int value ); -unsigned int get_transitionCoarseTime( void ); - -//*********** -// RTEMS TASK -rtems_task actn_task( rtems_task_argument unused ); - -//*********** -// TC ACTIONS -int action_reset( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); -int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id); -int action_update_info( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); -int action_enable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); -int action_disable_calibration( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); -int action_update_time( ccsdsTelecommandPacket_t *TC); - -// mode transition -int check_mode_value( unsigned char requestedMode ); -int check_mode_transition( unsigned char requestedMode ); -int check_transition_date( unsigned int transitionCoarseTime ); -int stop_current_mode( void ); -int enter_mode( unsigned char mode , unsigned int transitionCoarseTime ); -int restart_science_tasks(unsigned char lfrRequestedMode ); -int suspend_science_tasks(); -void launch_waveform_picker(unsigned char mode , unsigned int transitionCoarseTime); -void launch_spectral_matrix( void ); -void launch_spectral_matrix_simu( void ); -void set_irq_on_new_ready_matrix(unsigned char value ); -void set_run_matrix_spectral( unsigned char value ); - -// other functions -void updateLFRCurrentMode(); -void update_last_TC_exe( ccsdsTelecommandPacket_t *TC , unsigned char *time ); -void update_last_TC_rej(ccsdsTelecommandPacket_t *TC , unsigned char *time ); -void close_action( ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ); - -extern rtems_status_code get_message_queue_id_send( rtems_id *queue_id ); -extern rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ); - -#endif // TC_HANDLER_H_INCLUDED - - - diff --git a/timegen/header/tc_load_dump_parameters.h b/timegen/header/tc_load_dump_parameters.h deleted file mode 100644 --- a/timegen/header/tc_load_dump_parameters.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef TC_LOAD_DUMP_PARAMETERS_H -#define TC_LOAD_DUMP_PARAMETERS_H - -#include -#include - -#include "fsw_params.h" -#include "wf_handler.h" -#include "tm_lfr_tc_exe.h" -#include "fsw_misc.h" - -#define FLOAT_EQUAL_ZERO 0.001 - -extern unsigned short sequenceCounterParameterDump; - -int action_load_common_par( ccsdsTelecommandPacket_t *TC ); -int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); -int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); -int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); -int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id , unsigned char *time); -int action_dump_par(rtems_id queue_id ); - -// NORMAL -int check_common_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); -int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC ); -int set_sy_lfr_n_swf_p( ccsdsTelecommandPacket_t *TC ); -int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC ); -int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC ); -int set_sy_lfr_n_bp_p1( ccsdsTelecommandPacket_t *TC ); -int set_sy_lfr_n_cwf_long_f3( ccsdsTelecommandPacket_t *TC ); - -// BURST -int set_sy_lfr_b_bp_p0( ccsdsTelecommandPacket_t *TC ); -int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC ); - -// SBM1 -int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC ); -int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC ); - -// SBM2 -int set_sy_lfr_s2_bp_p0( ccsdsTelecommandPacket_t *TC ); -int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC ); - -// TC_LFR_UPDATE_INFO -unsigned int check_update_info_hk_lfr_mode( unsigned char mode ); -unsigned int check_update_info_hk_tds_mode( unsigned char mode ); -unsigned int check_update_info_hk_thr_mode( unsigned char mode ); - -void init_parameter_dump( void ); - -#endif // TC_LOAD_DUMP_PARAMETERS_H diff --git a/timegen/header/tm_byte_positions.h b/timegen/header/tm_byte_positions.h deleted file mode 100644 --- a/timegen/header/tm_byte_positions.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef TM_BYTE_POSITIONS_H -#define TM_BYTE_POSITIONS_H - -#define BYTE_POS_CP_LFR_MODE 11 - -// TC_LFR_LOAD_COMMON_PAR - -// TC_LFR_LOAD_NORMAL_PAR -#define BYTE_POS_SY_LFR_N_SWF_L 0 -#define BYTE_POS_SY_LFR_N_SWF_P 2 -#define BYTE_POS_SY_LFR_N_ASM_P 4 -#define BYTE_POS_SY_LFR_N_BP_P0 6 -#define BYTE_POS_SY_LFR_N_BP_P1 7 -#define BYTE_POS_SY_LFR_N_CWF_LONG_F3 8 - -// TC_LFR_LOAD_BURST_PAR - -// TC_LFR_LOAD_SBM1_PAR - -// TC_LFR_LOAD_SBM2_PAR - - -#endif // TM_BYTE_POSITIONS_H diff --git a/timegen/header/tm_lfr_tc_exe.h b/timegen/header/tm_lfr_tc_exe.h deleted file mode 100644 --- a/timegen/header/tm_lfr_tc_exe.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef TM_LFR_TC_EXE_H_INCLUDED -#define TM_LFR_TC_EXE_H_INCLUDED - -#include -#include - -#include "fsw_params.h" -#include "fsw_spacewire.h" - -extern unsigned short sequenceCounters_TC_EXE[]; - -int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); -int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, - unsigned char byte_position, unsigned char rcv_value ); -int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); -int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ); -int send_tm_lfr_tc_exe_error(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ); -int send_tm_lfr_tc_exe_corrupted( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, - unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV, unsigned char destinationID ); - -void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id ); - -#endif // TM_LFR_TC_EXE_H_INCLUDED - - - diff --git a/timegen/header/wf_handler.h b/timegen/header/wf_handler.h deleted file mode 100644 --- a/timegen/header/wf_handler.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef WF_HANDLER_H_INCLUDED -#define WF_HANDLER_H_INCLUDED - -#include -#include -#include -#include - -#include "fsw_params.h" -#include "fsw_spacewire.h" -#include "fsw_misc.h" -#include "fsw_params_wf_handler.h" - -#define pi 3.1415 - -extern int fdSPW; - -//***************** -// waveform buffers -extern volatile int wf_snap_f0[ ]; -extern volatile int wf_snap_f1[ ]; -extern volatile int wf_snap_f2[ ]; -extern volatile int wf_cont_f3[ ]; -extern char wf_cont_f3_light[ ]; - -extern waveform_picker_regs_new_t *waveform_picker_regs; -extern time_management_regs_t *time_management_regs; -extern Packet_TM_LFR_HK_t housekeeping_packet; -extern Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet; -extern struct param_local_str param_local; - -extern unsigned short sequenceCounters_SCIENCE_NORMAL_BURST; -extern unsigned short sequenceCounters_SCIENCE_SBM1_SBM2; - -extern rtems_id Task_id[20]; /* array of task ids */ - -extern unsigned char lfrCurrentMode; - -//********** -// RTEMS_ISR -void reset_extractSWF( void ); -rtems_isr waveforms_isr( rtems_vector_number vector ); - -//*********** -// RTEMS_TASK -rtems_task wfrm_task( rtems_task_argument argument ); -rtems_task cwf3_task( rtems_task_argument argument ); -rtems_task cwf2_task( rtems_task_argument argument ); -rtems_task cwf1_task( rtems_task_argument argument ); -rtems_task swbd_task( rtems_task_argument argument ); - -//****************** -// general functions -void WFP_init_rings( void ); -void init_waveform_ring( ring_node waveform_ring[], unsigned char nbNodes, volatile int wfrm[] ); -void WFP_reset_current_ring_nodes( void ); -// -int init_header_snapshot_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF ); -int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF ); -int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF ); -// -int send_waveform_SWF( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id ); -int send_waveform_CWF( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id ); -int send_waveform_CWF3( volatile int *waveform, unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id ); -int send_waveform_CWF3_light( volatile int *waveform, Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id ); -// -void compute_acquisition_time(unsigned int coarseTime, unsigned int fineTime, - unsigned int sid, unsigned char pa_lfr_pkt_nr, unsigned char *acquisitionTime ); -void build_snapshot_from_ring(ring_node *ring_node_to_send , unsigned char frequencyChannel ); -void build_acquisition_time( unsigned long long int * acquisitionTimeAslong, ring_node *current_ring_node ); -// -rtems_id get_pkts_queue_id( void ); - -//************** -// wfp registers -// RESET -void reset_wfp_burst_enable( void ); -void reset_wfp_status(void); -void reset_waveform_picker_regs( void ); -// SET -void set_wfp_data_shaping(void); -void set_wfp_burst_enable_register( unsigned char mode ); -void set_wfp_delta_snapshot( void ); -void set_wfp_delta_f0_f0_2( void ); -void set_wfp_delta_f1( void ); -void set_wfp_delta_f2( void ); - -//***************** -// local parameters -void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid ); - -#endif // WF_HANDLER_H_INCLUDED diff --git a/timegen/src/fsw_config.c b/timegen/src/fsw_config.c deleted file mode 100644 --- a/timegen/src/fsw_config.c +++ /dev/null @@ -1,25 +0,0 @@ -#include - -// GRSPW0 resources -struct drvmgr_key grlib_grspw_0n1_res[] = { - {"txBdCnt", KEY_TYPE_INT, {(unsigned int)50}}, // 7 SWF_F0, 7 SWF_F1, 7 SWF_F2, 7 CWF_F3, 7 CWF_F1 ou 7 CWF_F2 - {"rxBdCnt", KEY_TYPE_INT, {(unsigned int)10}}, - {"txDataSize", KEY_TYPE_INT, {(unsigned int)4096}}, - {"txHdrSize", KEY_TYPE_INT, {(unsigned int)20+12}}, // 12 is for the auxiliary header, when needed - {"rxPktSize", KEY_TYPE_INT, {(unsigned int)248+4}}, - KEY_EMPTY -}; - -// If RTEMS_DRVMGR_STARTUP is defined we override the "weak defaults" that is defined by the LEON3 BSP. - -struct drvmgr_bus_res grlib_drv_resources = { - .next = NULL, - .resource = { - {DRIVER_AMBAPP_GAISLER_GRSPW_ID, 0, &grlib_grspw_0n1_res[0]}, -// {DRIVER_AMBAPP_GAISLER_APBUART_ID, 0, &grlib_drv_res_apbuart0[0]}, -// {DRIVER_AMBAPP_GAISLER_APBUART_ID, 1, &grlib_drv_res_apbuart1[0]}, - RES_EMPTY /* Mark end of device resource array */ - } -}; - - diff --git a/timegen/src/fsw_globals.c b/timegen/src/fsw_globals.c deleted file mode 100644 --- a/timegen/src/fsw_globals.c +++ /dev/null @@ -1,75 +0,0 @@ -/** Global variables of the LFR flight software. - * - * @file - * @author P. LEROY - * - * Among global variables, there are: - * - RTEMS names and id. - * - APB configuration registers. - * - waveforms global buffers, used by the waveform picker hardware module to store data. - * - spectral matrices buffesr, used by the hardware module to store data. - * - variable related to LFR modes parameters. - * - the global HK packet buffer. - * - the global dump parameter buffer. - * - */ - -#include -#include - -#include "ccsds_types.h" -#include "grlib_regs.h" -#include "fsw_params.h" -#include "fsw_params_wf_handler.h" - -// RTEMS GLOBAL VARIABLES -rtems_name misc_name[5]; -rtems_id misc_id[5]; -rtems_name Task_name[20]; /* array of task names */ -rtems_id Task_id[20]; /* array of task ids */ -unsigned int maxCount; -int fdSPW = 0; -int fdUART = 0; -unsigned char lfrCurrentMode; - -// WAVEFORMS GLOBAL VARIABLES // 2048 * 3 * 4 + 2 * 4 = 24576 + 8 bytes = 24584 - // 97 * 256 = 24832 => delta = 248 bytes = 62 words -// WAVEFORMS GLOBAL VARIABLES // 2688 * 3 * 4 + 2 * 4 = 32256 + 8 bytes = 32264 - // 127 * 256 = 32512 => delta = 248 bytes = 62 words -// F0 F1 F2 F3 -volatile int wf_snap_f0[ NB_RING_NODES_F0 * WFRM_BUFFER ] __attribute__((aligned(0x100))); -volatile int wf_snap_f1[ NB_RING_NODES_F1 * WFRM_BUFFER ] __attribute__((aligned(0x100))); -volatile int wf_snap_f2[ NB_RING_NODES_F2 * WFRM_BUFFER ] __attribute__((aligned(0x100))); -volatile int wf_cont_f3[ NB_RING_NODES_F3 * WFRM_BUFFER ] __attribute__((aligned(0x100))); -char wf_cont_f3_light[ (NB_SAMPLES_PER_SNAPSHOT) * NB_BYTES_CWF3_LIGHT_BLK + TIME_OFFSET_IN_BYTES ] __attribute__((aligned(0x100))); - -//*********************************** -// SPECTRAL MATRICES GLOBAL VARIABLES - -// alignment constraints for the spectral matrices buffers => the first data after the time (8 bytes) shall be aligned on 0x00 -volatile int sm_f0[ NB_RING_NODES_SM_F0 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))); -volatile int sm_f1[ NB_RING_NODES_SM_F1 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))); -volatile int sm_f2[ NB_RING_NODES_SM_F2 * TOTAL_SIZE_SM ] __attribute__((aligned(0x100))); - -// APB CONFIGURATION REGISTERS -time_management_regs_t *time_management_regs = (time_management_regs_t*) REGS_ADDR_TIME_MANAGEMENT; -gptimer_regs_t *gptimer_regs = (gptimer_regs_t *) REGS_ADDR_GPTIMER; -waveform_picker_regs_new_t *waveform_picker_regs = (waveform_picker_regs_new_t*) REGS_ADDR_WAVEFORM_PICKER; -spectral_matrix_regs_t *spectral_matrix_regs = (spectral_matrix_regs_t*) REGS_ADDR_SPECTRAL_MATRIX; - -// MODE PARAMETERS -Packet_TM_LFR_PARAMETER_DUMP_t parameter_dump_packet; -struct param_local_str param_local; - -// HK PACKETS -Packet_TM_LFR_HK_t housekeeping_packet; -// sequence counters are incremented by APID (PID + CAT) and destination ID -unsigned short sequenceCounters_SCIENCE_NORMAL_BURST; -unsigned short sequenceCounters_SCIENCE_SBM1_SBM2; -unsigned short sequenceCounters_TC_EXE[SEQ_CNT_NB_DEST_ID]; -unsigned short sequenceCounterHK; -unsigned short sequenceCounterParameterDump; -spw_stats spacewire_stats; -spw_stats spacewire_stats_backup; - - diff --git a/timegen/src/fsw_init.c b/timegen/src/fsw_init.c deleted file mode 100644 --- a/timegen/src/fsw_init.c +++ /dev/null @@ -1,489 +0,0 @@ -/** This is the RTEMS initialization module. - * - * @file - * @author P. LEROY - * - * This module contains two very different information: - * - specific instructions to configure the compilation of the RTEMS executive - * - functions related to the fligth softwre initialization, especially the INIT RTEMS task - * - */ - -//************************* -// GPL reminder to be added -//************************* - -#include - -/* configuration information */ - -#define CONFIGURE_INIT - -#include /* for device driver prototypes */ - -/* configuration information */ - -#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER -#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER - -#define CONFIGURE_MAXIMUM_TASKS 20 -#define CONFIGURE_RTEMS_INIT_TASKS_TABLE -#define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE) -#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 32 -#define CONFIGURE_INIT_TASK_PRIORITY 1 // instead of 100 -#define CONFIGURE_INIT_TASK_MODE (RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT) -#define CONFIGURE_INIT_TASK_ATTRIBUTES (RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT) -#define CONFIGURE_MAXIMUM_DRIVERS 16 -#define CONFIGURE_MAXIMUM_PERIODS 5 -#define CONFIGURE_MAXIMUM_TIMERS 5 // STAT (1s), send SWF (0.3s), send CWF3 (1s) -#define CONFIGURE_MAXIMUM_MESSAGE_QUEUES 5 -#ifdef PRINT_STACK_REPORT - #define CONFIGURE_STACK_CHECKER_ENABLED -#endif - -#include - -/* If --drvmgr was enabled during the configuration of the RTEMS kernel */ -#ifdef RTEMS_DRVMGR_STARTUP - #ifdef LEON3 - /* Add Timer and UART Driver */ - #ifdef CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER - #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GPTIMER - #endif - #ifdef CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER - #define CONFIGURE_DRIVER_AMBAPP_GAISLER_APBUART - #endif - #endif - #define CONFIGURE_DRIVER_AMBAPP_GAISLER_GRSPW /* GRSPW Driver */ - #include -#endif - -#include "fsw_init.h" -#include "fsw_config.c" - -rtems_id rtems_task_id_updt; -rtems_name rtems_task_name_updt; - -rtems_task Init( rtems_task_argument ignored ) -{ - /** This is the RTEMS INIT taks, it the first task launched by the system. - * - * @param unused is the starting argument of the RTEMS task - * - * The INIT task create and run all other RTEMS tasks. - * - */ - - unsigned char *vhdlVersion; - - reset_local_time(); - - rtems_cpu_usage_reset(); - - rtems_status_code status; - rtems_status_code status_spw; - - struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO; - - // UART settings - send_console_outputs_on_apbuart_port(); - set_apbuart_scaler_reload_register(REGS_ADDR_APBUART, APBUART_SCALER_RELOAD_VALUE); - enable_apbuart_transmitter(); - DEBUG_PRINTF("\n\n\n\n\nIn INIT *** Now the console is on port COM1\n") - - PRINTF("\n\n\n\n\n") - PRINTF("*************************\n") - PRINTF("** timegen for LFR **\n") - PRINTF1("** %d.", SW_VERSION_N1) - PRINTF1("%d." , SW_VERSION_N2) - PRINTF1("%d." , SW_VERSION_N3) - PRINTF1("%d **\n", SW_VERSION_N4) - - vhdlVersion = (unsigned char *) (REGS_ADDR_VHDL_VERSION); - PRINTF("** VHDL **\n") - PRINTF1("** %d.", vhdlVersion[1]) - PRINTF1("%d." , vhdlVersion[2]) - PRINTF1("%d **\n", vhdlVersion[3]) - PRINTF("*************************\n") - PRINTF("\n\n") - - create_names(); // create all names - - status = create_message_queues(); // create message queues - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in INIT *** ERR in create_message_queues, code %d", status) - } - - status = create_all_tasks(); // create all tasks - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in INIT *** ERR in create_all_tasks, code %d\n", status) - } - - // ************************** - // - grspw_timecode_callback = &timecode_irq_handler; - - status_spw = spacewire_open_link(); // (1) open the link - if ( status_spw != RTEMS_SUCCESSFUL ) - { - PRINTF1("in INIT *** ERR spacewire_open_link code %d\n", status_spw ) - } - - if ( status_spw == RTEMS_SUCCESSFUL ) // (2) configure the link - { - status_spw = spacewire_configure_link( fdSPW ); - if ( status_spw != RTEMS_SUCCESSFUL ) - { - PRINTF1("in INIT *** ERR spacewire_configure_link code %d\n", status_spw ) - } - } - - if ( status_spw == RTEMS_SUCCESSFUL) // (3) start the link - { - status_spw = spacewire_start_link( fdSPW ); - if ( status_spw != RTEMS_SUCCESSFUL ) - { - PRINTF1("in INIT *** ERR spacewire_start_link code %d\n", status_spw ) - } - } - // - // *************************** - - status = start_all_tasks(); // start all tasks - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in INIT *** ERR in start_all_tasks, code %d", status) - } - - // start RECV and SEND *AFTER* SpaceWire Initialization, due to the timeout of the start call during the initialization - status = start_recv_send_tasks(); - if ( status != RTEMS_SUCCESSFUL ) - { - PRINTF1("in INIT *** ERR start_recv_send_tasks code %d\n", status ) - } - - // suspend science tasks, they will be restarted later depending on the mode - status = suspend_science_tasks(); // suspend science tasks (not done in stop_current_mode if current mode = STANDBY) - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in INIT *** in suspend_science_tasks *** ERR code: %d\n", status) - } - - // if the spacewire link is not up then send an event to the SPIQ task for link recovery - if ( status_spw != RTEMS_SUCCESSFUL ) - { - status = rtems_event_send( Task_id[TASKID_SPIQ], SPW_LINKERR_EVENT ); - if ( status != RTEMS_SUCCESSFUL ) { - PRINTF1("in INIT *** ERR rtems_event_send to SPIQ code %d\n", status ) - } - } - - //********************************* - // init GPIO for trigger generation - grgpio_regs->io_port_direction_register = - grgpio_regs->io_port_direction_register | 0x04; // [0000 0100], 0 = output disabled, 1 = output enabled - grgpio_regs->io_port_direction_register = - grgpio_regs->io_port_direction_register | 0x08; // [0000 1000], 0 = output disabled, 1 = output enabled - - BOOT_PRINTF("delete INIT\n") - - status = rtems_task_delete(RTEMS_SELF); - -} - -void init_local_mode_parameters( void ) -{ - /** This function initialize the param_local global variable with default values. - * - */ - - unsigned int i; - - // LOCAL PARAMETERS - - BOOT_PRINTF1("local_sbm1_nb_cwf_max %d \n", param_local.local_sbm1_nb_cwf_max) - BOOT_PRINTF1("local_sbm2_nb_cwf_max %d \n", param_local.local_sbm2_nb_cwf_max) - // BOOT_PRINTF1("nb_interrupt_f0_MAX = %d\n", param_local.local_nb_interrupt_f0_MAX) - - // init sequence counters - - for(i = 0; ictrl = 0x02; // software reset, coarse time = 0x80000000 -} - -void create_names( void ) // create all names for tasks and queues -{ - /** This function creates all RTEMS names used in the software for tasks and queues. - * - * @return RTEMS directive status codes: - * - RTEMS_SUCCESSFUL - successful completion - * - */ - - // task names - Task_name[TASKID_RECV] = rtems_build_name( 'R', 'E', 'C', 'V' ); - Task_name[TASKID_ACTN] = rtems_build_name( 'A', 'C', 'T', 'N' ); - Task_name[TASKID_SPIQ] = rtems_build_name( 'S', 'P', 'I', 'Q' ); - Task_name[TASKID_STAT] = rtems_build_name( 'S', 'T', 'A', 'T' ); - Task_name[TASKID_DUMB] = rtems_build_name( 'D', 'U', 'M', 'B' ); - Task_name[TASKID_SEND] = rtems_build_name( 'S', 'E', 'N', 'D' ); - Task_name[TASKID_WTDG] = rtems_build_name( 'W', 'T', 'D', 'G' ); - - rtems_task_name_updt = rtems_build_name( 'U', 'P', 'D', 'T' ); - - misc_name[QUEUE_RECV] = rtems_build_name( 'Q', '_', 'R', 'V' ); - misc_name[QUEUE_SEND] = rtems_build_name( 'Q', '_', 'S', 'D' ); - -} - -int create_all_tasks( void ) // create all tasks which run in the software -{ - /** This function creates all RTEMS tasks used in the software. - * - * @return RTEMS directive status codes: - * - RTEMS_SUCCESSFUL - task created successfully - * - RTEMS_INVALID_ADDRESS - id is NULL - * - RTEMS_INVALID_NAME - invalid task name - * - RTEMS_INVALID_PRIORITY - invalid task priority - * - RTEMS_MP_NOT_CONFIGURED - multiprocessing not configured - * - RTEMS_TOO_MANY - too many tasks created - * - RTEMS_UNSATISFIED - not enough memory for stack/FP context - * - RTEMS_TOO_MANY - too many global objects - * - */ - - rtems_status_code status; - - //********** - // SPACEWIRE - // RECV - status = rtems_task_create( - Task_name[TASKID_RECV], TASK_PRIORITY_RECV, RTEMS_MINIMUM_STACK_SIZE, - RTEMS_DEFAULT_MODES, - RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_RECV] - ); - if (status == RTEMS_SUCCESSFUL) // SEND - { - status = rtems_task_create( - Task_name[TASKID_SEND], TASK_PRIORITY_SEND, RTEMS_MINIMUM_STACK_SIZE, - RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, - RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SEND] - ); - } - if (status == RTEMS_SUCCESSFUL) // WTDG - { - status = rtems_task_create( - Task_name[TASKID_WTDG], TASK_PRIORITY_WTDG, RTEMS_MINIMUM_STACK_SIZE, - RTEMS_DEFAULT_MODES, - RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_WTDG] - ); - } - if (status == RTEMS_SUCCESSFUL) // ACTN - { - status = rtems_task_create( - Task_name[TASKID_ACTN], TASK_PRIORITY_ACTN, RTEMS_MINIMUM_STACK_SIZE, - RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, - RTEMS_DEFAULT_ATTRIBUTES | RTEMS_FLOATING_POINT, &Task_id[TASKID_ACTN] - ); - } - if (status == RTEMS_SUCCESSFUL) // SPIQ - { - status = rtems_task_create( - Task_name[TASKID_SPIQ], TASK_PRIORITY_SPIQ, RTEMS_MINIMUM_STACK_SIZE, - RTEMS_DEFAULT_MODES | RTEMS_NO_PREEMPT, - RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_SPIQ] - ); - } - - //***** - // MISC - if (status == RTEMS_SUCCESSFUL) // STAT - { - status = rtems_task_create( - Task_name[TASKID_STAT], TASK_PRIORITY_STAT, RTEMS_MINIMUM_STACK_SIZE, - RTEMS_DEFAULT_MODES, - RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_STAT] - ); - } - if (status == RTEMS_SUCCESSFUL) // DUMB - { - status = rtems_task_create( - Task_name[TASKID_DUMB], TASK_PRIORITY_DUMB, RTEMS_MINIMUM_STACK_SIZE, - RTEMS_DEFAULT_MODES, - RTEMS_DEFAULT_ATTRIBUTES, &Task_id[TASKID_DUMB] - ); - } - if (status == RTEMS_SUCCESSFUL) // UPDT - { - status = rtems_task_create( - rtems_task_name_updt, TASK_PRIORITY_HOUS, RTEMS_MINIMUM_STACK_SIZE, - RTEMS_DEFAULT_MODES, - RTEMS_DEFAULT_ATTRIBUTES, &rtems_task_id_updt - ); - } - - return status; -} - -int start_recv_send_tasks( void ) -{ - rtems_status_code status; - - status = rtems_task_start( Task_id[TASKID_RECV], recv_task, 1 ); - if (status!=RTEMS_SUCCESSFUL) { - BOOT_PRINTF("in INIT *** Error starting TASK_RECV\n") - } - - if (status == RTEMS_SUCCESSFUL) // SEND - { - status = rtems_task_start( Task_id[TASKID_SEND], send_task, 1 ); - if (status!=RTEMS_SUCCESSFUL) { - BOOT_PRINTF("in INIT *** Error starting TASK_SEND\n") - } - } - - return status; -} - -int start_all_tasks( void ) // start all tasks except SEND RECV and HOUS -{ - /** This function starts all RTEMS tasks used in the software. - * - * @return RTEMS directive status codes: - * - RTEMS_SUCCESSFUL - ask started successfully - * - RTEMS_INVALID_ADDRESS - invalid task entry point - * - RTEMS_INVALID_ID - invalid task id - * - RTEMS_INCORRECT_STATE - task not in the dormant state - * - RTEMS_ILLEGAL_ON_REMOTE_OBJECT - cannot start remote task - * - */ - // starts all the tasks fot eh flight software - - rtems_status_code status; - - //********** - // SPACEWIRE - status = rtems_task_start( Task_id[TASKID_SPIQ], spiq_task, 1 ); - if (status!=RTEMS_SUCCESSFUL) { - BOOT_PRINTF("in INIT *** Error starting TASK_SPIQ\n") - } - - if (status == RTEMS_SUCCESSFUL) // WTDG - { - status = rtems_task_start( Task_id[TASKID_WTDG], wtdg_task, 1 ); - if (status!=RTEMS_SUCCESSFUL) { - BOOT_PRINTF("in INIT *** Error starting TASK_WTDG\n") - } - } - - if (status == RTEMS_SUCCESSFUL) // ACTN - { - status = rtems_task_start( Task_id[TASKID_ACTN], actn_task, 1 ); - if (status!=RTEMS_SUCCESSFUL) { - BOOT_PRINTF("in INIT *** Error starting TASK_ACTN\n") - } - } - - //***** - // MISC - if (status == RTEMS_SUCCESSFUL) // DUMB - { - status = rtems_task_start( Task_id[TASKID_DUMB], dumb_task, 1 ); - if (status!=RTEMS_SUCCESSFUL) { - BOOT_PRINTF("in INIT *** Error starting TASK_DUMB\n") - } - } - if (status == RTEMS_SUCCESSFUL) // STAT - { - status = rtems_task_start( Task_id[TASKID_STAT], stat_task, 1 ); - if (status!=RTEMS_SUCCESSFUL) { - BOOT_PRINTF("in INIT *** Error starting TASK_STAT\n") - } - } - if (status == RTEMS_SUCCESSFUL) // UPDT - { - status = rtems_task_start( rtems_task_id_updt, updt_task, 1 ); - if (status!=RTEMS_SUCCESSFUL) { - BOOT_PRINTF("in INIT *** Error starting TASK_UPDT\n") - } - } - - return status; -} - -rtems_status_code create_message_queues( void ) // create the two message queues used in the software -{ - rtems_status_code status_recv; - rtems_status_code status_send; - - rtems_status_code ret; - rtems_id queue_id; - - ret = LFR_SUCCESSFUL; - - //**************************************** - // create the queue for handling valid TCs - status_recv = rtems_message_queue_create( misc_name[QUEUE_RECV], - MSG_QUEUE_COUNT_RECV, CCSDS_TC_PKT_MAX_SIZE, - RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); - if ( status_recv != RTEMS_SUCCESSFUL ) { - PRINTF1("in create_message_queues *** ERR creating QUEU queue, %d\n", status_recv) - } - - //************************************************ - // create the queue for handling TM packet sending - status_send = rtems_message_queue_create( misc_name[QUEUE_SEND], - MSG_QUEUE_COUNT_SEND, MSG_QUEUE_SIZE_SEND, - RTEMS_FIFO | RTEMS_LOCAL, &queue_id ); - if ( status_send != RTEMS_SUCCESSFUL ) { - PRINTF1("in create_message_queues *** ERR creating PKTS queue, %d\n", status_send) - } - - if ( status_recv != RTEMS_SUCCESSFUL ) - { - ret = status_recv; - } - else if( status_send != RTEMS_SUCCESSFUL ) - { - ret = status_send; - } - - return ret; -} - -rtems_status_code get_message_queue_id_send( rtems_id *queue_id ) -{ - rtems_status_code status; - rtems_name queue_name; - - queue_name = rtems_build_name( 'Q', '_', 'S', 'D' ); - - status = rtems_message_queue_ident( queue_name, 0, queue_id ); - - return status; -} - -rtems_status_code get_message_queue_id_recv( rtems_id *queue_id ) -{ - rtems_status_code status; - rtems_name queue_name; - - queue_name = rtems_build_name( 'Q', '_', 'R', 'V' ); - - status = rtems_message_queue_ident( queue_name, 0, queue_id ); - - return status; -} diff --git a/timegen/src/fsw_misc.c b/timegen/src/fsw_misc.c deleted file mode 100644 --- a/timegen/src/fsw_misc.c +++ /dev/null @@ -1,252 +0,0 @@ -/** General usage functions and RTEMS tasks. - * - * @file - * @author P. LEROY - * - */ - -#include "fsw_misc.h" - -void configure_timer(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider, - unsigned char interrupt_level, rtems_isr (*timer_isr)() ) -{ - /** This function configures a GPTIMER timer instantiated in the VHDL design. - * - * @param gptimer_regs points to the APB registers of the GPTIMER IP core. - * @param timer is the number of the timer in the IP core (several timers can be instantiated). - * @param clock_divider is the divider of the 1 MHz clock that will be configured. - * @param interrupt_level is the interrupt level that the timer drives. - * @param timer_isr is the interrupt subroutine that will be attached to the IRQ driven by the timer. - * - * Interrupt levels are described in the SPARC documentation sparcv8.pdf p.76 - * - */ - - rtems_status_code status; - rtems_isr_entry old_isr_handler; - - gptimer_regs->timer[timer].ctrl = 0x00; // reset the control register - - status = rtems_interrupt_catch( timer_isr, interrupt_level, &old_isr_handler) ; // see sparcv8.pdf p.76 for interrupt levels - if (status!=RTEMS_SUCCESSFUL) - { - PRINTF("in configure_timer *** ERR rtems_interrupt_catch\n") - } - - timer_set_clock_divider( gptimer_regs, timer, clock_divider); -} - -void timer_start(gptimer_regs_t *gptimer_regs, unsigned char timer) -{ - /** This function starts a GPTIMER timer. - * - * @param gptimer_regs points to the APB registers of the GPTIMER IP core. - * @param timer is the number of the timer in the IP core (several timers can be instantiated). - * - */ - - gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any - gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000004; // LD load value from the reload register - gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000001; // EN enable the timer - gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000002; // RS restart - gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000008; // IE interrupt enable -} - -void timer_stop(gptimer_regs_t *gptimer_regs, unsigned char timer) -{ - /** This function stops a GPTIMER timer. - * - * @param gptimer_regs points to the APB registers of the GPTIMER IP core. - * @param timer is the number of the timer in the IP core (several timers can be instantiated). - * - */ - - gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xfffffffe; // EN enable the timer - gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl & 0xffffffef; // IE interrupt enable - gptimer_regs->timer[timer].ctrl = gptimer_regs->timer[timer].ctrl | 0x00000010; // clear pending IRQ if any -} - -void timer_set_clock_divider(gptimer_regs_t *gptimer_regs, unsigned char timer, unsigned int clock_divider) -{ - /** This function sets the clock divider of a GPTIMER timer. - * - * @param gptimer_regs points to the APB registers of the GPTIMER IP core. - * @param timer is the number of the timer in the IP core (several timers can be instantiated). - * @param clock_divider is the divider of the 1 MHz clock that will be configured. - * - */ - - gptimer_regs->timer[timer].reload = clock_divider; // base clock frequency is 1 MHz -} - -int send_console_outputs_on_apbuart_port( void ) // Send the console outputs on the apbuart port -{ - struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; - - apbuart_regs->ctrl = APBUART_CTRL_REG_MASK_TE; - - return 0; -} - -int enable_apbuart_transmitter( void ) // set the bit 1, TE Transmitter Enable to 1 in the APBUART control register -{ - struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) REGS_ADDR_APBUART; - - apbuart_regs->ctrl = apbuart_regs->ctrl | APBUART_CTRL_REG_MASK_TE; - - return 0; -} - -void set_apbuart_scaler_reload_register(unsigned int regs, unsigned int value) -{ - /** This function sets the scaler reload register of the apbuart module - * - * @param regs is the address of the apbuart registers in memory - * @param value is the value that will be stored in the scaler register - * - * The value shall be set by the software to get data on the serial interface. - * - */ - - struct apbuart_regs_str *apbuart_regs = (struct apbuart_regs_str *) regs; - - apbuart_regs->scaler = value; - BOOT_PRINTF1("OK *** apbuart port scaler reload register set to 0x%x\n", value) -} - -//************ -// RTEMS TASKS - -rtems_task stat_task(rtems_task_argument argument) -{ - int i; - int j; - i = 0; - j = 0; - BOOT_PRINTF("in STAT *** \n") - while(1){ - rtems_task_wake_after(1000); - PRINTF1("%d\n", j) - if (i == CPU_USAGE_REPORT_PERIOD) { -// #ifdef PRINT_TASK_STATISTICS -// rtems_cpu_usage_report(); -// rtems_cpu_usage_reset(); -// #endif - i = 0; - } - else i++; - j++; - } -} - -rtems_task dumb_task( rtems_task_argument unused ) -{ - /** This RTEMS taks is used to print messages without affecting the general behaviour of the software. - * - * @param unused is the starting argument of the RTEMS task - * - * The DUMB taks waits for RTEMS events and print messages depending on the incoming events. - * - */ - - unsigned int i; - unsigned int intEventOut; - unsigned int coarse_time = 0; - unsigned int fine_time = 0; - rtems_event_set event_out; - - char *DumbMessages[12] = {"in DUMB *** default", // RTEMS_EVENT_0 - "in DUMB *** timecode_irq_handler", // RTEMS_EVENT_1 - "in DUMB *** f3 buffer changed", // RTEMS_EVENT_2 - "in DUMB *** in SMIQ *** Error sending event to AVF0", // RTEMS_EVENT_3 - "in DUMB *** spectral_matrices_isr *** Error sending event to SMIQ", // RTEMS_EVENT_4 - "in DUMB *** waveforms_simulator_isr", // RTEMS_EVENT_5 - "ERR HK", // RTEMS_EVENT_6 - "ready for dump", // RTEMS_EVENT_7 - "VHDL ERR *** spectral matrix", // RTEMS_EVENT_8 - "tick", // RTEMS_EVENT_9 - "VHDL ERR *** waveform picker", // RTEMS_EVENT_10 - "VHDL ERR *** unexpected ready matrix values" // RTEMS_EVENT_11 - }; - - BOOT_PRINTF("in DUMB *** \n") - - while(1){ - rtems_event_receive(RTEMS_EVENT_0 | RTEMS_EVENT_1 | RTEMS_EVENT_2 | RTEMS_EVENT_3 - | RTEMS_EVENT_4 | RTEMS_EVENT_5 | RTEMS_EVENT_6 | RTEMS_EVENT_7 - | RTEMS_EVENT_8 | RTEMS_EVENT_9, - RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT - intEventOut = (unsigned int) event_out; - for ( i=0; i<32; i++) - { - if ( ((intEventOut >> i) & 0x0001) != 0) - { - coarse_time = time_management_regs->coarse_time; - fine_time = time_management_regs->fine_time; - printf("in DUMB *** coarse: %x, fine: %x, %s\n", coarse_time, fine_time, DumbMessages[i]); - if (i==8) - { - } - if (i==10) - { - } - } - } - } -} - -//***************************** -// init housekeeping parameters - -void increment_seq_counter( unsigned short *packetSequenceControl ) -{ - /** This function increment the sequence counter psased in argument. - * - * The increment does not affect the grouping flag. In case of an overflow, the counter is reset to 0. - * - */ - - unsigned short segmentation_grouping_flag; - unsigned short sequence_cnt; - - segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; // keep bits 7 downto 6 - sequence_cnt = (*packetSequenceControl) & 0x3fff; // [0011 1111 1111 1111] - - if ( sequence_cnt < SEQ_CNT_MAX) - { - sequence_cnt = sequence_cnt + 1; - } - else - { - sequence_cnt = 0; - } - - *packetSequenceControl = segmentation_grouping_flag | sequence_cnt ; -} - -void getTime( unsigned char *time) -{ - /** This function write the current local time in the time buffer passed in argument. - * - */ - - time[0] = (unsigned char) (time_management_regs->coarse_time>>24); - time[1] = (unsigned char) (time_management_regs->coarse_time>>16); - time[2] = (unsigned char) (time_management_regs->coarse_time>>8); - time[3] = (unsigned char) (time_management_regs->coarse_time); - time[4] = (unsigned char) (time_management_regs->fine_time>>8); - time[5] = (unsigned char) (time_management_regs->fine_time); -} - -unsigned long long int getTimeAsUnsignedLongLongInt( ) -{ - /** This function write the current local time in the time buffer passed in argument. - * - */ - unsigned long long int time; - - time = ( (unsigned long long int) (time_management_regs->coarse_time & 0x7fffffff) << 16 ) - + time_management_regs->fine_time; - - return time; -} diff --git a/timegen/src/fsw_processing_globals.c b/timegen/src/fsw_processing_globals.c deleted file mode 100644 --- a/timegen/src/fsw_processing_globals.c +++ /dev/null @@ -1,46 +0,0 @@ -/** Global variables used by the processing functions. - * - * @file - * @author P. LEROY - * - */ - -// TOTAL = 32 coefficients * 4 = 128 octets * 3 * 12 = 4608 octets -// SX 12 coefficients -float K14_sx_re = 1; -float K14_sx_im = 1; -float K15_sx_re = 1; -float K15_sx_im = 1; -float K24_sx_re = 1; -float K24_sx_im = 1; -float K25_sx_re = 1; -float K25_sx_im = 1; -float K34_sx_re = 1; -float K34_sx_im = 1; -float K35_sx_re = 1; -float K35_sx_im = 1; -// NY 8 coefficients -float K24_ny_re = 1; -float K24_ny_im = 1; -float K25_ny_re = 1; -float K25_ny_im = 1; -float K34_ny_re = 1; -float K34_ny_im = 1; -float K35_ny_re = 1; -float K35_ny_im = 1; -// NZ 8 coefficients -float K24_nz_re = 1; -float K24_nz_im = 1; -float K25_nz_re = 1; -float K25_nz_im = 1; -float K34_nz_re = 1; -float K34_nz_im = 1; -float K35_nz_re = 1; -float K35_nz_im = 1; -// PE 4 coefficients -float K44_pe = 1; -float K55_pe = 1; -float K45_pe_re = 1; -float K45_pe_im = 1; - -float Alpha_M = M_PI/4; diff --git a/timegen/src/fsw_spacewire.c b/timegen/src/fsw_spacewire.c deleted file mode 100644 --- a/timegen/src/fsw_spacewire.c +++ /dev/null @@ -1,728 +0,0 @@ -/** Functions related to the SpaceWire interface. - * - * @file - * @author P. LEROY - * - * A group of functions to handle SpaceWire transmissions: - * - configuration of the SpaceWire link - * - SpaceWire related interruption requests processing - * - transmission of TeleMetry packets by a dedicated RTEMS task - * - reception of TeleCommands by a dedicated RTEMS task - * - */ - -#include "fsw_spacewire.h" - -rtems_name semq_name; -rtems_id semq_id; - -unsigned int localCoarseTime; - -void resetLocalCoarseTime() -{ - localCoarseTime = 0; -} - -void setLocalCoarseTime( unsigned int value ) -{ - localCoarseTime = value; -} - -unsigned int getLocalCoarseTime() -{ - return localCoarseTime; -} - -void incrementLocalCoarseTime() -{ - localCoarseTime = localCoarseTime + 1; -} - -//*********** -// RTEMS TASK -rtems_task spiq_task(rtems_task_argument unused) -{ - /** This RTEMS task is awaken by an rtems_event sent by the interruption subroutine of the SpaceWire driver. - * - * @param unused is the starting argument of the RTEMS task - * - */ - - rtems_event_set event_out; - rtems_status_code status; - int linkStatus; - - BOOT_PRINTF("in SPIQ *** \n") - - while(true){ - rtems_event_receive(SPW_LINKERR_EVENT, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT - PRINTF("in SPIQ *** got SPW_LINKERR_EVENT\n") - - // [0] SUSPEND RECV AND SEND TASKS - status = rtems_task_suspend( Task_id[ TASKID_RECV ] ); - if ( status != RTEMS_SUCCESSFUL ) { - PRINTF("in SPIQ *** ERR suspending RECV Task\n") - } - status = rtems_task_suspend( Task_id[ TASKID_SEND ] ); - if ( status != RTEMS_SUCCESSFUL ) { - PRINTF("in SPIQ *** ERR suspending SEND Task\n") - } - - // [1] CHECK THE LINK - status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (1) - if ( linkStatus != 5) { - PRINTF1("in SPIQ *** linkStatus %d, wait...\n", linkStatus) - status = rtems_task_wake_after( SY_LFR_DPU_CONNECT_TIMEOUT ); // wait SY_LFR_DPU_CONNECT_TIMEOUT 1000 ms - } - - // [2] RECHECK THE LINK AFTER SY_LFR_DPU_CONNECT_TIMEOUT - status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status (2) - if ( linkStatus != 5 ) // [2.a] not in run state, reset the link - { - spacewire_compute_stats_offsets(); - status = spacewire_reset_link( ); - } - else // [2.b] in run state, start the link - { - status = spacewire_stop_and_start_link( fdSPW ); // start the link - if ( status != RTEMS_SUCCESSFUL) - { - PRINTF1("in SPIQ *** ERR spacewire_start_link %d\n", status) - } - } - - // [3] COMPLETE RECOVERY ACTION AFTER SY_LFR_DPU_CONNECT_ATTEMPTS - if ( status == RTEMS_SUCCESSFUL ) // [3.a] the link is in run state and has been started successfully - { - status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); - if ( status != RTEMS_SUCCESSFUL ) { - PRINTF("in SPIQ *** ERR resuming SEND Task\n") - } - status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); - if ( status != RTEMS_SUCCESSFUL ) { - PRINTF("in SPIQ *** ERR resuming RECV Task\n") - } - } - else // [3.b] the link is not in run state, go in STANDBY mode - { - status = stop_current_mode(); - if ( status != RTEMS_SUCCESSFUL ) { - PRINTF1("in SPIQ *** ERR stop_current_mode *** code %d\n", status) - } - status = enter_mode( LFR_MODE_STANDBY, 0 ); - if ( status != RTEMS_SUCCESSFUL ) { - PRINTF1("in SPIQ *** ERR enter_standby_mode *** code %d\n", status) - } - // wake the WTDG task up to wait for the link recovery - status = rtems_event_send ( Task_id[TASKID_WTDG], RTEMS_EVENT_0 ); - status = rtems_task_suspend( RTEMS_SELF ); - } - } -} - -rtems_task recv_task( rtems_task_argument unused ) -{ - /** This RTEMS task is dedicated to the reception of incoming TeleCommands. - * - * @param unused is the starting argument of the RTEMS task - * - * The RECV task blocks on a call to the read system call, waiting for incoming SpaceWire data. When unblocked: - * 1. It reads the incoming data. - * 2. Launches the acceptance procedure. - * 3. If the Telecommand is valid, sends it to a dedicated RTEMS message queue. - * - */ - - int len; - ccsdsTelecommandPacket_t currentTC; - unsigned char computed_CRC[ 2 ]; - unsigned char currentTC_LEN_RCV[ 2 ]; - unsigned char destinationID; - unsigned int estimatedPacketLength; - unsigned int parserCode; - rtems_status_code status; - rtems_id queue_recv_id; - rtems_id queue_send_id; - - initLookUpTableForCRC(); // the table is used to compute Cyclic Redundancy Codes - - status = get_message_queue_id_recv( &queue_recv_id ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in RECV *** ERR get_message_queue_id_recv %d\n", status) - } - - status = get_message_queue_id_send( &queue_send_id ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in RECV *** ERR get_message_queue_id_send %d\n", status) - } - - BOOT_PRINTF("in RECV *** \n") - - while(1) - { - len = read( fdSPW, (char*) ¤tTC, CCSDS_TC_PKT_MAX_SIZE ); // the call to read is blocking - if (len == -1){ // error during the read call - PRINTF1("in RECV *** last read call returned -1, ERRNO %d\n", errno) - } - else { - if ( (len+1) < CCSDS_TC_PKT_MIN_SIZE ) { - PRINTF("in RECV *** packet lenght too short\n") - } - else { - estimatedPacketLength = (unsigned int) (len - CCSDS_TC_TM_PACKET_OFFSET - 3); // => -3 is for Prot ID, Reserved and User App bytes - currentTC_LEN_RCV[ 0 ] = (unsigned char) (estimatedPacketLength >> 8); - currentTC_LEN_RCV[ 1 ] = (unsigned char) (estimatedPacketLength ); - // CHECK THE TC - parserCode = tc_parser( ¤tTC, estimatedPacketLength, computed_CRC ) ; - if ( (parserCode == ILLEGAL_APID) || (parserCode == WRONG_LEN_PKT) - || (parserCode == INCOR_CHECKSUM) || (parserCode == ILL_TYPE) - || (parserCode == ILL_SUBTYPE) || (parserCode == WRONG_APP_DATA) - || (parserCode == WRONG_SRC_ID) ) - { // send TM_LFR_TC_EXE_CORRUPTED - PRINTF1("TC corrupted received, with code: %d\n", parserCode) - if ( !( (currentTC.serviceType==TC_TYPE_TIME) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_TIME) ) - && - !( (currentTC.serviceType==TC_TYPE_GEN) && (currentTC.serviceSubType==TC_SUBTYPE_UPDT_INFO)) - ) - { - if ( parserCode == WRONG_SRC_ID ) - { - destinationID = SID_TC_GROUND; - } - else - { - destinationID = currentTC.sourceID; - } - } - } - else - { // send valid TC to the action launcher - status = rtems_message_queue_send( queue_recv_id, ¤tTC, - estimatedPacketLength + CCSDS_TC_TM_PACKET_OFFSET + 3); - } - } - } - } -} - -rtems_task send_task( rtems_task_argument argument) -{ - /** This RTEMS task is dedicated to the transmission of TeleMetry packets. - * - * @param unused is the starting argument of the RTEMS task - * - * The SEND task waits for a message to become available in the dedicated RTEMS queue. When a message arrives: - * - if the first byte is equal to CCSDS_DESTINATION_ID, the message is sent as is using the write system call. - * - if the first byte is not equal to CCSDS_DESTINATION_ID, the message is handled as a spw_ioctl_pkt_send. After - * analyzis, the packet is sent either using the write system call or using the ioctl call SPACEWIRE_IOCTRL_SEND, depending on the - * data it contains. - * - */ - - rtems_status_code status; // RTEMS status code - char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer - spw_ioctl_pkt_send *spw_ioctl_send; - size_t size; // size of the incoming TC packet - u_int32_t count; - rtems_id queue_id; - - status = get_message_queue_id_send( &queue_id ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) - } - - BOOT_PRINTF("in SEND *** \n") - - while(1) - { - status = rtems_message_queue_receive( queue_id, incomingData, &size, - RTEMS_WAIT, RTEMS_NO_TIMEOUT ); - - if (status!=RTEMS_SUCCESSFUL) - { - PRINTF1("in SEND *** (1) ERR = %d\n", status) - } - else - { - if ((incomingData[0] == CCSDS_DESTINATION_ID) || (incomingData[0] == (char) 0xfe)) // the incoming message is a ccsds packet - { - status = write( fdSPW, incomingData, size ); - if (status == -1){ - PRINTF2("in SEND *** (2.a) ERRNO = %d, size = %d\n", errno, size) - } - } - else // the incoming message is a spw_ioctl_pkt_send structure - { - spw_ioctl_send = (spw_ioctl_pkt_send*) incomingData; - status = ioctl( fdSPW, SPACEWIRE_IOCTRL_SEND, spw_ioctl_send ); - if (status == -1){ - PRINTF2("in SEND *** (2.b) ERRNO = %d, RTEMS = %d\n", errno, status) - } - } - } - - status = rtems_message_queue_get_number_pending( queue_id, &count ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in SEND *** (3) ERR = %d\n", status) - } - else - { - if (count > maxCount) - { - maxCount = count; - } - } - } -} - -rtems_task wtdg_task( rtems_task_argument argument ) -{ - rtems_event_set event_out; - rtems_status_code status; - int linkStatus; - - BOOT_PRINTF("in WTDG ***\n") - - while(1) - { - // wait for an RTEMS_EVENT - rtems_event_receive( RTEMS_EVENT_0, - RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); - PRINTF("in WTDG *** wait for the link\n") - status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status - while( linkStatus != 5) // wait for the link - { - rtems_task_wake_after( 10 ); - status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status - } - - status = spacewire_stop_and_start_link( fdSPW ); - - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in WTDG *** ERR link not started %d\n", status) - } - else - { - PRINTF("in WTDG *** OK link started\n") - } - - // restart the SPIQ task - status = rtems_task_restart( Task_id[TASKID_SPIQ], 1 ); - if ( status != RTEMS_SUCCESSFUL ) { - PRINTF("in SPIQ *** ERR restarting SPIQ Task\n") - } - - // restart RECV and SEND - status = rtems_task_restart( Task_id[ TASKID_SEND ], 1 ); - if ( status != RTEMS_SUCCESSFUL ) { - PRINTF("in SPIQ *** ERR restarting SEND Task\n") - } - status = rtems_task_restart( Task_id[ TASKID_RECV ], 1 ); - if ( status != RTEMS_SUCCESSFUL ) { - PRINTF("in SPIQ *** ERR restarting RECV Task\n") - } - } -} - -//**************** -// OTHER FUNCTIONS -int spacewire_open_link( void ) // by default, the driver resets the core: [SPW_CTRL_WRITE(pDev, SPW_CTRL_RESET);] -{ - /** This function opens the SpaceWire link. - * - * @return a valid file descriptor in case of success, -1 in case of a failure - * - */ - rtems_status_code status; - - fdSPW = open(GRSPW_DEVICE_NAME, O_RDWR); // open the device. the open call resets the hardware - if ( fdSPW < 0 ) { - PRINTF1("ERR *** in configure_spw_link *** error opening "GRSPW_DEVICE_NAME" with ERR %d\n", errno) - } - else - { - status = RTEMS_SUCCESSFUL; - } - - return status; -} - -int spacewire_start_link( int fd ) -{ - rtems_status_code status; - - status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started - // -1 default hardcoded driver timeout - - return status; -} - -int spacewire_stop_and_start_link( int fd ) -{ - rtems_status_code status; - - status = ioctl( fd, SPACEWIRE_IOCTRL_STOP); // start fails if link pDev->running != 0 - status = ioctl( fd, SPACEWIRE_IOCTRL_START, -1); // returns successfuly if the link is started - // -1 default hardcoded driver timeout - - return status; -} - -int spacewire_configure_link( int fd ) -{ - /** This function configures the SpaceWire link. - * - * @return GR-RTEMS-DRIVER directive status codes: - * - 22 EINVAL - Null pointer or an out of range value was given as the argument. - * - 16 EBUSY - Only used for SEND. Returned when no descriptors are avialble in non-blocking mode. - * - 88 ENOSYS - Returned for SET_DESTKEY if RMAP command handler is not available or if a non-implemented call is used. - * - 116 ETIMEDOUT - REturned for SET_PACKET_SIZE and START if the link could not be brought up. - * - 12 ENOMEM - Returned for SET_PACKETSIZE if it was unable to allocate the new buffers. - * - 5 EIO - Error when writing to grswp hardware registers. - * - 2 ENOENT - No such file or directory - */ - - rtems_status_code status; - - spacewire_set_NP(1, REGS_ADDR_GRSPW); // [N]o [P]ort force - spacewire_set_RE(1, REGS_ADDR_GRSPW); // [R]MAP [E]nable, the dedicated call seems to break the no port force configuration - - status = ioctl(fd, SPACEWIRE_IOCTRL_SET_RXBLOCK, 1); // sets the blocking mode for reception - if (status!=RTEMS_SUCCESSFUL) { - PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_RXBLOCK\n") - } - // - status = ioctl(fd, SPACEWIRE_IOCTRL_SET_EVENT_ID, Task_id[TASKID_SPIQ]); // sets the task ID to which an event is sent when a - if (status!=RTEMS_SUCCESSFUL) { - PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_EVENT_ID\n") // link-error interrupt occurs - } - // - status = ioctl(fd, SPACEWIRE_IOCTRL_SET_DISABLE_ERR, 0); // automatic link-disabling due to link-error interrupts - if (status!=RTEMS_SUCCESSFUL) { - PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_DISABLE_ERR\n") - } - // - status = ioctl(fd, SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ, 1); // sets the link-error interrupt bit - if (status!=RTEMS_SUCCESSFUL) { - PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_LINK_ERR_IRQ\n") - } - // - status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK, 0); // transmission blocks - if (status!=RTEMS_SUCCESSFUL) { - PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK\n") - } - // - status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL, 1); // transmission blocks when no transmission descriptor is available - if (status!=RTEMS_SUCCESSFUL) { - PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TXBLOCK_ON_FULL\n") - } - // - status = ioctl(fd, SPACEWIRE_IOCTRL_SET_TCODE_CTRL, 0x0909); // [Time Rx : Time Tx : Link error : Tick-out IRQ] - if (status!=RTEMS_SUCCESSFUL) { - PRINTF("in SPIQ *** Error SPACEWIRE_IOCTRL_SET_TCODE_CTRL,\n") - } - - return status; -} - -int spacewire_reset_link( void ) -{ - /** This function is executed by the SPIQ rtems_task wehn it has been awaken by an interruption raised by the SpaceWire driver. - * - * @return RTEMS directive status code: - * - RTEMS_UNSATISFIED is returned is the link is not in the running state after 10 s. - * - RTEMS_SUCCESSFUL is returned if the link is up before the timeout. - * - */ - - rtems_status_code status_spw; - int i; - - for ( i=0; i> 8); - housekeeping_packet.hk_lfr_dpu_spw_pkt_rcv_cnt[1] = (unsigned char) (spacewire_stats.packets_received); - housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[0] = (unsigned char) (spacewire_stats.packets_sent >> 8); - housekeeping_packet.hk_lfr_dpu_spw_pkt_sent_cnt[1] = (unsigned char) (spacewire_stats.packets_sent); - //housekeeping_packet.hk_lfr_dpu_spw_tick_out_cnt; - //housekeeping_packet.hk_lfr_dpu_spw_last_timc; - - //****************************************** - // ERROR COUNTERS / SPACEWIRE / LOW SEVERITY - housekeeping_packet.hk_lfr_dpu_spw_parity = (unsigned char) spacewire_stats.parity_err; - housekeeping_packet.hk_lfr_dpu_spw_disconnect = (unsigned char) spacewire_stats.disconnect_err; - housekeeping_packet.hk_lfr_dpu_spw_escape = (unsigned char) spacewire_stats.escape_err; - housekeeping_packet.hk_lfr_dpu_spw_credit = (unsigned char) spacewire_stats.credit_err; - housekeeping_packet.hk_lfr_dpu_spw_write_sync = (unsigned char) spacewire_stats.write_sync_err; - - //********************************************* - // ERROR COUNTERS / SPACEWIRE / MEDIUM SEVERITY - housekeeping_packet.hk_lfr_dpu_spw_early_eop = (unsigned char) spacewire_stats.early_ep; - housekeeping_packet.hk_lfr_dpu_spw_invalid_addr = (unsigned char) spacewire_stats.invalid_address; - housekeeping_packet.hk_lfr_dpu_spw_eep = (unsigned char) spacewire_stats.rx_eep_err; - housekeeping_packet.hk_lfr_dpu_spw_rx_too_big = (unsigned char) spacewire_stats.rx_truncated; -} - -void timecode_irq_handler( void *pDev, void *regs, int minor, unsigned int tc ) -{ - struct grgpio_regs_str *grgpio_regs = (struct grgpio_regs_str *) REGS_ADDR_GRGPIO; - - incrementLocalCoarseTime(); - - //******* - // GPIO 2 - if ( get_transitionCoarseTime() == getLocalCoarseTime() ) - { - grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x04; // [0000 0100] - } - else - { - grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xfb; // [1111 1011] - } - - //******* - // GPIO 3 - if ( (grgpio_regs->io_port_output_register & 0x08) == 0x08 ) - { - grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register & 0xf7; // [1111 0111] - } - else - { - grgpio_regs->io_port_output_register = grgpio_regs->io_port_output_register | 0x08; // [0000 1000] - } - - rtems_event_send( rtems_task_id_updt, RTEMS_EVENT_0); -} - -rtems_timer_service_routine user_routine( rtems_id timer_id, void *user_data ) -{ - int linkStatus; - rtems_status_code status; - - status = ioctl(fdSPW, SPACEWIRE_IOCTRL_GET_LINK_STATUS, &linkStatus); // get the link status - - if ( linkStatus == 5) { - PRINTF("in spacewire_reset_link *** link is running\n") - status = RTEMS_SUCCESSFUL; - } -} - -rtems_task updt_task(rtems_task_argument unused) -{ - - rtems_event_set event_out; - rtems_status_code status; - rtems_id queue_id; - unsigned int coarseTimeToSend; - - Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_t update_time_packet; - - resetLocalCoarseTime(); - reset_transitionCoarseTime(); - - status = get_message_queue_id_send( &queue_id ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in HOUS *** ERR get_message_queue_id_send %d\n", status) - } - - update_time_packet.targetLogicalAddress = 0xfe; - update_time_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; - update_time_packet.reserved = DEFAULT_RESERVED; - update_time_packet.userApplication = CCSDS_USER_APP; - update_time_packet.packetID[0] = (unsigned char) (TC_LFR_PACKET_ID >> 8); - update_time_packet.packetID[1] = (unsigned char) (TC_LFR_PACKET_ID ); - update_time_packet.packetSequenceControl[0] = (unsigned char) (TC_LFR_PACKET_SEQUENCE_CONTROL >> 8); - update_time_packet.packetSequenceControl[1] = (unsigned char) (TC_LFR_PACKET_SEQUENCE_CONTROL ); - update_time_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_LFR_UPDATE_TIME >> 8); - update_time_packet.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_LFR_UPDATE_TIME ); - - update_time_packet.ccsdsSecHeaderFlag_pusVersion_ack = 0x19; - update_time_packet.serviceType = TC_TYPE_LFR_UPDATE_TIME; - update_time_packet.serviceSubType = TC_SUBTYPE_UPDATE_TIME; - update_time_packet.sourceID = SID_TC_RPW_INTERNAL; - - BOOT_PRINTF("in UPDT *** \n") - - while(true){ - rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); // wait for an SPW_LINKERR_EVENT - - coarseTimeToSend = getLocalCoarseTime() + 1; - updateTimePacket( coarseTimeToSend, &update_time_packet); - printf("UPDT will send %x as coarse time in 700 ms\n", coarseTimeToSend); - - rtems_task_wake_after( 70 ); // 70 => 700 ms - - status = rtems_message_queue_urgent( queue_id, &update_time_packet, - PACKET_LENGTH_TC_LFR_UPDATE_TIME + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES - + 0); // 1 is for the star dundee extra byte - if (status != RTEMS_SUCCESSFUL) { - PRINTF1("in HOUS *** ERR send: %d\n", status) - } - } -} - -void updateTimePacket(unsigned int time, Packet_TC_LFR_UPDATE_TIME_WITH_HEADER_t *packet) -{ - unsigned char crcAsTwoBytes[2]; - - packet->cp_rpw_time[0] = (unsigned char) (time >> 24); - packet->cp_rpw_time[1] = (unsigned char) (time >> 16); - packet->cp_rpw_time[2] = (unsigned char) (time >> 8); - packet->cp_rpw_time[3] = (unsigned char) (time); - packet->cp_rpw_time[4] = 0; // fine time MSB - packet->cp_rpw_time[5] = 0; // fine time LSB - - GetCRCAsTwoBytes((unsigned char*) &packet->packetID, crcAsTwoBytes, - PACKET_LENGTH_TC_LFR_UPDATE_TIME + CCSDS_TC_TM_PACKET_OFFSET - 2); - packet->crc[0] = crcAsTwoBytes[0]; - packet->crc[1] = crcAsTwoBytes[1]; -} diff --git a/timegen/src/lfr_cpu_usage_report.c b/timegen/src/lfr_cpu_usage_report.c deleted file mode 100644 --- a/timegen/src/lfr_cpu_usage_report.c +++ /dev/null @@ -1,115 +0,0 @@ -/* - * CPU Usage Reporter - * - * COPYRIGHT (c) 1989-2009 - * On-Line Applications Research Corporation (OAR). - * - * The license and distribution terms for this file may be - * found in the file LICENSE in this distribution or at - * http://www.rtems.com/license/LICENSE. - * - * $Id$ - */ - -#include "lfr_cpu_usage_report.h" - -unsigned char lfr_rtems_cpu_usage_report( void ) -{ - uint32_t api_index; - Thread_Control *the_thread; - Objects_Information *information; - uint32_t ival, fval; -#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ - Timestamp_Control uptime; - Timestamp_Control total; - Timestamp_Control ran; -#else - uint32_t total_units = 0; -#endif - - unsigned char cpu_load; - cpu_load = 0; - - /* - * When not using nanosecond CPU usage resolution, we have to count - * the number of "ticks" we gave credit for to give the user a rough - * guideline as to what each number means proportionally. - */ -#ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ - _TOD_Get_uptime( &uptime ); - _Timestamp_Subtract( &CPU_usage_Uptime_at_last_reset, &uptime, &total ); -#else - for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) { - if ( !_Objects_Information_table[ api_index ] ) { } - else - { - information = _Objects_Information_table[ api_index ][ 1 ]; - if ( information != NULL ) - { - for ( i=1 ; i <= information->maximum ; i++ ) { - the_thread = (Thread_Control *)information->local_table[ i ]; - - if ( the_thread != NULL ) - total_units += the_thread->cpu_time_used; - } - } - } - } -#endif - - for ( api_index = 1 ; api_index <= OBJECTS_APIS_LAST ; api_index++ ) - { - if ( !_Objects_Information_table[ api_index ] ) { } - else - { - information = _Objects_Information_table[ api_index ][ 1 ]; - if ( information != NULL ) - { - the_thread = (Thread_Control *)information->local_table[ 1 ]; - - if ( the_thread == NULL ) { } - else - { - #ifndef __RTEMS_USE_TICKS_FOR_STATISTICS__ - /* - * If this is the currently executing thread, account for time - * since the last context switch. - */ - ran = the_thread->cpu_time_used; - if ( _Thread_Executing->Object.id == the_thread->Object.id ) - { - Timestamp_Control used; - _Timestamp_Subtract( - &_Thread_Time_of_last_context_switch, &uptime, &used - ); - _Timestamp_Add_to( &ran, &used ); - } - _Timestamp_Divide( &ran, &total, &ival, &fval ); - - #else - if (total_units != 0) - { - uint64_t ival_64; - - ival_64 = the_thread->cpu_time_used; - ival_64 *= 100000; - ival = ival_64 / total_units; - } - else - { - ival = 0; - } - - fval = ival % 1000; - ival /= 1000; - #endif - } - } - } - } - cpu_load = (unsigned char) (100 - ival); - - return cpu_load; -} - - diff --git a/timegen/src/processing/avf0_prc0.c b/timegen/src/processing/avf0_prc0.c deleted file mode 100644 --- a/timegen/src/processing/avf0_prc0.c +++ /dev/null @@ -1,380 +0,0 @@ -/** Functions related to data processing. - * - * @file - * @author P. LEROY - * - * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation. - * - */ - -#include "avf0_prc0.h" -#include "fsw_processing.h" - -nb_sm_before_bp_asm_f0 nb_sm_before_f0; - -//*** -// F0 -ring_node_asm asm_ring_norm_f0 [ NB_RING_NODES_ASM_NORM_F0 ]; -ring_node_asm asm_ring_burst_sbm_f0[ NB_RING_NODES_ASM_BURST_SBM_F0 ]; - -float asm_f0_reorganized [ TOTAL_SIZE_SM ]; -char asm_f0_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ]; -float compressed_sm_norm_f0[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F0]; -float compressed_sm_sbm_f0 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F0 ]; -//unsigned char bp1_norm_f0 [ TOTAL_SIZE_BP1_NORM_F0 ]; -//unsigned char bp1_sbm_f0 [ TOTAL_SIZE_BP1_SBM_F0 ]; - -//************ -// RTEMS TASKS - -rtems_task avf0_task( rtems_task_argument lfrRequestedMode ) -{ - int i; - - rtems_event_set event_out; - rtems_status_code status; - rtems_id queue_id_prc0; - asm_msg msgForMATR; - ring_node_sm *ring_node_tab[8]; - ring_node_asm *current_ring_node_asm_burst_sbm_f0; - ring_node_asm *current_ring_node_asm_norm_f0; - - unsigned int nb_norm_bp1; - unsigned int nb_norm_bp2; - unsigned int nb_norm_asm; - unsigned int nb_sbm_bp1; - unsigned int nb_sbm_bp2; - - nb_norm_bp1 = 0; - nb_norm_bp2 = 0; - nb_norm_asm = 0; - nb_sbm_bp1 = 0; - nb_sbm_bp2 = 0; - - reset_nb_sm_f0( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions - ASM_generic_init_ring( asm_ring_norm_f0, NB_RING_NODES_ASM_NORM_F0 ); - ASM_generic_init_ring( asm_ring_burst_sbm_f0, NB_RING_NODES_ASM_BURST_SBM_F0 ); - current_ring_node_asm_norm_f0 = asm_ring_norm_f0; - current_ring_node_asm_burst_sbm_f0 = asm_ring_burst_sbm_f0; - - BOOT_PRINTF1("in AVFO *** lfrRequestedMode = %d\n", (int) lfrRequestedMode) - - status = get_message_queue_id_prc0( &queue_id_prc0 ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in MATR *** ERR get_message_queue_id_prc0 %d\n", status) - } - - while(1){ - rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 - - //**************************************** - // initialize the mesage for the MATR task - msgForMATR.norm = current_ring_node_asm_norm_f0; - msgForMATR.burst_sbm = current_ring_node_asm_burst_sbm_f0; - msgForMATR.event = 0x00; // this composite event will be sent to the MATR task - msgForMATR.coarseTime = ring_node_for_averaging_sm_f0->coarseTime; - msgForMATR.fineTime = ring_node_for_averaging_sm_f0->fineTime; - // - //**************************************** - - ring_node_tab[NB_SM_BEFORE_AVF0-1] = ring_node_for_averaging_sm_f0; - for ( i = 2; i < (NB_SM_BEFORE_AVF0+1); i++ ) - { - ring_node_for_averaging_sm_f0 = ring_node_for_averaging_sm_f0->previous; - ring_node_tab[NB_SM_BEFORE_AVF0-i] = ring_node_for_averaging_sm_f0; - } - - // compute the average and store it in the averaged_sm_f1 buffer - SM_average( current_ring_node_asm_norm_f0->matrix, - current_ring_node_asm_burst_sbm_f0->matrix, - ring_node_tab, - nb_norm_bp1, nb_sbm_bp1 ); - - // update nb_average - nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF0; - nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF0; - nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF0; - nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF0; - nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF0; - - if (nb_sbm_bp1 == nb_sm_before_f0.burst_sbm_bp1) - { - nb_sbm_bp1 = 0; - // set another ring for the ASM storage - current_ring_node_asm_burst_sbm_f0 = current_ring_node_asm_burst_sbm_f0->next; - if ( lfrCurrentMode == LFR_MODE_BURST ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP1_F0; - } - else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP1_F0; - } - } - - if (nb_sbm_bp2 == nb_sm_before_f0.burst_sbm_bp2) - { - nb_sbm_bp2 = 0; - if ( lfrCurrentMode == LFR_MODE_BURST ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP2_F0; - } - else if ( (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP2_F0; - } - } - - if (nb_norm_bp1 == nb_sm_before_f0.norm_bp1) - { - nb_norm_bp1 = 0; - // set another ring for the ASM storage - current_ring_node_asm_norm_f0 = current_ring_node_asm_norm_f0->next; - if ( (lfrCurrentMode == LFR_MODE_NORMAL) - || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F0; - } - } - - if (nb_norm_bp2 == nb_sm_before_f0.norm_bp2) - { - nb_norm_bp2 = 0; - if ( (lfrCurrentMode == LFR_MODE_NORMAL) - || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F0; - } - } - - if (nb_norm_asm == nb_sm_before_f0.norm_asm) - { - nb_norm_asm = 0; - if ( (lfrCurrentMode == LFR_MODE_NORMAL) - || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) - { -// PRINTF1("%lld\n", localTime) - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F0; - } - } - - //************************* - // send the message to MATR - if (msgForMATR.event != 0x00) - { - status = rtems_message_queue_send( queue_id_prc0, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC0); - } - - if (status != RTEMS_SUCCESSFUL) { - printf("in AVF0 *** Error sending message to MATR, code %d\n", status); - } - } -} - -rtems_task prc0_task( rtems_task_argument lfrRequestedMode ) -{ - char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer - size_t size; // size of the incoming TC packet - asm_msg *incomingMsg; - // - unsigned char sid; - spw_ioctl_pkt_send spw_ioctl_send_ASM; - rtems_status_code status; - rtems_id queue_id; - rtems_id queue_id_q_p0; - Header_TM_LFR_SCIENCE_ASM_t headerASM; - bp_packet_with_spare packet_norm_bp1_f0; - bp_packet packet_norm_bp2_f0; - bp_packet packet_sbm_bp1_f0; - bp_packet packet_sbm_bp2_f0; - - unsigned long long int localTime; - - ASM_init_header( &headerASM ); - - //************* - // NORM headers - BP_init_header_with_spare( &packet_norm_bp1_f0.header, - APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F0, - PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0, NB_BINS_COMPRESSED_SM_F0 ); - BP_init_header( &packet_norm_bp2_f0.header, - APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F0, - PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0, NB_BINS_COMPRESSED_SM_F0); - - //**************************** - // BURST SBM1 and SBM2 headers - if ( lfrRequestedMode == LFR_MODE_BURST ) - { - BP_init_header( &packet_sbm_bp1_f0.header, - APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F0, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0); - BP_init_header( &packet_sbm_bp2_f0.header, - APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F0, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0); - } - else if ( lfrRequestedMode == LFR_MODE_SBM1 ) - { - BP_init_header( &packet_sbm_bp1_f0.header, - APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP1_F0, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0); - BP_init_header( &packet_sbm_bp2_f0.header, - APID_TM_SCIENCE_SBM1_SBM2, SID_SBM1_BP2_F0, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0); - } - else if ( lfrRequestedMode == LFR_MODE_SBM2 ) - { - BP_init_header( &packet_sbm_bp1_f0.header, - APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F0, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0, NB_BINS_COMPRESSED_SM_SBM_F0); - BP_init_header( &packet_sbm_bp2_f0.header, - APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F0, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0, NB_BINS_COMPRESSED_SM_SBM_F0); - } - else - { - PRINTF1("in PRC0 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode) - } - - status = get_message_queue_id_send( &queue_id ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in PRC0 *** ERR get_message_queue_id_send %d\n", status) - } - status = get_message_queue_id_prc0( &queue_id_q_p0); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in PRC0 *** ERR get_message_queue_id_prc0 %d\n", status) - } - - BOOT_PRINTF1("in PRC0 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode) - - while(1){ - status = rtems_message_queue_receive( queue_id_q_p0, incomingData, &size, //************************************ - RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0 - - incomingMsg = (asm_msg*) incomingData; - - localTime = getTimeAsUnsignedLongLongInt( ); - - //**************** - //**************** - // BURST SBM1 SBM2 - //**************** - //**************** - if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F0 ) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F0 ) ) - { - sid = getSID( incomingMsg->event ); - // 1) compress the matrix for Basic Parameters calculation - ASM_compress_reorganize_and_divide( incomingMsg->burst_sbm->matrix, compressed_sm_sbm_f0, - nb_sm_before_f0.burst_sbm_bp1, - NB_BINS_COMPRESSED_SM_SBM_F0, NB_BINS_TO_AVERAGE_ASM_SBM_F0, - ASM_F0_INDICE_START); - // 2) compute the BP1 set -// BP1_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_SBM_F0, bp1_sbm_f0 ); - // 3) send the BP1 set - set_time( packet_sbm_bp1_f0.header.time, (unsigned char *) &incomingMsg->coarseTime ); - set_time( packet_sbm_bp1_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); - BP_send( (char *) &packet_sbm_bp1_f0, queue_id, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F0 + PACKET_LENGTH_DELTA, - sid); - // 4) compute the BP2 set if needed - if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F0) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F0) ) - { - // 1) compute the BP2 set - - // 2) send the BP2 set - set_time( packet_sbm_bp2_f0.header.time, (unsigned char *) &incomingMsg->coarseTime ); - set_time( packet_sbm_bp2_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); - BP_send( (char *) &packet_sbm_bp2_f0, queue_id, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F0 + PACKET_LENGTH_DELTA, - sid); - } - } - - //***** - //***** - // NORM - //***** - //***** - if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F0) - { - // 1) compress the matrix for Basic Parameters calculation - ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f0, - nb_sm_before_f0.norm_bp1, - NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0, - ASM_F0_INDICE_START ); - // 2) compute the BP1 set -// BP1_set( compressed_sm_norm_f0, NB_BINS_COMPRESSED_SM_F0, bp1_norm_f0 ); - // 3) send the BP1 set - set_time( packet_norm_bp1_f0.header.time, (unsigned char *) &incomingMsg->coarseTime ); - set_time( packet_norm_bp1_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); - BP_send( (char *) &packet_norm_bp1_f0, queue_id, - PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F0 + PACKET_LENGTH_DELTA, - SID_NORM_BP1_F0 ); - if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F0) - { - // 1) compute the BP2 set using the same ASM as the one used for BP1 - - // 2) send the BP2 set - set_time( packet_norm_bp2_f0.header.time, (unsigned char *) &incomingMsg->coarseTime ); - set_time( packet_norm_bp2_f0.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); - BP_send( (char *) &packet_norm_bp2_f0, queue_id, - PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F0 + PACKET_LENGTH_DELTA, - SID_NORM_BP2_F0); - } - } - - if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F0) - { - // 1) reorganize the ASM and divide - ASM_reorganize_and_divide( incomingMsg->norm->matrix, - asm_f0_reorganized, - nb_sm_before_f0.norm_bp1 ); - // 2) convert the float array in a char array - ASM_convert( asm_f0_reorganized, asm_f0_char); - // 3) send the spectral matrix packets - set_time( headerASM.time , (unsigned char *) &incomingMsg->coarseTime ); - set_time( headerASM.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); - ASM_send( &headerASM, asm_f0_char, SID_NORM_ASM_F0, &spw_ioctl_send_ASM, queue_id); - } - - } -} - -//********** -// FUNCTIONS - -void reset_nb_sm_f0( unsigned char lfrMode ) -{ - nb_sm_before_f0.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 96; - nb_sm_before_f0.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 96; - nb_sm_before_f0.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]) * 96; - nb_sm_before_f0.sbm1_bp1 = parameter_dump_packet.sy_lfr_s1_bp_p0 * 24; // 0.25 s per digit - nb_sm_before_f0.sbm1_bp2 = parameter_dump_packet.sy_lfr_s1_bp_p1 * 96; - nb_sm_before_f0.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 96; - nb_sm_before_f0.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 96; - nb_sm_before_f0.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 96; - nb_sm_before_f0.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 96; - - if (lfrMode == LFR_MODE_SBM1) - { - nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm1_bp1; - nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm1_bp2; - } - else if (lfrMode == LFR_MODE_SBM2) - { - nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.sbm2_bp1; - nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.sbm2_bp2; - } - else if (lfrMode == LFR_MODE_BURST) - { - nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1; - nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2; - } - else - { - nb_sm_before_f0.burst_sbm_bp1 = nb_sm_before_f0.burst_bp1; - nb_sm_before_f0.burst_sbm_bp2 = nb_sm_before_f0.burst_bp2; - } -} diff --git a/timegen/src/processing/avf1_prc1.c b/timegen/src/processing/avf1_prc1.c deleted file mode 100644 --- a/timegen/src/processing/avf1_prc1.c +++ /dev/null @@ -1,360 +0,0 @@ -/** Functions related to data processing. - * - * @file - * @author P. LEROY - * - * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation. - * - */ - -#include "avf1_prc1.h" - -nb_sm_before_bp_asm_f1 nb_sm_before_f1; - -//*** -// F1 -ring_node_asm asm_ring_norm_f1 [ NB_RING_NODES_ASM_NORM_F1 ]; -ring_node_asm asm_ring_burst_sbm_f1[ NB_RING_NODES_ASM_BURST_SBM_F1 ]; - -float asm_f1_reorganized [ TOTAL_SIZE_SM ]; -char asm_f1_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ]; -float compressed_sm_norm_f1[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F1]; -float compressed_sm_sbm_f1 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F1 ]; - -//************ -// RTEMS TASKS - -rtems_task avf1_task( rtems_task_argument lfrRequestedMode ) -{ - int i; - - rtems_event_set event_out; - rtems_status_code status; - rtems_id queue_id_prc1; - asm_msg msgForMATR; - ring_node_sm *ring_node_tab[8]; - ring_node_asm *current_ring_node_asm_burst_sbm_f1; - ring_node_asm *current_ring_node_asm_norm_f1; - - unsigned int nb_norm_bp1; - unsigned int nb_norm_bp2; - unsigned int nb_norm_asm; - unsigned int nb_sbm_bp1; - unsigned int nb_sbm_bp2; - - nb_norm_bp1 = 0; - nb_norm_bp2 = 0; - nb_norm_asm = 0; - nb_sbm_bp1 = 0; - nb_sbm_bp2 = 0; - - reset_nb_sm_f1( lfrRequestedMode ); // reset the sm counters that drive the BP and ASM computations / transmissions - ASM_generic_init_ring( asm_ring_norm_f1, NB_RING_NODES_ASM_NORM_F1 ); - ASM_generic_init_ring( asm_ring_burst_sbm_f1, NB_RING_NODES_ASM_BURST_SBM_F1 ); - current_ring_node_asm_norm_f1 = asm_ring_norm_f1; - current_ring_node_asm_burst_sbm_f1 = asm_ring_burst_sbm_f1; - - BOOT_PRINTF1("in AVF1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode) - - status = get_message_queue_id_prc1( &queue_id_prc1 ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in AVF1 *** ERR get_message_queue_id_prc1 %d\n", status) - } - - while(1){ - rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 - - //**************************************** - // initialize the mesage for the MATR task - msgForMATR.event = 0x00; // this composite event will be sent to the PRC1 task - msgForMATR.burst_sbm = current_ring_node_asm_burst_sbm_f1; - msgForMATR.norm = current_ring_node_asm_norm_f1; - msgForMATR.coarseTime = ring_node_for_averaging_sm_f1->coarseTime; - msgForMATR.fineTime = ring_node_for_averaging_sm_f1->fineTime; - // - //**************************************** - - ring_node_tab[NB_SM_BEFORE_AVF1-1] = ring_node_for_averaging_sm_f1; - for ( i = 2; i < (NB_SM_BEFORE_AVF1+1); i++ ) - { - ring_node_for_averaging_sm_f1 = ring_node_for_averaging_sm_f1->previous; - ring_node_tab[NB_SM_BEFORE_AVF1-i] = ring_node_for_averaging_sm_f1; - } - - // compute the average and store it in the averaged_sm_f1 buffer - SM_average( current_ring_node_asm_norm_f1->matrix, - current_ring_node_asm_burst_sbm_f1->matrix, - ring_node_tab, - nb_norm_bp1, nb_sbm_bp1 ); - - // update nb_average - nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF1; - nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF1; - nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF1; - nb_sbm_bp1 = nb_sbm_bp1 + NB_SM_BEFORE_AVF1; - nb_sbm_bp2 = nb_sbm_bp2 + NB_SM_BEFORE_AVF1; - - if (nb_sbm_bp1 == nb_sm_before_f1.burst_sbm_bp1) - { - nb_sbm_bp1 = 0; - // set another ring for the ASM storage - current_ring_node_asm_burst_sbm_f1 = current_ring_node_asm_burst_sbm_f1->next; - if ( lfrCurrentMode == LFR_MODE_BURST ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP1_F1; - } - else if ( lfrCurrentMode == LFR_MODE_SBM2 ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP1_F1; - } - } - - if (nb_sbm_bp2 == nb_sm_before_f1.burst_sbm_bp2) - { - nb_sbm_bp2 = 0; - if ( lfrCurrentMode == LFR_MODE_BURST ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_BURST_BP2_F1; - } - else if ( lfrCurrentMode == LFR_MODE_SBM2 ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_SBM_BP2_F1; - } - } - - if (nb_norm_bp1 == nb_sm_before_f1.norm_bp1) - { - nb_norm_bp1 = 0; - // set another ring for the ASM storage - current_ring_node_asm_norm_f1 = current_ring_node_asm_norm_f1->next; - if ( (lfrCurrentMode == LFR_MODE_NORMAL) - || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F1; - } - } - - if (nb_norm_bp2 == nb_sm_before_f1.norm_bp2) - { - nb_norm_bp2 = 0; - if ( (lfrCurrentMode == LFR_MODE_NORMAL) - || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F1; - } - } - - if (nb_norm_asm == nb_sm_before_f1.norm_asm) - { - nb_norm_asm = 0; - if ( (lfrCurrentMode == LFR_MODE_NORMAL) - || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F1; - } - } - - //************************* - // send the message to MATR - if (msgForMATR.event != 0x00) - { - status = rtems_message_queue_send( queue_id_prc1, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC1); - } - - if (status != RTEMS_SUCCESSFUL) { - printf("in AVF1 *** Error sending message to PRC1, code %d\n", status); - } - } -} - -rtems_task prc1_task( rtems_task_argument lfrRequestedMode ) -{ - char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer - size_t size; // size of the incoming TC packet - asm_msg *incomingMsg; - // - unsigned char sid; - spw_ioctl_pkt_send spw_ioctl_send_ASM; - rtems_status_code status; - rtems_id queue_id_send; - rtems_id queue_id_q_p1; - Header_TM_LFR_SCIENCE_ASM_t headerASM; - bp_packet_with_spare packet_norm_bp1; - bp_packet packet_norm_bp2; - bp_packet packet_sbm_bp1; - bp_packet packet_sbm_bp2; - - unsigned long long int localTime; - - ASM_init_header( &headerASM ); - - //************* - // NORM headers - BP_init_header_with_spare( &packet_norm_bp1.header, - APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F1, - PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1, NB_BINS_COMPRESSED_SM_F1 ); - BP_init_header( &packet_norm_bp2.header, - APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F1, - PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1, NB_BINS_COMPRESSED_SM_F1); - - //*********************** - // BURST and SBM2 headers - if ( lfrRequestedMode == LFR_MODE_BURST ) - { - BP_init_header( &packet_sbm_bp1.header, - APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP1_F1, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1); - BP_init_header( &packet_sbm_bp2.header, - APID_TM_SCIENCE_NORMAL_BURST, SID_BURST_BP2_F1, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1); - } - else if ( lfrRequestedMode == LFR_MODE_SBM2 ) - { - BP_init_header( &packet_sbm_bp1.header, - APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP1_F1, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1, NB_BINS_COMPRESSED_SM_SBM_F1); - BP_init_header( &packet_sbm_bp2.header, - APID_TM_SCIENCE_SBM1_SBM2, SID_SBM2_BP2_F1, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1, NB_BINS_COMPRESSED_SM_SBM_F1); - } - else - { - PRINTF1("in PRC1 *** lfrRequestedMode is %d, several headers not initialized\n", (unsigned int) lfrRequestedMode) - } - - status = get_message_queue_id_send( &queue_id_send ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in PRC1 *** ERR get_message_queue_id_send %d\n", status) - } - status = get_message_queue_id_prc1( &queue_id_q_p1); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in PRC1 *** ERR get_message_queue_id_prc1 %d\n", status) - } - - BOOT_PRINTF1("in PRC1 *** lfrRequestedMode = %d\n", (int) lfrRequestedMode) - - while(1){ - status = rtems_message_queue_receive( queue_id_q_p1, incomingData, &size, //************************************ - RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0 - - incomingMsg = (asm_msg*) incomingData; - - localTime = getTimeAsUnsignedLongLongInt( ); - //*********** - //*********** - // BURST SBM2 - //*********** - //*********** - if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP1_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP1_F1) ) - { - sid = getSID( incomingMsg->event ); - // 1) compress the matrix for Basic Parameters calculation - ASM_compress_reorganize_and_divide( incomingMsg->burst_sbm->matrix, compressed_sm_sbm_f1, - nb_sm_before_f1.burst_sbm_bp1, - NB_BINS_COMPRESSED_SM_SBM_F1, NB_BINS_TO_AVERAGE_ASM_SBM_F1, - ASM_F1_INDICE_START); - // 2) compute the BP1 set - - // 3) send the BP1 set - set_time( packet_sbm_bp1.header.time, (unsigned char *) &incomingMsg->coarseTime ); - set_time( packet_sbm_bp1.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); - BP_send( (char *) &packet_sbm_bp1, queue_id_send, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP1_F1 + PACKET_LENGTH_DELTA, - sid ); - // 4) compute the BP2 set if needed - if ( (incomingMsg->event & RTEMS_EVENT_BURST_BP2_F1) || (incomingMsg->event & RTEMS_EVENT_SBM_BP2_F1) ) - { - // 1) compute the BP2 set - - // 2) send the BP2 set - set_time( packet_sbm_bp2.header.time, (unsigned char *) &incomingMsg->coarseTime ); - set_time( packet_sbm_bp2.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); - BP_send( (char *) &packet_sbm_bp2, queue_id_send, - PACKET_LENGTH_TM_LFR_SCIENCE_SBM_BP2_F1 + PACKET_LENGTH_DELTA, - sid ); - } - } - - //***** - //***** - // NORM - //***** - //***** - if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F1) - { - // 1) compress the matrix for Basic Parameters calculation - ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f1, - nb_sm_before_f1.norm_bp1, - NB_BINS_COMPRESSED_SM_F0, NB_BINS_TO_AVERAGE_ASM_F0, - ASM_F0_INDICE_START ); - // 2) compute the BP1 set - - // 3) send the BP1 set - set_time( packet_norm_bp1.header.time, (unsigned char *) &incomingMsg->coarseTime ); - set_time( packet_norm_bp1.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); - BP_send( (char *) &packet_norm_bp1, queue_id_send, - PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F1 + PACKET_LENGTH_DELTA, - SID_NORM_BP1_F1 ); - if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F1) - { - // 1) compute the BP2 set - - // 2) send the BP2 set - set_time( packet_norm_bp2.header.time, (unsigned char *) &incomingMsg->coarseTime ); - set_time( packet_norm_bp2.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); - BP_send( (char *) &packet_norm_bp2, queue_id_send, - PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F1 + PACKET_LENGTH_DELTA, - SID_NORM_BP2_F1 ); - } - } - - if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F1) - { - // 1) reorganize the ASM and divide - ASM_reorganize_and_divide( incomingMsg->norm->matrix, - asm_f1_reorganized, - nb_sm_before_f1.norm_bp1 ); - // 2) convert the float array in a char array - ASM_convert( asm_f1_reorganized, asm_f1_char); - // 3) send the spectral matrix packets - set_time( headerASM.time , (unsigned char *) &incomingMsg->coarseTime ); - set_time( headerASM.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); - ASM_send( &headerASM, asm_f1_char, SID_NORM_ASM_F1, &spw_ioctl_send_ASM, queue_id_send); - } - - } -} - -//********** -// FUNCTIONS - -void reset_nb_sm_f1( unsigned char lfrMode ) -{ - nb_sm_before_f1.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0 * 16; - nb_sm_before_f1.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1 * 16; - nb_sm_before_f1.norm_asm = (parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]) * 16; - nb_sm_before_f1.sbm2_bp1 = parameter_dump_packet.sy_lfr_s2_bp_p0 * 16; - nb_sm_before_f1.sbm2_bp2 = parameter_dump_packet.sy_lfr_s2_bp_p1 * 16; - nb_sm_before_f1.burst_bp1 = parameter_dump_packet.sy_lfr_b_bp_p0 * 16; - nb_sm_before_f1.burst_bp2 = parameter_dump_packet.sy_lfr_b_bp_p1 * 16; - - if (lfrMode == LFR_MODE_SBM2) - { - nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.sbm2_bp1; - nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.sbm2_bp2; - } - else if (lfrMode == LFR_MODE_BURST) - { - nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1; - nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2; - } - else - { - nb_sm_before_f1.burst_sbm_bp1 = nb_sm_before_f1.burst_bp1; - nb_sm_before_f1.burst_sbm_bp2 = nb_sm_before_f1.burst_bp2; - } -} - diff --git a/timegen/src/processing/avf2_prc2.c b/timegen/src/processing/avf2_prc2.c deleted file mode 100644 --- a/timegen/src/processing/avf2_prc2.c +++ /dev/null @@ -1,255 +0,0 @@ -/** Functions related to data processing. - * - * @file - * @author P. LEROY - * - * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation. - * - */ - -#include "avf2_prc2.h" - -nb_sm_before_bp_asm_f2 nb_sm_before_f2; - -//*** -// F2 -ring_node_asm asm_ring_norm_f2 [ NB_RING_NODES_ASM_NORM_F2 ]; -ring_node_asm asm_ring_burst_sbm_f2[ NB_RING_NODES_ASM_BURST_SBM_F2 ]; - -float asm_f2_reorganized [ TOTAL_SIZE_SM ]; -char asm_f2_char [ TIME_OFFSET_IN_BYTES + (TOTAL_SIZE_SM * 2) ]; -float compressed_sm_norm_f2[ TOTAL_SIZE_COMPRESSED_ASM_NORM_F2]; -float compressed_sm_sbm_f2 [ TOTAL_SIZE_COMPRESSED_ASM_SBM_F2 ]; - -//************ -// RTEMS TASKS - -//*** -// F2 -rtems_task avf2_task( rtems_task_argument argument ) -{ - rtems_event_set event_out; - rtems_status_code status; - rtems_id queue_id_prc2; - asm_msg msgForMATR; - ring_node_asm *current_ring_node_asm_norm_f2; - - unsigned int nb_norm_bp1; - unsigned int nb_norm_bp2; - unsigned int nb_norm_asm; - - nb_norm_bp1 = 0; - nb_norm_bp2 = 0; - nb_norm_asm = 0; - - reset_nb_sm_f2( ); // reset the sm counters that drive the BP and ASM computations / transmissions - ASM_generic_init_ring( asm_ring_norm_f2, NB_RING_NODES_ASM_NORM_F2 ); - current_ring_node_asm_norm_f2 = asm_ring_norm_f2; - - BOOT_PRINTF("in AVF2 ***\n") - - status = get_message_queue_id_prc2( &queue_id_prc2 ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in AVF2 *** ERR get_message_queue_id_prc2 %d\n", status) - } - - while(1){ - rtems_event_receive(RTEMS_EVENT_0, RTEMS_WAIT, RTEMS_NO_TIMEOUT, &event_out); // wait for an RTEMS_EVENT0 - - //**************************************** - // initialize the mesage for the MATR task - msgForMATR.event = 0x00; // this composite event will be sent to the MATR task - msgForMATR.burst_sbm = NULL; - msgForMATR.norm = current_ring_node_asm_norm_f2; - msgForMATR.coarseTime = ring_node_for_averaging_sm_f2->coarseTime; - msgForMATR.fineTime = ring_node_for_averaging_sm_f2->fineTime; - // - //**************************************** - - // compute the average and store it in the averaged_sm_f2 buffer - SM_average_f2( current_ring_node_asm_norm_f2->matrix, - ring_node_for_averaging_sm_f2, - nb_norm_bp1 ); - - // update nb_average - nb_norm_bp1 = nb_norm_bp1 + NB_SM_BEFORE_AVF2; - nb_norm_bp2 = nb_norm_bp2 + NB_SM_BEFORE_AVF2; - nb_norm_asm = nb_norm_asm + NB_SM_BEFORE_AVF2; - - if (nb_norm_bp1 == nb_sm_before_f2.norm_bp1) - { - nb_norm_bp1 = 0; - // set another ring for the ASM storage - current_ring_node_asm_norm_f2 = current_ring_node_asm_norm_f2->next; - if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1) - || (lfrCurrentMode == LFR_MODE_SBM2) ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP1_F2; - } - } - - if (nb_norm_bp2 == nb_sm_before_f2.norm_bp2) - { - nb_norm_bp2 = 0; - if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1) - || (lfrCurrentMode == LFR_MODE_SBM2) ) - { - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_BP2_F2; - } - } - - if (nb_norm_asm == nb_sm_before_f2.norm_asm) - { - nb_norm_asm = 0; - if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_SBM1) - || (lfrCurrentMode == LFR_MODE_SBM2) ) - { -// PRINTF1("%lld\n", localTime) - msgForMATR.event = msgForMATR.event | RTEMS_EVENT_NORM_ASM_F2; - } - } - - //************************* - // send the message to MATR - if (msgForMATR.event != 0x00) - { - status = rtems_message_queue_send( queue_id_prc2, (char *) &msgForMATR, MSG_QUEUE_SIZE_PRC0); - } - - if (status != RTEMS_SUCCESSFUL) { - printf("in AVF2 *** Error sending message to MATR, code %d\n", status); - } - } -} - -rtems_task prc2_task( rtems_task_argument argument ) -{ - char incomingData[MSG_QUEUE_SIZE_SEND]; // incoming data buffer - size_t size; // size of the incoming TC packet - asm_msg *incomingMsg; - // - spw_ioctl_pkt_send spw_ioctl_send_ASM; - rtems_status_code status; - rtems_id queue_id; - rtems_id queue_id_q_p2; - Header_TM_LFR_SCIENCE_ASM_t headerASM; - bp_packet packet_norm_bp1_f2; - bp_packet packet_norm_bp2_f2; - - unsigned long long int localTime; - - incomingMsg = NULL; - - ASM_init_header( &headerASM ); - - //************* - // NORM headers - BP_init_header( &packet_norm_bp1_f2.header, - APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP1_F2, - PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2, NB_BINS_COMPRESSED_SM_F2 ); - BP_init_header( &packet_norm_bp2_f2.header, - APID_TM_SCIENCE_NORMAL_BURST, SID_NORM_BP2_F2, - PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2, NB_BINS_COMPRESSED_SM_F2 ); - - status = get_message_queue_id_send( &queue_id ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in PRC2 *** ERR get_message_queue_id_send %d\n", status) - } - status = get_message_queue_id_prc2( &queue_id_q_p2); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in PRC2 *** ERR get_message_queue_id_prc2 %d\n", status) - } - - BOOT_PRINTF("in PRC2 ***\n") - - while(1){ - status = rtems_message_queue_receive( queue_id_q_p2, incomingData, &size, //************************************ - RTEMS_WAIT, RTEMS_NO_TIMEOUT ); // wait for a message coming from AVF0 - - incomingMsg = (asm_msg*) incomingData; - - localTime = getTimeAsUnsignedLongLongInt( ); - - //***** - //***** - // NORM - //***** - //***** - if (incomingMsg->event & RTEMS_EVENT_NORM_BP1_F2) - { - // 1) compress the matrix for Basic Parameters calculation - ASM_compress_reorganize_and_divide( incomingMsg->norm->matrix, compressed_sm_norm_f2, - nb_sm_before_f2.norm_bp1, - NB_BINS_COMPRESSED_SM_F2, NB_BINS_TO_AVERAGE_ASM_F2, - ASM_F2_INDICE_START ); - // 2) compute the BP1 set - - // 3) send the BP1 set - set_time( packet_norm_bp1_f2.header.time, (unsigned char *) &incomingMsg->coarseTime ); - set_time( packet_norm_bp1_f2.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); - BP_send( (char *) &packet_norm_bp1_f2, queue_id, - PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP1_F2 + PACKET_LENGTH_DELTA, - SID_NORM_BP1_F2 ); - if (incomingMsg->event & RTEMS_EVENT_NORM_BP2_F2) - { - // 1) compute the BP2 set using the same ASM as the one used for BP1 - - // 2) send the BP2 set - set_time( packet_norm_bp2_f2.header.time, (unsigned char *) &incomingMsg->coarseTime ); - set_time( packet_norm_bp2_f2.header.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); - BP_send( (char *) &packet_norm_bp2_f2, queue_id, - PACKET_LENGTH_TM_LFR_SCIENCE_NORM_BP2_F2 + PACKET_LENGTH_DELTA, - SID_NORM_BP2_F2 ); - } - } - - if (incomingMsg->event & RTEMS_EVENT_NORM_ASM_F2) - { - // 1) reorganize the ASM and divide - ASM_reorganize_and_divide( incomingMsg->norm->matrix, - asm_f2_reorganized, - nb_sm_before_f2.norm_bp1 ); - // 2) convert the float array in a char array - ASM_convert( asm_f2_reorganized, asm_f2_char); - // 3) send the spectral matrix packets - set_time( headerASM.time , (unsigned char *) &incomingMsg->coarseTime ); - set_time( headerASM.acquisitionTime, (unsigned char *) &incomingMsg->coarseTime ); - ASM_send( &headerASM, asm_f2_char, SID_NORM_ASM_F2, &spw_ioctl_send_ASM, queue_id); - } - - } -} - -//********** -// FUNCTIONS - -void reset_nb_sm_f2( void ) -{ - nb_sm_before_f2.norm_bp1 = parameter_dump_packet.sy_lfr_n_bp_p0; - nb_sm_before_f2.norm_bp2 = parameter_dump_packet.sy_lfr_n_bp_p1; - nb_sm_before_f2.norm_asm = parameter_dump_packet.sy_lfr_n_asm_p[0] * 256 + parameter_dump_packet.sy_lfr_n_asm_p[1]; -} - -void SM_average_f2( float *averaged_spec_mat_f2, - ring_node_sm *ring_node, - unsigned int nbAverageNormF2 ) -{ - float sum; - unsigned int i; - - for(i=0; ibuffer_address) ) [ i ]; - if ( (nbAverageNormF2 == 0) ) - { - averaged_spec_mat_f2[ i ] = sum; - } - else - { - averaged_spec_mat_f2[ i ] = ( averaged_spec_mat_f2[ i ] + sum ); - } - } -} diff --git a/timegen/src/processing/fsw_processing.c b/timegen/src/processing/fsw_processing.c deleted file mode 100644 --- a/timegen/src/processing/fsw_processing.c +++ /dev/null @@ -1,696 +0,0 @@ -/** Functions related to data processing. - * - * @file - * @author P. LEROY - * - * These function are related to data processing, i.e. spectral matrices averaging and basic parameters computation. - * - */ - -#include "fsw_processing.h" -#include "fsw_processing_globals.c" - -unsigned int nb_sm_f0; -unsigned int nb_sm_f0_aux_f1; -unsigned int nb_sm_f1; -unsigned int nb_sm_f0_aux_f2; - -//************************ -// spectral matrices rings -ring_node_sm sm_ring_f0[ NB_RING_NODES_SM_F0 ]; -ring_node_sm sm_ring_f1[ NB_RING_NODES_SM_F1 ]; -ring_node_sm sm_ring_f2[ NB_RING_NODES_SM_F2 ]; -ring_node_sm *current_ring_node_sm_f0; -ring_node_sm *current_ring_node_sm_f1; -ring_node_sm *current_ring_node_sm_f2; -ring_node_sm *ring_node_for_averaging_sm_f0; -ring_node_sm *ring_node_for_averaging_sm_f1; -ring_node_sm *ring_node_for_averaging_sm_f2; - -//*********************************************************** -// Interrupt Service Routine for spectral matrices processing - -void spectral_matrices_isr_f0( void ) -{ - unsigned char status; - unsigned long long int time_0; - unsigned long long int time_1; - unsigned long long int syncBit0; - unsigned long long int syncBit1; - - status = spectral_matrix_regs->status & 0x03; // [0011] get the status_ready_matrix_f0_x bits - - time_0 = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f0_0_coarse_time ); - time_1 = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f0_1_coarse_time ); - syncBit0 = ( (unsigned long long int) (spectral_matrix_regs->f0_0_coarse_time & 0x80000000) ) << 16; - syncBit1 = ( (unsigned long long int) (spectral_matrix_regs->f0_1_coarse_time & 0x80000000) ) << 16; - - switch(status) - { - case 0: - break; - case 3: - if ( time_0 < time_1 ) - { - close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], - ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_0 | syncBit0); - current_ring_node_sm_f0 = current_ring_node_sm_f0->next; - spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address; - close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], - ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_1 | syncBit1); - current_ring_node_sm_f0 = current_ring_node_sm_f0->next; - spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address; - } - else - { - close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], - ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_1 | syncBit1); - current_ring_node_sm_f0 = current_ring_node_sm_f0->next; - spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address; - close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], - ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_0 | syncBit0); - current_ring_node_sm_f0 = current_ring_node_sm_f0->next; - spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address; - } - spectral_matrix_regs->status = 0x03; // [0011] - break; - case 1: - close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], - ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_0 | syncBit0); - current_ring_node_sm_f0 = current_ring_node_sm_f0->next; - spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->buffer_address; - spectral_matrix_regs->status = 0x01; // [0001] - break; - case 2: - close_matrix_actions( &nb_sm_f0, NB_SM_BEFORE_AVF0, Task_id[TASKID_AVF0], - ring_node_for_averaging_sm_f0, current_ring_node_sm_f0, time_1 | syncBit1); - current_ring_node_sm_f0 = current_ring_node_sm_f0->next; - spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address; - spectral_matrix_regs->status = 0x02; // [0010] - break; - } -} - -void spectral_matrices_isr_f1( void ) -{ - unsigned char status; - unsigned long long int time; - unsigned long long int syncBit; - rtems_status_code status_code; - - status = (spectral_matrix_regs->status & 0x0c) >> 2; // [1100] get the status_ready_matrix_f0_x bits - - switch(status) - { - case 0: - break; - case 3: - // UNEXPECTED VALUE - spectral_matrix_regs->status = 0xc0; // [1100] - status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 ); - break; - case 1: - time = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f1_0_coarse_time ); - syncBit = ( (unsigned long long int) (spectral_matrix_regs->f1_0_coarse_time & 0x80000000) ) << 16; - close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1], - ring_node_for_averaging_sm_f1, current_ring_node_sm_f1, time | syncBit); - current_ring_node_sm_f1 = current_ring_node_sm_f1->next; - spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->buffer_address; - spectral_matrix_regs->status = 0x04; // [0100] - break; - case 2: - time = get_acquisition_time( (unsigned char *) &spectral_matrix_regs->f1_1_coarse_time ); - syncBit = ( (unsigned long long int) (spectral_matrix_regs->f1_1_coarse_time & 0x80000000) ) << 16; - close_matrix_actions( &nb_sm_f1, NB_SM_BEFORE_AVF1, Task_id[TASKID_AVF1], - ring_node_for_averaging_sm_f1, current_ring_node_sm_f1, time | syncBit); - current_ring_node_sm_f1 = current_ring_node_sm_f1->next; - spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address; - spectral_matrix_regs->status = 0x08; // [1000] - break; - } -} - -void spectral_matrices_isr_f2( void ) -{ - unsigned char status; - rtems_status_code status_code; - - status = (spectral_matrix_regs->status & 0x30) >> 4; // [0011 0000] get the status_ready_matrix_f0_x bits - - ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2; - - current_ring_node_sm_f2 = current_ring_node_sm_f2->next; - - switch(status) - { - case 0: - break; - case 3: - // UNEXPECTED VALUE - spectral_matrix_regs->status = 0x30; // [0011 0000] - status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_11 ); - break; - case 1: - ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_0_coarse_time; - ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_0_fine_time; - spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->buffer_address; - spectral_matrix_regs->status = 0x10; // [0001 0000] - if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) - { - status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 ); - } - break; - case 2: - ring_node_for_averaging_sm_f2->coarseTime = spectral_matrix_regs->f2_1_coarse_time; - ring_node_for_averaging_sm_f2->fineTime = spectral_matrix_regs->f2_1_fine_time; - spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address; - spectral_matrix_regs->status = 0x20; // [0010 0000] - if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) - { - status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 ); - } - break; - } -} - -void spectral_matrix_isr_error_handler( void ) -{ - rtems_status_code status_code; - - if (spectral_matrix_regs->status & 0x7c0) // [0111 1100 0000] - { - status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_8 ); - } -} - -rtems_isr spectral_matrices_isr( rtems_vector_number vector ) -{ - // STATUS REGISTER - // input_fifo_write(2) *** input_fifo_write(1) *** input_fifo_write(0) - // 10 9 8 - // buffer_full ** bad_component_err ** f2_1 ** f2_0 ** f1_1 ** f1_0 ** f0_1 ** f0_0 - // 7 6 5 4 3 2 1 0 - - spectral_matrices_isr_f0(); - - spectral_matrices_isr_f1(); - - spectral_matrices_isr_f2(); - -// spectral_matrix_isr_error_handler(); -} - -rtems_isr spectral_matrices_isr_simu( rtems_vector_number vector ) -{ - rtems_status_code status_code; - - //*** - // F0 - nb_sm_f0 = nb_sm_f0 + 1; - if (nb_sm_f0 == NB_SM_BEFORE_AVF0 ) - { - ring_node_for_averaging_sm_f0 = current_ring_node_sm_f0; - if (rtems_event_send( Task_id[TASKID_AVF0], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) - { - status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 ); - } - nb_sm_f0 = 0; - } - - //*** - // F1 - nb_sm_f0_aux_f1 = nb_sm_f0_aux_f1 + 1; - if (nb_sm_f0_aux_f1 == 6) - { - nb_sm_f0_aux_f1 = 0; - nb_sm_f1 = nb_sm_f1 + 1; - } - if (nb_sm_f1 == NB_SM_BEFORE_AVF1 ) - { - ring_node_for_averaging_sm_f1 = current_ring_node_sm_f1; - if (rtems_event_send( Task_id[TASKID_AVF1], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) - { - status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 ); - } - nb_sm_f1 = 0; - } - - //*** - // F2 - nb_sm_f0_aux_f2 = nb_sm_f0_aux_f2 + 1; - if (nb_sm_f0_aux_f2 == 96) - { - nb_sm_f0_aux_f2 = 0; - ring_node_for_averaging_sm_f2 = current_ring_node_sm_f2; - if (rtems_event_send( Task_id[TASKID_AVF2], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) - { - status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 ); - } - } -} - -//****************** -// Spectral Matrices - -void reset_nb_sm( void ) -{ - nb_sm_f0 = 0; - nb_sm_f0_aux_f1 = 0; - nb_sm_f0_aux_f2 = 0; - - nb_sm_f1 = 0; -} - -void SM_init_rings( void ) -{ - unsigned char i; - - // F0 RING - sm_ring_f0[0].next = (ring_node_sm*) &sm_ring_f0[1]; - sm_ring_f0[0].previous = (ring_node_sm*) &sm_ring_f0[NB_RING_NODES_SM_F0-1]; - sm_ring_f0[0].buffer_address = - (int) &sm_f0[ 0 ]; - - sm_ring_f0[NB_RING_NODES_SM_F0-1].next = (ring_node_sm*) &sm_ring_f0[0]; - sm_ring_f0[NB_RING_NODES_SM_F0-1].previous = (ring_node_sm*) &sm_ring_f0[NB_RING_NODES_SM_F0-2]; - sm_ring_f0[NB_RING_NODES_SM_F0-1].buffer_address = - (int) &sm_f0[ (NB_RING_NODES_SM_F0-1) * TOTAL_SIZE_SM ]; - - for(i=1; if0_0_address = sm_ring_f0[0].buffer_address; - DEBUG_PRINTF1("spectral_matrix_regs->matrixF0_Address0 @%x\n", spectral_matrix_regs->f0_0_address) -} - -void SM_generic_init_ring( ring_node_sm *ring, unsigned char nbNodes, volatile int sm_f[] ) -{ - unsigned char i; - - //*************** - // BUFFER ADDRESS - for(i=0; itargetLogicalAddress = CCSDS_DESTINATION_ID; - header->protocolIdentifier = CCSDS_PROTOCOLE_ID; - header->reserved = 0x00; - header->userApplication = CCSDS_USER_APP; - header->packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); - header->packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); - header->packetSequenceControl[0] = 0xc0; - header->packetSequenceControl[1] = 0x00; - header->packetLength[0] = 0x00; - header->packetLength[1] = 0x00; - // DATA FIELD HEADER - header->spare1_pusVersion_spare2 = 0x10; - header->serviceType = TM_TYPE_LFR_SCIENCE; // service type - header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype - header->destinationID = TM_DESTINATION_ID_GROUND; - // AUXILIARY DATA HEADER - header->sid = 0x00; - header->biaStatusInfo = 0x00; - header->pa_lfr_pkt_cnt_asm = 0x00; - header->pa_lfr_pkt_nr_asm = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->pa_lfr_asm_blk_nr[0] = 0x00; // BLK_NR MSB - header->pa_lfr_asm_blk_nr[1] = 0x00; // BLK_NR LSB -} - -void ASM_send(Header_TM_LFR_SCIENCE_ASM_t *header, char *spectral_matrix, - unsigned int sid, spw_ioctl_pkt_send *spw_ioctl_send, rtems_id queue_id) -{ - unsigned int i; - unsigned int length = 0; - rtems_status_code status; - - for (i=0; i<2; i++) - { - // (1) BUILD THE DATA - switch(sid) - { - case SID_NORM_ASM_F0: - spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F0_IN_BYTES / 2; // 2 packets will be sent - spw_ioctl_send->data = &spectral_matrix[ - ( (ASM_F0_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F0) ) * NB_VALUES_PER_SM ) * 2 - ]; - length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F0; - header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F0) >> 8 ); // BLK_NR MSB - header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F0); // BLK_NR LSB - break; - case SID_NORM_ASM_F1: - spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F1_IN_BYTES / 2; // 2 packets will be sent - spw_ioctl_send->data = &spectral_matrix[ - ( (ASM_F1_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F1) ) * NB_VALUES_PER_SM ) * 2 - ]; - length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F1; - header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F1) >> 8 ); // BLK_NR MSB - header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F1); // BLK_NR LSB - break; - case SID_NORM_ASM_F2: - spw_ioctl_send->dlen = TOTAL_SIZE_ASM_F2_IN_BYTES / 2; // 2 packets will be sent - spw_ioctl_send->data = &spectral_matrix[ - ( (ASM_F2_INDICE_START + (i*NB_BINS_PER_PKT_ASM_F2) ) * NB_VALUES_PER_SM ) * 2 - ]; - length = PACKET_LENGTH_TM_LFR_SCIENCE_ASM_F2; - header->pa_lfr_asm_blk_nr[0] = (unsigned char) ( (NB_BINS_PER_PKT_ASM_F2) >> 8 ); // BLK_NR MSB - header->pa_lfr_asm_blk_nr[1] = (unsigned char) (NB_BINS_PER_PKT_ASM_F2); // BLK_NR LSB - break; - default: - PRINTF1("ERR *** in ASM_send *** unexpected sid %d\n", sid) - break; - } - spw_ioctl_send->hlen = HEADER_LENGTH_TM_LFR_SCIENCE_ASM + CCSDS_PROTOCOLE_EXTRA_BYTES; - spw_ioctl_send->hdr = (char *) header; - spw_ioctl_send->options = 0; - - // (2) BUILD THE HEADER - increment_seq_counter_source_id( header->packetSequenceControl, sid ); - header->packetLength[0] = (unsigned char) (length>>8); - header->packetLength[1] = (unsigned char) (length); - header->sid = (unsigned char) sid; // SID - header->pa_lfr_pkt_cnt_asm = 2; - header->pa_lfr_pkt_nr_asm = (unsigned char) (i+1); - - // (3) SET PACKET TIME - header->time[0] = (unsigned char) (time_management_regs->coarse_time>>24); - header->time[1] = (unsigned char) (time_management_regs->coarse_time>>16); - header->time[2] = (unsigned char) (time_management_regs->coarse_time>>8); - header->time[3] = (unsigned char) (time_management_regs->coarse_time); - header->time[4] = (unsigned char) (time_management_regs->fine_time>>8); - header->time[5] = (unsigned char) (time_management_regs->fine_time); - // - header->acquisitionTime[0] = header->time[0]; - header->acquisitionTime[1] = header->time[1]; - header->acquisitionTime[2] = header->time[2]; - header->acquisitionTime[3] = header->time[3]; - header->acquisitionTime[4] = header->time[4]; - header->acquisitionTime[5] = header->time[5]; - - // (4) SEND PACKET - status = rtems_message_queue_send( queue_id, spw_ioctl_send, ACTION_MSG_SPW_IOCTL_SEND_SIZE); - if (status != RTEMS_SUCCESSFUL) { - printf("in ASM_send *** ERR %d\n", (int) status); - } - } -} - -//***************** -// Basic Parameters - -void BP_init_header( Header_TM_LFR_SCIENCE_BP_t *header, - unsigned int apid, unsigned char sid, - unsigned int packetLength, unsigned char blkNr ) -{ - header->targetLogicalAddress = CCSDS_DESTINATION_ID; - header->protocolIdentifier = CCSDS_PROTOCOLE_ID; - header->reserved = 0x00; - header->userApplication = CCSDS_USER_APP; - header->packetID[0] = (unsigned char) (apid >> 8); - header->packetID[1] = (unsigned char) (apid); - header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; - header->packetSequenceControl[1] = 0x00; - header->packetLength[0] = (unsigned char) (packetLength >> 8); - header->packetLength[1] = (unsigned char) (packetLength); - // DATA FIELD HEADER - header->spare1_pusVersion_spare2 = 0x10; - header->serviceType = TM_TYPE_LFR_SCIENCE; // service type - header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype - header->destinationID = TM_DESTINATION_ID_GROUND; - // AUXILIARY DATA HEADER - header->sid = sid; - header->biaStatusInfo = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB - header->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB -} - -void BP_init_header_with_spare(Header_TM_LFR_SCIENCE_BP_with_spare_t *header, - unsigned int apid, unsigned char sid, - unsigned int packetLength , unsigned char blkNr) -{ - header->targetLogicalAddress = CCSDS_DESTINATION_ID; - header->protocolIdentifier = CCSDS_PROTOCOLE_ID; - header->reserved = 0x00; - header->userApplication = CCSDS_USER_APP; - header->packetID[0] = (unsigned char) (apid >> 8); - header->packetID[1] = (unsigned char) (apid); - header->packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; - header->packetSequenceControl[1] = 0x00; - header->packetLength[0] = (unsigned char) (packetLength >> 8); - header->packetLength[1] = (unsigned char) (packetLength); - // DATA FIELD HEADER - header->spare1_pusVersion_spare2 = 0x10; - header->serviceType = TM_TYPE_LFR_SCIENCE; // service type - header->serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype - header->destinationID = TM_DESTINATION_ID_GROUND; - // AUXILIARY DATA HEADER - header->sid = sid; - header->biaStatusInfo = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->time[0] = 0x00; - header->source_data_spare = 0x00; - header->pa_lfr_bp_blk_nr[0] = 0x00; // BLK_NR MSB - header->pa_lfr_bp_blk_nr[1] = blkNr; // BLK_NR LSB -} - -void BP_send(char *data, rtems_id queue_id, unsigned int nbBytesToSend, unsigned int sid ) -{ - rtems_status_code status; - - // SET THE SEQUENCE_CNT PARAMETER - increment_seq_counter_source_id( (unsigned char*) &data[ PACKET_POS_SEQUENCE_CNT ], sid ); - // SEND PACKET - status = rtems_message_queue_send( queue_id, data, nbBytesToSend); - if (status != RTEMS_SUCCESSFUL) - { - printf("ERR *** in BP_send *** ERR %d\n", (int) status); - } -} - -//****************** -// general functions - -void reset_spectral_matrix_regs( void ) -{ - /** This function resets the spectral matrices module registers. - * - * The registers affected by this function are located at the following offset addresses: - * - * - 0x00 config - * - 0x04 status - * - 0x08 matrixF0_Address0 - * - 0x10 matrixFO_Address1 - * - 0x14 matrixF1_Address - * - 0x18 matrixF2_Address - * - */ - - spectral_matrix_regs->config = 0x00; - spectral_matrix_regs->status = 0x00; - - spectral_matrix_regs->f0_0_address = current_ring_node_sm_f0->previous->buffer_address; - spectral_matrix_regs->f0_1_address = current_ring_node_sm_f0->buffer_address; - spectral_matrix_regs->f1_0_address = current_ring_node_sm_f1->previous->buffer_address; - spectral_matrix_regs->f1_1_address = current_ring_node_sm_f1->buffer_address; - spectral_matrix_regs->f2_0_address = current_ring_node_sm_f2->previous->buffer_address; - spectral_matrix_regs->f2_1_address = current_ring_node_sm_f2->buffer_address; -} - -void set_time( unsigned char *time, unsigned char * timeInBuffer ) -{ - time[0] = timeInBuffer[0]; - time[1] = timeInBuffer[1]; - time[2] = timeInBuffer[2]; - time[3] = timeInBuffer[3]; - time[4] = timeInBuffer[6]; - time[5] = timeInBuffer[7]; -} - -unsigned long long int get_acquisition_time( unsigned char *timePtr ) -{ - unsigned long long int acquisitionTimeAslong; - acquisitionTimeAslong = 0x00; - acquisitionTimeAslong = ( (unsigned long long int) (timePtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit - + ( (unsigned long long int) timePtr[1] << 32 ) - + ( (unsigned long long int) timePtr[2] << 24 ) - + ( (unsigned long long int) timePtr[3] << 16 ) - + ( (unsigned long long int) timePtr[6] << 8 ) - + ( (unsigned long long int) timePtr[7] ); - return acquisitionTimeAslong; -} - -void close_matrix_actions(unsigned int *nb_sm, unsigned int nb_sm_before_avf, rtems_id avf_task_id, - ring_node_sm *node_for_averaging, ring_node_sm *ringNode, - unsigned long long int time ) -{ - unsigned char *timePtr; - unsigned char *coarseTimePtr; - unsigned char *fineTimePtr; - rtems_status_code status_code; - - timePtr = (unsigned char *) &time; - coarseTimePtr = (unsigned char *) &node_for_averaging->coarseTime; - fineTimePtr = (unsigned char *) &node_for_averaging->fineTime; - - *nb_sm = *nb_sm + 1; - if (*nb_sm == nb_sm_before_avf) - { - node_for_averaging = ringNode; - coarseTimePtr[0] = timePtr[2]; - coarseTimePtr[1] = timePtr[3]; - coarseTimePtr[2] = timePtr[4]; - coarseTimePtr[3] = timePtr[5]; - fineTimePtr[2] = timePtr[6]; - fineTimePtr[3] = timePtr[7]; - if (rtems_event_send( avf_task_id, RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) - { - status_code = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_3 ); - } - *nb_sm = 0; - } -} - -unsigned char getSID( rtems_event_set event ) -{ - unsigned char sid; - - rtems_event_set eventSetBURST; - rtems_event_set eventSetSBM; - - //****** - // BURST - eventSetBURST = RTEMS_EVENT_BURST_BP1_F0 - | RTEMS_EVENT_BURST_BP1_F1 - | RTEMS_EVENT_BURST_BP2_F0 - | RTEMS_EVENT_BURST_BP2_F1; - - //**** - // SBM - eventSetSBM = RTEMS_EVENT_SBM_BP1_F0 - | RTEMS_EVENT_SBM_BP1_F1 - | RTEMS_EVENT_SBM_BP2_F0 - | RTEMS_EVENT_SBM_BP2_F1; - - if (event & eventSetBURST) - { - sid = SID_BURST_BP1_F0; - } - else if (event & eventSetSBM) - { - sid = SID_SBM1_BP1_F0; - } - else - { - sid = 0; - } - - return sid; -} - diff --git a/timegen/src/tc_acceptance.c b/timegen/src/tc_acceptance.c deleted file mode 100644 --- a/timegen/src/tc_acceptance.c +++ /dev/null @@ -1,437 +0,0 @@ -/** Functions related to TeleCommand acceptance. - * - * @file - * @author P. LEROY - * - * A group of functions to handle TeleCommands parsing.\n - * - */ - -#include "tc_acceptance.h" - -unsigned int lookUpTableForCRC[256]; - -//********************** -// GENERAL USE FUNCTIONS -unsigned int Crc_opt( unsigned char D, unsigned int Chk) -{ - /** This function generate the CRC for one byte and returns the value of the new syndrome. - * - * @param D is the current byte of data. - * @param Chk is the current syndrom value. - * - * @return the value of the new syndrome on two bytes. - * - */ - - return(((Chk << 8) & 0xff00)^lookUpTableForCRC [(((Chk >> 8)^D) & 0x00ff)]); -} - -void initLookUpTableForCRC( void ) -{ - /** This function is used to initiates the look-up table for fast CRC computation. - * - * The global table lookUpTableForCRC[256] is initiated. - * - */ - - unsigned int i; - unsigned int tmp; - - for (i=0; i<256; i++) - { - tmp = 0; - if((i & 1) != 0) { - tmp = tmp ^ 0x1021; - } - if((i & 2) != 0) { - tmp = tmp ^ 0x2042; - } - if((i & 4) != 0) { - tmp = tmp ^ 0x4084; - } - if((i & 8) != 0) { - tmp = tmp ^ 0x8108; - } - if((i & 16) != 0) { - tmp = tmp ^ 0x1231; - } - if((i & 32) != 0) { - tmp = tmp ^ 0x2462; - } - if((i & 64) != 0) { - tmp = tmp ^ 0x48c4; - } - if((i & 128) != 0) { - tmp = tmp ^ 0x9188; - } - lookUpTableForCRC[i] = tmp; - } -} - -void GetCRCAsTwoBytes(unsigned char* data, unsigned char* crcAsTwoBytes, unsigned int sizeOfData) -{ - /** This function calculates a two bytes Cyclic Redundancy Code. - * - * @param data points to a buffer containing the data on which to compute the CRC. - * @param crcAsTwoBytes points points to a two bytes buffer in which the CRC is stored. - * @param sizeOfData is the number of bytes of *data* used to compute the CRC. - * - * The specification of the Cyclic Redundancy Code is described in the following document: ECSS-E-70-41-A. - * - */ - - unsigned int Chk; - int j; - Chk = 0xffff; // reset the syndrom to all ones - for (j=0; j> 8); - crcAsTwoBytes[1] = (unsigned char) (Chk & 0x00ff); -} - -//********************* -// ACCEPTANCE FUNCTIONS -int tc_parser(ccsdsTelecommandPacket_t * TCPacket, unsigned int estimatedPacketLength, unsigned char *computed_CRC) -{ - /** This function parses TeleCommands. - * - * @param TC points to the TeleCommand that will be parsed. - * @param estimatedPacketLength is the PACKET_LENGTH field calculated from the effective length of the received packet. - * - * @return Status code of the parsing. - * - * The parsing checks: - * - process id - * - category - * - length: a global check is performed and a per subtype check also - * - type - * - subtype - * - crc - * - */ - - int status; - int status_crc; - unsigned char pid; - unsigned char category; - unsigned int packetLength; - unsigned char packetType; - unsigned char packetSubtype; - unsigned char sid; - - status = CCSDS_TM_VALID; - - // APID check *** APID on 2 bytes - pid = ((TCPacket->packetID[0] & 0x07)<<4) + ( (TCPacket->packetID[1]>>4) & 0x0f ); // PID = 11 *** 7 bits xxxxx210 7654xxxx - category = (TCPacket->packetID[1] & 0x0f); // PACKET_CATEGORY = 12 *** 4 bits xxxxxxxx xxxx3210 - packetLength = (TCPacket->packetLength[0] * 256) + TCPacket->packetLength[1]; - packetType = TCPacket->serviceType; - packetSubtype = TCPacket->serviceSubType; - sid = TCPacket->sourceID; - - if ( pid != CCSDS_PROCESS_ID ) // CHECK THE PROCESS ID - { - status = ILLEGAL_APID; - } - if (status == CCSDS_TM_VALID) // CHECK THE CATEGORY - { - if ( category != CCSDS_PACKET_CATEGORY ) - { - status = ILLEGAL_APID; - } - } - if (status == CCSDS_TM_VALID) // CHECK THE PACKET_LENGTH FIELD AND THE ESTIMATED PACKET_LENGTH COMPLIANCE - { - if (packetLength != estimatedPacketLength ) { - status = WRONG_LEN_PKT; - } - } - if (status == CCSDS_TM_VALID) // CHECK THAT THE PACKET DOES NOT EXCEED THE MAX SIZE - { - if ( packetLength >= CCSDS_TC_PKT_MAX_SIZE ) { - status = WRONG_LEN_PKT; - } - } - if (status == CCSDS_TM_VALID) // CHECK THE TYPE - { - status = tc_check_type( packetType ); - } - if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE - { - status = tc_check_type_subtype( packetType, packetSubtype ); - } - if (status == CCSDS_TM_VALID) // CHECK THE SID - { - status = tc_check_sid( sid ); - } - if (status == CCSDS_TM_VALID) // CHECK THE SUBTYPE AND LENGTH COMPLIANCE - { - status = tc_check_length( packetSubtype, packetLength ); - } - status_crc = tc_check_crc( TCPacket, estimatedPacketLength, computed_CRC ); - if (status == CCSDS_TM_VALID ) // CHECK CRC - { - status = status_crc; - } - - return status; -} - -int tc_check_type( unsigned char packetType ) -{ - /** This function checks that the type of a TeleCommand is valid. - * - * @param packetType is the type to check. - * - * @return Status code CCSDS_TM_VALID or ILL_TYPE. - * - */ - - int status; - - if ( (packetType == TC_TYPE_GEN) || (packetType == TC_TYPE_TIME)) - { - status = CCSDS_TM_VALID; - } - else - { - status = ILL_TYPE; - } - - return status; -} - -int tc_check_type_subtype( unsigned char packetType, unsigned char packetSubType ) -{ - /** This function checks that the subtype of a TeleCommand is valid and coherent with the type. - * - * @param packetType is the type of the TC. - * @param packetSubType is the subtype to check. - * - * @return Status code CCSDS_TM_VALID or ILL_SUBTYPE. - * - */ - - int status; - - switch(packetType) - { - case TC_TYPE_GEN: - if ( (packetSubType == TC_SUBTYPE_RESET) - || (packetSubType == TC_SUBTYPE_LOAD_COMM) - || (packetSubType == TC_SUBTYPE_LOAD_NORM) || (packetSubType == TC_SUBTYPE_LOAD_BURST) - || (packetSubType == TC_SUBTYPE_LOAD_SBM1) || (packetSubType == TC_SUBTYPE_LOAD_SBM2) - || (packetSubType == TC_SUBTYPE_DUMP) - || (packetSubType == TC_SUBTYPE_ENTER) - || (packetSubType == TC_SUBTYPE_UPDT_INFO) - || (packetSubType == TC_SUBTYPE_EN_CAL) || (packetSubType == TC_SUBTYPE_DIS_CAL) ) - { - status = CCSDS_TM_VALID; - } - else - { - status = ILL_SUBTYPE; - } - break; - - case TC_TYPE_TIME: - if (packetSubType == TC_SUBTYPE_UPDT_TIME) - { - status = CCSDS_TM_VALID; - } - else - { - status = ILL_SUBTYPE; - } - break; - - default: - status = ILL_SUBTYPE; - break; - } - - return status; -} - -int tc_check_sid( unsigned char sid ) -{ - /** This function checks that the sid of a TeleCommand is valid. - * - * @param sid is the sid to check. - * - * @return Status code CCSDS_TM_VALID or CORRUPTED. - * - */ - - int status; - - if ( (sid == SID_TC_MISSION_TIMELINE) || (sid == SID_TC_TC_SEQUENCES) || (sid == SID_TC_RECOVERY_ACTION_CMD) - || (sid == SID_TC_BACKUP_MISSION_TIMELINE) - || (sid == SID_TC_DIRECT_CMD) || (sid == SID_TC_SPARE_GRD_SRC1) || (sid == SID_TC_SPARE_GRD_SRC2) - || (sid == SID_TC_OBCP) || (sid == SID_TC_SYSTEM_CONTROL) || (sid == SID_TC_AOCS) - || (sid == SID_TC_RPW_INTERNAL)) - { - status = CCSDS_TM_VALID; - } - else - { - status = WRONG_SRC_ID; - } - - return status; -} - -int tc_check_length( unsigned char packetSubType, unsigned int length ) -{ - /** This function checks that the subtype and the length are compliant. - * - * @param packetSubType is the subtype to check. - * @param length is the length to check. - * - * @return Status code CCSDS_TM_VALID or ILL_TYPE. - * - */ - - int status; - - status = LFR_SUCCESSFUL; - - switch(packetSubType) - { - case TC_SUBTYPE_RESET: - if (length!=(TC_LEN_RESET-CCSDS_TC_TM_PACKET_OFFSET)) { - status = WRONG_LEN_PKT; - } - else { - status = CCSDS_TM_VALID; - } - break; - case TC_SUBTYPE_LOAD_COMM: - if (length!=(TC_LEN_LOAD_COMM-CCSDS_TC_TM_PACKET_OFFSET)) { - status = WRONG_LEN_PKT; - } - else { - status = CCSDS_TM_VALID; - } - break; - case TC_SUBTYPE_LOAD_NORM: - if (length!=(TC_LEN_LOAD_NORM-CCSDS_TC_TM_PACKET_OFFSET)) { - status = WRONG_LEN_PKT; - } - else { - status = CCSDS_TM_VALID; - } - break; - case TC_SUBTYPE_LOAD_BURST: - if (length!=(TC_LEN_LOAD_BURST-CCSDS_TC_TM_PACKET_OFFSET)) { - status = WRONG_LEN_PKT; - } - else { - status = CCSDS_TM_VALID; - } - break; - case TC_SUBTYPE_LOAD_SBM1: - if (length!=(TC_LEN_LOAD_SBM1-CCSDS_TC_TM_PACKET_OFFSET)) { - status = WRONG_LEN_PKT; - } - else { - status = CCSDS_TM_VALID; - } - break; - case TC_SUBTYPE_LOAD_SBM2: - if (length!=(TC_LEN_LOAD_SBM2-CCSDS_TC_TM_PACKET_OFFSET)) { - status = WRONG_LEN_PKT; - } - else { - status = CCSDS_TM_VALID; - } - break; - case TC_SUBTYPE_DUMP: - if (length!=(TC_LEN_DUMP-CCSDS_TC_TM_PACKET_OFFSET)) { - status = WRONG_LEN_PKT; - } - else { - status = CCSDS_TM_VALID; - } - break; - case TC_SUBTYPE_ENTER: - if (length!=(TC_LEN_ENTER-CCSDS_TC_TM_PACKET_OFFSET)) { - status = WRONG_LEN_PKT; - } - else { - status = CCSDS_TM_VALID; - } - break; - case TC_SUBTYPE_UPDT_INFO: - if (length!=(TC_LEN_UPDT_INFO-CCSDS_TC_TM_PACKET_OFFSET)) { - status = WRONG_LEN_PKT; - } - else { - status = CCSDS_TM_VALID; - } - break; - case TC_SUBTYPE_EN_CAL: - if (length!=(TC_LEN_EN_CAL-CCSDS_TC_TM_PACKET_OFFSET)) { - status = WRONG_LEN_PKT; - } - else { - status = CCSDS_TM_VALID; - } - break; - case TC_SUBTYPE_DIS_CAL: - if (length!=(TC_LEN_DIS_CAL-CCSDS_TC_TM_PACKET_OFFSET)) { - status = WRONG_LEN_PKT; - } - else { - status = CCSDS_TM_VALID; - } - break; - case TC_SUBTYPE_UPDT_TIME: - if (length!=(TC_LEN_UPDT_TIME-CCSDS_TC_TM_PACKET_OFFSET)) { - status = WRONG_LEN_PKT; - } - else { - status = CCSDS_TM_VALID; - } - break; - default: // if the subtype is not a legal value, return ILL_SUBTYPE - status = ILL_SUBTYPE; - break ; - } - - return status; -} - -int tc_check_crc( ccsdsTelecommandPacket_t * TCPacket, unsigned int length, unsigned char *computed_CRC ) -{ - /** This function checks the CRC validity of the corresponding TeleCommand packet. - * - * @param TCPacket points to the TeleCommand packet to check. - * @param length is the length of the TC packet. - * - * @return Status code CCSDS_TM_VALID or INCOR_CHECKSUM. - * - */ - - int status; - unsigned char * CCSDSContent; - - CCSDSContent = (unsigned char*) TCPacket->packetID; - GetCRCAsTwoBytes(CCSDSContent, computed_CRC, length + CCSDS_TC_TM_PACKET_OFFSET - 2); // 2 CRC bytes removed from the calculation of the CRC - if (computed_CRC[0] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -2]) { - status = INCOR_CHECKSUM; - } - else if (computed_CRC[1] != CCSDSContent[length + CCSDS_TC_TM_PACKET_OFFSET -1]) { - status = INCOR_CHECKSUM; - } - else { - status = CCSDS_TM_VALID; - } - - return status; -} - - - diff --git a/timegen/src/tc_handler.c b/timegen/src/tc_handler.c deleted file mode 100644 --- a/timegen/src/tc_handler.c +++ /dev/null @@ -1,250 +0,0 @@ -/** Functions and tasks related to TeleCommand handling. - * - * @file - * @author P. LEROY - * - * A group of functions to handle TeleCommands:\n - * action launching\n - * TC parsing\n - * ... - * - */ - -#include "tc_handler.h" - -//*********** -// RTEMS TASK - -unsigned int incomingTransitionCoarseTime; - -void reset_transitionCoarseTime( void ) -{ - incomingTransitionCoarseTime = 0xffffffff; -} - -void set_transitionCoarseTime( unsigned int value ) -{ - incomingTransitionCoarseTime = value; -} - -unsigned int get_transitionCoarseTime( void ) -{ - return incomingTransitionCoarseTime; -} - -rtems_task actn_task( rtems_task_argument unused ) -{ - /** This RTEMS task is responsible for launching actions upton the reception of valid TeleCommands. - * - * @param unused is the starting argument of the RTEMS task - * - * The ACTN task waits for data coming from an RTEMS msesage queue. When data arrives, it launches specific actions depending - * on the incoming TeleCommand. - * - */ - - int result; - rtems_status_code status; // RTEMS status code - ccsdsTelecommandPacket_t TC; // TC sent to the ACTN task - size_t size; // size of the incoming TC packet - unsigned char subtype; // subtype of the current TC packet - unsigned char time[6]; - rtems_id queue_rcv_id; - rtems_id queue_snd_id; - - status = get_message_queue_id_recv( &queue_rcv_id ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in ACTN *** ERR get_message_queue_id_recv %d\n", status) - } - - status = get_message_queue_id_send( &queue_snd_id ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in ACTN *** ERR get_message_queue_id_send %d\n", status) - } - - result = LFR_SUCCESSFUL; - subtype = 0; // subtype of the current TC packet - - BOOT_PRINTF("in ACTN *** \n") - - while(1) - { - status = rtems_message_queue_receive( queue_rcv_id, (char*) &TC, &size, - RTEMS_WAIT, RTEMS_NO_TIMEOUT); - getTime( time ); // set time to the current time - if (status!=RTEMS_SUCCESSFUL) - { - PRINTF1("ERR *** in task ACTN *** error receiving a message, code %d \n", status) - } - else - { - subtype = TC.serviceSubType; - switch(subtype) - { - case TC_SUBTYPE_ENTER: - result = action_enter_mode( &TC, queue_snd_id ); - break; - case TC_SUBTYPE_UPDATE_TIME: - result = action_update_time( &TC ); - break; - default: - break; - } - } - } -} - -//*********** -// TC ACTIONS - -int action_reset(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) -{ - return LFR_SUCCESSFUL; -} - -int action_enter_mode(ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) -{ - unsigned int *transitionCoarseTime_ptr; - unsigned int transitionCoarseTime; - unsigned char * bytePosPtr; - - bytePosPtr = (unsigned char *) &TC->packetID; - - transitionCoarseTime_ptr = (unsigned int *) ( &bytePosPtr[ BYTE_POS_CP_LFR_ENTER_MODE_TIME ] ); - transitionCoarseTime = transitionCoarseTime_ptr[0] & 0x7fffffff; - printf("local coarse time (without sync bit) = %x, requested transitionCoarseTime = %x\n", - getLocalCoarseTime(), - transitionCoarseTime); - - set_transitionCoarseTime( transitionCoarseTime ); - - return LFR_SUCCESSFUL; -} - -int action_update_info(ccsdsTelecommandPacket_t *TC, rtems_id queue_id) -{ - return LFR_SUCCESSFUL; -} - -int action_enable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) -{ - return LFR_SUCCESSFUL; -} - -int action_disable_calibration(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) -{ - return LFR_SUCCESSFUL; -} - -int action_update_time(ccsdsTelecommandPacket_t *TC) -{ - unsigned int incomingCoarseTime; - unsigned int currentLocalCoarseTime; - - incomingCoarseTime = (TC->dataAndCRC[0] << 24) - + (TC->dataAndCRC[1] << 16) - + (TC->dataAndCRC[2] << 8) - + TC->dataAndCRC[3]; - - currentLocalCoarseTime = getLocalCoarseTime(); - setLocalCoarseTime( incomingCoarseTime ); - printf( "currentLocalCoarseTime = %x, localCoarseTime set to: %x\n", currentLocalCoarseTime, getLocalCoarseTime() ); - - return LFR_SUCCESSFUL; -} - -//******************* -// ENTERING THE MODES -int check_mode_value( unsigned char requestedMode ) -{ - return LFR_SUCCESSFUL; -} - -int check_mode_transition( unsigned char requestedMode ) -{ - return LFR_SUCCESSFUL; -} - -int check_transition_date( unsigned int transitionCoarseTime ) -{ - return LFR_SUCCESSFUL; -} - -int stop_current_mode( void ) -{ - return LFR_SUCCESSFUL; -} - -int enter_mode( unsigned char mode, unsigned int transitionCoarseTime ) -{ - return LFR_SUCCESSFUL; -} - -int restart_science_tasks(unsigned char lfrRequestedMode ) -{ - return LFR_SUCCESSFUL; -} - -int suspend_science_tasks() -{ - return LFR_SUCCESSFUL; -} - -void launch_waveform_picker( unsigned char mode, unsigned int transitionCoarseTime ) -{ -} - -void launch_spectral_matrix( void ) -{ -} - -void launch_spectral_matrix_simu( void ) -{ -} - -void set_irq_on_new_ready_matrix( unsigned char value ) -{ -} - -void set_run_matrix_spectral( unsigned char value ) -{ -} - -//**************** -// CLOSING ACTIONS -void update_last_TC_exe( ccsdsTelecommandPacket_t *TC, unsigned char * time ) -{ -} - -void update_last_TC_rej(ccsdsTelecommandPacket_t *TC, unsigned char * time ) -{ -} - -void close_action(ccsdsTelecommandPacket_t *TC, int result, rtems_id queue_id ) -{ -} - -//*************************** -// Interrupt Service Routines -rtems_isr commutation_isr1( rtems_vector_number vector ) -{ - if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { - printf("In commutation_isr1 *** Error sending event to DUMB\n"); - } -} - -rtems_isr commutation_isr2( rtems_vector_number vector ) -{ - if (rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { - printf("In commutation_isr2 *** Error sending event to DUMB\n"); - } -} - -//**************** -// OTHER FUNCTIONS -void updateLFRCurrentMode() -{ -} - diff --git a/timegen/src/tc_load_dump_parameters.c b/timegen/src/tc_load_dump_parameters.c deleted file mode 100644 --- a/timegen/src/tc_load_dump_parameters.c +++ /dev/null @@ -1,772 +0,0 @@ -/** Functions to load and dump parameters in the LFR registers. - * - * @file - * @author P. LEROY - * - * A group of functions to handle TC related to parameter loading and dumping.\n - * TC_LFR_LOAD_COMMON_PAR\n - * TC_LFR_LOAD_NORMAL_PAR\n - * TC_LFR_LOAD_BURST_PAR\n - * TC_LFR_LOAD_SBM1_PAR\n - * TC_LFR_LOAD_SBM2_PAR\n - * - */ - -#include "tc_load_dump_parameters.h" - -int action_load_common_par(ccsdsTelecommandPacket_t *TC) -{ - /** This function updates the LFR registers with the incoming common parameters. - * - * @param TC points to the TeleCommand packet that is being processed - * - * - */ - - parameter_dump_packet.unused0 = TC->dataAndCRC[0]; - parameter_dump_packet.bw_sp0_sp1_r0_r1 = TC->dataAndCRC[1]; - set_wfp_data_shaping( ); - return LFR_SUCCESSFUL; -} - -int action_load_normal_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) -{ - /** This function updates the LFR registers with the incoming normal parameters. - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int result; - int flag; - rtems_status_code status; - - flag = LFR_SUCCESSFUL; - - if ( (lfrCurrentMode == LFR_MODE_NORMAL) || - (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) { - status = send_tm_lfr_tc_exe_not_executable( TC, queue_id ); - flag = LFR_DEFAULT; - } - - // CHECK THE PARAMETERS SET CONSISTENCY - if (flag == LFR_SUCCESSFUL) - { - flag = check_common_par_consistency( TC, queue_id ); - } - - // SET THE PARAMETERS IF THEY ARE CONSISTENT - if (flag == LFR_SUCCESSFUL) - { - result = set_sy_lfr_n_swf_l( TC ); - result = set_sy_lfr_n_swf_p( TC ); - result = set_sy_lfr_n_bp_p0( TC ); - result = set_sy_lfr_n_bp_p1( TC ); - result = set_sy_lfr_n_asm_p( TC ); - result = set_sy_lfr_n_cwf_long_f3( TC ); - } - - return flag; -} - -int action_load_burst_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) -{ - /** This function updates the LFR registers with the incoming burst parameters. - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int flag; - rtems_status_code status; - unsigned char sy_lfr_b_bp_p0; - unsigned char sy_lfr_b_bp_p1; - float aux; - - flag = LFR_SUCCESSFUL; - - if ( lfrCurrentMode == LFR_MODE_BURST ) { - status = send_tm_lfr_tc_exe_not_executable( TC, queue_id ); - flag = LFR_DEFAULT; - } - - sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ]; - sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ]; - - // sy_lfr_b_bp_p0 - if (flag == LFR_SUCCESSFUL) - { - if (sy_lfr_b_bp_p0 < DEFAULT_SY_LFR_B_BP_P0 ) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 ); - flag = WRONG_APP_DATA; - } - } - // sy_lfr_b_bp_p1 - if (flag == LFR_SUCCESSFUL) - { - if (sy_lfr_b_bp_p1 < DEFAULT_SY_LFR_B_BP_P1 ) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P1+10, sy_lfr_b_bp_p1 ); - flag = WRONG_APP_DATA; - } - } - //**************************************************************** - // check the consistency between sy_lfr_b_bp_p0 and sy_lfr_b_bp_p1 - if (flag == LFR_SUCCESSFUL) - { - sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ]; - sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ]; - aux = ( (float ) sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0 ) - floor(sy_lfr_b_bp_p1 / sy_lfr_b_bp_p0); - if (aux > FLOAT_EQUAL_ZERO) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_B_BP_P0+10, sy_lfr_b_bp_p0 ); - flag = LFR_DEFAULT; - } - } - - // SET HTE PARAMETERS - if (flag == LFR_SUCCESSFUL) - { - flag = set_sy_lfr_b_bp_p0( TC ); - flag = set_sy_lfr_b_bp_p1( TC ); - } - - return flag; -} - -int action_load_sbm1_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) -{ - /** This function updates the LFR registers with the incoming sbm1 parameters. - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int flag; - rtems_status_code status; - unsigned char sy_lfr_s1_bp_p0; - unsigned char sy_lfr_s1_bp_p1; - float aux; - - flag = LFR_SUCCESSFUL; - - if ( lfrCurrentMode == LFR_MODE_SBM1 ) { - status = send_tm_lfr_tc_exe_not_executable( TC, queue_id ); - flag = LFR_DEFAULT; - } - - sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ]; - sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ]; - - // sy_lfr_s1_bp_p0 - if (flag == LFR_SUCCESSFUL) - { - if (sy_lfr_s1_bp_p0 < DEFAULT_SY_LFR_S1_BP_P0 ) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 ); - flag = WRONG_APP_DATA; - } - } - // sy_lfr_s1_bp_p1 - if (flag == LFR_SUCCESSFUL) - { - if (sy_lfr_s1_bp_p1 < DEFAULT_SY_LFR_S1_BP_P1 ) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P1+10, sy_lfr_s1_bp_p1 ); - flag = WRONG_APP_DATA; - } - } - //****************************************************************** - // check the consistency between sy_lfr_s1_bp_p0 and sy_lfr_s1_bp_p1 - if (flag == LFR_SUCCESSFUL) - { - aux = ( (float ) sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25) ) - floor(sy_lfr_s1_bp_p1 / (sy_lfr_s1_bp_p0*0.25)); - if (aux > FLOAT_EQUAL_ZERO) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S1_BP_P0+10, sy_lfr_s1_bp_p0 ); - flag = LFR_DEFAULT; - } - } - - // SET THE PARAMETERS - if (flag == LFR_SUCCESSFUL) - { - flag = set_sy_lfr_s1_bp_p0( TC ); - flag = set_sy_lfr_s1_bp_p1( TC ); - } - - return flag; -} - -int action_load_sbm2_par(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time) -{ - /** This function updates the LFR registers with the incoming sbm2 parameters. - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int flag; - rtems_status_code status; - unsigned char sy_lfr_s2_bp_p0; - unsigned char sy_lfr_s2_bp_p1; - float aux; - - flag = LFR_SUCCESSFUL; - - if ( lfrCurrentMode == LFR_MODE_SBM2 ) { - status = send_tm_lfr_tc_exe_not_executable( TC, queue_id ); - flag = LFR_DEFAULT; - } - - sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ]; - sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ]; - - // sy_lfr_s2_bp_p0 - if (flag == LFR_SUCCESSFUL) - { - if (sy_lfr_s2_bp_p0 < DEFAULT_SY_LFR_S2_BP_P0 ) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 ); - flag = WRONG_APP_DATA; - } - } - // sy_lfr_s2_bp_p1 - if (flag == LFR_SUCCESSFUL) - { - if (sy_lfr_s2_bp_p1 < DEFAULT_SY_LFR_S2_BP_P1 ) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P1+10, sy_lfr_s2_bp_p1 ); - flag = WRONG_APP_DATA; - } - } - //****************************************************************** - // check the consistency between sy_lfr_s2_bp_p0 and sy_lfr_s2_bp_p1 - if (flag == LFR_SUCCESSFUL) - { - sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ]; - sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ]; - aux = ( (float ) sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0 ) - floor(sy_lfr_s2_bp_p1 / sy_lfr_s2_bp_p0); - if (aux > FLOAT_EQUAL_ZERO) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_S2_BP_P0+10, sy_lfr_s2_bp_p0 ); - flag = LFR_DEFAULT; - } - } - - // SET THE PARAMETERS - if (flag == LFR_SUCCESSFUL) - { - flag = set_sy_lfr_s2_bp_p0( TC ); - flag = set_sy_lfr_s2_bp_p1( TC ); - } - - return flag; -} - -int action_dump_par( rtems_id queue_id ) -{ - /** This function dumps the LFR parameters by sending the appropriate TM packet to the dedicated RTEMS message queue. - * - * @param queue_id is the id of the queue which handles TM related to this execution step. - * - * @return RTEMS directive status codes: - * - RTEMS_SUCCESSFUL - message sent successfully - * - RTEMS_INVALID_ID - invalid queue id - * - RTEMS_INVALID_SIZE - invalid message size - * - RTEMS_INVALID_ADDRESS - buffer is NULL - * - RTEMS_UNSATISFIED - out of message buffers - * - RTEMS_TOO_MANY - queue s limit has been reached - * - */ - - int status; - - // UPDATE TIME - parameter_dump_packet.packetSequenceControl[0] = (unsigned char) (sequenceCounterParameterDump >> 8); - parameter_dump_packet.packetSequenceControl[1] = (unsigned char) (sequenceCounterParameterDump ); - increment_seq_counter( &sequenceCounterParameterDump ); - - parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); - parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); - parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); - parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); - parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); - parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time); - // SEND DATA - status = rtems_message_queue_send( queue_id, ¶meter_dump_packet, - PACKET_LENGTH_PARAMETER_DUMP + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES); - if (status != RTEMS_SUCCESSFUL) { - PRINTF1("in action_dump *** ERR sending packet, code %d", status) - } - - return status; -} - -//*********************** -// NORMAL MODE PARAMETERS - -int check_common_par_consistency( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) -{ - unsigned char msb; - unsigned char lsb; - int flag; - float aux; - rtems_status_code status; - - unsigned int sy_lfr_n_swf_l; - unsigned int sy_lfr_n_swf_p; - unsigned int sy_lfr_n_asm_p; - unsigned char sy_lfr_n_bp_p0; - unsigned char sy_lfr_n_bp_p1; - unsigned char sy_lfr_n_cwf_long_f3; - - flag = LFR_SUCCESSFUL; - - //*************** - // get parameters - msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ]; - lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ]; - sy_lfr_n_swf_l = msb * 256 + lsb; - - msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ]; - lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ]; - sy_lfr_n_swf_p = msb * 256 + lsb; - - msb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ]; - lsb = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ]; - sy_lfr_n_asm_p = msb * 256 + lsb; - - sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ]; - - sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ]; - - sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ]; - - //****************** - // check consistency - // sy_lfr_n_swf_l - if (sy_lfr_n_swf_l != 2048) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_L+10, sy_lfr_n_swf_l ); - flag = WRONG_APP_DATA; - } - // sy_lfr_n_swf_p - if (flag == LFR_SUCCESSFUL) - { - if ( sy_lfr_n_swf_p < 16 ) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_SWF_P+10, sy_lfr_n_swf_p ); - flag = WRONG_APP_DATA; - } - } - // sy_lfr_n_bp_p0 - if (flag == LFR_SUCCESSFUL) - { - if (sy_lfr_n_bp_p0 < DFLT_SY_LFR_N_BP_P0) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P0+10, sy_lfr_n_bp_p0 ); - flag = WRONG_APP_DATA; - } - } - // sy_lfr_n_asm_p - if (flag == LFR_SUCCESSFUL) - { - if (sy_lfr_n_asm_p == 0) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p ); - flag = WRONG_APP_DATA; - } - } - // sy_lfr_n_asm_p shall be a whole multiple of sy_lfr_n_bp_p0 - if (flag == LFR_SUCCESSFUL) - { - aux = ( (float ) sy_lfr_n_asm_p / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_asm_p / sy_lfr_n_bp_p0); - if (aux > FLOAT_EQUAL_ZERO) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_ASM_P+10, sy_lfr_n_asm_p ); - flag = WRONG_APP_DATA; - } - } - // sy_lfr_n_bp_p1 - if (flag == LFR_SUCCESSFUL) - { - if (sy_lfr_n_bp_p1 < DFLT_SY_LFR_N_BP_P1) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 ); - flag = WRONG_APP_DATA; - } - } - // sy_lfr_n_bp_p1 shall be a whole multiple of sy_lfr_n_bp_p0 - if (flag == LFR_SUCCESSFUL) - { - aux = ( (float ) sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0 ) - floor(sy_lfr_n_bp_p1 / sy_lfr_n_bp_p0); - if (aux > FLOAT_EQUAL_ZERO) - { - status = send_tm_lfr_tc_exe_inconsistent( TC, queue_id, DATAFIELD_POS_SY_LFR_N_BP_P1+10, sy_lfr_n_bp_p1 ); - flag = LFR_DEFAULT; - } - } - // sy_lfr_n_cwf_long_f3 - - return flag; -} - -int set_sy_lfr_n_swf_l( ccsdsTelecommandPacket_t *TC ) -{ - /** This function sets the number of points of a snapshot (sy_lfr_n_swf_l). - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int result; - - result = LFR_SUCCESSFUL; - - parameter_dump_packet.sy_lfr_n_swf_l[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L ]; - parameter_dump_packet.sy_lfr_n_swf_l[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_L+1 ]; - - return result; -} - -int set_sy_lfr_n_swf_p(ccsdsTelecommandPacket_t *TC ) -{ - /** This function sets the time between two snapshots, in s (sy_lfr_n_swf_p). - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int result; - - result = LFR_SUCCESSFUL; - - parameter_dump_packet.sy_lfr_n_swf_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P ]; - parameter_dump_packet.sy_lfr_n_swf_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_SWF_P+1 ]; - - return result; -} - -int set_sy_lfr_n_asm_p( ccsdsTelecommandPacket_t *TC ) -{ - /** This function sets the time between two full spectral matrices transmission, in s (SY_LFR_N_ASM_P). - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int result; - - result = LFR_SUCCESSFUL; - - parameter_dump_packet.sy_lfr_n_asm_p[0] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P ]; - parameter_dump_packet.sy_lfr_n_asm_p[1] = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_ASM_P+1 ]; - - return result; -} - -int set_sy_lfr_n_bp_p0( ccsdsTelecommandPacket_t *TC ) -{ - /** This function sets the time between two basic parameter sets, in s (DFLT_SY_LFR_N_BP_P0). - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int status; - - status = LFR_SUCCESSFUL; - - parameter_dump_packet.sy_lfr_n_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P0 ]; - - return status; -} - -int set_sy_lfr_n_bp_p1(ccsdsTelecommandPacket_t *TC ) -{ - /** This function sets the time between two basic parameter sets (autocorrelation + crosscorrelation), in s (sy_lfr_n_bp_p1). - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int status; - - status = LFR_SUCCESSFUL; - - parameter_dump_packet.sy_lfr_n_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_BP_P1 ]; - - return status; -} - -int set_sy_lfr_n_cwf_long_f3(ccsdsTelecommandPacket_t *TC ) -{ - /** This function allows to switch from CWF_F3 packets to CWF_LONG_F3 packets. - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int status; - - status = LFR_SUCCESSFUL; - - parameter_dump_packet.sy_lfr_n_cwf_long_f3 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_N_CWF_LONG_F3 ]; - - return status; -} - -//********************** -// BURST MODE PARAMETERS -int set_sy_lfr_b_bp_p0(ccsdsTelecommandPacket_t *TC) -{ - /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P0). - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int status; - - status = LFR_SUCCESSFUL; - - parameter_dump_packet.sy_lfr_b_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P0 ]; - - return status; -} - -int set_sy_lfr_b_bp_p1( ccsdsTelecommandPacket_t *TC ) -{ - /** This function sets the time between two basic parameter sets, in s (SY_LFR_B_BP_P1). - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int status; - - status = LFR_SUCCESSFUL; - - parameter_dump_packet.sy_lfr_b_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_B_BP_P1 ]; - - return status; -} - -//********************* -// SBM1 MODE PARAMETERS -int set_sy_lfr_s1_bp_p0( ccsdsTelecommandPacket_t *TC ) -{ - /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P0). - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int status; - - status = LFR_SUCCESSFUL; - - parameter_dump_packet.sy_lfr_s1_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P0 ]; - - return status; -} - -int set_sy_lfr_s1_bp_p1( ccsdsTelecommandPacket_t *TC ) -{ - /** This function sets the time between two basic parameter sets, in s (SY_LFR_S1_BP_P1). - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int status; - - status = LFR_SUCCESSFUL; - - parameter_dump_packet.sy_lfr_s1_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S1_BP_P1 ]; - - return status; -} - -//********************* -// SBM2 MODE PARAMETERS -int set_sy_lfr_s2_bp_p0(ccsdsTelecommandPacket_t *TC) -{ - /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P0). - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int status; - - status = LFR_SUCCESSFUL; - - parameter_dump_packet.sy_lfr_s2_bp_p0 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P0 ]; - - return status; -} - -int set_sy_lfr_s2_bp_p1( ccsdsTelecommandPacket_t *TC ) -{ - /** This function sets the time between two basic parameter sets, in s (SY_LFR_S2_BP_P1). - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM related to this execution step - * - */ - - int status; - - status = LFR_SUCCESSFUL; - - parameter_dump_packet.sy_lfr_s2_bp_p1 = TC->dataAndCRC[ DATAFIELD_POS_SY_LFR_S2_BP_P1 ]; - - return status; -} - - -//******************* -// TC_LFR_UPDATE_INFO -unsigned int check_update_info_hk_lfr_mode( unsigned char mode ) -{ - unsigned int status; - - if ( (mode == LFR_MODE_STANDBY) || (mode == LFR_MODE_NORMAL) - || (mode == LFR_MODE_BURST) - || (mode == LFR_MODE_SBM1) || (mode == LFR_MODE_SBM2)) - { - status = LFR_SUCCESSFUL; - } - else - { - status = LFR_DEFAULT; - } - - return status; -} - -unsigned int check_update_info_hk_tds_mode( unsigned char mode ) -{ - unsigned int status; - - if ( (mode == TDS_MODE_STANDBY) || (mode == TDS_MODE_NORMAL) - || (mode == TDS_MODE_BURST) - || (mode == TDS_MODE_SBM1) || (mode == TDS_MODE_SBM2) - || (mode == TDS_MODE_LFM)) - { - status = LFR_SUCCESSFUL; - } - else - { - status = LFR_DEFAULT; - } - - return status; -} - -unsigned int check_update_info_hk_thr_mode( unsigned char mode ) -{ - unsigned int status; - - if ( (mode == THR_MODE_STANDBY) || (mode == THR_MODE_NORMAL) - || (mode == THR_MODE_BURST)) - { - status = LFR_SUCCESSFUL; - } - else - { - status = LFR_DEFAULT; - } - - return status; -} - -//********** -// init dump - -void init_parameter_dump( void ) -{ - /** This function initialize the parameter_dump_packet global variable with default values. - * - */ - - parameter_dump_packet.targetLogicalAddress = CCSDS_DESTINATION_ID; - parameter_dump_packet.protocolIdentifier = CCSDS_PROTOCOLE_ID; - parameter_dump_packet.reserved = CCSDS_RESERVED; - parameter_dump_packet.userApplication = CCSDS_USER_APP; - parameter_dump_packet.packetID[0] = (unsigned char) (APID_TM_PARAMETER_DUMP >> 8); - parameter_dump_packet.packetID[1] = (unsigned char) APID_TM_PARAMETER_DUMP; - parameter_dump_packet.packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; - parameter_dump_packet.packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; - parameter_dump_packet.packetLength[0] = (unsigned char) (PACKET_LENGTH_PARAMETER_DUMP >> 8); - parameter_dump_packet.packetLength[1] = (unsigned char) PACKET_LENGTH_PARAMETER_DUMP; - // DATA FIELD HEADER - parameter_dump_packet.spare1_pusVersion_spare2 = SPARE1_PUSVERSION_SPARE2; - parameter_dump_packet.serviceType = TM_TYPE_PARAMETER_DUMP; - parameter_dump_packet.serviceSubType = TM_SUBTYPE_PARAMETER_DUMP; - parameter_dump_packet.destinationID = TM_DESTINATION_ID_GROUND; - parameter_dump_packet.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); - parameter_dump_packet.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); - parameter_dump_packet.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); - parameter_dump_packet.time[3] = (unsigned char) (time_management_regs->coarse_time); - parameter_dump_packet.time[4] = (unsigned char) (time_management_regs->fine_time>>8); - parameter_dump_packet.time[5] = (unsigned char) (time_management_regs->fine_time); - parameter_dump_packet.sid = SID_PARAMETER_DUMP; - - //****************** - // COMMON PARAMETERS - parameter_dump_packet.unused0 = DEFAULT_SY_LFR_COMMON0; - parameter_dump_packet.bw_sp0_sp1_r0_r1 = DEFAULT_SY_LFR_COMMON1; - - //****************** - // NORMAL PARAMETERS - parameter_dump_packet.sy_lfr_n_swf_l[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_L >> 8); - parameter_dump_packet.sy_lfr_n_swf_l[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_L ); - parameter_dump_packet.sy_lfr_n_swf_p[0] = (unsigned char) (DFLT_SY_LFR_N_SWF_P >> 8); - parameter_dump_packet.sy_lfr_n_swf_p[1] = (unsigned char) (DFLT_SY_LFR_N_SWF_P ); - parameter_dump_packet.sy_lfr_n_asm_p[0] = (unsigned char) (DFLT_SY_LFR_N_ASM_P >> 8); - parameter_dump_packet.sy_lfr_n_asm_p[1] = (unsigned char) (DFLT_SY_LFR_N_ASM_P ); - parameter_dump_packet.sy_lfr_n_bp_p0 = (unsigned char) DFLT_SY_LFR_N_BP_P0; - parameter_dump_packet.sy_lfr_n_bp_p1 = (unsigned char) DFLT_SY_LFR_N_BP_P1; - parameter_dump_packet.sy_lfr_n_cwf_long_f3 = (unsigned char) DFLT_SY_LFR_N_CWF_LONG_F3; - - //***************** - // BURST PARAMETERS - parameter_dump_packet.sy_lfr_b_bp_p0 = (unsigned char) DEFAULT_SY_LFR_B_BP_P0; - parameter_dump_packet.sy_lfr_b_bp_p1 = (unsigned char) DEFAULT_SY_LFR_B_BP_P1; - - //**************** - // SBM1 PARAMETERS - parameter_dump_packet.sy_lfr_s1_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P0; // min value is 0.25 s for the period - parameter_dump_packet.sy_lfr_s1_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S1_BP_P1; - - //**************** - // SBM2 PARAMETERS - parameter_dump_packet.sy_lfr_s2_bp_p0 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P0; - parameter_dump_packet.sy_lfr_s2_bp_p1 = (unsigned char) DEFAULT_SY_LFR_S2_BP_P1; -} - - - - - - - diff --git a/timegen/src/tm_lfr_tc_exe.c b/timegen/src/tm_lfr_tc_exe.c deleted file mode 100644 --- a/timegen/src/tm_lfr_tc_exe.c +++ /dev/null @@ -1,510 +0,0 @@ -/** Functions to send TM packets related to TC parsing and execution. - * - * @file - * @author P. LEROY - * - * A group of functions to send appropriate TM packets after parsing and execution: - * - TM_LFR_TC_EXE_SUCCESS - * - TM_LFR_TC_EXE_INCONSISTENT - * - TM_LFR_TC_EXE_NOT_EXECUTABLE - * - TM_LFR_TC_EXE_NOT_IMPLEMENTED - * - TM_LFR_TC_EXE_ERROR - * - TM_LFR_TC_EXE_CORRUPTED - * - */ - -#include "tm_lfr_tc_exe.h" - -int send_tm_lfr_tc_exe_success( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) -{ - /** This function sends a TM_LFR_TC_EXE_SUCCESS packet in the dedicated RTEMS message queue. - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM - * - * @return RTEMS directive status code: - * - RTEMS_SUCCESSFUL - message sent successfully - * - RTEMS_INVALID_ID - invalid queue id - * - RTEMS_INVALID_SIZE - invalid message size - * - RTEMS_INVALID_ADDRESS - buffer is NULL - * - RTEMS_UNSATISFIED - out of message buffers - * - RTEMS_TOO_MANY - queue s limit has been reached - * - */ - - rtems_status_code status; - Packet_TM_LFR_TC_EXE_SUCCESS_t TM; - unsigned char messageSize; - - TM.targetLogicalAddress = CCSDS_DESTINATION_ID; - TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; - TM.reserved = DEFAULT_RESERVED; - TM.userApplication = CCSDS_USER_APP; - // PACKET HEADER - TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8); - TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); - increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); - TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS >> 8); - TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_SUCCESS ); - // DATA FIELD HEADER - TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; - TM.serviceType = TM_TYPE_TC_EXE; - TM.serviceSubType = TM_SUBTYPE_EXE_OK; - TM.destinationID = TC->sourceID; - TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); - TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); - TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); - TM.time[3] = (unsigned char) (time_management_regs->coarse_time); - TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8); - TM.time[5] = (unsigned char) (time_management_regs->fine_time); - // - TM.telecommand_pkt_id[0] = TC->packetID[0]; - TM.telecommand_pkt_id[1] = TC->packetID[1]; - TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; - TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; - - messageSize = PACKET_LENGTH_TC_EXE_SUCCESS + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; - - // SEND DATA - status = rtems_message_queue_send( queue_id, &TM, messageSize); - if (status != RTEMS_SUCCESSFUL) { - PRINTF("in send_tm_lfr_tc_exe_success *** ERR\n") - } - - // UPDATE HK FIELDS - update_last_TC_exe( TC, TM.time ); - - return status; -} - -int send_tm_lfr_tc_exe_inconsistent( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, - unsigned char byte_position, unsigned char rcv_value ) -{ - /** This function sends a TM_LFR_TC_EXE_INCONSISTENT packet in the dedicated RTEMS message queue. - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM - * @param byte_position is the byte position of the MSB of the parameter that has been seen as inconsistent - * @param rcv_value is the value of the LSB of the parameter that has been deteced as inconsistent - * - * @return RTEMS directive status code: - * - RTEMS_SUCCESSFUL - message sent successfully - * - RTEMS_INVALID_ID - invalid queue id - * - RTEMS_INVALID_SIZE - invalid message size - * - RTEMS_INVALID_ADDRESS - buffer is NULL - * - RTEMS_UNSATISFIED - out of message buffers - * - RTEMS_TOO_MANY - queue s limit has been reached - * - */ - - rtems_status_code status; - Packet_TM_LFR_TC_EXE_INCONSISTENT_t TM; - unsigned char messageSize; - - TM.targetLogicalAddress = CCSDS_DESTINATION_ID; - TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; - TM.reserved = DEFAULT_RESERVED; - TM.userApplication = CCSDS_USER_APP; - // PACKET HEADER - TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8); - TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); - increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); - TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT >> 8); - TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_INCONSISTENT ); - // DATA FIELD HEADER - TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; - TM.serviceType = TM_TYPE_TC_EXE; - TM.serviceSubType = TM_SUBTYPE_EXE_NOK; - TM.destinationID = TC->sourceID; - TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); - TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); - TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); - TM.time[3] = (unsigned char) (time_management_regs->coarse_time); - TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8); - TM.time[5] = (unsigned char) (time_management_regs->fine_time); - // - TM.tc_failure_code[0] = (char) (WRONG_APP_DATA >> 8); - TM.tc_failure_code[1] = (char) (WRONG_APP_DATA ); - TM.telecommand_pkt_id[0] = TC->packetID[0]; - TM.telecommand_pkt_id[1] = TC->packetID[1]; - TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; - TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; - TM.tc_service = TC->serviceType; // type of the rejected TC - TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC - TM.byte_position = byte_position; - TM.rcv_value = (unsigned char) rcv_value; - - messageSize = PACKET_LENGTH_TC_EXE_INCONSISTENT + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; - - // SEND DATA - status = rtems_message_queue_send( queue_id, &TM, messageSize); - if (status != RTEMS_SUCCESSFUL) { - PRINTF("in send_tm_lfr_tc_exe_inconsistent *** ERR\n") - } - - // UPDATE HK FIELDS - update_last_TC_rej( TC, TM.time ); - - return status; -} - -int send_tm_lfr_tc_exe_not_executable( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) -{ - /** This function sends a TM_LFR_TC_EXE_NOT_EXECUTABLE packet in the dedicated RTEMS message queue. - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM - * - * @return RTEMS directive status code: - * - RTEMS_SUCCESSFUL - message sent successfully - * - RTEMS_INVALID_ID - invalid queue id - * - RTEMS_INVALID_SIZE - invalid message size - * - RTEMS_INVALID_ADDRESS - buffer is NULL - * - RTEMS_UNSATISFIED - out of message buffers - * - RTEMS_TOO_MANY - queue s limit has been reached - * - */ - - rtems_status_code status; - Packet_TM_LFR_TC_EXE_NOT_EXECUTABLE_t TM; - unsigned char messageSize; - - TM.targetLogicalAddress = CCSDS_DESTINATION_ID; - TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; - TM.reserved = DEFAULT_RESERVED; - TM.userApplication = CCSDS_USER_APP; - // PACKET HEADER - TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8); - TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); - increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); - TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE >> 8); - TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE ); - // DATA FIELD HEADER - TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; - TM.serviceType = TM_TYPE_TC_EXE; - TM.serviceSubType = TM_SUBTYPE_EXE_NOK; - TM.destinationID = TC->sourceID; // default destination id - TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); - TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); - TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); - TM.time[3] = (unsigned char) (time_management_regs->coarse_time); - TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8); - TM.time[5] = (unsigned char) (time_management_regs->fine_time); - // - TM.tc_failure_code[0] = (char) (TC_NOT_EXE >> 8); - TM.tc_failure_code[1] = (char) (TC_NOT_EXE ); - TM.telecommand_pkt_id[0] = TC->packetID[0]; - TM.telecommand_pkt_id[1] = TC->packetID[1]; - TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; - TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; - TM.tc_service = TC->serviceType; // type of the rejected TC - TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC - TM.lfr_status_word[0] = housekeeping_packet.lfr_status_word[0]; - TM.lfr_status_word[1] = housekeeping_packet.lfr_status_word[1]; - - messageSize = PACKET_LENGTH_TC_EXE_NOT_EXECUTABLE + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; - - // SEND DATA - status = rtems_message_queue_send( queue_id, &TM, messageSize); - if (status != RTEMS_SUCCESSFUL) { - PRINTF("in send_tm_lfr_tc_exe_not_executable *** ERR\n") - } - - // UPDATE HK FIELDS - update_last_TC_rej( TC, TM.time ); - - return status; -} - -int send_tm_lfr_tc_exe_not_implemented( ccsdsTelecommandPacket_t *TC, rtems_id queue_id, unsigned char *time ) -{ - /** This function sends a TM_LFR_TC_EXE_NOT_IMPLEMENTED packet in the dedicated RTEMS message queue. - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM - * - * @return RTEMS directive status code: - * - RTEMS_SUCCESSFUL - message sent successfully - * - RTEMS_INVALID_ID - invalid queue id - * - RTEMS_INVALID_SIZE - invalid message size - * - RTEMS_INVALID_ADDRESS - buffer is NULL - * - RTEMS_UNSATISFIED - out of message buffers - * - RTEMS_TOO_MANY - queue s limit has been reached - * - */ - - rtems_status_code status; - Packet_TM_LFR_TC_EXE_NOT_IMPLEMENTED_t TM; - unsigned char messageSize; - - TM.targetLogicalAddress = CCSDS_DESTINATION_ID; - TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; - TM.reserved = DEFAULT_RESERVED; - TM.userApplication = CCSDS_USER_APP; - // PACKET HEADER - TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8); - TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); - increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); - TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED >> 8); - TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED ); - // DATA FIELD HEADER - TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; - TM.serviceType = TM_TYPE_TC_EXE; - TM.serviceSubType = TM_SUBTYPE_EXE_NOK; - TM.destinationID = TC->sourceID; // default destination id - TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); - TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); - TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); - TM.time[3] = (unsigned char) (time_management_regs->coarse_time); - TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8); - TM.time[5] = (unsigned char) (time_management_regs->fine_time); - // - TM.tc_failure_code[0] = (char) (FUNCT_NOT_IMPL >> 8); - TM.tc_failure_code[1] = (char) (FUNCT_NOT_IMPL ); - TM.telecommand_pkt_id[0] = TC->packetID[0]; - TM.telecommand_pkt_id[1] = TC->packetID[1]; - TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; - TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; - TM.tc_service = TC->serviceType; // type of the rejected TC - TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC - - messageSize = PACKET_LENGTH_TC_EXE_NOT_IMPLEMENTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; - - // SEND DATA - status = rtems_message_queue_send( queue_id, &TM, messageSize); - if (status != RTEMS_SUCCESSFUL) { - PRINTF("in send_tm_lfr_tc_exe_not_implemented *** ERR\n") - } - - // UPDATE HK FIELDS - update_last_TC_rej( TC, TM.time ); - - return status; -} - -int send_tm_lfr_tc_exe_error( ccsdsTelecommandPacket_t *TC, rtems_id queue_id ) -{ - /** This function sends a TM_LFR_TC_EXE_ERROR packet in the dedicated RTEMS message queue. - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM - * - * @return RTEMS directive status code: - * - RTEMS_SUCCESSFUL - message sent successfully - * - RTEMS_INVALID_ID - invalid queue id - * - RTEMS_INVALID_SIZE - invalid message size - * - RTEMS_INVALID_ADDRESS - buffer is NULL - * - RTEMS_UNSATISFIED - out of message buffers - * - RTEMS_TOO_MANY - queue s limit has been reached - * - */ - - rtems_status_code status; - Packet_TM_LFR_TC_EXE_ERROR_t TM; - unsigned char messageSize; - - TM.targetLogicalAddress = CCSDS_DESTINATION_ID; - TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; - TM.reserved = DEFAULT_RESERVED; - TM.userApplication = CCSDS_USER_APP; - // PACKET HEADER - TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8); - TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); - increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); - TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR >> 8); - TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_ERROR ); - // DATA FIELD HEADER - TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; - TM.serviceType = TM_TYPE_TC_EXE; - TM.serviceSubType = TM_SUBTYPE_EXE_NOK; - TM.destinationID = TC->sourceID; // default destination id - TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); - TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); - TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); - TM.time[3] = (unsigned char) (time_management_regs->coarse_time); - TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8); - TM.time[5] = (unsigned char) (time_management_regs->fine_time); - // - TM.tc_failure_code[0] = (char) (FAIL_DETECTED >> 8); - TM.tc_failure_code[1] = (char) (FAIL_DETECTED ); - TM.telecommand_pkt_id[0] = TC->packetID[0]; - TM.telecommand_pkt_id[1] = TC->packetID[1]; - TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; - TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; - TM.tc_service = TC->serviceType; // type of the rejected TC - TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC - - messageSize = PACKET_LENGTH_TC_EXE_ERROR + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; - - // SEND DATA - status = rtems_message_queue_send( queue_id, &TM, messageSize); - if (status != RTEMS_SUCCESSFUL) { - PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n") - } - - // UPDATE HK FIELDS - update_last_TC_rej( TC, TM.time ); - - return status; -} - -int send_tm_lfr_tc_exe_corrupted(ccsdsTelecommandPacket_t *TC, rtems_id queue_id, - unsigned char *computed_CRC, unsigned char *currentTC_LEN_RCV, - unsigned char destinationID ) -{ - /** This function sends a TM_LFR_TC_EXE_CORRUPTED packet in the dedicated RTEMS message queue. - * - * @param TC points to the TeleCommand packet that is being processed - * @param queue_id is the id of the queue which handles TM - * @param computed_CRC points to a buffer of two bytes containing the CRC computed during the parsing of the TeleCommand - * @param currentTC_LEN_RCV points to a buffer of two bytes containing a packet size field computed on the received data - * - * @return RTEMS directive status code: - * - RTEMS_SUCCESSFUL - message sent successfully - * - RTEMS_INVALID_ID - invalid queue id - * - RTEMS_INVALID_SIZE - invalid message size - * - RTEMS_INVALID_ADDRESS - buffer is NULL - * - RTEMS_UNSATISFIED - out of message buffers - * - RTEMS_TOO_MANY - queue s limit has been reached - * - */ - - rtems_status_code status; - Packet_TM_LFR_TC_EXE_CORRUPTED_t TM; - unsigned char messageSize; - unsigned int packetLength; - unsigned char *packetDataField; - - packetLength = (TC->packetLength[0] * 256) + TC->packetLength[1]; // compute the packet length parameter - packetDataField = (unsigned char *) &TC->headerFlag_pusVersion_Ack; // get the beginning of the data field - - TM.targetLogicalAddress = CCSDS_DESTINATION_ID; - TM.protocolIdentifier = CCSDS_PROTOCOLE_ID; - TM.reserved = DEFAULT_RESERVED; - TM.userApplication = CCSDS_USER_APP; - // PACKET HEADER - TM.packetID[0] = (unsigned char) (APID_TM_TC_EXE >> 8); - TM.packetID[1] = (unsigned char) (APID_TM_TC_EXE ); - increment_seq_counter_destination_id( TM.packetSequenceControl, TC->sourceID ); - TM.packetLength[0] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED >> 8); - TM.packetLength[1] = (unsigned char) (PACKET_LENGTH_TC_EXE_CORRUPTED ); - // DATA FIELD HEADER - TM.spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; - TM.serviceType = TM_TYPE_TC_EXE; - TM.serviceSubType = TM_SUBTYPE_EXE_NOK; - TM.destinationID = destinationID; - TM.time[0] = (unsigned char) (time_management_regs->coarse_time>>24); - TM.time[1] = (unsigned char) (time_management_regs->coarse_time>>16); - TM.time[2] = (unsigned char) (time_management_regs->coarse_time>>8); - TM.time[3] = (unsigned char) (time_management_regs->coarse_time); - TM.time[4] = (unsigned char) (time_management_regs->fine_time>>8); - TM.time[5] = (unsigned char) (time_management_regs->fine_time); - // - TM.tc_failure_code[0] = (unsigned char) (CORRUPTED >> 8); - TM.tc_failure_code[1] = (unsigned char) (CORRUPTED ); - TM.telecommand_pkt_id[0] = TC->packetID[0]; - TM.telecommand_pkt_id[1] = TC->packetID[1]; - TM.pkt_seq_control[0] = TC->packetSequenceControl[0]; - TM.pkt_seq_control[1] = TC->packetSequenceControl[1]; - TM.tc_service = TC->serviceType; // type of the rejected TC - TM.tc_subtype = TC->serviceSubType; // subtype of the rejected TC - TM.pkt_len_rcv_value[0] = TC->packetLength[0]; - TM.pkt_len_rcv_value[1] = TC->packetLength[1]; - TM.pkt_datafieldsize_cnt[0] = currentTC_LEN_RCV[0]; - TM.pkt_datafieldsize_cnt[1] = currentTC_LEN_RCV[1]; - TM.rcv_crc[0] = packetDataField[ packetLength - 1 ]; - TM.rcv_crc[1] = packetDataField[ packetLength ]; - TM.computed_crc[0] = computed_CRC[0]; - TM.computed_crc[1] = computed_CRC[1]; - - messageSize = PACKET_LENGTH_TC_EXE_CORRUPTED + CCSDS_TC_TM_PACKET_OFFSET + CCSDS_PROTOCOLE_EXTRA_BYTES; - - // SEND DATA - status = rtems_message_queue_send( queue_id, &TM, messageSize); - if (status != RTEMS_SUCCESSFUL) { - PRINTF("in send_tm_lfr_tc_exe_error *** ERR\n") - } - - // UPDATE HK FIELDS - update_last_TC_rej( TC, TM.time ); - - return status; -} - -void increment_seq_counter_destination_id( unsigned char *packet_sequence_control, unsigned char destination_id ) -{ - /** This function increment the packet sequence control parameter of a TC, depending on its destination ID. - * - * @param packet_sequence_control points to the packet sequence control which will be incremented - * @param destination_id is the destination ID of the TM, there is one counter by destination ID - * - * If the destination ID is not known, a dedicated counter is incremented. - * - */ - - unsigned short sequence_cnt; - unsigned short segmentation_grouping_flag; - unsigned short new_packet_sequence_control; - unsigned char i; - - switch (destination_id) - { - case SID_TC_GROUND: - i = GROUND; - break; - case SID_TC_MISSION_TIMELINE: - i = MISSION_TIMELINE; - break; - case SID_TC_TC_SEQUENCES: - i = TC_SEQUENCES; - break; - case SID_TC_RECOVERY_ACTION_CMD: - i = RECOVERY_ACTION_CMD; - break; - case SID_TC_BACKUP_MISSION_TIMELINE: - i = BACKUP_MISSION_TIMELINE; - break; - case SID_TC_DIRECT_CMD: - i = DIRECT_CMD; - break; - case SID_TC_SPARE_GRD_SRC1: - i = SPARE_GRD_SRC1; - break; - case SID_TC_SPARE_GRD_SRC2: - i = SPARE_GRD_SRC2; - break; - case SID_TC_OBCP: - i = OBCP; - break; - case SID_TC_SYSTEM_CONTROL: - i = SYSTEM_CONTROL; - break; - case SID_TC_AOCS: - i = AOCS; - break; - case SID_TC_RPW_INTERNAL: - i = RPW_INTERNAL; - break; - default: - i = GROUND; - break; - } - - segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; - sequence_cnt = sequenceCounters_TC_EXE[ i ] & 0x3fff; - - new_packet_sequence_control = segmentation_grouping_flag | sequence_cnt ; - - packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8); - packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); - - // increment the sequence counter - if ( sequenceCounters_TC_EXE[ i ] < SEQ_CNT_MAX ) - { - sequenceCounters_TC_EXE[ i ] = sequenceCounters_TC_EXE[ i ] + 1; - } - else - { - sequenceCounters_TC_EXE[ i ] = 0; - } -} diff --git a/timegen/src/wf_handler.c b/timegen/src/wf_handler.c deleted file mode 100644 --- a/timegen/src/wf_handler.c +++ /dev/null @@ -1,1323 +0,0 @@ -/** Functions and tasks related to waveform packet generation. - * - * @file - * @author P. LEROY - * - * A group of functions to handle waveforms, in snapshot or continuous format.\n - * - */ - -#include "wf_handler.h" - -//***************** -// waveform headers -// SWF -Header_TM_LFR_SCIENCE_SWF_t headerSWF_F0[7]; -Header_TM_LFR_SCIENCE_SWF_t headerSWF_F1[7]; -Header_TM_LFR_SCIENCE_SWF_t headerSWF_F2[7]; -// CWF -Header_TM_LFR_SCIENCE_CWF_t headerCWF_F1[ NB_PACKETS_PER_GROUP_OF_CWF ]; -Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_BURST[ NB_PACKETS_PER_GROUP_OF_CWF ]; -Header_TM_LFR_SCIENCE_CWF_t headerCWF_F2_SBM2[ NB_PACKETS_PER_GROUP_OF_CWF ]; -Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3[ NB_PACKETS_PER_GROUP_OF_CWF ]; -Header_TM_LFR_SCIENCE_CWF_t headerCWF_F3_light[ NB_PACKETS_PER_GROUP_OF_CWF_LIGHT ]; - -//************** -// waveform ring -ring_node waveform_ring_f0[NB_RING_NODES_F0]; -ring_node waveform_ring_f1[NB_RING_NODES_F1]; -ring_node waveform_ring_f2[NB_RING_NODES_F2]; -ring_node waveform_ring_f3[NB_RING_NODES_F3]; -ring_node *current_ring_node_f0; -ring_node *ring_node_to_send_swf_f0; -ring_node *current_ring_node_f1; -ring_node *ring_node_to_send_swf_f1; -ring_node *ring_node_to_send_cwf_f1; -ring_node *current_ring_node_f2; -ring_node *ring_node_to_send_swf_f2; -ring_node *ring_node_to_send_cwf_f2; -ring_node *current_ring_node_f3; -ring_node *ring_node_to_send_cwf_f3; - -bool extractSWF = false; -bool swf_f0_ready = false; -bool swf_f1_ready = false; -bool swf_f2_ready = false; - -int wf_snap_extracted[ (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK) + TIME_OFFSET ]; - -//********************* -// Interrupt SubRoutine - -void reset_extractSWF( void ) -{ - extractSWF = false; - swf_f0_ready = false; - swf_f1_ready = false; - swf_f2_ready = false; -} - -rtems_isr waveforms_isr( rtems_vector_number vector ) -{ - /** This is the interrupt sub routine called by the waveform picker core. - * - * This ISR launch different actions depending mainly on two pieces of information: - * 1. the values read in the registers of the waveform picker. - * 2. the current LFR mode. - * - */ - - rtems_status_code status; - rtems_status_code spare_status; - - if ( (lfrCurrentMode == LFR_MODE_NORMAL) || (lfrCurrentMode == LFR_MODE_BURST) // in BURST the data are used to place v, e1 and e2 in the HK packet - || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode == LFR_MODE_SBM2) ) - { // in modes other than STANDBY and BURST, send the CWF_F3 data - if ((waveform_picker_regs->status & 0x08) == 0x08){ // [1000] f3 is full - // (1) change the receiving buffer for the waveform picker - ring_node_to_send_cwf_f3 = current_ring_node_f3; - current_ring_node_f3 = current_ring_node_f3->next; - waveform_picker_regs->addr_data_f3 = current_ring_node_f3->buffer_address; - // (2) send an event for the waveforms transmission - if (rtems_event_send( Task_id[TASKID_CWF3], RTEMS_EVENT_0 ) != RTEMS_SUCCESSFUL) { - spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); - } - rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2); - waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff777; // reset f3 bits to 0, [1111 0111 0111 0111] - } - } - - switch(lfrCurrentMode) - { - //******** - // STANDBY - case(LFR_MODE_STANDBY): - break; - - //****** - // NORMAL - case(LFR_MODE_NORMAL): - if ( (waveform_picker_regs->status & 0xff8) != 0x00) // [1000] check the error bits - { - spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); - } - if ( (waveform_picker_regs->status & 0x07) == 0x07) // [0111] check the f2, f1, f0 full bits - { - // change F0 ring node - ring_node_to_send_swf_f0 = current_ring_node_f0; - current_ring_node_f0 = current_ring_node_f0->next; - waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address; - // change F1 ring node - ring_node_to_send_swf_f1 = current_ring_node_f1; - current_ring_node_f1 = current_ring_node_f1->next; - waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; - // change F2 ring node - ring_node_to_send_swf_f2 = current_ring_node_f2; - current_ring_node_f2 = current_ring_node_f2->next; - waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; - // - if (rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_NORMAL ) != RTEMS_SUCCESSFUL) - { - spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); - } - waveform_picker_regs->status = waveform_picker_regs->status & 0xfffff888; // [1000 1000 1000] - } - break; - - //****** - // BURST - case(LFR_MODE_BURST): - if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit - // (1) change the receiving buffer for the waveform picker - ring_node_to_send_cwf_f2 = current_ring_node_f2; - current_ring_node_f2 = current_ring_node_f2->next; - waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; - // (2) send an event for the waveforms transmission - if (rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_BURST ) != RTEMS_SUCCESSFUL) { - spare_status = rtems_event_send( Task_id[TASKID_DUMB], RTEMS_EVENT_2 ); - } - waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0 - } - break; - - //***** - // SBM1 - case(LFR_MODE_SBM1): - if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit - // (1) change the receiving buffer for the waveform picker - ring_node_to_send_cwf_f1 = current_ring_node_f1; - current_ring_node_f1 = current_ring_node_f1->next; - waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; - // (2) send an event for the the CWF1 task for transmission (and snapshot extraction if needed) - status = rtems_event_send( Task_id[TASKID_CWF1], RTEMS_EVENT_MODE_SBM1 ); - waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1 bits = 0 - } - if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit - swf_f0_ready = true; - waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffeee; // [1111 1110 1110 1110] f0 bits = 0 - } - if ( (waveform_picker_regs->status & 0x04) == 0x04 ) { // [0100] check the f2 full bit - swf_f2_ready = true; - waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bits = 0 - } - break; - - //***** - // SBM2 - case(LFR_MODE_SBM2): - if ( (waveform_picker_regs->status & 0x04) == 0x04 ){ // [0100] check the f2 full bit - // (1) change the receiving buffer for the waveform picker - ring_node_to_send_cwf_f2 = current_ring_node_f2; - current_ring_node_f2 = current_ring_node_f2->next; - waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; - // (2) send an event for the waveforms transmission - status = rtems_event_send( Task_id[TASKID_CWF2], RTEMS_EVENT_MODE_SBM2 ); - waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffbbb; // [1111 1011 1011 1011] f2 bit = 0 - } - if ( (waveform_picker_regs->status & 0x01) == 0x01 ) { // [0001] check the f0 full bit - swf_f0_ready = true; - waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffeee; // [1111 1110 1110 1110] f0 bits = 0 - } - if ( (waveform_picker_regs->status & 0x02) == 0x02 ) { // [0010] check the f1 full bit - swf_f1_ready = true; - waveform_picker_regs->status = waveform_picker_regs->status & 0xfffffddd; // [1111 1101 1101 1101] f1, f0 bits = 0 - } - break; - - //******** - // DEFAULT - default: - break; - } -} - -//************ -// RTEMS TASKS - -rtems_task wfrm_task(rtems_task_argument argument) //used with the waveform picker VHDL IP -{ - /** This RTEMS task is dedicated to the transmission of snapshots of the NORMAL mode. - * - * @param unused is the starting argument of the RTEMS task - * - * The following data packets are sent by this task: - * - TM_LFR_SCIENCE_NORMAL_SWF_F0 - * - TM_LFR_SCIENCE_NORMAL_SWF_F1 - * - TM_LFR_SCIENCE_NORMAL_SWF_F2 - * - */ - - rtems_event_set event_out; - rtems_id queue_id; - rtems_status_code status; - - init_header_snapshot_wf_table( SID_NORM_SWF_F0, headerSWF_F0 ); - init_header_snapshot_wf_table( SID_NORM_SWF_F1, headerSWF_F1 ); - init_header_snapshot_wf_table( SID_NORM_SWF_F2, headerSWF_F2 ); - - status = get_message_queue_id_send( &queue_id ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in WFRM *** ERR get_message_queue_id_send %d\n", status) - } - - BOOT_PRINTF("in WFRM ***\n") - - while(1){ - // wait for an RTEMS_EVENT - rtems_event_receive(RTEMS_EVENT_MODE_NORMAL | RTEMS_EVENT_MODE_SBM1 - | RTEMS_EVENT_MODE_SBM2 | RTEMS_EVENT_MODE_SBM2_WFRM, - RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); - if (event_out == RTEMS_EVENT_MODE_NORMAL) - { - DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_NORMAL\n") - send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id); - send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id); - send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id); - } - if (event_out == RTEMS_EVENT_MODE_SBM1) - { - DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM1\n") - send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id); - send_waveform_SWF((volatile int*) wf_snap_extracted , SID_NORM_SWF_F1, headerSWF_F1, queue_id); - send_waveform_SWF((volatile int*) ring_node_to_send_swf_f2->buffer_address, SID_NORM_SWF_F2, headerSWF_F2, queue_id); - } - if (event_out == RTEMS_EVENT_MODE_SBM2) - { - DEBUG_PRINTF("WFRM received RTEMS_EVENT_MODE_SBM2\n") - send_waveform_SWF((volatile int*) ring_node_to_send_swf_f0->buffer_address, SID_NORM_SWF_F0, headerSWF_F0, queue_id); - send_waveform_SWF((volatile int*) ring_node_to_send_swf_f1->buffer_address, SID_NORM_SWF_F1, headerSWF_F1, queue_id); - send_waveform_SWF((volatile int*) wf_snap_extracted , SID_NORM_SWF_F2, headerSWF_F2, queue_id); - } - } -} - -rtems_task cwf3_task(rtems_task_argument argument) //used with the waveform picker VHDL IP -{ - /** This RTEMS task is dedicated to the transmission of continuous waveforms at f3. - * - * @param unused is the starting argument of the RTEMS task - * - * The following data packet is sent by this task: - * - TM_LFR_SCIENCE_NORMAL_CWF_F3 - * - */ - - rtems_event_set event_out; - rtems_id queue_id; - rtems_status_code status; - - init_header_continuous_wf_table( SID_NORM_CWF_LONG_F3, headerCWF_F3 ); - init_header_continuous_cwf3_light_table( headerCWF_F3_light ); - - status = get_message_queue_id_send( &queue_id ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in CWF3 *** ERR get_message_queue_id_send %d\n", status) - } - - BOOT_PRINTF("in CWF3 ***\n") - - while(1){ - // wait for an RTEMS_EVENT - rtems_event_receive( RTEMS_EVENT_0, - RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); - if ( (lfrCurrentMode == LFR_MODE_NORMAL) - || (lfrCurrentMode == LFR_MODE_SBM1) || (lfrCurrentMode==LFR_MODE_SBM2) ) - { - if ( (parameter_dump_packet.sy_lfr_n_cwf_long_f3 & 0x01) == 0x01) - { - PRINTF("send CWF_LONG_F3\n") - send_waveform_CWF( - (volatile int*) ring_node_to_send_cwf_f3->buffer_address, - SID_NORM_CWF_LONG_F3, headerCWF_F3, queue_id ); - } - else - { - PRINTF("send CWF_F3 (light)\n") - send_waveform_CWF3_light( - (volatile int*) ring_node_to_send_cwf_f3->buffer_address, - headerCWF_F3_light, queue_id ); - } - - } - else - { - PRINTF1("in CWF3 *** lfrCurrentMode is %d, no data will be sent\n", lfrCurrentMode) - } - } -} - -rtems_task cwf2_task(rtems_task_argument argument) // ONLY USED IN BURST AND SBM2 -{ - /** This RTEMS task is dedicated to the transmission of continuous waveforms at f2. - * - * @param unused is the starting argument of the RTEMS task - * - * The following data packet is sent by this function: - * - TM_LFR_SCIENCE_BURST_CWF_F2 - * - TM_LFR_SCIENCE_SBM2_CWF_F2 - * - */ - - rtems_event_set event_out; - rtems_id queue_id; - rtems_status_code status; - - init_header_continuous_wf_table( SID_BURST_CWF_F2, headerCWF_F2_BURST ); - init_header_continuous_wf_table( SID_SBM2_CWF_F2, headerCWF_F2_SBM2 ); - - status = get_message_queue_id_send( &queue_id ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in CWF2 *** ERR get_message_queue_id_send %d\n", status) - } - - BOOT_PRINTF("in CWF2 ***\n") - - while(1){ - // wait for an RTEMS_EVENT - rtems_event_receive( RTEMS_EVENT_MODE_BURST | RTEMS_EVENT_MODE_SBM2, - RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); - if (event_out == RTEMS_EVENT_MODE_BURST) - { - send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_BURST_CWF_F2, headerCWF_F2_BURST, queue_id ); - } - if (event_out == RTEMS_EVENT_MODE_SBM2) - { - send_waveform_CWF( (volatile int *) ring_node_to_send_cwf_f2->buffer_address, SID_SBM2_CWF_F2, headerCWF_F2_SBM2, queue_id ); - // launch snapshot extraction if needed - if (extractSWF == true) - { - ring_node_to_send_swf_f2 = ring_node_to_send_cwf_f2; - // extract the snapshot - build_snapshot_from_ring( ring_node_to_send_swf_f2, 2 ); - // send the snapshot when built - status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM2 ); - extractSWF = false; - } - if (swf_f0_ready && swf_f1_ready) - { - extractSWF = true; - swf_f0_ready = false; - swf_f1_ready = false; - } - } - } -} - -rtems_task cwf1_task(rtems_task_argument argument) // ONLY USED IN SBM1 -{ - /** This RTEMS task is dedicated to the transmission of continuous waveforms at f1. - * - * @param unused is the starting argument of the RTEMS task - * - * The following data packet is sent by this function: - * - TM_LFR_SCIENCE_SBM1_CWF_F1 - * - */ - - rtems_event_set event_out; - rtems_id queue_id; - rtems_status_code status; - - init_header_continuous_wf_table( SID_SBM1_CWF_F1, headerCWF_F1 ); - - status = get_message_queue_id_send( &queue_id ); - if (status != RTEMS_SUCCESSFUL) - { - PRINTF1("in CWF1 *** ERR get_message_queue_id_send %d\n", status) - } - - BOOT_PRINTF("in CWF1 ***\n") - - while(1){ - // wait for an RTEMS_EVENT - rtems_event_receive( RTEMS_EVENT_MODE_SBM1, - RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); - send_waveform_CWF( (volatile int*) ring_node_to_send_cwf_f1->buffer_address, SID_SBM1_CWF_F1, headerCWF_F1, queue_id ); - // launch snapshot extraction if needed - if (extractSWF == true) - { - ring_node_to_send_swf_f1 = ring_node_to_send_cwf_f1; - // launch the snapshot extraction - status = rtems_event_send( Task_id[TASKID_SWBD], RTEMS_EVENT_MODE_SBM1 ); - extractSWF = false; - } - if (swf_f0_ready == true) - { - extractSWF = true; - swf_f0_ready = false; // this step shall be executed only one time - } - if ((swf_f1_ready == true) && (swf_f2_ready == true)) // swf_f1 is ready after the extraction - { - status = rtems_event_send( Task_id[TASKID_WFRM], RTEMS_EVENT_MODE_SBM1 ); - swf_f1_ready = false; - swf_f2_ready = false; - } - } -} - -rtems_task swbd_task(rtems_task_argument argument) -{ - /** This RTEMS task is dedicated to the building of snapshots from different continuous waveforms buffers. - * - * @param unused is the starting argument of the RTEMS task - * - */ - - rtems_event_set event_out; - - BOOT_PRINTF("in SWBD ***\n") - - while(1){ - // wait for an RTEMS_EVENT - rtems_event_receive( RTEMS_EVENT_MODE_SBM1 | RTEMS_EVENT_MODE_SBM2, - RTEMS_WAIT | RTEMS_EVENT_ANY, RTEMS_NO_TIMEOUT, &event_out); - if (event_out == RTEMS_EVENT_MODE_SBM1) - { - build_snapshot_from_ring( ring_node_to_send_swf_f1, 1 ); - swf_f1_ready = true; // the snapshot has been extracted and is ready to be sent - } - else - { - PRINTF1("in SWBD *** unexpected rtems event received %x\n", (int) event_out) - } - } -} - -//****************** -// general functions - -void WFP_init_rings( void ) -{ - // F0 RING - init_waveform_ring( waveform_ring_f0, NB_RING_NODES_F0, wf_snap_f0 ); - // F1 RING - init_waveform_ring( waveform_ring_f1, NB_RING_NODES_F1, wf_snap_f1 ); - // F2 RING - init_waveform_ring( waveform_ring_f2, NB_RING_NODES_F2, wf_snap_f2 ); - // F3 RING - init_waveform_ring( waveform_ring_f3, NB_RING_NODES_F3, wf_cont_f3 ); - - DEBUG_PRINTF1("waveform_ring_f0 @%x\n", (unsigned int) waveform_ring_f0) - DEBUG_PRINTF1("waveform_ring_f1 @%x\n", (unsigned int) waveform_ring_f1) - DEBUG_PRINTF1("waveform_ring_f2 @%x\n", (unsigned int) waveform_ring_f2) - DEBUG_PRINTF1("waveform_ring_f3 @%x\n", (unsigned int) waveform_ring_f3) -} - -void init_waveform_ring(ring_node waveform_ring[], unsigned char nbNodes, volatile int wfrm[] ) -{ - unsigned char i; - - waveform_ring[0].next = (ring_node*) &waveform_ring[ 1 ]; - waveform_ring[0].previous = (ring_node*) &waveform_ring[ nbNodes - 1 ]; - waveform_ring[0].buffer_address = (int) &wfrm[0]; - - waveform_ring[nbNodes-1].next = (ring_node*) &waveform_ring[ 0 ]; - waveform_ring[nbNodes-1].previous = (ring_node*) &waveform_ring[ nbNodes - 2 ]; - waveform_ring[nbNodes-1].buffer_address = (int) &wfrm[ (nbNodes-1) * WFRM_BUFFER ]; - - for(i=1; i> 8); - headerSWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); - headerSWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; - if (i == 6) - { - headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_224 >> 8); - headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_224 ); - headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_224 >> 8); - headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_224 ); - } - else - { - headerSWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_SWF_304 >> 8); - headerSWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_SWF_304 ); - headerSWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_304 >> 8); - headerSWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_304 ); - } - headerSWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; - headerSWF[ i ].pktCnt = DEFAULT_PKTCNT; // PKT_CNT - headerSWF[ i ].pktNr = i+1; // PKT_NR - // DATA FIELD HEADER - headerSWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; - headerSWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type - headerSWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype - headerSWF[ i ].destinationID = TM_DESTINATION_ID_GROUND; - // AUXILIARY DATA HEADER - headerSWF[ i ].time[0] = 0x00; - headerSWF[ i ].time[0] = 0x00; - headerSWF[ i ].time[0] = 0x00; - headerSWF[ i ].time[0] = 0x00; - headerSWF[ i ].time[0] = 0x00; - headerSWF[ i ].time[0] = 0x00; - headerSWF[ i ].sid = sid; - headerSWF[ i ].hkBIA = DEFAULT_HKBIA; - } - - return return_value; -} - -int init_header_continuous_wf_table( unsigned int sid, Header_TM_LFR_SCIENCE_CWF_t *headerCWF ) -{ - unsigned int i; - int return_value; - - return_value = LFR_SUCCESSFUL; - - for (i=0; i> 8); - headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_SBM1_SBM2); - } - else - { - headerCWF[ i ].packetID[0] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST >> 8); - headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); - } - headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; - headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_336 >> 8); - headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_336 ); - headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF >> 8); - headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF ); - headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; - // DATA FIELD HEADER - headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; - headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type - headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype - headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND; - // AUXILIARY DATA HEADER - headerCWF[ i ].sid = sid; - headerCWF[ i ].hkBIA = DEFAULT_HKBIA; - headerCWF[ i ].time[0] = 0x00; - headerCWF[ i ].time[0] = 0x00; - headerCWF[ i ].time[0] = 0x00; - headerCWF[ i ].time[0] = 0x00; - headerCWF[ i ].time[0] = 0x00; - headerCWF[ i ].time[0] = 0x00; - } - - return return_value; -} - -int init_header_continuous_cwf3_light_table( Header_TM_LFR_SCIENCE_CWF_t *headerCWF ) -{ - unsigned int i; - int return_value; - - return_value = LFR_SUCCESSFUL; - - for (i=0; i> 8); - headerCWF[ i ].packetID[1] = (unsigned char) (APID_TM_SCIENCE_NORMAL_BURST); - - headerCWF[ i ].packetSequenceControl[0] = TM_PACKET_SEQ_CTRL_STANDALONE; - headerCWF[ i ].packetLength[0] = (unsigned char) (TM_LEN_SCI_CWF_672 >> 8); - headerCWF[ i ].packetLength[1] = (unsigned char) (TM_LEN_SCI_CWF_672 ); - headerCWF[ i ].blkNr[0] = (unsigned char) (BLK_NR_CWF_SHORT_F3 >> 8); - headerCWF[ i ].blkNr[1] = (unsigned char) (BLK_NR_CWF_SHORT_F3 ); - - headerCWF[ i ].packetSequenceControl[1] = TM_PACKET_SEQ_CNT_DEFAULT; - // DATA FIELD HEADER - headerCWF[ i ].spare1_pusVersion_spare2 = DEFAULT_SPARE1_PUSVERSION_SPARE2; - headerCWF[ i ].serviceType = TM_TYPE_LFR_SCIENCE; // service type - headerCWF[ i ].serviceSubType = TM_SUBTYPE_LFR_SCIENCE; // service subtype - headerCWF[ i ].destinationID = TM_DESTINATION_ID_GROUND; - // AUXILIARY DATA HEADER - headerCWF[ i ].sid = SID_NORM_CWF_F3; - headerCWF[ i ].hkBIA = DEFAULT_HKBIA; - headerCWF[ i ].time[0] = 0x00; - headerCWF[ i ].time[0] = 0x00; - headerCWF[ i ].time[0] = 0x00; - headerCWF[ i ].time[0] = 0x00; - headerCWF[ i ].time[0] = 0x00; - headerCWF[ i ].time[0] = 0x00; - } - - return return_value; -} - -int send_waveform_SWF( volatile int *waveform, unsigned int sid, - Header_TM_LFR_SCIENCE_SWF_t *headerSWF, rtems_id queue_id ) -{ - /** This function sends SWF CCSDS packets (F2, F1 or F0). - * - * @param waveform points to the buffer containing the data that will be send. - * @param sid is the source identifier of the data that will be sent. - * @param headerSWF points to a table of headers that have been prepared for the data transmission. - * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures - * contain information to setup the transmission of the data packets. - * - * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. - * - */ - - unsigned int i; - int ret; - unsigned int coarseTime; - unsigned int fineTime; - rtems_status_code status; - spw_ioctl_pkt_send spw_ioctl_send_SWF; - - spw_ioctl_send_SWF.hlen = TM_HEADER_LEN + 4 + 12; // + 4 is for the protocole extra header, + 12 is for the auxiliary header - spw_ioctl_send_SWF.options = 0; - - ret = LFR_DEFAULT; - - coarseTime = waveform[0]; - fineTime = waveform[1]; - - for (i=0; i<7; i++) // send waveform - { - spw_ioctl_send_SWF.data = (char*) &waveform[ (i * BLK_NR_304 * NB_WORDS_SWF_BLK) + TIME_OFFSET]; - spw_ioctl_send_SWF.hdr = (char*) &headerSWF[ i ]; - // BUILD THE DATA - if (i==6) { - spw_ioctl_send_SWF.dlen = BLK_NR_224 * NB_BYTES_SWF_BLK; - } - else { - spw_ioctl_send_SWF.dlen = BLK_NR_304 * NB_BYTES_SWF_BLK; - } - // SET PACKET SEQUENCE COUNTER - increment_seq_counter_source_id( headerSWF[ i ].packetSequenceControl, sid ); - // SET PACKET TIME - compute_acquisition_time( coarseTime, fineTime, sid, i, headerSWF[ i ].acquisitionTime ); - // - headerSWF[ i ].time[0] = headerSWF[ i ].acquisitionTime[0]; - headerSWF[ i ].time[1] = headerSWF[ i ].acquisitionTime[1]; - headerSWF[ i ].time[2] = headerSWF[ i ].acquisitionTime[2]; - headerSWF[ i ].time[3] = headerSWF[ i ].acquisitionTime[3]; - headerSWF[ i ].time[4] = headerSWF[ i ].acquisitionTime[4]; - headerSWF[ i ].time[5] = headerSWF[ i ].acquisitionTime[5]; - // SEND PACKET - status = rtems_message_queue_send( queue_id, &spw_ioctl_send_SWF, ACTION_MSG_SPW_IOCTL_SEND_SIZE); - if (status != RTEMS_SUCCESSFUL) { - printf("%d-%d, ERR %d\n", sid, i, (int) status); - ret = LFR_DEFAULT; - } - rtems_task_wake_after(TIME_BETWEEN_TWO_SWF_PACKETS); // 300 ms between each packet => 7 * 3 = 21 packets => 6.3 seconds - } - - return ret; -} - -int send_waveform_CWF(volatile int *waveform, unsigned int sid, - Header_TM_LFR_SCIENCE_CWF_t *headerCWF, rtems_id queue_id) -{ - /** This function sends CWF CCSDS packets (F2, F1 or F0). - * - * @param waveform points to the buffer containing the data that will be send. - * @param sid is the source identifier of the data that will be sent. - * @param headerCWF points to a table of headers that have been prepared for the data transmission. - * @param queue_id is the id of the rtems queue to which spw_ioctl_pkt_send structures will be send. The structures - * contain information to setup the transmission of the data packets. - * - * One group of 2048 samples is sent as 7 consecutive packets, 6 packets containing 340 blocks and 8 packets containing 8 blocks. - * - */ - - unsigned int i; - int ret; - unsigned int coarseTime; - unsigned int fineTime; - rtems_status_code status; - spw_ioctl_pkt_send spw_ioctl_send_CWF; - - spw_ioctl_send_CWF.hlen = TM_HEADER_LEN + 4 + 10; // + 4 is for the protocole extra header, + 10 is for the auxiliary header - spw_ioctl_send_CWF.options = 0; - - ret = LFR_DEFAULT; - - coarseTime = waveform[0]; - fineTime = waveform[1]; - - for (i=0; i> 24 ); - localAcquisitionTime[1] = (unsigned char) ( coarseTime >> 16 ); - localAcquisitionTime[2] = (unsigned char) ( coarseTime >> 8 ); - localAcquisitionTime[3] = (unsigned char) ( coarseTime ); - localAcquisitionTime[4] = (unsigned char) ( fineTime >> 8 ); - localAcquisitionTime[5] = (unsigned char) ( fineTime ); - - acquisitionTimeAsLong = ( (unsigned long long int) localAcquisitionTime[0] << 40 ) - + ( (unsigned long long int) localAcquisitionTime[1] << 32 ) - + ( (unsigned long long int) localAcquisitionTime[2] << 24 ) - + ( (unsigned long long int) localAcquisitionTime[3] << 16 ) - + ( (unsigned long long int) localAcquisitionTime[4] << 8 ) - + ( (unsigned long long int) localAcquisitionTime[5] ); - - switch( sid ) - { - case SID_NORM_SWF_F0: - deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 24576. ; - break; - - case SID_NORM_SWF_F1: - deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 4096. ; - break; - - case SID_NORM_SWF_F2: - deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_304 * 65536. / 256. ; - break; - - case SID_SBM1_CWF_F1: - deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 4096. ; - break; - - case SID_SBM2_CWF_F2: - deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ; - break; - - case SID_BURST_CWF_F2: - deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 256. ; - break; - - case SID_NORM_CWF_F3: - deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF_SHORT_F3 * 65536. / 16. ; - break; - - case SID_NORM_CWF_LONG_F3: - deltaT = ( (double ) (pa_lfr_pkt_nr) ) * BLK_NR_CWF * 65536. / 16. ; - break; - - default: - PRINTF1("in compute_acquisition_time *** ERR unexpected sid %d", sid) - deltaT = 0.; - break; - } - - acquisitionTimeAsLong = acquisitionTimeAsLong + (unsigned long long int) deltaT; - // - acquisitionTime[0] = (unsigned char) (acquisitionTimeAsLong >> 40); - acquisitionTime[1] = (unsigned char) (acquisitionTimeAsLong >> 32); - acquisitionTime[2] = (unsigned char) (acquisitionTimeAsLong >> 24); - acquisitionTime[3] = (unsigned char) (acquisitionTimeAsLong >> 16); - acquisitionTime[4] = (unsigned char) (acquisitionTimeAsLong >> 8 ); - acquisitionTime[5] = (unsigned char) (acquisitionTimeAsLong ); - -} - -void build_snapshot_from_ring( ring_node *ring_node_to_send, unsigned char frequencyChannel ) -{ - unsigned int i; - unsigned long long int centerTime_asLong; - unsigned long long int acquisitionTimeF0_asLong; - unsigned long long int acquisitionTime_asLong; - unsigned long long int bufferAcquisitionTime_asLong; - unsigned char *ptr1; - unsigned char *ptr2; - unsigned char *timeCharPtr; - unsigned char nb_ring_nodes; - unsigned long long int frequency_asLong; - unsigned long long int nbTicksPerSample_asLong; - unsigned long long int nbSamplesPart1_asLong; - unsigned long long int sampleOffset_asLong; - - unsigned int deltaT_F0; - unsigned int deltaT_F1; - unsigned long long int deltaT_F2; - - deltaT_F0 = 2731; // (2048. / 24576. / 2.) * 65536. = 2730.667; - deltaT_F1 = 16384; // (2048. / 4096. / 2.) * 65536. = 16384; - deltaT_F2 = 262144; // (2048. / 256. / 2.) * 65536. = 262144; - sampleOffset_asLong = 0x00; - - // (1) get the f0 acquisition time - build_acquisition_time( &acquisitionTimeF0_asLong, current_ring_node_f0 ); - - // (2) compute the central reference time - centerTime_asLong = acquisitionTimeF0_asLong + deltaT_F0; - - // (3) compute the acquisition time of the current snapshot - switch(frequencyChannel) - { - case 1: // 1 is for F1 = 4096 Hz - acquisitionTime_asLong = centerTime_asLong - deltaT_F1; - nb_ring_nodes = NB_RING_NODES_F1; - frequency_asLong = 4096; - nbTicksPerSample_asLong = 16; // 65536 / 4096; - break; - case 2: // 2 is for F2 = 256 Hz - acquisitionTime_asLong = centerTime_asLong - deltaT_F2; - nb_ring_nodes = NB_RING_NODES_F2; - frequency_asLong = 256; - nbTicksPerSample_asLong = 256; // 65536 / 256; - break; - default: - acquisitionTime_asLong = centerTime_asLong; - frequency_asLong = 256; - nbTicksPerSample_asLong = 256; - break; - } - - //**************************************************************************** - // (4) search the ring_node with the acquisition time <= acquisitionTime_asLong - for (i=0; iprevious; - } - - // (5) compute the number of samples to take in the current buffer - sampleOffset_asLong = ((acquisitionTime_asLong - bufferAcquisitionTime_asLong) * frequency_asLong ) >> 16; - nbSamplesPart1_asLong = NB_SAMPLES_PER_SNAPSHOT - sampleOffset_asLong; - PRINTF2("sampleOffset_asLong = %llx, nbSamplesPart1_asLong = %llx\n", sampleOffset_asLong, nbSamplesPart1_asLong) - - // (6) compute the final acquisition time - acquisitionTime_asLong = bufferAcquisitionTime_asLong + - sampleOffset_asLong * nbTicksPerSample_asLong; - - // (7) copy the acquisition time at the beginning of the extrated snapshot - ptr1 = (unsigned char*) &acquisitionTime_asLong; - ptr2 = (unsigned char*) wf_snap_extracted; - ptr2[0] = ptr1[ 0 + 2 ]; - ptr2[1] = ptr1[ 1 + 2 ]; - ptr2[2] = ptr1[ 2 + 2 ]; - ptr2[3] = ptr1[ 3 + 2 ]; - ptr2[6] = ptr1[ 4 + 2 ]; - ptr2[7] = ptr1[ 5 + 2 ]; - - // re set the synchronization bit - timeCharPtr = (unsigned char*) ring_node_to_send->buffer_address; - ptr2[0] = ptr2[0] | (timeCharPtr[0] & 0x80); // [1000 0000] - - if ( (nbSamplesPart1_asLong >= NB_SAMPLES_PER_SNAPSHOT) | (nbSamplesPart1_asLong < 0) ) - { - nbSamplesPart1_asLong = 0; - } - // copy the part 1 of the snapshot in the extracted buffer - for ( i = 0; i < (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i++ ) - { - wf_snap_extracted[i + TIME_OFFSET] = - ((int*) ring_node_to_send->buffer_address)[i + (sampleOffset_asLong * NB_WORDS_SWF_BLK) + TIME_OFFSET]; - } - // copy the part 2 of the snapshot in the extracted buffer - ring_node_to_send = ring_node_to_send->next; - for ( i = (nbSamplesPart1_asLong * NB_WORDS_SWF_BLK); i < (NB_SAMPLES_PER_SNAPSHOT * NB_WORDS_SWF_BLK); i++ ) - { - wf_snap_extracted[i + TIME_OFFSET] = - ((int*) ring_node_to_send->buffer_address)[(i-(nbSamplesPart1_asLong * NB_WORDS_SWF_BLK)) + TIME_OFFSET]; - } -} - -void build_acquisition_time( unsigned long long int *acquisitionTimeAslong, ring_node *current_ring_node ) -{ - unsigned char *acquisitionTimeCharPtr; - - acquisitionTimeCharPtr = (unsigned char*) current_ring_node->buffer_address; - - *acquisitionTimeAslong = 0x00; - *acquisitionTimeAslong = ( (unsigned long long int) (acquisitionTimeCharPtr[0] & 0x7f) << 40 ) // [0111 1111] mask the synchronization bit - + ( (unsigned long long int) acquisitionTimeCharPtr[1] << 32 ) - + ( (unsigned long long int) acquisitionTimeCharPtr[2] << 24 ) - + ( (unsigned long long int) acquisitionTimeCharPtr[3] << 16 ) - + ( (unsigned long long int) acquisitionTimeCharPtr[6] << 8 ) - + ( (unsigned long long int) acquisitionTimeCharPtr[7] ); -} - -//************** -// wfp registers -void reset_wfp_burst_enable(void) -{ - /** This function resets the waveform picker burst_enable register. - * - * The burst bits [f2 f1 f0] and the enable bits [f3 f2 f1 f0] are set to 0. - * - */ - - waveform_picker_regs->run_burst_enable = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0 -} - -void reset_wfp_status( void ) -{ - /** This function resets the waveform picker status register. - * - * All status bits are set to 0 [new_err full_err full]. - * - */ - - waveform_picker_regs->status = 0x00; // burst f2, f1, f0 enable f3, f2, f1, f0 -} - -void reset_waveform_picker_regs(void) -{ - /** This function resets the waveform picker module registers. - * - * The registers affected by this function are located at the following offset addresses: - * - 0x00 data_shaping - * - 0x04 run_burst_enable - * - 0x08 addr_data_f0 - * - 0x0C addr_data_f1 - * - 0x10 addr_data_f2 - * - 0x14 addr_data_f3 - * - 0x18 status - * - 0x1C delta_snapshot - * - 0x20 delta_f0 - * - 0x24 delta_f0_2 - * - 0x28 delta_f1 - * - 0x2c delta_f2 - * - 0x30 nb_data_by_buffer - * - 0x34 nb_snapshot_param - * - 0x38 start_date - * - 0x3c nb_word_in_buffer - * - */ - - set_wfp_data_shaping(); // 0x00 *** R1 R0 SP1 SP0 BW - reset_wfp_burst_enable(); // 0x04 *** [run *** burst f2, f1, f0 *** enable f3, f2, f1, f0 ] - waveform_picker_regs->addr_data_f0 = current_ring_node_f0->buffer_address; // 0x08 - waveform_picker_regs->addr_data_f1 = current_ring_node_f1->buffer_address; // 0x0c - waveform_picker_regs->addr_data_f2 = current_ring_node_f2->buffer_address; // 0x10 - waveform_picker_regs->addr_data_f3 = current_ring_node_f3->buffer_address; // 0x14 - reset_wfp_status(); // 0x18 - // - set_wfp_delta_snapshot(); // 0x1c - set_wfp_delta_f0_f0_2(); // 0x20, 0x24 - set_wfp_delta_f1(); // 0x28 - set_wfp_delta_f2(); // 0x2c - DEBUG_PRINTF1("delta_snapshot %x\n", waveform_picker_regs->delta_snapshot) - DEBUG_PRINTF1("delta_f0 %x\n", waveform_picker_regs->delta_f0) - DEBUG_PRINTF1("delta_f0_2 %x\n", waveform_picker_regs->delta_f0_2) - DEBUG_PRINTF1("delta_f1 %x\n", waveform_picker_regs->delta_f1) - DEBUG_PRINTF1("delta_f2 %x\n", waveform_picker_regs->delta_f2) - // 2688 = 8 * 336 - waveform_picker_regs->nb_data_by_buffer = 0xa7f; // 0x30 *** 2688 - 1 => nb samples -1 - waveform_picker_regs->snapshot_param = 0xa80; // 0x34 *** 2688 => nb samples - waveform_picker_regs->start_date = 0x00; // 0x38 - waveform_picker_regs->nb_word_in_buffer = 0x1f82; // 0x3c *** 2688 * 3 + 2 = 8066 -} - -void set_wfp_data_shaping( void ) -{ - /** This function sets the data_shaping register of the waveform picker module. - * - * The value is read from one field of the parameter_dump_packet structure:\n - * bw_sp0_sp1_r0_r1 - * - */ - - unsigned char data_shaping; - - // get the parameters for the data shaping [BW SP0 SP1 R0 R1] in sy_lfr_common1 and configure the register - // waveform picker : [R1 R0 SP1 SP0 BW] - - data_shaping = parameter_dump_packet.bw_sp0_sp1_r0_r1; - - waveform_picker_regs->data_shaping = - ( (data_shaping & 0x10) >> 4 ) // BW - + ( (data_shaping & 0x08) >> 2 ) // SP0 - + ( (data_shaping & 0x04) ) // SP1 - + ( (data_shaping & 0x02) << 2 ) // R0 - + ( (data_shaping & 0x01) << 4 ); // R1 -} - -void set_wfp_burst_enable_register( unsigned char mode ) -{ - /** This function sets the waveform picker burst_enable register depending on the mode. - * - * @param mode is the LFR mode to launch. - * - * The burst bits shall be before the enable bits. - * - */ - - // [0000 0000] burst f2, f1, f0 enable f3 f2 f1 f0 - // the burst bits shall be set first, before the enable bits - switch(mode) { - case(LFR_MODE_NORMAL): - waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enable - waveform_picker_regs->run_burst_enable = 0x0f; // [0000 1111] enable f3 f2 f1 f0 - break; - case(LFR_MODE_BURST): - waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled -// waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x04; // [0100] enable f2 - waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0c; // [1100] enable f3 AND f2 - break; - case(LFR_MODE_SBM1): - waveform_picker_regs->run_burst_enable = 0x20; // [0010 0000] f1 burst enabled - waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0 - break; - case(LFR_MODE_SBM2): - waveform_picker_regs->run_burst_enable = 0x40; // [0100 0000] f2 burst enabled - waveform_picker_regs->run_burst_enable = waveform_picker_regs->run_burst_enable | 0x0f; // [1111] enable f3 f2 f1 f0 - break; - default: - waveform_picker_regs->run_burst_enable = 0x00; // [0000 0000] no burst enabled, no waveform enabled - break; - } -} - -void set_wfp_delta_snapshot( void ) -{ - /** This function sets the delta_snapshot register of the waveform picker module. - * - * The value is read from two (unsigned char) of the parameter_dump_packet structure: - * - sy_lfr_n_swf_p[0] - * - sy_lfr_n_swf_p[1] - * - */ - - unsigned int delta_snapshot; - unsigned int delta_snapshot_in_T2; - - delta_snapshot = parameter_dump_packet.sy_lfr_n_swf_p[0]*256 - + parameter_dump_packet.sy_lfr_n_swf_p[1]; - - delta_snapshot_in_T2 = delta_snapshot * 256; - waveform_picker_regs->delta_snapshot = delta_snapshot_in_T2 - 1; // max 4 bytes -} - -void set_wfp_delta_f0_f0_2( void ) -{ - unsigned int delta_snapshot; - unsigned int nb_samples_per_snapshot; - float delta_f0_in_float; - - delta_snapshot = waveform_picker_regs->delta_snapshot; - nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1]; - delta_f0_in_float =nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 24576.) * 256.; - - waveform_picker_regs->delta_f0 = delta_snapshot - floor( delta_f0_in_float ); - waveform_picker_regs->delta_f0_2 = 0x7; // max 7 bits -} - -void set_wfp_delta_f1( void ) -{ - unsigned int delta_snapshot; - unsigned int nb_samples_per_snapshot; - float delta_f1_in_float; - - delta_snapshot = waveform_picker_regs->delta_snapshot; - nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1]; - delta_f1_in_float = nb_samples_per_snapshot / 2. * ( 1. / 256. - 1. / 4096.) * 256.; - - waveform_picker_regs->delta_f1 = delta_snapshot - floor( delta_f1_in_float ); -} - -void set_wfp_delta_f2() -{ - unsigned int delta_snapshot; - unsigned int nb_samples_per_snapshot; - - delta_snapshot = waveform_picker_regs->delta_snapshot; - nb_samples_per_snapshot = parameter_dump_packet.sy_lfr_n_swf_l[0] * 256 + parameter_dump_packet.sy_lfr_n_swf_l[1]; - - waveform_picker_regs->delta_f2 = delta_snapshot - nb_samples_per_snapshot / 2; -} - -//***************** -// local parameters - -void increment_seq_counter_source_id( unsigned char *packet_sequence_control, unsigned int sid ) -{ - /** This function increments the parameter "sequence_cnt" depending on the sid passed in argument. - * - * @param packet_sequence_control is a pointer toward the parameter sequence_cnt to update. - * @param sid is the source identifier of the packet being updated. - * - * REQ-LFR-SRS-5240 / SSS-CP-FS-590 - * The sequence counters shall wrap around from 2^14 to zero. - * The sequence counter shall start at zero at startup. - * - * REQ-LFR-SRS-5239 / SSS-CP-FS-580 - * All TM_LFR_SCIENCE_ packets are sent to ground, i.e. destination id = 0 - * - */ - - unsigned short *sequence_cnt; - unsigned short segmentation_grouping_flag; - unsigned short new_packet_sequence_control; - rtems_mode initial_mode_set; - rtems_mode current_mode_set; - rtems_status_code status; - - //****************************************** - // CHANGE THE MODE OF THE CALLING RTEMS TASK - status = rtems_task_mode( RTEMS_NO_PREEMPT, RTEMS_PREEMPT_MASK, &initial_mode_set ); - - if ( (sid == SID_NORM_SWF_F0) || (sid == SID_NORM_SWF_F1) || (sid == SID_NORM_SWF_F2) - || (sid == SID_NORM_CWF_F3) || (sid == SID_NORM_CWF_LONG_F3) - || (sid == SID_BURST_CWF_F2) - || (sid == SID_NORM_ASM_F0) || (sid == SID_NORM_ASM_F1) || (sid == SID_NORM_ASM_F2) - || (sid == SID_NORM_BP1_F0) || (sid == SID_NORM_BP1_F1) || (sid == SID_NORM_BP1_F2) - || (sid == SID_NORM_BP2_F0) || (sid == SID_NORM_BP2_F1) || (sid == SID_NORM_BP2_F2) - || (sid == SID_BURST_BP1_F0) || (sid == SID_BURST_BP2_F0) - || (sid == SID_BURST_BP1_F1) || (sid == SID_BURST_BP2_F1) ) - { - sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_NORMAL_BURST; - } - else if ( (sid ==SID_SBM1_CWF_F1) || (sid ==SID_SBM2_CWF_F2) - || (sid == SID_SBM1_BP1_F0) || (sid == SID_SBM1_BP2_F0) - || (sid == SID_SBM2_BP1_F0) || (sid == SID_SBM2_BP2_F0) - || (sid == SID_SBM2_BP1_F1) || (sid == SID_SBM2_BP2_F1) ) - { - sequence_cnt = (unsigned short *) &sequenceCounters_SCIENCE_SBM1_SBM2; - } - else - { - sequence_cnt = (unsigned short *) NULL; - PRINTF1("in increment_seq_counter_source_id *** ERR apid_destid %d not known\n", sid) - } - - if (sequence_cnt != NULL) - { - segmentation_grouping_flag = TM_PACKET_SEQ_CTRL_STANDALONE << 8; - *sequence_cnt = (*sequence_cnt) & 0x3fff; - - new_packet_sequence_control = segmentation_grouping_flag | (*sequence_cnt) ; - - packet_sequence_control[0] = (unsigned char) (new_packet_sequence_control >> 8); - packet_sequence_control[1] = (unsigned char) (new_packet_sequence_control ); - - // increment the sequence counter - if ( *sequence_cnt < SEQ_CNT_MAX) - { - *sequence_cnt = *sequence_cnt + 1; - } - else - { - *sequence_cnt = 0; - } - } - - //*********************************** - // RESET THE MODE OF THE CALLING TASK - status = rtems_task_mode( initial_mode_set, RTEMS_PREEMPT_MASK, ¤t_mode_set ); -}