Sold slow control/
Fork of S_SCTRL_SMlib by
Embed:
(wiki syntax)
Show/hide line numbers
S_SCTRL_SM1_hwfunct.cpp
00001 /* hardware functions 00002 * ver 1.0 00003 * ver 1.1x connectors signal working 00004 * ver 1.20 added serialnr read 00005 * ver 1.22 defined cs lines to inactive in safe settings 00006 00007 */ 00008 00009 #include "mbed.h" 00010 #include "S_SCTRL_SM1_PinDef.h" 00011 #include "S_SCTRL_SM1_hwfunct.h" 00012 00013 00014 #define HW_LIB_SRC_VERSION "1.23" 00015 00016 #define MAXLIBVERCHAR 100 // max char for lib version 00017 00018 void assignports(HWlines *hwlines ) { 00019 00020 /// devices 00021 // SPI BI pins 00022 hwlines->msio[0] = new DigitalInOut(ADC_STIO); 00023 hwlines->sclk[0] = new DigitalOut(SCLK); 00024 hwlines->direction[0] = new DigitalOut(DIRECTION); 00025 hwlines->stio_mo[0] = new DigitalOut(STIO_MO); 00026 hwlines->csb1[0] = new DigitalOut(ADC1_CSN); 00027 hwlines->csb2[0] = new DigitalOut(ADC2_CSN); 00028 00029 // SPI pins 00030 hwlines->mosi[0] = new DigitalOut(MOSI); 00031 hwlines->miso[0] = new DigitalIn(MISO); 00032 00033 hwlines->t_cs[0] = new DigitalOut(TEMP_CSN); 00034 hwlines->tc_cs1[0] = new DigitalOut(TEMP_CABLE_CSN1); 00035 hwlines->tc_cs2[0] = new DigitalOut(TEMP_CABLE_CSN2); 00036 hwlines->dac_cs[0] = new DigitalOut(DAC_DCEN); 00037 hwlines->dac_rst[0] = new DigitalOut(DAC_RSTN); 00038 00039 // devices 00040 00041 // SPI BI pins 00042 hwlines->msio[1] = new DigitalInOut(ADC_2_STIO); 00043 hwlines->sclk[1] = new DigitalOut(SCLK_2); 00044 hwlines->direction[1] = new DigitalOut(DIRECTION2); 00045 hwlines->stio_mo[1] = new DigitalOut(STIO2_MO); 00046 hwlines->csb1[1] = new DigitalOut(ADC1_2_CSN); 00047 hwlines->csb2[1] = new DigitalOut(ADC2_2_CSN); 00048 00049 // SPI pins 00050 hwlines->mosi[1] = new DigitalOut(MOSI_2); 00051 hwlines->miso[1] = new DigitalIn(MISO_2); 00052 00053 hwlines->t_cs[1] = new DigitalOut(TEMP_2_CSN); 00054 hwlines->tc_cs1[1] = new DigitalOut(TEMP_2_CABLE_CSN1); 00055 hwlines->tc_cs2[1] = new DigitalOut(TEMP_2_CABLE_CSN2); 00056 hwlines->dac_cs[1] = new DigitalOut(DAC_2_DCEN); 00057 hwlines->dac_rst[1] = new DigitalOut(DAC_2_RSTN); 00058 00059 //cal 00060 hwlines->cal13[0] = new DigitalOut(CAL_TRIG_1AND3); 00061 hwlines->cal24[0] = new DigitalOut(CAL_TRIG_2AND4); 00062 hwlines->calint[0] = new DigitalOut(SEL_CAL_INT); 00063 hwlines->cal13[1] = new DigitalOut(CAL_TRIG_1AND3); 00064 hwlines->cal24[1] = new DigitalOut(CAL_TRIG_2AND4); 00065 hwlines->calint[1] = new DigitalOut(SEL_2_CAL_INT); 00066 00067 hwlines->calext = new DigitalOut(SEL_CAL_EXT); 00068 hwlines->calgenext = new DigitalOut(GEN_EXT_CAL); 00069 00070 hwlines->ledred = new DigitalOut(LEDRED); 00071 hwlines->ledgreen = new DigitalOut(LEDGREEN); 00072 00073 hwlines->ain[0] = new AnalogIn(ADC1); 00074 hwlines->ain[1] = new AnalogIn(ADC2); 00075 00076 hwlines->snr[0] = new DigitalIn(AD0); 00077 hwlines->snr[1] = new DigitalIn(AD1); 00078 hwlines->snr[2] = new DigitalIn(AD2); 00079 hwlines->snr[3] = new DigitalIn(AD3); 00080 hwlines->snr[4] = new DigitalIn(AD4); 00081 00082 } 00083 00084 // select intern or extern cal 0 = intern, 1 is extern 00085 void setcalsource(int external, HWlines hwl) { 00086 *(hwl.calext) = 0; 00087 *(hwl.calint[0]) = 0; 00088 *(hwl.calint[1]) = 0; //disable all 00089 if (external == 1) { 00090 *(hwl.calext) = 1; 00091 } else { 00092 *(hwl.calint[0]) = 1; 00093 *(hwl.calint[1]) = 1; 00094 } 00095 } 00096 00097 // set the default , save values 00098 void setdefault(HWlines hwl) { 00099 for (int i = 0; i < 2; i++) { 00100 hwl.msio[i]->input(); 00101 *(hwl.direction[i]) = RDIR_IN; 00102 *(hwl.stio_mo[i]) = LDIR_IN; 00103 hwl.sclk[i]->write(0); 00104 hwl.csb1[i]->write(0); 00105 hwl.csb2[i]->write(0); 00106 hwl.t_cs[i]->write(0); 00107 hwl.tc_cs1[i]->write(0); 00108 hwl.tc_cs2[i]->write(0); 00109 hwl.dac_cs[i]->write(0); 00110 hwl.dac_rst[i]->write(0); 00111 } 00112 setcalsource(0, hwl); //intern 00113 } 00114 00115 00116 void set_bi_spi_mo(int masterout, DigitalInOut * msio, DigitalOut * ldir, 00117 DigitalOut * rdir) { 00118 // default directions 00119 if (masterout == 0) { // master in 00120 msio->input(); 00121 rdir->write(RDIR_IN); 00122 ldir->write(LDIR_IN); 00123 } else { //master out 00124 ldir->write(LDIR_OUT); 00125 msio->output(); 00126 rdir->write(RDIR_OUT); 00127 } 00128 } 00129 00130 char libversion[MAXLIBVERCHAR] = {'e', 'm', 'p', 't', 'y', '\0'}; 00131 00132 char * hwfunct_lib_version() { 00133 sprintf(libversion, 00134 "hw lib versions src : %s header: %s pindef %s,date:%s %s \n\r", 00135 HW_LIB_SRC_VERSION, HW_LIB_HDR_VERSION, PINDEF_VER, __DATE__, 00136 __TIME__); 00137 return libversion; 00138 } 00139 00140 int get_serialnr(HWlines * hwlines) { 00141 int snr = 0; 00142 for (int bitnr = 4; bitnr >= 0; bitnr--) { 00143 snr = snr << 1; 00144 snr |= hwlines->snr[bitnr]->read(); 00145 } 00146 return snr; 00147 }
Generated on Thu Jul 14 2022 06:06:02 by
