Пример #1
0
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
/**
\brief This is the entry point for the application code.
*/
int p2_init(void) {
   dn_error_t      dnErr;
   INT8U           osErr;
   
   //===== initialize dnm_cli module
   
   // open CLI port
   dnErr = dnm_cli_openPort(DN_CLI_PORT_C0, 9600);
   ASSERT(dnErr==DN_ERR_NONE);
   
   // change CLI access level
   dnErr = dnm_cli_changeAccessLevel(DN_CLI_ACCESS_USER);
   ASSERT(dnErr==DN_ERR_NONE);
   
   //===== initialize dnm_local module
   
   // create a synchronous channel for the dnm_local module to receive notifications from the stack
   dnErr = dn_createSyncChannel(&hello_app_vars.locNotifChannel);
   ASSERT(dnErr==DN_ERR_NONE);
   
   // register that channel to DN_MSG_TYPE_NET_NOTIF notifications
   dnErr = dn_registerChannel(hello_app_vars.locNotifChannel, DN_MSG_TYPE_NET_NOTIF);
   ASSERT(dnErr==DN_ERR_NONE);
   
   // initialize the local interface
   dnErr = dnm_loc_init(
      PASSTHROUGH_OFF,                           // mode
      &hello_app_vars.cliContext,                // cliContext
      0,                                         // TraceFlag
      hello_app_vars.locNotifChannelBuf,         // pBuffer
      sizeof(hello_app_vars.locNotifChannelBuf)  // buffLen
   );
   ASSERT(dnErr==DN_ERR_NONE);
   
   //===== initialize locNotifTask
   
   osErr = OSTaskCreateExt(
      locNotifTask,
      (void *) 0,
      (OS_STK*) (&hello_app_vars.locNotifTaskStack[TASK_APP_LOCNOTIF_STK_SIZE - 1]),
      TASK_APP_LOCNOTIF_PRIORITY,
      TASK_APP_LOCNOTIF_PRIORITY,
      (OS_STK*) hello_app_vars.locNotifTaskStack,
      TASK_APP_LOCNOTIF_STK_SIZE,
      (void *) 0,
      OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR
   );
   ASSERT(osErr == OS_ERR_NONE);
   OSTaskNameSet(TASK_APP_LOCNOTIF_PRIORITY, (INT8U*)TASK_APP_LOCNOTIF_NAME, &osErr);
   ASSERT(osErr == OS_ERR_NONE);
   
   return 0;
}
Пример #3
0
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
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");
   }
}
Пример #5
0
void cli_task_init(dnm_cli_cont_t* cliContext, char* appName, dnm_cli_cmdDef_t* cliCmds) {
   dn_error_t      dnErr;
   INT8U           osErr;
   OS_MEM*         cliChannelMem;
   
   // store params
   cli_task_v.cliContext     = cliContext;
   cli_task_v.appName        = appName;
   cli_task_v.cliCmds        = cliCmds;
   
   // open CLI port
   dnErr = dnm_cli_openPort(DN_CLI_PORT_C0, 9600);
   ASSERT(dnErr==DN_ERR_NONE);

   // change CLI access level
   dnErr = dnm_cli_changeAccessLevel(DN_CLI_ACCESS_USER);
   ASSERT(dnErr==DN_ERR_NONE);
   
   // print appName
   dnm_cli_printf("%s app, ver %d.%d.%d.%d\n\r", cli_task_v.appName,
                                                 VER_MAJOR,
                                                 VER_MINOR,
                                                 VER_PATCH,
                                                 VER_BUILD);
   
   // stop here is no CLI commands to register
   if (cli_task_v.cliCmds==NULL) {
      return;
   }
   
   // create a memory block for CLI notification channel
   cliChannelMem = OSMemCreate(
       cli_task_v.cliChannelBuffer,
       1,
       DN_CH_ASYNC_RXBUF_SIZE(DN_CLI_NOTIF_SIZE),
       &osErr
   );
   ASSERT(osErr==OS_ERR_NONE);
   
   // create the CLI notification channel
   dnErr = dn_createAsyncChannel(
      cliChannelMem,
      &cli_task_v.cliChannelDesc
   );
   ASSERT(dnErr==DN_ERR_NONE);
   
   // register the channel for CLI input messages
   dnErr = dn_registerChannel(
      cli_task_v.cliChannelDesc,
      DN_MSG_TYPE_CLI_NOTIF
   );
   ASSERT(dnErr==DN_ERR_NONE);
   
   // create the CLI task
   osErr = OSTaskCreateExt(
      cliTask,
      NULL,
      (OS_STK*)&cli_task_v.cliTaskStack[CLI_TASK_STK_SIZE-1],
      CLI_TASK_PRIORITY,
      CLI_TASK_PRIORITY,
      (OS_STK*)cli_task_v.cliTaskStack,
      CLI_TASK_STK_SIZE,
      NULL,
      OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR
   );
   ASSERT(osErr==OS_ERR_NONE);
   OSTaskNameSet(CLI_TASK_PRIORITY, CLI_TASK_NAME, &osErr);
   ASSERT(osErr==OS_ERR_NONE);
}