コード例 #1
0
ファイル: bridge_app.c プロジェクト: TerryLo/onchipsdk-1
static void uartTask(void* unused) {
   dn_error_t           dnErr;
   INT8U                osErr;
   dn_uart_open_args_t  uartOpenArgs;
   INT32U               rxLen;
   INT32U               channelMsgType;
   INT32S               err;
   
   // create the memory block for the UART channel
   bridge_app_v.uartRxChannelMem = OSMemCreate(
      bridge_app_v.uartRxChannelMemBuf,
      1,
      sizeof(bridge_app_v.uartRxChannelMemBuf),
      &osErr
   );
   ASSERT(osErr==OS_ERR_NONE);
   
   // create an asynchronous notification channel
   dnErr = dn_createAsyncChannel(bridge_app_v.uartRxChannelMem, &bridge_app_v.uartRxChannel);
   ASSERT(dnErr==DN_ERR_NONE);
   
   // associate the channel descriptor with UART notifications
   dnErr = dn_registerChannel(bridge_app_v.uartRxChannel, DN_MSG_TYPE_UART_NOTIF);
   ASSERT(dnErr==DN_ERR_NONE);
   
   // open the UART device
   uartOpenArgs.rxChId    = bridge_app_v.uartRxChannel;
   uartOpenArgs.rate        = 115200u;
   uartOpenArgs.mode        = DN_UART_MODE_M4;
   uartOpenArgs.ctsOutVal   = 0;
   err = dn_open(
      DN_UART_DEV_ID,
      &uartOpenArgs,
      sizeof(uartOpenArgs)
   );
   ASSERT(err>=0);
   
   while(1) { // this is a task, it executes forever
      
      // wait for UART messages
      dnErr = dn_readAsyncMsg(
         bridge_app_v.uartRxChannel,   // chDesc
         bridge_app_v.uartRxBuffer,    // msg
         &rxLen,                       // rxLen
         &channelMsgType,              // msgType
         MAX_UART_PACKET_SIZE,         // maxLen
         0                             // timeout (0==never)
      );
      ASSERT(dnErr==DN_ERR_NONE);
      ASSERT(channelMsgType==DN_MSG_TYPE_UART_NOTIF);
      
      // call the callback
      serial_rx(bridge_app_v.uartRxBuffer,rxLen);
   }
}
コード例 #2
0
ファイル: dnm_cli.c プロジェクト: semalinear/onchipsdk
/**
\brief Wait for CLI input and process it.

This function blocks waiting for CLI input. When it receives input, it invokes
the appropriate CLI command handler. If the CLI command handler returns an
error, the help handler is invoked.

\param[in] pCont CLI context.

\return #DN_ERR_NONE if CLI input was received and handled correctly.
\return A error if the CLI channel could not be read (see #dn_readAsyncMsg()).
\return A error if CLI command could not be processed (see
   #dnm_cli_procNotif()).
*/
dn_error_t dnm_cli_input (dnm_cli_cont_t * pCont)
{
   INT32S              rxLen, msgType;
   INT8U               buf[DN_CLI_NOTIF_SIZE];
   dn_error_t          res;
   dn_cli_notifMsg_t * pCliNotif = (dn_cli_notifMsg_t *)buf;

   memset(buf, 0, sizeof(buf));
   res = dn_readAsyncMsg(pCont->inpCh, buf, &rxLen, &msgType, sizeof(buf), 0);
   if (res != DN_ERR_NONE)
      return res;
      
   return dnm_cli_procNotif (pCont, msgType, pCliNotif, rxLen);
      
      
      
}
コード例 #3
0
ファイル: lptimer_app.c プロジェクト: dustcloud/onchipsdk
static void lptimerTask(void* unused) {
    dn_error_t          dnErr;
    INT8U               osErr;
    INT32U              msg;
    INT32U              rxLen;
    INT32U              msgType;
    
    // give time for stack banner to print
    OSTimeDly(1 * SECOND);

    // create the memory block for the UART channel
    lptimer_app_v.eventChIdMem = OSMemCreate( lptimer_app_v.eventChIdMemBuf,
                                    EVENT_CHANNEL_SIZE, EVENT_CHANNEL_MSG_SIZE, &osErr);
    ASSERT(osErr==OS_ERR_NONE);

    // create an asynchronous notification channel
    dnErr = dn_createAsyncChannel(lptimer_app_v.eventChIdMem, &lptimer_app_v.eventChId);
    ASSERT(dnErr==DN_ERR_NONE);

    // associate the channel descriptor with UART notifications
    dnErr = dn_registerChannel(lptimer_app_v.eventChId, DN_MSG_TYPE_LPTIMER_NOTIF);
    ASSERT(dnErr==DN_ERR_NONE);

    while(1) { // this is a task, it executes forever

        // wait for event message
        dnErr = dn_readAsyncMsg(lptimer_app_v.eventChId, &msg, &rxLen, &msgType, sizeof(msg), 0 );
        ASSERT(dnErr==DN_ERR_NONE);
        ASSERT(msgType==DN_MSG_TYPE_LPTIMER_NOTIF);

        if(msg & DN_LPTIMER_COMPARE_EVENT) {
            // print message received - the count will have increased slightly since the capture
            dnm_ucli_printf("COMP Event %d\r\n", msg);
        }
        
        if(msg & DN_LPTIMER_CAPTURE_EVENT) {
            // print message received
            dnm_ucli_printf("CAPT Event %d\r\n", msg);
        }
        
        if(msg & DN_LPTIMER_OVERFLOW_EVENT) {
            lptimer_app_v.overflow++;
        }
    }
}
コード例 #4
0
ファイル: dnm_ucli.c プロジェクト: dustcloud/onchipsdk
/**
\brief Wait for CLI input and process it.

This function blocks waiting for CLI input. When it receives input, it invokes
function to process CLI notification
\param[in] chDesc Channel descriptor of CLI input.

\return #DN_ERR_NONE if CLI input was received and handled correctly.
\return An error if the CLI channel could not be read (see 
*       #dn_readAsyncMsg()) or processing function returned
*       error.
*/
dn_error_t dnm_ucli_input (CH_DESC chDesc)
{
   INT32U              rxLen, msgType;
   INT8U               buf[DN_CLI_NOTIF_SIZE];
   INT8U               paramsLen;
   dn_error_t          res;
   dn_cli_notifMsg_t * pCliNotif = (dn_cli_notifMsg_t *)buf;

   if (dnm_ucli_v.notifCb==NULL) {
      return DN_ERR_NO_RESOURCES;
   }

   memset(buf, 0, sizeof(buf));
   res = dn_readAsyncMsg(chDesc, buf, &rxLen, &msgType, sizeof(buf), 0);
   if (res != DN_ERR_NONE)
      return res;

   paramsLen = (INT8U)rxLen - (INT8U)((((dn_cli_notifMsg_t*)(0))->data) - ((INT8U *)(dn_cli_notifMsg_t*)0)) - pCliNotif->offset;
   return dnm_ucli_v.notifCb(pCliNotif->type, pCliNotif->cmdId, (const char*)pCliNotif->data+pCliNotif->offset, paramsLen);
}
コード例 #5
0
ファイル: uart_app.c プロジェクト: dustcloud/onchipsdk
static void uartRxTask(void* unused) {
   dn_error_t           dnErr;
   INT8U                osErr;
   dn_uart_open_args_t  uartOpenArgs;
   INT32U               rxLen;
   INT32U               msgType;
   INT8U                i;
   INT32S               err;
   
   // create the memory block for the UART channel
   uart_app_v.uartRxChannelMem = OSMemCreate(
      uart_app_v.uartRxChannelMemBuf,
      1,
      sizeof(uart_app_v.uartRxChannelMemBuf),
      &osErr
   );
   ASSERT(osErr==OS_ERR_NONE);
   
   // create an asynchronous notification channel
   dnErr = dn_createAsyncChannel(uart_app_v.uartRxChannelMem, &uart_app_v.uartRxChannel);
   ASSERT(dnErr==DN_ERR_NONE);
   
   // associate the channel descriptor with UART notifications
   dnErr = dn_registerChannel(uart_app_v.uartRxChannel, DN_MSG_TYPE_UART_NOTIF);
   ASSERT(dnErr==DN_ERR_NONE);
   
   // open the UART device
   uartOpenArgs.rxChId    = uart_app_v.uartRxChannel;
   uartOpenArgs.eventChId   = 0;
   uartOpenArgs.rate        = 115200u;
   uartOpenArgs.mode        = DN_UART_MODE_M4;
   uartOpenArgs.ctsOutVal   = 0;
   uartOpenArgs.fNoSleep    = 0;
   err = dn_open(
      DN_UART_DEV_ID,
      &uartOpenArgs,
      sizeof(uartOpenArgs)
   );
   ASSERT(err>=0);
   
   while(1) { // this is a task, it executes forever
      
      // wait for UART messages
      dnErr = dn_readAsyncMsg(
         uart_app_v.uartRxChannel,          // chDesc
         uart_app_v.uartRxBuffer,           // msg
         &rxLen,                            // rxLen
         &msgType,                          // msgType
         MAX_UART_PACKET_SIZE,              // maxLen
         0                                  // timeout (0==never)
      );
      ASSERT(dnErr==DN_ERR_NONE);
      ASSERT(msgType==DN_MSG_TYPE_UART_NOTIF);
      
      // print message received
      dnm_ucli_printf("uart RX (%d bytes)",rxLen);
      for (i=0;i<rxLen;i++) {
         dnm_ucli_printf(" %02x",uart_app_v.uartRxBuffer[i]);
      }
      dnm_ucli_printf("\r\n");
   }
}