📄 sdo.c
字号:
break;
default:
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
break;
}
}
else
{
/* The index can not be accessed, does not exist */
sdo_error = SDO_ECODE_NONEXISTENT;
}
break;
#endif /* __INCLUDE_TESTS__ */
default:
/* The index can not be accessed, does not exist */
sdo_error = SDO_ECODE_NONEXISTENT;
break;
}
/* Set appropriate SDO command specifier for reply... */
msg_data[0] = SDO_INITIATE_UPLOAD_RESP | SDO_EXPEDITED;
/* ...and segment size (count of non-significant bytes) */
msg_data[0] |= (SDO_SEGMENT_SIZE_INDICATED |
((4-nbytes) << SDO_DATA_SIZE_SHIFT));
return sdo_error;
}
/* ------------------------------------------------------------------------ */
static BYTE sdo_expedited_write( BYTE *msg_data )
{
BYTE sdo_error;
BYTE sdo_mode, nbytes;
BYTE od_index_hi, od_index_lo, od_subind;
/* No error */
sdo_error = 0;
/* Get the number of significant bytes */
sdo_mode = msg_data[0];
if( sdo_mode & SDO_DATA_SIZE_INDICATED )
/* Size indicated */
nbytes = 4-((sdo_mode & SDO_DATA_SIZE_MASK)>>SDO_DATA_SIZE_SHIFT);
else
/* If number of bytes is zero, size was not indicated... */
nbytes = 0;
/* Extract Object Dictionary indices */
od_index_lo = msg_data[1];
od_index_hi = msg_data[2];
od_subind = msg_data[3];
/* Write the requested object */
switch( od_index_hi )
{
case OD_DIGITAL_OUT_HI:
switch( od_index_lo )
{
case OD_DIGITAL_OUT_8_LO:
case OD_DIGITAL_OUT_8_MSK_LO:
if( od_subind != 0 && od_subind <= digout_port_cnt() )
{
if( nbytes <= 1 )
{
if( od_index_lo == OD_DIGITAL_OUT_8_LO )
digout_set_port( od_subind, msg_data[4] );
else
{
if( od_subind == 2 )
digout_set_mask( od_subind, msg_data[4] );
else
/* The sub-index cannot be written to */
sdo_error = SDO_ECODE_ACCESS;
}
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
default:
/* The index can not be accessed, does not exist */
sdo_error = SDO_ECODE_NONEXISTENT;
break;
}
break;
case OD_ANALOG_HI:
switch( od_index_lo )
{
case OD_ANALOG_OUT_16_LO:
if( od_subind != 0 && od_subind <= dac_chan_cnt() )
{
if( nbytes == 2 || nbytes == 0 )
{
if( dac_write( od_subind-1, &msg_data[4] ) == FALSE )
{
/* Something wrong with parameters */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
case OD_ANALOG_IN_DELTA_LO:
case OD_ANALOG_IN_UPPER_LO:
case OD_ANALOG_IN_LOWER_LO:
if( od_subind != 0 &&
(od_subind <= ADC_MAX_INPUTS || od_subind == 0xFF) )
{
if( nbytes == 4 || nbytes == 0 )
{
switch( od_index_lo )
{
case OD_ANALOG_IN_DELTA_LO:
if( adc_set_delta( od_subind-1, &msg_data[4] ) == FALSE )
{
/* EEPROM write operation failed */
sdo_error = SDO_ECODE_HARDWARE;
}
break;
case OD_ANALOG_IN_UPPER_LO:
if( adc_set_upperlimit( od_subind-1, &msg_data[4] ) ==
FALSE )
{
/* EEPROM write operation failed */
sdo_error = SDO_ECODE_HARDWARE;
}
break;
case OD_ANALOG_IN_LOWER_LO:
if( adc_set_lowerlimit( od_subind-1, &msg_data[4] ) ==
FALSE )
{
/* EEPROM write operation failed */
sdo_error = SDO_ECODE_HARDWARE;
}
break;
default:
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
break;
}
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
case OD_ANALOG_IN_INT_ENA_LO:
if( od_subind == 0 )
{
if( nbytes <= 1 )
{
if( adc_set_readout_on_change( msg_data[4] ) == FALSE )
sdo_error = SDO_ECODE_ATTRIBUTE;
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
default:
/* The index can not be accessed, does not exist */
sdo_error = SDO_ECODE_NONEXISTENT;
break;
}
break;
case OD_ADC_CONFIG_HI:
switch( od_index_lo )
{
case OD_ADC_CONFIG_LO:
if( adc_set_config( od_subind, nbytes, &msg_data[4] ) == FALSE )
{
/* Setting the parameter did not succeed:
- the sub-index does not exist or
- the parameter is read-only or
- the number of bytes is incorrect or
- parameter value is out of range or
- parameter can not be set: ADC in use */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
case OD_ADC_RESET_CALIB_LO:
if( od_subind == 0 )
{
if( nbytes <= 1 )
{
if( adc_reset_and_calibrate( TRUE ) == FALSE )
{
/* Reset or calibrate operation failed */
sdo_error = SDO_ECODE_HARDWARE;
}
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
case OD_ADC_RECALIB_SCAN_LO:
if( od_subind == 0 )
{
if( nbytes <= 1 )
{
if( adc_set_calib_before_scan( msg_data[4] ) == FALSE )
sdo_error = SDO_ECODE_ATTRIBUTE;
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
case OD_ADC_DELTA_ENA_LO:
if( od_subind == 0 )
{
if( nbytes <= 1 )
{
if( adc_set_delta_scan_ena( msg_data[4] ) == FALSE )
sdo_error = SDO_ECODE_ATTRIBUTE;
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
case OD_ADC_WINDOW_ENA_LO:
if( od_subind == 0 )
{
if( nbytes <= 1 )
{
if( adc_set_window_scan_ena( msg_data[4] ) == FALSE )
sdo_error = SDO_ECODE_ATTRIBUTE;
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
case OD_ADC_WINDOW_CNTR_LO:
if( od_subind == 0 )
{
if( nbytes <= 1 )
{
if( adc_set_window_scan_cntr( msg_data[4] ) == FALSE )
sdo_error = SDO_ECODE_ATTRIBUTE;
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
default:
/* The index can not be accessed, does not exist */
sdo_error = SDO_ECODE_NONEXISTENT;
break;
}
break;
case OD_TPDO_PAR_HI:
if( od_index_lo < TPDO_CNT )
{
if( tpdo_set_comm_par( od_index_lo, od_subind,
nbytes, &msg_data[4] ) == FALSE )
{
/* The subindex does not exist or the number of bytes
is incorrect or the parameter could not be written */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The index can not be accessed, does not exist */
sdo_error = SDO_ECODE_NONEXISTENT;
}
break;
case OD_DIGITAL_IN_HI:
switch( od_index_lo )
{
case OD_DIGIN_INTRPT_ENA_LO:
if( od_subind == 0 )
{
if( nbytes <= 1 )
{
if( digin_set_intrpt_ena( msg_data[4] ) == FALSE )
sdo_error = SDO_ECODE_ATTRIBUTE;
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
case OD_DIGIN_INTRPT_MSK_LO:
if( od_subind != 0 && od_subind <= digin_port_cnt() )
{
if( nbytes <= 1 )
{
digin_set_intrpt_mask( od_subind, msg_data[4] );
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
default:
/* The index can not be accessed, does not exist */
sdo_error = SDO_ECODE_NONEXISTENT;
break;
}
break;
case OD_DIGIN_PAR_HI:
if( od_index_lo == OD_DIGIN_DEBOUNCE_LO )
{
if( od_subind == 0 )
{
if( nbytes <= 1 )
{
digin_set_debounce( msg_data[4] );
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The index can not be accessed, does not exist */
sdo_error = SDO_ECODE_NONEXISTENT;
}
break;
case OD_DIGOUT_PAR_HI:
if( od_index_lo == OD_DIGOUT_INIT_LO )
{
if( od_subind == 0 )
{
if( nbytes <= 1 )
{
if( digout_set_init( msg_data[4] ) == FALSE )
sdo_error = SDO_ECODE_ATTRIBUTE;
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The index can not be accessed, does not exist */
sdo_error = SDO_ECODE_NONEXISTENT;
}
break;
case OD_DAC_CONFIG_HI:
if( od_index_lo == OD_DAC_CONFIG_LO )
{
switch( od_subind )
{
case 2:
if( nbytes <= 1 )
{
if( dac_set_max525_select( msg_data[4] ) == FALSE )
sdo_error = SDO_ECODE_ATTRIBUTE;
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
case 3:
if( nbytes <= 1 )
{
if( dac_set_opto_delay( msg_data[4] ) == FALSE )
sdo_error = SDO_ECODE_ATTRIBUTE;
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
default:
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
break;
}
}
else
{
/* The index can not be accessed, does not exist */
sdo_error = SDO_ECODE_NONEXISTENT;
}
break;
case OD_SPI_HI:
switch( od_index_lo )
{
case OD_SPI_ACCESS_LO:
if( od_subind > OD_NO_OF_ENTRIES && od_subind < 5 )
{
if( nbytes == 4 || nbytes == 0 )
{
switch( od_subind )
{
case 4:
spi_write_byte( msg_data[7] );
case 3:
spi_write_byte( msg_data[6] );
case 2:
spi_write_byte( msg_data[5] );
case 1:
spi_write_byte( msg_data[4] );
break;
}
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
case OD_SPI_SELECT_LO:
if( od_subind == 0 )
{
if( nbytes <= 1 )
{
if( spi_set_chipselect( msg_data[4] ) == FALSE )
sdo_error = SDO_ECODE_ATTRIBUTE;
}
else
{
/* Wrong number of bytes provided */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
}
else
{
/* The sub-index does not exist */
sdo_error = SDO_ECODE_ATTRIBUTE;
}
break;
case OD_SPI_CONFIG_LO:
switch( od_subind )
{
case 1:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -