예제 #1
0
// set the value of the comparison register
// device must already be open
dn_error_t cli_setCompareHandler(const char* arg, INT32U len) {
    dn_error_t      dnErr;
    int             length;
    INT32U          compare;  
    
    //--- param 0: len
    length = sscanf(arg, "%u", &compare);
    if (length != 1) {
       dnm_ucli_printf("Usage: set <cmp>\r\n");   
       return DN_ERR_NONE;
    }
    
    // Registers are 32-bits wide but only 16 bits are useable here
    // for the compare. Setting to >65535 in the dn_ioctl call will 
    // result in an error in future versions of the stack
    dnErr =  dn_ioctl(DN_LPTIMER_DEV_ID, DN_IOCTL_LPTIMER_SET_COMPARE, &compare, sizeof(compare));
    if (dnErr != DN_ERR_NONE)
    {
        dnm_ucli_printf("Failed RC=%d\r\n", dnErr);
        return dnErr;
    }
    
    dnm_ucli_printf("Compare: %u\r\n", compare);
    return DN_ERR_NONE;
}
예제 #2
0
// Register a single command.
static dn_error_t registerCommand(CH_DESC inpCh, const dnm_cli_cmdDef_t * pCmd, int id)
{
   dn_error_t rsp = DN_ERR_NONE;

   INT8U                  cmdLen;
   dn_cli_registerCmd_t  * rCmd;
   INT8U                  buf[DN_CLI_CTRL_SIZE];

   if (pCmd->handler == NULL) {
      return DN_ERR_INVALID;
   }

//   ((dn_cli_ctrlMsg_t *)buf)->cmdId = DN_CLI_CMD_TYPE_REGISTER;

//   rCmd = (dn_cli_registerCmd_t *)(((dn_cli_ctrlMsg_t *)buf)->data);
   rCmd = (dn_cli_registerCmd_t *)buf;
   rCmd->hdr.cmdId    = id;
   rCmd->hdr.chDesc   = inpCh;
   rCmd->hdr.lenCmd   = strlen(pCmd->command);
   rCmd->hdr.accessLevel = pCmd->accessLevel;

   // validate length of registration command
//   cmdLen = sizeof(dn_cli_ctrlMsg_t) + sizeof(dn_cli_registerCmdHdr_t) +
//            rCmd->hdr.lenCmd;
   cmdLen = sizeof(dn_cli_registerCmdHdr_t) + rCmd->hdr.lenCmd;
   
   if (cmdLen > sizeof(buf)) 
      return DN_ERR_ERROR;

   memcpy(rCmd->data, pCmd->command, rCmd->hdr.lenCmd);

   rsp = dn_ioctl(DN_CLI_DEV_ID, DN_IOCTL_CLI_REGISTER, (void *)rCmd, sizeof(dn_cli_registerCmd_t));
   return rsp;
}
예제 #3
0
/**
\brief Switch between blocking and non-blocking output modes.

The CLI device supports blocking and non-blocking output modes:
- in blocking mode, a call to #dn_write() blocks until the bytes are written in
  the CLI output buffer and are scheduled to be printed over the serial port.
- in non-blocking mode, a call to #dn_write() returns immediately, even when
  the serial transmit buffer is full. In this case, the bytes are dropped and
  not printed over the serial port; the characters <tt>...</tt> print over the
  serial port to indicate to the user some characters were dropped.

\param[in] fBlocking Set to <tt>TRUE</tt>  to swicth to     blocking mode;
                     set to <tt>FALSE</tt> to swicth to non-blocking mode.
*/
void dnm_cli_setOutputMode (BOOLEAN fBlocking)
{
   dn_cli_setOutMode_t cliMode;

   cliMode.mode = fBlocking ? DN_CLI_OUT_MODE_BLOCKING : DN_CLI_OUT_MODE_NONBLOCKING;
   dn_ioctl(DN_CLI_DEV_ID, DN_IOCTL_CLI_SET_OUTPUT_MODE, &cliMode, sizeof(cliMode));
}
예제 #4
0
/**
\brief Set the current user access level.

Sets new current user access level. Each command is associated a minimum
access level for each command (#dn_cli_registerCmdHdr_t::accessLevel). Raising
the user access level gives the user access to more commands.

It's your application's responsibility to raise/lower the user access level
appropriately. For example, you could implement a 'login' and 'logout'
CLI command to raise/lower the access level (a parameter for the 'login' CLI
command could be a password).

\post After this function returns, the user may have access to more/less CLI
   commands, depending on the user access level set.

\param[in] newAccessLevel New user access level. Acceptable values are listed
   in dn_cli_access_t.

\return The error received from calling #dn_ioctl() in the \ref device_cli.
*/
dn_error_t dnm_cli_changeAccessLevel(dn_cli_access_t newAccessLevel)
{
   dn_error_t             rsp;
   INT8U                  buf[sizeof(dn_cli_chAccessCmd_t)];
   dn_cli_chAccessCmd_t * rCmd;

   rCmd = (dn_cli_chAccessCmd_t *)buf;
   rCmd->access = (INT8U)newAccessLevel;
   rsp = dn_ioctl(DN_CLI_DEV_ID, DN_IOCTL_CLI_CHANGE_ACCESS, (void *)rCmd, sizeof(dn_cli_chAccessCmd_t));
   return rsp;
}
예제 #5
0
// disable capture in the current mode
dn_error_t cli_disableHandler(const char* arg, INT32U len) {
    dn_error_t               dnErr;

    dnErr =  dn_ioctl(DN_LPTIMER_DEV_ID, DN_IOCTL_LPTIMER_DISABLE, NULL, 0);
    if (dnErr != DN_ERR_NONE)
    {
        dnm_ucli_printf("Disable failed with RC=%d\r\n", dnErr);
        return dnErr;
    }

    return DN_ERR_NONE;
}
예제 #6
0
// get the current value of the capture register
// device must be open
dn_error_t cli_getCaptureHandler(const char* arg, INT32U len) {
    dn_error_t      dnErr;
    INT32U          capture;

    dnErr =  dn_ioctl(DN_LPTIMER_DEV_ID, DN_IOCTL_LPTIMER_GET_CAPTURE,
                &capture, sizeof(capture));
    if (dnErr != DN_ERR_NONE)
    {
        dnm_ucli_printf("Failed RC=%d\r\n", dnErr);
        return dnErr;
    }
    
    dnm_ucli_printf("Capture: %u\r\n", capture);
    return DN_ERR_NONE;
}
예제 #7
0
// get the current value of the counter register
dn_error_t cli_getCounterHandler(const char* arg, INT32U len) {
    dn_error_t      dnErr;
    INT32U          counter;

    dnErr =  dn_ioctl(DN_LPTIMER_DEV_ID, DN_IOCTL_LPTIMER_GET_COUNTER,
                &counter, sizeof(counter));
    if (dnErr != DN_ERR_NONE)
    {
        dnm_ucli_printf("Failed RC=%d\r\n", dnErr);
        return dnErr;
    }
    
    dnm_ucli_printf("Counter: %u\r\n", counter);
    return DN_ERR_NONE;
}
예제 #8
0
/**
\brief A demo task to show the use of the SPI.
*/
static void spiTask(void* unused) {
   INT8U                     i;
   dn_error_t                dnErr;
   INT8U                     osErr;
   dn_spi_open_args_t        spiOpenArgs;
   INT8U                     sendStatus;
   INT8U                     pkBuf[sizeof(loc_sendtoNW_t) + APP_DATA_BUF_SIZE];
   loc_sendtoNW_t*           pkToSend;
   dn_ioctl_spi_transfer_t   spiTransfer;
   
   //===== initialize the configuration file
   initConfigFile();
   
   //===== initialize packet variables
   pkToSend = (loc_sendtoNW_t*)pkBuf;
   
   //===== initialize SPI
   // open the SPI device
   spiOpenArgs.maxTransactionLenForCPHA_1 = 0;
   dnErr = dn_open(
      DN_SPI_DEV_ID,
      &spiOpenArgs,
      sizeof(spiOpenArgs)
   );
   if ((dnErr < DN_ERR_NONE) && (dnErr != DN_ERR_STATE)) {
      dnm_cli_printf("unable to open SPI device, error %d\n\r",dnErr);
   }
   
   // initialize spi communication parameters
   spiTransfer.txData             = spiNetApp_vars.spiTxBuffer;
   spiTransfer.rxData             = spiNetApp_vars.spiRxBuffer;
   spiTransfer.transactionLen     = sizeof(spiNetApp_vars.spiTxBuffer);
   spiTransfer.numSamples         = 1;
   spiTransfer.startDelay         = 0;
   spiTransfer.clockPolarity      = DN_SPI_CPOL_0;
   spiTransfer.clockPhase         = DN_SPI_CPHA_0;
   spiTransfer.bitOrder           = DN_SPI_MSB_FIRST;
   spiTransfer.slaveSelect        = DN_SPI_SSn0;
   spiTransfer.clockDivider       = DN_SPI_CLKDIV_16;
   
   //===== wait for the mote to have joined
   OSSemPend(spiNetApp_vars.joinedSem,0,&osErr);
   ASSERT(osErr == OS_ERR_NONE);
   
   while(1) { // this is a task, it executes forever
      
      //===== step 1. write over SPI
      
      // set bytes to send
      for (i=0;i<sizeof(spiNetApp_vars.spiTxBuffer);i++) {
         spiNetApp_vars.spiTxBuffer[i] = i;
      }
      
      // send bytes
      dnErr = dn_ioctl(
         DN_SPI_DEV_ID,
         DN_IOCTL_SPI_TRANSFER,
         &spiTransfer,
         sizeof(spiTransfer)
      );
      if (dnErr < DN_ERR_NONE) {
         dnm_cli_printf("Unable to communicate over SPI, err=%d\r\n",dnErr);
      }
      
      //===== step 2. print over CLI
      
      dnm_cli_printf("SPI sent:    ");
      for (i=0;i<sizeof(spiNetApp_vars.spiTxBuffer);i++) {
         dnm_cli_printf(" %02x",spiNetApp_vars.spiTxBuffer[i]);
      }
      dnm_cli_printf("\r\n");
      
      dnm_cli_printf("SPI received:");
      for (i=0;i<sizeof(spiNetApp_vars.spiRxBuffer);i++) {
         dnm_cli_printf(" %02x",spiNetApp_vars.spiRxBuffer[i]);
      }
      dnm_cli_printf("\r\n");
      
      //===== step 3. send data to manager
      
      // fill in packet "header"
      // Note: sendto->header is filled in dnm_loc_sendtoCmd
      pkToSend->locSendTo.socketId          = loc_getSocketId();
      pkToSend->locSendTo.destAddr          = DN_MGR_IPV6_MULTICAST_ADDR; // IPv6 address
      pkToSend->locSendTo.destPort          = WKP_SPI_NET;
      pkToSend->locSendTo.serviceType       = DN_API_SERVICE_TYPE_BW;   
      pkToSend->locSendTo.priority          = DN_API_PRIORITY_MED;   
      pkToSend->locSendTo.packetId          = 0xFFFF;
      
      // fill in the packet payload
      memcpy(&pkToSend->locSendTo.payload[0],&spiNetApp_vars.spiRxBuffer[0],APP_DATA_BUF_SIZE);
      
      // send the packet
      dnErr = dnm_loc_sendtoCmd(pkToSend, APP_DATA_BUF_SIZE, &sendStatus);
      ASSERT (dnErr == DN_ERR_NONE);
      
      //===== step 4. pause until next iteration
      
      // this call blocks the task until the specified timeout expires (in ms)
      OSTimeDly(spiNetApp_vars.period);
   }
}
예제 #9
0
/**
\brief A demo task to show the use of the I2C.
*/
static void i2cTask(void* unused) {
   dn_error_t                   dnErr;
   dn_i2c_open_args_t           i2cOpenArgs;
   INT8U                        i;
   INT8U                        txCounter;
   
   //===== open the I2C device
   
   // wait a bit
   OSTimeDly(1000);
   
   // open the I2C device
   i2cOpenArgs.frequency = DN_I2C_FREQ_184_KHZ;
   dnErr = dn_open(
      DN_I2C_DEV_ID,
      &i2cOpenArgs,
      sizeof(i2cOpenArgs)
   );
   ASSERT(dnErr==DN_ERR_NONE); 
   
   while(1) {
      // infinite loop
      
      //===== step 1. write to I2C slave
      
      // wait a bit
      OSTimeDly(1000);
     
      // prepare buffer
      for (i=0;i<I2C_PAYLOAD_LENGTH;i++) {
         i2c_app_v.i2cBuffer[i]             = 0x80+i;
      }
      
      // initialize I2C communication parameters
      i2c_app_v.i2cTransfer.slaveAddress    = I2C_SLAVE_ADDR;
      i2c_app_v.i2cTransfer.writeBuf        = i2c_app_v.i2cBuffer;
      i2c_app_v.i2cTransfer.readBuf         = NULL;
      i2c_app_v.i2cTransfer.writeLen        = sizeof(i2c_app_v.i2cBuffer);
      i2c_app_v.i2cTransfer.readLen         = 0;
      i2c_app_v.i2cTransfer.timeout         = 0xff;
      
      // initiate transaction
      dnErr = dn_ioctl(
         DN_I2C_DEV_ID,
         DN_IOCTL_I2C_TRANSFER,
         &i2c_app_v.i2cTransfer,
         sizeof(i2c_app_v.i2cTransfer)
      );
      
      // print
      if (dnErr==DN_ERR_NONE) {
         dnm_cli_printf("Sent to I2C slave %02x: 0x",I2C_SLAVE_ADDR);
         for (i=0;i<I2C_PAYLOAD_LENGTH;i++) {
            dnm_cli_printf("%02x",i2c_app_v.i2cBuffer[i]);
         }
         dnm_cli_printf("\r\n");         
      } else {
         dnm_cli_printf("Unable to write over I2C, err=%d\r\n",dnErr);
      }
      
      //===== step 2. read from I2C slave
      
      // wait a bit
      OSTimeDly(1000);
      
      // prepare buffer
      memset(i2c_app_v.i2cBuffer,0,sizeof(i2c_app_v.i2cBuffer));
      
      // initialize I2C communication parameters
      i2c_app_v.i2cTransfer.slaveAddress    = I2C_SLAVE_ADDR;
      i2c_app_v.i2cTransfer.writeBuf        = NULL;
      i2c_app_v.i2cTransfer.readBuf         = i2c_app_v.i2cBuffer;
      i2c_app_v.i2cTransfer.writeLen        = 0;
      i2c_app_v.i2cTransfer.readLen         = sizeof(i2c_app_v.i2cBuffer);
      i2c_app_v.i2cTransfer.timeout         = 0xff;
      
      // initiate transaction
      dnErr = dn_ioctl(
         DN_I2C_DEV_ID,
         DN_IOCTL_I2C_TRANSFER,
         &i2c_app_v.i2cTransfer,
         sizeof(i2c_app_v.i2cTransfer)
      );
      
      // print
      if (dnErr==DN_ERR_NONE) {
         dnm_cli_printf("Received from I2C slave %02x: 0x",I2C_SLAVE_ADDR);
         for (i=0;i<I2C_PAYLOAD_LENGTH;i++) {
            dnm_cli_printf("%02x",i2c_app_v.i2cBuffer[i]);
         }
         dnm_cli_printf("\r\n");
      } else {
         dnm_cli_printf("Unable to read over I2C, err=%d\r\n",dnErr);
      }
   }
}