Example #1
0
/*********************************************************************//**
 * @brief		Set pin used as PWM function corresponding to each channel.
 * @param[in]	PWMx: PWM peripheral, should be LPC_PWM1.
 * @param[in]	PWM_Channel PWM channel number, should be in range from
 * 							1 to 6
 * @param[in]	PinselOption PWM pin selection option, PinselOption depends
 * 				on which selected channel as following:
 * 				- PWM_Channel = 1:
 *					+ PWM1_1_P1_18
 *					+ PWM1_1_P2_0
 * 				- PWM_Channel = 2:
 *					+ PWM1_2_P1_20
 *					+ PWM1_2_P2_1
 * 				- PWM_Channel = 3:
 *					+ PWM1_3_P1_21
 *					+ PWM1_3_P2_2
 * 				- PWM_Channel = 4:
 *					+ PWM1_4_P1_23
 *					+ PWM1_4_P2_3
 * 				- PWM_Channel = 5:
 *					+ PWM1_5_P1_24
 *					+ PWM1_5_P2_4
 * 				- PWM_Channel = 6:
 *					+ PWM1_6_P1_26
 *					+ PWM1_6_P2_5
 * @return 		None
 **********************************************************************/
void PWM_PinConfig(LPC_PWM_TypeDef *PWMx, uint8_t PWM_Channel, uint8_t PinselOption)
{
	CHECK_PARAM(PARAM_PWMx(PWMx));

	if (PWMx == LPC_PWM1)
	{
		CHECK_PARAM(PARAM_PWM1_CHANNEL(PWM_Channel));
		switch (PWM_Channel)
		{
		case 1:
			CHECK_PARAM(PARAM_PWM1_1_PIN(PinselOption));
			PINSEL_ConfigPin((PINSEL_CFG_Type *)(&pwm1_1_pinsel[PinselOption]));
			break;
		case 2:
			CHECK_PARAM(PARAM_PWM1_2_PIN(PinselOption));
			PINSEL_ConfigPin((PINSEL_CFG_Type *)(&pwm1_2_pinsel[PinselOption]));
			break;
		case 3:
			CHECK_PARAM(PARAM_PWM1_3_PIN(PinselOption));
			PINSEL_ConfigPin((PINSEL_CFG_Type *)(&pwm1_3_pinsel[PinselOption]));
			break;
		case 4:
			CHECK_PARAM(PARAM_PWM1_4_PIN(PinselOption));
			PINSEL_ConfigPin((PINSEL_CFG_Type *)(&pwm1_4_pinsel[PinselOption]));
			break;
		case 5:
			CHECK_PARAM(PARAM_PWM1_5_PIN(PinselOption));
			PINSEL_ConfigPin((PINSEL_CFG_Type *)(&pwm1_5_pinsel[PinselOption]));
			break;
		case 6:
			CHECK_PARAM(PARAM_PWM1_6_PIN(PinselOption));
			PINSEL_ConfigPin((PINSEL_CFG_Type *)(&pwm1_6_pinsel[PinselOption]));
			break;
		}
	}
}
Example #2
0
//Ö§³Öhost name
//ÄÚ²¿º¯Êý ͨ¹ý½Ó¿Ú½á¹¹Ìå»ñÈ¡SOCKET ID
//Èë²Î thisÖ¸Õ룬 ·µ»ØÖµ SOCKET ID (OR INVALID SOCKET)
SOCKET IpappGetSocketId(IPAPP_USER_S* pThis)
{
  //Èë²Î¼ì²é
  CHECK_PARAM(pThis);
  
  UINT32 uiRet = VOS_OK;
  char* pcAddr = NULL;
  //SOCKET soSocket = 0;
  struct hostent *remoteHost = NULL;
  
  if (!pThis->bsocketid)
  {
    
    if(!pThis->bip)
    {
      remoteHost = gethostbyname(pThis->hostname);
      
      if (remoteHost == NULL)
      {
        uiRet = WSAGetLastError();
        printf("Function failed with error: %ld\n", uiRet);
        return VOS_ERROR;
      }
      
      pcAddr = inet_ntoa (*(struct in_addr *)*remoteHost->h_addr_list);
      
    }
    else
    {
      pcAddr = pThis->ip;
    }
    
    return CreateConnectSocket(pThis->usPort, (const char *) pcAddr);
  }
  
  return pThis->socketid;
  
}
Example #3
0
/********************************************************************//**
 * @brief		Initializes the SPIx peripheral according to the specified
*               parameters in the UART_ConfigStruct.
 * @param[in]	SPIx	SPI peripheral selected, should be SPI
 * @param[in]	SPI_ConfigStruct Pointer to a SPI_CFG_Type structure
*                    that contains the configuration information for the
*                    specified SPI peripheral.
 * @return 		None
 *********************************************************************/
void SPI_Init(SPI_TypeDef *SPIx, SPI_CFG_Type *SPI_ConfigStruct)
{
	SPI_PinCFG_Type defaultSPIPinCfg;
	uint32_t tmp;

	CHECK_PARAM(PARAM_SPIx(SPIx));

	if(SPIx == SPI)
	{
		/* Set up clock and power for UART module */
		CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCSPI, ENABLE);
		/* As default, peripheral clock for UART0 module
		 * is set to FCCLK / 2 */
		CLKPWR_SetPCLKDiv(CLKPWR_PCLKSEL_SPI, CLKPWR_PCLKSEL_CCLK_DIV_2);
		// Set UART0 function pin as default
		defaultSPIPinCfg.SCK_Pin = SPI_SCK_P0_15;
		defaultSPIPinCfg.SSEL_Pin = SPI_SSEL_P0_16;
		defaultSPIPinCfg.MISO_Pin = SPI_MISO_P0_17;
		defaultSPIPinCfg.MOSI_Pin = SPI_MOSI_P0_18;
		SPI_PinConfig(SPIx, &defaultSPIPinCfg, SPI_ConfigStruct->Mode);
	}

	// Configure SPI, interrupt is disable as default
	tmp = ((SPI_ConfigStruct->CPHA) | (SPI_ConfigStruct->CPOL) \
		| (SPI_ConfigStruct->DataOrder) | (SPI_ConfigStruct->Databit) \
		| (SPI_ConfigStruct->Mode) | SPI_SPCR_BIT_EN) & SPI_SPCR_BITMASK;
	// write back to SPI control register
	SPIx->SPCR = tmp;

	// Set clock rate for SPI peripheral
	SPI_SetClock(SPIx, SPI_ConfigStruct->ClockRate);

	// If interrupt flag is set, Write '1' to Clear interrupt flag
	if (SPIx->SPINT & SPI_SPINT_INTFLAG)
	{
		SPIx->SPINT = SPI_SPINT_INTFLAG;
	}
}
/********************************************************************//**
 * @brief		Initializes the I2Cx peripheral with specified parameter.
 * @param[in]	I2Cx	I2C peripheral selected, should be
 * 				- LPC_I2C0
 * 				- LPC_I2C1
 * 				- LPC_I2C2
 * @param[in]	clockrate Target clock rate value to initialized I2C
 * 				peripheral (Hz)
 * @return 		None
 *********************************************************************/
void I2C_Init(LPC_I2C_TypeDef *I2Cx, uint32_t clockrate)
{
	CHECK_PARAM(PARAM_I2Cx(I2Cx));

	if (I2Cx==LPC_I2C0)
	{
		/* Set up clock and power for I2C0 module */
		CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCI2C0, ENABLE);
		/* As default, peripheral clock for I2C0 module
		 * is set to FCCLK / 2 */
		CLKPWR_SetPCLKDiv(CLKPWR_PCLKSEL_I2C0, CLKPWR_PCLKSEL_CCLK_DIV_2);
	}
	else if (I2Cx==LPC_I2C1)
	{
		/* Set up clock and power for I2C1 module */
		CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCI2C1, ENABLE);
		/* As default, peripheral clock for I2C1 module
		 * is set to FCCLK / 2 */
		CLKPWR_SetPCLKDiv(CLKPWR_PCLKSEL_I2C1, CLKPWR_PCLKSEL_CCLK_DIV_2);
	}
	else if (I2Cx==LPC_I2C2)
	{
		/* Set up clock and power for I2C2 module */
		CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCI2C2, ENABLE);
		/* As default, peripheral clock for I2C2 module
		 * is set to FCCLK / 2 */
		CLKPWR_SetPCLKDiv(CLKPWR_PCLKSEL_I2C2, CLKPWR_PCLKSEL_CCLK_DIV_2);
	}
	else {
		// Up-Support this device
		return;
	}

    /* Set clock rate */
    I2C_SetClock(I2Cx, clockrate);
    /* Set I2C operation to default */
    I2Cx->I2CONCLR = (I2C_I2CONCLR_AAC | I2C_I2CONCLR_STAC | I2C_I2CONCLR_I2ENC);
}
Example #5
0
void CRC_WriteData( uint8_t * data, uint8_t bitlen )
{
    uint16_t * data_word = (uint16_t *)data;
    uint32_t * data_dword = (uint32_t *)data;

    CHECK_PARAM(( bitlen == 8 ) || ( bitlen == 16 ) || ( bitlen == 32 ));

    switch ( bitlen )
    {
        case 32:
        	LPC_CRC->WR_DATA_DWORD = *data_dword;
        	break;
        case 16:
        	LPC_CRC->WR_DATA_WORD = *data_word;
        	break;
        case 8:
       		LPC_CRC->WR_DATA_BYTE = *data;
        	break;
        default:
        	break;
    }
    return;
}
/*********************************************************************//**
 * @brief		De-initializes the I2C peripheral registers to their
 *                  default reset values.
 * @param[in]	I2Cx	I2C peripheral selected, should be
 *  			- LPC_I2C0
 * 				- LPC_I2C1
 * 				- LPC_I2C2
 * @return 		None
 **********************************************************************/
void I2C_DeInit(LPC_I2C_TypeDef* I2Cx)
{
	CHECK_PARAM(PARAM_I2Cx(I2Cx));

	/* Disable I2C control */
	I2Cx->I2CONCLR = I2C_I2CONCLR_I2ENC;

	if (I2Cx==LPC_I2C0)
	{
		/* Disable power for I2C0 module */
		CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCI2C0, DISABLE);
	}
	else if (I2Cx==LPC_I2C1)
	{
		/* Disable power for I2C1 module */
		CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCI2C1, DISABLE);
	}
	else if (I2Cx==LPC_I2C2)
	{
		/* Disable power for I2C2 module */
		CLKPWR_ConfigPPWR (CLKPWR_PCONP_PCI2C2, DISABLE);
	}
}
Example #7
0
/*********************************************************************//**
 * @brief 		Update Match value
 * @param[in]	TIMx Pointer to timer device, should be:
 *   			- LPC_TIM0: TIMER0 peripheral
 * 				- LPC_TIM1: TIMER1 peripheral
 * 				- LPC_TIM2: TIMER2 peripheral
 * 				- LPC_TIM3: TIMER3 peripheral
 * @param[in]	MatchChannel	Match channel, should be: 0..3
 * @param[in]	MatchValue		updated match value
 * @return 		None
 **********************************************************************/
void TIM_UpdateMatchValue(LPC_TIM_TypeDef *TIMx,uint8_t MatchChannel, uint32_t MatchValue)
{
	CHECK_PARAM(PARAM_TIMx(TIMx));
	switch(MatchChannel)
	{
	case 0:
		TIMx->MR0 = MatchValue;
		break;
	case 1:
		TIMx->MR1 = MatchValue;
		break;
	case 2:
		TIMx->MR2 = MatchValue;
		break;
	case 3:
		TIMx->MR3 = MatchValue;
		break;
	default:
		//Error Loop
		while(1);
	}

}
/*********************************************************************//**
 * @brief 		Setup clock rate for I2C peripheral
 * @param[in] 	I2Cx	I2C peripheral selected, should be:
 * 				- LPC_I2C0
 * 				- LPC_I2C1
 * 				- LPC_I2C2
 * @param[in]	target_clock : clock of SSP (Hz)
 * @return 		None
 ***********************************************************************/
static void I2C_SetClock (LPC_I2C_TypeDef *I2Cx, uint32_t target_clock)
{
	uint32_t temp;

	CHECK_PARAM(PARAM_I2Cx(I2Cx));

	// Get PCLK of I2C controller
	if (I2Cx == LPC_I2C0)
	{
		temp = CLKPWR_GetPCLK (CLKPWR_PCLKSEL_I2C0) / target_clock;
	}
	else if (I2Cx == LPC_I2C1)
	{
		temp = CLKPWR_GetPCLK (CLKPWR_PCLKSEL_I2C1) / target_clock;
	}
	else if (I2Cx == LPC_I2C2)
	{
		temp = CLKPWR_GetPCLK (CLKPWR_PCLKSEL_I2C2) / target_clock;
	}

	/* Set the I2C clock value to register */
	I2Cx->I2SCLH = (uint32_t)(temp / 2);
	I2Cx->I2SCLL = (uint32_t)(temp - I2Cx->I2SCLH);
}
Example #9
0
/****************************************************************************//**
 * @brief      Reset GPT counter 
 *
 * @param[in]  gptID:  Select the GPT module
 *
 * @return reset status
 *  
 * Reset the GPT counter
 *******************************************************************************/
Status GPT_CounterReset(GPT_ID_Type gptID)
{  
  gpt_reg_t * GPTx = (gpt_reg_t *)(gptAddr[gptID]);
  volatile uint32_t cnt = 0;
  
  CHECK_PARAM(IS_GPT_PERIPH(gptID));
    
  /* Reset the GPT counter */
  GPTx->CNT_EN.BF.CNT_RESET = 0x1;
  
  /* Wating until the counter reset is done */
  while(cnt < 0x300000)
  {
    /* Read the counter reset status */
    if(GPTx->CNT_EN.BF.CNT_RST_DONE)
    {
      return DSUCCESS;
    }
    
    cnt++;
  }
  
  return DERROR;
}
Example #10
0
/*********************************************************************//**
 * @brief		Transmit a single data through SSPx peripheral
 * @param[in]	SSPx	SSP peripheral selected, should be:
 * 						- LPC_SSP0: SSP0 peripheral
 * 						- LPC_SSP1: SSP1 peripheral
 * @param[in]	Data	Data to transmit (must be 16 or 8-bit long,
 * 						this depend on SSP data bit number configured)
 * @return 		none
 **********************************************************************/
void SSP_SendData(LPC_SSP_TypeDef* SSPx, uint16_t Data)
{
	CHECK_PARAM(PARAM_SSPx(SSPx));

	SSPx->DR = SSP_DR_BITMASK(Data);
}
Example #11
0
/*****************************************************************************//**
* @brief		Get data size bit selected
* @param[in]	SSPx pointer to LPC_SSP_TypeDef structure, should be:
* 				- LPC_SSP0: SSP0 peripheral
* 				- LPC_SSP1: SSP1 peripheral
* @return		Data size, could be:
*				- SSP_DATABIT_4: 4 bit transfer
*				- SSP_DATABIT_5: 5 bit transfer
*				...
*				- SSP_DATABIT_16: 16 bit transfer
*******************************************************************************/
uint8_t SSP_GetDataSize(LPC_SSP_TypeDef* SSPx)
{
	CHECK_PARAM(PARAM_SSPx(SSPx));
	return (SSPx->CR0 & (0xF));
}
Example #12
0
/*********************************************************************//**
 * @brief 		Clear ATIMER Interrupt Status
 * @param[in]	ATIMERx Pointer to timer device, should be: LPC_ATIMER
 * @return 		None
 **********************************************************************/
void ATIMER_ClearIntStatus(LPC_ATIMER_Type *ATIMERx)
{
	CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
	ATIMERx->CLR_STAT = 1;
	while((ATIMERx->STATUS & 1) == 1);
}
Example #13
0
/*********************************************************************//**
 * @brief 		Read value of preset register
 * @param[in]	ATIMERx Pointer to timer/counter device, should be: LPC_ATIMER
 * @return 		Value of capture register
 **********************************************************************/
uint32_t ATIMER_GetPresetValue(LPC_ATIMER_Type *ATIMERx)
{
	CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
	return ATIMERx->PRESET;
}
Example #14
0
/*********************************************************************//**
 * @brief 		Update Preset value
 * @param[in]	ATIMERx Pointer to timer device, should be: LPC_ATIMER
 * @param[in]	PresetValue	updated preset value
 * @return 		None
 **********************************************************************/
void ATIMER_UpdatePresetValue(LPC_ATIMER_Type *ATIMERx,uint32_t PresetValue)
{
	CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
	ATIMERx->PRESET = PresetValue;
}
/*********************************************************************//**
 * @brief 		Select 16/32 bit SCT counter
 * @param[in]	value 	configuration value for SCT
 * 					- SCT_CONFIG_16BIT_COUNTER	:16-bit counter
 * 					- SCT_CONFIG_32BIT_COUNTER	:32-bit counter
 * @return 		None
 **********************************************************************/
void SCT_Config(uint32_t value)
{
	CHECK_PARAM(PARAM_SCT_CONFIG_COUNTER_TYPE(value));

	LPC_SCT->CONFIG = value;
}
Example #16
0
int main(int argc, char **argv)
{
    ncMetadata meta = { "correlate-me-please", "eucalyptus" };
    virtualMachine params = { 64, 1, 1, "m1.small", NULL, NULL, NULL, NULL, NULL, {}, 0 };
    char *nc_hostport = DEFAULT_NC_HOSTPORT;
    char *walrus_hostport = DEFAULT_WALRUS_HOSTPORT;
    char *instance_id = NULL;
    char *image_id = NULL;
    char *image_manifest = NULL;
    char *kernel_id = NULL;
    char *kernel_manifest = NULL;
    char *ramdisk_id = NULL;
    char *ramdisk_manifest = NULL;
    char *reservation_id = NULL;
    char *uu_id = NULL;
    char *mac_addr = strdup(DEFAULT_MAC_ADDR);
    char *public_ip = strdup(DEFAULT_PUBLIC_IP);
    char *volume_id = NULL;
    char *remote_dev = NULL;
    char *local_dev = NULL;
    int force = 0;
    char *user_data = NULL;
    char *launch_index = NULL;
    char **group_names = NULL;
    int group_names_size = 0;
    char *timestamp_str = NULL;
    char *command = NULL;
    int local = 0;
    int count = 1;
    int ch;

    while ((ch = getopt(argc, argv, "lhdn:w:i:m:k:r:e:a:c:h:u:p:V:R:L:FU:I:G:v:t:")) != -1) {
        switch (ch) {
        case 'c':
            count = atoi(optarg);
            break;
        case 'd':
            debug = 1;
            break;
        case 'l':
            local = 1;
            break;
        case 'n':
            nc_hostport = optarg;
            break;
        case 'w':
            walrus_hostport = optarg;
            break;
        case 'i':
            instance_id = optarg;
            break;
        case 'p':
            public_ip = optarg;
            break;
        case 'm':
            image_id = strtok(optarg, ":");
            image_manifest = strtok(NULL, ":");
            if (image_id == NULL || image_manifest == NULL) {
                fprintf(stderr, "ERROR: could not parse image [id:manifest] paramters (try -h)\n");
                exit(1);
            }
            break;
        case 'k':
            kernel_id = strtok(optarg, ":");
            kernel_manifest = strtok(NULL, ":");
            if (kernel_id == NULL || kernel_manifest == NULL) {
                fprintf(stderr, "ERROR: could not parse kernel [id:manifest] paramters (try -h)\n");
                exit(1);
            }
            break;
        case 'r':
            ramdisk_id = strtok(optarg, ":");
            ramdisk_manifest = strtok(NULL, ":");
            if (ramdisk_id == NULL || ramdisk_manifest == NULL) {
                fprintf(stderr, "ERROR: could not parse ramdisk [id:manifest] paramters (try -h)\n");
                exit(1);
            }
            break;
        case 'e':
            reservation_id = optarg;
            break;
        case 'u':
            uu_id = optarg;
            break;
        case 'a':
            mac_addr = optarg;
            break;
        case 'V':
            volume_id = optarg;
            break;
        case 'R':
            remote_dev = optarg;
            break;
        case 'L':
            local_dev = optarg;
            break;
        case 'F':
            force = 1;
            break;
        case 'U':
            user_data = optarg;
            break;
        case 'I':
            launch_index = optarg;
            break;
        case 'G':
            {
                int i;
                group_names_size = 1;
                for (i = 0; optarg[i]; i++)
                    if (optarg[i] == ':')
                        group_names_size++;
                group_names = malloc(sizeof(char *) * group_names_size);
                if (group_names == NULL) {
                    fprintf(stderr, "ERROR: out of memory for group_names[]\n");
                    exit(1);
                }
                group_names[0] = strtok(optarg, ":");
                for (i = 1; i < group_names_size; i++)
                    group_names[i] = strtok(NULL, ":");
                break;
            }
        case 'v':
            if (add_vbr(optarg, &params)) {
                fprintf(stderr, "ERROR: could not parse the virtual boot record (try -h)\n");
                exit(1);
            }
            break;
        case 't':
            timestamp_str = optarg;
            break;
        case 'h':
            usage();            // will exit
        case '?':
        default:
            fprintf(stderr, "ERROR: unknown parameter (try -h)\n");
            exit(1);
        }
    }
    argc -= optind;
    argv += optind;

    if (argc > 0) {
        command = argv[0];
        if (argc > 1) {
            fprintf(stderr, "WARNING: too many parameters, using first one as command\n");
        }
    } else {
        fprintf(stderr, "ERROR: command not specified (try -h)\n");
        exit(1);
    }

    ncStub *stub;
    char configFile[1024], policyFile[1024];
    char *euca_home;
    int rc, use_wssec;
    char *tmpstr;

    euca_home = getenv("EUCALYPTUS");
    if (!euca_home) {
        euca_home = "";
    }
    snprintf(configFile, 1024, EUCALYPTUS_CONF_LOCATION, euca_home);
    snprintf(policyFile, 1024, EUCALYPTUS_KEYS_DIR "/nc-client-policy.xml", euca_home);
    rc = get_conf_var(configFile, "ENABLE_WS_SECURITY", &tmpstr);
    if (rc != 1) {
        /* Default to enabled */
        use_wssec = 1;
    } else {
        if (!strcmp(tmpstr, "Y")) {
            use_wssec = 1;
        } else {
            use_wssec = 0;
        }
    }

    char nc_url[BUFSIZE];
    snprintf(nc_url, BUFSIZE, "http://%s%s", nc_hostport, NC_ENDPOINT);
    if (debug)
        printf("connecting to NC at %s\n", nc_url);
    stub = ncStubCreate(nc_url, "NCclient.log", NULL);
    if (!stub) {
        fprintf(stderr, "ERROR: failed to connect to Web service\n");
        exit(2);
    }

    char walrus_url[BUFSIZE];
    snprintf(walrus_url, BUFSIZE, "http://%s%s", walrus_hostport, WALRUS_ENDPOINT);
    serviceInfoType *si = &(meta.services[meta.servicesLen++]);
    safe_strncpy(si->type, "walrus", sizeof(si->type));
    safe_strncpy(si->name, "walrus", sizeof(si->name));
    safe_strncpy(si->uris[0], walrus_url, sizeof(si->uris[0]));
    si->urisLen = 1;

    if (use_wssec && !local) {
        if (debug)
            printf("using policy file %s\n", policyFile);
        rc = InitWSSEC(stub->env, stub->stub, policyFile);
        if (rc) {
            fprintf(stderr, "ERROR: cannot initialize WS-SEC policy from %s\n", policyFile);
            exit(1);
        }
    }

    char *image_url = NULL;
    if (image_manifest) {
        char t[BUFSIZE];
        snprintf(t, BUFSIZE, "http://%s%s/%s", walrus_hostport, WALRUS_ENDPOINT, image_manifest);
        image_url = strdup(t);
    }

    char *kernel_url = NULL;
    if (kernel_manifest) {
        char t[BUFSIZE];
        snprintf(t, BUFSIZE, "http://%s%s/%s", walrus_hostport, WALRUS_ENDPOINT, kernel_manifest);
        kernel_url = strdup(t);
    }

    char *ramdisk_url = NULL;
    if (ramdisk_manifest) {
        char t[BUFSIZE];
        snprintf(t, BUFSIZE, "http://%s%s/%s", walrus_hostport, WALRUS_ENDPOINT, ramdisk_manifest);
        ramdisk_url = strdup(t);
    }

    /***********************************************************/
    if (!strcmp(command, "runInstance")) {
        if (params.virtualBootRecordLen < 1) {
            CHECK_PARAM(image_id, "image ID and manifest path");
            CHECK_PARAM(kernel_id, "kernel ID and manifest path");
        }

        char *privMac, *pubMac, *privIp;
        char *platform = NULL;
        int vlan = 3;
        privMac = strdup(mac_addr);
        mac_addr[0] = 'b';
        mac_addr[1] = 'b';
        privIp = strdup("10.0.0.202");
        srand(time(NULL));

        /* generate random IDs if they weren't specified */
#define C rand()%26 + 97

        while (count--) {
            char *iid, *rid, *uuid;

            char ibuf[8];
            if (instance_id == NULL || count > 1) {
                snprintf(ibuf, 8, "i-%c%c%c%c%c", C, C, C, C, C);
                iid = ibuf;
            } else {
                iid = instance_id;
            }

            char rbuf[8];
            if (reservation_id == NULL || count > 1) {
                snprintf(rbuf, 8, "r-%c%c%c%c%c", C, C, C, C, C);
                rid = rbuf;
            } else {
                rid = reservation_id;
            }

            char ubuf[48];
            if (uu_id == NULL || count > 1) {
                snprintf(ubuf, 48, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c", C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C,
                         C, C, C, C, C, C, C, C, C, C, C, C, C, C, C, C);
                uuid = ubuf;
            } else {
                uuid = uu_id;
            }

            netConfig netparams;
            ncInstance *outInst;
            bzero(&netparams, sizeof(netparams));
            netparams.vlan = vlan;
            snprintf(netparams.privateIp, 24, "%s", privIp);
            snprintf(netparams.privateMac, 24, "%s", privMac);

            int rc = ncRunInstanceStub(stub, &meta,
                                       uuid, iid, rid,
                                       &params,
                                       image_id, image_url,
                                       kernel_id, kernel_url,
                                       ramdisk_id, ramdisk_url,
                                       "eucalyptusUser", "eucalyptusAccount",
                                       "",  /* key */
                                       &netparams,
                                       //                                       privMac, privIp, vlan, 
                                       user_data, launch_index, platform, 0, group_names, group_names_size, /* CC stuff */
                                       &outInst);
            if (rc != 0) {
                printf("ncRunInstance() failed: instanceId=%s error=%d\n", instance_id, rc);
                exit(1);
            }
            // count device mappings
            int i, count = 0;
            for (i = 0; i < EUCA_MAX_VBRS; i++) {
                if (strlen(outInst->params.virtualBootRecord[i].typeName) > 0)
                    count++;
            }
            printf("instanceId=%s stateCode=%d stateName=%s deviceMappings=%d/%d\n", outInst->instanceId, outInst->stateCode, outInst->stateName,
                   count, outInst->params.virtualBootRecordLen);
        }

        /***********************************************************/
    } else if (!strcmp(command, "bundleInstance")) {
        CHECK_PARAM(instance_id, "instance id");
        int rc =
            ncBundleInstanceStub(stub, &meta, instance_id, "bucket-foo", "prefix-foo", "s3-url-foo", "user-key-foo", "s3policy-foo", "s3policy-sig");
        printf("ncBundleInstanceStub = %d\n", rc);

    } else if (!strcmp(command, "bundleRestartInstance")) {
        CHECK_PARAM(instance_id, "instance id");
        int rc = ncBundleRestartInstanceStub(stub, &meta, instance_id);
        printf("ncBundleRestartInstanceStub = %d\n", rc);
    } else if (!strcmp(command, "powerDown")) {
        int rc = ncPowerDownStub(stub, &meta);
    } else if (!strcmp(command, "describeBundleTasks")) {
        char *instIds[4];
        int instIdsLen;
        instIds[0] = malloc(sizeof(char) * 32);
        instIds[1] = malloc(sizeof(char) * 32);
        instIds[2] = malloc(sizeof(char) * 32);
        instIds[3] = malloc(sizeof(char) * 32);
        snprintf(instIds[0], 32, "i-12345675");
        snprintf(instIds[1], 32, "i-12345674");
        snprintf(instIds[2], 32, "i-12345673");
        snprintf(instIds[3], 32, "i-12345672");
        instIdsLen = 4;
        bundleTask **outBundleTasks = NULL;
        int outBundleTasksLen = 0;
        rc = ncDescribeBundleTasksStub(stub, &meta, instIds, instIdsLen, &outBundleTasks, &outBundleTasksLen);
        for (int i = 0; i < outBundleTasksLen; i++) {
            printf("BUNDLE %d: %s %s\n", i, outBundleTasks[i]->instanceId, outBundleTasks[i]->state);
        }
    } else if (!strcmp(command, "assignAddress")) {
        int rc = ncAssignAddressStub(stub, &meta, instance_id, public_ip);
    } else if (!strcmp(command, "terminateInstance")) {
        CHECK_PARAM(instance_id, "instance ID");

        int shutdownState, previousState;
        int rc = ncTerminateInstanceStub(stub, &meta, instance_id, 0, &shutdownState, &previousState);
        if (rc != 0) {
            printf("ncTerminateInstance() failed: error=%d\n", rc);
            exit(1);
        }
        printf("shutdownState=%d, previousState=%d\n", shutdownState, previousState);

        /***********************************************************/
    } else if (!strcmp(command, "describeInstances")) {
        /* TODO: pull out of argv[] requested instanceIDs */
        ncInstance **outInsts;
        int outInstsLen, i;
        int rc = ncDescribeInstancesStub(stub, &meta, NULL, 0, &outInsts, &outInstsLen);
        if (rc != 0) {
            printf("ncDescribeInstances() failed: error=%d\n", rc);
            exit(1);
        }
        for (i = 0; i < outInstsLen; i++) {
            ncInstance *inst = outInsts[i];
            printf("instanceId=%s state=%s time=%d\n", inst->instanceId, inst->stateName, inst->launchTime);
            if (debug) {
                printf("              userData=%s launchIndex=%s groupNames=", inst->userData, inst->launchIndex);
                if (inst->groupNamesSize > 0) {
                    int j;
                    for (j = 0; j < inst->groupNamesSize; j++) {
                        if (j > 0)
                            printf(":");
                        printf("%s", inst->groupNames[j]);
                    }
                } else {
                    printf("(none)");
                }
                printf("\n");

                printf("              attached volumes: ");
                int vol_count = 0;
                for (int j = 0; j < EUCA_MAX_VOLUMES; j++) {
                    if (strlen(inst->volumes[j].volumeId) > 0) {
                        if (vol_count > 0)
                            printf("                                ");
                        printf("%s %s %s\n", inst->volumes[j].volumeId, inst->volumes[j].remoteDev, inst->volumes[j].localDev);
                    }
                }
                if (vol_count)
                    printf("(none)\n");

                free_instance(&(outInsts[i]));
            }
        }
        /* TODO: fix free(outInsts); */

    /***********************************************************/
    } else if (!strcmp(command, "describeResource")) {
        char *type = NULL;
        ncResource *outRes;

        int rc = ncDescribeResourceStub(stub, &meta, type, &outRes);
        if (rc != 0) {
            printf("ncDescribeResource() failed: error=%d\n", rc);
            exit(1);
        }
        printf("node status=[%s] memory=%d/%d disk=%d/%d cores=%d/%d subnets=[%s]\n",
               outRes->nodeStatus,
               outRes->memorySizeMax, outRes->memorySizeAvailable, outRes->diskSizeMax, outRes->diskSizeAvailable, outRes->numberOfCoresMax,
               outRes->numberOfCoresAvailable, outRes->publicSubnets);

    /***********************************************************/
    } else if (!strcmp(command, "attachVolume")) {
        CHECK_PARAM(instance_id, "instance ID");
        CHECK_PARAM(volume_id, "volume ID");
        CHECK_PARAM(remote_dev, "remote dev");
        CHECK_PARAM(local_dev, "local dev");

        int rc = ncAttachVolumeStub(stub, &meta, instance_id, volume_id, remote_dev, local_dev);
        if (rc != 0) {
            printf("ncAttachVolume() failed: error=%d\n", rc);
            exit(1);
        }

    /***********************************************************/
    } else if (!strcmp(command, "detachVolume")) {
        CHECK_PARAM(instance_id, "instance ID");
        CHECK_PARAM(volume_id, "volume ID");
        CHECK_PARAM(remote_dev, "remote dev");
        CHECK_PARAM(local_dev, "local dev");

        int rc = ncDetachVolumeStub(stub, &meta, instance_id, volume_id, remote_dev, local_dev, force);
        if (rc != 0) {
            printf("ncDetachVolume() failed: error=%d\n", rc);
            exit(1);
        }

    /***********************************************************/
    } else if (!strcmp(command, "describeSensors")) {

        sensorResource **res;
        int resSize;

        int rc = ncDescribeSensorsStub(stub, &meta, 20, 5000, NULL, 0, NULL, 0, &res, &resSize);
        if (rc != 0) {
            printf("ncDescribeSensors() failed: error=%d\n", rc);
            exit(1);
        }
        char buf[102400];
        sensor_res2str(buf, sizeof(buf), res, resSize);
        printf("resources: %d\n%s\n", resSize, buf);

    /***********************************************************/
    } else if (!strcmp(command, "_convertTimestamp")) {
        CHECK_PARAM(timestamp_str, "timestamp");

        axutil_date_time_t *dt = unixms_to_datetime(stub->env, 0123L);
        long long ts_l = datetime_to_unixms(dt, stub->env);
        printf("timestamp: %lld\n", ts_l);

    /***********************************************************/
    } else {
        fprintf(stderr, "ERROR: command %s unknown (try -h)\n", command);
        exit(1);
    }

    if (local) {
        pthread_exit(NULL);
    } else {
        _exit(0);
    }
}
Example #17
0
/*********************************************************************//**
 * @brief 		Selects pin location for DCD pin
 * @param[in]	sck SCK0 pin position, it can be :
 *                -DCD_PIO2_2 : PIO2_2/DCD/MISO1     
 *                -DCD_PIO3_2 : PIO3_2/DCD
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void IOCON_DCDLocate(DCD_Position_Typedef dcd)
{
    CHECK_PARAM(PARAM_DCD(dcd));
    LPC_IOCON->DCDLOC = dcd;
}
Example #18
0
/*********************************************************************//**
 * @brief 		Selects pin location for SCK0 pin
 * @param[in]	sck SCK0 pin position, it can be :
 *                -SCK_PIO0_10 : SWCLK/PIO0_10/SCK0/CT16B0_MAT2        
 *                -SCK_PIO2_11 : PIO2_11/SCK0
 *                -SCK_PIO0_6  : PIO0_6/SCK0
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void IOCON_SCK0Locate(SCK0_Position_Typedef sck)
{
    CHECK_PARAM(PARAM_SCK(sck));
    LPC_IOCON->SCKLOC = sck;
}
Example #19
0
void ItemDB::load()
{
    if (mLoaded)
        unload();

    logger->log("Initializing item database...");

    mUnknown = new ItemInfo;
    mUnknown->setName(_("Unknown item"));
    mUnknown->setDisplay(SpriteDisplay());
    std::string errFile = paths.getStringValue("spriteErrorFile");
    mUnknown->setSprite(errFile, GENDER_MALE);
    mUnknown->setSprite(errFile, GENDER_FEMALE);

    XML::Document doc("items.xml");
    xmlNodePtr rootNode = doc.rootNode();

    if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "items"))
    {
        logger->error("ItemDB: Error while loading items.xml!");
    }

    for_each_xml_child_node(node, rootNode)
    {
        if (!xmlStrEqual(node->name, BAD_CAST "item"))
            continue;

        int id = XML::getProperty(node, "id", 0);

        if (id == 0)
        {
            logger->log("ItemDB: Invalid or missing item ID in items.xml!");
            continue;
        }
        else if (mItemInfos.find(id) != mItemInfos.end())
        {
            logger->log("ItemDB: Redefinition of item ID %d", id);
        }

        std::string typeStr = XML::getProperty(node, "type", "other");
        int weight = XML::getProperty(node, "weight", 0);
        int view = XML::getProperty(node, "view", 0);

        std::string name = XML::getProperty(node, "name", "");
        std::string image = XML::getProperty(node, "image", "");
        std::string description = XML::getProperty(node, "description", "");
        std::string attackAction = XML::getProperty(node, "attack-action", "");
        int attackRange = XML::getProperty(node, "attack-range", 0);
        std::string missileParticle = XML::getProperty(node, "missile-particle", "");

        SpriteDisplay display;
        display.image = image;

        ItemInfo *itemInfo = new ItemInfo;
        itemInfo->setId(id);
        itemInfo->setName(name.empty() ? _("unnamed") : name);
        itemInfo->setDescription(description);
        itemInfo->setType(itemTypeFromString(typeStr));
        itemInfo->setView(view);
        itemInfo->setWeight(weight);
        itemInfo->setAttackAction(attackAction);
        itemInfo->setAttackRange(attackRange);
        itemInfo->setMissileParticle(missileParticle);

        std::string effect;
        for (int i = 0; i < int(sizeof(fields) / sizeof(fields[0])); ++i)
        {
            int value = XML::getProperty(node, fields[i][0], 0);
            if (!value) continue;
            if (!effect.empty()) effect += " / ";
            effect += strprintf(gettext(fields[i][1]), value);
        }
        for (std::list<Stat>::iterator it = extraStats.begin();
                it != extraStats.end(); it++)
        {
            int value = XML::getProperty(node, it->tag.c_str(), 0);
            if (!value) continue;
            if (!effect.empty()) effect += " / ";
            effect += strprintf(it->format.c_str(), value);
        }
        std::string temp = XML::getProperty(node, "effect", "");
        if (!effect.empty() && !temp.empty())
            effect += " / ";
        effect += temp;
        itemInfo->setEffect(effect);

        for_each_xml_child_node(itemChild, node)
        {
            if (xmlStrEqual(itemChild->name, BAD_CAST "sprite"))
            {
                std::string attackParticle = XML::getProperty(
                    itemChild, "particle-effect", "");
                itemInfo->setParticleEffect(attackParticle);

                loadSpriteRef(itemInfo, itemChild);
            }
            else if (xmlStrEqual(itemChild->name, BAD_CAST "sound"))
            {
                loadSoundRef(itemInfo, itemChild);
            }
            else if (xmlStrEqual(itemChild->name, BAD_CAST "floor"))
            {
                loadFloorSprite(&display, itemChild);
            }
        }

        itemInfo->setDisplay(display);

        mItemInfos[id] = itemInfo;
        if (!name.empty())
        {
            std::string temp = normalized(name);

            NamedItemInfos::const_iterator itr = mNamedItemInfos.find(temp);
            if (itr == mNamedItemInfos.end())
            {
                mNamedItemInfos[temp] = itemInfo;
            }
            else
            {
                logger->log("ItemDB: Duplicate name of item found item %d", id);
            }
        }

        if (!attackAction.empty())
            if (attackRange == 0)
                logger->log("ItemDB: Missing attack range from weapon %i!", id);

#define CHECK_PARAM(param, error_value) \
        if (param == error_value) \
            logger->log("ItemDB: Missing " #param " attribute for item %i!",id)

        if (id >= 0)
        {
            CHECK_PARAM(name, "");
            CHECK_PARAM(description, "");
            CHECK_PARAM(image, "");
        }
        // CHECK_PARAM(effect, "");
        // CHECK_PARAM(type, 0);
        // CHECK_PARAM(weight, 0);
        // CHECK_PARAM(slot, 0);

#undef CHECK_PARAM
    }

    mLoaded = true;
}
/*********************************************************************//**
 * @brief		Get data from I2C data buffer in monitor mode.
 * @param[in]	I2Cx	I2C peripheral selected, should be
 *    			- LPC_I2C0
 * 				- LPC_I2C1
 * 				- LPC_I2C2
 * @return		None
 * Note:	In monitor mode, the I2C module may lose the ability to stretch
 * the clock (stall the bus) if the ENA_SCL bit is not set. This means that
 * the processor will have a limited amount of time to read the contents of
 * the data received on the bus. If the processor reads the I2DAT shift
 * register, as it ordinarily would, it could have only one bit-time to
 * respond to the interrupt before the received data is overwritten by
 * new data.
 **********************************************************************/
uint8_t I2C_MonitorGetDatabuffer(LPC_I2C_TypeDef *I2Cx)
{
	CHECK_PARAM(PARAM_I2Cx(I2Cx));
	return ((uint8_t)(I2Cx->I2DATA_BUFFER));
}
Example #21
0
/*********************************************************************//**
* @brief        Get ADC Data from AD Global register
* @param[in]    ADCx pointer to LPC_ADC_TypeDef, should be: LPC_ADC
* @return       Result of conversion
**********************************************************************/
uint32_t ADC_GlobalGetData(LPC_ADC_TypeDef *ADCx)
{
    CHECK_PARAM(PARAM_ADCx(ADCx));

    return ((uint32_t)(ADCx->ADGDR));
}
Example #22
0
/*********************************************************************//**
 * @brief		Receive a single data from SSPx peripheral
 * @param[in]	SSPx	SSP peripheral selected, should be
 * 						- LPC_SSP0: SSP0 peripheral
 * 						- LPC_SSP1: SSP1 peripheral
 * @return 		Data received (16-bit long)
 **********************************************************************/
uint16_t SSP_ReceiveData(LPC_SSP_TypeDef* SSPx)
{
	CHECK_PARAM(PARAM_SSPx(SSPx));

	return ((uint16_t) (SSP_DR_BITMASK(SSPx->DR)));
}
Example #23
0
/*********************************************************************//**
 * @brief		Get Raw Interrupt Status register
 * @param[in]	SSPx	SSP peripheral selected, should be:
 * 						- LPC_SSP0: SSP0 peripheral
 * 						- LPC_SSP1: SSP1 peripheral
 * @return		Raw Interrupt Status (RIS) register value
 **********************************************************************/
uint32_t SSP_GetRawIntStatusReg(LPC_SSP_TypeDef *SSPx)
{
	CHECK_PARAM(PARAM_SSPx(SSPx));
	return (SSPx->RIS);
}
Example #24
0
/*********************************************************************//**
 * @brief 		Disable ATIMER Interrupt
 * @param[in]	ATIMERx Pointer to timer device, should be: LPC_ATIMER
 * @return 		None
 **********************************************************************/
void ATIMER_IntDisable(LPC_ATIMER_Type *ATIMERx)
{
	CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
	ATIMERx->CLR_EN = 1;
	while((ATIMERx->ENABLE & 1) == 1);
}
Example #25
0
/*********************************************************************//**
 * @brief		De-initializes the RTC peripheral registers to their
*                  default reset values.
 * @param[in]	RTCx	RTC peripheral selected, should be LPC_RTC
 * @return 		None
 **********************************************************************/
void RTC_DeInit(LPC_RTC_Type *RTCx)
{
	CHECK_PARAM(PARAM_RTCx(RTCx));

	RTCx->CCR = 0x00;
}
/*********************************************************************//**
* @brief 		Clear SCT event generating interrupt request
* @param[in]	even_num 	SCT event number, should be: 0..15
* @return 		None
*********************************************************************/
void SCT_EventFlagClear(uint8_t even_num)
{
	CHECK_PARAM(PARAM_SCT_EVENT(even_num));

	LPC_SCT->EVFLAG = (1 << (even_num));
}
Example #27
0
/*********************************************************************//**
 * @brief 		Selects pin location for DSR pin
 * @param[in]	sck SCK0 pin position, it can be :
 *                -DSR_PIO2_1 : PIO2_1/DSR/SCK1     
 *                -DSR_PIO3_1 : PIO3_1/DSR
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void IOCON_DSRLocate(DSR_Position_Typedef dsr)
{
    CHECK_PARAM(PARAM_DSR(dsr));
    LPC_IOCON->DSRLOC = dsr;
}
Example #28
0
/*********************************************************************//**
 * @brief 		Set ATIMER Interrupt Status
 * @param[in]	ATIMERx Pointer to timer device, should be: LPC_ATIMER
 * @return 		None
 **********************************************************************/
void ATIMER_SetIntStatus(LPC_ATIMER_Type *ATIMERx)
{
	CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
	ATIMERx->SET_STAT = 1;
	while((ATIMERx->STATUS & 1) == 0);
}
Example #29
0
/*********************************************************************//**
 * @brief 		Selects pin location for RI pin
 * @param[in]	sck RI pin position, it can be :
 *                -RI_PIO2_3 : PIO2_3/RI/MOSI1     
 *                -RI_PIO3_3 : PIO3_3/RI
 * @param[in]	None
 * @return 		None
 **********************************************************************/
void IOCON_RILocate(RI_Position_Typedef ri)
{
    CHECK_PARAM(PARAM_RI(ri));
    LPC_IOCON->RILOC = ri;
}
Example #30
0
/*********************************************************************//**
 * @brief 		Enable ATIMER Interrupt
 * @param[in]	ATIMERx Pointer to timer device, should be: LPC_ATIMER
 * @return 		None
 **********************************************************************/
void ATIMER_IntEnable(LPC_ATIMER_Type *ATIMERx)
{
	CHECK_PARAM(PARAM_ATIMERx(ATIMERx));
	ATIMERx->SET_EN = 1;
	while((ATIMERx->ENABLE & 1) == 0);
}