コード例 #1
0
uint32_t serialize_name_value(char* buffer, char* name, char *value)
{
    char *p = buffer;
    uint32_t nl, vl;
    nl = strlen(name);
    vl = strlen(value);

    if( nl < 128 )
        *p++ = BYTE_0(nl);
    else
    {
        *p++ = BYTE_0(nl);
        *p++ = BYTE_1(nl);
        *p++ = BYTE_2(nl);
        *p++ = BYTE_3(nl);
    }

    if ( vl < 128 )
        *p++ = BYTE_0(vl);
    else
    {
        *p++ = BYTE_0(vl);
        *p++ = BYTE_1(vl);
        *p++ = BYTE_2(vl);
        *p++ = BYTE_3(vl);
    }

    memcpy(p, name, nl);
    p+=nl;
    memcpy(p, value, vl);
    p+= vl;

    return p - buffer;
}
コード例 #2
0
ファイル: picldr.c プロジェクト: AlainODea/illumos-gate
static picl_smc_event_t
env_handle_smc_local_event(void *res_datap)
{
	picl_errno_t rc = PICL_SUCCESS;
	uint8_t event = SMC_LOCAL_EVENT;
	uint8_t event_data = BYTE_0(res_datap);

	if (env_debug & EVENTS)
		syslog(LOG_INFO, "Local Event Received, data %x\n", event_data);

	switch (event_data) {
		case SMC_LOCAL_EVENT_BRIDGE_IN_RESET :	/*FALLTHRU*/
		case SMC_LOCAL_EVENT_BRIDGE_OUT_OF_RESET :
			if ((rc = env_platmod_handle_bus_if_change(
				event_data)) != PICL_SUCCESS) {
				syslog(LOG_ERR, gettext("SUNW_envmond:Error"
					" in handling bus interface change "
					"event, error = %d"), rc);
			}
			break;
		case SMC_LOCAL_EVENT_LATCH_OPENED:
			syslog(LOG_INFO, gettext("LATCH OPEN DETECTED"));
			if ((rc = env_platmod_handle_latch_open()) !=
				PICL_SUCCESS) {
				syslog(LOG_ERR, gettext("SUNW_envmond:Error"
					" in handling latch open event, "
					"error = %d"), rc);
			}
			break;
		default:
			break;
	}
	return (event);
}
コード例 #3
0
ファイル: picldr.c プロジェクト: AlainODea/illumos-gate
/*ARGSUSED*/
static picl_smc_event_t
env_process_smc_event(int fd, void **datapp)
{
	sc_rspmsg_t		rsp_msg;
	picl_smc_event_t	event;
	void			*res_datap = NULL;

	if (read(fd, (char *)&rsp_msg, SC_MSG_MAX_SIZE) < 0) {
		return (NO_EVENT);
	}

	if (SC_MSG_CC(&rsp_msg) != 0) {
		return (NO_EVENT);
	}

	res_datap = SC_MSG_DATA(&rsp_msg);
	if (env_debug & EVENTS)
		syslog(LOG_INFO, "Async Msg Cmd,data0,2 = %x,%x,%x\n",
			SC_MSG_CMD(&rsp_msg), BYTE_0(res_datap),
			BYTE_2(res_datap));

	if (SC_MSG_CMD(&rsp_msg) == SMC_SMC_LOCAL_EVENT_NOTIF) {
		event = env_handle_smc_local_event(res_datap);
	} else {	/* it must be an IPMI event */
		switch (BYTE_2(res_datap)) {
		case 0x3:
		case 0x4:
			if (env_debug & DEBUG)
				syslog(LOG_INFO, gettext("SUNW_envmond: "
					" Sensor Event Received\n"));
			/* sensor event */
			switch (BYTE_3(res_datap)) {
			case TEMPERATURE_SENSOR_TYPE:
				event = TEMPERATURE_SENSOR_EVENT;
				env_platmod_handle_sensor_event(res_datap);
				break;
			default:
				syslog(LOG_ERR, gettext("SUNW_envmond:Unknown "
				"sensor Event:%d\n"), BYTE_3(res_datap));
				event = NO_EVENT;
				break;
			}
		default:
			env_handle_async_msg_event(res_datap);
			break;
		}
	}
	return (event);
}
コード例 #4
0
ファイル: flash.c プロジェクト: aiss83/nucbit
static FibStatus fibFlashErase(FibEraseType eraseType, int32u address)
{
    int32u eraseOp;
    int32u *ptr;
    int32u length;
    FibStatus status = FIB_SUCCESS;
    if (BYTE_0(eraseType) == MFB_MASS_ERASE)
    {
        eraseOp = FLASH_CTRL_MASSERASE;
        ptr = (int32u *)MFB_BOTTOM;
        length = MFB_SIZE_W;
    }
    else if (BYTE_0(eraseType) == MFB_PAGE_ERASE)
    {
        if (address < MFB_BOTTOM || address > MFB_TOP)
        {
            return FIB_ERR_INVALID_ADDRESS;
        }
        eraseOp = FLASH_CTRL_PAGEERASE;
        ptr = (int32u *)(address & MFB_PAGE_MASK_B);
        length = MFB_PAGE_SIZE_W;
    }
    else if (BYTE_0(eraseType) == CIB_ERASE)
    {
        eraseOp = FLASH_CTRL_OPTWREN | FLASH_CTRL_OPTERASE;
        ptr = (int32u *)CIB_BOTTOM;
        length = CIB_SIZE_W;
    }
    else
    {
        return FIB_ERR_INVALID_TYPE;
    }
    if ((eraseType & DO_ERASE) != 0)
    {
        enableFlitf();
        FLASH_CTRL = eraseOp;
        if (BYTE_0(eraseType) == MFB_PAGE_ERASE)
        {
            FLASH_ADDR = (address & MFB_PAGE_MASK_B);
        }
        eraseOp |= FLASH_CTRL_FLA_START;
        // Perform the actual erase.
        FLASH_CTRL = eraseOp;
        // Wait for the busy bit to clear, indicating operation is done.
        while ((FLASH_STATUS & FLASH_STATUS_FLA_BSY) != 0) {}
        // Reset the operation complete flag.
        FLASH_STATUS = FLASH_STATUS_EOP;
        // Check for errors; the only relevant one for erasing is write protection.
        if (FLASH_STATUS & FLASH_STATUS_WRP_ERR)
        {
            FLASH_STATUS = FLASH_STATUS_WRP_ERR;
            status = FIB_ERR_WRITE_PROTECTED;
        }
        disableFlitf();
    }
    if (status == FIB_SUCCESS
            && (eraseType & DO_VERIFY) != 0)
    {
        int32u i;
        for (i = 0; i < length; i++)
        {
            if (*ptr != 0xFFFFFFFF)
            {
                return FIB_ERR_VERIFY_FAILED;
            }
            ptr++;
        }
    }
    return status;
}
コード例 #5
0
ファイル: talk.c プロジェクト: ndpr43/CpE5170
#define INACTIVE_TIMEOUT (10 * 4) // 10 seconds
/* Private variables ---------------------------------------------------------*/

/* radioTransmitConfig variables required from the SimpleMac library for packet 
   transmission */
RadioTransmitConfig radioTransmitConfig = RADIO_TRANSMIT_CONFIG_DEFAULTS;

/* generic data packet */
ALIGN_VAR(uint8_t txPacket[128], 2);
uint8_t txPacket[128] = { 
  0x0a, /* length */
  0x61, /* fcf - intra pan, ack request, data */
  0x08, /* fcf - src, dst mode */
  0x00, /* seq */
  BYTE_0(PTP_PAN_ID), /* dst pan l */
  BYTE_1(PTP_PAN_ID), /* dst pan h */
  BYTE_0(PTP_SHORT_ID), /* dst addr */
  BYTE_1(PTP_SHORT_ID), /* dst addr */
  0x00  /* data */
};

/* buffer for received packet */
uint8_t rxPacket[128];
/* received packet flag */
__IO boolean packetReceived = FALSE;
/* Retries counter */
uint8_t retries = MAX_RETRIES;

/* packet transmission complete flag */
__IO boolean txComplete = TRUE;
コード例 #6
0
sint8 m2m_crypto_sha256_hash_finish(tstrM2mSha256Ctxt *pstrSha256Ctxt, uint8 *pu8Sha256Digest)
{
	sint8	s8Ret = M2M_ERR_FAIL;
	tstrSHA256HashCtxt	*pstrSHA256 = (tstrSHA256HashCtxt*)pstrSha256Ctxt;
	if(pstrSHA256 != NULL)
	{
		uint32	u32ReadAddr;
		uint32	u32WriteAddr	= SHARED_MEM_BASE;
		uint32	u32Addr			= u32WriteAddr;
		uint16	u16Offset;
		uint16 	u16PaddingLength;
		uint16	u16NBlocks		= 1;
		uint32	u32RegVal		= 0;
		uint32	u32Idx,u32ByteIdx;
		uint32	au32Digest[M2M_SHA256_DIGEST_LEN / 4];
		uint8	u8IsDone		= 0;

		nm_write_reg(SHA256_CTRL,u32RegVal);
		u32RegVal |= SHA256_CTRL_FORCE_SHA256_QUIT_MASK;
		nm_write_reg(SHA256_CTRL,u32RegVal);

		if(pstrSHA256->u8InitHashFlag)
		{
			pstrSHA256->u8InitHashFlag = 0;
			u32RegVal |= SHA256_CTRL_INIT_SHA256_STATE_MASK;
		}

		/* Calculate the offset of the last data byte in the current block. */
		u16Offset = (uint16)(pstrSHA256->u32TotalLength % SHA_BLOCK_SIZE);

		/* Add the padding byte 0x80. */
		pstrSHA256->au8CurrentBlock[u16Offset ++] = 0x80;

		/* Calculate the required padding to complete
		one Hash Block Size.
		*/
		u16PaddingLength = SHA_BLOCK_SIZE - u16Offset;
		m2m_memset(&pstrSHA256->au8CurrentBlock[u16Offset], 0, u16PaddingLength);

		/* If the padding count is not enough to hold 64-bit representation of
		the total input message length, one padding block is required.
		*/
		if(u16PaddingLength < 8)
		{
			nm_write_block(u32Addr, pstrSHA256->au8CurrentBlock, SHA_BLOCK_SIZE);
			u32Addr += SHA_BLOCK_SIZE;
			m2m_memset(pstrSHA256->au8CurrentBlock, 0, SHA_BLOCK_SIZE);
			u16NBlocks ++;
		}

		/* pack the length at the end of the padding block */
		PUTU32(pstrSHA256->u32TotalLength << 3, pstrSHA256->au8CurrentBlock, (SHA_BLOCK_SIZE - 4));

		u32ReadAddr = u32WriteAddr + (u16NBlocks * SHA_BLOCK_SIZE);
		nm_write_block(u32Addr, pstrSHA256->au8CurrentBlock, SHA_BLOCK_SIZE);
		nm_write_reg(SHA256_DATA_LENGTH, (u16NBlocks * SHA_BLOCK_SIZE));
		nm_write_reg(SHA256_START_RD_ADDR, u32WriteAddr);
		nm_write_reg(SHA256_START_WR_ADDR, u32ReadAddr);

		u32RegVal |= SHA256_CTRL_START_CALC_MASK;
		u32RegVal |= SHA256_CTRL_WR_BACK_HASH_VALUE_MASK;
		u32RegVal &= ~(0x7UL << 8);
		u32RegVal |= (0x2UL << 8);

		nm_write_reg(SHA256_CTRL,u32RegVal);


		/* 5.	Wait for done_intr */
		while(!u8IsDone)
		{
			u32RegVal = nm_read_reg(SHA256_DONE_INTR_STS);
			u8IsDone = u32RegVal & NBIT0;
		}
		nm_read_block(u32ReadAddr, (uint8*)au32Digest, 32);
		
		/* Convert the output words to an array of bytes.
		*/
		u32ByteIdx = 0;
		for(u32Idx = 0; u32Idx < (M2M_SHA256_DIGEST_LEN / 4); u32Idx ++)
		{
			pu8Sha256Digest[u32ByteIdx ++] = BYTE_3(au32Digest[u32Idx]);
			pu8Sha256Digest[u32ByteIdx ++] = BYTE_2(au32Digest[u32Idx]);
			pu8Sha256Digest[u32ByteIdx ++] = BYTE_1(au32Digest[u32Idx]);
			pu8Sha256Digest[u32ByteIdx ++] = BYTE_0(au32Digest[u32Idx]);
		}
		s8Ret = M2M_SUCCESS;
	}
	return s8Ret;
}
コード例 #7
0
// A pairing index value of 0xFF means "local attributes".
void emAfRf4ceZrcReadOrWriteAttribute(uint8_t pairingIndex,
                                      uint8_t attrId,
                                      uint16_t entryIdOrValueLength,
                                      bool isRead,
                                      uint8_t *val)
{
  bool localAttributes = (pairingIndex == 0xFF);
  EmAfRf4ceZrcAttributes *attributes = (localAttributes)
                                       ? &emAfRf4ceZrcLocalNodeAttributes
                                       : &emAfRf4ceZrcRemoteNodeAttributes;

  if (isRead) {
    switch (attrId) {
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_VERSION:
      val[0] = LOW_BYTE(attributes->zrcProfileVersion);
      val[1] = HIGH_BYTE(attributes->zrcProfileVersion);
      break;
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_CAPABILITIES:
    {
      uint32_t cababilities = ((pairingIndex == 0xFF)
                             ? emAfRf4ceZrcGetLocalNodeCapabilities()
                             : emAfRf4ceZrcGetRemoteNodeCapabilities(pairingIndex));
      val[0] = BYTE_0(cababilities);
      val[1] = BYTE_1(cababilities);
      val[2] = BYTE_2(cababilities);
      val[3] = BYTE_3(cababilities);
    }
      break;
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_ACTION_BANKS_SUPPORTED_RX:
      MEMCOPY(val, attributes->actionBanksSupportedRx->contents, ZRC_BITMASK_SIZE);
      break;
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_ACTION_BANKS_SUPPORTED_TX:
      MEMCOPY(val, attributes->actionBanksSupportedTx->contents, ZRC_BITMASK_SIZE);
      break;
#if (defined(EMBER_AF_PLUGIN_RF4CE_ZRC20_LOCAL_IRDB_VENDOR_ATTRIBUTE_SUPPORT)       \
     || defined(EMBER_AF_PLUGIN_RF4CE_ZRC20_REMOTE_IRDB_VENDOR_ATTRIBUTES_SUPPORT)  \
     || defined(EMBER_SCRIPTED_TEST))
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_IRDB_VENDOR_SUPPORT:
    {
      // Can't just perform a MEMCOPY, endianness matters.
      uint8_t i;
      uint8_t entriesNum = (localAttributes
                          ? EMBER_AF_RF4CE_ZRC_IRDB_VENDOR_ID_COUNT
                          : EMBER_AF_PLUGIN_RF4CE_ZRC20_REMOTE_IRDB_VENDORS_SUPPORTED_TABLE_SIZE);

      // Non-valid entries are set to EMBER_RF4CE_NULL_VENDOR_ID.
      for(i=0; (i<entriesNum
                && attributes->IRDBVendorSupport[i] != EMBER_RF4CE_NULL_VENDOR_ID);
          i++) {
        val[2*i] = LOW_BYTE(attributes->IRDBVendorSupport[i]);
        val[2*i+1] = HIGH_BYTE(attributes->IRDBVendorSupport[i]);
      }
    }
      break;
#endif // EMBER_AF_PLUGIN_RF4CE_ZRC20_LOCAL_IRDB_VENDOR_ATTRIBUTE_SUPPORT || EMBER_AF_PLUGIN_RF4CE_ZRC20_REMOTE_IRDB_VENDOR_ATTRIBUTES_SUPPORT
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_ACTION_BANKS_VERSION:
      val[0] = LOW_BYTE(attributes->zrcActionBanksVersion);
      val[1] = HIGH_BYTE(attributes->zrcActionBanksVersion);
      break;
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_ACTION_CODES_SUPPORTED_RX:
#if (defined (EMBER_AF_RF4CE_ZRC_IS_HA_ACTIONS_RECIPIENT) || defined(EMBER_SCRIPTED_TEST))
      // RX action codes related to HA action banks should be all 0xFF if the
      // node is an HA actions recipient.
      if (entryIdOrValueLength >= EMBER_AF_RF4CE_ZRC_ACTION_BANK_HOME_AUTOMATION_INSTANCE_0
          && entryIdOrValueLength <= EMBER_AF_RF4CE_ZRC_ACTION_BANK_HOME_AUTOMATION_INSTANCE_31) {
        MEMSET(val, 0xFF, ZRC_BITMASK_SIZE);
        break;
      }
      // Fall-through here
#endif // EMBER_AF_RF4CE_ZRC_IS_HA_ACTIONS_RECIPIENT
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_ACTION_CODES_SUPPORTED_TX:
    {
      uint8_t *attrPtr = emAfRf4ceZrcGetActionCodesAttributePointer(attrId,
                                                                  entryIdOrValueLength,
                                                                  pairingIndex);
      assert(attrPtr != NULL);
      MEMCOPY(val, attrPtr, ZRC_BITMASK_SIZE);
      break;
    }
#if defined(EMBER_AF_PLUGIN_RF4CE_ZRC20_ACTION_MAPPING_SUPPORT) || defined(EMBER_SCRIPTED_TEST)
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_MAPPABLE_ACTIONS:
    {
      EmberAfRf4ceZrcMappableAction mappableAction;
      assert (emberAfPluginRf4ceZrc20GetMappableActionCallback(pairingIndex,
                                                               entryIdOrValueLength,
                                                               &mappableAction)
              == EMBER_SUCCESS);

      val[MAPPABLE_ACTION_ACTION_DEVICE_TYPE_OFFSET] = mappableAction.actionDeviceType;
      val[MAPPABLE_ACTION_ACTION_BANK_OFFSET] = mappableAction.actionBank;
      val[MAPPABLE_ACTION_ACTION_CODE_OFFSET] = mappableAction.actionCode;
    }
      break;
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_ACTION_MAPPINGS:
    {
      EmberAfRf4ceZrcActionMapping actionMapping;
      assert (emberAfPluginRf4ceZrc20GetActionMappingCallback(pairingIndex,
                                                              entryIdOrValueLength,
                                                              &actionMapping)
              == EMBER_SUCCESS);

      *val++ = actionMapping.mappingFlags;
      if (READBITS(actionMapping.mappingFlags,
                   (EMBER_AF_RF4CE_ZRC_ACTION_MAPPING_MAPPING_FLAGS_RF_SPECIFIED_BIT
                     | EMBER_AF_RF4CE_ZRC_ACTION_MAPPING_MAPPING_FLAGS_USE_DEFAULT_BIT))
          == EMBER_AF_RF4CE_ZRC_ACTION_MAPPING_MAPPING_FLAGS_RF_SPECIFIED_BIT) {
        *val++ = actionMapping.rfConfig;
        *val++ = actionMapping.rf4ceTxOptions;
        *val++ = actionMapping.actionDataLength;
        assert(actionMapping.actionData != NULL);
        MEMCOPY(val, actionMapping.actionData, actionMapping.actionDataLength);
        val += actionMapping.actionDataLength;
      }

      if (READBITS(actionMapping.mappingFlags,
                   (EMBER_AF_RF4CE_ZRC_ACTION_MAPPING_MAPPING_FLAGS_IR_SPECIFIED_BIT
                     | EMBER_AF_RF4CE_ZRC_ACTION_MAPPING_MAPPING_FLAGS_USE_DEFAULT_BIT))
          == EMBER_AF_RF4CE_ZRC_ACTION_MAPPING_MAPPING_FLAGS_IR_SPECIFIED_BIT) {
        *val++ = actionMapping.irConfig;
        if (actionMapping.irConfig
            & ACTION_MAPPING_IR_CONFIG_VENDOR_SPECIFIC_BIT) {
          *val++ = LOW_BYTE(actionMapping.irVendorId);
          *val++ = HIGH_BYTE(actionMapping.irVendorId);
        }
        *val++ = actionMapping.irCodeLength;
        assert(actionMapping.irCode != NULL);
        MEMCOPY(val, actionMapping.irCode, actionMapping.irCodeLength);
      }
    }
      break;
#endif // EMBER_AF_PLUGIN_RF4CE_ZRC20_ACTION_MAPPING_SUPPORT

#if (defined(EMBER_AF_RF4CE_ZRC_IS_HA_ACTIONS_ORIGINATOR)             \
     || defined (EMBER_AF_RF4CE_ZRC_IS_HA_ACTIONS_RECIPIENT)          \
     || defined(EMBER_SCRIPTED_TEST))
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_HOME_AUTOMATION:
      // This attribute can only be pulled and is stored at the application.
      // This plugin can only access this attribute via callback. As result,
      // we will get here only after having called (and it returns 'success')
      // emAfRf4ceZrcIsArrayedAttributeSupported() in the pullAttributes()
      // handler function. emAfRf4ceZrcIsArrayedAttributeSupported() saves the
      // contents in the static object tempHaAttribute. So we just copy it
      // here.
      assert(tempHaAttribute.contentsLength < (MAX_ZRC_ATTRIBUTE_SIZE - 1));
      *val++ = HA_ATTRIBUTE_STATUS_VALUE_AVAILABLE_FLAG;
      MEMCOPY(val, tempHaAttribute.contents, tempHaAttribute.contentsLength);
      break;
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_HOME_AUTOMATION_SUPPORTED:
      emberAfPluginRf4ceZrc20GetHomeAutomationSupportedCallback(pairingIndex,
                                                                entryIdOrValueLength,
                                                                (EmberAfRf4ceZrcHomeAutomationSupported*)val);
      break;
#endif // EMBER_AF_RF4CE_ZRC_IS_HA_ACTIONS_ORIGINATOR || EMBER_AF_RF4CE_ZRC_IS_HA_ACTIONS_RECIPIENT
    }
  } else { // !isRead
    switch (attrId) {
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_VERSION:
      attributes->zrcProfileVersion = HIGH_LOW_TO_INT(val[1], val[0]);
      break;
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_CAPABILITIES:
      // We only allow setting remote nodes capabilities.
      if (pairingIndex < 0xFF) {
        emAfRf4ceZrcSetRemoteNodeCapabilities(pairingIndex,
                                              emberFetchLowHighInt32u(val));
      }
      break;
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_ACTION_BANKS_SUPPORTED_RX:
      MEMCOPY(attributes->actionBanksSupportedRx->contents, val, ZRC_BITMASK_SIZE);
      break;
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_ACTION_BANKS_SUPPORTED_TX:
      MEMCOPY(attributes->actionBanksSupportedTx->contents, val, ZRC_BITMASK_SIZE);
      break;
#if defined(EMBER_AF_PLUGIN_RF4CE_ZRC20_REMOTE_IRDB_VENDOR_ATTRIBUTES_SUPPORT) || defined(EMBER_SCRIPTED_TEST)
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_IRDB_VENDOR_SUPPORT:
    {
      // Only remote IRDB vendor support attributes can written.
      uint8_t i;
      for (i=0; i < EMBER_AF_PLUGIN_RF4CE_ZRC20_REMOTE_IRDB_VENDORS_SUPPORTED_TABLE_SIZE; i++) {
        uint16_t vendorId;
        if (i < entryIdOrValueLength / 2) {
          vendorId = HIGH_LOW_TO_INT(val[2*i+1], val[2*i]);
        } else {
          // The rest of the entries are set to NULL_VENDOR_ID.
          vendorId = EMBER_RF4CE_NULL_VENDOR_ID;
        }

        attributes->IRDBVendorSupport[i] = vendorId;

#if defined(EMBER_SCRIPTED_TEST)
        simpleScriptCheck("", "Remote IRDB attribute, entry set", "ii",
                          i,
                          vendorId);
#endif // EMBER_SCRIPTED_TEST
      }
    }
      break;
#endif // EMBER_AF_PLUGIN_RF4CE_ZRC20_REMOTE_IRDB_VENDOR_ATTRIBUTES_SUPPORT
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_ACTION_BANKS_VERSION:
      attributes->zrcActionBanksVersion = HIGH_LOW_TO_INT(val[1], val[0]);
      break;
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_ACTION_CODES_SUPPORTED_RX:
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_ACTION_CODES_SUPPORTED_TX:
    {
      uint8_t *attrPtr = emAfRf4ceZrcGetActionCodesAttributePointer(attrId,
                                                                  entryIdOrValueLength,
                                                                  pairingIndex);
      assert(attrPtr != NULL);
      MEMCOPY(attrPtr, val, ZRC_BITMASK_SIZE);
      break;
    }

#if defined(EMBER_AF_PLUGIN_RF4CE_ZRC20_ACTION_MAPPING_SUPPORT) || defined(EMBER_SCRIPTED_TEST)
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_MAPPABLE_ACTIONS:
    {
      EmberAfRf4ceZrcMappableAction mappableAction;
      mappableAction.actionDeviceType = val[0];
      mappableAction.actionBank = val[1];
      mappableAction.actionCode = val[2];
      emberAfPluginRf4ceZrc20IncomingMappableActionCallback(emberAfRf4ceGetPairingIndex(),
                                                            entryIdOrValueLength,
                                                            &mappableAction);
    }
      break;
    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_ACTION_MAPPINGS:
    {
      EmberAfRf4ceZrcActionMapping actionMapping;
      uint8_t *finger = val;
      actionMapping.actionData = NULL;
      actionMapping.irCode = NULL;

      // Mapping flags
      actionMapping.mappingFlags = *finger++;

      // RF descriptor
      if (READBITS(actionMapping.mappingFlags,
                   (EMBER_AF_RF4CE_ZRC_ACTION_MAPPING_MAPPING_FLAGS_RF_SPECIFIED_BIT
                     | EMBER_AF_RF4CE_ZRC_ACTION_MAPPING_MAPPING_FLAGS_USE_DEFAULT_BIT))
          == EMBER_AF_RF4CE_ZRC_ACTION_MAPPING_MAPPING_FLAGS_RF_SPECIFIED_BIT) {
        actionMapping.rfConfig = *finger++;
        actionMapping.rf4ceTxOptions = *finger++;
        actionMapping.actionDataLength = *finger++;
        actionMapping.actionData = finger;
        finger += actionMapping.actionDataLength;
      }

      // IR descriptor
      if (READBITS(actionMapping.mappingFlags,
                   (EMBER_AF_RF4CE_ZRC_ACTION_MAPPING_MAPPING_FLAGS_IR_SPECIFIED_BIT
                     | EMBER_AF_RF4CE_ZRC_ACTION_MAPPING_MAPPING_FLAGS_USE_DEFAULT_BIT))
          == EMBER_AF_RF4CE_ZRC_ACTION_MAPPING_MAPPING_FLAGS_IR_SPECIFIED_BIT) {
        actionMapping.irConfig = *finger++;
        if (actionMapping.irConfig
            & ACTION_MAPPING_IR_CONFIG_VENDOR_SPECIFIC_BIT) {
          actionMapping.irVendorId = HIGH_LOW_TO_INT(finger[1], finger[0]);
          finger += 2;
        }
        actionMapping.irCodeLength = *finger++;
        actionMapping.irCode = finger;
      }

      emberAfPluginRf4ceZrc20IncomingActionMappingCallback(emberAfRf4ceGetPairingIndex(),
                                                           entryIdOrValueLength,
                                                           &actionMapping);
    }
      break;
#endif // EMBER_AF_PLUGIN_RF4CE_ZRC20_ACTION_MAPPING_SUPPORT

#if (defined(EMBER_AF_RF4CE_ZRC_IS_HA_ACTIONS_ORIGINATOR)             \
     || defined (EMBER_AF_RF4CE_ZRC_IS_HA_ACTIONS_RECIPIENT)          \
     || defined(EMBER_SCRIPTED_TEST))

    // EMBER_AF_RF4CE_ZRC_ATTRIBUTE_HOME_AUTOMATION attributes sets are handled
    // in the HA action code.

    case EMBER_AF_RF4CE_ZRC_ATTRIBUTE_HOME_AUTOMATION_SUPPORTED:
      emberAfPluginRf4ceZrc20IncomingHomeAutomationSupportedCallback(emberAfRf4ceGetPairingIndex(),
                                                                     entryIdOrValueLength,
                                                                     (EmberAfRf4ceZrcHomeAutomationSupported*)val);
      break;
#endif // EMBER_AF_RF4CE_ZRC_IS_HA_ACTIONS_ORIGINATOR || EMBER_AF_RF4CE_ZRC_IS_HA_ACTIONS_RECIPIENT
    }
  }
}
コード例 #8
0
void fcgi_header_set_request_id(fcgi_header *h, uint16_t request_id)
{
    h->request_id_lo = BYTE_0(request_id);
    h->request_id_hi = BYTE_1(request_id);
}
コード例 #9
0
ファイル: main.c プロジェクト: KNVRK/STM8SProjects
/**
  * @brief How to Write byte / Write word / Erase a block on FLASH memory.
  * @par Example description
  * - Program 32/64 (FLASH_BLOCK_SIZE/2) bytes from flash program memory end physical address minus FLASH_BLOCK_SIZE up to 
	*   flash program memory end physical address minus FLASH_BLOCK_SIZE/2.
  * - Check programmed bytes
  * - Program 8/16 (FLASH_BLOCK_SIZE/8) words from flash program memory end physical address minus FLASH_BLOCK_SIZE/2 up to 
	*   flash program memory end physical address.
  * - Checked programmed words
  * - Erase the last block in flash program memory
  * - Check erase
  * @par Parameters:
  * None
  * @retval 
  * None
  */
void main(void)
{
    u32 add, start_add, stop_add, new_val2 =0;
    u8 new_val1, val =0;
    u16 block =0;
    u8 i =0;

    _fctcpy('b');

    /* Define flash programming Time */
    FLASH_SetProgrammingTime(FLASH_PROGRAMTIME_STANDARD);

    /* Unlock Program memory */
    FLASH_Unlock(FLASH_MEMTYPE_PROG);
    /* Program FLASH_BLOCK_SIZE/2 bytes & check */
    start_add = FLASH_PROG_END_PHYSICAL_ADDRESS - FLASH_BLOCK_SIZE +1;
    stop_add = start_add + FLASH_BLOCK_SIZE/2;
    new_val1 = 0x55;
    for (add = start_add; add < stop_add; add++)
            {
                FLASH_ProgramByte(add, new_val1);
                if (FLASH_ReadByte(add) != new_val1)
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }
            }

    /* Program FLASH_BLOCK_SIZE/8 words & check */
    start_add = stop_add;
    stop_add = FLASH_PROG_END_PHYSICAL_ADDRESS;
    new_val2 = 0x12345678;
    add = start_add;
    for (i = 0; i < FLASH_BLOCK_SIZE/8; i++)
    {
        FLASH_ProgramWord(add, new_val2);
        add = add + 4;
    }

    /* check */
    for (add = start_add; add < stop_add; add++)
            {

                val = FLASH_ReadByte(add);
                if (val != BYTE_3(new_val2))
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }

                add += 1;
                val = FLASH_ReadByte(add);
                if (val != BYTE_2(new_val2))
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }

                add += 1;
                val = FLASH_ReadByte(add);
                if (val != BYTE_1(new_val2))
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }

                add += 1;
                val = FLASH_ReadByte(add);
                if (val != BYTE_0(new_val2))
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }
            }

    /* Erase the last block & check */
    block = FLASH_PROG_BLOCKS_NUMBER -1; /* Last block of Flash program memory */
    start_add = FLASH_PROG_END_PHYSICAL_ADDRESS - FLASH_BLOCK_SIZE +1;
    stop_add = FLASH_PROG_END_PHYSICAL_ADDRESS;
		/* Without calling the FLASH_WaitForLastOperation function */
		/* When the program goes back to Flash program memory, it is stalled untill the block erase operation is complete.*/
    FLASH_EraseBlock(block, FLASH_MEMTYPE_PROG);

    for (add = start_add; add < stop_add; add++)
            {
                if (FLASH_ReadByte(add) != 0x00)
                {
                    /* Error */
                    OperationStatus = FAILED;
                    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
                    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
                    while (1);
                }
            }

    /* Pass */
    OperationStatus = PASSED;
    /* OperationStatus = PASSED, if the data written/read to/from FLASH Program memory is correct */
    /* OperationStatus = FAILED, if the data written/read to/from FLASH Program memory is corrupted */
    while (1);

}
コード例 #10
0
ファイル: m2m_wifi.c プロジェクト: JacobV90/Embedded_Project
/**
*	@fn			m2m_wifi_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr, uint8 grp)
*	@brief		WiFi call back function
*	@param [in]	u8OpCode
*					HIF Opcode type.
*	@param [in]	u16DataSize
*					HIF data length.
*	@param [in]	u32Addr
*					HIF address.
*	@param [in]	grp
*					HIF group type.
*	@author
*	@date
*	@version	1.0
*/
static void m2m_wifi_cb(uint8 u8OpCode, uint16 u16DataSize, uint32 u32Addr)
{
	uint8 rx_buf[8];
	if (u8OpCode == M2M_WIFI_RESP_CON_STATE_CHANGED)
	{
		tstrM2mWifiStateChanged strState;
		if (hif_receive(u32Addr, (uint8*) &strState,sizeof(tstrM2mWifiStateChanged), 0) == M2M_SUCCESS)
		{
			if (gpfAppWifiCb)
				gpfAppWifiCb(M2M_WIFI_RESP_CON_STATE_CHANGED, &strState);
		}
	}
	else if (u8OpCode == M2M_WIFI_RESP_GET_SYS_TIME)
	{
		tstrSystemTime strSysTime;
		if (hif_receive(u32Addr, (uint8*) &strSysTime,sizeof(tstrSystemTime), 0) == M2M_SUCCESS)
		{
			if (gpfAppWifiCb)
				gpfAppWifiCb(M2M_WIFI_RESP_GET_SYS_TIME, &strSysTime);
		}
	}
	else if(u8OpCode == M2M_WIFI_RESP_CONN_INFO)
	{
		tstrM2MConnInfo		strConnInfo;
		if(hif_receive(u32Addr, (uint8*)&strConnInfo, sizeof(tstrM2MConnInfo), 1) == M2M_SUCCESS)
		{
			if(gpfAppWifiCb)
				gpfAppWifiCb(M2M_WIFI_RESP_CONN_INFO, &strConnInfo);
		}
	}
	else if (u8OpCode == M2M_WIFI_RESP_MEMORY_RECOVER)
	{
#if 0
		if (hif_receive(u32Addr, rx_buf, 4, 1) == M2M_SUCCESS)
		{
			tstrM2mWifiStateChanged strState;
			m2m_memcpy((uint8*) &strState, rx_buf,sizeof(tstrM2mWifiStateChanged));
			if (app_wifi_recover_cb)
				app_wifi_recover_cb(strState.u8CurrState);
		}
#endif
	}
	else if (u8OpCode == M2M_WIFI_REQ_DHCP_CONF)
	{
		tstrM2MIPConfig strIpConfig;
		if (hif_receive(u32Addr, (uint8 *)&strIpConfig, sizeof(tstrM2MIPConfig), 0) == M2M_SUCCESS)
		{
			if (gpfAppWifiCb)
				gpfAppWifiCb(M2M_WIFI_REQ_DHCP_CONF, (uint8 *)&strIpConfig);
		}
	}
	else if (u8OpCode == M2M_WIFI_REQ_WPS)
	{
		tstrM2MWPSInfo strWps;
		m2m_memset((uint8*)&strWps,0,sizeof(tstrM2MWPSInfo));
		if(hif_receive(u32Addr, (uint8*)&strWps, sizeof(tstrM2MWPSInfo), 0) == M2M_SUCCESS)
		{
			if (gpfAppWifiCb)
				gpfAppWifiCb(M2M_WIFI_REQ_WPS, &strWps);
		}
	}
	else if (u8OpCode == M2M_WIFI_RESP_IP_CONFLICT)
	{
		uint32  u32ConflictedIP;
		if(hif_receive(u32Addr, (uint8 *)&u32ConflictedIP, sizeof(u32ConflictedIP), 0) == M2M_SUCCESS)
		{
			M2M_INFO("Conflicted IP \" %u.%u.%u.%u \" \n",
				BYTE_0(u32ConflictedIP),BYTE_1(u32ConflictedIP),BYTE_2(u32ConflictedIP),BYTE_3(u32ConflictedIP));
			if (gpfAppWifiCb)
				gpfAppWifiCb(M2M_WIFI_RESP_IP_CONFLICT, NULL);

		}
	}
	else if (u8OpCode == M2M_WIFI_RESP_SCAN_DONE)
	{
		tstrM2mScanDone strState;
		gu8scanInProgress = 0;
		if(hif_receive(u32Addr, (uint8*)&strState, sizeof(tstrM2mScanDone), 0) == M2M_SUCCESS)
		{
			gu8ChNum = strState.u8NumofCh;
			if (gpfAppWifiCb)
				gpfAppWifiCb(M2M_WIFI_RESP_SCAN_DONE, &strState);
		}
	}
	else if (u8OpCode == M2M_WIFI_RESP_SCAN_RESULT)
	{
		tstrM2mWifiscanResult strScanResult;
		if(hif_receive(u32Addr, (uint8*)&strScanResult, sizeof(tstrM2mWifiscanResult), 0) == M2M_SUCCESS)
		{
			if (gpfAppWifiCb)
				gpfAppWifiCb(M2M_WIFI_RESP_SCAN_RESULT, &strScanResult);
		}
	}
	else if (u8OpCode == M2M_WIFI_RESP_CURRENT_RSSI)
	{
		if (hif_receive(u32Addr, rx_buf, 4, 0) == M2M_SUCCESS)
		{
			if (gpfAppWifiCb)
				gpfAppWifiCb(M2M_WIFI_RESP_CURRENT_RSSI, rx_buf);
		}
	}
	else if (u8OpCode == M2M_WIFI_RESP_CLIENT_INFO)
	{
		if (hif_receive(u32Addr, rx_buf, 4, 0) == M2M_SUCCESS)
		{
			if (gpfAppWifiCb)
				gpfAppWifiCb(M2M_WIFI_RESP_CLIENT_INFO, rx_buf);
		}
	}
	else if(u8OpCode == M2M_WIFI_RESP_PROVISION_INFO)
	{
		tstrM2MProvisionInfo	strProvInfo;
		if(hif_receive(u32Addr, (uint8*)&strProvInfo, sizeof(tstrM2MProvisionInfo), 1) == M2M_SUCCESS)
		{
			if(gpfAppWifiCb)
				gpfAppWifiCb(M2M_WIFI_RESP_PROVISION_INFO, &strProvInfo);
		}
	}
	else if(u8OpCode == M2M_WIFI_RESP_DEFAULT_CONNECT)
	{
		tstrM2MDefaultConnResp	strResp;
		if(hif_receive(u32Addr, (uint8*)&strResp, sizeof(tstrM2MDefaultConnResp), 1) == M2M_SUCCESS)
		{
			if(gpfAppWifiCb)
				gpfAppWifiCb(M2M_WIFI_RESP_DEFAULT_CONNECT, &strResp);
		}
	}
#ifdef ETH_MODE
		else if(u8OpCode == M2M_WIFI_RESP_ETHERNET_RX_PACKET)
		{
			if(hif_receive(u32Addr, rx_buf ,sizeof(tstrM2mIpRsvdPkt), 0) == M2M_SUCCESS)
			{
				tstrM2mIpRsvdPkt * pstrM2MIpRxPkt = (tstrM2mIpRsvdPkt*)rx_buf;
				tstrM2mIpCtrlBuf  strM2mIpCtrlBuf;
				uint16 u16Offset = pstrM2MIpRxPkt->u16PktOffset;

				strM2mIpCtrlBuf.u16RemainigDataSize = pstrM2MIpRxPkt->u16PktSz;
				if((gpfAppEthCb) &&(gau8ethRcvBuf)&& (gu16ethRcvBufSize > 0))
				{
					while (strM2mIpCtrlBuf.u16RemainigDataSize > 0)
					{
						if(strM2mIpCtrlBuf.u16RemainigDataSize > gu16ethRcvBufSize)
						{
							strM2mIpCtrlBuf.u16DataSize = gu16ethRcvBufSize ;
						}
						else
						{
							strM2mIpCtrlBuf.u16DataSize = strM2mIpCtrlBuf.u16RemainigDataSize;
						}
						if(hif_receive(u32Addr+u16Offset, gau8ethRcvBuf, strM2mIpCtrlBuf.u16DataSize, 0) == M2M_SUCCESS)
						{
							strM2mIpCtrlBuf.u16RemainigDataSize -= strM2mIpCtrlBuf.u16DataSize;
							u16Offset += strM2mIpCtrlBuf.u16DataSize;
							gpfAppEthCb(M2M_WIFI_RESP_ETHERNET_RX_PACKET, gau8ethRcvBuf, &(strM2mIpCtrlBuf));
						}
						else
						{
							break;
						}
					}
				}
			}
		}
#endif

#ifdef CONF_MGMT
	else if(u8OpCode == M2M_WIFI_RESP_WIFI_RX_PACKET)
	{
		tstrM2MWifiRxPacketInfo		strRxPacketInfo;
		if(u16DataSize >= sizeof(tstrM2MWifiRxPacketInfo)) {
			if(hif_receive(u32Addr, (uint8*)&strRxPacketInfo, sizeof(tstrM2MWifiRxPacketInfo), 0) == M2M_SUCCESS)
			{
				u16DataSize -= sizeof(tstrM2MWifiRxPacketInfo);
				if(u16DataSize > 0 && gstrMgmtCtrl.pu8Buf != NULL)
				{
					if(u16DataSize > (gstrMgmtCtrl.u16Sz + gstrMgmtCtrl.u16Offset))
					{
						u16DataSize = gstrMgmtCtrl.u16Sz;
					}
					u32Addr += sizeof(tstrM2MWifiRxPacketInfo) + gstrMgmtCtrl.u16Offset;
					if(hif_receive(u32Addr , gstrMgmtCtrl.pu8Buf, u16DataSize, 1) != M2M_SUCCESS)
					{
						u16DataSize = 0;
					}
				}
				if(gpfAppMonCb)
					gpfAppMonCb(&strRxPacketInfo, gstrMgmtCtrl.pu8Buf,u16DataSize);
			}
		} else {
			M2M_ERR("Incorrect mon data size %u\n", u16DataSize);
		}
	}
#endif
	else
	{
		M2M_ERR("REQ Not defined %d\n",u8OpCode);
	}
}
コード例 #11
0
ファイル: Def_Para.c プロジェクト: Tulga11201/meter-645-2007
}
*/

//默认校表参数
CONST INT8U Def_SDI_ADJ_METER_PUL_VOL_CUR_SPEC[]={0x00,0x01,0x00};
CONST INT8U Def_SDI_ADJ_METER_PARA_STATUS[]={0x00};
/*
CONST INT8U Def_ADJ_METER_A_POW[36]={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
                                     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,\
                                     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
CONST INT8U Def_MeterAddr0[]={0x00,0x00,0x00,0x00,0x00,0x00};
CONST INT8U Def_MeterAddr1[]={0x00,0x00,0x00,0x00,0x00,0x00};
*/
CONST INT8U Def_SDI_ADJ_METER_A_POW[]= 
{
BYTE_0(0x000C491E),BYTE_1(0x000C491E),BYTE_2(0x000C491E),
BYTE_0(0x000D08FA),BYTE_1(0x000D08FA),BYTE_2(0x000D08FA),
BYTE_0(0x000C3D32),BYTE_1(0x000C3D32),BYTE_2(0x000C3D32),
          
BYTE_0(0x00000000),BYTE_1(0x00000000),BYTE_2(0x00000000),
BYTE_0(0x00000000),BYTE_1(0x00000000),BYTE_2(0x00000000),
BYTE_0(0x00000000),BYTE_1(0x00000000),BYTE_2(0x00000000),
          
BYTE_0(0x000020CD),BYTE_1(0x000020CD),BYTE_2(0x000020CD),
BYTE_0(0x0001665E),BYTE_1(0x0001665E),BYTE_2(0x0001665E),
BYTE_0(0x00011A6E),BYTE_1(0x00011A6E),BYTE_2(0x00011A6E),
          
BYTE_0(0x00450100),BYTE_1(0x00450100),BYTE_2(0x00450100),
BYTE_0(0x00442897),BYTE_1(0x00442897),BYTE_2(0x00442897),
BYTE_0(0x00439E74),BYTE_1(0x00439E74),BYTE_2(0x00439E74),