Esempio n. 1
0
void test_dyn_map1 (void)
{
	DDS_DynamicTypeSupport ts;
	DDS_DynamicTypeBuilder sb1, mb, sb;
	DDS_DynamicType s1, s, m;
	DDS_TypeDescriptor *desc;
	DDS_MemberDescriptor *md;
	DDS_DynamicData dd, dd2, ddm;
	DDS_ReturnCode_t rc;

	v_printf ("test_dyn_map1 - ");

	/* 1. Create the type. */
	desc = DDS_TypeDescriptor__alloc ();
	fail_unless (desc != NULL);

	md = DDS_MemberDescriptor__alloc ();
	fail_unless (md != NULL);

	sb = DDS_DynamicTypeBuilderFactory_create_string_type (50);
	fail_unless (sb != NULL);

	s = DDS_DynamicTypeBuilder_build (sb);
	fail_unless (s != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (sb);

	mb = DDS_DynamicTypeBuilderFactory_create_map_type (
		DDS_DynamicTypeBuilderFactory_get_primitive_type (DDS_INT_32_TYPE),
		s, DDS_UNBOUNDED_COLLECTION);
	fail_unless (mb != NULL);

	m = DDS_DynamicTypeBuilder_build (mb);
	fail_unless (m != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (mb);

	desc->kind = DDS_STRUCTURE_TYPE;
	desc->name = "dmap1";

	sb1 = DDS_DynamicTypeBuilderFactory_create_type (desc);
	fail_unless (sb1 != NULL);

	md->name = "m";
	md->id = 0;
	md->type = m;
	md->index = 0;
	fail_unless (md->type != NULL);

	rc = DDS_DynamicTypeBuilder_add_member (sb1, md);
	fail_unless (rc == DDS_RETCODE_OK);

	md->name = "b";
	md->id = 1;
	md->type = DDS_DynamicTypeBuilderFactory_get_primitive_type (DDS_INT_64_TYPE);
	md->index = 1;
	fail_unless (md->type != NULL);

	rc = DDS_DynamicTypeBuilder_add_member (sb1, md);
	fail_unless (rc == DDS_RETCODE_OK);

	s1 = DDS_DynamicTypeBuilder_build (sb1);
	fail_unless (s1 != NULL);

	DDS_DynamicTypeBuilderFactory_delete_type (sb1);

	ts = DDS_DynamicTypeSupport_create_type_support (s1);
	fail_unless (ts != NULL);

	DDS_TypeDescriptor__free (desc);
	DDS_MemberDescriptor__free (md);

	DDS_TypeSupport_dump_type (0, (DDS_TypeSupport) ts, 15);

	/* 2. Create a Dynamic data item for this type. */
	ddm = DDS_DynamicDataFactory_create_data (m);
	md->name = "key";
	md->id = DDS_DynamicData_get_member_id_by_name (ddm, "alfa");
	md->type = DDS_DynamicTypeBuilderFactory_get_primitive_type (DDS_INT_32_TYPE);
	md->default_value = "0"; 
	md->index = 0;
	md->default_label = 0;


	dd = DDS_DynamicDataFactory_create_data (s1);
	fail_unless (dd != NULL);

	rc = DDS_DynamicData_set_int32_value (dd, 0, 0xCAFEBABE);
	fail_unless (rc == DDS_RETCODE_OK);

	rc = DDS_DynamicData_set_int64_value (dd, 1, -1);
	fail_unless (rc == DDS_RETCODE_OK);

	marshallDynamic (dd, &dd2, ts);

	DDS_DynamicDataFactory_delete_data (dd);
	DDS_DynamicTypeBuilderFactory_delete_type (s1);
	DDS_DynamicTypeSupport_delete_type_support (ts);

	v_printf ("success!\r\n");
}
Esempio n. 2
0
static qeo_retcode_t data_member_accessor(qeocore_data_t *data,
                                          qeocore_member_id_t id,
                                          void *value,
                                          int get)
{
    qeo_retcode_t rc = QEO_EINVAL;
    DDS_ReturnCode_t ddsrc;
    DDS_DynamicTypeMember mtype = DDS_DynamicTypeMember__alloc();
    DDS_DynamicType dyntype = dtype_from_data(data, &data->d.dynamic);
    DDS_DynamicData dyndata = (DDS_DynamicData)sample_from_data(data);

    if (NULL != mtype) {
        ddsrc = DDS_DynamicType_get_member(dyntype, mtype, id);
        qeo_log_dds_rc("DDS_DynamicType_get_member", ddsrc);
        if (DDS_RETCODE_OK == ddsrc) {
            DDS_ReturnCode_t ddsrc = DDS_RETCODE_BAD_PARAMETER;
            DDS_MemberDescriptor mdesc = { 0 };
            DDS_TypeDescriptor tdesc = { 0 };

            ddsrc = DDS_DynamicTypeMember_get_descriptor(mtype, &mdesc);
            qeo_log_dds_rc("DDS_DynamicTypeMember_get_descriptor", ddsrc);
            ddsrc = DDS_DynamicType_get_descriptor(mdesc.type, &tdesc);
            qeo_log_dds_rc("DDS_DynamicType_get_descriptor", ddsrc);
            switch (tdesc.kind) {
                case DDS_BOOLEAN_TYPE: {
                    if (get) {
                        ddsrc = DDS_DynamicData_get_boolean_value(dyndata, (qeo_boolean_t *)value, id);
                        qeo_log_dds_rc("DDS_DynamicData_get_boolean_value", ddsrc);
                    }
                    else {
                        ddsrc = DDS_DynamicData_set_boolean_value(dyndata, id, *((qeo_boolean_t *)value));
                        qeo_log_dds_rc("DDS_DynamicData_set_boolean_value", ddsrc);
                    }
                    break;
                }
                case DDS_BYTE_TYPE: /* QEOCORE_TYPECODE_INT8 */
                    if (get) {
                        ddsrc = DDS_DynamicData_get_byte_value(dyndata, (unsigned char *)value, id);
                        qeo_log_dds_rc("DDS_DynamicData_get_byte_value", ddsrc);
                    }
                    else {
                        ddsrc = DDS_DynamicData_set_byte_value(dyndata, id, *((unsigned char *)value));
                        qeo_log_dds_rc("DDS_DynamicData_set_byte_value", ddsrc);
                    }
                    break;
                case DDS_INT_16_TYPE: /* QEOCORE_TYPECODE_INT16 */
                    if (get) {
                        ddsrc = DDS_DynamicData_get_int16_value(dyndata, (int16_t *)value, id);
                        qeo_log_dds_rc("DDS_DynamicData_get_int16_value", ddsrc);
                    }
                    else {
                        ddsrc = DDS_DynamicData_set_int16_value(dyndata, id, *((int16_t *)value));
                        qeo_log_dds_rc("DDS_DynamicData_set_int16_value", ddsrc);
                    }
                    break;
                case DDS_INT_32_TYPE: /* QEOCORE_TYPECODE_INT32 */
                case DDS_ENUMERATION_TYPE: /* QEOCORE_TYPECODE_ENUM */
                    if (get) {
                        ddsrc = DDS_DynamicData_get_int32_value(dyndata, (int32_t *)value, id);
                        qeo_log_dds_rc("DDS_DynamicData_get_int32_value", ddsrc);
                    }
                    else {
                        ddsrc = DDS_DynamicData_set_int32_value(dyndata, id, *((int32_t *)value));
                        qeo_log_dds_rc("DDS_DynamicData_set_int32_value", ddsrc);
                    }
                    break;
                case DDS_INT_64_TYPE: /* QEOCORE_TYPECODE_INT64 */
                    if (get) {
                        ddsrc = DDS_DynamicData_get_int64_value(dyndata, (int64_t *)value, id);
                        qeo_log_dds_rc("DDS_DynamicData_get_int64_value", ddsrc);
                    }
                    else {
                        ddsrc = DDS_DynamicData_set_int64_value(dyndata, id, *((int64_t *)value));
                        qeo_log_dds_rc("DDS_DynamicData_set_int64_value", ddsrc);
                    }
                    break;
                case DDS_FLOAT_32_TYPE: /* QEOCORE_TYPECODE_FLOAT32 */
                    if (get) {
                        ddsrc = DDS_DynamicData_get_float32_value(dyndata, (float *)value, id);
                        qeo_log_dds_rc("DDS_DynamicData_get_float32_value", ddsrc);
                    }
                    else {
                        ddsrc = DDS_DynamicData_set_float32_value(dyndata, id, *((float *)value));
                        qeo_log_dds_rc("DDS_DynamicData_set_float32_value", ddsrc);
                    }
                    break;
                case DDS_STRING_TYPE: /* QEOCORE_TYPECODE_STRING */
                    if (get) {
                        char **string = (char **)value;
                        int len = DDS_DynamicData_get_string_length(dyndata, id);

                        if (len > -1) {
                            *string = malloc(len + 1);
                            if (NULL != *string) {
                                ddsrc = DDS_DynamicData_get_string_value(dyndata, *string, id);
                                qeo_log_dds_rc("DDS_DynamicData_get_string_value", ddsrc);
                                if (DDS_RETCODE_OK != ddsrc) {
                                    free(*string);
                                    *string = NULL;
                                }
                            }
                        }
                    }
                    else {
                        char **string = (char **)value;

                        ddsrc = DDS_DynamicData_set_string_value(dyndata, id, *string);
                        qeo_log_dds_rc("DDS_DynamicData_set_string_value", ddsrc);
                    }
                    break;
                case DDS_SEQUENCE_TYPE: { /* QEOCORE_TYPECODE_SEQUENCE */
                    if (get) {
                        ddsrc = sequence_get(value, dyndata, id, mdesc.type);
                    }
                    else {
                        ddsrc = sequence_set(value, dyndata, id);
                    }
                    break;
                }
                case DDS_STRUCTURE_TYPE: { /* QEOCORE_TYPECODE_STRUCT */
                    qeocore_data_t **inner_data = (qeocore_data_t **)value;

                    if (get) {
                        ddsrc = struct_get(inner_data, dyndata, id, &mdesc);
                    }
                    else {
                        ddsrc = struct_set(inner_data, dyndata, id);
                    }
                    break;
                }
                default:
                    qeo_log_e("unsupported type %d", tdesc.kind);
                    abort(); // unsupported for now
                    break;
            }
            DDS_MemberDescriptor__clear(&mdesc);
            DDS_TypeDescriptor__clear(&tdesc);

            //TODO: Make the following code more generic and use the overall error translation function
            if ((DDS_RETCODE_OK == ddsrc) || (DDS_RETCODE_NO_DATA == ddsrc)){
                rc = QEO_OK;
            } else if (DDS_RETCODE_OUT_OF_RESOURCES == ddsrc) {
                rc = QEO_ENOMEM;
            } else {
                rc = QEO_EFAIL;
            }
        }
        DDS_DynamicTypeMember__free(mtype);
    }
    return rc;
}
Esempio n. 3
0
	if ((XRESET_GPIO_pin > 7) || (DREQ_GPIO_pin > 7))
		return MP3_VS1053_INVALID_PARAMETER;

	mp3_VS1053_prvt_ctx.hSpiMaster = spi_master_handle;
	mp3_VS1053_prvt_ctx.XRESET_GPIO_port = XRESET_GPIO_port;
	mp3_VS1053_prvt_ctx.XRESET_GPIO_pin = XRESET_GPIO_pin;
	mp3_VS1053_prvt_ctx.DREQ_GPIO_port = DREQ_GPIO_port;
	mp3_VS1053_prvt_ctx.DREQ_GPIO_pin = DREQ_GPIO_pin;
	mp3_VS1053_prvt_ctx.SDI_CS_identifier = SDI_CS_identifier;
	mp3_VS1053_prvt_ctx.SCI_CS_identifier = SCI_CS_identifier;

	return MP3_VS1053_OK;
}

int	mp3_VS1053_detach()
{
	mp3_VS1053_prvt_ctx.hSpiMaster = NULL;

	return MP3_VS1053_OK;
}

int mp3_VS1053_hard_reset(void)
{
	unsigned char mask;
	mask = 0x01 << mp3_VS1053_prvt_ctx.XRESET_GPIO_pin;

	switch (mp3_VS1053_prvt_ctx.XRESET_GPIO_port)
	{
		case PORT_A:
			vII_gpio_data_tx_pa_1 &= (~mask); // set the pin LOW
			vos_delay_msecs(3); // wait for some time
			vII_gpio_data_tx_pa_1 |= mask; // set the pin HIGH
			break;
		case PORT_B:
			vII_gpio_data_tx_pb_1 &= (~mask); // set the pin LOW
			vos_delay_msecs(3); // wait for some time
			vII_gpio_data_tx_pb_1 |= mask; // set the pin HIGH
			break;
		case PORT_C:
			vII_gpio_data_tx_pc_1 &= (~mask); // set the pin LOW
			vos_delay_msecs(3); // wait for some time
			vII_gpio_data_tx_pc_1 |= mask; // set the pin HIGH
			break;
		case PORT_D:
			vII_gpio_data_tx_pd_1 &= (~mask); // set the pin LOW
			vos_delay_msecs(3); // wait for some time
			vII_gpio_data_tx_pd_1 |= mask; // set the pin HIGH
			break;
		case PORT_E:
			vII_gpio_data_tx_pe_1 &= (~mask); // set the pin LOW
			vos_delay_msecs(3); // wait for some time
			vII_gpio_data_tx_pe_1 |= mask; // set the pin HIGH
			break;
		default:
			return MP3_VS1053_INVALID_PARAMETER;
	}
	return MP3_VS1053_OK;
}
	
int mp3_VS1053_soft_reset(void)
{
	mp3_VS1053_write_reg(SCI_MODE, MASK_SM_RESET); // Set Reset bit in mode register
	vos_delay_msecs(2); // At least 2 millisecond delay
	mp3_VS1053_wait_for_dreq(); // wait for startup
	// Then set mode register and clock register again
	mp3_VS1053_write_reg(SCI_MODE, MASK_SM_SDINEW_VS1002);
	mp3_VS1053_write_reg(SCI_CLOCKF, 0x8800);
	vos_delay_msecs(1); // 1 millisecond delay
	mp3_VS1053_wait_for_dreq(); // wait for the commands to complete

	return MP3_VS1053_OK;
}	

int mp3_VS1053_setup(void)
{
	unsigned short regVal;
	common_ioctl_cb_t spim_iocb;

	// Initialize SPI pins
	// Reset VS1053 codec hardware
	mp3_VS1053_hard_reset();
	// Configure VS1053 defaults
	mp3_VS1053_write_reg(SCI_MODE, MASK_SM_SDINEW_VS1002);	
	mp3_VS1053_write_reg(SCI_CLOCKF, 0xe000);
	return 0;
}

// Waits for the DREQ line to go high...
int mp3_VS1053_wait_for_dreq(void)
{
	unsigned char port_value = 0, mask;
	int timeout = 0;
	
	mask = 0x01 << mp3_VS1053_prvt_ctx.DREQ_GPIO_pin;
	
	switch (mp3_VS1053_prvt_ctx.DREQ_GPIO_port)
	{
		case PORT_A:
			// Read the pin. If the pin is LOW, continue reading it until it is HIGH
			do
			{
				port_value = vII_gpio_data_rx_pa_1;
			}
			while ((port_value & mask) == 0);
			break;
		case PORT_B:
			// Read the pin. If the pin is LOW, continue reading it until it is HIGH
			do {
				port_value = vII_gpio_data_rx_pb_1;
				//vos_delay_msecs(1);
			} while ((port_value & mask) == 0);
			break;
		case PORT_C:
			// Read the pin. If the pin is LOW, continue reading it until it is HIGH
			do
			{
				port_value = vII_gpio_data_rx_pc_1;
			}
			while ((port_value & mask) == 0);
			break;
		case PORT_D:
			// Read the pin. If the pin is LOW, continue reading it until it is HIGH
			do
			{
				port_value = vII_gpio_data_rx_pd_1;
			}
			while ((port_value & mask) == 0);
			break;
		case PORT_E:
			// Read the pin. If the pin is LOW, continue reading it until it is HIGH
			do
			{
				port_value = vII_gpio_data_rx_pe_1;
			}
			while ((port_value & mask) == 0);
			break;
		default:
			return MP3_VS1053_INVALID_PARAMETER;
	}		
}

int mp3_VS1053_select_control(void)	
{
	if (mp3_VS1053_prvt_ctx.SCI_CS_identifier == SPI_CHIP_SELECT_0)
		spim_iocb.ioctl_code = VOS_IOCTL_SPI_MASTER_SS_0;
	else if (mp3_VS1053_prvt_ctx.SCI_CS_identifier == SPI_CHIP_SELECT_1)
		spim_iocb.ioctl_code = VOS_IOCTL_SPI_MASTER_SS_1;
	spim_iocb.set.param = SPI_MASTER_SS_ENABLE;
	vos_dev_ioctl(mp3_VS1053_prvt_ctx.hSpiMaster, &spim_iocb);
	
	return MP3_VS1053_OK;