Esempio n. 1
0
static void msg1_execute(void) {
  msg_t msg;

  /*
   * Testing the whole messages loop.
   */
  threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriority() + 1,
                                 thread, chThdSelf());
  chMsgRelease(msg = chMsgWait());
  test_emit_token(msg);
  chMsgRelease(msg = chMsgWait());
  test_emit_token(msg);
  chMsgRelease(msg = chMsgWait());
  test_emit_token(msg);
  test_assert_sequence(1, "ABC");

  /*
   * Testing message fetch using chMsgGet().
   * Note, the following is valid because the sender has higher priority than
   * the receiver.
   */
  msg = chMsgGet();
  test_assert(1, msg != 0, "no message");
  chMsgRelease(0);
  test_assert(2, msg == 'D', "wrong message");

  /*
   * Must not have pending messages.
   */
  msg = chMsgGet();
  test_assert(3, msg == 0, "unknown message");
}
Esempio n. 2
0
static void test_006_001_execute(void) {
  thread_t *tp;
  msg_t msg;

  /* [6.1.1] Starting the messenger thread.*/
  test_set_step(1);
  {
    threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX() + 1,
                                   msg_thread1, chThdGetSelfX());
  }

  /* [6.1.2] Waiting for four messages then testing the receive
     order.*/
  test_set_step(2);
  {
    unsigned i;

    for (i = 0; i < 4; i++) {
      tp = chMsgWait();
      msg = chMsgGet(tp);
      chMsgRelease(tp, msg);
      test_emit_token(msg);
    }
    test_wait_threads();
    test_assert_sequence("ABCD", "invalid sequence");
  }
}
Esempio n. 3
0
  msg_t ThreadReference::getMessage(void) {

    chDbgAssert(thread_ref != NULL,
                "not referenced");

    return chMsgGet(thread_ref);
  }
Esempio n. 4
0
THD_FUNCTION( sd_logger, p )
{
  (void) p;
  struct sdlog_stru * plog;
  FIL    file;
  UINT   nb;
  BYTE   mode;

  chRegSetThreadName( "sd_logger" );

  while( true )
  {
    thread_t * tp = chMsgWait();
    plog = (struct sdlog_stru *) chMsgGet( tp );
    DEBUG_PRINT( "Write to file %s\r\n%s\r\n", plog->file, plog->line );

    mode = FA_WRITE | ( plog->append ? FA_OPEN_ALWAYS : FA_CREATE_ALWAYS );
    if( f_open( & file, plog->file, mode ) == FR_OK )
    {
      if( plog->append )
        f_lseek( & file, f_size( & file ));
      f_write( & file, plog->line, strlen( plog->line ), (UINT *) & nb );
      f_close( & file );
    }

    chMsgRelease( tp, MSG_OK );
  }
}
Esempio n. 5
0
/*
 * Console print server done using synchronous messages. This makes the access
 * to the C printf() thread safe and the print operation atomic among threads.
 * In this example the message is the zero terminated string itself.
 */
static THD_FUNCTION(console_thread, arg) {

  (void)arg;
  while (!chThdShouldTerminateX()) {
    thread_t *tp = chMsgWait();
    puts((char *)chMsgGet(tp));
    fflush(stdout);
    chMsgRelease(tp, MSG_OK);
  }
}
Esempio n. 6
0
/*
 * Console print server done using synchronous messages. This makes the access
 * to the C printf() thread safe and the print operation atomic among threads.
 * In this example the message is the zero termitated string itself.
 */
static msg_t console_thread(void *arg) {

  (void)arg;
  while (!chThdShouldTerminate()) {
    Thread *tp = chMsgWait();
    puts((char *)chMsgGet(tp));
    fflush(stdout);
    chMsgRelease(tp, RDY_OK);
  }
  return 0;
}
Esempio n. 7
0
static msg_t thread1(void *p) {
  Thread *tp;
  msg_t msg;

  (void)p;
  do {
    tp = chMsgWait();
    msg = chMsgGet(tp);
    chMsgRelease(tp, msg);
  } while (msg);
  return 0;
}
Esempio n. 8
0
static void msg1_execute(void) {
  thread_t *tp;
  msg_t msg;

  /*
   * Testing the whole messages loop.
   */
  threads[0] = chThdCreateStatic(wa[0], WA_SIZE, chThdGetPriorityX() + 1,
                                 thread, chThdGetSelfX());
  tp = chMsgWait();
  msg = chMsgGet(tp);
  chMsgRelease(tp, msg);
  test_emit_token(msg);
  tp = chMsgWait();
  msg = chMsgGet(tp);
  chMsgRelease(tp, msg);
  test_emit_token(msg);
  tp = chMsgWait();
  msg = chMsgGet(tp);
  chMsgRelease(tp, msg);
  test_emit_token(msg);
  test_assert_sequence(1, "ABC");
}
Esempio n. 9
0
static THD_FUNCTION(Thread1, arg) {

  (void)arg;
  chRegSetThreadName("blinker");
  while (true) {
          /* Waiting for a queued message then retrieving it.*/
          thread_t *tp = chMsgWait();
          msg_t msg = chMsgGet(tp);

          /* Processing the message.*/
          if(msg == (msg_t)"ON")
            palSetPad(GPIOA, GPIOA_LED_GREEN);
          else if (msg == (msg_t)"OFF")
            palClearPad(GPIOA, GPIOA_LED_GREEN);
          /* Sending back an acknowledge.*/
          chMsgRelease(tp, MSG_OK);
  }
}
  msg_t BaseThread::GetMessage(Thread* tp) {

    return chMsgGet(tp);
  }
Esempio n. 11
0
msg_t BaseThread::GetMessage(void) {

    return chMsgGet();
}
static msg_t ThreadFatFSWorker(void *arg) {
    (void)arg;

    Thread* p;

    chRegSetThreadName("fatfsWorker");
    while (!chThdShouldTerminate()) {

        /* Wait for msg with work to do. */
        p = chMsgWait();


        struct wrapper_msg_base* msg = (struct wrapper_msg_base*) chMsgGet(p);

        msg->result = FR_INVALID_PARAMETER;

        switch(msg->action) {

        case eTERMINATE: {
            break;
        }

#if HAS_MOUNT
        case eFMOUNT: {
            const struct wrapper_msg_vBYTEpFATFS* exmsg = \
                    (const struct wrapper_msg_vBYTEpFATFS*) msg;
            msg->result = f_mount(exmsg->byte, exmsg->fatfsp);
            break;
        }
#endif /* HAS_MOUNT */

#if HAS_OPEN
        case eFOPEN: {
            const struct wrapper_msg_pFILpTCHARvBYTE* exmsg = \
                    (const struct wrapper_msg_pFILpTCHARvBYTE*) msg;

            msg->result = f_open(exmsg->filep, exmsg->string, exmsg->byte);
            break;
        }
#endif /* HAS_OPEN */

#if HAS_READ
        case eFREAD: {
            const struct wrapper_msg_pFILpVOIDvUINTpUINT* exmsg = \
                    (const struct wrapper_msg_pFILpVOIDvUINTpUINT*) msg;

            msg->result = f_read(exmsg->filep, exmsg->voidp, exmsg->uint,
                                 exmsg->uintp);
            break;
        }
#endif /* HAS_READ */

#if HAS_WRITE
        case eFWRITE: {
            const struct wrapper_msg_pFILpVOIDvUINTpUINT* exmsg = \
                    (const struct wrapper_msg_pFILpVOIDvUINTpUINT*) msg;
            msg->result = f_write(exmsg->filep, exmsg->voidp, exmsg->uint,
                                  exmsg->uintp);
            break;
        }
#endif /* HAD_WRITE */

#if HAS_SYNC
        case eFSYNC: {
            const struct wrapper_msg_pFIL* exmsg = \
                                                   (const struct wrapper_msg_pFIL*) msg;
            msg->result = f_sync(exmsg->filep);
            break;
        }
#endif /* HAS_SYNC */

#if HAS_CHDRIVE
        case eFCHDRIVE: {
            const struct wrapper_msg_vBYTE* exmsg = \
                                                    (const struct wrapper_msg_vBYTE*) msg;
            msg->result = f_chdrive(exmsg->byte);
            break;
        }
#endif

#if HAS_CHDIR
        case eFCHDIR: {
            const struct wrapper_msg_pTCHAR* exmsg = \
                    (const struct wrapper_msg_pTCHAR*) msg;

            msg->result = f_chdir(exmsg->string);
            break;
        }
#endif /* HAS_CHDIR */

#if HAS_GETCWD
        case eFGETCWD: {
            const struct wrapper_msg_pTCHARvUINT* exmsg = \
                    (const struct wrapper_msg_pTCHARvUINT*) msg;
            msg->result = f_getcwd(exmsg->string, exmsg->uint);
            break;
        }
#endif

#if HAS_LSEEK
        case eFLSEEK: {
            const struct wrapper_msg_pFILvDWORD* exmsg = \
                    (const struct wrapper_msg_pFILvDWORD*) msg;
            msg->result = f_lseek(exmsg->filep, exmsg->dword);
            break;
        }
#endif /* HAS_LSEEK */

#if HAS_CLOSE
        case eFCLOSE: {
            const struct wrapper_msg_pFIL* exmsg = \
                                                   (const struct wrapper_msg_pFIL*) msg;
            msg->result = f_close(exmsg->filep);
            break;
        }
#endif /* HAS_CLOSE */

#if HAS_OPENDIR
        case eFOPENDIR: {
            const struct wrapper_msg_pDIRpTCHAR* exmsg = \
                    (const struct wrapper_msg_pDIRpTCHAR*) msg;
            msg->result = f_opendir(exmsg->dirp, exmsg->string);
            break;
        }
#endif /* HAD_OPENDIR */

#if HAS_READDIR
        case eFREADDIR: {
            const struct wrapper_msg_pDIRpFILINFO* exmsg = \
                    (const struct wrapper_msg_pDIRpFILINFO*) msg;
            msg->result = f_readdir(exmsg->dirp, exmsg->filinfop);
            break;
        }
#endif /* HAS_READDIR */

#if HAS_STAT
        case eFSTAT: {
            const struct wrapper_msg_pTCHARpFILINFO* exmsg = \
                    (const struct wrapper_msg_pTCHARpFILINFO*) msg;
            msg->result = f_stat(exmsg->string, exmsg->filinfop);
            break;
        }
#endif /* HAS_STAT */

#if HAS_GETFREE
        case eFGETFREE: {
            const struct wrapper_msg_pTCHARpDWORDppFATFS* exmsg = \
                    (const struct wrapper_msg_pTCHARpDWORDppFATFS*) msg;
            msg->result = f_getfree(exmsg->string, exmsg->dwordp, exmsg->fatfspp);
            break;
        }
#endif /* HAS_GETFREE */

#if HAS_TRUNCATE
        case eFTRUNCATE: {
            const struct wrapper_msg_pFIL* exmsg = \
                                                   (const struct wrapper_msg_pFIL*) msg;
            msg->result = f_truncate(exmsg->filep);
            break;
        }
#endif /* HAS_TRUNCATE */

#if HAS_UNLINK
        case eFUNLINK: {
            const struct wrapper_msg_pTCHAR* exmsg = \
                    (const struct wrapper_msg_pTCHAR*) msg;
            msg->result = f_unlink(exmsg->string);
            break;
        }
#endif /* HAS_UNLINK */

#if HAS_MKDIR
        case eFMKDIR: {
            const struct wrapper_msg_pTCHAR* exmsg = \
                    (const struct wrapper_msg_pTCHAR*) msg;
            msg->result = f_mkdir(exmsg->string);
            break;
        }
#endif /* HAS_MKDIR */

#if HAS_CHMOD
        case eFCHMOD: {
            const struct wrapper_msg_pTCHARvBYTEvBYTE* exmsg = \
                    (const struct wrapper_msg_pTCHARvBYTEvBYTE*) msg;
            msg->result = f_chmod(exmsg->string, exmsg->byte1, exmsg->byte2);
            break;
        }
#endif /* HAS_CHMOD */

#if HAS_UTIME
        case eFUTIME: {
            const struct wrapper_msg_pTCHARpFILINFO* exmsg = \
                    (const struct wrapper_msg_pTCHARpFILINFO*) msg;
            msg->result = f_utime(exmsg->string, exmsg->filinfop);
            break;
        }
#endif /* HAD_UTIME */

#if HAS_RENAME
        case eFRENAME: {
            const struct wrapper_msg_pTCHARpTCHAR* exmsg = \
                    (const struct wrapper_msg_pTCHARpTCHAR*) msg;

            msg->result = f_rename(exmsg->string1, exmsg->string2);
            break;
        }
#endif /* HAS_RENAME */

#if HAS_MKFS
        case eFMKFS: {
            const struct wrapper_msg_vBYTEvBYTEvUINT* exmsg = \
                    (const struct wrapper_msg_vBYTEvBYTEvUINT*) msg;
            msg->result = f_mkfs(exmsg->byte1, exmsg->byte2, exmsg->uint);
            break;
        }
#endif /* HAS_MKFS */

#if HAS_FDISK
        case eFFDISK: {
            const struct wrapper_msg_vBYTEpDWORDpVOID* exmsg = \
                    (const struct wrapper_msg_vBYTEpDWORDpVOID*) msg;
            msg->result = f_fdisk(exmsg->byte, exmsg->dwordp, exmsg->voidp);
            break;
        }
#endif /* HAS_FDISK */

#if HAS_GETS
        case eFGETS: {
            struct wrapper_msg_pTCHARvINTpFILpTCHAR* exmsg = \
                    (struct wrapper_msg_pTCHARvINTpFILpTCHAR*) msg;

            exmsg->string2 = f_gets(exmsg->string, exmsg->n, exmsg->filep);
            break;
        }
#endif /* HAS_GETS */

#if HAS_PUTC
        case eFPUTC: {
            const struct wrapper_msg_vTCHARpFIL* exmsg = \
                    (const struct wrapper_msg_vTCHARpFIL*) msg;

            msg->result = f_putc(exmsg->tchar, exmsg->filep);
            break;
        }
#endif /* HAS_PUTC */

#if HAS_PUTS
        case eFPUTS: {
            const struct wrapper_msg_pTCHARpFIL* exmsg = \
                    (const struct wrapper_msg_pTCHARpFIL*) msg;

            msg->result = f_puts(exmsg->string, exmsg->filep);
            break;
        }
#endif /* HAS_PUTS */

        }

        /* Done, release msg again. */
        chMsgRelease(p, 0);
    }

    return 0;
}