hw functions for the SOLID slow control

Dependents:   S_SCTRL_e_test SPItest sscm

Committer:
wbeaumont
Date:
Tue Sep 16 19:36:21 2014 +0000
Revision:
8:fe1477cd1c14
Parent:
7:cb139102ec05
Child:
9:20f21cb7792e
tested with all pins and functions, no flash test

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 8:fe1477cd1c14 5
wbeaumont 8:fe1477cd1c14 6
wbeaumont 8:fe1477cd1c14 7 */
wbeaumont 8:fe1477cd1c14 8
wbeaumont 0:8d755a0f3ab3 9 #include "mbed.h"
wbeaumont 0:8d755a0f3ab3 10 #include "S_SCTRL_SM1_PinDef.h"
wbeaumont 1:af78e316f889 11 #include "S_SCTRL_SM1_hwfunct.h"
wbeaumont 1:af78e316f889 12
wbeaumont 0:8d755a0f3ab3 13
wbeaumont 8:fe1477cd1c14 14 #define HW_LIB_SRC_VERSION "1.21"
wbeaumont 3:39671ee1347d 15
wbeaumont 3:39671ee1347d 16 #define MAXLIBVERCHAR 100 // max char for lib version
wbeaumont 0:8d755a0f3ab3 17
wbeaumont 1:af78e316f889 18 void assignports(HWlines *hwlines ){
wbeaumont 0:8d755a0f3ab3 19
wbeaumont 0:8d755a0f3ab3 20 /// devices
wbeaumont 0:8d755a0f3ab3 21 // SPI BI pins
wbeaumont 1:af78e316f889 22 hwlines->msio[0] = new DigitalInOut(ADC_STIO);
wbeaumont 1:af78e316f889 23 hwlines->sclk[0] = new DigitalOut(SCLK);
wbeaumont 1:af78e316f889 24 hwlines->direction[0] = new DigitalOut(DIRECTION);
wbeaumont 1:af78e316f889 25 hwlines->stio_mo[0] = new DigitalOut(STIO_MO);
wbeaumont 4:a83242fe9d37 26 hwlines->csb1[0] = new DigitalOut(ADC1_CSN);
wbeaumont 4:a83242fe9d37 27 hwlines->csb2[0] = new DigitalOut(ADC2_CSN);
wbeaumont 0:8d755a0f3ab3 28
wbeaumont 0:8d755a0f3ab3 29
wbeaumont 0:8d755a0f3ab3 30
wbeaumont 0:8d755a0f3ab3 31 // SPI pins
wbeaumont 1:af78e316f889 32 hwlines->mosi[0] = new DigitalOut(MOSI);
wbeaumont 1:af78e316f889 33 hwlines->miso[0] = new DigitalIn(MISO);
wbeaumont 0:8d755a0f3ab3 34
wbeaumont 1:af78e316f889 35 hwlines->t_cs[0] = new DigitalOut(TEMP_CSN);
wbeaumont 1:af78e316f889 36 hwlines->tc_cs1[0] = new DigitalOut(TEMP_CABLE_CSN1);
wbeaumont 1:af78e316f889 37 hwlines->tc_cs2[0] = new DigitalOut(TEMP_CABLE_CSN2);
wbeaumont 1:af78e316f889 38 hwlines->dac_cs[0] = new DigitalOut(DAC_DCEN);
wbeaumont 1:af78e316f889 39 hwlines->dac_rst[0] = new DigitalOut(DAC_RSTN);
wbeaumont 0:8d755a0f3ab3 40
wbeaumont 0:8d755a0f3ab3 41
wbeaumont 0:8d755a0f3ab3 42
wbeaumont 0:8d755a0f3ab3 43
wbeaumont 0:8d755a0f3ab3 44 // devices
wbeaumont 0:8d755a0f3ab3 45 // SPI BI pins
wbeaumont 1:af78e316f889 46 hwlines->msio[1] = new DigitalInOut(ADC_2_STIO);
wbeaumont 1:af78e316f889 47 hwlines->sclk[1] = new DigitalOut(SCLK_2);
wbeaumont 1:af78e316f889 48 hwlines->direction[1] = new DigitalOut(DIRECTION2);
wbeaumont 1:af78e316f889 49 hwlines->stio_mo[1] = new DigitalOut(STIO2_MO);
wbeaumont 4:a83242fe9d37 50 hwlines->csb1[1] = new DigitalOut(ADC1_2_CSN);
wbeaumont 4:a83242fe9d37 51 hwlines->csb2[1] = new DigitalOut(ADC2_2_CSN);
wbeaumont 0:8d755a0f3ab3 52
wbeaumont 0:8d755a0f3ab3 53 // SPI pins
wbeaumont 1:af78e316f889 54 hwlines->mosi[1] = new DigitalOut(MOSI_2);
wbeaumont 1:af78e316f889 55 hwlines->miso[1] = new DigitalIn(MISO_2);
wbeaumont 0:8d755a0f3ab3 56
wbeaumont 1:af78e316f889 57 hwlines->t_cs[1] = new DigitalOut(TEMP_2_CSN);
wbeaumont 1:af78e316f889 58 hwlines->tc_cs1[1] = new DigitalOut(TEMP_2_CABLE_CSN1);
wbeaumont 1:af78e316f889 59 hwlines->tc_cs2[1] = new DigitalOut(TEMP_2_CABLE_CSN2);
wbeaumont 1:af78e316f889 60 hwlines->dac_cs[1] = new DigitalOut(DAC_2_DCEN);
wbeaumont 1:af78e316f889 61 hwlines->dac_rst[1] = new DigitalOut(DAC_2_RSTN);
wbeaumont 0:8d755a0f3ab3 62
wbeaumont 0:8d755a0f3ab3 63
wbeaumont 0:8d755a0f3ab3 64 //cal
wbeaumont 1:af78e316f889 65 hwlines->cal13[0] = new DigitalOut(CAL_TRIG_1AND3);
wbeaumont 1:af78e316f889 66 hwlines->cal24[0] = new DigitalOut(CAL_TRIG_2AND4);
wbeaumont 1:af78e316f889 67 hwlines->calint[0] = new DigitalOut(SEL_CAL_INT);
wbeaumont 1:af78e316f889 68 hwlines->cal13[1] = new DigitalOut(CAL_TRIG_1AND3);
wbeaumont 1:af78e316f889 69 hwlines->cal24[1] = new DigitalOut(CAL_TRIG_2AND4);
wbeaumont 1:af78e316f889 70 hwlines->calint[1] = new DigitalOut(SEL_2_CAL_INT);
wbeaumont 0:8d755a0f3ab3 71
wbeaumont 1:af78e316f889 72 hwlines->calext = new DigitalOut(SEL_CAL_EXT);
wbeaumont 1:af78e316f889 73 hwlines->calgenext = new DigitalOut(GEN_EXT_CAL);
wbeaumont 0:8d755a0f3ab3 74
wbeaumont 1:af78e316f889 75 hwlines->ledred = new DigitalOut(LEDRED);
wbeaumont 1:af78e316f889 76 hwlines->ledgreen = new DigitalOut(LEDGREEN);
wbeaumont 0:8d755a0f3ab3 77
wbeaumont 1:af78e316f889 78 hwlines->ain[0] = new AnalogIn(ADC1);
wbeaumont 1:af78e316f889 79 hwlines->ain[1] = new AnalogIn(ADC2);
wbeaumont 0:8d755a0f3ab3 80
wbeaumont 8:fe1477cd1c14 81 hwlines->snr[0] = new DigitalIn(AD0);
wbeaumont 8:fe1477cd1c14 82 hwlines->snr[1] = new DigitalIn(AD1);
wbeaumont 8:fe1477cd1c14 83 hwlines->snr[2] = new DigitalIn(AD2);
wbeaumont 8:fe1477cd1c14 84 hwlines->snr[3] = new DigitalIn(AD3);
wbeaumont 8:fe1477cd1c14 85 hwlines->snr[4] = new DigitalIn(AD4);
wbeaumont 0:8d755a0f3ab3 86
wbeaumont 0:8d755a0f3ab3 87 }
wbeaumont 0:8d755a0f3ab3 88
wbeaumont 0:8d755a0f3ab3 89
wbeaumont 0:8d755a0f3ab3 90
wbeaumont 0:8d755a0f3ab3 91 // select intern or extern cal 0 = intern, 1 is extern
wbeaumont 1:af78e316f889 92 void setcalsource( int external, HWlines hwl) {
wbeaumont 8:fe1477cd1c14 93 *(hwl.calext)=0; *(hwl.calint[0])=0; *(hwl.calint[1])=0; //disable all
wbeaumont 0:8d755a0f3ab3 94 if ( external==1 ) {*(hwl.calext)=1; }
wbeaumont 8:fe1477cd1c14 95 else {*(hwl.calint[0])=1; *(hwl.calint[1])=1; }
wbeaumont 0:8d755a0f3ab3 96
wbeaumont 0:8d755a0f3ab3 97
wbeaumont 0:8d755a0f3ab3 98 }
wbeaumont 0:8d755a0f3ab3 99
wbeaumont 5:b527df9432c3 100 // set the default , save values
wbeaumont 0:8d755a0f3ab3 101 void setdefault(HWlines hwl ) {
wbeaumont 0:8d755a0f3ab3 102 for ( int i=0;i<2;i++){
wbeaumont 0:8d755a0f3ab3 103 hwl.msio[i]->input();
wbeaumont 8:fe1477cd1c14 104 *(hwl.direction[i])=RDIR_IN;
wbeaumont 8:fe1477cd1c14 105 *(hwl.stio_mo[i])=LDIR_IN;
wbeaumont 0:8d755a0f3ab3 106 }
wbeaumont 1:af78e316f889 107 setcalsource(0,hwl); //intern
wbeaumont 0:8d755a0f3ab3 108 }
wbeaumont 0:8d755a0f3ab3 109
wbeaumont 6:24e981a63851 110
wbeaumont 5:b527df9432c3 111 void set_bi_spi_mo(int masterout, DigitalInOut* msio, DigitalOut* ldir, DigitalOut* rdir){
wbeaumont 5:b527df9432c3 112 // default directions
wbeaumont 5:b527df9432c3 113 if( masterout == 0 ) { // master in
wbeaumont 5:b527df9432c3 114 msio->input();
wbeaumont 5:b527df9432c3 115 rdir->write(RDIR_IN);
wbeaumont 5:b527df9432c3 116 ldir->write(LDIR_IN);
wbeaumont 5:b527df9432c3 117
wbeaumont 5:b527df9432c3 118 }
wbeaumont 5:b527df9432c3 119 else { //master out
wbeaumont 5:b527df9432c3 120
wbeaumont 5:b527df9432c3 121 ldir->write(LDIR_OUT);
wbeaumont 5:b527df9432c3 122 msio->output();
wbeaumont 5:b527df9432c3 123 rdir->write(RDIR_OUT);
wbeaumont 5:b527df9432c3 124 }
wbeaumont 5:b527df9432c3 125 }
wbeaumont 5:b527df9432c3 126
wbeaumont 5:b527df9432c3 127
wbeaumont 6:24e981a63851 128
wbeaumont 3:39671ee1347d 129 char libversion[MAXLIBVERCHAR]={'e','m','p','t','y','\0'};
wbeaumont 3:39671ee1347d 130
wbeaumont 3:39671ee1347d 131
wbeaumont 3:39671ee1347d 132 char* hwfunct_lib_version(){
wbeaumont 8:fe1477cd1c14 133 sprintf(libversion,"hw lib versions src : %s header: %s pindef %s,date:%s %s \n\r",
wbeaumont 8:fe1477cd1c14 134 HW_LIB_SRC_VERSION,HW_LIB_HDR_VERSION , PINDEF_VER, __DATE__,__TIME__);
wbeaumont 3:39671ee1347d 135 return libversion;
wbeaumont 3:39671ee1347d 136
wbeaumont 6:24e981a63851 137 }
wbeaumont 6:24e981a63851 138
wbeaumont 8:fe1477cd1c14 139 int get_serialnr(HWlines *hwlines ){
wbeaumont 8:fe1477cd1c14 140 int snr=0;
wbeaumont 8:fe1477cd1c14 141 for( int bitnr=4 ; bitnr >= 0 ;bitnr--){
wbeaumont 8:fe1477cd1c14 142 snr=snr<<1;
wbeaumont 8:fe1477cd1c14 143 snr|=hwlines->snr[bitnr]->read();
wbeaumont 8:fe1477cd1c14 144 }
wbeaumont 8:fe1477cd1c14 145 return snr;
wbeaumont 8:fe1477cd1c14 146 }