123

Dependencies:   mbed

Fork of LG by igor Apu

Device.h

Committer:
Diletant
Date:
2016-05-15
Revision:
161:efd949e8d536
Parent:
156:e68ee0bcdcda
Child:
166:c3c0b8a90d81

File content as of revision 161:efd949e8d536:

#ifndef __DEVICE_H__
#define __DEVICE_H__

#define DEV_BOARD_HAOYU
#ifdef DEV_BOARD_HAOYU
#warning "Program config: development board!!!"
#endif

#include "LPC17xx.h"
#include "system_LPC17xx.h"
#include "DeviceController.h"
#include "DeviceDAC.h"
#include "DeviceUserProtocol.h"
#include "DeviceCounters.h"
#include "DeviceDither.h"
#include "DeviceLightUp.h"
#include "DeviceISACS.h"
#include "DevicePLCS.h"

typedef enum _DeviceLatchMode {
  DeviceLatch10kHz,   //internal latch  by pulses 10 kHz (power on default mode)
  DeviceLatchMeander, //internal latch by signed meander pulses (not used?)
  DeviceLatchRS422,   //external latch by RS422 request
  DeviceLatchPin      //external latch by hardware pin request
} DeviceLatchMode;

typedef enum _DeviceLatchFormat {
  DeviceLatchFormatDeltaPS,   //latch data in DELTA_PS response format
  DeviceLatchFormatDeltaBINS, //latch data in DELTA_BINS response format
  DeviceLatchFormatDeltaSF    //latch data in DELTA_SF response format
} DeviceLatchFormat;

typedef struct _DeviceLatchState {
  uint8_t ready;
  DeviceLatchMode mode;       //latch source
  DeviceLatchFormat format;   //data to latch
  uint8_t reset;              //set to reset counters on each latch (default), clear to keep (DELTA_SF)
} DeviceLatchState;

typedef enum _DeviceCountingSource {
  DeviceCountingSourceReference, //Accumulate pulses using reference +/- counters as source
  DeviceCountingSourceDither,    //Accumulate pulses using dither counters as source
} DeviceCountingSource;

//Device service communication typedefs
typedef struct _Service {
  char buffer[512];
  uint16_t position; //Transmission position
} Service;

//Device measurement cycle typedefs
typedef struct _DeviceMeasurementCycle {
  uint32_t length;  //Measurement cycle length
  uint32_t counter; //Measurement cycle counter
} DeviceMeasurementCycle;

//Device regular cycle typedefs
typedef struct _DeviceRegularCycle {
  volatile uint32_t event1Hz;
  volatile uint32_t event500Hz;
  volatile uint32_t event1K;
  volatile uint32_t event10K;
  volatile uint32_t event100K;

  volatile uint32_t time100K;
  volatile uint32_t time10K;
  volatile uint32_t time1K;
  volatile uint32_t time500Hz;
  volatile uint32_t time1Hz;
} DeviceRegularCycle;

//Device sensor typedefs
typedef struct _DeviceSensorSettings {
  //Device ID
  uint16_t id;
  //Block ID
  uint16_t block;
} DeviceSensorSettings;

typedef struct _DeviceSensorState {
} DeviceSensorState;

typedef struct _DeviceSensor {
  DeviceSensorSettings settings;
  DeviceSensorState state;
} DeviceSensor;

//Device typedefs
typedef struct _Device {
  //Measurement cycle
  DeviceMeasurementCycle measurement;
  //Control cycle
  DeviceRegularCycle regular;
  //Counting
  DeviceLatchState latch;
  DeviceCounters counters;
  //Controller
  DeviceController controller;
  //Protocols
  Service service; //Service communication protocol - asynchronous serial port 0
  DeviceUserProtocol user;       //Host communication protocol - asynchronous serial port 1
  //Units
  DeviceSensor sensor;
  DeviceLightUp lightUp;
  DeviceDither dither;
  DeviceDAC dac;   //2-channel DAC of isas & plcs
  DeviceISACS isacs; //Information signal amplitude stabilizer
  DevicePathLengthControlSystem plcs; //Path length control system
} Device;

typedef struct _HashParam {
  uint32_t hash;
  void * ref;
  uint32_t size;
} HashParam;

#define HASH_PARAM_COUNT 153

typedef struct _HashFunc {
  uint32_t hash;
  void * ref;
  uint32_t resultSize;
  uint32_t paramCount;
} HashFunc;

#define HASH_FUNC_COUNT 3

void InitDevice(void);
void DeviceStart(void);

void DeviceInitAllWithDefaults(void);
void DeviceInitAll(void);
void InitHashParamTable(void);

void DeviceRegularEvent1Hz(void);
void DeviceRegularEvent500Hz(void);
void DeviceRegularEvent1KHz(void);
void DeviceRegularEvent10KHz(void);
void DeviceRegularEvent100KHz(void);

void DeviceMeasurementInterruptHandler(void);
void DeviceRegularInterruptHandler(void);
#endif  /* __DEVICE_H__ */