view src/cs/riviera/support/exception.h @ 600:8f50b202e81f

board preprocessor conditionals: prep for more FC hw in the future This change eliminates the CONFIG_TARGET_FCDEV3B preprocessor symbol and all preprocessor conditionals throughout the code base that tested for it, replacing them with CONFIG_TARGET_FCFAM or CONFIG_TARGET_FCMODEM. These new symbols are specified as follows: CONFIG_TARGET_FCFAM is intended to cover all hardware designs created by Mother Mychaela under the FreeCalypso trademark. This family will include modem products (repackagings of the FCDEV3B, possibly with RFFE or even RF transceiver changes), and also my desired FreeCalypso handset product. CONFIG_TARGET_FCMODEM is intended to cover all FreeCalypso modem products (which will be firmware-compatible with the FCDEV3B if they use TI Rita transceiver, or will require a different fw build if we switch to one of Silabs Aero transceivers), but not the handset product. Right now this CONFIG_TARGET_FCMODEM preprocessor symbol is used to conditionalize everything dealing with MCSI. At the present moment the future of FC hardware evolution is still unknown: it is not known whether we will ever have any beyond-FCDEV3B hardware at all (contingent on uncertain funding), and if we do produce further FC hardware designs, it is not known whether they will retain the same FIC modem core (triband), if we are going to have a quadband design that still retains the classic Rita transceiver, or if we are going to switch to Silabs Aero II or some other transceiver. If we produce a quadband modem that still uses Rita, it will run exactly the same fw as the FCDEV3B thanks to the way we define TSPACT signals for the RF_FAM=12 && CONFIG_TARGET_FCFAM combination, and the current fcdev3b build target will be renamed to fcmodem. OTOH, if that putative quadband modem will be Aero-based, then it will require a different fw build target, the fcdev3b target will stay as it is, and the two targets will both define CONFIG_TARGET_FCFAM and CONFIG_TARGET_FCMODEM, but will have different RF_FAM numbers. But no matter which way we are going to evolve, it is not right to have conditionals on CONFIG_TARGET_FCDEV3B in places like ACI, and the present change clears the way for future evolution.
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 01 Apr 2019 01:05:24 +0000
parents 945cf7f506b2
children
line wrap: on
line source

/*
 ******************************
 * 
 *
 * Initialial version: Laurent Deniau, Laurent.Deniau@cern.ch
 *
 * For more information, please see the paper:
 * http://cern.ch/Laurent.Deniau/html/oopc/exception.html
 * 
 * -----------------------------------------------------------
 *
 * Strong rework and adaption to riviera by Christophe Favergeon
 *
 ******************************
 */

#ifndef RVF_EXCEPTION_H
#define RVF_EXCEPTION_H

#include "rvf/rvf_api.h"
#include "rvf/rvf_target.h"

#include <string.h>



//#ifndef __STDC__
//#  error "exception.h needs ISO C compiler to work properly"
//#endif

#include <setjmp.h>

typedef enum K_RVF_EXCEPTIONS { E_invalid=1, E_not_enough_memory,E_unknown } T_RVF_EXCEPTIONS; 

typedef void (*T_RVF_RELEASE_PROTECTED_POINTER)(void *p);

/*
  choose context savings
*/

#define rvf_save_context_buffer_(context)         setjmp(context)
#define rvf_restore_context_buffer_(context, val) longjmp(context, val)

/*
  some hidden types used to handle exceptions
*/

/* type of stack of protected pointer */
struct _protectedPtr_ {
  struct _protectedPtr_ *next;
  struct _protectedPtr_ *previous;
  void *ptr;
  T_RVF_RELEASE_PROTECTED_POINTER func;
};

/* type of stack of exception */
struct _exceptionContext_ {
  struct _exceptionContext_ *next;
  struct _protectedPtr_ *stack;
  jmp_buf context;
};

extern struct _exceptionContext_ *const _returnExceptionContext_[MAX_RVF_TASKS];
extern struct _exceptionContext_ *_currentExceptionContext_[MAX_RVF_TASKS];

/* exception keywords */
#define try								 \
  do {									 \
	struct _exceptionContext_ _localExceptionContext_ ;\
	memset(&_localExceptionContext_,0,sizeof(struct _exceptionContext_));\
    _localExceptionContext_.next=_currentExceptionContext_[rvf_get_taskid()];\
    _currentExceptionContext_[rvf_get_taskid()] = &_localExceptionContext_;		 \
    do {								 \
      int const exception =						 \
              rvf_save_context_buffer_(_currentExceptionContext_[rvf_get_taskid()]->context); \
      if (!exception) {

#define catch(except)							\
      } else if ((int)(except) == exception) {				\
        _currentExceptionContext_[rvf_get_taskid()] = _currentExceptionContext_[rvf_get_taskid()]->next;

#define catch_any							\
      } else {								\
        _currentExceptionContext_[rvf_get_taskid()] = _currentExceptionContext_[rvf_get_taskid()]->next;

#define endtry								\
      }									\
    } while(0);								\
    if (_currentExceptionContext_[rvf_get_taskid()] == &_localExceptionContext_) {	\
      rvf_forget_protected_ptr();\
      _currentExceptionContext_[rvf_get_taskid()] = _currentExceptionContext_[rvf_get_taskid()]->next;	\
    }									\
  } while(0)

#define rethrow throw(exception)
#define break_try break

/*
#define return_try(...)						\
  do {								\
    _currentExceptionContext_ = _returnExceptionContext_;	\
    return __VA_ARGS__;						\
  } while(0)
*/

#define throw(except) _exceptionThrow_((int)(except))


/*
  extern declarations
*/

extern void _exceptionThrow_(int except);

extern void rvf_forget_protected_ptr();
extern void rvf_protect_pointer(T_RVF_MB_ID mb_id,void *p,T_RVF_RELEASE_PROTECTED_POINTER func);

#define RVF_PROTECT(bank,p) rvf_protect_pointer(bank,p,(T_RVF_RELEASE_PROTECTED_POINTER)rvf_free_buf)

#define THROW_IF_ERROR(err) if (err!=0) throw(E_unknown)
#define THROW_IF_NULL(p) if (p==NULL) throw(E_not_enough_memory)
#define THROW_IF_YELLOW(b,p) if ((p==NULL) || (rvf_get_mb_status(b)==RVF_YELLOW)) throw(E_not_enough_memory)
#endif