123

Dependencies:   mbed

Fork of LG by igor Apu

DeviceSSP.c

Committer:
Diletant
Date:
2016-05-03
Revision:
149:abbf7663d27d
Child:
156:e68ee0bcdcda

File content as of revision 149:abbf7663d27d:

#include "Device.h"
extern Device device;

void InitSSPWithDefaults(void){
}

void InitSSP(void){
}

void DeviceSSPReceive(void){
  //Prepare ADCs for sampling
  LPC_GPIO0->FIOCLR = 1<<16; //reset SSEL signal for ADCs
  //Start ADCs sampling
  LPC_GPIO0->FIOSET = 1<<16; //set SSEL signal for ADCs
  //Get samples
  uint32_t value;
  device.SSP.accumulator[4] += LPC_SSP0->DR;
  device.SSP.accumulator[3] += LPC_SSP0->DR;
  device.SSP.accumulator[2] += LPC_SSP0->DR;
  device.SSP.accumulator[1] += LPC_SSP0->DR;
  device.SSP.accumulator[0] += LPC_SSP0->DR;
  while (LPC_SSP0->SR & 0x00000004) value = LPC_SSP0->DR;
  //Average samples for dither period
  if (device.dither.state.inPeriodCounter == 0) {
    for (uint8_t i = 0; i < 5; i++){
      device.SSP.in[i] = device.SSP.accumulator[i] >> 5;
      device.SSP.accumulator[i] = 0;  
      device.SSP.dataReady = 1;
    }
  }
}

void DeviceSSPTransmit(uint8_t index){
  LPC_GPIO0->FIOSET = 1<<23; //set SSEL signal for DACs
  LPC_GPIO0->FIOCLR = 1<<23; //reset SSEL signal for DACs
  
  LPC_SSP0->DR=0x5555;
  LPC_SSP0->DR=0x5555;
  LPC_SSP0->DR=0x5555;

  if (index){
    LPC_SSP0->DR = 0x00000030; //Write DAC0
    LPC_SSP0->DR = device.SSP.out[0];
  } else {
    LPC_SSP0->DR = 0x00000031; //Write DAC1
    LPC_SSP0->DR = device.SSP.out[1];
    /*
    //Move to DevicePLCS from here as not SSP specific
    uint32_t value;
    switch(device.plcs.state.modulation) {
        case 1://малое воздействие
          value = device.SSP.DAC[1] + Gyro.StrayPLC_Pls;
        break;
        
        case 3://малое воздействие
          value = device.SSP.DAC[1] + Gyro.StrayPLC_Mns;
        break;
        
        case 2://большое воздействие
          value = device.SSP.DAC[1] + Gyro.StrayPLC_2Mode;
        break;
        
        default://режим без воздействия
          value = device.SSP.DAC[1];
        break;
    }
    LPC_SSP0->DR = device.SSP.DAC[1];
    */
  }
}