Пример #1
0
static int f_dbg() {
  enum state {
    NONE, LEVEL, ENABLE, DISABLE
  } st = NONE;
  int a;
  if (_argc == 0) {
    print_debug_setting();
    return 0;
  }
  for (a = 0; a < _argc; a++) {
    u32_t f = 0;
    char *s = (char*) _args[a];
    if (!IS_STRING(s)) {
      return -1;
    }
    if (strcmp("level", s) == 0) {
      st = LEVEL;
    } else if (strcmp("enable", s) == 0) {
      st = ENABLE;
    } else if (strcmp("disable", s) == 0) {
      st = DISABLE;
    } else {
      switch (st) {
      case LEVEL:
        if (strcmp("dbg", s) == 0) {
          SYS_dbg_level(D_DEBUG);
        } else if (strcmp("info", s) == 0) {
          SYS_dbg_level(D_INFO);
        } else if (strcmp("warn", s) == 0) {
          SYS_dbg_level(D_WARN);
        } else if (strcmp("fatal", s) == 0) {
          SYS_dbg_level(D_FATAL);
        } else {
          return -1;
        }
        break;
      case ENABLE:
      case DISABLE: {
        int d;
        for (d = 0; f == 0 && d < sizeof(DBG_BIT_NAME) / sizeof(const char*);
            d++) {
          if (strcmp(DBG_BIT_NAME[d], s) == 0) {
            f = (1 << d);
          }
        }
        if (strcmp("all", s) == 0) {
          f = D_ANY;
        }
        if (f == 0) {
          return -1;
        }
        if (st == ENABLE) {
          SYS_dbg_mask_enable(f);
        } else {
          SYS_dbg_mask_disable(f);
        }
        break;
      }
      default:
        return -1;
      }
    }
  }
  print_debug_setting();
  return 0;
}
Пример #2
0
static int cli_dbg(u32_t argc, ...) {
    enum state {
        NONE, LEVEL, ENABLE, DISABLE
    } st = NONE;
    if (argc == 0) {
        print_debug_setting();
        return 0;
    }
    va_list va;
    va_start(va, argc);
    u32_t i;
    for (i = 0; i < argc; i++) {
        char *s = va_arg(va, char *);
        u32_t f = 0;
        if (!IS_STRING(s)) {
            return -1;
        }
        if (strcmp("level", s) == 0) {
            st = LEVEL;
        } else if (strcmp("on", s) == 0) {
            st = ENABLE;
        } else if (strcmp("off", s) == 0) {
            st = DISABLE;
        } else {
            switch (st) {
            case LEVEL:
                if (strcmp("dbg", s) == 0) {
                    SYS_dbg_level(D_DEBUG);
                } else if (strcmp("info", s) == 0) {
                    SYS_dbg_level(D_INFO);
                } else if (strcmp("warn", s) == 0) {
                    SYS_dbg_level(D_WARN);
                } else if (strcmp("fatal", s) == 0) {
                    SYS_dbg_level(D_FATAL);
                } else {
                    return -1;
                }
                break;
            case ENABLE:
            case DISABLE: {
                int d;
                for (d = 0; f == 0 && d < sizeof(DBG_BIT_NAME) / sizeof(const char*);
                        d++) {
                    if (strcmp(DBG_BIT_NAME[d], s) == 0) {
                        f = (1 << d);
                    }
                }
                if (strcmp("all", s) == 0) {
                    f = D_ANY;
                }
                if (f == 0) {
                    return -1;
                }
                if (st == ENABLE) {
                    SYS_dbg_mask_enable(f);
                } else {
                    SYS_dbg_mask_disable(f);
                }
                break;
            }
            default:
                return -1;
            }
        }
    }
    print_debug_setting();
    va_end(va);
    return CLI_OK;
}