关闭

重新审视Xilins Driver API:ASSERT一探

1067人阅读 评论(1) 收藏 举报

再没有见过比xilinx的assert更晦涩的assert函数了,这就是硬件相关带给人类(其实只有我)的....汗!

#define XCOMPONENT_IS_READY     0x11111111  /* component has been initialized */
#define XCOMPONENT_IS_STARTED   0x22222222  /* component has been started */

#define XTEST_PASSED    0
#define XTEST_FAILED    1

#define XASSERT_NONE     0
#define XASSERT_OCCURRED 1

unsigned int XAssertStatus;
extern void XAssert(char *, int);
Xboolean XWaitInAssert = XTRUE;             /* 如果这个值被设置为真,则Xassert函数就会进入无限循环 */

/* Xilinx processor IP reference Guide上是这么说的The XAssert function calls a user defined function and then enters an endless loop. */

typedef void (*XAssertCallback)(char* FilenamePtr, int LineNumber);
static XAssertCallback XAssertCallbackRoutine = (XAssertCallback)XNULL;


void XAssert(char *File, int Line)
{
    /* if the callback has been set then invoke it */
    if (XAssertCallbackRoutine != XNULL)
    {
        (*XAssertCallbackRoutine)(File, Line);
    }

    /* if specified, wait indefinitely such that the assert will show up
     * in testing
     */
    while (XWaitInAssert)
    {
    }
}

/* 这个宏不返回值。它和XWaitInAssert一起使用,可以在测试的时候及时assert失败,也能让执行继续 */

#define XASSERT_VOID(expression)                   /
{                                                  /
    if (expression)                                /
    {                                              /
        XAssertStatus = XASSERT_NONE;              /
    }                                              /
    else                                           /
    {                                              /
        XAssert(__FILE__, __LINE__);               /
                XAssertStatus = XASSERT_OCCURRED;  /
        return;                                    /
    }                                              /
}

/* 这个宏返回值。它和XWaitInAssert一起使用,可以在测试的时候及时assert失败,也能让执行继续 */

#define XASSERT_NONVOID(expression)                /
{                                                  /
    if (expression)                                /
    {                                              /
        XAssertStatus = XASSERT_NONE;              /
    }                                              /
    else                                           /
    {                                              /
        XAssert(__FILE__, __LINE__);               /
                XAssertStatus = XASSERT_OCCURRED;  /
        return 0;                                  /
    }                                              /
}

/* 这个宏不返回值。用在assert总会发生的地方(还不明白有什么用) */

#define XASSERT_VOID_ALWAYS()                      /
{                                                  /
   XAssert(__FILE__, __LINE__);                    /
           XAssertStatus = XASSERT_OCCURRED;       /
   return;                                         /
}

/* 这个宏返回值。用在assert总会发生的地方(还不明白有什么用) */

#define XASSERT_NONVOID_ALWAYS()                   /
{                                                  /
   XAssert(__FILE__, __LINE__);                    /
           XAssertStatus = XASSERT_OCCURRED;       /
   return 0;                                       /
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:101654次
    • 积分:1625
    • 等级:
    • 排名:千里之外
    • 原创:62篇
    • 转载:0篇
    • 译文:0篇
    • 评论:12条
    文章分类
    最新评论