// Description: User settings, global includes, global declarations
#pragma once
#include <F28x_Project.h>
// This sets the BUILDLEVEL to one of the available choices.
const unsigned BUILDLEVEL=1;
// 1 = Module check out (do not connect the motors) LEVEL1
// 2 = Verify ADC, park/clarke, calibrate the offset and speed measurement
// 3 = Verify closed current(torque) loop and its PIs
// 4 = Verify speed loop and speed PID
#define bit(x) (1UL<<(x))
typedef unsigned char uint8_t; // fehlt irgendwie
#define elemof(x) (sizeof(x)/sizeof(*(x)))
// This sets the Current sense option
// Can be measured from multiple sources, but one is taken for control.
const enum {
SHUNT_CURRENT_SENSE,LEM_CURRENT_SENSE,SD_CURRENT_SENSE
}CURRENT_TAKE = LEM_CURRENT_SENSE;
// All sources are used for tripping!!
const int SENSES = bit(LEM_CURRENT_SENSE)|bit(SD_CURRENT_SENSE);
// Position Encoder options
// Only one is measured and used. SinCos is not yet implemented.
const enum {
QEP_ENCODER,SINCOS_ENCODER
}POSITION_ENCODER = QEP_ENCODER;
const int ENCODERS = bit(QEP_ENCODER);
// Define CPU and system frequency (Hz)
const float F_CPU=200E6; // 200 MHz
const float F_LSP=F_CPU; // Low-Speed-Takt (für SPI)
// Define some frequencies (Hz)
const float F_PWM=10E3; // 10 kHz PWM-Grundfrequenz (Pfeifen)
const float F_ISR=10E3; // 10 kHz
void configPwm(volatile EPWM_REGS&,Uint16 period,Uint16 slave_phase);
// Konfiguriere I/O-Pin: Mit Sonderfunktion (allgemein), als Ausgang oder als Eingang
// Pin-Nr. = 0..31 für Port A, 32..63 für Port B usw.
void configGpio(uint8_t pin, unsigned modebits);
inline void configGpio(uint8_t pin, uint8_t mux/*4bit*/,
uint8_t qsel/*2bit*/,
bool pullup_off=true,
bool inv=false,
bool dir_out=false,
bool open_drain=false,
uint8_t csel=0/*4bit*/,
bool lock=false) {
configGpio(pin, mux|csel<<4|qsel<<8|dir_out<<10|pullup_off<<11|inv<<12|open_drain<<13|lock<<14);
}
inline void configGpioOut(uint8_t pin, bool open_drain=false,
uint8_t csel=0/*4bit*/,
bool pullup_off=true,
bool lock=false) {
configGpio(pin, csel<<4|true<<10|pullup_off<<11|open_drain<<13|lock<<14);
}
inline void configGpioIn(uint8_t pin, bool inv=false,
uint8_t csel=0/*4bit*/,
bool pullup_off=false,
bool lock=false) {
configGpio(pin, csel<<4|pullup_off<<11|inv<<12|lock<<14);
}
// adc.cpp
struct Currentsense{
float As,Bs,Cs; // Phase A, B, C
void readSDFM(); // sigmadelta.cpp
void readShunt();
void readLEM();
static void integrateSDFMoffset(float K2); // sigmadelta.cpp
static void resetSDFMoffset(); // sigmadelta.cpp
static void integrateADCoffset(float K2);
static void resetADCoffset();
static void setADCoffsetregs();
};
struct Adc{
static void GetSinCos(float sincos[2]);
static void InitAll();
static float myGetTemperatureC(int16_t);
};
struct PosEnc{ // posEncoderSuite.cpp
static float ElecTheta,MechTheta; // ref: MotorControl.cpp
static Uint16 lsw; // ref: MotorControl.cpp
static void Suite(); // ref: MotorControl.cpp
static void InitAll(); // ref: main.cpp
};
struct Amc1210 { // amc1210spi.cpp
static void InitAll();
// Der Standardtransfer ist 1 Adressbyte, gefolgt von 1 oder mehr 16-Bit-Wörtern.
// Das Adressbyte besteht aus 1 R/W-Bit (1 = Lesen) und 7 Adressbits.
// rx und tx dürfen gleich sein, dürfen NULL sein.
// rx und tx sollten nicht gleichzeitig NULL sein, wäre wohl Quatsch.
// n muss zwischen 1 und 16 liegen.
static void send(uint8_t adr, const void*tx, unsigned n=1); // Senden (max. 16)
static void recv(uint8_t adr, void*rx, unsigned n=1); // Senden (Adresse und Dummies) (max. 16)
// „Bottom Half“ = Abholen / Leeren der FIFO und ChipSelect = High
static void wait(); // Warten und Abholen / leeren (max. 16)
static void send(uint8_t adr, uint16_t msg); // Einzel-Transfer
static uint16_t recv(uint8_t adr); // Einzel-Transfer
typedef struct{
int16_t value;
uint16_t timestamp;
}data16_t[4];
typedef struct{
int32_t value;
uint16_t timestamp;
}data32_t[4];
};
// comport.cpp
// Vorzugsweise ist wchar_t für Text zu verwenden, aber ohne Surrogates
// d.h. nur Unicode-Codepoints 0..FFFF.
// Damit der Compiler wchar_t-String-Konstanten wie L"xyz" korrekt übersetzt,
// muss jeder Quelltext mit Byte Order Mark (BOM) erstellt sein.
struct Comport {
volatile SCI_REGS®s;
const uint8_t*sendptr; // für ISR
uint8_t*recvptr; // für ISR
volatile size_t sendlen,recvlen; // für ISR
uint8_t sendbin,recvbin; // für ISR, wenn Bit 0 = 1 dann ist Bit 1 = Byteadresse
Comport(volatile SCI_REGS&r):regs(r) {} // Konstruktor
// <constexpr> kennt der Compiler nicht!!
// constexpr uint16_t BRR(float baud) {return F_CPU/8/baud-0.5;}
#define BRR(x) uint16_t(F_CPU/8/(float)(x)-0.5)
void init(uint16_t brr);
// Im Normalfall wird "Text" transferiert, so als ob typeof(tx) == char* ist.
// Da im TMS320 ein char = 16 Bit ist, muss binary auf true gesetzt werden,
// um für Speicherabzüge und wchar_t* 2 Bytes pro Adresse zu senden bzw. zu empfangen.
// Im Binärmodus ist n = Anzahl der BYTES, Bit 1 von <binary> gibt den Startwert (Lo oder Hi) vor.
// So lassen sich Speicherbereiche bytegenau (Anfang UND Ende) transferieren
void send(const uint8_t*tx, size_t n,uint8_t binary=false);
void recv(uint8_t*rx, size_t n,uint8_t binary=false);
enum{
RxComplete=1, // letztes Bit eingeschoben
TxComplete=2, // letztes Bit ausgeschoben
TxDataOut=4, // Daten(schwanz) komplett in Sende-FIFO
RxStop=8, // Empfang abbrechen oder neu vorbereiten
TxStop=16, // Senden abbrechen
};
void wait(uint8_t mask); // Warten bis fertig (kein Handshake, dadurch endlich)
void RxIsr();
void TxIsr();
// synchron ohne Interrupt-Overhead, für Text und 12-MBaud-UART
private:
void send(char) const;
void send(const char*,size_t) const;
// void send(const char*) const;
public:
void send(wchar_t) const; // in UTF-8-Kodierung
void send(const wchar_t*) const;
void send(const wchar_t*,size_t) const;
// void vprintf(const char*,va_list) const;
void vprintf(const wchar_t*,va_list) const;
// void printf(const char*,...) const;
void printf(const wchar_t*,...) const;
private:
int recv() const; // Liest 1 Byte, -1 wenn keins in der RxFifo
// int recv(char*) const; // Liest 0..16 Bytes, liefert gelesene Zeichen
char getchr() const; // wartet (unendlich) bis 1 Byte angekommen ist, für UTF-8
wchar_t getwchr() const; // wartet (unendlich) bis ganze UTF-8-Sequenz angekommen ist
public:
int recv(wchar_t*) const; // Liest 0..16 Zeichen, mit UTF-8-Dekodierung
static void InitAll();
};
extern Comport com0; // main.cpp, ref: terminal.cpp
// Other source file entries
struct SysInit { // sysinit.cpp
static void InitAll(); // ref: main.cpp
};
struct Terminal { // terminal.cpp
static void Update(); // ref: main.cpp
};
struct Trip { // trip.cpp
static void InitAll(); // ref: main.cpp
static void Check(); // ref: main.cpp
};
void initMotorControl(); // MotorControl.cpp, ref: main.cpp
extern bool RunMotor; // MotorControl.cpp, ref: main.cpp
void initSigmaDelta(); // sigmadelta.cpp, ref: main.cpp
#ifdef _FLASH
# define RAMFUNC __attribute__((ramfunc))
#else
# define RAMFUNC // don't place into “.TI.ramfuncs” section
#endif
#ifdef _DEBUG
# define MONITOR // visible in CCS (Eclipse) Expressions window
#else
# define MONITOR static // suppress visibility
#endif
Detected encoding: ASCII (7 bit) | 8
|