hw functions for the SOLID slow control

Dependents:   S_SCTRL_e_test SPItest sscm

Committer:
wbeaumont
Date:
Fri Oct 23 11:22:52 2015 +0000
Revision:
16:6bbb6bb0678a
Parent:
14:ee02872b282b
production version archiving

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wbeaumont 8:fe1477cd1c14 1 /* hardware functions
wbeaumont 8:fe1477cd1c14 2 * ver 1.0
wbeaumont 8:fe1477cd1c14 3 * ver 1.1x connectors signal working
wbeaumont 8:fe1477cd1c14 4 * ver 1.20 added serialnr read
wbeaumont 9:20f21cb7792e 5 * ver 1.22 defined cs lines to inactive in safe settings
wbeaumont 11:0416cf017b7a 6 * ver 1.30 added CAL puls function
wbeaumont 13:3d82f8e27414 7 * ver 1.31 added CAL line lvl function
wbeaumont 13:3d82f8e27414 8 * ver 1.32 added bias2dac voltage and dac2bias
wbeaumont 14:ee02872b282b 9 * ver 1.33 removed bias2dac voltage and dac2bias
wbeaumont 16:6bbb6bb0678a 10 *
wbeaumont 16:6bbb6bb0678a 11 * (C) Wim Beaumont Univeristeit Antwerpen 2014 , 2015
wbeaumont 8:fe1477cd1c14 12 */
wbeaumont 8:fe1477cd1c14 13
wbeaumont 0:8d755a0f3ab3 14 #include "mbed.h"
wbeaumont 0:8d755a0f3ab3 15 #include "S_SCTRL_SM1_PinDef.h"
wbeaumont 1:af78e316f889 16 #include "S_SCTRL_SM1_hwfunct.h"
wbeaumont 1:af78e316f889 17
wbeaumont 0:8d755a0f3ab3 18
wbeaumont 14:ee02872b282b 19 #define HW_LIB_SRC_VERSION "1.33"
wbeaumont 3:39671ee1347d 20
wbeaumont 3:39671ee1347d 21 #define MAXLIBVERCHAR 100 // max char for lib version
wbeaumont 0:8d755a0f3ab3 22
wbeaumont 1:af78e316f889 23 void assignports(HWlines *hwlines ){
wbeaumont 0:8d755a0f3ab3 24
wbeaumont 0:8d755a0f3ab3 25 /// devices
wbeaumont 0:8d755a0f3ab3 26 // SPI BI pins
wbeaumont 1:af78e316f889 27 hwlines->msio[0] = new DigitalInOut(ADC_STIO);
wbeaumont 1:af78e316f889 28 hwlines->sclk[0] = new DigitalOut(SCLK);
wbeaumont 1:af78e316f889 29 hwlines->direction[0] = new DigitalOut(DIRECTION);
wbeaumont 1:af78e316f889 30 hwlines->stio_mo[0] = new DigitalOut(STIO_MO);
wbeaumont 4:a83242fe9d37 31 hwlines->csb1[0] = new DigitalOut(ADC1_CSN);
wbeaumont 4:a83242fe9d37 32 hwlines->csb2[0] = new DigitalOut(ADC2_CSN);
wbeaumont 0:8d755a0f3ab3 33
wbeaumont 0:8d755a0f3ab3 34
wbeaumont 0:8d755a0f3ab3 35
wbeaumont 0:8d755a0f3ab3 36 // SPI pins
wbeaumont 1:af78e316f889 37 hwlines->mosi[0] = new DigitalOut(MOSI);
wbeaumont 1:af78e316f889 38 hwlines->miso[0] = new DigitalIn(MISO);
wbeaumont 0:8d755a0f3ab3 39
wbeaumont 1:af78e316f889 40 hwlines->t_cs[0] = new DigitalOut(TEMP_CSN);
wbeaumont 1:af78e316f889 41 hwlines->tc_cs1[0] = new DigitalOut(TEMP_CABLE_CSN1);
wbeaumont 1:af78e316f889 42 hwlines->tc_cs2[0] = new DigitalOut(TEMP_CABLE_CSN2);
wbeaumont 1:af78e316f889 43 hwlines->dac_cs[0] = new DigitalOut(DAC_DCEN);
wbeaumont 1:af78e316f889 44 hwlines->dac_rst[0] = new DigitalOut(DAC_RSTN);
wbeaumont 0:8d755a0f3ab3 45
wbeaumont 0:8d755a0f3ab3 46
wbeaumont 0:8d755a0f3ab3 47
wbeaumont 0:8d755a0f3ab3 48
wbeaumont 0:8d755a0f3ab3 49 // devices
wbeaumont 0:8d755a0f3ab3 50 // SPI BI pins
wbeaumont 1:af78e316f889 51 hwlines->msio[1] = new DigitalInOut(ADC_2_STIO);
wbeaumont 1:af78e316f889 52 hwlines->sclk[1] = new DigitalOut(SCLK_2);
wbeaumont 1:af78e316f889 53 hwlines->direction[1] = new DigitalOut(DIRECTION2);
wbeaumont 1:af78e316f889 54 hwlines->stio_mo[1] = new DigitalOut(STIO2_MO);
wbeaumont 4:a83242fe9d37 55 hwlines->csb1[1] = new DigitalOut(ADC1_2_CSN);
wbeaumont 4:a83242fe9d37 56 hwlines->csb2[1] = new DigitalOut(ADC2_2_CSN);
wbeaumont 0:8d755a0f3ab3 57
wbeaumont 0:8d755a0f3ab3 58 // SPI pins
wbeaumont 1:af78e316f889 59 hwlines->mosi[1] = new DigitalOut(MOSI_2);
wbeaumont 1:af78e316f889 60 hwlines->miso[1] = new DigitalIn(MISO_2);
wbeaumont 0:8d755a0f3ab3 61
wbeaumont 1:af78e316f889 62 hwlines->t_cs[1] = new DigitalOut(TEMP_2_CSN);
wbeaumont 1:af78e316f889 63 hwlines->tc_cs1[1] = new DigitalOut(TEMP_2_CABLE_CSN1);
wbeaumont 1:af78e316f889 64 hwlines->tc_cs2[1] = new DigitalOut(TEMP_2_CABLE_CSN2);
wbeaumont 1:af78e316f889 65 hwlines->dac_cs[1] = new DigitalOut(DAC_2_DCEN);
wbeaumont 1:af78e316f889 66 hwlines->dac_rst[1] = new DigitalOut(DAC_2_RSTN);
wbeaumont 0:8d755a0f3ab3 67
wbeaumont 0:8d755a0f3ab3 68
wbeaumont 0:8d755a0f3ab3 69 //cal
wbeaumont 1:af78e316f889 70 hwlines->cal13[0] = new DigitalOut(CAL_TRIG_1AND3);
wbeaumont 1:af78e316f889 71 hwlines->cal24[0] = new DigitalOut(CAL_TRIG_2AND4);
wbeaumont 1:af78e316f889 72 hwlines->calint[0] = new DigitalOut(SEL_CAL_INT);
wbeaumont 1:af78e316f889 73 hwlines->cal13[1] = new DigitalOut(CAL_TRIG_1AND3);
wbeaumont 1:af78e316f889 74 hwlines->cal24[1] = new DigitalOut(CAL_TRIG_2AND4);
wbeaumont 1:af78e316f889 75 hwlines->calint[1] = new DigitalOut(SEL_2_CAL_INT);
wbeaumont 0:8d755a0f3ab3 76
wbeaumont 1:af78e316f889 77 hwlines->calext = new DigitalOut(SEL_CAL_EXT);
wbeaumont 1:af78e316f889 78 hwlines->calgenext = new DigitalOut(GEN_EXT_CAL);
wbeaumont 0:8d755a0f3ab3 79
wbeaumont 1:af78e316f889 80 hwlines->ledred = new DigitalOut(LEDRED);
wbeaumont 1:af78e316f889 81 hwlines->ledgreen = new DigitalOut(LEDGREEN);
wbeaumont 0:8d755a0f3ab3 82
wbeaumont 1:af78e316f889 83 hwlines->ain[0] = new AnalogIn(ADC1);
wbeaumont 1:af78e316f889 84 hwlines->ain[1] = new AnalogIn(ADC2);
wbeaumont 0:8d755a0f3ab3 85
wbeaumont 8:fe1477cd1c14 86 hwlines->snr[0] = new DigitalIn(AD0);
wbeaumont 8:fe1477cd1c14 87 hwlines->snr[1] = new DigitalIn(AD1);
wbeaumont 8:fe1477cd1c14 88 hwlines->snr[2] = new DigitalIn(AD2);
wbeaumont 8:fe1477cd1c14 89 hwlines->snr[3] = new DigitalIn(AD3);
wbeaumont 8:fe1477cd1c14 90 hwlines->snr[4] = new DigitalIn(AD4);
wbeaumont 0:8d755a0f3ab3 91
wbeaumont 0:8d755a0f3ab3 92 }
wbeaumont 0:8d755a0f3ab3 93
wbeaumont 0:8d755a0f3ab3 94
wbeaumont 0:8d755a0f3ab3 95
wbeaumont 0:8d755a0f3ab3 96 // select intern or extern cal 0 = intern, 1 is extern
wbeaumont 1:af78e316f889 97 void setcalsource( int external, HWlines hwl) {
wbeaumont 9:20f21cb7792e 98 *(hwl.calext)=0;
wbeaumont 9:20f21cb7792e 99 *(hwl.calint[0])=0; *(hwl.calint[1])=0; //disable all
wbeaumont 0:8d755a0f3ab3 100 if ( external==1 ) {*(hwl.calext)=1; }
wbeaumont 8:fe1477cd1c14 101 else {*(hwl.calint[0])=1; *(hwl.calint[1])=1; }
wbeaumont 0:8d755a0f3ab3 102
wbeaumont 0:8d755a0f3ab3 103
wbeaumont 0:8d755a0f3ab3 104 }
wbeaumont 0:8d755a0f3ab3 105
wbeaumont 5:b527df9432c3 106 // set the default , save values
wbeaumont 0:8d755a0f3ab3 107 void setdefault(HWlines hwl ) {
wbeaumont 11:0416cf017b7a 108 for ( int i=0;i<2;i++){ // i == connector
wbeaumont 0:8d755a0f3ab3 109 hwl.msio[i]->input();
wbeaumont 8:fe1477cd1c14 110 *(hwl.direction[i])=RDIR_IN;
wbeaumont 8:fe1477cd1c14 111 *(hwl.stio_mo[i])=LDIR_IN;
wbeaumont 9:20f21cb7792e 112 hwl.sclk[i]->write(0);
wbeaumont 9:20f21cb7792e 113 hwl.csb1[i]->write(0);
wbeaumont 9:20f21cb7792e 114 hwl.csb2[i]->write(0);
wbeaumont 9:20f21cb7792e 115 hwl.t_cs[i]->write(0);
wbeaumont 9:20f21cb7792e 116 hwl.tc_cs1[i]->write(0);
wbeaumont 9:20f21cb7792e 117 hwl.tc_cs2[i]->write(0);
wbeaumont 9:20f21cb7792e 118 hwl.dac_cs[i]->write(0);
wbeaumont 9:20f21cb7792e 119 hwl.dac_rst[i]->write(0);
wbeaumont 0:8d755a0f3ab3 120 }
wbeaumont 11:0416cf017b7a 121 hwl.cal13[0]->write(CAL_DEACTIVE);
wbeaumont 11:0416cf017b7a 122 hwl.cal24[0]->write(CAL_DEACTIVE);
wbeaumont 1:af78e316f889 123 setcalsource(0,hwl); //intern
wbeaumont 0:8d755a0f3ab3 124 }
wbeaumont 0:8d755a0f3ab3 125
wbeaumont 6:24e981a63851 126
wbeaumont 5:b527df9432c3 127 void set_bi_spi_mo(int masterout, DigitalInOut* msio, DigitalOut* ldir, DigitalOut* rdir){
wbeaumont 5:b527df9432c3 128 // default directions
wbeaumont 5:b527df9432c3 129 if( masterout == 0 ) { // master in
wbeaumont 5:b527df9432c3 130 msio->input();
wbeaumont 5:b527df9432c3 131 rdir->write(RDIR_IN);
wbeaumont 5:b527df9432c3 132 ldir->write(LDIR_IN);
wbeaumont 5:b527df9432c3 133
wbeaumont 5:b527df9432c3 134 }
wbeaumont 5:b527df9432c3 135 else { //master out
wbeaumont 5:b527df9432c3 136
wbeaumont 5:b527df9432c3 137 ldir->write(LDIR_OUT);
wbeaumont 5:b527df9432c3 138 msio->output();
wbeaumont 5:b527df9432c3 139 rdir->write(RDIR_OUT);
wbeaumont 5:b527df9432c3 140 }
wbeaumont 5:b527df9432c3 141 }
wbeaumont 5:b527df9432c3 142
wbeaumont 5:b527df9432c3 143
wbeaumont 6:24e981a63851 144
wbeaumont 3:39671ee1347d 145 char libversion[MAXLIBVERCHAR]={'e','m','p','t','y','\0'};
wbeaumont 12:467def75b457 146
wbeaumont 12:467def75b457 147
wbeaumont 12:467def75b457 148 void set_cal_line(HWlines hwl, int calline ,int level ){
wbeaumont 12:467def75b457 149 int lvl;
wbeaumont 12:467def75b457 150 if( level ==1) lvl=CAL_ACTIVE; else lvl=CAL_DEACTIVE;
wbeaumont 12:467def75b457 151 if( calline == 0) {
wbeaumont 12:467def75b457 152 hwl.cal13[0]->write(lvl); //index can be hard coded as it are the same lines)
wbeaumont 12:467def75b457 153 hwl.cal24[0]->write(lvl);
wbeaumont 12:467def75b457 154 }
wbeaumont 12:467def75b457 155 if( calline == 1) {
wbeaumont 12:467def75b457 156 hwl.cal13[0]->write(lvl); //index can be hard coded as it are the same lines)
wbeaumont 12:467def75b457 157 }
wbeaumont 12:467def75b457 158 if( calline == 2) {
wbeaumont 12:467def75b457 159 hwl.cal24[0]->write(lvl);
wbeaumont 12:467def75b457 160 }
wbeaumont 12:467def75b457 161
wbeaumont 12:467def75b457 162 }
wbeaumont 11:0416cf017b7a 163
wbeaumont 11:0416cf017b7a 164 void toggle_cal(HWlines hwl, int calline){
wbeaumont 11:0416cf017b7a 165 if( calline == 0) {
wbeaumont 11:0416cf017b7a 166 hwl.cal13[0]->write(CAL_ACTIVE); //index can be hard coded as it are the same lines)
wbeaumont 11:0416cf017b7a 167 hwl.cal24[0]->write(CAL_ACTIVE);
wbeaumont 11:0416cf017b7a 168 }
wbeaumont 11:0416cf017b7a 169 if( calline == 1) {
wbeaumont 11:0416cf017b7a 170 hwl.cal13[0]->write(CAL_ACTIVE); //index can be hard coded as it are the same lines)
wbeaumont 11:0416cf017b7a 171 }
wbeaumont 11:0416cf017b7a 172 if( calline == 2) {
wbeaumont 11:0416cf017b7a 173 hwl.cal24[0]->write(CAL_ACTIVE);
wbeaumont 11:0416cf017b7a 174 }
wbeaumont 11:0416cf017b7a 175 // else we don't do nothing
wbeaumont 11:0416cf017b7a 176 wait_us(10);
wbeaumont 11:0416cf017b7a 177 hwl.cal13[0]->write(CAL_DEACTIVE);
wbeaumont 11:0416cf017b7a 178 hwl.cal24[0]->write(CAL_DEACTIVE);
wbeaumont 11:0416cf017b7a 179
wbeaumont 11:0416cf017b7a 180 }
wbeaumont 3:39671ee1347d 181
wbeaumont 3:39671ee1347d 182
wbeaumont 3:39671ee1347d 183 char* hwfunct_lib_version(){
wbeaumont 8:fe1477cd1c14 184 sprintf(libversion,"hw lib versions src : %s header: %s pindef %s,date:%s %s \n\r",
wbeaumont 8:fe1477cd1c14 185 HW_LIB_SRC_VERSION,HW_LIB_HDR_VERSION , PINDEF_VER, __DATE__,__TIME__);
wbeaumont 3:39671ee1347d 186 return libversion;
wbeaumont 3:39671ee1347d 187
wbeaumont 6:24e981a63851 188 }
wbeaumont 6:24e981a63851 189
wbeaumont 8:fe1477cd1c14 190 int get_serialnr(HWlines *hwlines ){
wbeaumont 8:fe1477cd1c14 191 int snr=0;
wbeaumont 8:fe1477cd1c14 192 for( int bitnr=4 ; bitnr >= 0 ;bitnr--){
wbeaumont 8:fe1477cd1c14 193 snr=snr<<1;
wbeaumont 8:fe1477cd1c14 194 snr|=hwlines->snr[bitnr]->read();
wbeaumont 8:fe1477cd1c14 195 }
wbeaumont 8:fe1477cd1c14 196 return snr;
wbeaumont 8:fe1477cd1c14 197 }
wbeaumont 13:3d82f8e27414 198