37 #include "esos_pc_stdio.h"
45 #include <sys/select.h>
55 void reverseString(
char *psz_s1,
char *psz_s2);
56 uint32_t randomNumInRange(uint32_t u32_lo, uint32_t u32_hi);
72 static uint8_t psz_CRNL[3]= {0x0D, 0x0A, 0};
76 uint32_t u32_myT1Count = 0;
84 struct stTask* pst_MyTasks[3];
97 __esos_tmrSvcsExecute();
117 uint32_t randomNumInRange(uint32_t u32_lo, uint32_t u32_hi) {
118 uint32_t u32_d1, u32_d2, u32_d4, u32_ret;
123 u32_ret = u32_lo + u32_d4;
124 if (u32_ret <= u32_hi)
return u32_ret;
128 u32_ret = u32_lo + u32_d2;
129 if (u32_ret <= u32_hi)
return u32_ret;
132 u32_ret = u32_lo + u32_d1;
133 if (u32_ret <= u32_hi)
return u32_ret;
152 static uint32_t u32_cnt;
154 printf(
"A:%d\n", u32_cnt++);
159 static uint32_t u32_cnt;
161 printf(
"B:%d\n", u32_cnt++);
166 static uint32_t u32_cnt;
168 printf(
"C:%d\n", u32_cnt++);
186 printf(
"T1 (%d)\n", u32_rnd);
199 printf(
"T2 (%d)\n", u32_rnd);
212 printf(
"T3 (%d)\n", u32_rnd);
241 printf(
"taskSemA %d (%d)\n", u8_cnt, u32_rnd);
258 printf(
"taskSemB %d (%d)\n", u8_cnt, u32_rnd);
275 printf(
"taskSemC %d (%d)\n", u8_cnt, u32_rnd);
293 printf(
"taskMutexA %d (%d)\n", u8_cnt, u32_rnd);
312 printf(
"taskMutexB %d (%d)\n", u8_cnt, u32_rnd);
356 if (u8_char ==
' ') {
380 if ((u8_char >=
'a') && (u8_char <=
'z') )
381 u8_char = u8_char -
'a' +
'A';
409 if ((au8_x[u8_i] >=
'a') && (au8_x[u8_i] <=
'z') )
410 au8_y[u8_i] = au8_x[u8_i] -
'a' +
'A';
412 au8_y[u8_i] = au8_x[u8_i];
413 if (au8_x[u8_i] == 0)
break;
429 static char sz_in[257];
430 static char sz_out[257];
438 reverseString( sz_in, sz_out );
458 void reverseString(
char *psz_s1,
char *psz_s2) {
466 while (*psz_s1end) psz_s1end++;
469 while (psz_s1end != psz_s1) {
470 *psz_s2 = *psz_s1end;
475 *psz_s2 = *psz_s1end;
502 printf(
"T0 sending %d %d\n", u8_cnt, __pstSelf->u16_taskID);
508 printf(
"T0 sending %d %d\n", 10000+u8_cnt, __pstSelf->u16_taskID);
509 __esos_CB_WriteUINT16( hTask16->pst_Mailbox->pst_CBuffer, 10000+u8_cnt );
512 printf(
"T0 sending %d %d\n", 1000000+u8_cnt, __pstSelf->u16_taskID);
513 __esos_CB_WriteUINT32( hTask32->pst_Mailbox->pst_CBuffer, 1000000+u8_cnt );
516 if (u8_cnt>50) u8_cnt=0;
538 printf(
"T1 sending %d %d\n", 100+u8_cnt, __pstSelf->u16_taskID);
544 printf(
"T1 sending %d %d\n", 20000+u8_cnt, __pstSelf->u16_taskID);
545 __esos_CB_WriteUINT16( hTask16->pst_Mailbox->pst_CBuffer, 20000+u8_cnt );
548 printf(
"T1 sending %d %d\n", 2000000+u8_cnt, __pstSelf->u16_taskID);
549 __esos_CB_WriteUINT32( hTask32->pst_Mailbox->pst_CBuffer, 2000000+u8_cnt );
552 if (u8_cnt>50) u8_cnt=0;
572 printf(
"T2 sending %d %d\n", 200+u8_cnt, __pstSelf->u16_taskID);
578 printf(
"T2 sending %d %d\n", 30000+u8_cnt, __pstSelf->u16_taskID);
579 __esos_CB_WriteUINT16( hTask16->pst_Mailbox->pst_CBuffer, 30000+u8_cnt );
586 if (u8_cnt>50) u8_cnt=0;
608 u8_x = __esos_CB_ReadUINT8( __pstSelf->pst_Mailbox->pst_CBuffer );
612 printf(
"mailtaskA got mail.... %3d %d\n", u8_x, __pstSelf->pst_Mailbox->pst_CBuffer->u16_Count);
614 printf(
"mailtaskA got mail.... %3d %d\n", u8_x, u8_cnt);
630 u8_x = __esos_CB_ReadUINT8( __pstSelf->pst_Mailbox->pst_CBuffer );
633 printf(
"mailtaskAA got mail.... %d\n", u8_x);
648 u16_x = __esos_CB_ReadUINT16( __pstSelf->pst_Mailbox->pst_CBuffer );
649 printf(
"mailtaskB got mail.... %d\n", u16_x);
663 u32_x = __esos_CB_ReadUINT32( __pstSelf->pst_Mailbox->pst_CBuffer );
664 printf(
"mailtaskC got mail.... %d\n", u32_x);
675 static MAILMESSAGE st_Message;
685 ESOS_TASK_MAKE_MSG_UINT8(st_Message, u8_cnt);
687 if ( (u8_cnt % 5) ==0 ) {
688 st_Message.u8_flags |= ESOS_MAILMESSAGE_REQUEST_ACK;
691 if (st_Message.u8_flags & ESOS_MAILMESSAGE_REQUEST_ACK) {
692 printf(
"T0 sending MESSAGE with ACK request %3d\n", u8_cnt);
693 ESOS_TASK_SEND_MESSAGE_WAIT_DELIVERY(hTask, &st_Message);
695 printf(
"T0 sending MESSAGE %3d\n", u8_cnt);
696 ESOS_TASK_SEND_MESSAGE(hTask, &st_Message);
700 if (u8_cnt>=100) u8_cnt=0;
709 static MAILMESSAGE st_Message;
719 ESOS_TASK_MAKE_MSG_UINT8(st_Message, u8_cnt);
721 if ( (u8_cnt % 3) ==0 ) {
722 st_Message.u8_flags |= ESOS_MAILMESSAGE_REQUEST_ACK;
725 if (st_Message.u8_flags & ESOS_MAILMESSAGE_REQUEST_ACK) {
726 printf(
"T1 sending MESSAGE with ACK request %3d\n", u8_cnt);
727 ESOS_TASK_SEND_MESSAGE_WAIT_DELIVERY(hTask, &st_Message);
729 printf(
"T1 sending MESSAGE %3d\n", u8_cnt );
730 ESOS_TASK_SEND_MESSAGE(hTask, &st_Message);
734 if (u8_cnt>=200) u8_cnt=100;
745 static MAILMESSAGE stMsg;
758 __esos_ReadMailMessage(__pstSelf, &stMsg );
760 printf(
"Got a message from ");
761 if ( ESOS_IS_TASK_SENDER( hMSG0, stMsg) ) {
762 printf(
"mailtaskMSG0");
763 }
else if ( ESOS_IS_TASK_SENDER(hMSG1, stMsg) ) {
764 printf(
"mailtaskMSG1");
768 printf (
" containing %3d delivery time = %d ms\n", stMsg.au8_Contents[0],
esos_GetSystemTick()-stMsg.u32_Postmark );
814 __esos_unsafe_PutString( HELLO_MSG );