view src/g23m-fad/app/app_util.c @ 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 90eb61ecd093
children
line wrap: on
line source

/* 
+------------------------------------------------------------------------------
|  File:       app_cmds.c
+------------------------------------------------------------------------------
|  Copyright 2004 Texas Instruments Berlin, AG 
|                 All rights reserved. 
| 
|                 This file is confidential and a trade secret of Texas 
|                 Instruments Berlin, AG 
|                 The receipt of or possession of this file does not convey 
|                 any rights to reproduce or disclose its contents or to 
|                 manufacture, use, or sell anything it may describe, in 
|                 whole, or in part, without the specific written consent of 
|                 Texas Instruments Berlin, AG. 
+----------------------------------------------------------------------------- 
|  Purpose :  Utilities and stuff common for the different test parts
+----------------------------------------------------------------------------- 
*/ 


#define APP_UTIL_C

/*==== INCLUDES =============================================================*/

#include "app_util.h"

#include <string.h>             /* String functions, e. g. strncpy(). */
#include <ctype.h>
#include <stdlib.h>
#ifndef _SIMULATION_
#endif /* _SIMULATION_ */
#include "vsi.h"                /* A lot of macros. */
#ifndef _SIMULATION_
#include "custom.h"
#include "gsm.h"                /* A lot of macros. */
#include "tools.h"              /* Common tools. */
#endif /* _SIMULATION_ */

/*==== Local defines =========================================================*/

#define MAX_TOKENS 4            /* Maximum number of tokens to search for;
                                 * first token is the command name, last token
                                 * the rest of the line. */
/*==== Local functions =======================================================*/

static char **tokenize_cmd(char *command)
{
  /* Three tokens will be enough: command name, parameter 1, parameter 2. Empty
   * tokens will be NULL. */
  static char *cmd_token[MAX_TOKENS] ;
  char *cur ;                   /* Pointer to current character. */
  
  int cur_tok ;                 /* Current token number. */

  
  cur = command ;
  cur_tok = 0 ;
  do
  {
    while (isspace(*cur))       /* FALSE also for NUl character. */
    {
        cur++ ;                 /* Skip whitespace. */
    }
    if (!*cur)                  /* String terminated. */
    {
      cmd_token[cur_tok] = 0 ;   /* No token here and stop. */
      break ;
    }
    cmd_token[cur_tok++] = cur ;
    cmd_token[cur_tok] = 0 ;
    while (*cur && !isspace(*cur))
    {
      cur++ ;                   /* Skip non-whitespace. */
    }
    if (*cur) *cur++ = 0 ;      /* Zero-terminate token if not end of string. */
  }
  while (cur_tok < MAX_TOKENS) ;

  return cmd_token ;
}

char *string_to_lower(char *s)
{
  char *tmp ;

  for (tmp = s; *tmp; tmp++)
  {
    *tmp = tolower(*tmp) ;
  }
  return s ;
}

/*==== Exported functions ====================================================*/

/** Parse a command and execute it if it is valid. Return appropriate error
 * message if the command is invalid or fails.
 * 
 * @param command    command line to execute
 * @return an error message or NULL on success
 */
char *app_handle_command(char *command, app_cmd_entry_t * cmd_table)
{
  char **tokened_cmd ;          /* Tokenized command line. */
  int cmd_index ;

  TRACE_FUNCTION("app_handle_command()") ;

  tokened_cmd = tokenize_cmd(command) ;
  if (!tokened_cmd[0])
  {
    return "ERROR: empty command line" ;
  }

  string_to_lower(tokened_cmd[0]) ; /* convert to lower char */
  cmd_index = 0 ;
  while (cmd_table[cmd_index].cmd_name)
  {
    if (!strcmp(tokened_cmd[0], cmd_table[cmd_index].cmd_name))
    {
      TRACE_EVENT_P4("Call %s(%s, %s, %s)", cmd_table[cmd_index].cmd_name,
                     tokened_cmd[1] ? tokened_cmd[1] : "(null)",
                     tokened_cmd[2] ? tokened_cmd[2] : "(null)",
                     tokened_cmd[3] ? tokened_cmd[3] : "(null)") ;
      return cmd_table[cmd_index].cmd_func(&cmd_table[cmd_index],
                                           tokened_cmd[1],
                                           tokened_cmd[2],
                                           tokened_cmd[3],
                                           cmd_table[cmd_index].core_func) ;
    }
    cmd_index++ ;
  }
  return "ERROR: command not recognized" ;
}



/**
 * Convert a string into an integer.
 * If not possibly, assume the default value.
 */
int get_item(char *param, int default_item, BOOL can_null)
{
  U32 item = default_item;
  if (param)
  {
    item = atoi(param);
    if (!can_null AND item EQ 0)
    {
      TRACE_EVENT("WARNING: item is 0, setting to default");
      item = default_item;
    }
  }
  return item;
}


/* This is onoy for the case that the macro UI_TRACE() is undefined, in which
 * case the linker bemoans it as missing. */

/* EOF */