123

Dependencies:   mbed

Fork of LG by igor Apu

Committer:
Diletant
Date:
Tue May 03 05:12:26 2016 +0000
Revision:
149:abbf7663d27d
Child:
156:e68ee0bcdcda
Device & ... update. Not final!!!

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Diletant 149:abbf7663d27d 1 #include "Device.h"
Diletant 149:abbf7663d27d 2 extern Device device;
Diletant 149:abbf7663d27d 3
Diletant 149:abbf7663d27d 4 void InitSSPWithDefaults(void){
Diletant 149:abbf7663d27d 5 }
Diletant 149:abbf7663d27d 6
Diletant 149:abbf7663d27d 7 void InitSSP(void){
Diletant 149:abbf7663d27d 8 }
Diletant 149:abbf7663d27d 9
Diletant 149:abbf7663d27d 10 void DeviceSSPReceive(void){
Diletant 149:abbf7663d27d 11 //Prepare ADCs for sampling
Diletant 149:abbf7663d27d 12 LPC_GPIO0->FIOCLR = 1<<16; //reset SSEL signal for ADCs
Diletant 149:abbf7663d27d 13 //Start ADCs sampling
Diletant 149:abbf7663d27d 14 LPC_GPIO0->FIOSET = 1<<16; //set SSEL signal for ADCs
Diletant 149:abbf7663d27d 15 //Get samples
Diletant 149:abbf7663d27d 16 uint32_t value;
Diletant 149:abbf7663d27d 17 device.SSP.accumulator[4] += LPC_SSP0->DR;
Diletant 149:abbf7663d27d 18 device.SSP.accumulator[3] += LPC_SSP0->DR;
Diletant 149:abbf7663d27d 19 device.SSP.accumulator[2] += LPC_SSP0->DR;
Diletant 149:abbf7663d27d 20 device.SSP.accumulator[1] += LPC_SSP0->DR;
Diletant 149:abbf7663d27d 21 device.SSP.accumulator[0] += LPC_SSP0->DR;
Diletant 149:abbf7663d27d 22 while (LPC_SSP0->SR & 0x00000004) value = LPC_SSP0->DR;
Diletant 149:abbf7663d27d 23 //Average samples for dither period
Diletant 149:abbf7663d27d 24 if (device.dither.state.inPeriodCounter == 0) {
Diletant 149:abbf7663d27d 25 for (uint8_t i = 0; i < 5; i++){
Diletant 149:abbf7663d27d 26 device.SSP.in[i] = device.SSP.accumulator[i] >> 5;
Diletant 149:abbf7663d27d 27 device.SSP.accumulator[i] = 0;
Diletant 149:abbf7663d27d 28 device.SSP.dataReady = 1;
Diletant 149:abbf7663d27d 29 }
Diletant 149:abbf7663d27d 30 }
Diletant 149:abbf7663d27d 31 }
Diletant 149:abbf7663d27d 32
Diletant 149:abbf7663d27d 33 void DeviceSSPTransmit(uint8_t index){
Diletant 149:abbf7663d27d 34 LPC_GPIO0->FIOSET = 1<<23; //set SSEL signal for DACs
Diletant 149:abbf7663d27d 35 LPC_GPIO0->FIOCLR = 1<<23; //reset SSEL signal for DACs
Diletant 149:abbf7663d27d 36
Diletant 149:abbf7663d27d 37 LPC_SSP0->DR=0x5555;
Diletant 149:abbf7663d27d 38 LPC_SSP0->DR=0x5555;
Diletant 149:abbf7663d27d 39 LPC_SSP0->DR=0x5555;
Diletant 149:abbf7663d27d 40
Diletant 149:abbf7663d27d 41 if (index){
Diletant 149:abbf7663d27d 42 LPC_SSP0->DR = 0x00000030; //Write DAC0
Diletant 149:abbf7663d27d 43 LPC_SSP0->DR = device.SSP.out[0];
Diletant 149:abbf7663d27d 44 } else {
Diletant 149:abbf7663d27d 45 LPC_SSP0->DR = 0x00000031; //Write DAC1
Diletant 149:abbf7663d27d 46 LPC_SSP0->DR = device.SSP.out[1];
Diletant 149:abbf7663d27d 47 /*
Diletant 149:abbf7663d27d 48 //Move to DevicePLCS from here as not SSP specific
Diletant 149:abbf7663d27d 49 uint32_t value;
Diletant 149:abbf7663d27d 50 switch(device.plcs.state.modulation) {
Diletant 149:abbf7663d27d 51 case 1://малое воздействие
Diletant 149:abbf7663d27d 52 value = device.SSP.DAC[1] + Gyro.StrayPLC_Pls;
Diletant 149:abbf7663d27d 53 break;
Diletant 149:abbf7663d27d 54
Diletant 149:abbf7663d27d 55 case 3://малое воздействие
Diletant 149:abbf7663d27d 56 value = device.SSP.DAC[1] + Gyro.StrayPLC_Mns;
Diletant 149:abbf7663d27d 57 break;
Diletant 149:abbf7663d27d 58
Diletant 149:abbf7663d27d 59 case 2://большое воздействие
Diletant 149:abbf7663d27d 60 value = device.SSP.DAC[1] + Gyro.StrayPLC_2Mode;
Diletant 149:abbf7663d27d 61 break;
Diletant 149:abbf7663d27d 62
Diletant 149:abbf7663d27d 63 default://режим без воздействия
Diletant 149:abbf7663d27d 64 value = device.SSP.DAC[1];
Diletant 149:abbf7663d27d 65 break;
Diletant 149:abbf7663d27d 66 }
Diletant 149:abbf7663d27d 67 LPC_SSP0->DR = device.SSP.DAC[1];
Diletant 149:abbf7663d27d 68 */
Diletant 149:abbf7663d27d 69 }
Diletant 149:abbf7663d27d 70 }