35 #include "esos_pc_stdio.h"
43 #include <sys/select.h>
53 void reverseString(
char *psz_s1,
char *psz_s2);
54 uint32_t randomNumInRange(uint32_t u32_lo, uint32_t u32_hi);
70 static uint8_t psz_CRNL[3]= {0x0D, 0x0A, 0};
74 uint32_t u32_myT1Count = 0;
82 struct stTask* pst_MyTasks[3];
95 __esos_tmrSvcsExecute();
115 uint32_t randomNumInRange(uint32_t u32_lo, uint32_t u32_hi) {
116 uint32_t u32_d1, u32_d2, u32_d4, u32_ret;
121 u32_ret = u32_lo + u32_d4;
122 if (u32_ret <= u32_hi)
return u32_ret;
126 u32_ret = u32_lo + u32_d2;
127 if (u32_ret <= u32_hi)
return u32_ret;
130 u32_ret = u32_lo + u32_d1;
131 if (u32_ret <= u32_hi)
return u32_ret;
150 static uint32_t u32_cnt;
152 printf(
"A:%d\n", u32_cnt++);
157 static uint32_t u32_cnt;
159 printf(
"B:%d\n", u32_cnt++);
164 static uint32_t u32_cnt;
166 printf(
"C:%d\n", u32_cnt++);
184 printf(
"T1 (%d)\n", u32_rnd);
197 printf(
"T2 (%d)\n", u32_rnd);
210 printf(
"T3 (%d)\n", u32_rnd);
225 static uint8_t u8_cnt;
239 printf(
"taskSemA %d (%d)\n", u8_cnt, u32_rnd);
247 static uint8_t u8_cnt;
256 printf(
"taskSemB %d (%d)\n", u8_cnt, u32_rnd);
264 static uint8_t u8_cnt;
273 printf(
"taskSemC %d (%d)\n", u8_cnt, u32_rnd);
282 static uint8_t u8_cnt;
291 printf(
"taskMutexA %d (%d)\n", u8_cnt, u32_rnd);
301 static uint8_t u8_cnt;
310 printf(
"taskMutexB %d (%d)\n", u8_cnt, u32_rnd);
346 static uint8_t u8_char;
351 ESOS_TASK_SIGNAL_BUSY_IN_COMM();
354 if (u8_char ==
' ') {
356 ESOS_TASK_SIGNAL_BUSY_OUT_COMM();
370 static uint8_t u8_char;
375 ESOS_TASK_SIGNAL_BUSY_IN_COMM();
378 if ((u8_char >=
'a') && (u8_char <=
'z') )
379 u8_char = u8_char -
'a' +
'A';
381 ESOS_TASK_SIGNAL_BUSY_OUT_COMM();
396 static uint8_t au8_x[257];
397 static uint8_t au8_y[257];
402 ESOS_TASK_SIGNAL_BUSY_IN_COMM();
407 if ((au8_x[u8_i] >=
'a') && (au8_x[u8_i] <=
'z') )
408 au8_y[u8_i] = au8_x[u8_i] -
'a' +
'A';
410 au8_y[u8_i] = au8_x[u8_i];
411 if (au8_x[u8_i] == 0)
break;
415 ESOS_TASK_SIGNAL_BUSY_OUT_COMM();
426 static uint8_t u8_char;
427 static char sz_in[257];
428 static char sz_out[257];
433 ESOS_TASK_SIGNAL_BUSY_IN_COMM();
436 reverseString( sz_in, sz_out );
438 ESOS_TASK_SIGNAL_BUSY_OUT_COMM();
456 void reverseString(
char *psz_s1,
char *psz_s2) {
464 while (*psz_s1end) psz_s1end++;
467 while (psz_s1end != psz_s1) {
468 *psz_s2 = *psz_s1end;
473 *psz_s2 = *psz_s1end;
487 static uint8_t u8_cnt;
500 printf(
"T0 sending %d %d\n", u8_cnt, __pstSelf->u16_taskID);
506 printf(
"T0 sending %d %d\n", 10000+u8_cnt, __pstSelf->u16_taskID);
507 __esos_CB_WriteUINT16( hTask16->pst_Mailbox->pst_CBuffer, 10000+u8_cnt );
510 printf(
"T0 sending %d %d\n", 1000000+u8_cnt, __pstSelf->u16_taskID);
511 __esos_CB_WriteUINT32( hTask32->pst_Mailbox->pst_CBuffer, 1000000+u8_cnt );
514 if (u8_cnt>50) u8_cnt=0;
523 static uint8_t u8_cnt;
536 printf(
"T1 sending %d %d\n", 100+u8_cnt, __pstSelf->u16_taskID);
542 printf(
"T1 sending %d %d\n", 20000+u8_cnt, __pstSelf->u16_taskID);
543 __esos_CB_WriteUINT16( hTask16->pst_Mailbox->pst_CBuffer, 20000+u8_cnt );
546 printf(
"T1 sending %d %d\n", 2000000+u8_cnt, __pstSelf->u16_taskID);
547 __esos_CB_WriteUINT32( hTask32->pst_Mailbox->pst_CBuffer, 2000000+u8_cnt );
550 if (u8_cnt>50) u8_cnt=0;
558 static uint8_t u8_cnt;
570 printf(
"T2 sending %d %d\n", 200+u8_cnt, __pstSelf->u16_taskID);
576 printf(
"T2 sending %d %d\n", 30000+u8_cnt, __pstSelf->u16_taskID);
577 __esos_CB_WriteUINT16( hTask16->pst_Mailbox->pst_CBuffer, 30000+u8_cnt );
584 if (u8_cnt>50) u8_cnt=0;
594 static uint8_t u8_cnt;
606 u8_x = __esos_CB_ReadUINT8( __pstSelf->pst_Mailbox->pst_CBuffer );
610 printf(
"mailtaskA got mail.... %3d %d\n", u8_x, __pstSelf->pst_Mailbox->pst_CBuffer->u16_Count);
612 printf(
"mailtaskA got mail.... %3d %d\n", u8_x, u8_cnt);
628 u8_x = __esos_CB_ReadUINT8( __pstSelf->pst_Mailbox->pst_CBuffer );
631 printf(
"mailtaskAA got mail.... %d\n", u8_x);
646 u16_x = __esos_CB_ReadUINT16( __pstSelf->pst_Mailbox->pst_CBuffer );
647 printf(
"mailtaskB got mail.... %d\n", u16_x);
661 u32_x = __esos_CB_ReadUINT32( __pstSelf->pst_Mailbox->pst_CBuffer );
662 printf(
"mailtaskC got mail.... %d\n", u32_x);
671 static uint8_t u8_cnt;
683 ESOS_TASK_MAKE_MSG_UINT8(st_Message, u8_cnt);
685 if ( (u8_cnt % 5) ==0 ) {
686 st_Message.u8_flags |= ESOS_MAILMESSAGE_REQUEST_ACK;
689 if (st_Message.u8_flags & ESOS_MAILMESSAGE_REQUEST_ACK) {
690 printf(
"T0 sending MESSAGE with ACK request %3d\n", u8_cnt);
691 ESOS_TASK_SEND_MESSAGE_WAIT_DELIVERY(hTask, &st_Message);
693 printf(
"T0 sending MESSAGE %3d\n", u8_cnt);
694 ESOS_TASK_SEND_MESSAGE(hTask, &st_Message);
698 if (u8_cnt>=100) u8_cnt=0;
705 static uint8_t u8_cnt;
717 ESOS_TASK_MAKE_MSG_UINT8(st_Message, u8_cnt);
719 if ( (u8_cnt % 3) ==0 ) {
720 st_Message.u8_flags |= ESOS_MAILMESSAGE_REQUEST_ACK;
723 if (st_Message.u8_flags & ESOS_MAILMESSAGE_REQUEST_ACK) {
724 printf(
"T1 sending MESSAGE with ACK request %3d\n", u8_cnt);
725 ESOS_TASK_SEND_MESSAGE_WAIT_DELIVERY(hTask, &st_Message);
727 printf(
"T1 sending MESSAGE %3d\n", u8_cnt );
728 ESOS_TASK_SEND_MESSAGE(hTask, &st_Message);
732 if (u8_cnt>=200) u8_cnt=100;
742 static uint8_t u8_cnt;
758 printf(
"Got a message from ");
759 if ( ESOS_IS_TASK_SENDER( hMSG0, stMsg) ) {
760 printf(
"mailtaskMSG0");
761 }
else if ( ESOS_IS_TASK_SENDER(hMSG1, stMsg) ) {
762 printf(
"mailtaskMSG1");
766 printf (
" containing %3d delivery time = %d ms\n", stMsg.au8_Contents[0],
esos_GetSystemTick()-stMsg.u32_Postmark );
812 __esos_unsafe_PutString( HELLO_MSG );