Exemplo n.º 1
0
static void ftdi_execute_reset(struct jtag_command *cmd)
{
    DEBUG_JTAG_IO("reset trst: %i srst %i",
                  cmd->cmd.reset->trst, cmd->cmd.reset->srst);

    if (cmd->cmd.reset->trst == 1
            || (cmd->cmd.reset->srst
                && (jtag_get_reset_config() & RESET_SRST_PULLS_TRST)))
        tap_set_state(TAP_RESET);

    struct signal *trst = find_signal_by_name("nTRST");
    if (trst && cmd->cmd.reset->trst == 1) {
        ftdi_set_signal(trst, '0');
    } else if (trst && cmd->cmd.reset->trst == 0) {
        if (jtag_get_reset_config() & RESET_TRST_OPEN_DRAIN)
            ftdi_set_signal(trst, 'z');
        else
            ftdi_set_signal(trst, '1');
    }

    struct signal *srst = find_signal_by_name("nSRST");
    if (srst && cmd->cmd.reset->srst == 1) {
        ftdi_set_signal(srst, '0');
    } else if (srst && cmd->cmd.reset->srst == 0) {
        if (jtag_get_reset_config() & RESET_SRST_PUSH_PULL)
            ftdi_set_signal(srst, '1');
        else
            ftdi_set_signal(srst, 'z');
    }

    DEBUG_JTAG_IO("trst: %i, srst: %i",
                  cmd->cmd.reset->trst, cmd->cmd.reset->srst);
}
Exemplo n.º 2
0
static int gpio_command_get(struct host_cmd_handler_args *args)
{
	const struct ec_params_gpio_get_v1 *p_v1 = args->params;
	struct ec_response_gpio_get_v1 *r_v1 = args->response;
	int i, len;

	if (args->version == 0) {
		const struct ec_params_gpio_get *p = args->params;
		struct ec_response_gpio_get *r = args->response;

		i = find_signal_by_name(p->name);
		if (i == GPIO_COUNT)
			return EC_RES_ERROR;

		r->val = gpio_get_level(i);
		args->response_size = sizeof(struct ec_response_gpio_get);
		return EC_RES_SUCCESS;
	}

	switch (p_v1->subcmd) {
	case EC_GPIO_GET_BY_NAME:
		i = find_signal_by_name(p_v1->get_value_by_name.name);
		if (i == GPIO_COUNT)
			return EC_RES_ERROR;

		r_v1->get_value_by_name.val = gpio_get_level(i);
		args->response_size = sizeof(r_v1->get_value_by_name);
		break;
	case EC_GPIO_GET_COUNT:
		r_v1->get_count.val = GPIO_COUNT;
		args->response_size = sizeof(r_v1->get_count);
		break;
	case EC_GPIO_GET_INFO:
		if (p_v1->get_info.index >= GPIO_COUNT)
			return EC_RES_ERROR;

		i = p_v1->get_info.index;
		len = strlen(gpio_get_name(i));
		memcpy(r_v1->get_info.name, gpio_get_name(i), len+1);
		r_v1->get_info.val = gpio_get_level(i);
		r_v1->get_info.flags = gpio_get_default_flags(i);
		args->response_size = sizeof(r_v1->get_info);
		break;
	default:
		return EC_RES_INVALID_PARAM;
	}

	return EC_RES_SUCCESS;

}
Exemplo n.º 3
0
static int signal_cmd_throw(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    int sig = SIGINT;

    if (argc == 1) {
        if ((sig = find_signal_by_name(interp, Jim_String(argv[0]))) < 0) {
            return JIM_ERR;
        }
    }

    /* If the signal is ignored (blocked) ... */
    if (siginfo[sig].status == SIGNAL_ACTION_IGNORE) {
        sigsblocked |= sig_to_bit(sig);
        return JIM_OK;
    }

    /* Just set the signal */
    interp->sigmask |= sig_to_bit(sig);

    /* Set the canonical name of the signal as the result */
    Jim_SetResultString(interp, Jim_SignalId(sig), -1);

    /* And simply say we caught the signal */
    return JIM_SIGNAL;
}
Exemplo n.º 4
0
static int SignalKillCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
                        Jsi_Value **ret, Jsi_Func *funcPtr)
{
    Jsi_Value *vpid = Jsi_ValueArrayIndex(interp, args, 0);
    Jsi_Value *sv = Jsi_ValueArrayIndex(interp, args, 1);
    Jsi_Number npid;
    int rc, sigNum = SIGTERM;
    if (Jsi_GetNumberFromValue(interp, vpid, &npid) != JSI_OK) {
        Jsi_LogError("bad pid");
        return JSI_ERROR;
    }
    if (sv) {
        if (sv->vt == JSI_VT_NUMBER)
            sigNum = (int)sv->d.num;
        else {
            char *ts = Jsi_ValueArrayIndexToStr(interp, args, 1, NULL);
            if ((sigNum = find_signal_by_name(interp, ts)) < 0) {
                Jsi_LogError("bad signal: %s", ts);
                return JSI_ERROR;
            }
        }
    }
    if (sigNum < 0 || sigNum >= MAX_SIGNALS) {
        Jsi_LogError("bad signal: %d", sigNum);
        return JSI_ERROR;
    }
    rc = kill((int)npid, sigNum);
    if (rc != 0) {
        Jsi_LogError("kill failure");
        return JSI_ERROR;
    }
    return JSI_OK;
}
Exemplo n.º 5
0
static int command_gpio_get(int argc, char **argv)
{
	int changed, v, i;

	/* If a signal is specified, print only that one */
	if (argc == 2) {
		i = find_signal_by_name(argv[1]);
		if (i == GPIO_COUNT)
			return EC_ERROR_PARAM1;
		v = gpio_get_level(i);
		changed = last_val_changed(i, v);
		ccprintf("  %d%c %s\n", v, (changed ? '*' : ' '),
			 gpio_get_name(i));

		return EC_SUCCESS;
	}

	/* Otherwise print them all */
	for (i = 0; i < GPIO_COUNT; i++) {
		if (!gpio_is_implemented(i))
			continue;  /* Skip unsupported signals */

		v = gpio_get_level(i);
		changed = last_val_changed(i, v);
		ccprintf("  %d%c %s\n", v, (changed ? '*' : ' '),
			 gpio_get_name(i));

		/* Flush console to avoid truncating output */
		cflush();
	}

	return EC_SUCCESS;
}
Exemplo n.º 6
0
static int command_gpio_set(int argc, char **argv)
{
#ifdef CONFIG_CMD_GPIO_EXTENDED
	int gpio;
	int flags = 0;
	int af = -1;
	char *e;

	if (argc < 3)
		return EC_ERROR_PARAM_COUNT;

	gpio = find_signal_by_name(argv[1]);
	if (gpio == GPIO_COUNT)
		return EC_ERROR_PARAM1;

	if (strcasecmp(argv[2], "IN") == 0)
		flags = GPIO_INPUT;
	else if (strcasecmp(argv[2], "1") == 0)
		flags = GPIO_OUT_HIGH;
	else if (strcasecmp(argv[2], "0") == 0)
		flags = GPIO_OUT_LOW;
	else if (strcasecmp(argv[2], "A") == 0)
		flags = GPIO_ANALOG;
	else if (strcasecmp(argv[2], "ALT") == 0) {
		if (argc >= 4) {
			af = strtoi(argv[3], &e, 0);
			if (*e || af < 0 || af > 5)
				return EC_ERROR_PARAM2;
		}
		flags = GPIO_ALTERNATE;
	} else
		return EC_ERROR_PARAM2;

	/* Update alt function if requested. */
	if (af >= 0) {
		const struct gpio_info *g = gpio_list + gpio;

		gpio_set_alternate_function(g->port, g->mask, af);
	}
	/* Update GPIO flags. */
	gpio_set_flags(gpio, flags);
#else
	char *e;
	int v;

	if (argc < 3)
		return EC_ERROR_PARAM_COUNT;

	v = strtoi(argv[2], &e, 0);
	if (*e)
		return EC_ERROR_PARAM2;

	if (set(argv[1], v) != EC_SUCCESS)
		return EC_ERROR_PARAM1;
#endif
	return EC_SUCCESS;
}
Exemplo n.º 7
0
static int ftdi_execute_swd_seq(struct jtag_command *cmd)
{
	struct signal *swdoe = find_signal_by_name("SWDOE");
	int retval = 0;

	DEBUG_JTAG_IO("SWD sending raw sequence, length %d bits",
		      cmd->cmd.swd_seq->num_bits);
	retval |= ftdi_set_signal(swdoe, '1');
	retval |= mpsse_clock_data_out(mpsse_ctx,
				       cmd->cmd.swd_seq->bits, 0,
				       cmd->cmd.swd_seq->num_bits,
				       SWD_MODE);
	return (retval);
}
Exemplo n.º 8
0
static int SignalCallbackCmd(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
    Jsi_Value **ret, Jsi_Func *funcPtr)
{
    int isNew;
    Jsi_Event *ev;
    uint id;
    int sigNum;
    Jsi_Value *fv = Jsi_ValueArrayIndex(interp, args, 0);
    Jsi_Value *sv = Jsi_ValueArrayIndex(interp, args, 1);
    
    if (!Jsi_ValueIsFunction(interp, fv)) {
        Jsi_LogError("expected function");
        return JSI_ERROR;
    }
    if (sv && sv->vt == JSI_VT_NUMBER)
        sigNum = (int)sv->d.num;
    else {
        char *ts = Jsi_ValueArrayIndexToStr(interp, args, 1, NULL);
        if ((sigNum = find_signal_by_name(interp, ts)) < 0) {
            Jsi_LogError("expected signal");
            return JSI_ERROR;
        }
    }
    if (sigNum < 0 || sigNum >= MAX_SIGNALS) {
        Jsi_LogError("unknown signal: %d", sigNum);
        return JSI_ERROR;
    }
    while (1) {
        id = interp->eventIdx++;
        Jsi_HashEntry *hPtr = Jsi_HashEntryCreate(interp->eventTbl, (void*)id, &isNew);
        if (!isNew)
            continue;
        ev = Jsi_Calloc(1, sizeof(*ev));
        SIGINIT(ev,EVENT);
        ev->id = id;
        ev->funcVal = fv;
        Jsi_IncrRefCount(interp, fv);
        ev->hPtr = hPtr;
        ev->sigNum = sigNum;
        ev->evType = JSI_EVENT_SIGNAL;
        Jsi_HashValueSet(hPtr, ev);
        break;
    }
    jsi_SignalSet(interp, sigNum);
    Jsi_ValueMakeNumber(interp, *ret, (Jsi_Number)id);
    return JSI_OK;
}
Exemplo n.º 9
0
static enum ec_error_list set(const char *name, int value)
{
	enum gpio_signal signal = find_signal_by_name(name);

	if (signal == GPIO_COUNT)
		return EC_ERROR_INVAL;

	if (!gpio_is_implemented(signal))
		return EC_ERROR_INVAL;

	if (!(gpio_get_default_flags(signal) & GPIO_OUTPUT))
		return EC_ERROR_INVAL;

	gpio_set_level(signal, value);

	return EC_SUCCESS;
}
Exemplo n.º 10
0
static int Jim_KillCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    int sig;
    long pid;
    Jim_Obj *pidObj;
    const char *signame;

    if (argc != 2 && argc != 3) {
        Jim_WrongNumArgs(interp, 1, argv, "?SIG|-0? pid");
        return JIM_ERR;
    }

    if (argc == 2) {
        sig = SIGTERM;
        pidObj = argv[1];
    }
    else {
        signame = Jim_String(argv[1]);
        pidObj = argv[2];

        /* Special 'kill -0 pid' to determine if a pid exists */
        if (strcmp(signame, "-0") == 0 || strcmp(signame, "0") == 0) {
            sig = 0;
        }
        else {
            sig = find_signal_by_name(interp, signame);
            if (sig < 0) {
                return JIM_ERR;
            }
        }
    }

    if (Jim_GetLong(interp, pidObj, &pid) != JIM_OK) {
        return JIM_ERR;
    }

    if (kill(pid, sig) == 0) {
        return JIM_OK;
    }

    Jim_SetResultString(interp, "kill: Failed to deliver signal", -1);
    return JIM_ERR;
}
Exemplo n.º 11
0
static int ftdi_execute_queue(void)
{
    /* blink, if the current layout has that feature */
    struct signal *led = find_signal_by_name("LED");
    if (led)
        ftdi_set_signal(led, '1');

    for (struct jtag_command *cmd = jtag_command_queue; cmd; cmd = cmd->next) {
        /* fill the write buffer with the desired command */
        ftdi_execute_command(cmd);
    }

    if (led)
        ftdi_set_signal(led, '0');

    int retval = mpsse_flush(mpsse_ctx);
    if (retval != ERROR_OK)
        LOG_ERROR("error while flushing MPSSE queue: %d", retval);

    return retval;
}
Exemplo n.º 12
0
static int signal_cmd_check(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
{
    int clear = 0;
    jim_wide mask = 0;
    jim_wide blocked;

    if (argc > 0 && Jim_CompareStringImmediate(interp, argv[0], "-clear")) {
        clear++;
    }
    if (argc > clear) {
        int i;

        /* Signals specified */
        for (i = clear; i < argc; i++) {
            int sig = find_signal_by_name(interp, Jim_String(argv[i]));

            if (sig < 0 || sig >= MAX_SIGNALS) {
                return -1;
            }
            mask |= sig_to_bit(sig);
        }
    }
    else {
        /* No signals specified, so check/clear all */
        mask = ~mask;
    }

    if ((sigsblocked & mask) == 0) {
        /* No matching signals, so empty result and nothing to do */
        return JIM_OK;
    }
    /* Be careful we don't have a race condition where signals are cleared but not returned */
    blocked = sigsblocked & mask;
    if (clear) {
        sigsblocked &= ~blocked;
    }
    /* Set the result */
    signal_set_sigmask_result(interp, blocked);
    return JIM_OK;
}
Exemplo n.º 13
0
static int command_gpio_get(int argc, char **argv)
{
	int i;

	/* If a signal is specified, print only that one */
	if (argc == 2) {
		i = find_signal_by_name(argv[1]);
		if (i == GPIO_COUNT)
			return EC_ERROR_PARAM1;
		print_gpio_info(i);

		return EC_SUCCESS;
	}

	/* Otherwise print them all */
	for (i = 0; i < GPIO_COUNT; i++) {
		if (!gpio_is_implemented(i))
			continue;  /* Skip unsupported signals */

		print_gpio_info(i);
	}

	return EC_SUCCESS;
}
Exemplo n.º 14
0
static int do_signal_cmd(Jim_Interp *interp, int action, int argc, Jim_Obj *const *argv)
{
    struct sigaction sa;
    int i;

    if (argc == 0) {
        Jim_SetResult(interp, Jim_NewListObj(interp, NULL, 0));
        for (i = 1; i < MAX_SIGNALS; i++) {
            if (siginfo[i].status == action) {
                /* Add signal name to the list  */
                Jim_ListAppendElement(interp, Jim_GetResult(interp),
                    Jim_NewStringObj(interp, Jim_SignalId(i), -1));
            }
        }
        return JIM_OK;
    }

    /* Catch all the signals we care about */
    if (action != SIGNAL_ACTION_DEFAULT) {
        sa.sa_flags = 0;
        sigemptyset(&sa.sa_mask);
        if (action == SIGNAL_ACTION_HANDLE) {
            sa.sa_handler = signal_handler;
        }
        else {
            sa.sa_handler = signal_ignorer;
        }
    }

    /* Iterate through the provided signals */
    for (i = 0; i < argc; i++) {
        int sig = find_signal_by_name(interp, Jim_String(argv[i]));

        if (sig < 0) {
            return JIM_ERR;
        }
        if (action != siginfo[sig].status) {
            /* Need to change the action for this signal */
            switch (action) {
                case SIGNAL_ACTION_HANDLE:
                case SIGNAL_ACTION_IGNORE:
                    if (siginfo[sig].status == SIGNAL_ACTION_DEFAULT) {
                        if (!sa_old) {
                            /* Allocate the structure the first time through */
                            sa_old = Jim_Alloc(sizeof(*sa_old) * MAX_SIGNALS);
                        }
                        sigaction(sig, &sa, &sa_old[sig]);
                    }
                    else {
                        sigaction(sig, &sa, 0);
                    }
                    break;

                case SIGNAL_ACTION_DEFAULT:
                    /* Restore old handler */
                    if (sa_old) {
                        sigaction(sig, &sa_old[sig], 0);
                    }
            }
            siginfo[sig].status = action;
        }
    }

    return JIM_OK;
}
Exemplo n.º 15
0
static int SignalSub(Jsi_Interp *interp, Jsi_Value *args, Jsi_Value *_this,
    Jsi_Value **ret, Jsi_Func *funcPtr, int action)
{

    struct sigaction sa;
    int i, argc = Jsi_ValueGetLength(interp, args);
    
    if (&interp->sigmask != sigloc) {
        Jsi_LogWarn("not primary interp");
        return JSI_OK;
    }
    
    if (argc == 0) {
        Jsi_Obj *nobj = Jsi_ObjNew(interp);
        int m;
        Jsi_ValueMakeArrayObject(interp,*ret, nobj);
        for (i = 0, m = 0; i < MAX_SIGNALS; i++) {
            if (signal_handling[i] == action) {
                /* Add signal name to the list  */
                Jsi_ObjArraySet(interp, nobj, Jsi_ValueNewStringKey(interp, Jsi_SignalName(i)), m++);
            }
        }
        return JSI_OK;
    }

    /* Catch all the signals we care about */
    if (action != SIGNAL_ACTION_DEFAULT) {
        sa.sa_flags = 0;
        sigemptyset(&sa.sa_mask);
        if (action == SIGNAL_ACTION_HANDLE) {
            sa.sa_handler = signal_handler;
        }
        else {
            sa.sa_handler = signal_ignorer;
        }
    }

    /* Iterate through the provided signals */
    for (i = 0; i < argc; i++) {
        char *sstr;
        int sig = find_signal_by_name(interp, sstr=Jsi_ValueArrayIndexToStr(interp,args,i, NULL));

        if (sig < 0) {
            Jsi_LogError("unknown signal: %s", sstr);
            return JSI_ERROR;
        }
        if (action != signal_handling[sig]) {
            /* Need to change the action for this signal */
            switch (action) {
                case SIGNAL_ACTION_HANDLE:
                case SIGNAL_ACTION_IGNORE:
                    if (signal_handling[sig] == SIGNAL_ACTION_DEFAULT) {
                        if (!sa_old) {
                            /* Allocate the structure the first time through */
                            sa_old = Jsi_Calloc(MAX_SIGNALS, sizeof(*sa_old));
                        }
                        sigaction(sig, &sa, &sa_old[sig]);
                    }
                    else {
                        sigaction(sig, &sa, 0);
                    }
                    break;

                case SIGNAL_ACTION_DEFAULT:
                    /* Restore old handler */
                    if (sa_old) {
                        sigaction(sig, &sa_old[sig], 0);
                    }
            }
            signal_handling[sig] = action;
        }
    }

    return JSI_OK;
}