Sold slow control/

Dependents:   sscm

Fork of S_SCTRL_SMlib by wimbeaumont Project

Committer:
NickRyder
Date:
Tue Oct 07 21:30:56 2014 +0000
Revision:
11:05bc1c823bc4
Parent:
10:1cae1504a800
Tidying up.

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