#include #include #include /************ Unable to access the data stored in the message box */ /* Definition of threads,Mailboxes, etc..*/ cyg_thread threadA,threadB; cyg_thread_entry_t procedureA, procedureB; cyg_handle_t handleA, handleB,getmboxA, getmboxB; char threadstack[2][4096]; cyg_mbox mailA, mailB; void cyg_user_start(void) { printf("\n This program demonstrates the usage of the Mailbox."); cyg_mbox_create(&getmboxA,&mailA); cyg_mbox_create(&getmboxB,&mailB); cyg_thread_create(4,procedureA, (cyg_addrword_t)0, "ThreadMailA", threadstack[0],4096,&handleA,&threadA); cyg_thread_create(3,procedureB, (cyg_addrword_t)1, "ThreadMailB", threadstack[1],4096,&handleB,&threadB); cyg_thread_resume(handleA); cyg_thread_resume(handleB); } void procedureA(cyg_addrword_t data) { int message = (int)data; void *add,*text="Thank You"; add=NULL; printf("\nThis Thread %d is waiting for mesage from thread 1",message); if(add=cyg_mbox_get(getmboxA)) { printf("\n Message received %s from thread 1",(char*)add); if(cyg_mbox_put(getmboxB,&text)) printf("\n Sent Acknowledge message to thread 1"); else printf("\n Failed to post message to thread 1"); } } void procedureB(cyg_addrword_t data) { int message = (int)data; void *textdata ="Hello"; void *string ; printf("\n This Thread %d will send a message to thread 0",message); if(cyg_mbox_put(getmboxA, &textdata)) printf("\n Posted message to thread 0"); if(string=cyg_mbox_get(getmboxB)) printf("\n Received message %s from Thread 0",(char*)string); }