Esempio n. 1
0
int Zprintf0(int force, char *buf)
{
        int l;
        int n;
        int ret;
        int msgret;
        char *str;
        char junk;

        str = buf;
        l = sipx_min(ABSOLUTE_MAX_LOG_MSG_LEN, strlen(buf));
        ret = l;
        if (0 == MpMisc.LogQ) {
            ret = force ? fwrite(str, 1, ret, stderr) : 0;
            return ret;
        }
        if (force || logging) {
            if ((ret > MpMisc.logMsgSize) && !intContext()) {
                taskLock();
            }
            while (l > 0) {
                n = sipx_min(l, MpMisc.logMsgSize);
                msgret = msgQSend(MpMisc.LogQ, buf, n,
                                       VX_NO_WAIT, MSG_PRI_NORMAL);
                if (ERROR == msgret) {
                    // int r2 =
                    msgQReceive(MpMisc.LogQ, &junk, 1, VX_NO_WAIT);
                    // osPrintf("discard message; r1=%d, r2=%d, q=0x%X: '%s'\n",
                        // msgret, r2, MpMisc.LogQ, buf);
                    numDiscarded++;
                    msgret = msgQSend(MpMisc.LogQ, buf, n,
                                       VX_NO_WAIT, MSG_PRI_NORMAL);
                }
                if ((ERROR == msgret) && force) {
                    fwrite(str, 1, ret, stderr);
                    l = 0;
                } else {
                    l -= n;
                    buf += n;
                }
            }
            if ((ret > MpMisc.logMsgSize) && !intContext()) {
                taskUnlock();
            }
        } else {
            ret = 0;
        }
        return ret;
}
Esempio n. 2
0
int timer_delete
    (
    timer_t timerid	/* timer ID */
    )
    {
    if (intContext ())
	return (ERROR);

    if (timerid == NULL)
	{
	errno = EINVAL;
	return (ERROR);
	}

    if (timer_cancel (timerid) != 0)
	return (ERROR);

    if (wdDelete (timerid->wdog) != OK)
    return (ERROR);

    (void)sigPendDestroy (&timerid->sigpend);

    free ((char *) timerid);

    return (OK);
    }
Esempio n. 3
0
int putchar(int c)
{
    extern int32_t _the_console_fd;
    extern long xTaskGetSchedulerState( void );
    extern unsigned long getNesting( void );
    if ((intContext() == TRUE) || (_the_console_fd <= 0)
            || (getNesting() > 0)) //|| (xTaskGetSchedulerState() != 1))
    {
        /* 在终端中或调度器未运行时直接调用底层输出保证不使用taskDelay */
        if (c == '\n')
        {
            bsp_putchar('\r');
        }
        bsp_putchar((unsigned char)c);
    }
    else
    {
        if((c) == '\n')
        {
            char ch = '\r';
            dev_write(_the_console_fd, (uint8_t* )&ch, 1);
        }
        dev_write(_the_console_fd, (uint8_t* )&c, 1);
    }
    return 1;
}
Esempio n. 4
0
/**
 ******************************************************************************
 * @brief   日志输出
 * @param[in]  fmt  : 日志信息与printf相同
 *
 * @retval     ERROR: 发送日志消息失败
 * @retval     OK   : 发送日志消息成功
 ******************************************************************************
 */
status_t
logmsg(const char *fmt, ...)
{
    log_msg_t *msg;

    if (the_logmsg_taskid == NULL)
    {
        va_list args;

        va_start( args, fmt );
        print( 0, fmt, args );
        return OK;
    }

    if (strlen(fmt) > (MAX_BYTES_IN_A_MSG - 1))
    {
        return ERROR;
    }
    msg = malloc(sizeof(log_msg_t));

    /* 判断是否在中断中调用 */
    msg->id = (intContext() == TRUE) ? -1 : (int32_t)taskIdSelf();

    char *out = (char *)msg->buf;

    va_list args;
    va_start( args, fmt );
    msg->len = print( &out, fmt, args );
    va_end(args);

    if (msg->len > (MAX_BYTES_IN_A_MSG - 1))
    {
        the_logmsgs_outoflen++; /* shit out of buf length */
    }
    msg->buf[msg->len] = '\0';


    if (msgQSend(the_logmsg_qid, (void *) msg) != OK)
    {
        ++the_logmsgs_lost;
        return ERROR;
    }

    return OK;
}
Esempio n. 5
0
/**
 ******************************************************************************
 * @brief   在loglib中输出指定的缓冲区数据
 * @param[in]  pbuf : 需要输出的缓冲区指针
 * @param[in]  len  : 需要输出的缓冲区数据长度
 *
 * @retval     ERROR: 发送日志消息失败
 * @retval     OK   : 发送日志消息成功
 ******************************************************************************
 */
status_t
logbuf(const uint8_t *pbuf, uint32_t len)
{
    log_msg_t *msg;

    if (the_logmsg_taskid == NULL)
    {
        printbuffer("", pbuf, len);
        return OK;
    }

    msg = malloc(sizeof(log_msg_t));

    /* 判断是否在中断中调用 */
    msg->id = (intContext() == TRUE) ? -1 : (int32_t)taskIdSelf();

    int32_t i;
    for (i = 0; i < MIN(len , ((MAX_BYTES_IN_A_MSG - 2) / 3)); i++)
    {
        (void)sprintf((char *)msg->buf + (i*3) , "%02x ", *pbuf);
        msg->len += 3;
        pbuf++;
    }
    msg->buf[i*3] = '\r';
    msg->buf[(i*3)+1] = '\n';
    msg->len += 2;
    if (msg->len > (MAX_BYTES_IN_A_MSG - 1))
    {
        the_logmsgs_outoflen++; /* shit out of buf length */
    }
    msg->buf[msg->len] = '\0';


    if (msgQSend(the_logmsg_qid, (void *) msg) != OK)
    {
        ++the_logmsgs_lost;
        return ERROR;
    }

    return OK;

}
Esempio n. 6
0
int timer_show
    (
    timer_t timerid	/* timer ID */
    )
    {
    static char *title1 = "task       timerid    evp        routine\n";
    static char *title2 = "---------- ---------- ---------- ----------\n";

    if (intContext ())
	return (ERROR);

    if (timerid == NULL)
	return (OK);

    printf (title1);
    printf (title2);

    printf ("%#10x %#10x %#10x %#10x\n", timerid->taskId, (unsigned int)timerid,
		(unsigned int)&timerid->sevent, (unsigned int)timerid->routine);

    return (OK);
    }
Esempio n. 7
0
int timer_connect
    (
    timer_t     timerid,	/* timer ID      */
    VOIDFUNCPTR routine,	/* user routine  */
    int         arg		/* user argument */
    )
    {
    static struct sigaction timerSig;

    if (timerSig.sa_handler == 0)
	{
	/* just the first time */
	timerSig.sa_handler = (void (*)(int))timerConHandler;
	(void) sigemptyset (&timerSig.sa_mask);
	timerSig.sa_flags = 0;	/* !SA_SIGINFO: cause timerid to be passed */
	}

    if (intContext ())
	return (ERROR);

    if (timerid == NULL)
	{
	errno = EINVAL;
	return (ERROR);
	}

    timerid->routine = routine;
    timerid->arg     = arg;

    timerid->sevent.sigev_signo = SIGALRM;
    timerid->sevent.sigev_value.sival_ptr = timerid;	/* !SA_SIGINFO */

    if (sigaction (SIGALRM, &timerSig, NULL) == ERROR)
	return (ERROR);
    else
	return (OK);
    }
Esempio n. 8
0
int timer_create
    (
    clockid_t clock_id,		/* clock ID (always CLOCK_REALTIME) */
    struct sigevent *evp,	/* user event handler               */
    timer_t * pTimer		/* ptr to return value 		    */
    )
    {
    timer_t timerid;
    struct sigevent sevp;

    if (intContext ())
	return (ERROR);

    (void)clockLibInit (); /* make sure clock "running" */

    timerid = (timer_t) calloc (1, sizeof(*timerid));

    if (timerid == NULL)
	{
	/* errno = EMTIMERS;  * S_memLib_NOT_ENOUGH_MEMORY will be lost */
	return (ERROR);
	}

    if ((timerid->wdog = wdCreate ()) == NULL)
        {
	free ((char *) timerid);
	return (ERROR);
        }

    timerid->active = FALSE;
    timerid->taskId = taskIdSelf ();

    timerid->clock_id = clock_id;	/* should check for known clock_id? */

    if (evp == NULL)
	{
	sevp.sigev_signo = SIGALRM;
	/* remember value possibly set in timer_connect() */
	/* XXX
	sevp.sigev_value.sival_int = timerid->sevent.sigev_value.sival_int;
	*/
	sevp.sigev_value.sival_ptr = timerid;
	}
    else
	{
	if (evp->sigev_signo < 1 || evp->sigev_signo > _NSIGS)
	    {
	    errno = EINVAL;
	    return (ERROR);
	    }
	sevp = *evp;
	}

    timerid->sevent = sevp;
    timerid->sigpend.sigp_info.si_signo = sevp.sigev_signo;
    timerid->sigpend.sigp_info.si_code  = SI_TIMER;
    timerid->sigpend.sigp_info.si_value = sevp.sigev_value;

    sigPendInit (&timerid->sigpend);

    TV_ZERO(timerid->exp.it_interval);
    TV_ZERO(timerid->exp.it_value);

    *pTimer = timerid;
    return (OK);
    }
Esempio n. 9
0
int  epicsInterruptIsInterruptContext() {return(intContext());}