TI中文支持网
TI专业的中文技术问题搜集分享网站

C6678 system_printf

您好:代码如下

void cbFxn(UInt16 procId, UInt16 lineId, UInt32 eventId, UArg arg, UInt32 payload)//Notify回调函数
{
Semaphore_post(semHandle);
}

void *tsk_func(void *arg)
{
int status;
if (MultiProc_self() == 0) {

/*这里可以添加主核需要执行的任务代码*/
System_printf("core%d \n",MultiProc_self());

/* Send an event to the next processor */
status = Notify_sendEvent(1, 0, 10, NULL, TRUE);
if (status < 0) {
System_abort("Notify_sendEvent for slaveCore1 failed\n");
}
/* Wait to be released by the cbFxn posting the semaphore */
Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 主核等待从核1完成其工作返回

/* Send an event to the next processor */
status = Notify_sendEvent(2, 0, 10, NULL, TRUE);
if (status < 0) {
System_abort("Notify_sendEvent for slaveCore2 failed\n");
}
/* Wait to be released by the cbFxn posting the semaphore */
Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 主核等待从核2完成其工作返回

/* Send an event to the next processor */
status = Notify_sendEvent(3, 0, 10, NULL, TRUE);
if (status < 0) {
System_abort("Notify_sendEvent for slaveCore3 failed\n");
}
/* Wait to be released by the cbFxn posting the semaphore */
Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 主核等待从核3完成其工作返回

/* Send an event to the next processor */
status = Notify_sendEvent(4, 0, 10, NULL, TRUE);
if (status < 0) {
System_abort("Notify_sendEvent for slaveCore4 failed\n");
}
/* Wait to be released by the cbFxn posting the semaphore */
Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 主核等待从核4完成其工作返回

/* Send an event to the next processor */
status = Notify_sendEvent(5, 0, 10, NULL, TRUE);
if (status < 0) {
System_abort("Notify_sendEvent for slaveCore5 failed\n");
}
/* Wait to be released by the cbFxn posting the semaphore */
Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 主核等待从核5完成其工作返回

/* Send an event to the next processor */
status = Notify_sendEvent(6, 0, 10, NULL, TRUE);
if (status < 0) {
System_abort("Notify_sendEvent for slaveCore6 failed\n");
}
/* Wait to be released by the cbFxn posting the semaphore */
Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 主核等待从核6完成其工作返回

/* Send an event to the next processor */
status = Notify_sendEvent(7, 0, 10, NULL, TRUE);
if (status < 0) {
System_abort("Notify_sendEvent for slaveCore7 failed\n");
}
/* Wait to be released by the cbFxn posting the semaphore */
Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 主核等待从核7完成其工作返回

System_printf("MasterCore0 Received Event from All SloverCores \n");
}
else {
System_printf("core%d \n",MultiProc_self());

/* wait forever on a semaphore, semaphore is posted in callback */
Semaphore_pend(semHandle, BIOS_WAIT_FOREVER); // 等待主核通知开始执行任务

System_printf("SlaverCore%d Received Event from MasterCore0 \n", MultiProc_self());

/*这里可以添加从核执行的任务*/

/* Send an event to the next processor */
status = Notify_sendEvent(0, 0, 10, NULL, TRUE);
if (status < 0) {
System_abort("sendEvent to MasterCore0 failed\n");
}

System_printf("SlaverCore%d sent Event to MasterCore0 \n", MultiProc_self());
}

System_printf("Test over \n");
BIOS_exit(0);
return (void*)0;
}

int main()
{
int status;
status = Ipc_start();
if (status < 0) {
System_abort("Ipc_start failed\n");
}
System_printf("Ipc_start successfully\n");

pthread_t tsk;
pthread_attr_t attr;
size_t stacksize = 0x1000000;//16MB
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr,stacksize);
if(pthread_create(&tsk,&attr,tsk_func,NULL))
{
tsk = 0;
System_abort("create tsk failed\n");
}

if(MultiProc_self() == 0)//0是主核,1-7是从核
{
do{
status = Ipc_attach(1);
}while(status < 0);// 完成从核1的连接
do{
status = Ipc_attach(2);
}while(status < 0);// 完成从核2的连接
do{
status = Ipc_attach(3);
}while(status < 0);// 完成从核3的连接
do{
status = Ipc_attach(4);
}while(status < 0);// 完成从核4的连接
do{
status = Ipc_attach(5);
}while(status < 0);// 完成从核5的连接
do{
status = Ipc_attach(6);
}while(status < 0);// 完成从核6的连接
do{
status = Ipc_attach(7);
}while(status < 0);// 完成从核7的连接

status = Notify_registerEvent(1, 0, 10, (Notify_FnNotifyCbck)cbFxn, NULL);
if (status < 0) {
System_abort("Notify_registerEvent for slaveCore1 failed\n");
}// 完成从核1的事件注册
status = Notify_registerEvent(2, 0, 10, (Notify_FnNotifyCbck)cbFxn, NULL);
if (status < 0) {
System_abort("Notify_registerEvent for slaveCore2 failed\n");
}// 完成从核2的事件注册
status = Notify_registerEvent(3, 0, 10, (Notify_FnNotifyCbck)cbFxn, NULL);
if (status < 0) {
System_abort("Notify_registerEvent for slaveCore3 failed\n");
}// 完成从核3的事件注册
status = Notify_registerEvent(4, 0, 10, (Notify_FnNotifyCbck)cbFxn, NULL);
if (status < 0) {
System_abort("Notify_registerEvent for slaveCore4 failed\n");
}// 完成从核4的事件注册
status = Notify_registerEvent(5, 0, 10, (Notify_FnNotifyCbck)cbFxn, NULL);
if (status < 0) {
System_abort("Notify_registerEvent for slaveCore5 failed\n");
}// 完成从核5的事件注册
status = Notify_registerEvent(6, 0, 10, (Notify_FnNotifyCbck)cbFxn, NULL);
if (status < 0) {
System_abort("Notify_registerEvent for slaveCore6 failed\n");
}// 完成从核6的事件注册
status = Notify_registerEvent(7, 0, 10, (Notify_FnNotifyCbck)cbFxn, NULL);
if (status < 0) {
System_abort("Notify_registerEvent for slaveCore7 failed\n");
}// 完成从核7的事件注册

System_printf("Notify_registerEvent for slaveCores successfully\n");
}
else{
do{
status = Ipc_attach(0);
}while(status < 0);// 完成主核0的连接

status = Notify_registerEvent(0, 0, 10, (Notify_FnNotifyCbck)cbFxn, NULL);
if (status < 0) {
System_abort("Notify_registerEvent for masterCore0 failed\n");
}// 完成主核0的事件注册

System_printf("Notify_registerEvent for masterCore0 successfully\n");
}

BIOS_start();
return 0;
}

结果:

[C66xx_6] Ipc_start successfully
Notify_registerEvent for masterCore0 successfully
core6SlaverCore6 Received Event from MasterCore0SlaverCore6 sent Event to MasterCore0Test over[C66xx_7] Ipc_start successfully
Notify_registerEvent for masterCore0 successfully
core7SlaverCore7 Received Event from MasterCore0SlaverCore7 sent Event to MasterCore0Test over[C66xx_5] Ipc_start successfully
Notify_registerEvent for masterCore0 successfully
core5SlaverCore5 Received Event from MasterCore0SlaverCore5 sent Event to MasterCore0Test over[C66xx_0] Ipc_start successfully
Notify_registerEvent for slaveCores successfully
core0MasterCore0 Received Event from All SloverCoresTest over[C66xx_1] Ipc_start successfully
Notify_registerEvent for masterCore0 successfully
core1SlaverCore1 Received Event from MasterCore0SlaverCore1 sent Event to MasterCore0Test over[C66xx_2] Ipc_start successfully
Notify_registerEvent for masterCore0 successfully
core2SlaverCore2 Received Event from MasterCore0SlaverCore2 sent Event to MasterCore0Test over[C66xx_3] Ipc_start successfully
Notify_registerEvent for masterCore0 successfully
core3SlaverCore3 Received Event from MasterCore0SlaverCore3 sent Event to MasterCore0Test over[C66xx_4] Ipc_start successfully
Notify_registerEvent for masterCore0 successfully
core4SlaverCore4 Received Event from MasterCore0SlaverCore4 sent Event to MasterCore0Test over

当使用system _printf()的时候,运行是正常的,打印信息也是对的,但是当使用printf()的时候,运行就会出错,显示如下:

[C66xx_6] Ipc_start successfully
[C66xx_7] Ipc_start successfully
[C66xx_0] Ipc_start successfully
[C66xx_1] Ipc_start successfully
[C66xx_2] Ipc_start successfully
[C66xx_3] Ipc_start successfully
[C66xx_4] Ipc_start successfully
[C66xx_5] Ipc_start successfully
[C66xx_1] Notify_registerEvent for masterCore0 successfully
[C66xx_2] Notify_registerEvent for masterCore0 successfully
[C66xx_3] Notify_registerEvent for masterCore0 successfully
[C66xx_4] Notify_registerEvent for masterCore0 successfully
[C66xx_5] Notify_registerEvent for masterCore0 successfully
[C66xx_6] Notify_registerEvent for masterCore0 successfully
[C66xx_7] Notify_registerEvent for masterCore0 successfully
[C66xx_1] core1[C66xx_2] core2[C66xx_3] core3[C66xx_4] core4[C66xx_5] core5[C66xx_6] core6[C66xx_7] core7[C66xx_0] Notify_registerEvent for slaveCores successfully
20bc338 B15=0x81000640
B16=0x4 B17=0x800003e0
B18=0xff B19=0x920b9cc8
B20=0x20 B21=0x10028066
B22=0x0 B23=0x7ff00000
B24=0x4410 B25=0x10
B26=0xd4206 B27=0x62180
B28=0x42800040 B29=0x6383
B30=0xc00f100 B31=0x2
NTSR=0x1000f
ITSR=0x0
IRP=0x0
SSR=0x0
AMR=0x0
RILC=0x0
ILC=0x0
Exception at 0xbebebebe
EFR=0x2 NRP=0xbebebebe
Internal exception: IERR=0x2
Fetch packet exception
ti.sysbios.family.c64p.Exception: line 256: E_exceptionMax: pc = 0xbebebebe, sp = 0x81000640.
xdc.runtime.Error.raise: terminating execution

使用system_printf会一次性打印一个内核的信息,不便于观察,我想使用printf(),请问是什么原因,谢谢!

Shine:

printf会占用较大的heap, stack,把heap, stack加大试试。

另外,在sys/bios里还是用system_printf比较好。http://processors.wiki.ti.com/index.php/Tips_for_using_printf#Additional_Tips_for_DSP.2FBIOS_Users

qq z:

回复 Shine:

BIOS.heapSize 给了256M,Program.stack 给了32M,线程的栈给了16M,应该不是给的太小的问题吧

qq z:

回复 Shine:

您好,我再请教您一个问题,在上面的代码中,我有注释“在这里添加主核的代码”和“在这里添加从核的代码”,我想请问的是,在这两个地方是否可以创建同一个线程,谢谢!

赞(0)
未经允许不得转载:TI中文支持网 » C6678 system_printf
分享到: 更多 (0)