repo_name
stringlengths 6
97
| path
stringlengths 3
341
| text
stringlengths 8
1.02M
|
---|---|---|
patwonder/pbrt-v2-skin | src/shapes/trianglemesh.h | <reponame>patwonder/pbrt-v2-skin
/*
pbrt source code Copyright(c) 1998-2012 <NAME> and <NAME>.
This file is part of pbrt.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if defined(_MSC_VER)
#pragma once
#endif
#ifndef PBRT_SHAPES_TRIANGLEMESH_H
#define PBRT_SHAPES_TRIANGLEMESH_H
// shapes/trianglemesh.h*
#include "shape.h"
#include "renderers/surfacepoints.h"
#include <map>
#include <functional>
using std::map;
struct BarycentricCoordinate;
class BumpMapping;
// TriangleMesh Declarations
class TriangleMesh : public ShrinkableShape, public Tessellatable {
public:
// TriangleMesh Public Methods
TriangleMesh(const Transform *o2w, const Transform *w2o, bool ro,
int ntris, int nverts, const int *vptr,
const Point *P, const Normal *N, const Vector *S,
const float *uv, const Reference<Texture<float> > &atex);
~TriangleMesh();
BBox ObjectBound() const;
BBox WorldBound() const;
bool CanIntersect() const { return false; }
void Refine(vector<Reference<Shape> > &refined) const;
Reference<ShrinkableShape> Shrink(float distance) const override;
void TessellateSurfacePoints(float minDist, const BumpMapping& bump, uint32_t materialId,
vector<SurfacePoint>& points, ProgressReporter* pr = NULL, bool incenter = false) const override;
int GetTessellationWork() const override;
template<class MeshReferenceType>
friend class TriangleBase;
template <typename T> friend class VertexTexture;
protected:
// TriangleMesh Protected Data
int ntris, nverts;
int *vertexIndex;
Point *p;
Normal *n;
Vector *s;
float *uvs;
Reference<Texture<float> > alphaTexture;
private:
// TriangleMesh Private Methods
// Just obtain a copy of the base class subobject
TriangleMesh(const TriangleMesh&);
// Fixed-function tessellator similar to DX11's
static void tessellator(float tfe0, float tfe1, float tfe2, float tfc,
const std::function<void (BarycentricCoordinate bv0,
BarycentricCoordinate bv1, BarycentricCoordinate bv2)>& domainShader);
static void matching(BarycentricCoordinate b0Inner, BarycentricCoordinate b1Inner, int segsInner,
BarycentricCoordinate b0Outer, BarycentricCoordinate b1Outer, int segsOuter,
const std::function<void (BarycentricCoordinate bv0, BarycentricCoordinate bv1,
BarycentricCoordinate bv2)>& domainShader);
};
template<class MeshReferenceType>
class TriangleBase : public Shape {
public:
// Triangle Public Methods
TriangleBase(const Transform *o2w, const Transform *w2o, bool ro,
const TriangleMesh *m, int n)
: Shape(o2w, w2o, ro) {
mesh = m;
v = &mesh->vertexIndex[3*n];
PBRT_CREATED_TRIANGLE(this);
}
BBox ObjectBound() const;
BBox WorldBound() const;
bool Intersect(const Ray &ray, float *tHit, float *rayEpsilon,
DifferentialGeometry *dg) const;
bool IntersectP(const Ray &ray) const;
void GetUVs(float uv[3][2]) const {
if (mesh->uvs) {
uv[0][0] = mesh->uvs[2*v[0]];
uv[0][1] = mesh->uvs[2*v[0]+1];
uv[1][0] = mesh->uvs[2*v[1]];
uv[1][1] = mesh->uvs[2*v[1]+1];
uv[2][0] = mesh->uvs[2*v[2]];
uv[2][1] = mesh->uvs[2*v[2]+1];
}
else {
uv[0][0] = 0.; uv[0][1] = 0.;
uv[1][0] = 1.; uv[1][1] = 0.;
uv[2][0] = 1.; uv[2][1] = 1.;
}
}
float Area() const;
virtual void GetShadingGeometry(const Transform &obj2world,
const DifferentialGeometry &dg,
DifferentialGeometry *dgShading) const;
void GetDifferentialGeometries(const BarycentricCoordinate& bc,
DifferentialGeometry* dgGeom, DifferentialGeometry* dgShading) const;
Point Sample(float u1, float u2, Normal *Ns) const;
private:
// Triangle Private Data
MeshReferenceType mesh;
int *v;
};
typedef TriangleBase<Reference<const TriangleMesh> > Triangle;
typedef TriangleBase<const TriangleMesh*> TempTriangle;
#include "trianglemesh.inl"
TriangleMesh *CreateTriangleMeshShape(const Transform *o2w, const Transform *w2o,
bool reverseOrientation, const ParamSet ¶ms,
map<string, Reference<Texture<float> > > *floatTextures = NULL);
#endif // PBRT_SHAPES_TRIANGLEMESH_H
|
patwonder/pbrt-v2-skin | src/multipole/MultipoleProfileCalculator/numutil.h | <reponame>patwonder/pbrt-v2-skin
/*
Copyright(c) 2013-2014 <NAME>.
This file is part of fork of pbrt (pbrt-v2-skin).
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <cassert>
#include "mpc-types.h"
#include "cachedallocator.h"
template <class T>
inline T clamp(T value, T low, T high) {
if (value <= low) return low;
if (value >= high) return high;
return value;
}
static const float PI = 3.141592654f;
static const float INV_FOURPI = 0.25f / PI;
template<class Type>
class MTX_Traits {
public:
static Type zero() {
return Type(0);
}
static Type one() {
return Type(1);
}
};
extern CachedAllocator<size_t, void*> mtxAlloc;
template <class Type, class Type_traits=MTX_Traits<Type> >
class Matrix {
public:
Matrix(uint32 rows, uint32 cols) {
data = (Type*)mtxAlloc.alloc(sizeof(Type) * rows * cols);
nRows = rows; nCols = cols;
}
~Matrix() {
mtxAlloc.free(data);
}
Matrix(const Matrix& other) {
nRows = other.nRows;
nCols = other.nCols;
uint32 nSize = nRows * nCols;
data = (Type*)mtxAlloc.alloc(sizeof(Type) * nSize);
memcpy(data, other.data, sizeof(Type) * nSize);
}
Matrix(Matrix&& other) {
nRows = other.nRows;
nCols = other.nCols;
data = other.data;
other.data = NULL;
}
Matrix& operator=(const Matrix& other) {
if (this == &other) return *this;
nRows = other.nRows;
nCols = other.nCols;
mtxAlloc.free(data);
uint32 nSize = nRows * nCols;
data = (Type*)mtxAlloc.alloc(sizeof(Type) * nSize);
memcpy(data, other.data, sizeof(Type) * nSize);
return *this;
}
Matrix& operator=(Matrix&& other) {
if (this == &other) return *this;
nRows = other.nRows;
nCols = other.nCols;
Type* p = data;
data = other.data;
other.data = p;
return *this;
}
Type* operator[](uint32 row) {
return data + row * nCols;
}
const Type* operator[](uint32 row) const {
return data + row * nCols;
}
Matrix& operator+=(const Matrix& other) {
return doAssignOp(other, [] (Type& th, const Type& oth) {
th += oth;
});
}
const Matrix operator+(const Matrix& other) const {
return Matrix(*this) += other;
}
Matrix& operator-=(const Matrix& other) {
return doAssignOp(other, [] (Type& th, const Type& oth) {
th -= oth;
});
}
const Matrix operator-(const Matrix& other) const {
return Matrix(*this) -= other;
}
// Component-wise multiplication
Matrix& operator*=(const Matrix& other) {
return doAssignOp(other, [] (Type& th, const Type& oth) {
th *= oth;
});
}
const Matrix operator*(const Matrix& other) const {
return Matrix(*this) *= other;
}
Matrix& operator*=(Type mul) {
return doAssignOp([&] (Type& th) {
th *= mul;
});
}
const Matrix operator*(Type mul) const {
return Matrix(*this) *= mul;
}
// Component-wise division
Matrix& operator/=(const Matrix& other) {
return doAssignOp(other, [] (Type& th, const Type& oth) {
th /= oth;
});
}
const Matrix operator/(const Matrix& other) const {
return Matrix(*this) /= other;
}
Matrix& operator/=(Type div) {
return doAssignOp([&] (Type& th) {
th /= div;
});
}
const Matrix operator/(Type div) const {
return Matrix(*this) /= div;
}
Matrix& OneMinusSelf() {
return doAssignOp([&] (Type& th) {
th = Type_traits::one() - th;
});
}
Matrix ChangeSize(uint32 newRows, uint32 newCols, uint32 baseRow, uint32 baseCol, uint32 startRow, uint32 startCol) const {
Matrix ret(newRows, newCols);
uint32 minRows = min(newRows - baseRow, nRows - startRow), minCols = min(newCols - baseCol, nCols - startCol);
ret.Clear();
for (uint32 i = 0; i < minRows; i++) {
for (uint32 j = 0; j < minCols; j++) {
ret[baseRow + i][baseCol + j] = (*this)[startRow + i][startCol + j];
}
}
return ret;
}
Matrix& ChangeSizeFrom(const Matrix& from, uint32 baseRow, uint32 baseCol, uint32 startRow, uint32 startCol) {
Clear();
uint32 minRows = min(from.nRows - startRow, nRows - baseRow), minCols = min(from.nCols - startCol, nCols - baseCol);
for (uint32 i = 0; i < minRows; i++) {
for (uint32 j = 0; j < minCols; j++) {
(*this)[baseRow + i][baseCol + j] = from[startRow + i][startCol + j];
}
}
return *this;
}
Matrix ScaleAndShift(uint32 newRows, uint32 newCols, uint32 shRow, uint32 shCol) const {
Matrix ret(newRows, newCols);
uint32 minRows = min(nRows, newRows), minCols = min(nCols, newCols);
ret.Clear();
for (uint32 i = 0; i < minRows; i++) {
uint32 ii = newRows - shRow + i; if (ii >= newRows) ii -= newRows;
for (uint32 j = 0; j < minCols; j++) {
uint32 jj = newCols - shCol + j; if (jj >= newCols) jj -= newCols;
ret[ii][jj] = (*this)[i][j];
}
}
return ret;
}
Matrix ScaleAndShiftReversed(uint32 newRows, uint32 newCols, uint32 shRow, uint32 shCol) const {
Matrix ret(newRows, newCols);
uint32 minRows = min(nRows, newRows), minCols = min(nCols, newCols);
ret.Clear();
for (uint32 i = 0; i < minRows; i++) {
uint32 ii = nRows - shRow + i; if (ii >= nRows) ii -= nRows;
for (uint32 j = 0; j < minCols; j++) {
uint32 jj = nRows - shCol + j; if (jj >= nCols) jj -= nCols;
ret[i][j] = (*this)[ii][jj];
}
}
return ret;
}
void swapRow(uint32 nRow1, uint32 nRow2, uint32 startCol = 0) {
for (uint32 i = startCol; i < nCols; i++) {
std::swap((*this)[nRow1][i], (*this)[nRow2][i]);
}
}
void swapCol(uint32 nCol1, uint32 nCol2, uint32 startRow = 0) {
for (uint32 i = startRow; i < nRows; i++) {
swap((*this)[i][nCol1], (*this)[i][nCol2]);
}
}
Type Sum() const {
// Using Kahan Summation Algorithm for better accuracy
Type sum = Type_traits::zero();
Type c = Type_traits::zero();
doReadOp([&] (const Type& th) {
Type y = th - c;
Type t = sum + y;
c = (t - sum) - y;
sum = t;
});
return sum;
}
Type* GetData() { return data; }
const Type* GetData() const { return data; }
uint32 GetNumRows() const { return nRows; }
uint32 GetNumCols() const { return nCols; }
void Clear() {
doAssignOp([&] (Type& th) {
th = Type_traits::zero();
});
}
private:
Type* data;
uint32 nRows, nCols;
template <class Op>
void doReadOp(const Op& op) const {
uint32 nSize = nRows * nCols;
const Type* ptr = data;
for (uint32 i = 0; i < nSize; i++) {
op(ptr[i]);
}
}
template <class Op>
Matrix& doAssignOp(const Op& op) {
uint32 nSize = nRows * nCols;
Type* ptr = data;
for (uint32 i = 0; i < nSize; i++) {
op(ptr[i]);
}
return *this;
}
template <class Op>
Matrix& doAssignOp(const Matrix& other, const Op& op) {
assert(nRows == other.nRows && nCols == other.nCols);
uint32 nSize = nRows * nCols;
Type* ptr = data;
Type* ptrOther = other.data;
for (uint32 i = 0; i < nSize; i++) {
op(ptr[i], ptrOther[i]);
}
return *this;
}
};
|
patwonder/pbrt-v2-skin | src/core/geometry.h |
/*
pbrt source code Copyright(c) 1998-2012 <NAME> and <NAME>.
This file is part of pbrt.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#if defined(_MSC_VER)
#pragma once
#endif
#ifndef PBRT_CORE_GEOMETRY_H
#define PBRT_CORE_GEOMETRY_H
// core/geometry.h*
#include "pbrt.h"
// Geometry Declarations
template <class scalar>
class VectorBase {
protected:
typedef ScalarTraits<scalar> Traits;
public:
// VectorBase Public Methods
VectorBase() { x = y = z = Traits::zero(); }
VectorBase(scalar xx, scalar yy, scalar zz)
: x(xx), y(yy), z(zz) {
Assert(!HasNaNs());
}
bool HasNaNs() const { return Traits::isNaN(x) || Traits::isNaN(y) || Traits::isNaN(z); }
explicit VectorBase(const PointBase<scalar> &p);
#ifndef NDEBUG
// The default versions of these are fine for release builds; for debug
// we define them so that we can add the Assert checks.
VectorBase(const VectorBase &v) {
Assert(!v.HasNaNs());
x = v.x; y = v.y; z = v.z;
}
VectorBase &operator=(const VectorBase &v) {
Assert(!v.HasNaNs());
x = v.x; y = v.y; z = v.z;
return *this;
}
#endif // !NDEBUG
VectorBase operator+(const VectorBase &v) const {
Assert(!v.HasNaNs());
return VectorBase(x + v.x, y + v.y, z + v.z);
}
VectorBase& operator+=(const VectorBase &v) {
Assert(!v.HasNaNs());
x += v.x; y += v.y; z += v.z;
return *this;
}
VectorBase operator-(const VectorBase &v) const {
Assert(!v.HasNaNs());
return VectorBase(x - v.x, y - v.y, z - v.z);
}
VectorBase& operator-=(const VectorBase &v) {
Assert(!v.HasNaNs());
x -= v.x; y -= v.y; z -= v.z;
return *this;
}
template <class scalartype>
VectorBase operator*(scalartype f) const {
return VectorBase(Traits::value(f)*x, Traits::value(f)*y, Traits::value(f)*z);
}
template <class scalartype>
VectorBase &operator*=(scalartype f) {
Assert(!Traits::isNaN(Traits::value(f)));
x *= Traits::value(f); y *= Traits::value(f); z *= Traits::value(f);
return *this;
}
template <class scalartype>
VectorBase operator/(scalartype f) const {
Assert(Traits::value(f) != Traits::zero());
scalar inv = Traits::one() / Traits::value(f);
return VectorBase(x * inv, y * inv, z * inv);
}
template <class scalartype>
VectorBase &operator/=(scalartype f) {
Assert(Traits::value(f) != Traits::zero());
scalar inv = Traits::one() / Traits::value(f);
x *= inv; y *= inv; z *= inv;
return *this;
}
VectorBase operator-() const { return VectorBase(-x, -y, -z); }
scalar operator[](int i) const {
Assert(i >= 0 && i <= 2);
return (&x)[i];
}
scalar &operator[](int i) {
Assert(i >= 0 && i <= 2);
return (&x)[i];
}
scalar LengthSquared() const { return x*x + y*y + z*z; }
scalar Length() const { return sqrt(LengthSquared()); }
explicit VectorBase(const NormalBase<scalar> &n);
bool operator==(const VectorBase &v) const {
return x == v.x && y == v.y && z == v.z;
}
bool operator!=(const VectorBase &v) const {
return x != v.x || y != v.y || z != v.z;
}
// VectorBase Public Data
scalar x, y, z;
// VectorBase Public Static Data
static const VectorBase Zero;
};
template<class scalar>
const VectorBase<scalar> VectorBase<scalar>::Zero(Traits::zero(), Traits::zero(), Traits::zero());
template <class scalar>
class PointBase {
protected:
typedef ScalarTraits<scalar> Traits;
public:
// PointBase Public Methods
PointBase() { x = y = z = Traits::zero(); }
PointBase(scalar xx, scalar yy, scalar zz)
: x(xx), y(yy), z(zz) {
Assert(!HasNaNs());
}
#ifndef NDEBUG
PointBase(const PointBase &p) {
Assert(!p.HasNaNs());
x = p.x; y = p.y; z = p.z;
}
PointBase &operator=(const PointBase &p) {
Assert(!p.HasNaNs());
x = p.x; y = p.y; z = p.z;
return *this;
}
#endif // !NDEBUG
PointBase operator+(const VectorBase<scalar> &v) const {
Assert(!v.HasNaNs());
return PointBase(x + v.x, y + v.y, z + v.z);
}
PointBase &operator+=(const VectorBase<scalar> &v) {
Assert(!v.HasNaNs());
x += v.x; y += v.y; z += v.z;
return *this;
}
VectorBase<scalar> operator-(const PointBase &p) const {
Assert(!p.HasNaNs());
return VectorBase<scalar>(x - p.x, y - p.y, z - p.z);
}
PointBase operator-(const VectorBase<scalar> &v) const {
Assert(!v.HasNaNs());
return PointBase(x - v.x, y - v.y, z - v.z);
}
PointBase &operator-=(const VectorBase<scalar> &v) {
Assert(!v.HasNaNs());
x -= v.x; y -= v.y; z -= v.z;
return *this;
}
PointBase &operator+=(const PointBase &p) {
Assert(!p.HasNaNs());
x += p.x; y += p.y; z += p.z;
return *this;
}
PointBase operator+(const PointBase &p) const {
Assert(!p.HasNaNs());
return PointBase(x + p.x, y + p.y, z + p.z);
}
template <class scalartype>
PointBase operator* (scalartype f) const {
return PointBase(Traits::value(f)*x, Traits::value(f)*y, Traits::value(f)*z);
}
template <class scalartype>
PointBase &operator*=(scalartype f) {
x *= Traits::value(f); y *= Traits::value(f); z *= Traits::value(f);
return *this;
}
template <class scalartype>
PointBase operator/ (scalartype f) const {
scalar inv = Traits::one()/Traits::value(f);
return PointBase(inv*x, inv*y, inv*z);
}
template <class scalartype>
PointBase &operator/=(scalartype f) {
scalar inv = Traits::one()/Traits::value(f);
x *= inv; y *= inv; z *= inv;
return *this;
}
scalar operator[](int i) const {
Assert(i >= 0 && i <= 2);
return (&x)[i];
}
scalar &operator[](int i) {
Assert(i >= 0 && i <= 2);
return (&x)[i];
}
bool HasNaNs() const {
return Traits::isNaN(x) || Traits::isNaN(y) || Traits::isNaN(z);
}
bool operator==(const PointBase &p) const {
return x == p.x && y == p.y && z == p.z;
}
bool operator!=(const PointBase &p) const {
return x != p.x || y != p.y || z != p.z;
}
// PointBase Public Data
scalar x, y, z;
// PointBase Public Static Data
static const PointBase Zero;
};
template<class scalar>
const PointBase<scalar> PointBase<scalar>::Zero(Traits::zero(), Traits::zero(), Traits::zero());
template <class scalar>
class NormalBase {
protected:
typedef ScalarTraits<scalar> Traits;
public:
// NormalBase Public Methods
NormalBase() { x = y = z = Traits::zero(); }
NormalBase(scalar xx, scalar yy, scalar zz)
: x(xx), y(yy), z(zz) {
Assert(!HasNaNs());
}
NormalBase operator-() const {
return NormalBase(-x, -y, -z);
}
NormalBase operator+ (const NormalBase &n) const {
Assert(!n.HasNaNs());
return NormalBase(x + n.x, y + n.y, z + n.z);
}
NormalBase& operator+=(const NormalBase &n) {
Assert(!n.HasNaNs());
x += n.x; y += n.y; z += n.z;
return *this;
}
NormalBase operator- (const NormalBase &n) const {
Assert(!n.HasNaNs());
return NormalBase(x - n.x, y - n.y, z - n.z);
}
NormalBase& operator-=(const NormalBase &n) {
Assert(!n.HasNaNs());
x -= n.x; y -= n.y; z -= n.z;
return *this;
}
bool HasNaNs() const {
return Traits::isNaN(x) || Traits::isNaN(y) || Traits::isNaN(z);
}
template <class scalartype>
NormalBase operator*(scalartype f) const {
return NormalBase(Traits::value(f)*x, Traits::value(f)*y, Traits::value(f)*z);
}
template <class scalartype>
NormalBase &operator*=(scalartype f) {
x *= Traits::value(f); y *= Traits::value(f); z *= Traits::value(f);
return *this;
}
template <class scalartype>
NormalBase operator/(scalartype f) const {
Assert(Traits::value(f) != Traits::zero());
scalar inv = Traits::one()/Traits::value(f);
return NormalBase(x * inv, y * inv, z * inv);
}
template <class scalartype>
NormalBase &operator/=(scalartype f) {
Assert(Traits::value(f) != Traits::zero());
scalar inv = Traits::one()/Traits::value(f);
x *= inv; y *= inv; z *= inv;
return *this;
}
scalar LengthSquared() const { return x*x + y*y + z*z; }
scalar Length() const { return sqrt(LengthSquared()); }
#ifndef NDEBUG
NormalBase(const NormalBase &n) {
Assert(!n.HasNaNs());
x = n.x; y = n.y; z = n.z;
}
NormalBase &operator=(const NormalBase &n) {
Assert(!n.HasNaNs());
x = n.x; y = n.y; z = n.z;
return *this;
}
#endif // !NDEBUG
explicit NormalBase(const VectorBase<scalar> &v)
: x(v.x), y(v.y), z(v.z) {
Assert(!v.HasNaNs());
}
scalar operator[](int i) const {
Assert(i >= 0 && i <= 2);
return (&x)[i];
}
scalar &operator[](int i) {
Assert(i >= 0 && i <= 2);
return (&x)[i];
}
bool operator==(const NormalBase &n) const {
return x == n.x && y == n.y && z == n.z;
}
bool operator!=(const NormalBase &n) const {
return x != n.x || y != n.y || z != n.z;
}
// NormalBase Public Data
scalar x, y, z;
// NormalBase Public Static Data
static const NormalBase Zero;
};
template<class scalar>
const NormalBase<scalar> NormalBase<scalar>::Zero(Traits::zero(), Traits::zero(), Traits::zero());
template <class scalar>
class RayBase {
protected:
typedef ScalarTraits<scalar> Traits;
public:
// RayBase Public Methods
RayBase() : mint(ScalarTraits<scalar>::zero()), maxt(Traits::max()), time(ScalarTraits<scalar>::zero()), depth(0) { }
RayBase(const PointBase<scalar> &origin, const VectorBase<scalar> &direction,
scalar start, scalar end = Traits::max(), scalar t = ScalarTraits<scalar>::zero(), int d = 0)
: o(origin), d(direction), mint(start), maxt(end), time(t), depth(d) { }
RayBase(const PointBase<scalar> &origin, const VectorBase<scalar> &direction, const RayBase &parent,
scalar start, scalar end = Traits::max())
: o(origin), d(direction), mint(start), maxt(end),
time(parent.time), depth(parent.depth+1) { }
template <class scalartype>
PointBase<scalar> operator()(scalartype t) const { return o + d * Traits::value(t); }
bool HasNaNs() const {
return (o.HasNaNs() || d.HasNaNs() ||
Traits::isNaN(mint) || Traits::isNaN(maxt));
}
// RayBase Public Data
PointBase<scalar> o;
VectorBase<scalar> d;
mutable scalar mint, maxt;
scalar time;
int depth;
};
template <class scalar>
class RayDifferentialBase : public RayBase<scalar> {
public:
// RayDifferentialBase Public Methods
RayDifferentialBase() { hasDifferentials = false; }
RayDifferentialBase(const PointBase<scalar> &org, const VectorBase<scalar> &dir, scalar start,
scalar end = Traits::max(), scalar t = ScalarTraits<scalar>::zero(), int d = 0)
: RayBase<scalar>(org, dir, start, end, t, d) {
hasDifferentials = false;
}
RayDifferentialBase(const PointBase<scalar> &org, const VectorBase<scalar> &dir, const RayBase<scalar> &parent,
scalar start, scalar end = Traits::max())
: RayBase<scalar>(org, dir, start, end, parent.time, parent.depth+1) {
hasDifferentials = false;
}
explicit RayDifferentialBase(const RayBase<scalar> &ray) : RayBase<scalar>(ray) {
hasDifferentials = false;
}
bool HasNaNs() const {
return RayBase<scalar>::HasNaNs() ||
(hasDifferentials && (rxOrigin.HasNaNs() || ryOrigin.HasNaNs() ||
rxDirection.HasNaNs() || ryDirection.HasNaNs()));
}
template <class scalartype>
void ScaleDifferentials(scalartype s) {
rxOrigin = o + (rxOrigin - o) * Traits::value(s);
ryOrigin = o + (ryOrigin - o) * Traits::value(s);
rxDirection = d + (rxDirection - d) * Traits::value(s);
ryDirection = d + (ryDirection - d) * Traits::value(s);
}
// RayDifferentialBase Public Data
bool hasDifferentials;
PointBase<scalar> rxOrigin, ryOrigin;
VectorBase<scalar> rxDirection, ryDirection;
};
template <class scalar>
class BBoxBase {
private:
typedef ScalarTraits<scalar> Traits;
public:
// BBoxBase Public Methods
BBoxBase() {
pMin = PointBase<scalar>(Traits::max(), Traits::max(), Traits::max());
pMax = PointBase<scalar>(Traits::negmax(), Traits::negmax(), Traits::negmax());
}
BBoxBase(const PointBase<scalar> &p) : pMin(p), pMax(p) { }
BBoxBase(const PointBase<scalar> &p1, const PointBase<scalar> &p2) {
pMin = PointBase<scalar>(min(p1.x, p2.x), min(p1.y, p2.y), min(p1.z, p2.z));
pMax = PointBase<scalar>(max(p1.x, p2.x), max(p1.y, p2.y), max(p1.z, p2.z));
}
friend BBoxBase Union(const BBoxBase &b, const PointBase<scalar> &p);
friend BBoxBase Union(const BBoxBase &b, const BBoxBase &b2);
bool Overlaps(const BBoxBase &b) const {
bool x = (pMax.x >= b.pMin.x) && (pMin.x <= b.pMax.x);
bool y = (pMax.y >= b.pMin.y) && (pMin.y <= b.pMax.y);
bool z = (pMax.z >= b.pMin.z) && (pMin.z <= b.pMax.z);
return (x && y && z);
}
bool Inside(const PointBase<scalar> &pt) const {
return (pt.x >= pMin.x && pt.x <= pMax.x &&
pt.y >= pMin.y && pt.y <= pMax.y &&
pt.z >= pMin.z && pt.z <= pMax.z);
}
template <class scalartype>
void Expand(scalartype delta) {
pMin -= VectorBase<scalar>(Traits::value(delta), Traits::value(delta), Traits::value(delta));
pMax += VectorBase<scalar>(Traits::value(delta), Traits::value(delta), Traits::value(delta));
}
scalar SurfaceArea() const {
VectorBase<scalar> d = pMax - pMin;
return Traits::value(2) * (d.x * d.y + d.x * d.z + d.y * d.z);
}
scalar Volume() const {
VectorBase<scalar> d = pMax - pMin;
return d.x * d.y * d.z;
}
int MaximumExtent() const {
VectorBase<scalar> diag = pMax - pMin;
if (diag.x > diag.y && diag.x > diag.z)
return 0;
else if (diag.y > diag.z)
return 1;
else
return 2;
}
const PointBase<scalar> &operator[](int i) const;
PointBase<scalar> &operator[](int i);
template <class scalar1, class scalar2, class scalar3>
PointBase<scalar> Lerp(scalar1 tx, scalar2 ty, scalar3 tz) const {
return PointBase<scalar>(::Lerp(Traits::value(tx), pMin.x, pMax.x), ::Lerp(Traits::value(ty), pMin.y, pMax.y),
::Lerp(Traits::value(tz), pMin.z, pMax.z));
}
VectorBase<scalar> Offset(const PointBase<scalar> &p) const {
return VectorBase<scalar>((p.x - pMin.x) / (pMax.x - pMin.x),
(p.y - pMin.y) / (pMax.y - pMin.y),
(p.z - pMin.z) / (pMax.z - pMin.z));
}
void BoundingSphere(PointBase<scalar> *c, scalar *rad) const;
bool IntersectP(const RayBase<scalar> &ray, scalar *hitt0 = NULL, scalar *hitt1 = NULL) const;
bool operator==(const BBoxBase &b) const {
return b.pMin == pMin && b.pMax == pMax;
}
bool operator!=(const BBoxBase &b) const {
return b.pMin != pMin || b.pMax != pMax;
}
// BBoxBase Public Data
PointBase<scalar> pMin, pMax;
};
// Geometry Inline Functions
template <class scalar>
inline VectorBase<scalar>::VectorBase(const PointBase<scalar> &p)
: x(p.x), y(p.y), z(p.z) {
Assert(!HasNaNs());
}
template <class scalar, class scalartype>
inline VectorBase<scalar> operator*(scalartype f, const VectorBase<scalar> &v) { return v*f; }
template <class scalar>
inline float Dot(const VectorBase<scalar> &v1, const VectorBase<scalar> &v2) {
Assert(!v1.HasNaNs() && !v2.HasNaNs());
return v1.x * v2.x + v1.y * v2.y + v1.z * v2.z;
}
template <class scalar>
inline float AbsDot(const VectorBase<scalar> &v1, const VectorBase<scalar> &v2) {
Assert(!v1.HasNaNs() && !v2.HasNaNs());
return abs(Dot(v1, v2));
}
template <class scalar>
inline VectorBase<scalar> Cross(const VectorBase<scalar> &v1, const VectorBase<scalar> &v2) {
Assert(!v1.HasNaNs() && !v2.HasNaNs());
double v1x = v1.x, v1y = v1.y, v1z = v1.z;
double v2x = v2.x, v2y = v2.y, v2z = v2.z;
return VectorBase<scalar>((v1y * v2z) - (v1z * v2y),
(v1z * v2x) - (v1x * v2z),
(v1x * v2y) - (v1y * v2x));
}
template <class scalar>
inline VectorBase<scalar> Cross(const VectorBase<scalar> &v1, const NormalBase<scalar> &v2) {
Assert(!v1.HasNaNs() && !v2.HasNaNs());
double v1x = v1.x, v1y = v1.y, v1z = v1.z;
double v2x = v2.x, v2y = v2.y, v2z = v2.z;
return VectorBase<scalar>((v1y * v2z) - (v1z * v2y),
(v1z * v2x) - (v1x * v2z),
(v1x * v2y) - (v1y * v2x));
}
template <class scalar>
inline VectorBase<scalar> Cross(const NormalBase<scalar> &v1, const VectorBase<scalar> &v2) {
Assert(!v1.HasNaNs() && !v2.HasNaNs());
double v1x = v1.x, v1y = v1.y, v1z = v1.z;
double v2x = v2.x, v2y = v2.y, v2z = v2.z;
return VectorBase<scalar>((v1y * v2z) - (v1z * v2y),
(v1z * v2x) - (v1x * v2z),
(v1x * v2y) - (v1y * v2x));
}
template <class scalar>
inline VectorBase<scalar> Normalize(const VectorBase<scalar> &v) { return v / v.Length(); }
template <class scalar>
inline void CoordinateSystem(const VectorBase<scalar> &v1, VectorBase<scalar> *v2, VectorBase<scalar> *v3) {
if (abs(v1.x) > abs(v1.y)) {
scalar invLen = ScalarTraits<scalar>::one() / sqrt(v1.x*v1.x + v1.z*v1.z);
*v2 = VectorBase<scalar>(-v1.z * invLen, ScalarTraits<scalar>::zero(), v1.x * invLen);
}
else {
scalar invLen = ScalarTraits<scalar>::one() / sqrt(v1.y*v1.y + v1.z*v1.z);
*v2 = VectorBase<scalar>(ScalarTraits<scalar>::zero(), v1.z * invLen, -v1.y * invLen);
}
*v3 = Cross(v1, *v2);
}
template <class scalar>
inline scalar Distance(const PointBase<scalar> &p1, const PointBase<scalar> &p2) {
return (p1 - p2).Length();
}
template <class scalar>
inline scalar DistanceSquared(const PointBase<scalar> &p1, const PointBase<scalar> &p2) {
return (p1 - p2).LengthSquared();
}
template <class scalar, class scalartype>
inline PointBase<scalar> operator*(scalartype f, const PointBase<scalar> &p) {
Assert(!p.HasNaNs());
return p*f;
}
template <class scalar, class scalartype>
inline NormalBase<scalar> operator*(scalartype f, const NormalBase<scalar> &n) {
return NormalBase<scalar>(ScaVal(f)*n.x,
ScaVal(f)*n.y, ScaVal(f)*n.z);
}
template <class scalar>
inline NormalBase<scalar> Normalize(const NormalBase<scalar> &n) {
return n / n.Length();
}
template <class scalar>
inline VectorBase<scalar>::VectorBase(const NormalBase<scalar> &n)
: x(n.x), y(n.y), z(n.z) {
Assert(!n.HasNaNs());
}
template <class scalar>
inline scalar Dot(const NormalBase<scalar> &n1, const VectorBase<scalar> &v2) {
Assert(!n1.HasNaNs() && !v2.HasNaNs());
return n1.x * v2.x + n1.y * v2.y + n1.z * v2.z;
}
template <class scalar>
inline scalar Dot(const VectorBase<scalar> &v1, const NormalBase<scalar> &n2) {
Assert(!v1.HasNaNs() && !n2.HasNaNs());
return v1.x * n2.x + v1.y * n2.y + v1.z * n2.z;
}
template <class scalar>
inline scalar Dot(const NormalBase<scalar> &n1, const NormalBase<scalar> &n2) {
Assert(!n1.HasNaNs() && !n2.HasNaNs());
return n1.x * n2.x + n1.y * n2.y + n1.z * n2.z;
}
template <class scalar>
inline scalar AbsDot(const NormalBase<scalar> &n1, const VectorBase<scalar> &v2) {
Assert(!n1.HasNaNs() && !v2.HasNaNs());
return abs(n1.x * v2.x + n1.y * v2.y + n1.z * v2.z);
}
template <class scalar>
inline scalar AbsDot(const VectorBase<scalar> &v1, const NormalBase<scalar> &n2) {
Assert(!v1.HasNaNs() && !n2.HasNaNs());
return abs(v1.x * n2.x + v1.y * n2.y + v1.z * n2.z);
}
template <class scalar>
inline scalar AbsDot(const NormalBase<scalar> &n1, const NormalBase<scalar> &n2) {
Assert(!n1.HasNaNs() && !n2.HasNaNs());
return abs(n1.x * n2.x + n1.y * n2.y + n1.z * n2.z);
}
template <class scalar>
inline NormalBase<scalar> Faceforward(const NormalBase<scalar> &n, const VectorBase<scalar> &v) {
return (Dot(n, v) < ScalarTraits<scalar>::zero()) ? -n : n;
}
template <class scalar>
inline NormalBase<scalar> Faceforward(const NormalBase<scalar> &n, const NormalBase<scalar> &n2) {
return (Dot(n, n2) < ScalarTraits<scalar>::zero()) ? -n : n;
}
template <class scalar>
inline VectorBase<scalar> Faceforward(const VectorBase<scalar> &v, const VectorBase<scalar> &v2) {
return (Dot(v, v2) < ScalarTraits<scalar>::zero()) ? -v : v;
}
template <class scalar>
inline VectorBase<scalar> Faceforward(const VectorBase<scalar> &v, const NormalBase<scalar> &n2) {
return (Dot(v, n2) < ScalarTraits<scalar>::zero()) ? -v : v;
}
template <class scalar>
inline const PointBase<scalar> &BBoxBase<scalar>::operator[](int i) const {
Assert(i == 0 || i == 1);
return (&pMin)[i];
}
template <class scalar>
inline PointBase<scalar> &BBoxBase<scalar>::operator[](int i) {
Assert(i == 0 || i == 1);
return (&pMin)[i];
}
template <class scalar, class scalar1, class scalar2, class scalar3>
inline VectorBase<scalar> SphericalDirection(scalar1 sintheta,
scalar2 costheta, scalar3 phi) {
return VectorBase<scalar>(ScaVal(sintheta) * cos(ScaVal(phi)),
ScaVal(sintheta) * sin(ScaVal(phi)),
ScaVal(costheta));
}
template <class scalar, class scalar1, class scalar2, class scalar3>
inline VectorBase<scalar> SphericalDirection(scalar1 sintheta, scalar2 costheta,
scalar3 phi, const VectorBase<scalar> &x,
const VectorBase<scalar> &y, const VectorBase<scalar> &z) {
return ScaVal(sintheta) * cos(ScaVal(phi)) * x +
ScaVal(sintheta) * sin(ScaVal(phi)) * y +
ScaVal(costheta) * z;
}
template <class scalar>
inline scalar SphericalTheta(const VectorBase<scalar> &v) {
return acos(Clamp(v.z, -ScalarTraits<scalar>::one(), ScalarTraits<scalar>::one()));
}
template <class scalar>
inline scalar SphericalPhi(const VectorBase<scalar> &v) {
scalar p = atan2(v.y, v.x);
return (p < ScalarTraits<scalar>::zero()) ? p + ScaVal(2*M_PI) : p;
}
#endif // PBRT_CORE_GEOMETRY_H
|
patwonder/pbrt-v2-skin | src/renderers/mcprofile.h |
/*
Copyright(c) 2013-2014 <NAME>.
This file is part of fork of pbrt (pbrt-v2-skin).
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "pbrt.h"
#include "renderer.h"
#include "layer.h"
struct MCProfileEntry {
MCProfileEntry() {
reflectance = transmittance = 0.;
}
MCProfileEntry(double r, double t)
: reflectance(r), transmittance(t)
{
}
double reflectance;
double transmittance;
};
typedef vector<MCProfileEntry> MCProfile;
struct MCProfileResult {
double totalMCReflectance;
double totalMCTransmittance;
double totalNoLerpReflectance;
double totalNoLerpTransmittance;
double totalLerpReflectance;
double totalLerpTransmittance;
MCProfileResult() {
totalMCReflectance = 0.;
totalMCTransmittance = 0.;
totalNoLerpReflectance = 0.;
totalNoLerpTransmittance = 0.;
totalLerpReflectance = 0.;
totalLerpTransmittance = 0.;
}
};
class MonteCarloProfileRenderer : public Renderer {
public:
// MonteCarloProfileRenderer Public Methods
MonteCarloProfileRenderer(const Layer* layers, int nLayers, float mfpRange,
int segments, uint64_t photons, string filename,
bool noClearCache = false, bool silent = false, bool noCompare = false)
: layers(layers, layers + nLayers), mfpRange(mfpRange), nSegments(segments),
nPhotons(photons), filename(filename), noClearCache(noClearCache), silent(silent),
noCompare(noCompare)
{
}
void Render(const Scene* scene) override;
Spectrum Li(const Scene* scene, const RayDifferential& ray,
const Sample* sample, RNG& rng, MemoryArena& arena,
Intersection* isect, Spectrum* T) const override;
Spectrum Transmittance(const Scene* scene, const RayDifferential& ray,
const Sample* sample, RNG& rng, MemoryArena& arena) const override;
const MCProfileResult& GetResult() const { return result; }
const MCProfile& GetProfile() const { return resultProfile; }
static void ClearCache();
private:
// MonteCarloProfileRenderer Private Data
vector<Layer> layers;
float mfpRange;
int nSegments;
string filename;
uint64_t nPhotons;
bool noClearCache;
bool silent;
bool noCompare;
MCProfileResult result;
MCProfile resultProfile;
// MonteCarloProfileRenderer Private Methods
};
MonteCarloProfileRenderer* CreateMonteCarloProfileRenderer(const ParamSet& params);
|
n4226/SwiftyMetal | Sources/SwiftyMetal-C/include/shaderTypes.h |
#ifndef ShaderTypes_h
#define ShaderTypes_h
#ifdef __METAL_VERSION__
#define NS_ENUM(_type, _name) enum _name : _type _name; enum _name : _type
#define NSInteger metal::int32_t
#else
#import <Foundation/Foundation.h>
#endif
#include <simd/simd.h>
typedef NS_ENUM(NSInteger, VertexAttribute)
{
VertexAttributePosition = 0,
VertexAttributeColor = 1,
VertexAttributeUV = 2,
VertexAttributeNormal = 3,
VertexAttributeTangent = 4,
VertexAttributeBitangent = 5,
};
typedef NS_ENUM(NSInteger, MatArgId)
{
MatArgIdPipeline = 0,
MatArgIdAlbedo = 1,
MatArgIdMetallic = 2,
MatArgIdNormal = 3,
MatArgIdRoughness = 4,
MatArgIdAo = 5,
MatArgIdShadowMap = 6,
MatArgIdUseColors = 7
};
typedef NS_ENUM(NSInteger, BufferIndex)
{
BufferIndexMeshPositions = 0,
BufferIndexMeshGenerics = 1,
BufferIndexUniforms = 13,
BufferIndexMaterial = 14,
BufferIndexSubMesh = 15,
BufferIndexModelTransform = 16,
BufferIndexModelTransformUpperLeft = 17,
};
typedef NS_ENUM(NSInteger, PostProcessingIndicies)
{
PostProcessingIndiciesInput = 18,
PostProcessingIndiciesOutput = 19,
};
typedef NS_ENUM(NSInteger, RenderTargetIndices)
{
RenderTargetLighting = 0,
RenderTargetAlbedo = 1,
RenderTargetNormal = 2,
RenderTargetDepth = 3,
RenderTargetShadowDepth = 4
};
typedef struct
{
matrix_float4x4 projectionViewMatrix;
matrix_float4x4 projectionMatrix;
matrix_float4x4 viewMatrix;
matrix_float4x4 projection_matrix_inverse;
uint framebuffer_width;
uint framebuffer_height;
} Uniforms;
#endif /* Header_h */
|
n4226/SwiftyMetal | Sources/SwiftyMetal-C/include/argumentBuffers.h |
#ifdef __METAL_VERSION__
#ifndef Header_h
#define Header_h
typedef struct {
render_pipeline_state pipelinestate [[id(MatArgIdPipeline)]];
texture2d<half,access::sample> albedo [[id(MatArgIdAlbedo)]]; // float3
texture2d<half,access::sample> metallic [[id(MatArgIdMetallic)]];
texture2d<half,access::sample> normal [[id(MatArgIdNormal)]];
texture2d<half,access::sample> roughness [[id(MatArgIdRoughness)]];
texture2d<half,access::sample> ao [[id(MatArgIdAo)]];
depth2d<float,access::sample> shadowMap [[ id(MatArgIdShadowMap) ]];
bool useColors [[ id(MatArgIdUseColors) ]];
// float
} PBRMaterial;
typedef struct {
float3 albedo; // float3
float metallic;
float roughness;
float ao;
} SampledPBRMaterial;
// Raster order group definitions
#define LightingROG 0
#define GBufferROG 1
// G-buffer outputs using Raster Order Groups
struct GBufferData
{
half4 lighting [[color(RenderTargetLighting), raster_order_group(AAPLLightingROG)]];
half4 albedo_specular [[color(RenderTargetAlbedo), raster_order_group(AAPLGBufferROG)]];
half4 normal_shadow [[color(RenderTargetNormal), raster_order_group(AAPLGBufferROG)]];
float depth [[color(RenderTargetDepth), raster_order_group(AAPLGBufferROG)]];
};
#endif /* Header_h */
#endif
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/mtpFilesystemErrors.h | /*
* mtpFilesystemErrors.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MTPFILESYSTEMERRORS_H_
#define MTPFILESYSTEMERRORS_H_
#include <stdexcept>
// There appears to be a bug in Android 4.0.4 on the Galaxy Nexus (and maybe
// other Android versions as well) where if you specify a filename greater
// that 233 characters the MTP stack looses it mind. Creating the file
// reports an error. The file or may not have actually been created on the
// device filesystem, but either way MTP will show the file as existing
// but generate an error if you try to delete the file. You have to
// reboot the device to get MTP to start behaving again.
// So to prevent this from happening we set a limit on the filename
// length.
#define MAX_MTP_NAME_LENGTH 233
class MtpFilesystemError : public std::runtime_error
{
public:
MtpFilesystemError(const std::string& what) : std::runtime_error(what) {};
};
class FileNotFound : public MtpFilesystemError
{
public:
FileNotFound(const std::string& what) : MtpFilesystemError(std::string("File not found: ") + what)
{
}
};
class NotImplemented : public MtpFilesystemError
{
public:
NotImplemented(const std::string& what) : MtpFilesystemError(std::string("Not implemented: ") + what)
{
}
};
class MtpFilesystemErrorWithErrorCode : public MtpFilesystemError
{
public:
MtpFilesystemErrorWithErrorCode(int errorCode, const std::string& message) : MtpFilesystemError(message), m_errorCode(errorCode)
{
}
int ErrorCode() const { return m_errorCode; };
private:
int m_errorCode;
};
class CantCreateTempFile : public MtpFilesystemErrorWithErrorCode
{
public:
CantCreateTempFile(int errorCode) : MtpFilesystemErrorWithErrorCode(errorCode, "Can't create temp file") {}
};
class ReadError : public MtpFilesystemErrorWithErrorCode
{
public:
ReadError(int errorCode) : MtpFilesystemErrorWithErrorCode(errorCode, "Can't read file") {}
};
class WriteError : public MtpFilesystemErrorWithErrorCode
{
public:
WriteError(int errorCode) : MtpFilesystemErrorWithErrorCode(errorCode, "Can't write file") {}
};
class ReadOnly : public MtpFilesystemErrorWithErrorCode
{
public:
ReadOnly() : MtpFilesystemErrorWithErrorCode(EROFS, "read only") {}
};
class MtpDirectoryNotEmpty : public MtpFilesystemErrorWithErrorCode
{
public:
MtpDirectoryNotEmpty() : MtpFilesystemErrorWithErrorCode(ENOTEMPTY, "Directoy not empty") {};
};
class NotADirectory : public MtpFilesystemError
{
public:
NotADirectory() : MtpFilesystemError("Not a directory: ") {}
};
class MtpNameTooLong : public MtpFilesystemErrorWithErrorCode
{
public:
MtpNameTooLong() : MtpFilesystemErrorWithErrorCode(ENAMETOOLONG, "Filename too long") {};
};
#endif /* MTPFILESYSTEMERRORS_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/MtpFuseContext.h | <reponame>akshaykumar23399/DOTS<filename>jmtpfs/src/jmtpfs-0.5/src/MtpFuseContext.h
/*
* MtpFuseContext.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MTPFUSECONTEXT_H_
#define MTPFUSECONTEXT_H_
#include "MtpDevice.h"
#include "MtpMetadataCache.h"
#include "MtpNode.h"
#include <memory>
#include <sys/types.h>
class MtpFuseContext
{
public:
MtpFuseContext(std::unique_ptr<MtpDevice> device, uid_t uid, gid_t gid);
std::unique_ptr<MtpNode> getNode(const FilesystemPath& path);
uid_t uid() const;
gid_t gid() const;
protected:
uid_t m_uid;
gid_t m_gid;
std::unique_ptr<MtpDevice> m_device;
MtpMetadataCache m_cache;
};
#endif /* MTPFUSECONTEXT_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/MtpRoot.h | <gh_stars>0
/*
* MtpRoot.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MTPROOT_H_
#define MTPROOT_H_
#include "MtpNode.h"
class MtpRoot : public MtpNode
{
public:
MtpRoot(MtpDevice& device, MtpMetadataCache& cache);
std::unique_ptr<MtpNode> getNode(const FilesystemPath& path);
void getattr(struct stat& info);
std::vector<std::string> readDirectory();
void mkdir(const std::string& name);
void Remove();
MtpNodeMetadata getMetadata();
MtpStorageInfo GetStorageInfo();
void statfs(struct statvfs *stat);
};
#endif /* MTPROOT_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/MtpFile.h | <filename>jmtpfs/src/jmtpfs-0.5/src/MtpFile.h
/*
* MtpFile.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MTPFILE_H_
#define MTPFILE_H_
#include "MtpNode.h"
#include <stdio.h>
class MtpFile : public MtpNode
{
public:
MtpFile(MtpDevice& device, MtpMetadataCache& cache, uint32_t id);
~MtpFile();
std::unique_ptr<MtpNode> getNode(const FilesystemPath& path);
void getattr(struct stat& info);
void Open();
void Close();
int Read(char *buf, size_t size, off_t offset);
int Write(const char* buf, size_t size, off_t offset);
void Remove();
void Fsync();
void Truncate(off_t length);
void Rename(MtpNode& newParent, const std::string& newName);
MtpNodeMetadata getMetadata();
protected:
MtpFileInfo m_info;
bool m_opened;
FILE* m_localFile;
bool m_needWrite;
};
#endif /* MTPFILE_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/MtpFolder.h | <gh_stars>0
/*
* MtpFolder.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MTPFOLDER_H_
#define MTPFOLDER_H_
#include "MtpNode.h"
class MtpFolder : public MtpNode
{
public:
MtpFolder(MtpDevice& device, MtpMetadataCache& cache, uint32_t storageId, uint32_t folderId);
std::unique_ptr<MtpNode> getNode(const FilesystemPath& path);
void getattr(struct stat& info);
std::vector<std::string> readDirectory();
void Remove();
void mkdir(const std::string& name);
void CreateFile(const std::string& name);
uint32_t FolderId();
uint32_t StorageId();
void Rename(MtpNode& newParent, const std::string& newName);
MtpNodeMetadata getMetadata();
protected:
std::vector<MtpFileInfo> m_files;
uint32_t m_storageId, m_folderId;
};
#endif /* MTPFOLDER_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/MtpNode.h | /*
* MtpNode.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MTPNODE_H_
#define MTPNODE_H_
#include "MtpMetadataCache.h"
#include "MtpFilesystemPath.h"
#include "MtpDevice.h"
#include "FuseHeader.h"
#include <time.h>
#include <vector>
#include <string>
#include <memory>
class MtpNode : public MtpMetadataCacheFiller
{
public:
MtpNode(MtpDevice& device, MtpMetadataCache& cache, uint32_t id);
virtual ~MtpNode();
virtual std::vector<std::string> readdir();
virtual uint32_t Id();
virtual std::unique_ptr<MtpNode> getNode(const FilesystemPath& path)=0;
virtual std::vector<std::string> readDirectory();
virtual void getattr(struct stat& info) = 0;
virtual void Open();
virtual void Close();
virtual int Read(char *buf, size_t size, off_t offset);
virtual int Write(const char* buf, size_t size, off_t offset);
virtual void mkdir(const std::string& name);
virtual void Remove();
virtual void CreateFile(const std::string& name);
virtual void Rename(MtpNode& newParent, const std::string& newName);
virtual void Truncate(off_t length);
virtual MtpStorageInfo GetStorageInfo();
virtual uint32_t FolderId();
virtual uint32_t StorageId();
virtual std::unique_ptr<MtpNode> Clone();
virtual void statfs(struct statvfs *stat);
protected:
uint32_t GetParentNodeId();
MtpDevice& m_device;
MtpMetadataCache& m_cache;
uint32_t m_id;
};
#endif /* MTPNODE_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/Mutex.h | /*
* Mutex.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MUTEX_H_
#define MUTEX_H_
#include <pthread.h>
class RecursiveMutex
{
public:
RecursiveMutex();
~RecursiveMutex();
void Lock();
void Unlock();
protected:
pthread_mutex_t m_mutex;
};
class LockMutex
{
public:
LockMutex(RecursiveMutex& mutex);
~LockMutex();
protected:
RecursiveMutex& m_mutex;
};
#endif /* MUTEX_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/MtpLocalFileCopy.h | /*
* MtpLocalFileCopy.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MTPLOCALFILECOPY_H_
#define MTPLOCALFILECOPY_H_
#include "MtpDevice.h"
class MtpLocalFileCopy
{
public:
MtpLocalFileCopy(MtpDevice& device, uint32_t id);
~MtpLocalFileCopy();
/*
* Close the local copy and write changes back to the remote if needed.
* The return value is the id for the remote file, which may have
* changed if we had to write back changes.
*/
uint32_t close();
off_t getSize();
void seek(long offset);
size_t write(const void* ptr, size_t size);
void truncate(off_t length);
size_t read(void* ptr, size_t size);
void CopyTo(MtpDevice& device, NewLIBMTPFile& destination);
private:
MtpLocalFileCopy(const MtpLocalFileCopy&);
MtpLocalFileCopy& operator=(const MtpLocalFileCopy&);
MtpDevice& m_device;
FILE* m_localFile;
uint32_t m_remoteId;
bool m_needWriteBack;
};
#endif /* MTPLOCALFILECOPY_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/MtpStorage.h | /*
* MtpStorage.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MTPSTORAGE_H_
#define MTPSTORAGE_H_
#include "MtpFolder.h"
class MtpStorage : public MtpFolder
{
public:
MtpStorage(MtpDevice& device, MtpMetadataCache& cache, uint32_t id);
void Remove();
void Rename(MtpNode& newParent, const std::string& newName);
std::unique_ptr<MtpNode> Clone();
};
#endif /* MTPSTORAGE_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/TemporaryFile.h | /*
* TempFile.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef TEMPORARYFILE_H_
#define TEMPORARYFILE_H_
#include <stdio.h>
class TemporaryFile
{
public:
TemporaryFile();
~TemporaryFile();
int FileNo();
FILE* Fd();
protected:
FILE* m_file;
};
#endif /* TEMPORARYFILE_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/FuseHeader.h | <reponame>akshaykumar23399/DOTS<gh_stars>0
/*
* FuseHeader.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef FUSEHEADER_H_
#define FUSEHEADER_H_
#define FUSE_USE_VERSION 26
#include <fuse.h>
#include <fuse_opt.h>
#endif /* FUSEHEADER_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/MtpLibLock.h | <reponame>akshaykumar23399/DOTS
/*
* MtpLibLock.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MTPLIBLOCK_H_
#define MTPLIBLOCK_H_
#include "Mutex.h"
class MtpLibLock
{
public:
MtpLibLock();
~MtpLibLock();
private:
static RecursiveMutex m_mutex;
};
#endif /* MTPLIBLOCK_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/MtpDevice.h | /*
* MtpDevice.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MTPDEVICE_H_
#define MTPDEVICE_H_
#include "libmtp.h"
#include <string>
#include <vector>
#include <stdexcept>
#include <string.h>
#include <magic.h>
#define MAGIC_BUFFER_SIZE 8192
class MtpError : public std::runtime_error
{
public:
explicit MtpError(const std::string& message, LIBMTP_error_number_t errorCode) : std::runtime_error(message), m_errorCode(errorCode) {}
LIBMTP_error_number_t ErrorCode() { return m_errorCode; }
protected:
LIBMTP_error_number_t m_errorCode;
};
class ExpectedMtpErrorNotFound : public MtpError
{
public:
ExpectedMtpErrorNotFound() : MtpError("Expected an error condition but found none", LIBMTP_ERROR_GENERAL) {}
};
class MtpErrorCantOpenDevice : public MtpError
{
public:
MtpErrorCantOpenDevice() : MtpError("Can't open device", LIBMTP_ERROR_GENERAL) {}
};
class MtpDeviceDisconnected : public MtpError
{
public:
MtpDeviceDisconnected(const std::string& message) : MtpError(message, LIBMTP_ERROR_NO_DEVICE_ATTACHED) {}
};
class MtpDeviceNotFound : public MtpError
{
public:
MtpDeviceNotFound(const std::string& message) : MtpError(message, LIBMTP_ERROR_GENERAL) {}
};
class MtpStorageNotFound : public MtpError
{
public:
MtpStorageNotFound(const std::string& message) : MtpError(message, LIBMTP_ERROR_GENERAL) {}
};
struct MtpStorageInfo
{
MtpStorageInfo() {}
MtpStorageInfo(uint32_t i, std::string s, uint64_t fs, uint64_t mc) :
id(i), description(s), freeSpaceInBytes(fs), maxCapacity(mc) {}
uint32_t id;
std::string description;
uint64_t freeSpaceInBytes;
uint64_t maxCapacity;
};
struct MtpFileInfo
{
MtpFileInfo() {}
MtpFileInfo(LIBMTP_file_t& info);
MtpFileInfo(uint32_t i, uint32_t p, uint32_t storage, std::string s, LIBMTP_filetype_t t, uint64_t fs) :
id(i), parentId(p), storageId(storage), name(s), filetype(t),
filesize(fs){}
uint32_t id;
uint32_t parentId;
uint32_t storageId;
std::string name;
LIBMTP_filetype_t filetype;
uint64_t filesize;
time_t modificationdate;
};
class NewLIBMTPFile
{
public:
NewLIBMTPFile(const std::string& filename, uint32_t parentId, uint32_t storageId, uint64_t size=0);
~NewLIBMTPFile();
operator LIBMTP_file_t* ();
protected:
LIBMTP_file_t* m_fileInfo;
private:
NewLIBMTPFile(const NewLIBMTPFile&);
NewLIBMTPFile& operator=(const NewLIBMTPFile&);
};
class MtpDevice
{
public:
MtpDevice(LIBMTP_raw_device_t& rawDevice);
~MtpDevice();
std::string Get_Modelname();
std::vector<MtpStorageInfo> GetStorageDevices();
MtpStorageInfo GetStorageInfo(uint32_t storageId);
std::vector<MtpFileInfo> GetFolderContents(uint32_t storageId, uint32_t folderId);
MtpFileInfo GetFileInfo(uint32_t id);
void GetFile(uint32_t id, int fd);
void SendFile(LIBMTP_file_t* destination, int fd);
void CreateFolder(const std::string& name, uint32_t parentId, uint32_t storageId);
void DeleteObject(uint32_t id);
void RenameFile(uint32_t id, const std::string& newName);
void SetObjectProperty(uint32_t id, LIBMTP_property_t property, const std::string& value);
static LIBMTP_filetype_t PropertyTypeFromMimeType(const std::string& mimeType);
protected:
void CheckErrors(bool throwEvenIfNoError);
LIBMTP_mtpdevice_t* m_mtpdevice;
uint32_t m_busLocation;
uint8_t m_devnum;
magic_t m_magicCookie;
char m_magicBuffer[MAGIC_BUFFER_SIZE];
};
#endif /* MTPDEVICE_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/MtpMetadataCache.h | <reponame>akshaykumar23399/DOTS<gh_stars>0
/*
* MtpMetadataCache.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MTPMETADATACACHE_H_
#define MTPMETADATACACHE_H_
#include "MtpNodeMetadata.h"
#include "MtpLocalFileCopy.h"
#include <list>
#include <unordered_map>
class MtpMetadataCacheFiller
{
public:
virtual ~MtpMetadataCacheFiller();
virtual MtpNodeMetadata getMetadata()=0;
};
class MtpMetadataCache
{
public:
MtpMetadataCache();
~MtpMetadataCache();
MtpNodeMetadata getItem(uint32_t id, MtpMetadataCacheFiller& source);
void clearItem(uint32_t id);
MtpLocalFileCopy* openFile(MtpDevice& device, uint32_t id);
MtpLocalFileCopy* getOpenedFile(uint32_t id);
uint32_t closeFile(uint32_t id);
private:
void clearOld();
struct CacheEntry
{
MtpNodeMetadata data;
time_t whenCreated;
};
typedef std::list<CacheEntry> cache_type;
typedef std::unordered_map<uint32_t, cache_type::iterator> cache_lookup_type;
typedef std::unordered_map<uint32_t, MtpLocalFileCopy*> local_file_cache_type;
cache_type m_cache;
cache_lookup_type m_cacheLookup;
local_file_cache_type m_localFileCache;
};
#endif /* MTPMETADATACACHE_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/ConnectedMtpDevices.h | <reponame>akshaykumar23399/DOTS
/*
* ConnectedMtpDevices.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef CONNECTEDMTPDEVICES_H_
#define CONNECTEDMTPDEVICES_H_
#include "MtpDevice.h"
#include <memory>
struct ConnectedDeviceInfo
{
uint32_t bus_location;
uint8_t devnum;
uint32_t device_flags;
std::string product;
uint16_t product_id;
std::string vendor;
uint16_t vendor_id;
};
class ConnectedMtpDevices
{
public:
ConnectedMtpDevices();
~ConnectedMtpDevices();
int NumDevices();
std::unique_ptr<MtpDevice> GetDevice(int index);
std::unique_ptr<MtpDevice> GetDevice(uint32_t busLocation, uint8_t devnum);
ConnectedDeviceInfo GetDeviceInfo(int index);
LIBMTP_raw_device_t& GetRawDeviceEntry(int index);
protected:
static bool m_instantiated;
LIBMTP_raw_device_t* m_devs;
int m_numDevs;
};
#endif /* CONNECTEDMTPDEVICES_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/MtpNodeMetadata.h | <gh_stars>0
/*
* MtpNoteMetadata.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MTPNODEMETADATA_H_
#define MTPNODEMETADATA_H_
#include "MtpDevice.h"
#include <vector>
class MtpNodeMetadata
{
public:
MtpFileInfo self;
std::vector<MtpFileInfo> children;
std::vector<MtpStorageInfo> storages;
};
#endif /* MTPNODEMETADATA_H_ */
|
akshaykumar23399/DOTS | jmtpfs/src/jmtpfs-0.5/src/MtpFilesystemPath.h | /*
* MtpFilesystemPath.h
*
* Author: <NAME>
*
* This software is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 3 as published by the Free Software Foundation.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02111-1301, USA.
* <EMAIL>
*/
#ifndef MTPFILESYSTEMPATH_H_
#define MTPFILESYSTEMPATH_H_
#include <string>
class FilesystemPath
{
public:
FilesystemPath(const char* path);
std::string Head() const;
std::string Tail() const;
FilesystemPath Body() const;
FilesystemPath AllButTail() const;
bool Empty() const;
std::string str() const;
protected:
std::string m_path;
};
#endif /* MTPFILESYSTEMPATH_H_ */
|
KittyMac/pony.apple | libapple/libapple-osx/libapple_osx.h | //
// libapple_osx.h
// libapple-osx
//
// Created by <NAME> on 5/4/20.
// Copyright © 2020 <NAME>. All rights reserved.
//
#import <Foundation/Foundation.h>
//! Project version number for libapple_osx.
FOUNDATION_EXPORT double libapple_osxVersionNumber;
//! Project version string for libapple_osx.
FOUNDATION_EXPORT const unsigned char libapple_osxVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <libapple_osx/PublicHeader.h>
|
KittyMac/pony.apple | libapple/libapple/libapple.h | <reponame>KittyMac/pony.apple<gh_stars>0
//
// libapple.h
// libapple
//
// Created by <NAME> on 5/4/20.
// Copyright © 2020 <NAME>. All rights reserved.
//
#import <Foundation/Foundation.h>
//! Project version number for libapple.
FOUNDATION_EXPORT double libappleVersionNumber;
//! Project version string for libapple.
FOUNDATION_EXPORT const unsigned char libappleVersionString[];
// In this header, you should import all the public headers of your framework using statements like #import <libapple/PublicHeader.h>
|
KittyMac/pony.apple | libapple/src/libapple.h | //
// libapple.h
// libapple
//
// Created by <NAME> on 4/25/20.
// Copyright © 2020 <NAME>. All rights reserved.
//
#import <Foundation/Foundation.h>
#include "atomics.h"
#include "pony.h"
void pony_retain_actor(pony_ctx_t * ctx, void * obj);
void pony_release_actor(pony_ctx_t * ctx, void * obj);
|
colinw7/CTabWebPage | src/CTabWebPage.h | #ifndef CTabWebPage_H
#define CTabWebPage_H
#include <string>
#include <vector>
#include <map>
class CFile;
class CTabWebPage {
public:
enum class Type {
NONE,
TAB,
ACCORDION,
IMAGE
};
enum class Orientation {
HORIZONTAL,
VERTICAL
};
public:
CTabWebPage();
const Orientation &orientation() const { return orientation_; }
void setOrientation(const Orientation &o) { orientation_ = o; }
const std::string &title() const { return title_; }
void setTitle(const std::string &s) { title_ = s; }
bool isEmbed() const { return embed_; }
void setEmbed(bool b) { embed_ = b; }
bool isFullPage() const { return fullpage_; }
void setFullPage(bool b) { fullpage_ = b; }
void addFile(CFile &file);
void generate();
private:
using Lines = std::vector<std::string>;
struct TabData {
Type type { Type::TAB };
std::string name;
int id { -1 };
std::string desc;
std::string color { "white" };
Lines lines;
bool mouseOver { false };
TabData() = default;
explicit TabData(const std::string &name) :
name(name) {
}
};
using Tabs = std::vector<TabData *>;
struct TabGroupData {
Tabs tabs;
int id { -1 };
TabData *currentTab { nullptr };
};
using TabGroups = std::vector<TabGroupData *>;
enum class DocPart {
HEAD,
BODY_START,
BODY_END,
TAIL
};
struct TabFileData {
std::string tabTitle;
DocPart docPart { DocPart::BODY_START };
int skipN { 0 };
Lines startLines;
Lines endLines;
TabGroups tabGroups;
TabGroupData* currentTabGroup { nullptr };
};
using TabFiles = std::vector<TabFileData *>;
private:
void init();
void term();
void generateFile(TabFileData *fileData);
TabGroupData *addTabGroup(TabFileData *fileData);
TabData *addTab(TabGroupData *tabGroup, const std::string &tabName, Type tabType);
void addTypeCss(Type type);
void addTypeJS (Type type);
private:
using TypeCss = std::map<Type, bool>;
using TypeJS = std::map<Type, bool>;
using TypeCount = std::map<Type, int>;
Orientation orientation_ { Orientation::HORIZONTAL };
std::string title_;
bool embed_ { false };
bool fullpage_ { false };
TypeCss typeCss_;
TypeJS typeJS_;
TypeCount tabTypeCount_;
TabFiles tabFiles_;
TabFileData* currentFile_ { nullptr };
int tabCount_ { 0 };
int groupCount_ { 0 };
};
#endif
|
michalsvento/Digital-electronics_2 | Homeworks/Knightrider/Knightrider/main.c | <filename>Homeworks/Knightrider/Knightrider/main.c
/***********************************************************************
*
* Knightrider leds
* ATmega328P (Arduino Uno), 16 MHz, AVR 8-bit Toolchain 3.6.2
*
* Copyright (c) 2018-2020 <NAME>
* Dept. of Radio Electronics, Brno University of Technology, Czechia
* This work is licensed under the terms of the MIT license.
*
**********************************************************************/
/* Defines -----------------------------------------------------------*/
#define LED_1 PB1 // AVR pin where green LED is connected
#define LED_2 PB2
#define LED_3 PB3
#define LED_4 PB4
#define LED_5 PB5
#define BLINK_DELAY 250
#define BTN PD0
#ifndef F_CPU
#define F_CPU 16000000 // CPU frequency in Hz required for delay
#endif
/* Includes ----------------------------------------------------------*/
#include <util/delay.h> // Functions for busy-wait delay loops
#include <avr/io.h> // AVR device-specific IO definitions
#include <avr/interrupt.h>
#include "gpio.h"
#include "timer.h"
/*
* Main function where the program execution begins. Toggle two LEDs
* when a push button is pressed.
*/
int main(void)
{
/* GREEN LED */
// Set pin as output in Data Direction Register...
//DDRB = DDRB | (1<<LED_1) | (1<<LED_2)| (1<<LED_3) | (1<<LED_4) | (1<<LED_5) ;
GPIO_config_output(&DDRB,LED_1);
GPIO_config_output(&DDRB,LED_2);
GPIO_config_output(&DDRB,LED_3);
GPIO_config_output(&DDRB,LED_4);
GPIO_config_output(&DDRB,LED_5);
// ...and turn LED off in Data Register
//PORTB = PORTB & ~(1<<LED_1) ;
GPIO_write_low(&PORTB,LED_1);
GPIO_config_input_pullup(&DDRD,BTN);
/* Configuration of 16-bit Timer/Counter1
* Set prescaler and enable overflow interrupt */
TIM1_overflow_1s();
TIM1_overflow_interrupt_enable();
/* Configuration of 8-bit Timer/Counter2 *
Set prescaler and enable overflow interrupt */
TIM2_overflow_1ms();
TIM2_overflow_interrupt_enable();
sei();
// Infinite loop
while (1)
{
if(!GPIO_read(&PIND,BTN))
{
ISR(TIMER1_OVF_vect)
{
GPIO_toggle(&PORTB,LED_1);
//}
//ISR(TIMER1_OVF_vect){
GPIO_toggle(&PORTB,LED_1);
GPIO_toggle(&PORTB,LED_2);
//}
//ISR(TIMER1_OVF_vect){
GPIO_toggle(&PORTB,LED_2);
GPIO_toggle(&PORTB,LED_3);
//ISR(TIMER1_OVF_vect){
GPIO_toggle(&PORTB,LED_3);
GPIO_toggle(&PORTB,LED_4);
//ISR(TIMER1_OVF_vect){
GPIO_toggle(&PORTB,LED_4);
GPIO_toggle(&PORTB,LED_5);
GPIO_toggle(&PORTB,LED_5);
GPIO_toggle(&PORTB,LED_4);
GPIO_toggle(&PORTB,LED_4);
GPIO_toggle(&PORTB,LED_3);
GPIO_toggle(&PORTB,LED_3);
GPIO_toggle(&PORTB,LED_2);
GPIO_toggle(&PORTB,LED_2);
}
}
else
ISR(TIMER2_OVF_vect){
GPIO_toggle(&PORTB,LED_1);
//}
//ISR(TIMER1_OVF_vect){
GPIO_toggle(&PORTB,LED_1);
GPIO_toggle(&PORTB,LED_2);
//}
//ISR(TIMER1_OVF_vect){
GPIO_toggle(&PORTB,LED_2);
GPIO_toggle(&PORTB,LED_3);
//ISR(TIMER1_OVF_vect){
GPIO_toggle(&PORTB,LED_3);
GPIO_toggle(&PORTB,LED_4);
//ISR(TIMER1_OVF_vect){
GPIO_toggle(&PORTB,LED_4);
GPIO_toggle(&PORTB,LED_5);
GPIO_toggle(&PORTB,LED_5);
GPIO_toggle(&PORTB,LED_4);
GPIO_toggle(&PORTB,LED_4);
GPIO_toggle(&PORTB,LED_3);
GPIO_toggle(&PORTB,LED_3);
GPIO_toggle(&PORTB,LED_2);
GPIO_toggle(&PORTB,LED_2);
}
return 0;
// Will never reach this
}
|
michalsvento/Digital-electronics_2 | Homeworks/EXAMPLES/PWM/PWM/main.c | <reponame>michalsvento/Digital-electronics_2
/*
* PWM.c
*
* Created: 18. 10. 2020 21:40:52
* Author : Michal
*/
#define LED_D1 PB2
#include <avr/io.h>
#include <avr/interrupt.h>
#include "timer.h"
#include "gpio.h"
int main(void)
{
GPIO_config_output(&DDRB,LED_D1);
GPIO_write_low(&PORTB, LED_D1);
TCCR1A |= (1<<COM1B1); TCCR1A &= !(1<<COM1B0); //noniverting mode
TCCR1A |= (1<<WGM12 | 1<<WGM11 | 1<<WGM10); TCCR1A &= !(1 << WGM13);
TCCR1B |= (1<<WGM12 | 1<<WGM11 | 1<<WGM10); TCCR1B &= !(1 << WGM13);
TIM1_overflow_33ms();
OCR1B = 0x01FF;
TIMSK1 |= (1 << OCIE1B);
sei();
/* Replace with your application code */
while (1)
{
}
}
ISR(TIMER1_COMPB_vect){
GPIO_toggle(&PORTB,LED_D1);
if(OCR1B <= 0x3FF){
OCR1B = OCR1B + 1;
}
OCR1B = 0x01FF;
}
|
michalsvento/Digital-electronics_2 | Labs/07-uart/07-uart/07-uart/main.c | /***********************************************************************
*
* Analog-to-digital conversion with displaying result on LCD and
* transmitting via UART.
* ATmega328P (Arduino Uno), 16 MHz, AVR 8-bit Toolchain 3.6.2
*
* Copyright (c) 2018-2020 <NAME>
* Dept. of Radio Electronics, Brno University of Technology, Czechia
* This work is licensed under the terms of the MIT license.
*
**********************************************************************/
/* Includes ----------------------------------------------------------*/
#include <avr/io.h> // AVR device-specific IO definitions
#include <avr/interrupt.h> // Interrupts standard C library for AVR-GCC
#include "timer.h" // Timer library for AVR-GCC
#include "lcd.h" // Peter Fleury's LCD library
#include <stdlib.h> // C library. Needed for conversion function
#include "uart.h" // Peter Fleury's UART library
#ifndef F_CPU
#define F_CPU 16000000
#endif
/* Function definitions ----------------------------------------------*/
/**
* Main function where the program execution begins. Use Timer/Counter1
* and start ADC conversion four times per second. Send value to LCD
* and UART.
*/
int main(void)
{
//
// Initialize LCD display
lcd_init(LCD_DISP_ON);
lcd_gotoxy(1, 0);
lcd_puts("value:");
lcd_gotoxy(3, 1);
lcd_puts("key:");
// Configure ADC to convert PC0[A0] analog value
// Set ADC reference to AVcc
ADMUX |= (1<<REFS0);
ADMUX &= ~(1<<REFS1);
// Set input channel to ADC0
ADMUX &= ~((1<<MUX0)|(1<<MUX1)|(1<<MUX2)|(1<<MUX3));
// Enable ADC module
ADCSRA |= (1<<ADEN);
// Enable conversion complete interrupt
ADCSRA |= (1<<ADIE);
// Set clock prescaler to 128
ADCSRA |= ((1<ADPS2)|(1<ADPS1)|(1<ADPS0));
// Configure 16-bit Timer/Counter1 to start ADC conversion
// Enable interrupt and set the overflow prescaler to 262 ms
TIM1_overflow_262ms();
TIM1_overflow_interrupt_enable();
// Initialize UART to asynchronous, 8N1, 9600
uart_init(UART_BAUD_SELECT(9600,F_CPU));
// Enables interrupts by setting the global interrupt mask
sei();
// Infinite loop
while (1)
{
/* Empty loop. All subsequent operations are performed exclusively
* inside interrupt service routines ISRs */
}
// Will never reach this
return 0;
}
/* Interrupt service routines ----------------------------------------*/
/**
* ISR starts when Timer/Counter1 overflows. Use single conversion mode
* and start conversion four times per second.
*/
ISR(TIMER1_OVF_vect)
{
// Start ADC conversion
ADCSRA |= (1<< ADSC);
}
/* -------------------------------------------------------------------*/
/**
* ISR starts when ADC completes the conversion. Display value on LCD
* and send it to UART.
*/
ISR(ADC_vect)
{
uint16_t value=0;
static uint16_t compare=0;
uint8_t parity=0;
char lcd_string[4];
value=ADC;
if(compare!=value) //makes this process when ADC changes value
{
//Show value in decimal
itoa(value,lcd_string,10);
lcd_gotoxy(8,0);
lcd_puts(" ");
lcd_gotoxy(8,0);
lcd_puts(lcd_string);
// Display parity bit and send UART only for Buttons
//uart DECIMAL
uart_puts("ADC decimal ");
uart_puts(lcd_string);
// odd parity
char lcd_binary [10];
for (uint8_t i=0; value !=0; i++)
{
lcd_binary[i]= value %2;
if(lcd_binary[i] == 1)
{
parity++;
}
value= value / 2;
}
lcd_gotoxy(15,1);
if (parity % 2)
{
uart_puts(" PARITY 1 ");
lcd_puts("1");
}
else
{
uart_puts(" PARITY 0 ");
lcd_puts("0");
}
value=ADC; // return orig. value, which was changed in cycle
// show value in hex
itoa(value,lcd_string,16);
lcd_gotoxy(13,0);
lcd_puts(" ");
lcd_gotoxy(13,0);
lcd_puts(lcd_string);
// Display the name of key on LCD & UART
lcd_gotoxy(8,1);
lcd_puts(" ");
// none
if(value >= 1016)
{
lcd_gotoxy(8,1);
lcd_puts("none");
uart_puts("\n");
}
// RIGHT
if(value <=2 )
{
lcd_gotoxy(8,1);
lcd_puts("RIGHT");
uart_puts("RIGHT");
uart_puts("\n");
}
// UP
if(value >= 99 && value <=103 )
{
lcd_gotoxy(8,1);
lcd_puts("UP");
uart_puts("UP");
uart_puts("\n");
}
// DOWN
if(value >= 244 && value <=248 )
{
lcd_gotoxy(8,1);
lcd_puts("DOWN");
uart_puts("DOWN");
uart_puts("\n");
}
// LEFT
if(value >= 401 && value <=405 )
{
lcd_gotoxy(8,1);
lcd_puts("LEFT");
uart_puts("LEFT");
uart_puts("\n");
}
//SELECT
if (value >= 648 && value<=655)
{
lcd_gotoxy(8,1);
lcd_puts("SELECT");
uart_puts("SELECT");
uart_puts("\n");
}
compare=value; //
}
}
|
michalsvento/Digital-electronics_2 | Homeworks/EXAMPLES/05-segment/05-segment/main.c | /*
* 05-segment.c
*
* Created: 21. 10. 2020 11:12:15
* Author : Michal
*/
#include <avr/io.h>
int main(void)
{
/* Replace with your application code */
while (1)
{
}
}
|
michalsvento/Digital-electronics_2 | Homeworks/Snake2/Snejk/Snejk/main.c | <gh_stars>0
/***********************************************************************
*
* Decimal counter with 7-segment output.
* ATmega328P (Arduino Uno), 16 MHz, AVR 8-bit Toolchain 3.6.2
*
* Copyright (c) 2018-2020 <NAME>
* Dept. of Radio Electronics, Brno University of Technology, Czechia
* This work is licensed under the terms of the MIT license.
*
**********************************************************************/
/* Includes ----------------------------------------------------------*/
#include <avr/io.h> // AVR device-specific IO definitions
#include <avr/interrupt.h> // Interrupts standard C library for AVR-GCC
#include "timer.h" // Timer library for AVR-GCC
#include "segment.h" // Seven-segment display library for AVR-GCC
/* Variables ---------------------------------------------------------*/
static uint8_t led=0;
static uint8_t pos=0;
/* Function definitions ----------------------------------------------*/
/**
* Main function where the program execution begins. Display decimal
* counter values on SSD (Seven-segment display) when 16-bit
* Timer/Counter1 overflows.
*/
int main(void)
{
// Configure SSD signals
SEG_init();
/* Configure 16-bit Timer/Counter1
* Set prescaler and enable overflow interrupt */
TIM1_overflow_33ms();
TIM1_overflow_interrupt_enable();
// Enables interrupts by setting the global interrupt mask
sei();
// Infinite loop
while (1)
{
/* Empty loop. All subsequent operations are performed exclusively
* inside interrupt service routines ISRs */
}
// Will never reach this
return 0;
}
/* Interrupt service routines ----------------------------------------*/
ISR(TIMER1_OVF_vect)
{
SEG_update_shift_regs(led,pos);
static uint8_t Ndisplays=4; //Number of displays
++led;
if(led<=4) //First part from SEG A-SEG D
{
if(led==4) // last segment, position 0
{
if(pos<(Ndisplays-1))
{
pos++; // move to position of Ndisplays
led--; // SegmentD stays until condition true
}
}
}
if( (led<=7) && (led>4 ))
{
if(led==7)
{
if(pos>0) //move to Seg A , position 0
{
pos--;
led--;
}
else
{
led=1; // Start with SEG B and repeat the cycle
}
}
}
}
|
michalsvento/Digital-electronics_2 | Labs/06-lcd/06-lcd/06-lcd/main.c | <reponame>michalsvento/Digital-electronics_2<filename>Labs/06-lcd/06-lcd/06-lcd/main.c<gh_stars>0
/***********************************************************************
*
* Stopwatch with LCD display output.
* ATmega328P (Arduino Uno), 16 MHz, AVR 8-bit Toolchain 3.6.2
*
* Copyright (c) 2017-2020 <NAME>
* Dept. of Radio Electronics, Brno University of Technology, Czechia
* This work is licensed under the terms of the MIT license.
*
**********************************************************************/
/* Includes ----------------------------------------------------------*/
#include <avr/io.h> // AVR device-specific IO definitions
#include <avr/interrupt.h> // Interrupts standard C library for AVR-GCC
#include "timer.h" // Timer library for AVR-GCC
#include "lcd.h" // Peter Fleury's LCD library
#include <stdlib.h> // C library. Needed for conversion function
uint8_t customChar[48] = {
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b10000,
0b10000,
0b10000,
0b10000,
0b10000,
0b10000,
0b10000,
0b10000,
0b11000,
0b11000,
0b11000,
0b11000,
0b11000,
0b11000,
0b11000,
0b11000,
0b11100,
0b11100,
0b11100,
0b11100,
0b11100,
0b11100,
0b11100,
0b11100,
0b11110,
0b11110,
0b11110,
0b11110,
0b11110,
0b11110,
0b11110,
0b11110,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111,
0b11111
};
/* Function definitions ----------------------------------------------*/
/**
* Main function where the program execution begins. Update stopwatch
* value on LCD display when 8-bit Timer/Counter2 overflows.
*/
int main(void)
{
// Initialize LCD display
lcd_init(LCD_DISP_ON);
// Set pointer to beginning of CGRAM memory
lcd_command(1 << LCD_CGRAM);
for (uint8_t i = 0; i < 48; i++)
{
// Store all new chars to memory line by line
lcd_data(customChar[i]);
}
// Set DDRAM address
lcd_command(1 << LCD_DDRAM);
// Display first custom character
// Put string(s) at LCD display
lcd_gotoxy(1, 0);
lcd_puts("00:00.0");
// Configure 8-bit Timer/Counter2 for Stopwatch
// Set prescaler and enable overflow interrupt every 16 ms
TIM2_overflow_16ms();
TIM2_overflow_interrupt_enable();
// Configure 8-bit Timer/Counter1 for Stopwatch
// Set prescaler and enable overflow interrupt every 1 s
TIM1_overflow_262ms();
TIM1_overflow_interrupt_enable();
// Configure 8-bit Timer/Counter0 for Stopwatch
// Set prescaler and enable overflow interrupt every 16 ms
TIM0_overflow_4ms();
TIM0_overflow_interrupt_enable();
// Enables interrupts by setting the global interrupt mask
sei();
// Infinite loop
while (1)
{
/* Empty loop. All subsequent operations are performed exclusively
* inside interrupt service routines ISRs */
}
// Will never reach this
return 0;
}
/* Interrupt service routines ----------------------------------------*/
/**
* ISR starts when Timer/Counter2 overflows. Update the stopwatch on
* LCD display every sixth overflow, ie approximately every 100 ms
* (6 x 16 ms = 100 ms).
*/
ISR(TIMER2_OVF_vect)
{
static uint8_t number_of_overflows = 0;
static uint8_t tens = 0; // Tenths of a second
static uint8_t secs = 0; // Seconds
static uint8_t minutes = 0; // minutes
static uint16_t secsqr = 0; // variable for square of seconds
char lcd_string[2] = " "; // String for converting numbers by itoa()
char lcd_square[4]= " ";
number_of_overflows++;
if (number_of_overflows >= 6)
{
// Do this every 6 x 16 ms = 100 ms
number_of_overflows = 0;
tens++;
if (tens> 9)
{
tens=0;
secs++;
if (secs>59)
{
secs=0;
minutes++;
if (minutes>59)
{
minutes=0;
}
}
}
itoa(tens, lcd_string,10);
lcd_gotoxy(7,0);
lcd_puts(lcd_string);
itoa(secs, lcd_string,10);
if(secs<10) //single digit or two digits
{
lcd_gotoxy(5,0);
}
else
{
lcd_gotoxy(4,0);
}
lcd_puts(lcd_string);
itoa(minutes, lcd_string,10);
if(minutes<10)
{
lcd_gotoxy(2,0);
}
else
{
lcd_gotoxy(1,0);
}
lcd_puts(lcd_string);
// counts the square of secs and show from pos 11,0
secsqr = secs*secs;
if (secs==0) // for reset on the positions 12-14
{
lcd_gotoxy(11,0);
lcd_puts("0 ");
}
else
{
itoa(secsqr,lcd_square,10);
lcd_gotoxy(11,0);
lcd_puts(lcd_square);
}
}
}
/*--------------------------------------------------------------------*/
/**
* ISR starts when Timer/Counter1 overflows. Move one letter left every
* 1 s.
*/
ISR(TIMER1_OVF_vect)
{
static uint8_t i=0;
uint8_t running_text[32]= " I like Digital electronics! ";
char lcd_shown[5]= " ";
lcd_gotoxy(11,1);
if(i< (sizeof(running_text)-4))
{
lcd_shown[0] = running_text[i];
lcd_shown[1] = running_text[i+1];
lcd_shown[2] = running_text[i+2];
lcd_shown[3] = running_text[i+3];
lcd_shown[4] = running_text[i+4];
lcd_puts(lcd_shown);
i++;
}
if(i==(sizeof(running_text)-1))
{
lcd_shown[0] = running_text[i];
lcd_shown[1] = running_text[0];
lcd_shown[2] = running_text[1];
lcd_shown[3] = running_text[2];
lcd_shown[4] = running_text[3];
lcd_puts(lcd_shown);
i=0;
}
if(i==(sizeof(running_text)-2))
{
lcd_shown[0] = running_text[i];
lcd_shown[1] = running_text[i+1];
lcd_shown[2] = running_text[0];
lcd_shown[3] = running_text[1];
lcd_shown[4] = running_text[2];
lcd_puts(lcd_shown);
i++;
}
if(i==(sizeof(running_text)-3))
{
lcd_shown[0] = running_text[i];
lcd_shown[1] = running_text[i+1];
lcd_shown[2] = running_text[i+2];
lcd_shown[3] = running_text[0];
lcd_shown[4] = running_text[1];
lcd_puts(lcd_shown);
i++;
}
if(i==(sizeof(running_text)-4))
{
lcd_shown[0] = running_text[i];
lcd_shown[1] = running_text[i+1];
lcd_shown[2] = running_text[i+2];
lcd_shown[3] = running_text[i+3];
lcd_shown[4] = running_text[0];
lcd_puts(lcd_shown);
i++;
}
}
/**
* ISR starts when Timer/Counter0 overflows. Move every 16ms
* one user-defined character. Resets the bar when
* when lcd_gotoxy(10,1) & symbol 0x05 is reached
* user-defined character from 0 - 5
* " "| " "|| " "||| " "|||| " "|||||"
*/
ISR(TIMER0_OVF_vect)
{
static uint8_t symbol = 0;
static uint8_t position = 0;
lcd_gotoxy(1 + position, 1);
lcd_putc(symbol);
symbol++;
if(symbol>5)
{
symbol=0;
position++;
if (position>9)
{
lcd_gotoxy(1,1);
lcd_puts(" "); // 10 spaces for reset
position=0;
}
}
}
|
michalsvento/Digital-electronics_2 | Homeworks/Snake/Snake/Snake/segment.h | #ifndef SEGMENT_H
#define SEGMENT_H
/***********************************************************************
*
* Seven-segment display library for AVR-GCC.
* ATmega328P (Arduino Uno), 16 MHz, AVR 8-bit Toolchain 3.6.2
*
* Copyright (c) 2019-2020 <NAME>
* Dept. of Radio Electronics, Brno University of Technology, Czechia
* This work is licensed under the terms of the MIT license.
*
**********************************************************************/
/**
* @file segment.h
* @brief Seven-segment display library for AVR-GCC.
*
* @details
* The library contains functions for controlling the seven-segment
* display (SSD) using two shift registers 74HC595.
*
* @copyright (c) 2019-2020 <NAME>
* Dept. of Radio Electronics, Brno University of Technology, Czechia
* This work is licensed under the terms of the MIT license.
*/
/* Includes ----------------------------------------------------------*/
#include <avr/io.h>
/* Defines -----------------------------------------------------------*/
/**
* @brief Defines the interface of SSD.
* @note Connection is based on Multi-function shield.
*/
#define SEGMENT_LATCH PD4
#define SEGMENT_CLK PD7
#define SEGMENT_DATA PB0
/* Function prototypes -----------------------------------------------*/
/**
* @brief Configure SSD signals LATCH, CLK, and DATA as output.
*/
void SEG_init(void);
/**
* @brief Display segments at one position of the SSD.
* @param segments - Segments to be displayed (abcdefgDP, active low)
* @param position - Position of the display where the segments is to
* be displayed (p3 p2 p1 p0 ...., active high)
* @note Two shift registers are connected in series, ie 16 bits are
* transmitted.
*/
void SEG_update_shift_regs(uint8_t snake, uint8_t position);
/* SEG_clear */
/* SEG_clk_2us */
#endif |
michalsvento/Digital-electronics_2 | Labs/05-segments/05-segment/05-segment/main.c | /***********************************************************************
*
* Decimal counter with 7-segment output.
* ATmega328P (Arduino Uno), 16 MHz, AVR 8-bit Toolchain 3.6.2
*
* Copyright (c) 2018-2020 <NAME>
* Dept. of Radio Electronics, Brno University of Technology, Czechia
* This work is licensed under the terms of the MIT license.
*
**********************************************************************/
/* Defines -----------------------------------------------------------*/
#define BTN PB1
#define BTNCLR PD0
#ifndef F_CPU
#define F_CPU 16000000
#endif
/* Includes ----------------------------------------------------------*/
#include <avr/io.h> // AVR device-specific IO definitions
#include <avr/interrupt.h> // Interrupts standard C library for AVR-GCC
#include <util/delay.h>
#include "timer.h" // Timer library for AVR-GCC
#include "segment.h" // Seven-segment display library for AVR-GCC
#include "gpio.h"
static uint8_t position = 0;
static uint8_t units = 0;
static uint8_t decimals = 0;
static uint8_t seconds =0;
static uint8_t tens = 0;
/* Function definitions ----------------------------------------------*/
/**
* Main function where the program execution begins. Display decimal
* counter values on SSD (Seven-segment display) when 16-bit
* Timer/Counter1 overflows.
*/
int main(void)
{
// Configure SSD signals
SEG_init();
// Configure PB0 as input pull up & for Pin interrupt
GPIO_config_input_pullup(&DDRB,BTN);
PCICR = PCICR | (1 << PCIE0);
PCMSK0 = PCMSK0 |(1 << PCINT1);
GPIO_config_input_pullup(&DDRD,BTNCLR);
PCICR |= (1<< PCIE2);
PCMSK2 |= (1<< PCINT16);
/* Configure 8-bit Timer/Counter0
* Set prescaler and enable overflow interrupt */
TIM0_overflow_16ms();
TIM0_overflow_interrupt_enable();
/* Configure 16-bit Timer/Counter1
* Set prescaler and enable overflow interrupt */
TIM1_overflow_1s();
TIM1_overflow_interrupt_enable();
// Enables interrupts by setting the global interrupt mask
sei();
// Infinite loop
while (1)
{
/* Empty loop. All subsequent operations are performed exclusively
* inside interrupt service routines ISRs */
}
// Will never reach this
return 0;
}
/* Interrupt service routines ----------------------------------------*/
/**
* ISR starts when is change on PB1
*/
ISR(PCINT0_vect)
{
if(!GPIO_read(&PINB,BTN)){
units = 0;
decimals = 0;
seconds =0;
tens = 0;
}
}
ISR(PCINT2_vect)
{
if(!GPIO_read(&DDRD,BTNCLR))
{
SEG_clear();
}
}
/**
* ISR starts when Timer/Counter0 overflows. Display value on SSD
*/
ISR(TIMER0_OVF_vect){
switch(position){
case 0:
SEG_update_shift_regs(units,0,1);
position=1;
break;
case 1:
SEG_update_shift_regs(decimals,1,1);
position=2;
break;
case 2:
SEG_update_shift_regs(seconds,2,0);
position=3;
break;
case 3:
SEG_update_shift_regs(tens,3,1);
position=0;
break;
default:
SEG_update_shift_regs(units,0,1);
position=0;
}
}
/* ISR starts when Timer/Counter1 overflows.Increment decimal counter value
*/
ISR(TIMER1_OVF_vect){
units++;
if(units>9)
{
units=0;
decimals++;
if(decimals>5)
{
decimals=0;
seconds++;
if(seconds> 9)
{
seconds=0;
tens++;
if(tens>5)
{
tens=0;
}
}
}
}
}
|
shsanek/HRLog | HRLoger/HRLoger/HRViewerViewController.h | //
// ViewController.h
// HRLogViewer
//
// Created by <NAME> on 24/02/16.
// Copyright © 2016 <NAME>. All rights reserved.
//
#import <Cocoa/Cocoa.h>
#import "HRKeyDefine.h"
@class HRLogbookManager;
@class HRLogbook;
HRIntefaceKey(kHRViewerViewControllerOpenNotification);
@interface HRViewerViewController : NSViewController
@property (nonatomic,strong) HRLogbook* logbook;
@property (nonatomic,strong) HRLogbookManager* logbookManger;
@end
|
shsanek/HRLog | HRLoger/Pods/HRSocket/HRSocket/HRSocket.h | //
// HRSocket.h
// HRLog
//
// Created by <NAME> on 28/02/16.
// Copyright © 2016 <NAME>. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "HRQueue.h"
@class HRSocket;
@protocol HRSocketDelegate <NSObject>
- (void) contentSocket:(HRSocket*) socket;
- (void) socket:(HRSocket*) socket didRecivData:(NSData*) data;
- (void) discontentSocket:(HRSocket*) socket;
@end
@interface HRSocket : NSObject
@property (nonatomic,weak) id<HRSocketDelegate> delegate;
@property (nonatomic,assign,readonly) int socket;
@property (nonatomic,strong,readonly) HRQueue* writeQueue;
@property (nonatomic,strong,readonly) HRQueue* readQueue;
- (instancetype) initWithSocket:(int) socket readQueue:(HRQueue*) readQueue writeQueue:(HRQueue*) writeQueue;
- (instancetype) initWithReadQueue:(HRQueue*) readQueue writeQueue:(HRQueue*) writeQueue;
- (void) sendData:(NSData*) data completionBloack:(void (^)(BOOL isFinish)) completionBloack;
- (void) recivSoketCompletionBlock:(void (^)(NSData* data)) completionBlock;
- (void) close;
@end
|
shsanek/HRLog | HRLog/logs/HRLog.h | //
// HRLog.h
// Pods
//
// Created by <NAME> on 21/02/2017.
//
//
#ifndef HRLog_h
#define HRLog_h
#define HRPositionString [NSString stringWithFormat:@"<FILE '%s', ROW %d>",__FILE__,__LINE__]
#define HRCheckErrorLog(error) if (error) {\
HRLog(@"<ERROR IN %@:\n%@",HRPositionString,error);\
\
};
void HRLog(NSString* format,...);
void HRErrorLog(NSError * error,NSString* format,...);
void HRSenderErrorLog(id sender,NSError * error,NSString* format,...);
void HRBeginLog(NSString* format,...);
void HREndLog();
#endif /* HRLog_h */
|
shsanek/HRLog | HRLoger/HRLoger/AppDelegate.h | //
// AppDelegate.h
// HRLoger
//
// Created by <NAME> on 21/02/2017.
// Copyright © 2017 hr. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
|
shsanek/HRLog | HRLog/logs/HRLogViewController.h | //
// HRLogView.h
// HRLoger
//
// Created by <NAME> on 21/02/2017.
// Copyright © 2017 hr. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface HRLogViewController : UIViewController
+ (void) setAppName:(NSString*) appName withEmail:(NSString*) email;
+ (void) addGestureShowInWindow:(UIWindow*) window;
@end
|
shsanek/HRLog | HRLog/logs/HRLoger.h | <filename>HRLog/logs/HRLoger.h
//
// HRLoger.h
// HRLoger
//
// Created by <NAME> on 21/02/2017.
// Copyright © 2017 <NAME>. All rights reserved.
//
#import <Foundation/Foundation.h>
#import "HRLog.h"
@class HRLogSession;
@protocol HRLogSessionDelegate <NSObject>
@optional
- (void) logSession:(HRLogSession*) session appendSting:(NSString*) text;
@end
@interface HRLogSession : NSObject<NSCoding>
@property (nonatomic, weak) id<HRLogSessionDelegate> delegate;
@property (nonatomic, strong, readonly) NSDate* date;
@property (nonatomic, strong, readonly) NSString* path;
@property (nonatomic, weak, readonly) NSData* log;
@property (nonatomic, strong, readonly) NSString* localPath;
@end
@interface HRLoger : NSObject
+ (instancetype) loger;
- (void) startSesstion;////CALL FOR START SESSION IN applicationDidFinishLaunching
@property (nonatomic, assign) BOOL notAddDateInLog;
@property (nonatomic, strong) NSString* startSymbol;
@property (nonatomic, assign) NSInteger numberOfSessionForSave;//default 10
@property (nonatomic, assign) BOOL printInNSLog;//default YES
@property (nonatomic, assign) BOOL addNewRow;//default YES;
@property (nonatomic, assign) BOOL replaceDuplicatesMessage;//id YES repetitive massage
@property (nonatomic, strong, readonly) NSArray<HRLogSession*>* lastSessions;
@property (nonatomic, strong, readonly) HRLogSession* currentSession;
@end
|
smokey-edgy/DayZ-ModStarter | DayZModStarter/5_Mission/server.c | modded class MissionServer
{
void MissionServer()
{
/* This message will appear in the server's script.log
and indicates that the mod was loaded on the server side */
Print("DayZModStarter loaded!");
}
}
|
smokey-edgy/DayZ-ModStarter | DayZModStarter/5_Mission/client.c | <reponame>smokey-edgy/DayZ-ModStarter
modded class MissionGameplay
{
void MissionGameplay()
{
}
override void TickScheduler(float timeslice)
{
/* This code runs on the client and should show a system message saying 'Tick'.
This will prove your client side code is running properly. */
GetGame().ChatPlayer(1, "Tick");
}
}
|
ludwick/pebble-kexp-now-playing | src/kexp_now_playing_main.c | /*
* Copyright (C) 2015, <NAME>
* Licensed under the terms of the MIT License.
*/
#include <pebble.h>
static Window *window;
static TextLayer *title_text_layer;
static ScrollLayer *current_info_scroll_layer;
static TextLayer *current_info_text_layer;
static GRect bounds;
static char current_info[255] = "--\n--\n--";
static void log_rect(char* label, GRect r) {
APP_LOG(APP_LOG_LEVEL_ERROR, "%s bounds: origin: [%d, %d], size: [%d, %d]\n", label, r.origin.x,r.origin.y,r.size.w, r.size.h);
}
static void display_current() {
text_layer_set_text(current_info_text_layer, current_info);
GSize max_size = text_layer_get_content_size(current_info_text_layer);
//text_layer_set_size(current_info_text_layer, max_size);
scroll_layer_set_content_size(current_info_scroll_layer, GSize(bounds.size.w, max_size.h + 4));
}
#define KEY_SONG_INFO 0
static void inbox_received_callback(DictionaryIterator *iterator, void *context) {
// Read first item
Tuple *t = dict_read_first(iterator);
// For all items
while(t != NULL) {
// Which key was received?
switch(t->key) {
case KEY_SONG_INFO:
snprintf(current_info, sizeof(current_info), "%s", t->value->cstring);
break;
default:
APP_LOG(APP_LOG_LEVEL_ERROR, "Key %d not recognized!", (int)t->key);
break;
}
// Look for next item
t = dict_read_next(iterator);
}
display_current();
}
static void trigger_update() {
DictionaryIterator *iter;
app_message_outbox_begin(&iter);
// Add a key-value pair
dict_write_uint8(iter, 0, 0);
// Send the message!
app_message_outbox_send();
}
static void inbox_dropped_callback(AppMessageResult reason, void *context) {
APP_LOG(APP_LOG_LEVEL_ERROR, "Message dropped!");
}
static void outbox_failed_callback(DictionaryIterator *iterator, AppMessageResult reason, void *context) {
APP_LOG(APP_LOG_LEVEL_ERROR, "Outbox send failed!");
}
static void outbox_sent_callback(DictionaryIterator *iterator, void *context) {
APP_LOG(APP_LOG_LEVEL_INFO, "Outbox send success!");
}
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
trigger_update();
display_current();
}
static void click_config_provider(void *context) {
window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler);
}
static void window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window);
bounds = layer_get_bounds(window_layer);
int16_t box_w = bounds.size.w;
int16_t box_h = bounds.size.h;
log_rect("window", bounds);
const int16_t title_o_x = 5;
const int16_t title_o_y = 5;
const int16_t title_h = 30;
GRect title_box = (GRect) { .origin = {title_o_x, title_o_y}, .size = { box_w, title_h }};
log_rect("title", title_box);
title_text_layer = text_layer_create(title_box);
text_layer_set_text(title_text_layer, "KEXP Now Playing");
text_layer_set_text_alignment(title_text_layer, GTextAlignmentCenter);
text_layer_set_font(title_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
layer_add_child(window_layer, text_layer_get_layer(title_text_layer));
int16_t remaining_h = box_h - title_o_y - title_h;
const int16_t padding = 2;
GRect scroll_layer_box = (GRect) {
.origin = { 0, title_o_y + title_h + padding },
.size = { box_w, remaining_h}
};
log_rect("scroll layer box", scroll_layer_box );
current_info_scroll_layer = scroll_layer_create(scroll_layer_box);
scroll_layer_set_click_config_onto_window(current_info_scroll_layer, window);
layer_add_child(window_layer, scroll_layer_get_layer(current_info_scroll_layer));
scroll_layer_set_callbacks(current_info_scroll_layer, (ScrollLayerCallbacks) {
.click_config_provider = click_config_provider
}
);
GRect text_layer_box = (GRect) {
.origin = { 0, 0 },
.size = { box_w, scroll_layer_box.size.h*3 }
};
log_rect("text layer box", text_layer_box );
current_info_text_layer = text_layer_create(text_layer_box);
text_layer_set_text_alignment(current_info_text_layer, GTextAlignmentCenter);
text_layer_set_overflow_mode(current_info_text_layer, GTextOverflowModeTrailingEllipsis);
text_layer_set_font(current_info_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
scroll_layer_add_child(current_info_scroll_layer, text_layer_get_layer(current_info_text_layer));
scroll_layer_set_content_size(current_info_scroll_layer, text_layer_get_content_size(current_info_text_layer));
// JS on ready loads data, so this just displays
display_current();
}
static void window_unload(Window *window) {
text_layer_destroy(title_text_layer);
text_layer_destroy(current_info_text_layer);
scroll_layer_destroy(current_info_scroll_layer);
}
static void init(void) {
app_message_register_inbox_received(inbox_received_callback);
app_message_register_inbox_dropped(inbox_dropped_callback);
app_message_register_outbox_failed(outbox_failed_callback);
app_message_register_outbox_sent(outbox_sent_callback);
app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
window = window_create();
window_set_window_handlers(window, (WindowHandlers) {
.load = window_load,
.unload = window_unload,
});
const bool animated = true;
window_stack_push(window, animated);
}
static void deinit(void) {
window_destroy(window);
}
int main(void) {
init();
app_event_loop();
deinit();
}
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/ext/lpc11xx/cmsis/system_LPC11xx.h | /**************************************************************************//**
* $Id:: $
*
* @file system_LPC11xx.h
* @brief CMSIS Cortex-M0 Device Peripheral Access Layer Header File
* for the NXP LPC11xx Device Series
* @version V1.00
* @date 17. November 2009
*
* @note
* Copyright (C) 2009 ARM Limited. All rights reserved.
*
* @par
* ARM Limited (ARM) is supplying this software for use with Cortex-M
* processor based microcontrollers. This file can be freely distributed
* within development tools that are supporting such ARM based processors.
*
* @par
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*
******************************************************************************/
#ifndef __SYSTEM_LPC11xx_H
#define __SYSTEM_LPC11xx_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */
/**
* Initialize the system
*
* @param none
* @return none
*
* @brief Setup the microcontroller system.
* Initialize the System and update the SystemCoreClock variable.
*/
#define CONFIG_ENABLE_CMSIS_SYSTEMINIT 1
extern void SystemInit (void);
/**
* Update SystemCoreClock variable
*
* @param none
* @return none
*
* @brief Updates the SystemCoreClock with current core Clock
* retrieved from cpu registers.
*/
#define CONFIG_ENABLE_CMSIS_SYSTEMCORECLOCKUPDATE 1
//#define CONFIG_CMSIS_SET_SYSTEMCORECLOCK_DEFAULT 48000000
extern void SystemCoreClockUpdate (void);
/*
//-------- <<< Use Configuration Wizard in Context Menu >>> ------------------
*/
/*--------------------- Clock Configuration ----------------------------------
//
// <e> Clock Configuration
// <e1> System Clock Setup
// <e2> System Oscillator Enable
// <o3.1> Select System Oscillator Frequency Range
// <0=> 1 - 20 MHz
// <1=> 15 - 25 MHz
// </e2>
// <e4> Watchdog Oscillator Enable
// <o5.0..4> Select Divider for Fclkana
// <0=> 2 <1=> 4 <2=> 6 <3=> 8
// <4=> 10 <5=> 12 <6=> 14 <7=> 16
// <8=> 18 <9=> 20 <10=> 22 <11=> 24
// <12=> 26 <13=> 28 <14=> 30 <15=> 32
// <16=> 34 <17=> 36 <18=> 38 <19=> 40
// <20=> 42 <21=> 44 <22=> 46 <23=> 48
// <24=> 50 <25=> 52 <26=> 54 <27=> 56
// <28=> 58 <29=> 60 <30=> 62 <31=> 64
// <o5.5..8> Select Watchdog Oscillator Analog Frequency (Fclkana)
// <0=> Disabled
// <1=> 0.5 MHz
// <2=> 0.8 MHz
// <3=> 1.1 MHz
// <4=> 1.4 MHz
// <5=> 1.6 MHz
// <6=> 1.8 MHz
// <7=> 2.0 MHz
// <8=> 2.2 MHz
// <9=> 2.4 MHz
// <10=> 2.6 MHz
// <11=> 2.7 MHz
// <12=> 2.9 MHz
// <13=> 3.1 MHz
// <14=> 3.2 MHz
// <15=> 3.4 MHz
// </e4>
// <o6> Select Input Clock for sys_pllclkin (Register: SYSPLLCLKSEL)
// <0=> IRC Oscillator
// <1=> System Oscillator
// <2=> WDT Oscillator
// <3=> Invalid
// <e7> Use System PLL
// <i> F_pll = M * F_in
// <i> F_in must be in the range of 10 MHz to 25 MHz
// <o8.0..4> M: PLL Multiplier Selection
// <1-32><#-1>
// <o8.5..6> P: PLL Divider Selection
// <0=> 2
// <1=> 4
// <2=> 8
// <3=> 16
// <o8.7> DIRECT: Direct CCO Clock Output Enable
// <o8.8> BYPASS: PLL Bypass Enable
// </e7>
// <o9> Select Input Clock for Main clock (Register: MAINCLKSEL)
// <0=> IRC Oscillator
// <1=> Input Clock to System PLL
// <2=> WDT Oscillator
// <3=> System PLL Clock Out
// </e1>
// <o10.0..7> System AHB Divider <0-255>
// <i> 0 = is disabled
// <o11.0> SYS Clock Enable
// <o11.1> ROM Clock Enable
// <o11.2> RAM Clock Enable
// <o11.3> FLASHREG Flash Register Interface Clock Enable
// <o11.4> FLASHARRAY Flash Array Access Clock Enable
// <o11.5> I2C Clock Enable
// <o11.6> GPIO Clock Enable
// <o11.7> CT16B0 Clock Enable
// <o11.8> CT16B1 Clock Enable
// <o11.9> CT32B0 Clock Enable
// <o11.10> CT32B1 Clock Enable
// <o11.11> SSP0 Clock Enable
// <o11.12> UART Clock Enable
// <o11.13> ADC Clock Enable
// <o11.15> WDT Clock Enable
// <o11.16> IOCON Clock Enable
// <o11.18> SSP1 Clock Enable
//
// <o12.0..7> SSP0 Clock Divider <0-255>
// <i> 0 = is disabled
// <o13.0..7> UART Clock Divider <0-255>
// <i> 0 = is disabled
// <o14.0..7> SSP1 Clock Divider <0-255>
// <i> 0 = is disabled
// </e>
*/
#define CLOCK_SETUP 1
#define SYSCLK_SETUP 1
#define SYSOSC_SETUP 1
#define SYSOSCCTRL_Val 0x00000000
#define WDTOSC_SETUP 0
#define WDTOSCCTRL_Val 0x000000A0
#define SYSPLLCLKSEL_Val 0x00000001
#define SYSPLL_SETUP 1
#define SYSPLLCTRL_Val 0x00000023
#define MAINCLKSEL_Val 0x00000003
#define SYSAHBCLKDIV_Val 0x00000001
#define AHBCLKCTRL_Val 0x0001005F
#define SSP0CLKDIV_Val 0x00000001
#define UARTCLKDIV_Val 0x00000001
#define SSP1CLKDIV_Val 0x00000001
/*--------------------- Memory Mapping Configuration -------------------------
//
// <e> Memory Mapping
// <o1.0..1> System Memory Remap (Register: SYSMEMREMAP)
// <0=> Bootloader mapped to address 0
// <1=> RAM mapped to address 0
// <2=> Flash mapped to address 0
// <3=> Flash mapped to address 0
// </e>
*/
#define MEMMAP_SETUP 0
#define SYSMEMREMAP_Val 0x00000001
/*
//-------- <<< end of configuration section >>> ------------------------------
*/
#ifdef __cplusplus
}
#endif
#endif /* __SYSTEM_LPC11x_H */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/src/xpcc/architecture/platform/arm7/at91/startup/at91_init.c | // coding: utf-8
// ----------------------------------------------------------------------------
/* Copyright (c) 2011, Roboterclub Aachen e.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Roboterclub Aachen e.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// ----------------------------------------------------------------------------
#include <stdint.h>
#include "../device.h"
#include "../../common/default_handler.h"
// ----------------------------------------------------------------------------
static void
initializePll(void)
{
// 1. Enable the Main Oscillator:
// SCK = 1/32768 = 30.51 uSecond
// OSCOUNT = 6
// Start up time = 8 * OSCOUNT / SCK = 56 * 30.51 = 1,46 ms
AT91C_BASE_PMC->PMC_MOR = ((6 << 8) & AT91C_CKGR_OSCOUNT) | AT91C_CKGR_MOSCEN;
while ((AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MOSCS) == 0) {
// wait unitl the main oscillator has stabilized
}
// 2. Checking the Main Oscillator Frequency (Optional)
// 3. Set the PLL and Divider:
// - div by 14 Fin = 1.3165 = (18,432 / 14)
// - Mul 72+1: Fout = 96.1097 = (3,6864 * 73)
// for 96 MHz the error is 0.11%
// Field out NOT USED = 0
// PLLCOUNT pll startup time estimate at : 0.844 ms
// PLLCOUNT 28 = 0.000844 / (1 / 32768)
AT91C_BASE_PMC->PMC_PLLR =
((AT91C_CKGR_DIV & 14) |
(AT91C_CKGR_PLLCOUNT & (28 << 8)) |
(AT91C_CKGR_MUL & (72 << 16)));
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_LOCK)) {
// wait until PLL is locked
}
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY)) {
// wait until Master Clock is ready
}
// 4. Selection of Master Clock and Processor Clock
// select the PLL clock divided by 2
AT91C_BASE_PMC->PMC_MCKR = AT91C_PMC_PRES_CLK_2;
while(!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY)) {
// wait until Master Clock is ready
}
// Use PLL as clock source
AT91C_BASE_PMC->PMC_MCKR |= AT91C_PMC_CSS_PLL_CLK;
while (!(AT91C_BASE_PMC->PMC_SR & AT91C_PMC_MCKRDY)) {
// wait until Master Clock is ready
}
}
// ----------------------------------------------------------------------------
/*
* @brief Hardware start-up function
*
*/
void
_at91Init(void)
{
// Watchdog Disable
AT91C_BASE_WDTC->WDTC_WDMR = AT91C_WDTC_WDDIS;
// TODO Enable User Reset and set its minimal assertion to 960 us
AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_URSTEN | (0x4<<8) | (unsigned int)(0xA5<<24);
// Initialize Flash Wait States
//
// See Datasheet AT91SAM7S256, Rev. C:
// 40.9.1.1 EFC: Embedded Flash Access Time 1
// The embedded Flash maximum access time is 20 MHz (instead of 30 MHz)
// at zero Wait State (FWS = 0).
// The maximum operating frequency with one Wait State (FWS = 1) is
// 48.1 MHz (instead of 55 MHz). Above 48.1 MHz and up to 55 MHz,
// two Wait States (FWS = 2) are required.
uint32_t flashParameter = 0;
#if F_CPU < 20000000UL
flashParameter |= AT91C_MC_FWS_0FWS;
#elif F_CPU < 48100000UL
flashParameter |= AT91C_MC_FWS_1FWS;
#else
flashParameter |= AT91C_MC_FWS_2FWS;
#endif
// Set cycles-per-microsecond
// as per datasheet,
// - NVM bits require a setting of F_CPU / 1000
// - general flash write requires a setting of 1.5 * F_CPU / 1000
// (here we're extra conservative setting clock cycles equal to 2us)
flashParameter |= ((F_CPU * 2 / 1000L) << 16) & AT91C_MC_FMCN;
#if defined(__ARM_AT91SAM7S512__) || defined(__ARM_AT91SAM7X512__)
AT91C_BASE_EFC0->EFC_FMR = flashParameter;
AT91C_BASE_EFC1->EFC_FMR = flashParameter;
#else
AT91C_BASE_MC->MC_FMR = flashParameter;
#endif
initializePll();
// Set up the default interrupts handler vectors
AT91C_BASE_AIC->AIC_SPU = (uintptr_t) defaultSpuriousHandler;
AT91C_BASE_AIC->AIC_SVR[0] = (uintptr_t) defaultFiqHandler;
for (int i = 1; i < 31; i++) {
AT91C_BASE_AIC->AIC_SVR[i] = (uintptr_t) defaultIrqHandler;
}
}
|
jrahlf/3D-Non-Contact-Laser-Profilometer | pc/pcDaemon2/mainwindow.h | <reponame>jrahlf/3D-Non-Contact-Laser-Profilometer
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "myThread.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
Ui::MainWindow *ui;
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
void registerButtonHandler(myThread* receiver);
public slots:
void setPositionX(double x);
void setPositionY(double y);
void setMeasurement(double m);
private:
};
#endif // MAINWINDOW_H
|
jrahlf/3D-Non-Contact-Laser-Profilometer | pc/pcDaemon2/infolog.h | <filename>pc/pcDaemon2/infolog.h
#ifndef INFOLOG_H
#define INFOLOG_H
#include <QMainWindow>
namespace Ui {
class InfoLog;
}
class InfoLog : public QMainWindow
{
Q_OBJECT
public:
explicit InfoLog(QWidget *parent = 0);
~InfoLog();
public slots:
void append(QString);
private:
Ui::InfoLog *ui;
};
#endif // INFOLOG_H
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/transform.h | <reponame>jrahlf/3D-Non-Contact-Laser-Profilometer<filename>microcontroller/transform.h
/*
* transform.h
*
* Created on: Jan 23, 2014
* Author: jonas
*/
#ifndef TRANSFORM_H_
#define TRANSFORM_H_
#include "project.h"
struct Transform{
static int mmToEncoder(float mm){
return int(MOTOR_ENC_PER_REV*MOTOR_GEAR_RATIO*mm + 0.5f);
}
static float encoderToMM(int encoder){
return float(encoder)/float(MOTOR_ENC_PER_REV*MOTOR_GEAR_RATIO);
}
static int mumToEncoder(float mum){
return int(mum*2 + 0.5f);
}
static float encoderToMUM(int encoder){
return float(encoder)*0.5f;
}
};
#endif /* TRANSFORM_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/rectangle.h | /*
* rectangle.h
*
* Created on: Feb 1, 2014
* Author: jonas
*/
#ifndef RECTANGLE_H_
#define RECTANGLE_H_
#include "pattern.h"
class Quadrangle{
private:
static int x, y, width, height;
public:
/**
* Units in mm
* @param x
* @param y
* @param width
* @param height
*/
static void configure(float x, float y, float width, float height);
static void configure(Point points[4]);
static void sample();
};
#endif /* RECTANGLE_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/src/xpcc/architecture/platform/cortex_m3/stm32/stm32f2_4/startup/startup.c | <filename>xpcc/src/xpcc/architecture/platform/cortex_m3/stm32/stm32f2_4/startup/startup.c
// coding: utf-8
// ----------------------------------------------------------------------------
/* Copyright (c) 2011, Roboterclub Aachen e.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Roboterclub Aachen e.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// ----------------------------------------------------------------------------
#include <stdint.h>
#include <xpcc/architecture/utils.hpp>
#if defined(STM32F2XX)
# include <stm32f2xx.h>
#elif defined(STM32F4XX)
# include <stm32f4xx.h>
#endif
#include "xpcc_config.hpp"
// ----------------------------------------------------------------------------
#define FLASH_WAIT_STATE_0 0x0
#define FLASH_WAIT_STATE_1 0x1
#define FLASH_WAIT_STATE_2 0x2
#define FLASH_WAIT_STATE_3 0x3
#define FLASH_WAIT_STATE_4 0x4
#define FLASH_WAIT_STATE_5 0x5
#define FLASH_WAIT_STATE_6 0x6
#define FLASH_WAIT_STATE_7 0x7
#define NR_INTERRUPTS 82
// ----------------------------------------------------------------------------
/*
* Provide weak aliases for each Exception handler to defaultHandler.
* As they are weak aliases, any function with the same name will override
* this definition.
*/
void Reset_Handler(void);
void NMI_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void HardFault_Handler(void);
void MemManage_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void BusFault_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void UsageFault_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void SVC_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void DebugMon_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void PendSV_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void SysTick_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void WWDG_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void PVD_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TAMP_STAMP_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void RTC_WKUP_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void FLASH_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void RCC_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI0_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI1_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI2_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI3_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI4_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_Stream0_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_Stream1_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_Stream2_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_Stream3_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_Stream4_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_Stream5_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_Stream6_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void ADC_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void CAN1_TX_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void CAN1_RX0_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void CAN1_RX1_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void CAN1_SCE_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI9_5_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM1_BRK_TIM9_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM1_UP_TIM10_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM1_TRG_COM_TIM11_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM1_CC_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM2_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM3_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM4_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void I2C1_EV_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void I2C1_ER_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void I2C2_EV_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void I2C2_ER_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void SPI1_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void SPI2_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void USART1_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void USART2_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void USART3_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI15_10_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void RTCAlarm_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void OTG_FS_WKUP_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM8_BRK_TIM12_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM8_UP_TIM13_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM8_TRG_COM_TIM14_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM8_CC_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_Stream7_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void FSMC_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void SDIO_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM5_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void SPI3_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void UART4_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void UART5_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM6_DAC_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM7_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA2_Stream0_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA2_Stream1_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA2_Stream2_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA2_Stream3_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA2_Stream4_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void ETH_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void ETH_WKUP_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void CAN2_TX_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void CAN2_RX0_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void CAN2_RX1_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void CAN2_SCE_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void OTG_FS_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA2_Stream5_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA2_Stream6_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA2_Stream7_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void USART6_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void I2C3_EV_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void I2C3_ER_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void OTG_HS_EP1_OUT_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void OTG_HS_EP1_IN_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void OTG_HS_WKUP_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void OTG_HS_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DCMI_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void CRYP_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void HASH_RNG_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void FPU_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
// ----------------------------------------------------------------------------
// Interrupt vectors
typedef void (* const FunctionPointer)(void);
// defined in the linkerscript
extern uint32_t __stack_end;
#if CORTEX_VECTORS_RAM
// Define the vector table
FunctionPointer flashVectors[4]
__attribute__ ((section(".reset"))) =
{
(FunctionPointer) &__stack_end, // stack pointer
Reset_Handler, // code entry point
NMI_Handler, // NMI handler
HardFault_Handler, // hard fault handler
};
FunctionPointer ramVectors[] __attribute__ ((section(".vectors"))) =
#else
FunctionPointer flashVectors[] __attribute__ ((section(".reset"))) =
#endif
{
(FunctionPointer) &__stack_end, // stack pointer
Reset_Handler, // code entry point
NMI_Handler, // NMI handler
HardFault_Handler, // hard fault handler
MemManage_Handler, // MPU Fault Handler
BusFault_Handler, // Bus Fault Handler
UsageFault_Handler, // Usage Fault Handler
0,
0,
0,
0,
SVC_Handler, // SVCall Handler
DebugMon_Handler, // Debug Monitor Handler
0,
PendSV_Handler, // PendSV Handler
SysTick_Handler, // SysTick Handler
// Peripheral interrupts (STM32 specific)
WWDG_IRQHandler, // 0: Window Watchdog
PVD_IRQHandler, // 1: PVD through EXTI Line detect
TAMP_STAMP_IRQHandler, // 2: Tamper and TimeStamps through the EXTI line
RTC_WKUP_IRQHandler, // 3: Wakeup through the EXTI line
FLASH_IRQHandler, // 4: Flash
RCC_IRQHandler, // 5: RCC
EXTI0_IRQHandler, // EXTI Line 0
EXTI1_IRQHandler, // EXTI Line 1
EXTI2_IRQHandler, // EXTI Line 2
EXTI3_IRQHandler, // EXTI Line 3
EXTI4_IRQHandler, // 10: EXTI Line 4
DMA1_Stream0_IRQHandler, // DMA1 Stream 0
DMA1_Stream1_IRQHandler, // DMA1 Stream 1
DMA1_Stream2_IRQHandler, // DMA1 Stream 2
DMA1_Stream3_IRQHandler, // DMA1 Stream 3
DMA1_Stream4_IRQHandler, // 15: DMA1 Stream 4
DMA1_Stream5_IRQHandler, // DMA1 Stream 5
DMA1_Stream6_IRQHandler, // DMA1 Stream 6
ADC_IRQHandler, // ADC1, ADC2 and ADC3s
CAN1_TX_IRQHandler, // CAN1 TX
CAN1_RX0_IRQHandler, // 20: CAN1 RX0
CAN1_RX1_IRQHandler, // CAN1 RX1
CAN1_SCE_IRQHandler, // CAN1 SCE
EXTI9_5_IRQHandler, // EXTI Line 9..5
TIM1_BRK_TIM9_IRQHandler, // TIM1 Break
TIM1_UP_TIM10_IRQHandler, // 25: TIM1 Update
TIM1_TRG_COM_TIM11_IRQHandler, // TIM1 Trigger and Commutation
TIM1_CC_IRQHandler, // TIM1 Capture Compare
TIM2_IRQHandler, // TIM2
TIM3_IRQHandler, // TIM3
TIM4_IRQHandler, // 30: TIM4
I2C1_EV_IRQHandler, // I2C1 Event
I2C1_ER_IRQHandler, // I2C1 Error
I2C2_EV_IRQHandler, // I2C2 Event
I2C2_ER_IRQHandler, // I2C2 Error
SPI1_IRQHandler, // 35: SPI1
SPI2_IRQHandler, // SPI2
USART1_IRQHandler, // USART1
USART2_IRQHandler, // USART2
USART3_IRQHandler, // USART3
EXTI15_10_IRQHandler, // 40: External Line[15:10]s
RTCAlarm_IRQHandler, // RTC Alarm (A and B) through EXTI Line
OTG_FS_WKUP_IRQHandler, // USB OTG FS Wakeup through EXTI line
TIM8_BRK_TIM12_IRQHandler, // TIM8 Break and TIM12
TIM8_UP_TIM13_IRQHandler, // TIM8 Update and TIM13
TIM8_TRG_COM_TIM14_IRQHandler, // 45: TIM8 Trigger and Commutation and TIM14
TIM8_CC_IRQHandler,
DMA1_Stream7_IRQHandler,
FSMC_IRQHandler,
SDIO_IRQHandler,
TIM5_IRQHandler, // 50:
SPI3_IRQHandler,
UART4_IRQHandler,
UART5_IRQHandler,
TIM6_DAC_IRQHandler, // TIM6 and DAC1&2 under-run errors
TIM7_IRQHandler, // 55:
DMA2_Stream0_IRQHandler,
DMA2_Stream1_IRQHandler,
DMA2_Stream2_IRQHandler,
DMA2_Stream3_IRQHandler,
DMA2_Stream4_IRQHandler, // 60:
ETH_IRQHandler, //
ETH_WKUP_IRQHandler, // Ethernet Wakeup through EXTI line
CAN2_TX_IRQHandler,
CAN2_RX0_IRQHandler,
CAN2_RX1_IRQHandler, // 65:
CAN2_SCE_IRQHandler,
OTG_FS_IRQHandler,
DMA2_Stream5_IRQHandler, // DMA2 Stream 5
DMA2_Stream6_IRQHandler, // DMA2 Stream 6
DMA2_Stream7_IRQHandler, // 70: DMA2 Stream 7
USART6_IRQHandler, // USART6
I2C3_EV_IRQHandler, // I2C3 event
I2C3_ER_IRQHandler, // I2C3 error
OTG_HS_EP1_OUT_IRQHandler, // USB OTG HS End Point 1 Out
OTG_HS_EP1_IN_IRQHandler, // 75: USB OTG HS End Point 1 In
OTG_HS_WKUP_IRQHandler, // USB OTG HS Wakeup through EXTI
OTG_HS_IRQHandler, // USB OTG HS
DCMI_IRQHandler, // DCMI
CRYP_IRQHandler, // CRYP Crypto
HASH_RNG_IRQHandler, // 80: Hash and Random Number Generator
FPU_IRQHandler, // FPU
};
// ----------------------------------------------------------------------------
// defined in the linkerscript
extern uint32_t __fastcode_load;
extern uint32_t __fastcode_start;
extern uint32_t __fastcode_end;
extern uint32_t __data_load;
extern uint32_t __data_start;
extern uint32_t __data_end;
extern uint32_t __bss_start;
extern uint32_t __bss_end;
// Application's main function
int
main(void);
// calls CTORS of static objects
void
__libc_init_array(void);
extern void
exit(int) __attribute__ ((noreturn, weak));
// ----------------------------------------------------------------------------
void
Reset_Handler(void)
{
// startup delay
for (volatile unsigned long i = 0; i < 500000; i++)
{
}
// Copy functions to RAM (.fastcode)
uint32_t* src = &__fastcode_load;
uint32_t* dest = &__fastcode_start;
while (dest < &__fastcode_end)
{
*(dest++) = *(src++);
}
// Copy the data segment initializers from flash to RAM (.data)
src = &__data_load;
dest = &__data_start;
while (dest < &__data_end)
{
*(dest++) = *(src++);
}
// Fill the bss segment with zero (.bss)
dest = &__bss_start;
while (dest < &__bss_end)
{
*(dest++) = 0;
}
#if defined(STM32F4XX)
// prepare flash latency for working at 168MHz and supply voltage > 2.7
FLASH->ACR = (FLASH->ACR & ~FLASH_ACR_LATENCY) | FLASH_WAIT_STATE_5;
#elif defined(STM32F2XX)
// prepare flash latency for working at 120MHz and supply voltage > 2.7
FLASH->ACR = (FLASH->ACR & ~FLASH_ACR_LATENCY) | FLASH_WAIT_STATE_3;
#else
#error "This file is not supposed to be used with given CPU (only STM32F2/4xx)"
#endif
// enable flash prefetch
FLASH->ACR |= FLASH_ACR_PRFTEN | FLASH_ACR_DCEN | FLASH_ACR_ICEN;
#if defined(STM32F4XX)
// Enable FPU in privileged and user mode
SCB->CPACR |= ((3UL << 10*2) | (3UL << 11*2)); // set CP10 and CP11 Full Access
// Enable Core Coupled Memory (CCM)
RCC->AHB1ENR |= RCC_AHB1ENR_CCMDATARAMEN;
#endif
// Enable GPIO clock
// TODO adapt to actual pin count!
// GPIOA-D
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOAEN | RCC_AHB1ENR_GPIOBEN | RCC_AHB1ENR_GPIOCEN | RCC_AHB1ENR_GPIODEN;
RCC->AHB1RSTR |= RCC_AHB1RSTR_GPIOARST | RCC_AHB1RSTR_GPIOBRST | RCC_AHB1RSTR_GPIOCRST | RCC_AHB1RSTR_GPIODRST;
RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOARST | RCC_AHB1RSTR_GPIOBRST | RCC_AHB1RSTR_GPIOCRST | RCC_AHB1RSTR_GPIODRST);
// GPIOE-I
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN | RCC_AHB1ENR_GPIOFEN | RCC_AHB1ENR_GPIOGEN | RCC_AHB1ENR_GPIOHEN | RCC_AHB1ENR_GPIOIEN;
RCC->AHB1RSTR |= RCC_AHB1RSTR_GPIOERST | RCC_AHB1RSTR_GPIOFRST | RCC_AHB1RSTR_GPIOGRST | RCC_AHB1RSTR_GPIOHRST | RCC_AHB1RSTR_GPIOIRST;
RCC->AHB1RSTR &= ~(RCC_AHB1RSTR_GPIOERST | RCC_AHB1RSTR_GPIOFRST | RCC_AHB1RSTR_GPIOGRST | RCC_AHB1RSTR_GPIOHRST | RCC_AHB1RSTR_GPIOIRST);
// Setup NVIC
// Set vector table
const uint32_t offset = 0;
SCB->VTOR = 0x08000000 | (offset & 0x1FFFFF80);
// Lower priority level for all peripheral interrupts to lowest possible
for (uint32_t i = 0; i < NR_INTERRUPTS; i++) {
const uint32_t priority = 0xF;
NVIC->IP[i] = (priority & 0xF) << 4;
}
// Set the PRIGROUP[10:8] bits to
// - 4 bits for pre-emption priority,
// - 0 bits for subpriority
SCB->AIRCR = 0x05FA0000 | 0x300;
// Enable fault handlers
/*SCB->SHCSR |=
SCB_SHCSR_BUSFAULTENA_Msk |
SCB_SHCSR_USGFAULTENA_Msk |
SCB_SHCSR_MEMFAULTENA_Msk;*/
// Call CTORS of static objects
__libc_init_array();
// Call the application's entry point
main();
exit(1);
while (1)
{
}
}
// ----------------------------------------------------------------------------
/**
* @brief Default interrupt handler
*
* This functions gets called if an interrupt handler is not defined. It just
* enters an infinite loop leaving the processor state intact for a debugger
* to be examined.
*/
void
defaultHandler(void)
{
while (1)
{
}
}
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/control.h | <gh_stars>1-10
/*
* control.h
*
* Created on: Nov 24, 2013
* Author: jonas
*/
#ifndef CONTROL_H_
#define CONTROL_H_
#include "project.h"
#include <xpcc/math/filter/pid.hpp>
template<Axis axis>
class Control{
friend class Control<ALL>;
private:
static volatile int pos_shall;
static volatile int v_is; // velocity in pulses/s
static volatile int v_shall;
static float maxSpeed;
static xpcc::Pid<float, 1> v_pid;
static xpcc::Pid<float, 1> pos_pid;
static int v_u; // speed controller output
static int v_ureal;
static int last_pos; //position when the last control loop was executed
static bool positionControlEnabled;
static bool speedControlEnabled;
public:
static bool init();
static void enablePositionControl(bool enable);
static void enableSpeedControl(bool enable);
static void setShallPosition(int x);
/**
* Also disables the position controller
* @param speed [-1,1]
*/
static void setShallSpeed(double speed);
static int getSpeedErrorSum();
static int getPositionErrorSum();
static int32_t getIsPosition();
static inline int getShallSpeed(){ return v_shall; }
static inline int getIsSpeed(){ return v_is; }
static inline int getShallPosition(){ return pos_shall; }
static inline int getSpeedU(){ return v_u; }
static inline int getSpeedRealU(){ return v_ureal; }
static inline int getPosU(){ return v_shall; } //only valid if position controller is active
static const xpcc::Pid<float,1>::Parameter& getVPidParams(){ return v_pid.getParameter(); }
static const xpcc::Pid<float,1>::Parameter& getPosPidParams(){ return pos_pid.getParameter(); }
static bool isPositionControlEnabled(){ return positionControlEnabled; }
static bool isSpeedControlEnabled(){ return speedControlEnabled; }
static void resetVPid();
static void resetPosPid();
static float getMaxSpeed(){ return maxSpeed; }
/**
* [0, 1]
* Limits the output of the position controller
*/
static void setMaxSpeed(float maxSpeed);
/**
* To be called periodically (1kHz)
* Computes new ouput values for the H-bridge
*/
static void update(bool externalLimitation);
};
template<Axis axis> volatile int Control<axis>::pos_shall;
template<Axis axis> volatile int Control<axis>::v_is;
template<Axis axis> volatile int Control<axis>::v_shall;
template<Axis axis> int Control<axis>::v_u;
template<Axis axis> int Control<axis>::v_ureal;
template<Axis axis> float Control<axis>::maxSpeed;
template<Axis axis> bool Control<axis>::positionControlEnabled;
template<Axis axis> bool Control<axis>::speedControlEnabled;
template<Axis axis> xpcc::Pid<float, 1> Control<axis>::v_pid;
template<Axis axis> xpcc::Pid<float, 1> Control<axis>::pos_pid;
template<Axis axis> int Control<axis>::last_pos; //position when the last control loop was executed
template<> void Control<ALL>::update(bool externalLimitation);
template<> int32_t Control<X>::getIsPosition();
template<> int32_t Control<Y>::getIsPosition();
template<> bool Control<ALL>::init();
#include "control_impl.h"
#endif /* CONTROL_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/src/xpcc/architecture/platform/cortex_m3/stm32/device.h | <gh_stars>1-10
// coding: utf-8
// ----------------------------------------------------------------------------
/* Copyright (c) 2011, Roboterclub Aachen e.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Roboterclub Aachen e.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ROBOTERCL<NAME>HEN E.V. ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// ----------------------------------------------------------------------------
#ifndef STM32__DEVICE_H
#define STM32__DEVICE_H
/**
* Reduce compile dependencies for the hardware drivers.
* Do not include <xpcc/architecture.hpp> to avoid recompiling the whole set
* of drivers if anything unrelated changed.
*/
#if !defined(STM32F4XX) && !defined(STM32F2XX) && \
!defined(STM32F10X_CL) && \
!defined(STM32F10X_LD) && !defined(STM32F10X_MD) && !defined(STM32F10X_HD) && !defined(STM32F10X_XL) && \
!defined(STM32F10X_LD_VL) && !defined(STM32F10X_MD_VL) && !defined (STM32F10X_HD_VL) && \
!defined(STM32F30X)
# error "Please select the target STM32F??X device used in your application (in the stm32f??x.h file)"
#endif
#if defined(STM32F10X_CL) || \
defined(STM32F10X_LD) || \
defined(STM32F10X_MD) || \
defined(STM32F10X_HD) || \
defined(STM32F10X_XL) || \
defined(STM32F10X_LD_VL) || \
defined(STM32F10X_MD_VL) || \
defined(STM32F10X_HD_VL)
# include <stm32f10x.h>
#elif defined(STM32F2XX)
# include <stm32f2xx.h>
#elif defined(STM32F30X)
# include <stm32f30x.h>
#elif defined(STM32F4XX)
# include <stm32f4xx.h>
#else
#error "Please be more specific here."
#endif
/**
* \defgroup stm32f1 STM32F10x
* \ingroup stm32
*/
/**
* \defgroup stm32f3 STM32F3xx
* \ingroup stm32
*/
/**
* \defgroup stm32f2_4 STM32F2xx and STM32F4xx
* \ingroup stm32
*/
#endif // STM32__DEVICE_H
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/src/xpcc/architecture/platform/avr/atmega/uart/uart_defines.h | // coding: utf-8
// ----------------------------------------------------------------------------
/* Copyright (c) 2011, Roboterclub Aachen e.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Roboterclub Aachen e.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// ----------------------------------------------------------------------------
#ifndef UART_DEFINES_H
#define UART_DEFINES_H
// Atmel made a mess with the register names for UART0 between the "old" devices.
// To avoid to much conditional compiling we try to mimic the new names for
// the old devices.
#if defined (UDR) && defined (UDR0)
#undef UDR0
#endif
#if defined (UDR)
# define UDR0 UDR
# define UBRR0L UBRRL
# define UBRR0H UBRRH
# define UCSR0A UCSRA
# define UCSR0B UCSRB
# define UCSR0C UCSRC
# define DOR0 DOR
# define FE0 FE
# define RXCIE0 RXCIE
# define TXCIE0 TXCIE
# define RXEN0 RXEN
# define TXEN0 TXEN
# define U2X0 U2X
# define URSEL0 URSEL
# define UCSZ00 UCSZ0
# define UCSZ01 UCSZ1
# define UDRIE0 UDRIE
#endif
// We want the interrupt names to be "USART0_RX_vect", "USART0_UDRE_vect" and
// "USART0_TX_vect".
#if defined(USART0_RX_vect)
// everything is fine
#elif defined(USART_RX_vect)
# define USART0_RX_vect USART_RX_vect
# define USART0_UDRE_vect USART_UDRE_vect
# define USART0_TX_vect USART_TX_vect
#elif defined(USARTRXC_vect)
# define USART0_RX_vect USARTRXC_vect
# define USART0_UDRE_vect USARTUDRE_vect
# define USART0_TX_vect USARTTXC_vect
#elif defined(USART_RXC_vect)
# define USART0_RX_vect USART_RXC_vect
# define USART0_UDRE_vect USART_UDRE_vect
# define USART0_TX_vect USART_TXC_vect
#endif
#endif // UART_DEFINES_H
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/securityController.h | /*
* securityController.h
*
* Created on: Dec 28, 2013
* Author: jonas
*/
#ifndef SECURITYCONTROLLER_H_
#define SECURITYCONTROLLER_H_
#include "project.h"
#include "hallSensor.h"
#include "state.h"
template <Axis axis> class HallSensor;
template<Axis axis>
class SecurityController{
public:
template<typename T>
static void saturate(T& value){
if((!HallSensor<axis>::getEndState()) && value > 0){
value = 0;
//bool clear = HallSensor<axis>::checkEndState();
//State::setSecondaryState(State::MOTOR_LIMITED, !clear);
}else if((!HallSensor<axis>::getFrontState()) && value < 0){
value = 0;
//bool clear = HallSensor<axis>::checkFrontState();
//State::setSecondaryState(State::MOTOR_LIMITED, !clear);
}
}
};
#endif /* SECURITYCONTROLLER_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/src/xpcc/architecture/platform/arm7/lpc/device/lpc213x.h | <filename>xpcc/src/xpcc/architecture/platform/arm7/lpc/device/lpc213x.h
/**
* @file lpc21xx.h
* @brief Header file for Philips LPC2131/32/34/36/38
*
*/
#ifndef LPC213x_REGISTERS_H
#define LPC213x_REGISTERS_H
/* Vectored Interrupt Controller (VIC) */
#define VICIRQStatus (*((volatile unsigned long *) 0xFFFFF000))
#define VICFIQStatus (*((volatile unsigned long *) 0xFFFFF004))
#define VICRawIntr (*((volatile unsigned long *) 0xFFFFF008))
#define VICIntSelect (*((volatile unsigned long *) 0xFFFFF00C))
#define VICIntEnable (*((volatile unsigned long *) 0xFFFFF010))
#define VICIntEnClr (*((volatile unsigned long *) 0xFFFFF014))
#define VICSoftInt (*((volatile unsigned long *) 0xFFFFF018))
#define VICSoftIntClr (*((volatile unsigned long *) 0xFFFFF01C))
#define VICProtection (*((volatile unsigned long *) 0xFFFFF020))
#define VICVectAddr (*((volatile unsigned long *) 0xFFFFF030))
#define VICDefVectAddr (*((volatile unsigned long *) 0xFFFFF034))
#define VICVectAddr0 (*((volatile unsigned long *) 0xFFFFF100))
#define VICVectAddr1 (*((volatile unsigned long *) 0xFFFFF104))
#define VICVectAddr2 (*((volatile unsigned long *) 0xFFFFF108))
#define VICVectAddr3 (*((volatile unsigned long *) 0xFFFFF10C))
#define VICVectAddr4 (*((volatile unsigned long *) 0xFFFFF110))
#define VICVectAddr5 (*((volatile unsigned long *) 0xFFFFF114))
#define VICVectAddr6 (*((volatile unsigned long *) 0xFFFFF118))
#define VICVectAddr7 (*((volatile unsigned long *) 0xFFFFF11C))
#define VICVectAddr8 (*((volatile unsigned long *) 0xFFFFF120))
#define VICVectAddr9 (*((volatile unsigned long *) 0xFFFFF124))
#define VICVectAddr10 (*((volatile unsigned long *) 0xFFFFF128))
#define VICVectAddr11 (*((volatile unsigned long *) 0xFFFFF12C))
#define VICVectAddr12 (*((volatile unsigned long *) 0xFFFFF130))
#define VICVectAddr13 (*((volatile unsigned long *) 0xFFFFF134))
#define VICVectAddr14 (*((volatile unsigned long *) 0xFFFFF138))
#define VICVectAddr15 (*((volatile unsigned long *) 0xFFFFF13C))
#define VICVectCntl0 (*((volatile unsigned long *) 0xFFFFF200))
#define VICVectCntl1 (*((volatile unsigned long *) 0xFFFFF204))
#define VICVectCntl2 (*((volatile unsigned long *) 0xFFFFF208))
#define VICVectCntl3 (*((volatile unsigned long *) 0xFFFFF20C))
#define VICVectCntl4 (*((volatile unsigned long *) 0xFFFFF210))
#define VICVectCntl5 (*((volatile unsigned long *) 0xFFFFF214))
#define VICVectCntl6 (*((volatile unsigned long *) 0xFFFFF218))
#define VICVectCntl7 (*((volatile unsigned long *) 0xFFFFF21C))
#define VICVectCntl8 (*((volatile unsigned long *) 0xFFFFF220))
#define VICVectCntl9 (*((volatile unsigned long *) 0xFFFFF224))
#define VICVectCntl10 (*((volatile unsigned long *) 0xFFFFF228))
#define VICVectCntl11 (*((volatile unsigned long *) 0xFFFFF22C))
#define VICVectCntl12 (*((volatile unsigned long *) 0xFFFFF230))
#define VICVectCntl13 (*((volatile unsigned long *) 0xFFFFF234))
#define VICVectCntl14 (*((volatile unsigned long *) 0xFFFFF238))
#define VICVectCntl15 (*((volatile unsigned long *) 0xFFFFF23C))
/* Pin Connect Block */
#define PINSEL0 (*((volatile unsigned long *) 0xE002C000))
#define PINSEL1 (*((volatile unsigned long *) 0xE002C004))
#define PINSEL2 (*((volatile unsigned long *) 0xE002C014))
/* General Purpose Input/Output (GPIO) */
#define IOPIN0 (*((volatile unsigned long *) 0xE0028000))
#define IOSET0 (*((volatile unsigned long *) 0xE0028004))
#define IODIR0 (*((volatile unsigned long *) 0xE0028008))
#define IOCLR0 (*((volatile unsigned long *) 0xE002800C))
#define IOPIN1 (*((volatile unsigned long *) 0xE0028010))
#define IOSET1 (*((volatile unsigned long *) 0xE0028014))
#define IODIR1 (*((volatile unsigned long *) 0xE0028018))
#define IOCLR1 (*((volatile unsigned long *) 0xE002801C))
/* Memory Accelerator Module (MAM) */
#define MAMCR (*((volatile unsigned char *) 0xE01FC000))
#define MAMTIM (*((volatile unsigned char *) 0xE01FC004))
#define MEMMAP (*((volatile unsigned char *) 0xE01FC040))
/* Phase Locked Loop (PLL) */
#define PLLCON (*((volatile unsigned char *) 0xE01FC080))
#define PLLCFG (*((volatile unsigned char *) 0xE01FC084))
#define PLLSTAT (*((volatile unsigned short*) 0xE01FC088))
#define PLLFEED (*((volatile unsigned char *) 0xE01FC08C))
/* VPB Divider */
#define VPBDIV (*((volatile unsigned char *) 0xE01FC100))
/* Power Control */
#define PCON (*((volatile unsigned char *) 0xE01FC0C0))
#define PCONP (*((volatile unsigned long *) 0xE01FC0C4))
/* External Interrupts */
#define EXTINT (*((volatile unsigned char *) 0xE01FC140))
#define INTWAKE (*((volatile unsigned char *) 0xE01FC144))
#define EXTMODE (*((volatile unsigned char *) 0xE01FC148))
#define EXTPOLAR (*((volatile unsigned char *) 0xE01FC14C))
/* Reset */
#define RSID (*((volatile unsigned char *) 0xE01FC180))
/* Code Security / Debugging */
#define CSPR (*((volatile unsigned char *) 0xE01FC184))
/* Timer 0 */
#define T0IR (*((volatile unsigned long *) 0xE0004000))
#define T0TCR (*((volatile unsigned long *) 0xE0004004))
#define T0TC (*((volatile unsigned long *) 0xE0004008))
#define T0PR (*((volatile unsigned long *) 0xE000400C))
#define T0PC (*((volatile unsigned long *) 0xE0004010))
#define T0MCR (*((volatile unsigned long *) 0xE0004014))
#define T0MR0 (*((volatile unsigned long *) 0xE0004018))
#define T0MR1 (*((volatile unsigned long *) 0xE000401C))
#define T0MR2 (*((volatile unsigned long *) 0xE0004020))
#define T0MR3 (*((volatile unsigned long *) 0xE0004024))
#define T0CCR (*((volatile unsigned long *) 0xE0004028))
#define T0CR0 (*((volatile unsigned long *) 0xE000402C))
#define T0CR1 (*((volatile unsigned long *) 0xE0004030))
#define T0CR2 (*((volatile unsigned long *) 0xE0004034))
#define T0CR3 (*((volatile unsigned long *) 0xE0004038))
#define T0EMR (*((volatile unsigned long *) 0xE000403C))
#define T0CTCR (*((volatile unsigned long *) 0xE0004070))
/* Timer 1 */
#define T1IR (*((volatile unsigned long *) 0xE0008000))
#define T1TCR (*((volatile unsigned long *) 0xE0008004))
#define T1TC (*((volatile unsigned long *) 0xE0008008))
#define T1PR (*((volatile unsigned long *) 0xE000800C))
#define T1PC (*((volatile unsigned long *) 0xE0008010))
#define T1MCR (*((volatile unsigned long *) 0xE0008014))
#define T1MR0 (*((volatile unsigned long *) 0xE0008018))
#define T1MR1 (*((volatile unsigned long *) 0xE000801C))
#define T1MR2 (*((volatile unsigned long *) 0xE0008020))
#define T1MR3 (*((volatile unsigned long *) 0xE0008024))
#define T1CCR (*((volatile unsigned long *) 0xE0008028))
#define T1CR0 (*((volatile unsigned long *) 0xE000802C))
#define T1CR1 (*((volatile unsigned long *) 0xE0008030))
#define T1CR2 (*((volatile unsigned long *) 0xE0008034))
#define T1CR3 (*((volatile unsigned long *) 0xE0008038))
#define T1EMR (*((volatile unsigned long *) 0xE000803C))
#define T1CTCR (*((volatile unsigned long *) 0xE0008070))
/* Pulse Width Modulator (PWM) */
#define PWMIR (*((volatile unsigned long *) 0xE0014000))
#define PWMTCR (*((volatile unsigned long *) 0xE0014004))
#define PWMTC (*((volatile unsigned long *) 0xE0014008))
#define PWMPR (*((volatile unsigned long *) 0xE001400C))
#define PWMPC (*((volatile unsigned long *) 0xE0014010))
#define PWMMCR (*((volatile unsigned long *) 0xE0014014))
#define PWMMR0 (*((volatile unsigned long *) 0xE0014018))
#define PWMMR1 (*((volatile unsigned long *) 0xE001401C))
#define PWMMR2 (*((volatile unsigned long *) 0xE0014020))
#define PWMMR3 (*((volatile unsigned long *) 0xE0014024))
#define PWMMR4 (*((volatile unsigned long *) 0xE0014040))
#define PWMMR5 (*((volatile unsigned long *) 0xE0014044))
#define PWMMR6 (*((volatile unsigned long *) 0xE0014048))
#define PWMEMR (*((volatile unsigned long *) 0xE001403C))
#define PWMPCR (*((volatile unsigned long *) 0xE001404C))
#define PWMLER (*((volatile unsigned long *) 0xE0014050))
/* Universal Asynchronous Receiver Transmitter 0 (UART0) */
#define U0RBR (*((volatile unsigned char *) 0xE000C000))
#define U0THR (*((volatile unsigned char *) 0xE000C000))
#define U0IER (*((volatile unsigned char *) 0xE000C004))
#define U0IIR (*((volatile unsigned char *) 0xE000C008))
#define U0FCR (*((volatile unsigned char *) 0xE000C008))
#define U0LCR (*((volatile unsigned char *) 0xE000C00C))
#define U0LSR (*((volatile unsigned char *) 0xE000C014))
#define U0SCR (*((volatile unsigned char *) 0xE000C01C))
#define U0DLL (*((volatile unsigned char *) 0xE000C000))
#define U0DLM (*((volatile unsigned char *) 0xE000C004))
#define U0TER (*((volatile unsigned char *) 0xE000C030))
/* Universal Asynchronous Receiver Transmitter 1 (UART1) */
#define U1RBR (*((volatile unsigned char *) 0xE0010000))
#define U1THR (*((volatile unsigned char *) 0xE0010000))
#define U1IER (*((volatile unsigned char *) 0xE0010004))
#define U1IIR (*((volatile unsigned char *) 0xE0010008))
#define U1FCR (*((volatile unsigned char *) 0xE0010008))
#define U1LCR (*((volatile unsigned char *) 0xE001000C))
#define U1MCR (*((volatile unsigned char *) 0xE0010010))
#define U1LSR (*((volatile unsigned char *) 0xE0010014))
#define U1MSR (*((volatile unsigned char *) 0xE0010018))
#define U1SCR (*((volatile unsigned char *) 0xE001001C))
#define U1DLL (*((volatile unsigned char *) 0xE0010000))
#define U1DLM (*((volatile unsigned char *) 0xE0010004))
#define U1TER (*((volatile unsigned char *) 0xE0010030))
/* I2C Interface 0 */
#define I20CONSET (*((volatile unsigned char *) 0xE001C000))
#define I20STAT (*((volatile unsigned char *) 0xE001C004))
#define I20DAT (*((volatile unsigned char *) 0xE001C008))
#define I20ADR (*((volatile unsigned char *) 0xE001C00C))
#define I20SCLH (*((volatile unsigned short*) 0xE001C010))
#define I20SCLL (*((volatile unsigned short*) 0xE001C014))
#define I20CONCLR (*((volatile unsigned char *) 0xE001C018))
/* I2C Interface 1 */
#define I21CONSET (*((volatile unsigned char *) 0xE005C000))
#define I21STAT (*((volatile unsigned char *) 0xE005C004))
#define I21DAT (*((volatile unsigned char *) 0xE005C008))
#define I21ADR (*((volatile unsigned char *) 0xE005C00C))
#define I21SCLH (*((volatile unsigned short*) 0xE005C010))
#define I21SCLL (*((volatile unsigned short*) 0xE005C014))
#define I21CONCLR (*((volatile unsigned char *) 0xE005C018))
/* SPI0 (Serial Peripheral Interface 0) */
#define S0SPCR (*((volatile unsigned char *) 0xE0020000))
#define S0SPSR (*((volatile unsigned char *) 0xE0020004))
#define S0SPDR (*((volatile unsigned char *) 0xE0020008))
#define S0SPCCR (*((volatile unsigned char *) 0xE002000C))
#define S0SPTCR (*((volatile unsigned char *) 0xE0020010))
#define S0SPTSR (*((volatile unsigned char *) 0xE0020014))
#define S0SPTOR (*((volatile unsigned char *) 0xE0020018))
#define S0SPINT (*((volatile unsigned char *) 0xE002001C))
/* SSP Controller */
#define SSPCR0 (*((volatile unsigned short* ) 0xE0068000))
#define SSPCR1 (*((volatile unsigned char * ) 0xE0068004))
#define SSPDR (*((volatile unsigned short* ) 0xE0068008))
#define SSPSR (*((volatile unsigned char * ) 0xE006800C))
#define SSPCPSR (*((volatile unsigned char * ) 0xE0068010))
#define SSPIMSC (*((volatile unsigned char * ) 0xE0068014))
#define SSPRIS (*((volatile unsigned char * ) 0xE0068018))
#define SSPMIS (*((volatile unsigned char * ) 0xE006801C))
#define SSPICR (*((volatile unsigned char * ) 0xE0068020))
#define SSPDMACR (*((volatile unsigned char * ) 0xE0068024))
/* Real Time Clock */
#define ILR (*((volatile unsigned char *) 0xE0024000))
#define CTC (*((volatile unsigned short*) 0xE0024004))
#define CCR (*((volatile unsigned char *) 0xE0024008))
#define CIIR (*((volatile unsigned char *) 0xE002400C))
#define AMR (*((volatile unsigned char *) 0xE0024010))
#define CTIME0 (*((volatile unsigned long *) 0xE0024014))
#define CTIME1 (*((volatile unsigned long *) 0xE0024018))
#define CTIME2 (*((volatile unsigned long *) 0xE002401C))
#define SEC (*((volatile unsigned char *) 0xE0024020))
#define MIN (*((volatile unsigned char *) 0xE0024024))
#define HOUR (*((volatile unsigned char *) 0xE0024028))
#define DOM (*((volatile unsigned char *) 0xE002402C))
#define DOW (*((volatile unsigned char *) 0xE0024030))
#define DOY (*((volatile unsigned short*) 0xE0024034))
#define MONTH (*((volatile unsigned char *) 0xE0024038))
#define YEAR (*((volatile unsigned short*) 0xE002403C))
#define ALSEC (*((volatile unsigned char *) 0xE0024060))
#define ALMIN (*((volatile unsigned char *) 0xE0024064))
#define ALHOUR (*((volatile unsigned char *) 0xE0024068))
#define ALDOM (*((volatile unsigned char *) 0xE002406C))
#define ALDOW (*((volatile unsigned char *) 0xE0024070))
#define ALDOY (*((volatile unsigned short*) 0xE0024074))
#define ALMON (*((volatile unsigned char *) 0xE0024078))
#define ALYEAR (*((volatile unsigned short*) 0xE002407C))
#define PREINT (*((volatile unsigned short*) 0xE0024080))
#define PREFRAC (*((volatile unsigned short*) 0xE0024084))
/* A/D Converter 0 (AD0) */
#define AD0CR (*((volatile unsigned long *) 0xE0034000))
#define AD0DR (*((volatile unsigned long *) 0xE0034004))
/* A/D Converter 1 (AD1) */
#define AD1CR (*((volatile unsigned long *) 0xE0060000))
#define AD1DR (*((volatile unsigned long *) 0xE0060004))
/* D/A Converter */
#define DACR (*((volatile unsigned long *) 0xE006C000))
/* Watchdog */
#define WDMOD (*((volatile unsigned char *) 0xE0000000))
#define WDTC (*((volatile unsigned long *) 0xE0000004))
#define WDFEED (*((volatile unsigned char *) 0xE0000008))
#define WDTV (*((volatile unsigned long *) 0xE000000C))
#endif // LPC213x_REGISTERS_H
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/motor.h | /*
* motor.h
*
* Created on: Nov 24, 2013
* Author: jonas
*/
#ifndef MOTOR_H_
#define MOTOR_H_
#include "project.h"
#include "control.h"
template<Axis axis>
class Motor {
friend class Control<axis>;
friend class Motor<ALL>;
public:
static bool init();
struct Ext{
/**
* Brakes the motor
*/
static void brake();
/**
* Lets the motor run freely
*/
static void freeRun();
};
friend class Motor<axis>::Ext;
friend class PC;
static bool getFaultStatus();
public:
//These functions shall be only called by a Controller
/**
* Set the current speed
* @param speed in the range of [-1200,1200]
*/
static void setSpeed(int speed);
/**
* Brakes the motor
*/
static void brake();
/**
* Lets the motor run freely
*/
static void freeRun();
};
#endif /* MOTOR_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/quadrangleZigZag.h | <reponame>jrahlf/3D-Non-Contact-Laser-Profilometer
/*
* RectangleZigZag.h
*
* Created on: Jan 18, 2014
* Author: jonas
*/
#ifndef RECTANGLEZIGZAG_H_
#define RECTANGLEZIGZAG_H_
#include "pattern.h"
#include "Trigger.h"
class QuadrangleZigZag{
private:
static int startX, stopX, startY, stopY;
static int samplingResolution;
static bool isAtEnd();
static void start();
static void yLongSample();
static void xLongSample();
public:
/**
* Size in mm
* samplingResolution in encoder counts
*/
static void configure(float x, float y, float width, float height, int samplingResolution);
/**
* Size in mm
* samplingResolution in encoder counts
*/
static void configure2(float startX, float startY, float stopX, float stopY, int samplingResolution);
/**
* Point coordinates in encoder counts
* samplingResolution in encoder counts
*/
static void configure(Point points[4], int samplingResolution = Trigger::getThreshold());
static void sample();
};
#endif /* RECTANGLEZIGZAG_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/control_impl.h | /*
* control.cpp
*
* Created on: Nov 25, 2013
* Author: jonas
*/
#include "project.h"
#include "control.h"
#include "motor.h"
#include "hallSensor.h"
#include "securityController.h"
template<Axis axis>
class Motor;
template<Axis axis>
bool Control<axis>::init(){
Control<axis>::v_is = 0;
Control<axis>::v_shall = 0;
Control<axis>::last_pos = 0;
Control<axis>::positionControlEnabled = true;
Control<axis>::speedControlEnabled = true;
//param order: P, I, D, maxErrorSum, maxOutput
Control<axis>::pos_pid = xpcc::Pid<float, 1>(CONTROLX_KP, CONTROLX_KI, CONTROLX_KD,
CONTROLX_MAX_ERRORSUM, CONTROLX_MAX_OUTPUT);
Control<axis>::v_pid = xpcc::Pid<float, 1>(CONTROLV_KP, CONTROLV_KI, CONTROLV_KD,
CONTROLV_MAX_ERRORSUM, CONTROLV_MAX_OUTPUT);
return true;
}
template<Axis axis>
void Control<axis>::update(bool externalLimitation){
int enc = getIsPosition();
if(positionControlEnabled){
pos_pid.update(pos_shall - enc, externalLimitation);
v_shall = pos_pid.getValue();
/*if(abs(pos_shall - enc) <= CONTROLX_DEADBAND){
v_shall = 0;
}*/
}
v_is = (enc - last_pos)*CONTROL_FREQUENCY;
last_pos = enc;
if(speedControlEnabled){
v_pid.update(v_shall - v_is);
v_u = v_pid.getValue();
v_ureal = v_u;
SecurityController<axis>::saturate(v_ureal);
if((abs(pos_shall - enc) <= CONTROLX_DEADBAND && positionControlEnabled)
|| (!positionControlEnabled && abs(v_shall - v_is) < 1000)){
v_ureal = 0;
v_pid.reset();
pos_pid.reset();
}
Motor<axis>::setSpeed(v_ureal);
}
}
template<Axis axis>
void Control<axis>::setShallPosition(int position){
Control<ALL>::resetPosPid();
Control<ALL>::resetVPid();
pos_shall = position;
}
//max speed is 5500rpm*400 counts/rev
template<Axis axis>
void Control<axis>::setShallSpeed(double speed){
//disable position control
Control<ALL>::enablePositionControl(false);
if(speed > 1)
speed = 1;
if(speed < -1)
speed = -1;
v_shall = speed*MOTOR_MAX_SPEED;
}
template<Axis axis>
int Control<axis>::getSpeedErrorSum(){
return v_pid.getErrorSum();
}
template<Axis axis>
int Control<axis>::getPositionErrorSum(){
return pos_pid.getErrorSum();
}
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/state.h | <reponame>jrahlf/3D-Non-Contact-Laser-Profilometer
/*
* state.h
*
* Created on: Dec 30, 2013
* Author: jonas
*/
#ifndef STATE_H_
#define STATE_H_
class State{
public:
static const int INITIALIZING = 0x0;
static const int READY = 0x1;
static const int MOTOR_LIMITED = 0x1<<1;
static const int SCANNING_RECTANGLE = 0x1<<2;
static const int PC_INIT_FAIL = 0x1<<3;
static const int MOTOR1_FAULT = 0x1<<4;
static const int MOTOR2_FAULT = 0x1<<5;
/**
* This should be the very first function call
* after setting up the cpu frequency
*/
static void init();
/**
*
* @return the current state
*/
static int get(){
return currentState;
}
/**
* Sets the new state
* @param newState the new state
* TODO send message to PC in case of errors
*/
static void set(int newState);
static void setSecondaryState(int state, bool set);
static void setGreen(bool on);
static void setRed(bool on);
static void setBlue(bool on);
static void setOrange(bool on);
private:
static int currentState;
};
#endif /* STATE_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/atof.h | /*
* atof.h
*
* Created on: Jan 3, 2014
* Author: jonas
*/
#ifndef ATOF_H_
#define ATOF_H_
/**
* Takes a pointer to a string and converts the
* first number found into an int and returns it
* If the number is a fractional number, it is expected to
* have exactly 2 decimal digits. The value is multiplied by
* 1000 prior returning it
*
* @param p pointer to string
* @param stopPosition position where parsing was stopped due to non numerical character
* this is a pointer to the original string and can be reused to parse several arguments
* 0 can be passed if position is not needed
* @return Integer of string, if fractional 1000 times the value
*/
int atoi2(const char *p, const char** stopPosition);
/**
* Same as atoi2(const char *p), but scans by at most maxLen characters
* @param p pointer to string
* @param maxLen
* @param errorValue value which is returned if no number is found
* @return Integer of string, or errorValue
*/
int atoi2(const char *p, const int maxLen, const int errorValue);
/**
* @param p pointer to string
* @param maxLen
* @param errorValue value which is returned if no number is found
* @return float of string, or errorValue
*/
float atof2(const char *p, const int maxLen, const float errorValue);
/**
* @param p pointer to string
* @param maxLen
* @param errorValue value which is returned if no number is found
* @return float of string, or errorValue
*/
float atof2(const char *p, const char** stopPosition, const float errorValue);
#endif /* ATOF_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/Trigger.h | /*
* Trigger.h
*
* Created on: Jan 16, 2014
* Author: jonas
*/
#ifndef TRIGGER_H_
#define TRIGGER_H_
/**
* Used in conjunction with the laser and sends the current
* measurement + position if the stage moved by a certain threshold
*/
class Trigger {
private:
public:
/**
* Should be called from main loop at maximum frequency
*/
static void sample();
static void forceTrigger();
/**
* Sets a new threshold in encoder counts
* @param threshold
*/
static void setThreshold(int threshold);
static int getThreshold();
/**
* Enable or disables triggering
* @param enable
*/
static void enable(bool enable);
/**
* If disabled, only the position will be output
* @param enable
*/
static void enableMeasurementOutput(bool enable);
};
#endif /* TRIGGER_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/src/xpcc/architecture/platform/arm7/lpc/uart/uart_settings.h | <reponame>jrahlf/3D-Non-Contact-Laser-Profilometer
#ifndef UART_SETTINGS_H
#define UART_SETTINGS_H
#include "lpc24xx_registers.h"
/** Setup for UART-Interface ********************/
/* Settings for 250000 Baud (at 72 MHz)
* UxPCLK setCCLKD4
* UxDLLVAL 0x03
* UxDLMVAL 0x00
* UxDIVMUL 0x21
*
* Settings for 115200 Baud (at 72 MHz):
* UxPCLK setCCLKD4
* UxDLLVAL 0x08
* UxDLMVAL 0x00
* UxDIVMUL 0x92
*
* Settings for 57600 Baud (at 72 MHz):
* UxPCLK setCCLKD4
* UxDLLVAL 0x10
* UxDLMVAL 0x00
* UxDIVMUL 0x92
*
* Settings for 9600 Baud (at 72 MHz):
* UxPCLK setCCLKD4
* UxDLLVAL 0x5F
* UxDLMVAL 0x00
* UxDIVMUL 0xD3
*
* General (high error):
* U0DLL = ((CCLK * 1000000 / (BAUD*16))/(1+(2/9))) & 0xFF;
* UxDLM = (((CCLK * 1000000 / (BAUD*16))/(1+(2/9))) & 0xFF00)>>8;
* UxDIVMUL 0x92
*/
/** Setup for UART0 *****************************/
// => Debug interface (115200 Baud)
#define U0PCLK setCCLKD4 // pclk = CCLK/4 = 18 MHz
#define U0DIVMUL 0x92 // mulval & divaddval (Frac=0.22 s.b.)
#define U0DLLVAL 8 // Untere 8 Bit des Teilers
#define U0DLMVAL 0 // Obere 8 Bit des Teilers
#define U0MODE 3 // 8N1
/** Setup for UART1 *****************************/
// => MWS (250 kBaud)
#define U1PCLK setCCLKD4 // pclk = CCLK/4 = 18 MHz
#define U1DIVMUL 0x21 // mulval & divaddval (Frac=0.22 s.b.)
#define U1DLLVAL 3 // Untere 8 Bit des Teilers
#define U1DLMVAL 0 // Obere 8 Bit des Teilers
#define U1MODE 3 // 8N1
/** Setup for UART2 *****************************/
// => MWS (250 kBaud)
#define U2PCLK setCCLKD4 // pclk = CCLK/4 = 18 MHz
#define U2DIVMUL 0x21 // mulval & divaddval (Frac=0.22 s.b.)
#define U2DLLVAL 3 // Untere 8 Bit des Teilers
#define U2DLMVAL 0 // Obere 8 Bit des Teilers
#define U2MODE 3 // 8N1
/** Setup for UART3 *****************************/
// not used
#define U3PCLK setCCLKD4 // pclk = CCLK/4 = 18 MHz
#define U3DIVMUL 0x92 // mulval & divaddval (Frac=0.22 s.b.)
#define U3DLLVAL 8 // Untere 8 Bit des Teilers
#define U3DLMVAL 0 // Obere 8 Bit des Teilers
#define U3MODE 3 // 8N1
#endif // UART_SETTINGS_H
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/pcInterface.h | <filename>microcontroller/pcInterface.h
/*
* pcInterface.h
*
* Created on: Dec 30, 2013
* Author: jonas
*/
#ifndef PCINTERFACE_H_
#define PCINTERFACE_H_
#include "project.h"
#include "checksum.h"
#ifdef __arm__
#include <xpcc/architecture.hpp>
extern xpcc::stm32::BufferedUsart2 uart;
#endif
static const bool ENABLE_STREAMS = true;
struct Prefix{
static const char DEBUG = 'D';
static const char POSITION = 'P';
static const char MEASUREMENT = 'M';
static const char INFO = 'I';
static const char ERROR = 'E';
static const char COMMAND = 'C';
static const char CONTROL = 'K';
};
class PC{
public:
struct ucCommand{
constexpr static const char* FLUSH_DATA = "flush data";
};
/**
* Setup UART for communication
* Should be the first init function to call
* @return
*/
static bool init();
static void scanForCommands();
static void registerCommandHandler(const char* command, bool (*handler)(const char*, int));
struct Command {
const char* name;
bool (*handler)(const char*, int); //if true is returned, "ok - command" is printed on uart
};
static bool defaultHandler(const char*, int);
static Command* getCommand(const char* command);
};
#ifdef __arm__
/**
* Wrapper class to provide various streams
*/
template<char prefix, bool useChecksum, bool enable = ENABLE_STREAMS, int TEXT_BUFFER_SIZE = 300>
class Stream{
private:
static char text[TEXT_BUFFER_SIZE];
static int pos;
public:
static void flush();
static void writeMeasurement(char* measurement, int length);
static void write(char c);
static bool read(char &c){ (void)c; return false;}
static bool read(uint8_t &c){ (void)c; return false;}
private:
static void calcChecksum();
};
template<char prefix, bool useChecksum, bool enable, int TEXT_BUFFER_SIZE>
char Stream<prefix, useChecksum, enable, TEXT_BUFFER_SIZE>::text[TEXT_BUFFER_SIZE];
template<char prefix, bool useChecksum, bool enable, int TEXT_BUFFER_SIZE>
int Stream<prefix, useChecksum, enable, TEXT_BUFFER_SIZE>::pos;
template<char prefix, bool useChecksum, bool enable, int TEXT_BUFFER_SIZE>
void Stream<prefix, useChecksum, enable, TEXT_BUFFER_SIZE>::write(char c){
if(!enable){
return;
}
//if(prefix != 'M'){
if(pos == TEXT_BUFFER_SIZE-3){
text[pos++] = c;
//text[pos+1] = '\n';
//text[pos+2] = '\0';
flush();
return;
}
if(c == '\n'){
flush();
return;
}
text[pos++] = c;
/*}else{ //zero overhead version for measurement
//text[pos++] = c;
uart.write(c);
}*/
}
template<char prefix, bool useChecksum, bool enable, int TEXT_BUFFER_SIZE>
void Stream<prefix, useChecksum, enable, TEXT_BUFFER_SIZE>::flush(){
if(!enable){
return;
}
uart.write(prefix);
if(useChecksum){
calcChecksum();
}
uart.write(',');
const char* ptr = &text[0];
const char* end = &text[pos];
while(ptr != end){
uart.write(*ptr);
ptr++;
}
//coutRaw << " l: " << pos;
uart.write('\n');
pos = 0;
}
template<char prefix, bool useChecksum, bool enable, int TEXT_BUFFER_SIZE>
void Stream<prefix, useChecksum, enable, TEXT_BUFFER_SIZE>::calcChecksum(){
char check = Checksum::getFor(text, pos, prefix);
uart.write(check);
}
#endif
#endif /* PCINTERFACE_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | pc/pcDaemon2/debuglog.h | <filename>pc/pcDaemon2/debuglog.h
#ifndef DEBUGLOG_H
#define DEBUGLOG_H
#include <QMainWindow>
namespace Ui {
class debugLog;
}
class debugLog : public QMainWindow
{
Q_OBJECT
public:
Ui::debugLog *ui;
explicit debugLog(QWidget *parent = 0);
~debugLog();
public slots:
void append(QString);
private:
};
#endif // DEBUGLOG_H
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/linePattern.h | <gh_stars>1-10
/*
* linePattern.h
*
* Created on: Mar 7, 2014
* Author: jonas
*/
#ifndef LINEPATTERN_H_
#define LINEPATTERN_H_
#include "project.h"
class LinePattern{
public:
static void configure(Point points[2]);
static void sample();
};
#endif /* LINEPATTERN_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/hallSensor.h | /*
* hallSensor.h
*
* Created on: Dec 23, 2013
* Author: jonas
*/
#ifndef HALLSENSOR_H_
#define HALLSENSOR_H_
//#pragma GCC push_options
//#pragma GCC optimize ("O0")
#include "project.h"
#include "control.h"
template<Axis axis>
class HallSensor{
private:
static volatile bool triggered[2];
static volatile bool state[2]; //the real current state
static volatile int triggeredPosition[2];
GPIO__INPUT(XFRONT, E, 11);
GPIO__INPUT(XEND, E, 7);
GPIO__INPUT(YFRONT, D, 8);
GPIO__INPUT(YEND, D, 9);
public:
static bool init();
static bool isAtFront(){
return triggered[0];
}
static bool isAtEnd(){
return triggered[1];
}
static void clearFrontSensor(){
triggered[0] = false;
}
static void clearEndSensor(){
triggered[1] = false;
}
//get the real states
static bool getFrontState(){
if(axis == X){
return XFRONT::read();//state[0];
}else{
return YFRONT::read();
}
}
static bool getEndState(){
if(axis == X){
return XEND::read();//state[1];
}else{
return YEND::read();
}
}
//set real state, called by interrupt routine
//if new state is false, triggered will be set too
static void setFrontState(bool newState){
//state[0] = newState;
newState = !newState;
//dout << "setfront " << axis << " newstate " << newState << " -> front " << triggered[0] << endl;
if(newState){
triggered[0] = true;
triggeredPosition[0] = Control<axis>::getIsPosition();
}
}
static void setEndState(bool newState){
//state[1] = newState;
newState = !newState;
//dout << "setend " << axis << " newstate " << newState << " -> end " << triggered[1] << endl;
if(newState){
triggered[1] = true;
triggeredPosition[1] = Control<axis>::getIsPosition();
}
}
/**
* If the trigger is set and the axis has been moved
* by at least HALLSENSOR_HYSTERESIS, the trigger is unset
* @return returns true, if trigger is unset
*/
static bool checkFrontState();
/**
* If the trigger is set and the axis has been moved
* by at least HALLSENSOR_HYSTERESIS, the trigger is unset
* @return true, if trigger is unset
*/
static bool checkEndState();
};
template<Axis axis> volatile bool HallSensor<axis>::triggered[2];
template<Axis axis> volatile bool HallSensor<axis>::state[2];
template<Axis axis> volatile int HallSensor<axis>::triggeredPosition[2];
template<> bool HallSensor<ALL>::init();
#include "hallSensor_impl.h"
//#pragma GCC pop_options
#endif /* HALLSENSOR_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/ext/lpc11xx/cmsis/system_LPC11xx.c | /**************************************************************************//**
* $Id:: $
*
* @file system_LPC11xx.c
* @brief CMSIS Cortex-M0 Device Peripheral Access Layer Source File
* for the NXP LPC11xx Device Series
* @version V1.00
* @date 17. November 2009
*
* @note
* Copyright (C) 2009 ARM Limited. All rights reserved.
*
* @par
* ARM Limited (ARM) is supplying this software for use with Cortex-M
* processor based microcontrollers. This file can be freely distributed
* within development tools that are supporting such ARM based processors.
*
* @par
* THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
* OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
* ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
* CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
*
******************************************************************************/
#include <stdint.h>
#include <xpcc_config.hpp>
#include "LPC11xx.h"
/*----------------------------------------------------------------------------
Check the register settings
*----------------------------------------------------------------------------*/
#define CHECK_RANGE(val, min, max) ((val < min) || (val > max))
#define CHECK_RSVD(val, mask) (val & mask)
/* Clock Configuration -------------------------------------------------------*/
#if (CHECK_RSVD((SYSOSCCTRL_Val), ~0x00000003))
#error "SYSOSCCTRL: Invalid values of reserved bits!"
#endif
#if (CHECK_RSVD((WDTOSCCTRL_Val), ~0x000001FF))
#error "WDTOSCCTRL: Invalid values of reserved bits!"
#endif
#if (CHECK_RANGE((SYSPLLCLKSEL_Val), 0, 2))
#error "SYSPLLCLKSEL: Value out of range!"
#endif
#if (CHECK_RSVD((SYSPLLCTRL_Val), ~0x000001FF))
#error "SYSPLLCTRL: Invalid values of reserved bits!"
#endif
#if (CHECK_RSVD((MAINCLKSEL_Val), ~0x00000003))
#error "MAINCLKSEL: Invalid values of reserved bits!"
#endif
#if (CHECK_RANGE((SYSAHBCLKDIV_Val), 0, 255))
#error "SYSAHBCLKDIV: Value out of range!"
#endif
#if (CHECK_RSVD((AHBCLKCTRL_Val), ~0x0001FFFF))
#error "AHBCLKCTRL: Invalid values of reserved bits!"
#endif
#if (CHECK_RANGE((SSP0CLKDIV_Val), 0, 255))
#error "SSP0CLKDIV: Value out of range!"
#endif
#if (CHECK_RANGE((UARTCLKDIV_Val), 0, 255))
#error "UARTCLKDIV: Value out of range!"
#endif
#if (CHECK_RANGE((SSP1CLKDIV_Val), 0, 255))
#error "SSP1CLKDIV: Value out of range!"
#endif
#if (CHECK_RSVD((SYSMEMREMAP_Val), ~0x00000003))
#error "SYSMEMREMAP: Invalid values of reserved bits!"
#endif
#ifndef MEMMAP_INIT
# define MEMMAP_INIT 0
#endif
/*----------------------------------------------------------------------------
DEFINES
*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------
Define clocks
*----------------------------------------------------------------------------*/
#define __XTAL (12000000UL) /* Oscillator frequency */
#define __SYS_OSC_CLK ( __XTAL) /* Main oscillator frequency */
#define __IRC_OSC_CLK (12000000UL) /* Internal RC oscillator frequency */
#define __FREQSEL ((WDTOSCCTRL_Val >> 5) & 0x0F)
#define __DIVSEL (((WDTOSCCTRL_Val & 0x1F) << 1) + 2)
#if (CLOCK_SETUP) /* Clock Setup */
#if (SYSCLK_SETUP) /* System Clock Setup */
#if (WDTOSC_SETUP) /* Watchdog Oscillator Setup*/
#if (__FREQSEL == 0)
#define __WDT_OSC_CLK ( 400000 / __DIVSEL)
#elif (__FREQSEL == 1)
#define __WDT_OSC_CLK ( 500000 / __DIVSEL)
#elif (__FREQSEL == 2)
#define __WDT_OSC_CLK ( 800000 / __DIVSEL)
#elif (__FREQSEL == 3)
#define __WDT_OSC_CLK (1100000 / __DIVSEL)
#elif (__FREQSEL == 4)
#define __WDT_OSC_CLK (1400000 / __DIVSEL)
#elif (__FREQSEL == 5)
#define __WDT_OSC_CLK (1600000 / __DIVSEL)
#elif (__FREQSEL == 6)
#define __WDT_OSC_CLK (1800000 / __DIVSEL)
#elif (__FREQSEL == 7)
#define __WDT_OSC_CLK (2000000 / __DIVSEL)
#elif (__FREQSEL == 8)
#define __WDT_OSC_CLK (2200000 / __DIVSEL)
#elif (__FREQSEL == 9)
#define __WDT_OSC_CLK (2400000 / __DIVSEL)
#elif (__FREQSEL == 10)
#define __WDT_OSC_CLK (2600000 / __DIVSEL)
#elif (__FREQSEL == 11)
#define __WDT_OSC_CLK (2700000 / __DIVSEL)
#elif (__FREQSEL == 12)
#define __WDT_OSC_CLK (2900000 / __DIVSEL)
#elif (__FREQSEL == 13)
#define __WDT_OSC_CLK (3100000 / __DIVSEL)
#elif (__FREQSEL == 14)
#define __WDT_OSC_CLK (3200000 / __DIVSEL)
#else
#define __WDT_OSC_CLK (3400000 / __DIVSEL)
#endif
#else
#define __WDT_OSC_CLK (1600000 / 2)
#endif // WDTOSC_SETUP
/* sys_pllclkin calculation */
#if ((SYSPLLCLKSEL_Val & 0x03) == 0)
#define __SYS_PLLCLKIN (__IRC_OSC_CLK)
#elif ((SYSPLLCLKSEL_Val & 0x03) == 1)
#define __SYS_PLLCLKIN (__SYS_OSC_CLK)
#elif ((SYSPLLCLKSEL_Val & 0x03) == 2)
#define __SYS_PLLCLKIN (__WDT_OSC_CLK)
#else
#define __SYS_PLLCLKIN (0)
#endif
#if (SYSPLL_SETUP) /* System PLL Setup */
#define __SYS_PLLCLKOUT (__SYS_PLLCLKIN * ((SYSPLLCTRL_Val & 0x01F) + 1))
#else
#define __SYS_PLLCLKOUT (__SYS_PLLCLKIN * (1))
#endif // SYSPLL_SETUP
/* main clock calculation */
#if ((MAINCLKSEL_Val & 0x03) == 0)
#define __MAIN_CLOCK (__IRC_OSC_CLK)
#elif ((MAINCLKSEL_Val & 0x03) == 1)
#define __MAIN_CLOCK (__SYS_PLLCLKIN)
#elif ((MAINCLKSEL_Val & 0x03) == 2)
#define __MAIN_CLOCK (__WDT_OSC_CLK)
#elif ((MAINCLKSEL_Val & 0x03) == 3)
#define __MAIN_CLOCK (__SYS_PLLCLKOUT)
#else
#define __MAIN_CLOCK (0)
#endif
#define __SYSTEM_CLOCK (__MAIN_CLOCK / SYSAHBCLKDIV_Val)
#else // SYSCLK_SETUP
#if (SYSAHBCLKDIV_Val == 0)
#define __SYSTEM_CLOCK (0)
#else
#define __SYSTEM_CLOCK (__XTAL / SYSAHBCLKDIV_Val)
#endif
#endif // SYSCLK_SETUP
#else
#define __SYSTEM_CLOCK (__XTAL)
#endif // CLOCK_SETUP
/*----------------------------------------------------------------------------
Clock Variable definitions
*----------------------------------------------------------------------------*/
uint32_t SystemCoreClock = __SYSTEM_CLOCK;/*!< System Clock Frequency (Core Clock)*/
#if CONFIG_ENABLE_CMSIS_SYSTEMCORECLOCKUPDATE==1 || !defined(CONFIG_ENABLE_CMSIS_SYSTEMCORECLOCKUPDATE)
/*----------------------------------------------------------------------------
Clock functions
*----------------------------------------------------------------------------*/
void SystemCoreClockUpdate (void) /* Get Core Clock Frequency */
{
uint32_t wdt_osc = 0;
/* Determine clock frequency according to clock register values */
switch ((LPC_SYSCON->WDTOSCCTRL >> 5) & 0x0F) {
case 0: wdt_osc = 400000; break;
case 1: wdt_osc = 500000; break;
case 2: wdt_osc = 800000; break;
case 3: wdt_osc = 1100000; break;
case 4: wdt_osc = 1400000; break;
case 5: wdt_osc = 1600000; break;
case 6: wdt_osc = 1800000; break;
case 7: wdt_osc = 2000000; break;
case 8: wdt_osc = 2200000; break;
case 9: wdt_osc = 2400000; break;
case 10: wdt_osc = 2600000; break;
case 11: wdt_osc = 2700000; break;
case 12: wdt_osc = 2900000; break;
case 13: wdt_osc = 3100000; break;
case 14: wdt_osc = 3200000; break;
case 15: wdt_osc = 3400000; break;
}
wdt_osc /= ((LPC_SYSCON->WDTOSCCTRL & 0x1F) << 1) + 2;
switch (LPC_SYSCON->MAINCLKSEL & 0x03) {
case 0: /* Internal RC oscillator */
SystemCoreClock = __IRC_OSC_CLK;
break;
case 1: /* Input Clock to System PLL */
switch (LPC_SYSCON->SYSPLLCLKSEL & 0x03) {
case 0: /* Internal RC oscillator */
SystemCoreClock = __IRC_OSC_CLK;
break;
case 1: /* System oscillator */
SystemCoreClock = __SYS_OSC_CLK;
break;
case 2: /* WDT Oscillator */
SystemCoreClock = wdt_osc;
break;
case 3: /* Reserved */
SystemCoreClock = 0;
break;
}
break;
case 2: /* WDT Oscillator */
SystemCoreClock = wdt_osc;
break;
case 3: /* System PLL Clock Out */
switch (LPC_SYSCON->SYSPLLCLKSEL & 0x03) {
case 0: /* Internal RC oscillator */
if (LPC_SYSCON->SYSPLLCTRL & 0x180) {
SystemCoreClock = __IRC_OSC_CLK;
} else {
SystemCoreClock = __IRC_OSC_CLK * ((LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1);
}
break;
case 1: /* System oscillator */
if (LPC_SYSCON->SYSPLLCTRL & 0x180) {
SystemCoreClock = __SYS_OSC_CLK;
} else {
SystemCoreClock = __SYS_OSC_CLK * ((LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1);
}
break;
case 2: /* WDT Oscillator */
if (LPC_SYSCON->SYSPLLCTRL & 0x180) {
SystemCoreClock = wdt_osc;
} else {
SystemCoreClock = wdt_osc * ((LPC_SYSCON->SYSPLLCTRL & 0x01F) + 1);
}
break;
case 3: /* Reserved */
SystemCoreClock = 0;
break;
}
break;
}
SystemCoreClock /= LPC_SYSCON->SYSAHBCLKDIV;
LPC_SYSCON->SYSTCKCAL = (SystemCoreClock / 100) - 1;
}
#else
void SystemCoreClockUpdate (void) /* Get Core Clock Frequency */
{
SystemCoreClock = CONFIG_CMSIS_SET_SYSTEMCORECLOCK_DEFAULT;
}
#endif
#if CONFIG_ENABLE_CMSIS_SYSTEMINIT==1 || !defined(CONFIG_ENABLE_CMSIS_SYSTEMINIT)
/**
* Initialize the system
*
* @param none
* @return none
*
* @brief Setup the microcontroller system.
* Initialize the System.
*/
void SystemInit (void)
{
#if CORTEX_VECTORS_RAM
// Then assume need to map vectors to RAM
LPC_SYSCON->SYSMEMREMAP = ((LPC_SYSCON->SYSMEMREMAP)& ~3) | 1;
#else
// LPC_SYSCON->SYSMEMREMAP |= 3; // Map to flash
#endif
#if (CLOCK_SETUP) /* Clock Setup */
#if (SYSCLK_SETUP) /* System Clock Setup */
#if (SYSOSC_SETUP) /* System Oscillator Setup */
uint32_t i;
LPC_SYSCON->PDRUNCFG &= ~(1 << 5); /* Power-up System Osc */
LPC_SYSCON->SYSOSCCTRL = SYSOSCCTRL_Val;
for (i = 0; i < 200; i++) __NOP();
LPC_SYSCON->SYSPLLCLKSEL = SYSPLLCLKSEL_Val; /* Select PLL Input */
LPC_SYSCON->SYSPLLCLKUEN = 0x01; /* Update Clock Source */
LPC_SYSCON->SYSPLLCLKUEN = 0x00; /* Toggle Update Register */
LPC_SYSCON->SYSPLLCLKUEN = 0x01;
while (!(LPC_SYSCON->SYSPLLCLKUEN & 0x01)); /* Wait Until Updated */
#if (SYSPLL_SETUP) /* System PLL Setup */
LPC_SYSCON->SYSPLLCTRL = SYSPLLCTRL_Val;
LPC_SYSCON->PDRUNCFG &= ~(1 << 7); /* Power-up SYSPLL */
while (!(LPC_SYSCON->SYSPLLSTAT & 0x01)); /* Wait Until PLL Locked */
#endif
#endif
#if (WDTOSC_SETUP) /* Watchdog Oscillator Setup*/
LPC_SYSCON->WDTOSCCTRL = WDTOSCCTRL_Val;
LPC_SYSCON->PDRUNCFG &= ~(1 << 6); /* Power-up WDT Clock */
#endif
LPC_SYSCON->MAINCLKSEL = MAINCLKSEL_Val; /* Select PLL Clock Output */
LPC_SYSCON->MAINCLKUEN = 0x01; /* Update MCLK Clock Source */
LPC_SYSCON->MAINCLKUEN = 0x00; /* Toggle Update Register */
LPC_SYSCON->MAINCLKUEN = 0x01;
while (!(LPC_SYSCON->MAINCLKUEN & 0x01)); /* Wait Until Updated */
#endif
LPC_SYSCON->SYSAHBCLKDIV = SYSAHBCLKDIV_Val;
LPC_SYSCON->SYSAHBCLKCTRL = AHBCLKCTRL_Val;
LPC_SYSCON->SSP0CLKDIV = SSP0CLKDIV_Val;
LPC_SYSCON->UARTCLKDIV = UARTCLKDIV_Val;
LPC_SYSCON->SSP1CLKDIV = SSP1CLKDIV_Val;
#endif
#if (MEMMAP_SETUP || MEMMAP_INIT) /* Memory Mapping Setup */
LPC_SYSCON->SYSMEMREMAP = SYSMEMREMAP_Val;
#endif
SystemCoreClockUpdate();
}
#else
void SystemInit (void)
{
SystemCoreClockUpdate();
}
#endif
|
jrahlf/3D-Non-Contact-Laser-Profilometer | pc/pcDaemon2/slantCorrection.h | <gh_stars>1-10
#pragma once
#include <string>
namespace SlantCorrect{
bool init(std::string);
void correct(double x, double y, double& z);
}
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/project.h | <filename>microcontroller/project.h
/*
* project.h
*
* Created on: Dec 29, 2013
* Author: jonas
*/
#ifndef PROJECT_H_
#define PROJECT_H_
enum Axis{
X = 0,
Y = 2,
Z = 4, //unused
ALL
};
struct Point{
int x,y;
};
#ifdef __arm__
#include <xpcc/architecture.hpp>
/**
* position-out, similar to mout, but only contains position data
* Prefix character: P
*/
extern xpcc::IOStream pout;
/**
* measurement-out, for sending measurement data to computer
* Prefix character: M
* Raw stream like coutRaw, to reduce latency and prevent inconsistency
* between position and measurement
*/
extern xpcc::IOStream mout;
/**
* debug-out, for printing debug statements
* should be disabled for final software
* Prefix character: D
*/
extern xpcc::IOStream dout;
/**
* for error logging
* Prefix character: E
*/
extern xpcc::IOStream cerr;
/**
* INFO-out, for printing important informations
* and for printing requested values (e.g. getLaserError)
* Prefix character: I
*/
extern xpcc::IOStream iout;
/**
* COMMAND-out, for sending commands from microcontroller
* to computer
* Prefix character: C
*/
extern xpcc::IOStream commandOut;
/**
* CONTROL-out, for dumping position/velocity control
* Prefix character: K
*/
extern xpcc::IOStream controlOut;
/**
* for debugging, no prefix
* Not to be used with final software
*/
extern xpcc::IOStream coutRaw;
#endif
#define endl '\n'
// --------------------------------------------------------------------
// Motor related constants
// --------------------------------------------------------------------
const int MOTOR_RPM = 5500;
const int MOTOR_ENC_PER_REV = 400;
const int MOTOR_GEAR_RATIO = 5;
//datasheet: 36666
//experimental: 49000
const int MOTOR_MAX_SPEED = 49000; //encoder counts per second
#define MOTOR_MAX_VOLTAGE 12
// --------------------------------------------------------------------
// CONTROL RELATED CONSTANTS
// CONTROLX refers to position control
// --------------------------------------------------------------------
#define CONTROL_FREQUENCY 1000
const float CONTROLV_KP = 0.2f;
const float CONTROLV_KI = 0.1f;
const float CONTROLV_KD = 0;
const float CONTROLV_MAX_OUTPUT = 1200;
const float CONTROLV_MAX_ERRORSUM = MOTOR_MAX_SPEED/5;
const float CONTROLX_KP = 10.0f;
const float CONTROLX_KI = 0.1f;
const float CONTROLX_KD = 0.3f;
const float CONTROLX_MAX_OUTPUT = MOTOR_MAX_SPEED;
const float CONTROLX_MAX_ERRORSUM = MOTOR_ENC_PER_REV*10;
const int CONTROLX_DEADBAND = 0;
// --------------------------------------------------------------------
// Rectangle zig-zag pattern related constants
// --------------------------------------------------------------------
const int RECTANGLE_ZIGZAG_THRESHOLD = CONTROLX_DEADBAND+1;
const int RECTANGLE_ZIGZAG_TIMEOUT = 500; //[ms]
// --------------------------------------------------------------------
// Security controller related constants
// --------------------------------------------------------------------
#define HALLSENSOR_HYSTERESIS 5000
// --------------------------------------------------------------------
// Laser interface related constants
// --------------------------------------------------------------------
#define LASER_INPUT_BUFFER_SIZE 50
#define INVALID_MEASUREMENT_STRING "9000"
#define USE_LASER_DMA 0
// --------------------------------------------------------------------
// X-Y stage related constants
// --------------------------------------------------------------------
//TODO
const int YSTAGE_LENGTH_MM = 100;
const int XSTAGE_LENGTH_MM = 100;
const int XSTAGE_LENGTH_ENCODER = XSTAGE_LENGTH_MM*MOTOR_ENC_PER_REV*MOTOR_GEAR_RATIO;
const int YSTAGE_LENGTH_ENCODER = YSTAGE_LENGTH_MM*MOTOR_ENC_PER_REV*MOTOR_GEAR_RATIO;
#endif /* PROJECT_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/tools/bootloader/can/at90can/main.c | <filename>xpcc/tools/bootloader/can/at90can/main.c
// coding: utf-8
// ----------------------------------------------------------------------------
/* Copyright (c) 2010, Roboterclub Aachen e.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Roboterclub Aachen e.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// ----------------------------------------------------------------------------
/**
* \brief CAN Bootloader
*
*
* \author <NAME> <<EMAIL>>
* \author <NAME>
*/
// ----------------------------------------------------------------------------
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/boot.h>
#include <avr/eeprom.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "utils.h"
#include "defaults.h"
#include "at90can.h"
#define MESSAGE_NUMBER message_number
#define MESSAGE_DATA_COUNTER message_data_counter
#define MESSAGE_DATA_LENGH message_data_length
#define MESSAGE_DATA(x) message_data[x]
// ----------------------------------------------------------------------------
// globale Variablen
static uint16_t flashpage = 0;
static uint8_t page_buffer_pos = 0;
static uint8_t page_buffer[SPM_PAGESIZE];
// -----------------------------------------------------------------------------
// Watchdog Timer als erstes im Programm deaktivieren
// siehe http://www.nongnu.org/avr-libc/user-manual/group__avr__watchdog.html
void
disable_watchdog(void) \
__attribute__((naked)) \
__attribute__((section(".init3")));
void
disable_watchdog(void)
{
// Save MCUSR so that the main program can access if later
GPIOR0 = MCUSR;
MCUSR = 0;
wdt_disable();
}
// ----------------------------------------------------------------------------
/**
* \brief starts the application program
*/
void
boot_jump_to_application(void)
{
// relocate interrupt vectors
uint8_t reg = MCUCR & ~((1 << IVCE) | (1 << IVSEL));
MCUCR = reg | (1 << IVCE);
MCUCR = reg;
// reset SPI interface to power-up state
SPCR = 0;
SPSR = 0;
#if FLASHEND > 0xffff
__asm__ __volatile__(
"push __zero_reg__" "\n\t"
"push __zero_reg__" "\n\t"
"push __zero_reg__" "\n\t");
#else
__asm__ __volatile__(
"push __zero_reg__" "\n\t"
"push __zero_reg__" "\n\t");
#endif
// when the functions executes the 'ret' command to return to
// its origin the AVR loads the return address from the stack. Because we
// pushed null it instead jumps to address null which starts the main
// application.
}
// ----------------------------------------------------------------------------
/**
* \brief write a complete page to the flash memorey
*
* \param page page which should be written
* \param *buf Pointer to the buffer with the data
*
* \see avr-libc Documentation > Modules > Bootloader Support Utilities
*/
void
boot_program_page(uint16_t page, uint8_t *buf)
{
uint32_t adr = page * SPM_PAGESIZE;
boot_page_erase(adr);
boot_spm_busy_wait(); // Wait until the memory is erased.
for (uint16_t i=0; i < SPM_PAGESIZE; i+=2)
{
// Set up little-endian word.
uint16_t w = *buf++;
w += (*buf++) << 8;
boot_page_fill(adr + i, w);
}
boot_page_write(adr); // Store buffer in flash page.
boot_spm_busy_wait(); // Wait until the memory is written.
// Reenable RWW-section again. We need this if we want to jump back
// to the application after bootloading.
boot_rww_enable();
}
// ----------------------------------------------------------------------------
int
main(void) __attribute__((OS_main));
int
main(void)
{
enum {
IDLE,
COLLECT_DATA,
RECEIVED_PAGE
} state = IDLE;
uint8_t next_message_number = -1;
// do some addition initialization
BOOT_INIT;
BOOT_LED_SET_OUTPUT;
BOOT_LED_ON;
// Relocate interrupt vectors to boot area
MCUCR = (1 << IVCE);
MCUCR = (1 << IVSEL);
at90can_init();
// start timer
TCNT1 = TIMER_PRELOAD;
TCCR1A = 0;
TCCR1B = TIMER_PRESCALER;
// clear overflow-flag
TIMER_INTERRUPT_FLAG_REGISTER = (1 << TOV1);
sei();
while (1)
{
uint8_t command;
uint16_t page;
static uint8_t next_message_data_counter;
// wait until we receive a new message
while ((command = at90can_get_message()) == NO_MESSAGE)
{
if (TIMER_INTERRUPT_FLAG_REGISTER & (1 << TOV1))
{
BOOT_LED_OFF;
// timeout => start application
boot_jump_to_application();
}
}
// stop timer
TCCR1B = 0;
// check if the message is a request, otherwise reject it
if ((command & ~COMMAND_MASK) != REQUEST)
continue;
command &= COMMAND_MASK;
// check message number
next_message_number++;
if (message_number != next_message_number)
{
// wrong message number => send NACK
message_number = next_message_number;
next_message_number--;
at90can_send_message(command | WRONG_NUMBER_REPSONSE, 0);
continue;
}
BOOT_LED_TOGGLE;
// process command
switch (command)
{
case IDENTIFY:
// version and command of the bootloader
message_data[0] = (BOOTLOADER_TYPE << 4) | (BOOTLOADER_VERSION & 0x0f);
message_data[1] = PAGESIZE_IDENTIFIER;
// number of writeable pages
message_data[2] = HIGH_BYTE(RWW_PAGES);
message_data[3] = LOW_BYTE(RWW_PAGES);
at90can_send_message(IDENTIFY | SUCCESSFULL_RESPONSE, 4);
break;
// --------------------------------------------------------------------
// set the current address in the page buffer
case SET_ADDRESS:
page = (message_data[0] << 8) | message_data[1];
if (message_data_length == 4 &&
message_data[2] < (SPM_PAGESIZE / 4) &&
page < RWW_PAGES)
{
flashpage = page;
page_buffer_pos = message_data[3];
state = COLLECT_DATA;
at90can_send_message(SET_ADDRESS | SUCCESSFULL_RESPONSE, 4);
}
else {
goto error_response;
}
break;
// --------------------------------------------------------------------
// collect data
case DATA:
if (message_data_length != 4 ||
page_buffer_pos >= (SPM_PAGESIZE / 4) ||
state == IDLE) {
state = IDLE;
goto error_response;
}
// check if the message starts a new block
if (message_data_counter & START_OF_MESSAGE_MASK)
{
message_data_counter &= ~START_OF_MESSAGE_MASK; // clear flag
next_message_data_counter = message_data_counter;
state = COLLECT_DATA;
}
if (message_data_counter != next_message_data_counter) {
state = IDLE;
goto error_response;
}
next_message_data_counter--;
// copy data
memcpy(page_buffer + page_buffer_pos * 4, &message_data[0], 4);
page_buffer_pos++;
if (message_data_counter == 0)
{
if (page_buffer_pos == (SPM_PAGESIZE / 4))
{
message_data[0] = flashpage >> 8;
message_data[1] = flashpage & 0xff;
if (flashpage >= RWW_PAGES) {
message_data_length = 2;
goto error_response;
}
boot_program_page( flashpage, page_buffer );
page_buffer_pos = 0;
flashpage += 1;
// send ACK
at90can_send_message(DATA | SUCCESSFULL_RESPONSE, 2);
}
else {
at90can_send_message(DATA | SUCCESSFULL_RESPONSE, 0);
}
}
break;
// --------------------------------------------------------------------
// start the flashed application program
case START_APP:
at90can_send_message(START_APP | SUCCESSFULL_RESPONSE, 0);
// wait for the mcp2515 to send the message
_delay_ms(50);
// start application
BOOT_LED_OFF;
boot_jump_to_application();
break;
#if BOOTLOADER_TYPE > 0
// --------------------------------------------------------------------
case GET_FUSEBITS:
message_data[0] = boot_lock_fuse_bits_get(GET_LOCK_BITS);
message_data[1] = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
message_data[2] = boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS);
message_data[3] = boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS);
at90can_send_message(GET_FUSEBITS | SUCCESSFULL_RESPONSE, 4);
break;
// --------------------------------------------------------------------
case CHIP_ERASE:
// erase complete flash except the bootloader region
for (uint16_t i = 0; i < RWW_PAGES; i++ )
{
uint32_t adr = i * SPM_PAGESIZE;
boot_page_erase( adr );
boot_spm_busy_wait();
}
boot_rww_enable();
at90can_send_message(CHIP_ERASE | SUCCESSFULL_RESPONSE, 0);
break;
// Lese 1..6 Byte aus dem EEprom
case READ_EEPROM:
if (message_length == 5 && MESSAGE_DATA[4] > 0 && MESSAGE_DATA[4] <= 6)
{
uint16_t ee_ptr = (MESSAGE_DATA[2] << 8) | MESSAGE_DATA[3];
if (ee_ptr <= E2END) {
message_length = MESSAGE_DATA[4] + 2;
eeprom_read_block(MESSAGE_DATA + 2, (void *) ee_ptr, MESSAGE_DATA[4]);
break;
}
}
response = NACK;
break;
// schreibe 1..4 Byte ins EEprom
case WRITE_EEPROM:
if (message_length > 4) {
uint16_t ee_ptr = (MESSAGE_DATA[2] << 8) | MESSAGE_DATA[3];
if (ee_ptr <= E2END) {
eeprom_write_block(MESSAGE_DATA + 4, (void *) ee_ptr, message_length - 4);
response = ACK;
break;
}
}
response = NACK;
break;
// Lese 1..65556 Byte aus dem Flash. Bei mehr als 6 Zeichen
// wird das Ergebniss auf mehrere Nachrichten verteilt.
case READ_FLASH:
if (message_length == 6)
{
uint16_t flash_ptr = (MESSAGE_DATA[2] << 8) | MESSAGE_DATA[3];
if (flash_ptr <= FLASHEND)
{
uint16_t number = (MESSAGE_DATA[4] << 8) | MESSAGE_DATA[5];
// Anzahl der zu senden Nachrichten bestimmen
div_t r = div(number, 6);
number = r.quot;
if (r.rem > 0)
number += 1;
uint16_t counter = 0;
for (uint16_t i=0;i<number;i++)
{
if (i == r.quot)
// das letze Paket ist eventl. kuerzer
message_length = r.rem;
else
message_length = 6;
// FIXME
//memcpy_P( MESSAGE_DATA + 2, (PGM_VOID_P) flash_ptr, message_length );
flash_ptr += message_length;
MESSAGE_DATA[1] = counter;
counter = (counter + 1) & 0x3f;
// Nachricht verschicken
at90can_send_message(0);
}
response = ACK;
break;
}
}
response = NACK;
break;
#endif
error_response:
default:
at90can_send_message(command | ERROR_RESPONSE, message_data_length);
break;
}
}
}
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/pattern.h | /*
* pattern.h
*
* Created on: Jan 18, 2014
* Author: jonas
*/
#ifndef PATTERN_H_
#define PATTERN_H_
#include "control.h"
#include "project.h"
#include "state.h"
#include "pcInterface.h"
class QuadrangleZigZag;
class Pattern{
static void (*func)(void);
static bool running;
static bool paused;
public:
template<class T>
static void setPattern(T pattern, float maxSpeed = 1){
(void)pattern;
//Control<ALL>::setMaxSpeed(maxSpeed);
func = &T::sample;
}
static void follow(){
if(!running || func == 0){
return;
}
func();
}
static void pause(){
running = false;
paused = true;
}
static void start(){
running = true;
paused = false;
State::set(State::SCANNING_RECTANGLE);
dout << "Pattern start" << endl;
commandOut << PC::ucCommand::FLUSH_DATA << endl;
}
static void resume(){
running = true;
/*if(!paused){
start();
}*/
paused = false;
}
static void done(){
running = 0;
State::set(State::READY);
dout << "Pattern done" << endl;
}
static int isRunning(){
return running && !paused;
}
};
#endif /* PATTERN_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/laserInterface.h | <filename>microcontroller/laserInterface.h
/*
* laserInterface.h
*
* Created on: Dec 30, 2013
* Author: jonas
*/
#ifndef LASERINTERFACE_H_
#define LASERINTERFACE_H_
#include "project.h"
class Laser{
public:
class DoubleBuffer{
public:
static unsigned char buf1[LASER_INPUT_BUFFER_SIZE+1];
static unsigned char buf2[LASER_INPUT_BUFFER_SIZE+1];
//swap pointers instead of copying
static unsigned char* bufInPtr;
static unsigned char* bufOutPtr;
static int inSize;
static int outSize;
public:
static inline int getInSize(){
return inSize;
}
static inline void addChar(unsigned char c){
bufInPtr[inSize] = c;
inSize++;
}
static inline unsigned char* inPtr(){
return bufInPtr;
}
static inline unsigned char* outPtr(){
return bufOutPtr;
}
/**
* Returns outPtr as an integer
* @return the current measurement in nm
*/
static int asInt();
/**
* Also resets input buffer and adds trailing
* null byte to new output buffer
*/
static inline void swap(){
unsigned char* temp = bufInPtr;
bufInPtr = bufOutPtr;
bufOutPtr = temp;
bufOutPtr[inSize] = '\0';
outSize = inSize;
inSize = 0;
}
static inline void reset(){
inSize = 0;
}
static char* get(){
return (char*)bufOutPtr;
}
static int good();
};
public:
static bool init();
static int getLastError();
static void enableRequests();
static void disableRequests();
static void sendString(const char* cmd);
static const char* exec(const char* cmd);
static const char* getMeasurement();
static void handleChar(char c);
static void sendMeasurementRequest();
};
#endif /* LASERINTERFACE_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/commandHandlers.h | /*
* commandHandlers.h
*
* Created on: Jan 23, 2014
* Author: jonas
*/
#ifndef COMMANDHANDLERS_H_
#define COMMANDHANDLERS_H_
#include <xpcc/architecture.hpp>
#include "project.h"
#include "control.h"
#include "atof.h"
#include "limits.h"
#include "transform.h"
#include "motor.h"
#include "laserInterface.h"
#include "Trigger.h"
#include "../ext/stm32f4xx_lib/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h"
#include "utils.h"
#include "pattern.h"
#include "rectangle.h"
#include "quadrangleZigZag.h"
#include "linePattern.h"
struct Handlers{
template<Axis axis>
static bool gotoHandler(const char* cmd, int length){
float pos = atof2(cmd, length, 99999.0f);
if(pos == 99999.0f){
return false;
}
Utils::startLoggingControl();
pos = Transform::mmToEncoder(pos);
Control<ALL>::enablePositionControl(true);
Control<axis>::setShallPosition(pos);
dout << axis << " going to " << pos << endl;
return true;
}
template<Axis axis>
static bool moveHandler(const char* cmd, int length){
float pos = atof2(cmd, length, 99999.0f);
if(pos == 99999.0f){
return false;
}
Utils::startLoggingControl();
pos = Transform::mmToEncoder(pos);
Control<ALL>::enablePositionControl(true);
pos = Control<axis>::getIsPosition() + pos;
Control<axis>::setShallPosition(pos);
dout << axis << " going to " << pos << endl;
return true;
}
template<Axis axis>
static bool setSpeedHandler(const char* cmd, int length){
float speed = atof2(cmd, length, 2.f);
if(speed == 2.f){
cerr << "speed param must be between -1 and 1" << endl;
return false;
}
Utils::startLoggingControl();
Control<ALL>::enablePositionControl(false);
Control<ALL>::enableSpeedControl(true);
Control<axis>::setShallSpeed(speed);
//dout << axis << " set speed to " << speed << endl;
return true;
}
static bool setMaxSpeedHandler(const char* cmd, int length){
float speed = atof2(cmd, length, 2.f);
if(speed == 2.f){
cerr << "speed param must be between 0 and 1" << endl;
return false;
}
Control<ALL>::setMaxSpeed(speed);
dout << " set speed to " << speed << endl;
return true;
}
template<Axis axis>
static bool setPwmHandler(const char* cmd, int length){
int speed = atoi2(cmd, length, INT_MAX);
if(speed == INT_MAX){
return false;
}
xpcc::stm32::SysTickTimer::enable();
xpcc::delay_ms(5);
if(speed > 1200){
speed = 1200;
}else if(speed < -1200){
speed = -1200;
}
Control<ALL>::enablePositionControl(false);
Control<ALL>::enableSpeedControl(false);
Motor<axis>::setSpeed(speed);
dout << axis << " set pwm to " << speed << endl;
return true;
}
static bool enableSystickHandler(const char* cmd, int length){
(void) cmd;
(void) length;
bool enable = atoi2(cmd, 1, 1);
if(enable){
Utils::enableSystick();
}else{
Utils::disableSystick();
}
dout << "systick enable " << enable << endl;
return true;
}
static bool enableTrigger(const char* cmd, int length){
(void) cmd;
(void) length;
bool param = atoi2(cmd, 1, 2);
Trigger::enable(param);
dout << "trigger enable " << param << endl;
return true;
}
static bool getLaserError(const char* cmd, int length){
(void) cmd;
(void) length;
iout << "Laser error: " << Laser::getLastError() << endl;
return false;
}
static bool resetHandler(const char* cmd, int length){
(void) cmd;
(void) length;
NVIC_SystemReset();
return true;
}
static bool pausePatternHandler(const char* cmd, int length){
(void) cmd;
(void) length;
Pattern::pause();
return true;
}
static bool resumePatternHandler(const char* cmd, int length){
(void) cmd;
(void) length;
Pattern::resume();
return true;
}
static bool stopPatternHandler(const char* cmd, int length){
(void) cmd;
(void) length;
Pattern::done();
return true;
}
static bool getPushButtonStates(const char* cmd, int length){
(void) cmd;
(void) length;
iout << "real states: X: " << HallSensor<X>::getFrontState() << "-" << HallSensor<X>::getEndState();
iout << " :: Y: " << HallSensor<Y>::getFrontState() << "-" << HallSensor<Y>::getEndState() << endl;
iout << "buffered states: " << HallSensor<X>::isAtFront() << "-" << HallSensor<X>::isAtEnd();
iout << " :: " << HallSensor<Y>::isAtFront() << "-" << HallSensor<Y>::isAtEnd() << endl;
return false;
}
static bool getMeasurement(const char* cmd, int length){
(void) cmd;
(void) length;
Trigger::forceTrigger();
return false;
}
static bool execLaserCommand(const char* cmd, int length){
//TODO
(void) length;
const char* result = Laser::exec(cmd);
iout << "EXEC: " << result << endl;
return false;
}
static bool mirrorCommand(const char* cmd, int length){
//TODO
(void) cmd;
(void) length;
if(length < 1){
iout << "no command found to mirror" << endl;
return false;
}
commandOut << cmd << endl;
return false;
}
static bool setTriggerThreshold(const char* cmd, int length){
float param = atof2(cmd, length, 0);
if(param == 0){
iout << "invalid argument for trigger threshold" << endl;
return false;
}
int threshold = Transform::mumToEncoder(param);
Trigger::setThreshold(threshold);
return true;
}
template<Axis axis>
static bool getControlOutputs(const char* cmd, int length){
(void) cmd;
(void) length;
iout << "w_x x w_v v v_u v_ureal" << endl;
iout << Control<axis>::getShallPosition() << " " << Control<axis>::getIsPosition() << " "
<< Control<axis>::getShallSpeed() << " " << Control<axis>::getIsSpeed() << " "
<< Control<axis>::getSpeedU() << " " << Control<axis>::getSpeedRealU() << endl;
iout << "posPid enabled, vPid enabled" << endl;
iout << Control<axis>::isPositionControlEnabled() << ", " << Control<axis>::isSpeedControlEnabled() << endl;
return false;
}
static bool rectanglePatternHandler3(const char* cmd, int length){
static int i = 0;
static Point points[5];
if(Pattern::isRunning()){
iout << "Previous pattern is still running!" << endl;
return false;
}
points[i].x = Control<X>::getIsPosition();
points[i].y = Control<Y>::getIsPosition();
dout << "point added (" << points[i].x << ", " << points[i].y << ") i " << i << endl;
i++;
if(i < 4){
return false;
}
if(i == 5){
Pattern::start();
i = 0;
}
Utils::enableSystick();
Control<ALL>::enablePositionControl(true);
//execute pattern
QuadrangleZigZag zRect;
zRect.configure(points);
Pattern::setPattern(zRect);
//Trigger::setThreshold(samplingResolution);
Trigger::enable(true);
iout << "pattern recorded, send command once more to start it" << endl;
//Pattern::start();
//i = 0;
return false;
}
static bool linePatternHandler(const char* cmd, int length){
static int i = 0;
static Point points[3];
if(Pattern::isRunning()){
iout << "Previous pattern is still running!" << endl;
return false;
}
points[i].x = Control<X>::getIsPosition();
points[i].y = Control<Y>::getIsPosition();
dout << "point added (" << points[i].x << ", " << points[i].y << ") i " << i << endl;
i++;
if(i < 2){
return false;
}
if(i == 3){
//dout << "starting pattern" << endl;
Pattern::start();
i = 0;
return true;
}
//dout << "setting up pattern" << endl;
Utils::enableSystick();
Control<ALL>::enablePositionControl(true);
//execute pattern
LinePattern line;
line.configure(points);
Pattern::setPattern(line);
Trigger::enable(true);
iout << "pattern recorded, send command once more to start it" << endl;
//Pattern::start();
//i = 0;
return false;
}
static bool rectanglePatternHandler2(const char* cmd, int length){
//expected: 4 arguments: start x, start y, stop x, stop y
static float lastx=-1, lasty=-1, lastStopX=-1, lastStopY=-1;
const char* currentPos;
float startx = atof2(cmd, ¤tPos, 100000.f);
float starty = atof2(currentPos, ¤tPos, 100000.f);
float stopx = atof2(currentPos, ¤tPos, 100000.f);
float stopy = atof2(currentPos, ¤tPos, 100000.f);
int samplingResolution = atoi2(currentPos, ¤tPos);
//sanity checks:
if(currentPos - cmd > length){
cerr << "buffer overrun " << (currentPos - cmd) << endl;
return false;
}
if(startx > XSTAGE_LENGTH_MM || startx < 0){
iout << "x param is out of bounds: " << startx << endl;
return false;
}
if(starty > YSTAGE_LENGTH_MM || stopy < 0){
iout << "y param is out of bounds: " << stopy << endl;
return false;
}
if(stopx > XSTAGE_LENGTH_MM || stopx < startx){
iout << "stopx param is out of bounds: " << stopx << endl;
return false;
}
if(stopy > YSTAGE_LENGTH_MM || stopy < starty){
iout << "stopy param is out of bounds: " << starty << endl;
return false;
}
if(samplingResolution < CONTROLX_DEADBAND || samplingResolution > 100000){
iout << "sampling resolution param is out of bounds: " << samplingResolution << endl;
return false;
}
dout << "rectangle: (startx, starty, stopx, stopy) "
<< startx << ", " << starty << ", " << stopx << ", " << stopy << endl;
if(Pattern::isRunning()){
iout << "Previous pattern is still running!" << endl;
return false;
}
Control<ALL>::setMaxSpeed(0.05);
Utils::enableSystick();
Control<ALL>::enablePositionControl(true);
if( true || (startx == lastx && starty == lasty && stopx == lastStopX && stopy == lastStopY)){
//execute pattern
Trigger::enable(true);
QuadrangleZigZag zRect;
zRect.configure2(startx, starty, stopx, stopy, samplingResolution);
Pattern::setPattern(zRect);
Trigger::setThreshold(samplingResolution);
Trigger::enable(true);
Pattern::start();
return true;
}
lastx = startx;
lasty = starty;
lastStopX = stopx;
lastStopY = stopy;
//demonstrate pattern outline
Trigger::enable(true);
Quadrangle rect;
rect.configure(startx, starty, stopx-startx, stopy-starty);
Pattern::setPattern(rect);
Pattern::start();
return true;
}
static bool rectanglePatternHandler(const char* cmd, int length){
//expected: 4 arguments: x, y, width, height
static float lastx=-1, lasty=-1, lastw=-1, lasth=-1;
const char* currentPos;
float x = atof2(cmd, ¤tPos, 100000.f);
float y = atof2(currentPos, ¤tPos, 100000.f);
float width = atof2(currentPos, ¤tPos, 100000.f);
float height = atof2(currentPos, ¤tPos, 100000.f);
int samplingResolution = atoi2(currentPos, ¤tPos);
//sanity checks:
if(currentPos - cmd > length){
cerr << "buffer overrun " << (currentPos - cmd) << endl;
return false;
}
if(x > XSTAGE_LENGTH_MM || x < 0){
iout << "x param is out of bounds: " << x << endl;
return false;
}
if(y > YSTAGE_LENGTH_MM || y < 0){
iout << "y param is out of bounds: " << y << endl;
return false;
}
if(x+width > XSTAGE_LENGTH_MM || width <= 0){
iout << "(x+)width param is out of bounds: " << (x+width) << endl;
return false;
}
if(y+height > YSTAGE_LENGTH_MM || height <= 0){
iout << "(y+)height param is out of bounds: " << height << endl;
return false;
}
if(samplingResolution < CONTROLX_DEADBAND || samplingResolution > 100000){
iout << "sampling resolution param is out of bounds: " << samplingResolution << endl;
return false;
}
dout << "rectangle: (x,y,width,height) " << x << ", " << y << ", " << width << ", " << height << endl;
if(Pattern::isRunning()){
iout << "Previous pattern is still running!" << endl;
return false;
}
Utils::enableSystick();
Control<ALL>::enablePositionControl(true);
if(x == lastx && y == lasty && width == lastw && height == lasth){
//execute pattern
Trigger::enable(true);
QuadrangleZigZag zRect;
zRect.configure(x, y, width, height, samplingResolution);
Pattern::setPattern(zRect);
Trigger::setThreshold(samplingResolution);
Trigger::enable(true);
Pattern::start();
return true;
}
lastx = x;
lasty = y;
lastw = width;
lasth = height;
//demonstrate pattern outline
Trigger::enable(true);
Quadrangle rect;
rect.configure(x, y, width, height);
Pattern::setPattern(rect);
Pattern::start();
return true;
}
};
#endif /* COMMANDHANDLERS_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/src/xpcc/architecture/platform/arm7/lpc/device/lpc21xx.h | <reponame>jrahlf/3D-Non-Contact-Laser-Profilometer
/**
* @file lpc21xx.h
* @brief Header file for Philips LPC2114 / LPC2119 / LPC2124 / LPC2129 / LPC2194
*
*/
#ifndef LPC21xx_REGISTERS_H
#define LPC21xx_REGISTERS_H
/* Vectored Interrupt Controller (VIC) */
#define VICIRQStatus (*((volatile unsigned long *) 0xFFFFF000))
#define VICFIQStatus (*((volatile unsigned long *) 0xFFFFF004))
#define VICRawIntr (*((volatile unsigned long *) 0xFFFFF008))
#define VICIntSelect (*((volatile unsigned long *) 0xFFFFF00C))
#define VICIntEnable (*((volatile unsigned long *) 0xFFFFF010))
#define VICIntEnClr (*((volatile unsigned long *) 0xFFFFF014))
#define VICSoftInt (*((volatile unsigned long *) 0xFFFFF018))
#define VICSoftIntClr (*((volatile unsigned long *) 0xFFFFF01C))
#define VICProtection (*((volatile unsigned long *) 0xFFFFF020))
#define VICVectAddr (*((volatile unsigned long *) 0xFFFFF030))
#define VICDefVectAddr (*((volatile unsigned long *) 0xFFFFF034))
#define VICVectAddr0 (*((volatile unsigned long *) 0xFFFFF100))
#define VICVectAddr1 (*((volatile unsigned long *) 0xFFFFF104))
#define VICVectAddr2 (*((volatile unsigned long *) 0xFFFFF108))
#define VICVectAddr3 (*((volatile unsigned long *) 0xFFFFF10C))
#define VICVectAddr4 (*((volatile unsigned long *) 0xFFFFF110))
#define VICVectAddr5 (*((volatile unsigned long *) 0xFFFFF114))
#define VICVectAddr6 (*((volatile unsigned long *) 0xFFFFF118))
#define VICVectAddr7 (*((volatile unsigned long *) 0xFFFFF11C))
#define VICVectAddr8 (*((volatile unsigned long *) 0xFFFFF120))
#define VICVectAddr9 (*((volatile unsigned long *) 0xFFFFF124))
#define VICVectAddr10 (*((volatile unsigned long *) 0xFFFFF128))
#define VICVectAddr11 (*((volatile unsigned long *) 0xFFFFF12C))
#define VICVectAddr12 (*((volatile unsigned long *) 0xFFFFF130))
#define VICVectAddr13 (*((volatile unsigned long *) 0xFFFFF134))
#define VICVectAddr14 (*((volatile unsigned long *) 0xFFFFF138))
#define VICVectAddr15 (*((volatile unsigned long *) 0xFFFFF13C))
#define VICVectCntl0 (*((volatile unsigned long *) 0xFFFFF200))
#define VICVectCntl1 (*((volatile unsigned long *) 0xFFFFF204))
#define VICVectCntl2 (*((volatile unsigned long *) 0xFFFFF208))
#define VICVectCntl3 (*((volatile unsigned long *) 0xFFFFF20C))
#define VICVectCntl4 (*((volatile unsigned long *) 0xFFFFF210))
#define VICVectCntl5 (*((volatile unsigned long *) 0xFFFFF214))
#define VICVectCntl6 (*((volatile unsigned long *) 0xFFFFF218))
#define VICVectCntl7 (*((volatile unsigned long *) 0xFFFFF21C))
#define VICVectCntl8 (*((volatile unsigned long *) 0xFFFFF220))
#define VICVectCntl9 (*((volatile unsigned long *) 0xFFFFF224))
#define VICVectCntl10 (*((volatile unsigned long *) 0xFFFFF228))
#define VICVectCntl11 (*((volatile unsigned long *) 0xFFFFF22C))
#define VICVectCntl12 (*((volatile unsigned long *) 0xFFFFF230))
#define VICVectCntl13 (*((volatile unsigned long *) 0xFFFFF234))
#define VICVectCntl14 (*((volatile unsigned long *) 0xFFFFF238))
#define VICVectCntl15 (*((volatile unsigned long *) 0xFFFFF23C))
/* Pin Connect Block */
#define PINSEL0 (*((volatile unsigned long *) 0xE002C000))
#define PINSEL1 (*((volatile unsigned long *) 0xE002C004))
#define PINSEL2 (*((volatile unsigned long *) 0xE002C014))
/* General Purpose Input/Output (GPIO) */
#define GPIO_BASE_ADDR 0xE0028000
#define IOPIN0 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x00))
#define IOSET0 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x04))
#define IODIR0 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x08))
#define IOCLR0 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x0C))
#define IOPIN1 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x10))
#define IOSET1 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x14))
#define IODIR1 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x18))
#define IOCLR1 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x1C))
#define IOPIN2 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x20))
#define IOSET2 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x24))
#define IODIR2 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x28))
#define IOCLR2 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x2C))
#define IOPIN3 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x30))
#define IOSET3 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x34))
#define IODIR3 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x38))
#define IOCLR3 (*(volatile unsigned long *)(GPIO_BASE_ADDR + 0x3C))
/* System Control Block(SCB) modules include Memory Accelerator Module,
Phase Locked Loop, VPB divider, Power Control, External Interrupt,
Reset, and Code Security/Debugging */
#define SCB_BASE_ADDR 0xE01FC000
/* Memory Accelerator Module (MAM) */
#define MAMCR (*(volatile unsigned char *)(SCB_BASE_ADDR + 0x00))
#define MAMTIM (*(volatile unsigned char *)(SCB_BASE_ADDR + 0x04))
#define MEMMAP (*(volatile unsigned char *)(SCB_BASE_ADDR + 0x40))
/* Phase Locked Loop (PLL) */
#define PLLCON (*(volatile unsigned char *)(SCB_BASE_ADDR + 0x80))
#define PLLCFG (*(volatile unsigned char *)(SCB_BASE_ADDR + 0x84))
#define PLLSTAT (*(volatile unsigned short*)(SCB_BASE_ADDR + 0x88))
#define PLLFEED (*(volatile unsigned char *)(SCB_BASE_ADDR + 0x8C))
/* Power Control */
#define PCON (*(volatile unsigned char *)(SCB_BASE_ADDR + 0xC0))
#define PCONP (*(volatile unsigned long *)(SCB_BASE_ADDR + 0xC4))
/* APB Divider */
#define APBDIV (*(volatile unsigned char *)(SCB_BASE_ADDR + 0x100))
/* System Controls and Status */
#define SCS (*(volatile unsigned long *)(SCB_BASE_ADDR + 0x1A0))
/* External Interrupts */
#define EXTINT (*(volatile unsigned char *)(SCB_BASE_ADDR + 0x140))
#define EXTWAKE (*(volatile unsigned char *)(SCB_BASE_ADDR + 0x144)) // LPC213x: INTWAKE
#define EXTMODE (*(volatile unsigned char *)(SCB_BASE_ADDR + 0x148))
#define EXTPOLAR (*(volatile unsigned char *)(SCB_BASE_ADDR + 0x14C))
/* LPC213x: Reset */
#define RSID (*((volatile unsigned char *) 0xE01FC180))
/* LPC213x:Code Security / Debugging */
#define CSPR (*((volatile unsigned char *) 0xE01FC184))
/* Timer 0 */
#define T0IR (*((volatile unsigned long *) 0xE0004000))
#define T0TCR (*((volatile unsigned long *) 0xE0004004))
#define T0TC (*((volatile unsigned long *) 0xE0004008))
#define T0PR (*((volatile unsigned long *) 0xE000400C))
#define T0PC (*((volatile unsigned long *) 0xE0004010))
#define T0MCR (*((volatile unsigned long *) 0xE0004014))
#define T0MR0 (*((volatile unsigned long *) 0xE0004018))
#define T0MR1 (*((volatile unsigned long *) 0xE000401C))
#define T0MR2 (*((volatile unsigned long *) 0xE0004020))
#define T0MR3 (*((volatile unsigned long *) 0xE0004024))
#define T0CCR (*((volatile unsigned long *) 0xE0004028))
#define T0CR0 (*((volatile unsigned long *) 0xE000402C))
#define T0CR1 (*((volatile unsigned long *) 0xE0004030))
#define T0CR2 (*((volatile unsigned long *) 0xE0004034))
#define T0CR3 (*((volatile unsigned long *) 0xE0004038))
#define T0EMR (*((volatile unsigned long *) 0xE000403C))
// LPC213x: T0CTCR
/* Timer 1 */
#define T1IR (*((volatile unsigned long *) 0xE0008000))
#define T1TCR (*((volatile unsigned long *) 0xE0008004))
#define T1TC (*((volatile unsigned long *) 0xE0008008))
#define T1PR (*((volatile unsigned long *) 0xE000800C))
#define T1PC (*((volatile unsigned long *) 0xE0008010))
#define T1MCR (*((volatile unsigned long *) 0xE0008014))
#define T1MR0 (*((volatile unsigned long *) 0xE0008018))
#define T1MR1 (*((volatile unsigned long *) 0xE000801C))
#define T1MR2 (*((volatile unsigned long *) 0xE0008020))
#define T1MR3 (*((volatile unsigned long *) 0xE0008024))
#define T1CCR (*((volatile unsigned long *) 0xE0008028))
#define T1CR0 (*((volatile unsigned long *) 0xE000802C))
#define T1CR1 (*((volatile unsigned long *) 0xE0008030))
#define T1CR2 (*((volatile unsigned long *) 0xE0008034))
#define T1CR3 (*((volatile unsigned long *) 0xE0008038))
#define T1EMR (*((volatile unsigned long *) 0xE000803C))
// LPC213x: T1CTCR
/* Pulse Width Modulator (PWM) */
#define PWMIR (*((volatile unsigned long *) 0xE0014000))
#define PWMTCR (*((volatile unsigned long *) 0xE0014004))
#define PWMTC (*((volatile unsigned long *) 0xE0014008))
#define PWMPR (*((volatile unsigned long *) 0xE001400C))
#define PWMPC (*((volatile unsigned long *) 0xE0014010))
#define PWMMCR (*((volatile unsigned long *) 0xE0014014))
#define PWMMR0 (*((volatile unsigned long *) 0xE0014018))
#define PWMMR1 (*((volatile unsigned long *) 0xE001401C))
#define PWMMR2 (*((volatile unsigned long *) 0xE0014020))
#define PWMMR3 (*((volatile unsigned long *) 0xE0014024))
#define PWMMR4 (*((volatile unsigned long *) 0xE0014040))
#define PWMMR5 (*((volatile unsigned long *) 0xE0014044))
#define PWMMR6 (*((volatile unsigned long *) 0xE0014048))
#define PWMCCR (*((volatile unsigned long *) 0xE0014028)) // LPC213x: not available
#define PWMCR0 (*((volatile unsigned long *) 0xE001402C)) // LPC213x: not available
#define PWMCR1 (*((volatile unsigned long *) 0xE0014030)) // LPC213x: not available
#define PWMCR2 (*((volatile unsigned long *) 0xE0014034)) // LPC213x: not available
#define PWMCR3 (*((volatile unsigned long *) 0xE0014038)) // LPC213x: not available
#define PWMEMR (*((volatile unsigned long *) 0xE001403C))
#define PWMPCR (*((volatile unsigned long *) 0xE001404C))
#define PWMLER (*((volatile unsigned long *) 0xE0014050))
/* Universal Asynchronous Receiver Transmitter 0 (UART0) */
#define U0RBR (*((volatile unsigned char *) 0xE000C000))
#define U0THR (*((volatile unsigned char *) 0xE000C000))
#define U0IER (*((volatile unsigned char *) 0xE000C004))
#define U0IIR (*((volatile unsigned char *) 0xE000C008))
#define U0FCR (*((volatile unsigned char *) 0xE000C008))
#define U0LCR (*((volatile unsigned char *) 0xE000C00C))
#define U0MCR (*((volatile unsigned char *) 0xE000C010)) // LPC213x: not available
#define U0LSR (*((volatile unsigned char *) 0xE000C014))
#define U0MSR (*((volatile unsigned char *) 0xE000C018))
#define U0SCR (*((volatile unsigned char *) 0xE000C01C))
#define U0DLL (*((volatile unsigned char *) 0xE000C000))
#define U0DLM (*((volatile unsigned char *) 0xE000C004))
/* Universal Asynchronous Receiver Transmitter 1 (UART1) */
#define U1RBR (*((volatile unsigned char *) 0xE0010000))
#define U1THR (*((volatile unsigned char *) 0xE0010000))
#define U1IER (*((volatile unsigned char *) 0xE0010004))
#define U1IIR (*((volatile unsigned char *) 0xE0010008))
#define U1FCR (*((volatile unsigned char *) 0xE0010008))
#define U1LCR (*((volatile unsigned char *) 0xE001000C))
#define U1MCR (*((volatile unsigned char *) 0xE0010010))
#define U1LSR (*((volatile unsigned char *) 0xE0010014))
#define U1MSR (*((volatile unsigned char *) 0xE0010018))
#define U1SCR (*((volatile unsigned char *) 0xE001001C))
#define U1DLL (*((volatile unsigned char *) 0xE0010000))
#define U1DLM (*((volatile unsigned char *) 0xE0010004))
// LPC213x: #define U1TER (*((volatile unsigned char *) 0xE0010030))
/* I2C Interface */
#define I2CONSET (*((volatile unsigned char *) 0xE001C000))
#define I2STAT (*((volatile unsigned char *) 0xE001C004))
#define I2DAT (*((volatile unsigned char *) 0xE001C008))
#define I2ADR (*((volatile unsigned char *) 0xE001C00C))
#define I2SCLH (*((volatile unsigned short*) 0xE001C010))
#define I2SCLL (*((volatile unsigned short*) 0xE001C014))
#define I2CONCLR (*((volatile unsigned char *) 0xE001C018))
/* SPI0 (Serial Peripheral Interface 0) */
#define S0SPCR (*((volatile unsigned char *) 0xE0020000))
#define S0SPSR (*((volatile unsigned char *) 0xE0020004))
#define S0SPDR (*((volatile unsigned char *) 0xE0020008))
#define S0SPCCR (*((volatile unsigned char *) 0xE002000C))
#define S0SPTCR (*((volatile unsigned char *) 0xE0020010))
#define S0SPTSR (*((volatile unsigned char *) 0xE0020014))
#define S0SPTOR (*((volatile unsigned char *) 0xE0020018))
#define S0SPINT (*((volatile unsigned char *) 0xE002001C))
/* SPI1 (Serial Peripheral Interface 1) */
#define S1SPCR (*((volatile unsigned char *) 0xE0030000))
#define S1SPSR (*((volatile unsigned char *) 0xE0030004))
#define S1SPDR (*((volatile unsigned char *) 0xE0030008))
#define S1SPCCR (*((volatile unsigned char *) 0xE003000C))
#define S1SPTCR (*((volatile unsigned char *) 0xE0030010))
#define S1SPTSR (*((volatile unsigned char *) 0xE0030014))
#define S1SPTOR (*((volatile unsigned char *) 0xE0030018))
#define S1SPINT (*((volatile unsigned char *) 0xE003001C))
/* Real Time Clock */
#define ILR (*((volatile unsigned char *) 0xE0024000))
#define CTC (*((volatile unsigned short*) 0xE0024004))
#define CCR (*((volatile unsigned char *) 0xE0024008))
#define CIIR (*((volatile unsigned char *) 0xE002400C))
#define AMR (*((volatile unsigned char *) 0xE0024010))
#define CTIME0 (*((volatile unsigned long *) 0xE0024014))
#define CTIME1 (*((volatile unsigned long *) 0xE0024018))
#define CTIME2 (*((volatile unsigned long *) 0xE002401C))
#define SEC (*((volatile unsigned char *) 0xE0024020))
#define MIN (*((volatile unsigned char *) 0xE0024024))
#define HOUR (*((volatile unsigned char *) 0xE0024028))
#define DOM (*((volatile unsigned char *) 0xE002402C))
#define DOW (*((volatile unsigned char *) 0xE0024030))
#define DOY (*((volatile unsigned short*) 0xE0024034))
#define MONTH (*((volatile unsigned char *) 0xE0024038))
#define YEAR (*((volatile unsigned short*) 0xE002403C))
#define ALSEC (*((volatile unsigned char *) 0xE0024060))
#define ALMIN (*((volatile unsigned char *) 0xE0024064))
#define ALHOUR (*((volatile unsigned char *) 0xE0024068))
#define ALDOM (*((volatile unsigned char *) 0xE002406C))
#define ALDOW (*((volatile unsigned char *) 0xE0024070))
#define ALDOY (*((volatile unsigned short*) 0xE0024074))
#define ALMON (*((volatile unsigned char *) 0xE0024078))
#define ALYEAR (*((volatile unsigned short*) 0xE002407C))
#define PREINT (*((volatile unsigned short*) 0xE0024080))
#define PREFRAC (*((volatile unsigned short*) 0xE0024084))
/* A/D Converter */
#define ADCR (*((volatile unsigned long *) 0xE0034000))
#define ADDR (*((volatile unsigned long *) 0xE0034004))
/* CAN Acceptance Filter RAM */
#define AFRAM (*((volatile unsigned long *) 0xE0038000))
/* CAN Acceptance Filter */
#define AFMR (*((volatile unsigned long *) 0xE003C000))
#define SFF_sa (*((volatile unsigned long *) 0xE003C004))
#define SFF_GRP_sa (*((volatile unsigned long *) 0xE003C008))
#define EFF_sa (*((volatile unsigned long *) 0xE003C00C))
#define EFF_GRP_sa (*((volatile unsigned long *) 0xE003C010))
#define ENDofTable (*((volatile unsigned long *) 0xE003C014))
#define LUTerrAd (*((volatile unsigned long *) 0xE003C018))
#define LUTerr (*((volatile unsigned long *) 0xE003C01C))
/* CAN Central Registers */
#define CANTxSR (*((volatile unsigned long *) 0xE0040000))
#define CANRxSR (*((volatile unsigned long *) 0xE0040004))
#define CANMSR (*((volatile unsigned long *) 0xE0040008))
/* CAN Controller 1 (CAN1) */
#define C1MOD (*((volatile unsigned long *) 0xE0044000))
#define C1CMR (*((volatile unsigned long *) 0xE0044004))
#define C1GSR (*((volatile unsigned long *) 0xE0044008))
#define C1ICR (*((volatile unsigned long *) 0xE004400C))
#define C1IER (*((volatile unsigned long *) 0xE0044010))
#define C1BTR (*((volatile unsigned long *) 0xE0044014))
#define C1EWL (*((volatile unsigned long *) 0xE0044018))
#define C1SR (*((volatile unsigned long *) 0xE004401C))
#define C1RFS (*((volatile unsigned long *) 0xE0044020))
#define C1RID (*((volatile unsigned long *) 0xE0044024))
#define C1RDA (*((volatile unsigned long *) 0xE0044028))
#define C1RDB (*((volatile unsigned long *) 0xE004402C))
#define C1TFI1 (*((volatile unsigned long *) 0xE0044030))
#define C1TID1 (*((volatile unsigned long *) 0xE0044034))
#define C1TDA1 (*((volatile unsigned long *) 0xE0044038))
#define C1TDB1 (*((volatile unsigned long *) 0xE004403C))
#define C1TFI2 (*((volatile unsigned long *) 0xE0044040))
#define C1TID2 (*((volatile unsigned long *) 0xE0044044))
#define C1TDA2 (*((volatile unsigned long *) 0xE0044048))
#define C1TDB2 (*((volatile unsigned long *) 0xE004404C))
#define C1TFI3 (*((volatile unsigned long *) 0xE0044050))
#define C1TID3 (*((volatile unsigned long *) 0xE0044054))
#define C1TDA3 (*((volatile unsigned long *) 0xE0044058))
#define C1TDB3 (*((volatile unsigned long *) 0xE004405C))
/* CAN Controller 2 (CAN2) */
#define C2MOD (*((volatile unsigned long *) 0xE0048000))
#define C2CMR (*((volatile unsigned long *) 0xE0048004))
#define C2GSR (*((volatile unsigned long *) 0xE0048008))
#define C2ICR (*((volatile unsigned long *) 0xE004800C))
#define C2IER (*((volatile unsigned long *) 0xE0048010))
#define C2BTR (*((volatile unsigned long *) 0xE0048014))
#define C2EWL (*((volatile unsigned long *) 0xE0048018))
#define C2SR (*((volatile unsigned long *) 0xE004801C))
#define C2RFS (*((volatile unsigned long *) 0xE0048020))
#define C2RID (*((volatile unsigned long *) 0xE0048024))
#define C2RDA (*((volatile unsigned long *) 0xE0048028))
#define C2RDB (*((volatile unsigned long *) 0xE004802C))
#define C2TFI1 (*((volatile unsigned long *) 0xE0048030))
#define C2TID1 (*((volatile unsigned long *) 0xE0048034))
#define C2TDA1 (*((volatile unsigned long *) 0xE0048038))
#define C2TDB1 (*((volatile unsigned long *) 0xE004803C))
#define C2TFI2 (*((volatile unsigned long *) 0xE0048040))
#define C2TID2 (*((volatile unsigned long *) 0xE0048044))
#define C2TDA2 (*((volatile unsigned long *) 0xE0048048))
#define C2TDB2 (*((volatile unsigned long *) 0xE004804C))
#define C2TFI3 (*((volatile unsigned long *) 0xE0048050))
#define C2TID3 (*((volatile unsigned long *) 0xE0048054))
#define C2TDA3 (*((volatile unsigned long *) 0xE0048058))
#define C2TDB3 (*((volatile unsigned long *) 0xE004805C))
/* CAN Controller 3 (CAN3) */
#define C3MOD (*((volatile unsigned long *) 0xE004C000))
#define C3CMR (*((volatile unsigned long *) 0xE004C004))
#define C3GSR (*((volatile unsigned long *) 0xE004C008))
#define C3ICR (*((volatile unsigned long *) 0xE004C00C))
#define C3IER (*((volatile unsigned long *) 0xE004C010))
#define C3BTR (*((volatile unsigned long *) 0xE004C014))
#define C3EWL (*((volatile unsigned long *) 0xE004C018))
#define C3SR (*((volatile unsigned long *) 0xE004C01C))
#define C3RFS (*((volatile unsigned long *) 0xE004C020))
#define C3RID (*((volatile unsigned long *) 0xE004C024))
#define C3RDA (*((volatile unsigned long *) 0xE004C028))
#define C3RDB (*((volatile unsigned long *) 0xE004C02C))
#define C3TFI1 (*((volatile unsigned long *) 0xE004C030))
#define C3TID1 (*((volatile unsigned long *) 0xE004C034))
#define C3TDA1 (*((volatile unsigned long *) 0xE004C038))
#define C3TDB1 (*((volatile unsigned long *) 0xE004C03C))
#define C3TFI2 (*((volatile unsigned long *) 0xE004C040))
#define C3TID2 (*((volatile unsigned long *) 0xE004C044))
#define C3TDA2 (*((volatile unsigned long *) 0xE004C048))
#define C3TDB2 (*((volatile unsigned long *) 0xE004C04C))
#define C3TFI3 (*((volatile unsigned long *) 0xE004C050))
#define C3TID3 (*((volatile unsigned long *) 0xE004C054))
#define C3TDA3 (*((volatile unsigned long *) 0xE004C058))
#define C3TDB3 (*((volatile unsigned long *) 0xE004C05C))
/* CAN Controller 4 (CAN4) */
#define C4MOD (*((volatile unsigned long *) 0xE0050000))
#define C4CMR (*((volatile unsigned long *) 0xE0050004))
#define C4GSR (*((volatile unsigned long *) 0xE0050008))
#define C4ICR (*((volatile unsigned long *) 0xE005000C))
#define C4IER (*((volatile unsigned long *) 0xE0050010))
#define C4BTR (*((volatile unsigned long *) 0xE0050014))
#define C4EWL (*((volatile unsigned long *) 0xE0050018))
#define C4SR (*((volatile unsigned long *) 0xE005001C))
#define C4RFS (*((volatile unsigned long *) 0xE0050020))
#define C4RID (*((volatile unsigned long *) 0xE0050024))
#define C4RDA (*((volatile unsigned long *) 0xE0050028))
#define C4RDB (*((volatile unsigned long *) 0xE005002C))
#define C4TFI1 (*((volatile unsigned long *) 0xE0050030))
#define C4TID1 (*((volatile unsigned long *) 0xE0050034))
#define C4TDA1 (*((volatile unsigned long *) 0xE0050038))
#define C4TDB1 (*((volatile unsigned long *) 0xE005003C))
#define C4TFI2 (*((volatile unsigned long *) 0xE0050040))
#define C4TID2 (*((volatile unsigned long *) 0xE0050044))
#define C4TDA2 (*((volatile unsigned long *) 0xE0050048))
#define C4TDB2 (*((volatile unsigned long *) 0xE005004C))
#define C4TFI3 (*((volatile unsigned long *) 0xE0050050))
#define C4TID3 (*((volatile unsigned long *) 0xE0050054))
#define C4TDA3 (*((volatile unsigned long *) 0xE0050058))
#define C4TDB3 (*((volatile unsigned long *) 0xE005005C))
/* Watchdog */
#define WDMOD (*((volatile unsigned char *) 0xE0000000))
#define WDTC (*((volatile unsigned long *) 0xE0000004))
#define WDFEED (*((volatile unsigned char *) 0xE0000008))
#define WDTV (*((volatile unsigned long *) 0xE000000C))
#endif // LPC21xx_REGISTERS_H
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/checksum.h | <gh_stars>1-10
/*
* checksum.cpp
*
* Created on: Feb 11, 2014
* Author: jonas
*/
#pragma once
struct Checksum{
/**
* @brief getFor: Returns the checksum for a message
* @param data message the checksum shall be calculated for
* @param length number of characters, the newline character shall not be included
* @param specifier the specifier of the message
* @return computed checksum
*/
static char getFor(const char* data, int length, char specifier){
char checksum = 0x0;
const char* const pEnd = data+length;
while(data != pEnd){
checksum ^= *data;
data++;
}
checksum ^= specifier;
return checksum;
}
};
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/src/xpcc/architecture/platform/cortex_m3/stm32/stm32f3/startup/startup.c | // coding: utf-8
// ----------------------------------------------------------------------------
/* Copyright (c) 2011, Roboterclub Aachen e.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Roboterclub Aachen e.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ROBOTERCL<NAME>HEN E.V. ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// ----------------------------------------------------------------------------
#include <stdint.h>
#include <xpcc/architecture/utils.hpp>
#if defined(STM32F30X)
# include <stm32f30x.h>
#else
#error "This file is not supposed to be used with given CPU (only STM32F3xx)"
#endif
#include "xpcc_config.hpp"
// ----------------------------------------------------------------------------
#define FLASH_WAIT_STATE_0 0x0
#define FLASH_WAIT_STATE_1 0x1
#define FLASH_WAIT_STATE_2 0x2
#define FLASH_WAIT_STATE_3 0x3
#define FLASH_WAIT_STATE_4 0x4
#define FLASH_WAIT_STATE_5 0x5
#define FLASH_WAIT_STATE_6 0x6
#define FLASH_WAIT_STATE_7 0x7
#define NR_INTERRUPTS 82
// ----------------------------------------------------------------------------
/*
* Provide weak aliases for each Exception handler to defaultHandler.
* As they are weak aliases, any function with the same name will override
* this definition.
*/
void Reset_Handler(void);
void NMI_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void HardFault_Handler(void);
void MemManage_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void BusFault_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void UsageFault_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void SVC_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void PendSV_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void SysTick_Handler(void) __attribute__ ((weak, alias("defaultHandler")));
void WWDG_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void PVD_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TAMP_STAMP_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void RTC_WKUP_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void FLASH_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void RCC_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI0_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI1_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI2_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI3_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI4_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_CH1_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_CH2_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_CH3_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_CH4_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_CH5_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA1_CH6_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void ADC1_2_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void CAN1_TX_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void CAN1_RX0_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void CAN1_RX1_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void CAN1_SCE_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI9_5_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM1_BRK_TIM15_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM1_UP_TIM16_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM1_TRG_COM_TIM17_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM1_CC_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM2_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM3_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM4_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void I2C1_EV_EXTI23_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void I2C1_ER_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void I2C2_EV_EXTI24_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void I2C2_ER_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void SPI1_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void SPI2_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void USART1_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void USART2_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void USART3_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void EXTI15_10_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void RTCAlarm_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM8_BRK_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM8_UP_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM8_TRG_COM_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM8_CC_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void ADC3_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void SPI3_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void UART4_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void UART5_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM6_DAC_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void TIM7_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA2_CH1_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA2_CH2_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA2_CH3_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA2_CH4_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void DMA2_CH5_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void ADC4_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void COMP123_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void COMP456_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void COMP7_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void USB_HP_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void USB_LP_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void USB_WKUP_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
void FPU_IRQHandler(void) __attribute__ ((weak, alias("defaultHandler")));
// ----------------------------------------------------------------------------
// Interrupt vectors
typedef void (* const FunctionPointer)(void);
// defined in the linkerscript
extern uint32_t __stack_end;
#if CORTEX_VECTORS_RAM
// Define the vector table
FunctionPointer flashVectors[4]
__attribute__ ((section(".reset"))) =
{
(FunctionPointer) &__stack_end, // stack pointer
Reset_Handler, // code entry point
NMI_Handler, // NMI handler
HardFault_Handler, // hard fault handler
};
FunctionPointer ramVectors[] __attribute__ ((section(".vectors"))) =
#else
FunctionPointer flashVectors[] __attribute__ ((section(".reset"))) =
#endif
{
(FunctionPointer) &__stack_end, // stack pointer
Reset_Handler, // 0000 0004 code entry point
NMI_Handler, // 0000 0008 NMI handler
HardFault_Handler, // 0000 000C hard fault handler
MemManage_Handler, // 0000 0010 MPU Fault Handler
BusFault_Handler, // 0000 0014 Bus Fault Handler
UsageFault_Handler, // 0000 0018 Usage Fault Handler
0, // 0000 001C
0, // 0000 0020
0, // 0000 0024
0, // 0000 0028
SVC_Handler, // 0000 002C SVCall Handler
0, // 0000 0030
0, // 0000 0034
PendSV_Handler, // 0000 0038 PendSV Handler
SysTick_Handler, // 0000 003C SysTick Handler
// Peripheral interrupts (STM32 specific)
WWDG_IRQHandler, // 0000 0040: Window Watchdog
PVD_IRQHandler, // 0000 0044 1: PVD through EXTI Line detect
TAMP_STAMP_IRQHandler, // 0000 0048 2: Tamper and TimeStamps through the EXTI line
RTC_WKUP_IRQHandler, // 0000 004C 3: Wakeup through the EXTI line
FLASH_IRQHandler, // 0000 0050 4: Flash
RCC_IRQHandler, // 0000 0054 5: RCC
EXTI0_IRQHandler, // 0000 0058 EXTI Line 0
EXTI1_IRQHandler, // 0000 005C EXTI Line 1
EXTI2_IRQHandler, // 0000 0060 EXTI Line 2
EXTI3_IRQHandler, // 0000 0064 EXTI Line 3
EXTI4_IRQHandler, // 0000 0068 10: EXTI Line 4
DMA1_CH1_IRQHandler, // 0000 006C DMA1 Channel 1
DMA1_CH1_IRQHandler, // 0000 0070 DMA1 Channel 2
DMA1_CH2_IRQHandler, // 0000 0074 DMA1 Channel 3
DMA1_CH3_IRQHandler, // 0000 0078 DMA1 Channel 4
DMA1_CH4_IRQHandler, // 0000 007C 15: DMA1 Channel 5
DMA1_CH5_IRQHandler, // 0000 0080 DMA1 Channel 6
DMA1_CH6_IRQHandler, // 0000 0084 DMA1 Channel 7
ADC1_2_IRQHandler, // 0000 0088 ADC1 and ADC2
CAN1_TX_IRQHandler, // 0000 008C CAN1 TX
CAN1_RX0_IRQHandler, // 0000 0090 20: CAN1 RX0
CAN1_RX1_IRQHandler, // 0000 0094 CAN1 RX1
CAN1_SCE_IRQHandler, // 0000 0098 CAN1 SCE
EXTI9_5_IRQHandler, // 0000 009C EXTI Line 9..5
TIM1_BRK_TIM15_IRQHandler, // 0000 00A0 TIM1 Break
TIM1_UP_TIM16_IRQHandler, // 0000 00A4 25: TIM1 Update
TIM1_TRG_COM_TIM17_IRQHandler, // 0000 00A8 TIM1 Trigger and Commutation
TIM1_CC_IRQHandler, // 0000 00AC TIM1 Capture Compare
TIM2_IRQHandler, // 0000 00B0 TIM2
TIM3_IRQHandler, // 0000 00B4 TIM3
TIM4_IRQHandler, // 0000 00B8 30: TIM4
I2C1_EV_EXTI23_IRQHandler, // 0000 00BC I2C1 Event and EXTI Line23
I2C1_ER_IRQHandler, // 0000 00C0 I2C1 Error
I2C2_EV_EXTI24_IRQHandler, // 0000 00C4 I2C2 Event and EXTI Line24
I2C2_ER_IRQHandler, // 0000 00C8 I2C2 Error
SPI1_IRQHandler, // 0000 00CC 35: SPI1
SPI2_IRQHandler, // 0000 00D0 SPI2
USART1_IRQHandler, // 0000 00D4 USART1
USART2_IRQHandler, // 0000 00D8 USART2
USART3_IRQHandler, // 0000 00DC USART3
EXTI15_10_IRQHandler, // 0000 00E0 40: External Line[15:10]s
RTCAlarm_IRQHandler, // 0000 00E4 RTC Alarm (A and B) through EXTI Line
USB_WKUP_IRQHandler, // 0000 00E8 USB Wakeup through EXTI line
TIM8_BRK_IRQHandler, // 0000 00EC TIM8 Break
TIM8_UP_IRQHandler, // 0000 00F0 TIM8 Update and TIM13
TIM8_TRG_COM_IRQHandler, // 0000 00F4 45: TIM8 Trigger and Commutation
TIM8_CC_IRQHandler, // 0000 00F8 TIM8 Capture compare
ADC3_IRQHandler, // 0000 00FC ADC3
0, // 0000 0100
0, // 0000 0104
0, // 0000 0108 50:
SPI3_IRQHandler, // 0000 010C
UART4_IRQHandler, // 0000 0110
UART5_IRQHandler, // 0000 0114
TIM6_DAC_IRQHandler, // 0000 0118 TIM6 and DAC1&2 under-run errors
TIM7_IRQHandler, // 0000 011C 55:
DMA2_CH1_IRQHandler, // 0000 0120
DMA2_CH2_IRQHandler, // 0000 0124
DMA2_CH3_IRQHandler, // 0000 0128
DMA2_CH4_IRQHandler, // 0000 012C
DMA2_CH5_IRQHandler, // 0000 0130 60:
ADC4_IRQHandler, // 0000 0134
0, // 0000 0138
0, // 0000 013C
COMP123_IRQHandler, // 0000 0140
COMP456_IRQHandler, // 0000 0144 65:
COMP7_IRQHandler, // 0000 0148
0, // 0000 014C
0, // 0000 0150
0, // 0000 0154
0, // 0000 0158 70:
0, // 0000 015C
0, // 0000 0160
0, // 0000 0164
USB_HP_IRQHandler, // 0000 0168 USB High priority
USB_LP_IRQHandler, // 0000 016C 75: USB Low prioroty
USB_WKUP_IRQHandler, // 0000 0170 USB Wakeup through EXTI
0, // 0000 0174
0, // 0000 0178
0, // 0000 017C
0, // 0000 0180 80:
FPU_IRQHandler, // 0000 0184 FPU
};
// FIXME set USB_IT_RMP bit in the Section 9.1.1: SYSCFG configuration register 1 (SYSCFG_CFGR1)
// ----------------------------------------------------------------------------
// defined in the linker script
extern uint32_t __fastcode_load;
extern uint32_t __fastcode_start;
extern uint32_t __fastcode_end;
extern uint32_t __data_load;
extern uint32_t __data_start;
extern uint32_t __data_end;
extern uint32_t __bss_start;
extern uint32_t __bss_end;
// Application's main function
int
main(void);
// calls CTORS of static objects
void
__libc_init_array(void);
extern void
exit(int) __attribute__ ((noreturn, weak));
// ----------------------------------------------------------------------------
void
Reset_Handler(void)
{
// startup delay
for (volatile unsigned long i = 0; i < 500000; i++)
{
}
// Copy functions to RAM (.fastcode)
uint32_t* src = &__fastcode_load;
uint32_t* dest = &__fastcode_start;
while (dest < &__fastcode_end)
{
*(dest++) = *(src++);
}
// Copy the data segment initializers from flash to RAM (.data)
src = &__data_load;
dest = &__data_start;
while (dest < &__data_end)
{
*(dest++) = *(src++);
}
// Fill the bss segment with zero (.bss)
dest = &__bss_start;
while (dest < &__bss_end)
{
*(dest++) = 0;
}
// prepare flash latency for working at 72MHz and supply voltage > 2.7
FLASH->ACR = (FLASH->ACR & ~FLASH_ACR_LATENCY) | FLASH_ACR_LATENCY_1;
// enable flash prefetch
FLASH->ACR |= FLASH_ACR_PRFTBE;
#if defined(STM32F3XX)
// Enable FPU in privileged and user mode
SCB->CPACR |= ((3UL << 10*2) | (3UL << 11*2)); // set CP10 and CP11 Full Access
#endif
// Enable GPIO clock
// TODO adapt to actual pin count!
// GPIOA-F
RCC->AHBENR |=
RCC_AHBENR_GPIOAEN
| RCC_AHBENR_GPIOBEN
| RCC_AHBENR_GPIOCEN
| RCC_AHBENR_GPIODEN
| RCC_AHBENR_GPIOEEN
| RCC_AHBENR_GPIOFEN
;
RCC->AHBRSTR |=
RCC_AHBRSTR_GPIOARST
| RCC_AHBRSTR_GPIOBRST
| RCC_AHBRSTR_GPIOCRST
| RCC_AHBRSTR_GPIODRST
| RCC_AHBRSTR_GPIOFRST
; // Reset value is 0, check if this can be left out.
RCC->AHBRSTR &=
~( RCC_AHBRSTR_GPIOARST
| RCC_AHBRSTR_GPIOBRST
| RCC_AHBRSTR_GPIOCRST
| RCC_AHBRSTR_GPIODRST
| RCC_AHBRSTR_GPIOFRST)
;
// Setup NVIC
// Set vector table
const uint32_t offset = 0;
SCB->VTOR = 0x08000000 | (offset & 0x1FFFFF80);
// Lower priority level for all peripheral interrupts to lowest possible
for (uint32_t i = 0; i < NR_INTERRUPTS; i++) {
const uint32_t priority = 0xF;
NVIC->IP[i] = (priority & 0xF) << 4;
}
// Set the PRIGROUP[10:8] bits to
// - 4 bits for pre-emption priority,
// - 0 bits for subpriority
SCB->AIRCR = 0x05FA0000 | 0x300;
// Enable fault handlers
/*SCB->SHCSR |=
SCB_SHCSR_BUSFAULTENA_Msk |
SCB_SHCSR_USGFAULTENA_Msk |
SCB_SHCSR_MEMFAULTENA_Msk;*/
// Call CTORS of static objects
__libc_init_array();
// Call the application's entry point
main();
exit(1);
while (1)
{
}
}
// ----------------------------------------------------------------------------
/**
* @brief Default interrupt handler
*
* This functions gets called if an interrupt handler is not defined. It just
* enters an infinite loop leaving the processor state intact for a debugger
* to be examined.
*/
void
defaultHandler(void)
{
while (1)
{
}
}
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/src/xpcc/architecture/platform/arm7/lpc/uart/uart.h |
#ifndef UART_BASE_H
#define UART_BASE_H
#include <stdint.h>
/**
* @brief Abstract base class for UART drivers
*
* @date May 2011
* @author <NAME>
*/
class UartInterface
{
public:
/**
* @brief Initialize the hardware
*
* Sets the registers etc.
*
* With the trigger level it is possible to make a tradeoff between
* latency and interrupt count. A small value will give you more interrupts
* but a faster response time, a bigger value will decrease the
* number of interrupts.
* Nonetheless after 3.5 - 4.5 character times the remaining bytes will
* be collected from the FIFO.
*
* Possible values for \c level:
* - 0 => 1 byte
* - 1 => 4 byte
* - 2 => 8 byte
* - 3 => 14 byte
*
* @brief level Trigger level for the UART Fifos.
*/
virtual void
initialize(uint8_t level = 2) = 0;
/**
* @brief Send a character
*
* @param c character to be send
* @param blocking If \c true the function will wait until the
* character could be send. Otherwise the function
* will return immediately even if sending failed.
* @return \c true if the character was send, \c false otherwise.
*/
virtual bool
write(char c, bool blocking = true) = 0;
/**
* @brief Check if a character was received and is ready to be read
*/
virtual bool
isCharacterAvailable() = 0;
/**
* @brief Read a single character
*
* @return \c true if a character was available and was stored in \c c,
* false if nothing was available. \c c will remain untouched
* in this case.
*/
virtual bool
read(char &c, bool blocking = false) = 0;
};
#endif // UART_BASE_H
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/encoder.h | /*
* encoder.h
*
* Created on: Nov 26, 2013
* Author: jonas
*/
#ifndef ENCODER_H_
#define ENCODER_H_
#include <xpcc/architecture.hpp>
namespace Encoder{
/**
* Initializes Timer 2 and Timer 5 to be used to decode quadrature
* encoder signal in 4x decoding
* @return
*/
bool init();
/**
* Zeros the internal encoder values
*/
void zero();
/**
*
*/
void pause();
void start();
};
#endif /* ENCODER_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/utils.h | <reponame>jrahlf/3D-Non-Contact-Laser-Profilometer<gh_stars>1-10
/*
* utils.h
*
* Created on: Feb 1, 2014
* Author: jonas
*/
#ifndef UTILS_H_
#define UTILS_H_
namespace Utils{
void enableSystick();
void disableSystick();
void startLoggingControl();
/**
* Drives to position (0,0), that is the most left and most lower
* position of the stage, when viewed from the top
* When that position is reached, the current position is set to 0
* To be called at startup
*/
void calibrateZero();
};
#endif /* UTILS_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | microcontroller/hallSensor_impl.h | /*
* hallSensor_impl.h
*
* Created on: Jan 1, 2014
* Author: jonas
*/
#ifndef HALLSENSOR_IMPL_H_
#define HALLSENSOR_IMPL_H_
#include "project.h"
template<Axis axis>
bool HallSensor<axis>::checkFrontState(){
//coutRaw << "a " << Control<axis>::getIsPosition() - triggeredPosition[0] << endl;
if(Control<axis>::getIsPosition() - triggeredPosition[0] > HALLSENSOR_HYSTERESIS){
triggered[0] = false;
return true;
}
return false;
}
template<Axis axis>
bool HallSensor<axis>::checkEndState(){
//coutRaw << "b " << Control<axis>::getIsPosition() - triggeredPosition[0] << endl;
if(Control<axis>::getIsPosition() - triggeredPosition[1] < -HALLSENSOR_HYSTERESIS){
triggered[1] = false;
return true;
}
return false;
}
#endif /* HALLSENSOR_IMPL_H_ */
|
jrahlf/3D-Non-Contact-Laser-Profilometer | pc/pcDaemon2/myThread.h | #ifndef MYTHREAD_H
#define MYTHREAD_H
#include <QtCore>
class myThread : public QThread{
Q_OBJECT
signals:
void appendDLog(QString);
void appendELog(QString);
void appendILog(QString);
void setX(double);
void setY(double);
void setZ(double);
private slots:
void handleUpdateButton();
public:
void run();
};
#endif // MYTHREAD_H
|
jrahlf/3D-Non-Contact-Laser-Profilometer | pc/pcDaemon2/errorlog.h | #ifndef ERRORLOG_H
#define ERRORLOG_H
#include <QMainWindow>
namespace Ui {
class ErrorLog;
}
class ErrorLog : public QMainWindow
{
Q_OBJECT
public:
explicit ErrorLog(QWidget *parent = 0);
~ErrorLog();
public slots:
void append(QString);
private:
Ui::ErrorLog *ui;
};
#endif // ERRORLOG_H
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/tools/bootloader/can/mcp2515/main.c | <reponame>jrahlf/3D-Non-Contact-Laser-Profilometer<filename>xpcc/tools/bootloader/can/mcp2515/main.c<gh_stars>1-10
// coding: utf-8
// ----------------------------------------------------------------------------
/* Copyright (c) 2010, Roboterclub Aachen e.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Roboterclub Aachen e.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// ----------------------------------------------------------------------------
/**
* \brief CAN Bootloader (MCP2515)
*
* \author <NAME> <<EMAIL>>
* \author <NAME>
*/
// ----------------------------------------------------------------------------
#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/boot.h>
#include <avr/eeprom.h>
#include <avr/pgmspace.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include "utils.h"
#include "defaults.h"
#include "mcp2515.h"
#include "mcp2515_defs.h"
// ----------------------------------------------------------------------------
// global variables
static uint16_t flashpage = 0;
static uint8_t page_buffer_pos = 0;
static uint8_t page_buffer[SPM_PAGESIZE];
// ----------------------------------------------------------------------------
/**
* \brief starts the application program
*/
void
boot_jump_to_application(void)
{
// relocate interrupt vectors
uint8_t reg = IV_REG & ~((1 << IVCE) | (1 << IVSEL));
IV_REG = reg | (1 << IVCE);
IV_REG = reg;
// reset SPI interface to power-up state
SPCR = 0;
SPSR = 0;
#if FLASHEND > 0xffff
__asm__ __volatile__(
"push __zero_reg__" "\n\t"
"push __zero_reg__" "\n\t"
"push __zero_reg__" "\n\t");
#else
__asm__ __volatile__(
"push __zero_reg__" "\n\t"
"push __zero_reg__" "\n\t");
#endif
// when the functions executes the 'ret' command to return to
// its origin the AVR loads the return address from the stack. Because we
// pushed null it instead jumps to address null which starts the main
// application.
}
// ----------------------------------------------------------------------------
/**
* \brief write a complete page to the flash memorey
*
* \param page page which should be written
* \param *buf Pointer to the buffer with the data
*
* \see avr-libc Documentation > Modules > Bootloader Support Utilities
*/
void
boot_program_page(uint16_t page, uint8_t *buf)
{
uint32_t adr = page * SPM_PAGESIZE;
boot_page_erase(adr);
boot_spm_busy_wait(); // Wait until the memory is erased.
for (uint16_t i=0; i < SPM_PAGESIZE; i+=2)
{
// Set up little-endian word.
uint16_t w = *buf++;
w += (*buf++) << 8;
boot_page_fill(adr + i, w);
}
boot_page_write(adr); // Store buffer in flash page.
boot_spm_busy_wait(); // Wait until the memory is written.
// Reenable RWW-section again. We need this if we want to jump back
// to the application after bootloading.
boot_rww_enable();
}
// ----------------------------------------------------------------------------
void
boot(void) \
__attribute__((naked)) \
__attribute__((section(".vectors")));
void
boot(void)
{
__asm__ __volatile__ ("rjmp init" "\n\t");
}
// ----------------------------------------------------------------------------
void
init(void) \
__attribute__((naked)) \
__attribute__((section(".init2")));
void
init(void)
{
// Clear r1 (__zero_reg__) and initialize the stack
__asm__ __volatile__ (
"eor r1, r1" "\n\t"
"out 0x3f, r1" "\n\t"
"ldi r28, 0xFF" "\n\t"
"ldi r29, 0x04" "\n\t"
"out 0x3e, r29" "\n\t"
"out 0x3d, r28" "\n\t");
#ifdef GPIOR0
// Save MCUSR so that the main program can access if later
GPIOR0 = MCUSR;
#endif
MCUSR = 0;
// Disable the watchdog timer
// see http://www.nongnu.org/avr-libc/user-manual/group__avr__watchdog.html
//
// The orignal implementation uses additional commands to disable
// interrupts. As we never enable interrupts this is not needed here.
__asm__ __volatile__ ( \
"sts %0, %1" "\n\t" \
"sts %0, __zero_reg__" "\n\t" \
: /* no outputs */ \
: "M" (_SFR_MEM_ADDR(_WD_CONTROL_REG)), \
"r" ((uint8_t) ((1 << _WD_CHANGE_BIT) | (1 << WDE))) \
: "r0");
}
// ----------------------------------------------------------------------------
int
main(void) __attribute__((naked)) \
__attribute__((section(".init9")));
int
main(void)
{
enum {
IDLE,
COLLECT_DATA,
RECEIVED_PAGE
} state = IDLE;
uint8_t next_message_number = -1;
// Do some additional initialization provided by the user
BOOT_INIT;
BOOT_LED_SET_OUTPUT;
BOOT_LED_ON;
// Start timer
TCNT1 = TIMER_PRELOAD;
TCCR1A = 0;
TCCR1B = TIMER_PRESCALER;
// Clear overflow-flag
TIMER_INTERRUPT_FLAG_REGISTER = (1 << TOV1);
while (1)
{
uint8_t command;
uint16_t page;
static uint8_t next_message_data_counter;
// wait until we receive a new message
while ((command = mcp2515_get_message()) == NO_MESSAGE)
{
if (TIMER_INTERRUPT_FLAG_REGISTER & (1 << TOV1))
{
BOOT_LED_OFF;
// timeout => start application
boot_jump_to_application();
}
}
// stop timer
TCCR1B = 0;
// check if the message is a request, otherwise reject it
if ((command & ~COMMAND_MASK) != REQUEST) {
continue;
}
command &= COMMAND_MASK;
// check message number
next_message_number++;
if (message_number != next_message_number)
{
// wrong message number => send NACK
message_number = next_message_number;
next_message_number--;
mcp2515_send_message(command | WRONG_NUMBER_REPSONSE, 0);
continue;
}
BOOT_LED_TOGGLE;
// process command
if (command == IDENTIFY)
{
// version and command of the bootloader
message_data[0] = (BOOTLOADER_TYPE << 4) | (BOOTLOADER_VERSION & 0x0f);
message_data[1] = PAGESIZE_IDENTIFIER;
// number of writeable pages
message_data[2] = HIGH_BYTE(RWW_PAGES);
message_data[3] = LOW_BYTE(RWW_PAGES);
mcp2515_send_message(IDENTIFY | SUCCESSFULL_RESPONSE, 4);
}
else if (command == SET_ADDRESS) // set the current address in the page buffer
{
page = (message_data[0] << 8) | message_data[1];
if (message_data_length == 4 &&
message_data[2] < (SPM_PAGESIZE / 4) &&
page < RWW_PAGES)
{
flashpage = page;
page_buffer_pos = message_data[3];
state = COLLECT_DATA;
mcp2515_send_message(SET_ADDRESS | SUCCESSFULL_RESPONSE, 4);
}
else {
goto error_response;
}
}
else if (command == DATA) // collect data
{
if (message_data_length != 4 ||
page_buffer_pos >= (SPM_PAGESIZE / 4) ||
state == IDLE) {
state = IDLE;
goto error_response;
}
// check if the message starts a new block
if (message_data_counter & START_OF_MESSAGE_MASK)
{
message_data_counter &= ~START_OF_MESSAGE_MASK; // clear flag
next_message_data_counter = message_data_counter;
state = COLLECT_DATA;
}
if (message_data_counter != next_message_data_counter) {
state = IDLE;
goto error_response;
}
next_message_data_counter--;
// copy data
memcpy(page_buffer + page_buffer_pos * 4, message_data, 4);
page_buffer_pos++;
if (message_data_counter == 0)
{
if (page_buffer_pos == (SPM_PAGESIZE / 4))
{
message_data[0] = flashpage >> 8;
message_data[1] = flashpage & 0xff;
if (flashpage >= RWW_PAGES) {
message_data_length = 2;
goto error_response;
}
boot_program_page(flashpage, page_buffer);
page_buffer_pos = 0;
flashpage += 1;
// send ACK
mcp2515_send_message(DATA | SUCCESSFULL_RESPONSE, 2);
}
else {
mcp2515_send_message(DATA | SUCCESSFULL_RESPONSE, 0);
}
}
}
else if (command == START_APP) // start the flashed application program
{
mcp2515_send_message(START_APP | SUCCESSFULL_RESPONSE, 0);
// wait for the mcp2515 to send the message
_delay_ms(50);
// start application
BOOT_LED_OFF;
boot_jump_to_application();
}
#if BOOTLOADER_TYPE > 0
else if (command == GET_FUSEBITS)
{
message_data[0] = boot_lock_fuse_bits_get(GET_LOCK_BITS);
message_data[1] = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS);
message_data[2] = boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS);
message_data[3] = boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS);
mcp2515_send_message(GET_FUSEBITS | SUCCESSFULL_RESPONSE, 4);
}
else if (command == CHIP_ERASE)
{
// erase complete flash except the bootloader region
for (uint32_t i = 0; i < RWW_PAGES; i++ )
{
boot_page_erase(i * SPM_PAGESIZE);
boot_spm_busy_wait();
}
boot_rww_enable();
mcp2515_send_message(CHIP_ERASE | SUCCESSFULL_RESPONSE, 0);
}
/* // der folgende Teil muss noch überarbeitet werden!!!
else if (command == READ_EEPROM)
{
// Lese 1..6 Byte aus dem EEprom
if (message_length == 5 && message_data[4] > 0 && message_data[4] <= 6)
{
uint16_t ee_ptr = (message_data[2] << 8) | message_data[3];
if (ee_ptr <= E2END) {
message_length = message_data[4] + 2;
eeprom_read_block(message_data + 2, (void *) ee_ptr, message_data[4]);
break;
}
}
response = NACK;
}
else if (command == WRITE_EEPROM)
{
// schreibe 1..4 Byte ins EEprom
if (message_length > 4) {
uint16_t ee_ptr = (message_data[2] << 8) | message_data[3];
if (ee_ptr <= E2END) {
eeprom_write_block(message_data + 4,(void *) ee_ptr, message_length - 4);
response = ACK;
break;
}
}
response = NACK;
}
else if (command == READ_FLASH)
{
// Lese 1..65556 Byte aus dem Flash. Bei mehr als 6 Zeichen
// wird das Ergebniss auf mehrere Nachrichten verteilt.
if (message_length == 6)
{
uint16_t flash_ptr = (message_data[2] << 8) | message_data[3];
if (flash_ptr <= FLASHEND)
{
uint16_t number = (message_data[4] << 8) | message_data[5];
// Anzahl der zu senden Nachrichten bestimmen
div_t r = div(number, 6);
number = r.quot;
if (r.rem > 0)
number += 1;
uint16_t counter = 0;
for (uint16_t i=0;i<number;i++)
{
if (i == r.quot)
// das letze Paket ist eventl. kuerzer
message_length = r.rem;
else
message_length = 6;
// FIXME
//memcpy_P( message_data + 2, (PGM_VOID_P) flash_ptr, message_length );
flash_ptr += message_length;
message_data[1] = counter;
counter = (counter + 1) & 0x3f;
// Nachricht verschicken
mcp2515_send_message(0);
}
response = ACK;
break;
}
}
response = NACK;
}*/
#endif
else
{
error_response:
mcp2515_send_message( command | ERROR_RESPONSE, message_data_length );
}
}
}
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/src/xpcc/architecture/platform/arm7/common/abort.h | // coding: utf-8
// ----------------------------------------------------------------------------
/* Copyright (c) 2010, Roboterclub Aachen e.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Roboterclub Aachen e.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// ----------------------------------------------------------------------------
#ifndef XPCC__ABORT_H
#define XPCC__ABORT_H
#include <stdint.h>
typedef struct
{
uint32_t sp_usr;
uint32_t sp_fiq;
uint32_t sp_irq;
uint32_t sp_svc;
uint32_t reg[16];
uint32_t pc;
uint32_t abort_id;
uint32_t cpsr;
} AbortContext;
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Abort handler
*
* Implement this function to
*/
void
_abortHandler(const AbortContext *context);
#ifdef __cplusplus
}
#endif
#endif // XPCC__ABORT_H
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/src/xpcc/architecture/platform/cortex_m3/stm32/stm32f1/startup/startup.c | <reponame>jrahlf/3D-Non-Contact-Laser-Profilometer
// coding: utf-8
// ----------------------------------------------------------------------------
/* Copyright (c) 2011, Roboterclub Aachen e.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Roboterclub Aachen e.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ROBOTERCL<NAME>HEN E.V. ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// ----------------------------------------------------------------------------
#include <stdint.h>
#include <stm32f10x.h>
#include <xpcc/architecture/utils.hpp>
#include <xpcc_config.hpp>
// ----------------------------------------------------------------------------
#define SYSTICK_RELOAD_VAL 71999
#define FLASH_WAIT_STATE_0 0x0
#define FLASH_WAIT_STATE_1 0x1
#define FLASH_WAIT_STATE_2 0x2
#if defined STM32F10X_LD
# define NR_INTERRUPTS 43
#elif defined STM32F10X_MD
# define NR_INTERRUPTS 43
#elif defined STM32F10X_HD || defined STM32F10X_XL
# define NR_INTERRUPTS 60
#elif defined STM32F10X_CL
# define NR_INTERRUPTS 68
#endif
// ----------------------------------------------------------------------------
/*
* Provide weak aliases for each Exception handler to defaultHandler.
* As they are weak aliases, any function with the same name will override
* this definition.
*/
#define ALIAS(f) __attribute__ ((weak, alias (#f)))
void Reset_Handler(void);
void NMI_Handler(void) ALIAS(defaultHandler);
void HardFault_Handler(void);// ALIAS(defaultHandler);
void MemManage_Handler(void) ALIAS(defaultHandler);
void BusFault_Handler(void) ALIAS(defaultHandler);
void UsageFault_Handler(void) ALIAS(defaultHandler);
void SVC_Handler(void) ALIAS(defaultHandler);
void DebugMon_Handler(void) ALIAS(defaultHandler);
void PendSV_Handler(void) ALIAS(defaultHandler);
void SysTick_Handler(void) ALIAS(defaultHandler);
void WWDG_IRQHandler(void) ALIAS(defaultHandler);
void PVD_IRQHandler(void) ALIAS(defaultHandler);
void TAMPER_IRQHandler(void) ALIAS(defaultHandler);
void RTC_IRQHandler(void) ALIAS(defaultHandler);
void FLASH_IRQHandler(void) ALIAS(defaultHandler);
void RCC_IRQHandler(void) ALIAS(defaultHandler);
void EXTI0_IRQHandler(void) ALIAS(defaultHandler);
void EXTI1_IRQHandler(void) ALIAS(defaultHandler);
void EXTI2_IRQHandler(void) ALIAS(defaultHandler);
void EXTI3_IRQHandler(void) ALIAS(defaultHandler);
void EXTI4_IRQHandler(void) ALIAS(defaultHandler);
void DMA1_Channel1_IRQHandler(void) ALIAS(defaultHandler);
void DMA1_Channel2_IRQHandler(void) ALIAS(defaultHandler);
void DMA1_Channel3_IRQHandler(void) ALIAS(defaultHandler);
void DMA1_Channel4_IRQHandler(void) ALIAS(defaultHandler);
void DMA1_Channel5_IRQHandler(void) ALIAS(defaultHandler);
void DMA1_Channel6_IRQHandler(void) ALIAS(defaultHandler);
void DMA1_Channel7_IRQHandler(void) ALIAS(defaultHandler);
void ADC1_2_IRQHandler(void) ALIAS(defaultHandler);
#if defined (STM32F10X_CL)
void CAN1_TX_IRQHandler(void) ALIAS(defaultHandler);
void CAN1_RX0_IRQHandler(void) ALIAS(defaultHandler);
#else
void USB_HP_CAN1_TX_IRQHandler(void) ALIAS(defaultHandler);
void USB_LP_CAN1_RX0_IRQHandler(void) ALIAS(defaultHandler);
#endif
void CAN1_RX1_IRQHandler(void) ALIAS(defaultHandler);
void CAN1_SCE_IRQHandler(void) ALIAS(defaultHandler);
void EXTI9_5_IRQHandler(void) ALIAS(defaultHandler);
#if defined (STM32F10X_XL)
void TIM1_BRK_TIM9_IRQHandler(void) ALIAS(defaultHandler);
void TIM1_UP_TIM10_IRQHandler(void) ALIAS(defaultHandler);
void TIM1_TRG_COM_TIM11_IRQHandler(void) ALIAS(defaultHandler);
#else
void TIM1_BRK_IRQHandler(void) ALIAS(defaultHandler);
void TIM1_UP_IRQHandler(void) ALIAS(defaultHandler);
void TIM1_TRG_COM_IRQHandler(void) ALIAS(defaultHandler);
#endif
void TIM1_CC_IRQHandler(void) ALIAS(defaultHandler);
void TIM2_IRQHandler(void) ALIAS(defaultHandler);
void TIM3_IRQHandler(void) ALIAS(defaultHandler);
void TIM4_IRQHandler(void) ALIAS(defaultHandler);
void I2C1_EV_IRQHandler(void) ALIAS(defaultHandler);
void I2C1_ER_IRQHandler(void) ALIAS(defaultHandler);
void I2C2_EV_IRQHandler(void) ALIAS(defaultHandler);
void I2C2_ER_IRQHandler(void) ALIAS(defaultHandler);
void SPI1_IRQHandler(void) ALIAS(defaultHandler);
void SPI2_IRQHandler(void) ALIAS(defaultHandler);
void USART1_IRQHandler(void) ALIAS(defaultHandler);
void USART2_IRQHandler(void) ALIAS(defaultHandler);
void USART3_IRQHandler(void) ALIAS(defaultHandler);
void EXTI15_10_IRQHandler(void) ALIAS(defaultHandler);
void RTCAlarm_IRQHandler(void) ALIAS(defaultHandler);
#if defined (STM32F10X_CL)
void OTG_FS_WKUP_IRQHandler(void) ALIAS(defaultHandler);
void TIM5_IRQHandler(void) ALIAS(defaultHandler);
void SPI3_IRQHandler(void) ALIAS(defaultHandler);
void UART4_IRQHandler(void) ALIAS(defaultHandler);
void UART5_IRQHandler(void) ALIAS(defaultHandler);
void TIM6_IRQHandler(void) ALIAS(defaultHandler);
void TIM7_IRQHandler(void) ALIAS(defaultHandler);
void DMA2_Channel1_IRQHandler(void) ALIAS(defaultHandler);
void DMA2_Channel2_IRQHandler(void) ALIAS(defaultHandler);
void DMA2_Channel3_IRQHandler(void) ALIAS(defaultHandler);
void DMA2_Channel4_IRQHandler(void) ALIAS(defaultHandler);
void DMA2_Channel5_IRQHandler(void) ALIAS(defaultHandler);
void ETH_IRQHandler(void) ALIAS(defaultHandler);
void ETH_WKUP_IRQHandler(void) ALIAS(defaultHandler);
void CAN2_TX_IRQHandler(void) ALIAS(defaultHandler);
void CAN2_RX0_IRQHandler(void) ALIAS(defaultHandler);
void CAN2_RX1_IRQHandler(void) ALIAS(defaultHandler);
void CAN2_SCE_IRQHandler(void) ALIAS(defaultHandler);
void OTG_FS_IRQHandler(void) ALIAS(defaultHandler);
#else
void USBWakeUp_IRQHandler(void) ALIAS(defaultHandler);
#if defined (STM32F10X_HD) || defined (STM32F10X_XL)
void TIM8_BRK_TIM12_IRQHandler(void) ALIAS(defaultHandler);
void TIM8_UP_TIM13_IRQHandler(void) ALIAS(defaultHandler);
void TIM8_TRG_COM_TIM14_IRQHandler(void) ALIAS(defaultHandler);
void TIM8_CC_IRQHandler(void) ALIAS(defaultHandler);
void ADC3_IRQHandler(void) ALIAS(defaultHandler);
void FSMC_IRQHandler(void) ALIAS(defaultHandler);
void SDIO_IRQHandler(void) ALIAS(defaultHandler);
void TIM5_IRQHandler(void) ALIAS(defaultHandler);
void SPI3_IRQHandler(void) ALIAS(defaultHandler);
void UART4_IRQHandler(void) ALIAS(defaultHandler);
void UART5_IRQHandler(void) ALIAS(defaultHandler);
void TIM6_IRQHandler(void) ALIAS(defaultHandler);
void TIM7_IRQHandler(void) ALIAS(defaultHandler);
void DMA2_Channel1_IRQHandler(void) ALIAS(defaultHandler);
void DMA2_Channel2_IRQHandler(void) ALIAS(defaultHandler);
void DMA2_Channel3_IRQHandler(void) ALIAS(defaultHandler);
void DMA2_Channel4_5_IRQHandler(void) ALIAS(defaultHandler);
#endif
#endif
// ----------------------------------------------------------------------------
// Interrupt vectors
typedef void (* const FunctionPointer)(void);
// defined in the linkerscript
extern uint32_t __stack_end;
#if CORTEX_VECTORS_RAM
// Define the vector table
FunctionPointer flashVectors[4]
__attribute__ ((section(".reset"))) =
{
(FunctionPointer) &__stack_end, // stack pointer
Reset_Handler, // code entry point
NMI_Handler, // NMI handler
HardFault_Handler, // hard fault handler
};
FunctionPointer ramVectors[] __attribute__ ((section(".vectors"))) =
#else
FunctionPointer flashVectors[] __attribute__ ((section(".reset"))) =
#endif
{
(FunctionPointer) &__stack_end, // stack pointer
Reset_Handler, // code entry point
NMI_Handler, // NMI handler
HardFault_Handler, // hard fault handler
MemManage_Handler, // MPU Fault Handler
BusFault_Handler, // Bus Fault Handler
UsageFault_Handler, // Usage Fault Handler
0,
0,
0,
0,
SVC_Handler, // SVCall Handler
DebugMon_Handler, // Debug Monitor Handler
0,
PendSV_Handler, // PendSV Handler
SysTick_Handler, // SysTick Handler
// Peripheral interrupts (STM32 specific)
WWDG_IRQHandler, // 0: Window Watchdog
PVD_IRQHandler, // 1: PVD through EXTI Line detect
TAMPER_IRQHandler, // 2: Tamper
RTC_IRQHandler, // 3: RTC
FLASH_IRQHandler, // 4: Flash
RCC_IRQHandler, // 5: RCC
EXTI0_IRQHandler, // EXTI Line 0
EXTI1_IRQHandler, // EXTI Line 1
EXTI2_IRQHandler, // EXTI Line 2
EXTI3_IRQHandler, // EXTI Line 3
EXTI4_IRQHandler, // 10: EXTI Line 4
DMA1_Channel1_IRQHandler, // DMA1 Channel 1
DMA1_Channel2_IRQHandler, // DMA1 Channel 2
DMA1_Channel3_IRQHandler, // DMA1 Channel 3
DMA1_Channel4_IRQHandler, // DMA1 Channel 4
DMA1_Channel5_IRQHandler, // 15: DMA1 Channel 5
DMA1_Channel6_IRQHandler, // DMA1 Channel 6
DMA1_Channel7_IRQHandler, // DMA1 Channel 7
ADC1_2_IRQHandler, // ADC1 & ADC2
#if defined(STM32F10X_CL)
CAN1_TX_IRQHandler, //
CAN1_RX0_IRQHandler, // 20:
#else
USB_HP_CAN1_TX_IRQHandler, // USB High Priority or CAN1 TX
USB_LP_CAN1_RX0_IRQHandler, // 20: USB Low Priority or CAN1 RX0
#endif
CAN1_RX1_IRQHandler, // CAN1 RX1
CAN1_SCE_IRQHandler, // CAN1 SCE
EXTI9_5_IRQHandler, // EXTI Line 9..5
#if defined (STM32F10X_XL)
TIM1_BRK_TIM9_IRQHandler, // TIM1 Break
TIM1_UP_TIM10_IRQHandler, // 25: TIM1 Update
TIM1_TRG_COM_TIM11_IRQHandler, // TIM1 Trigger and Commutation
#else
TIM1_BRK_IRQHandler, // TIM1 Break
TIM1_UP_IRQHandler, // 25: TIM1 Update
TIM1_TRG_COM_IRQHandler, // TIM1 Trigger and Commutation
#endif
TIM1_CC_IRQHandler, // TIM1 Capture Compare
TIM2_IRQHandler, // TIM2
TIM3_IRQHandler, // TIM3
TIM4_IRQHandler, // 30: TIM4
I2C1_EV_IRQHandler, // I2C1 Event
I2C1_ER_IRQHandler, // I2C1 Error
I2C2_EV_IRQHandler, // I2C2 Event
I2C2_ER_IRQHandler, // I2C2 Error
SPI1_IRQHandler, // 35: SPI1
SPI2_IRQHandler, // SPI2
USART1_IRQHandler, // USART1
USART2_IRQHandler, // USART2
USART3_IRQHandler, // USART3
EXTI15_10_IRQHandler, // 40: EXTI Line 15..10
RTCAlarm_IRQHandler, // RTC Alarm through EXTI Line
#if defined(STM32F10X_CL)
OTG_FS_WKUP_IRQHandler,
#else
USBWakeUp_IRQHandler, // 42: USB Wakeup from suspend
#endif
#if defined (STM32F10X_HD) || defined (STM32F10X_XL) || defined(STM32F10X_CL)
#if defined(STM32F10X_CL)
0,
0,
0, // 45: unused
0,
0,
0,
0, // 49: unused
#else
TIM8_BRK_TIM12_IRQHandler,
TIM8_UP_TIM13_IRQHandler,
TIM8_TRG_COM_TIM14_IRQHandler, // 45:
TIM8_CC_IRQHandler,
ADC3_IRQHandler,
FSMC_IRQHandler,
SDIO_IRQHandler, // 49:
#endif
TIM5_IRQHandler, // 50:
SPI3_IRQHandler,
UART4_IRQHandler,
UART5_IRQHandler,
TIM6_IRQHandler,
TIM7_IRQHandler, // 55:
DMA2_Channel1_IRQHandler,
DMA2_Channel2_IRQHandler,
DMA2_Channel3_IRQHandler, // 58:
#if defined(STM32F10X_CL)
DMA2_Channel4_IRQHandler,
DMA2_Channel5_IRQHandler, // 60:
ETH_IRQHandler,
ETH_WKUP_IRQHandler,
CAN2_TX_IRQHandler,
CAN2_RX0_IRQHandler,
CAN2_RX1_IRQHandler, // 65:
CAN2_SCE_IRQHandler,
OTG_FS_IRQHandler, // 67:
#else
DMA2_Channel4_5_IRQHandler, // 59:
#endif
#endif
};
// ----------------------------------------------------------------------------
// The following are constructs created by the linker, indicating where the
// the "data" and "bss" segments reside in memory. The initializers for the
// for the "data" segment resides immediately following the "text" segment.
extern uint32_t __fastcode_load;
extern uint32_t __fastcode_start;
extern uint32_t __fastcode_end;
extern uint32_t __data_load;
extern uint32_t __data_start;
extern uint32_t __data_end;
extern uint32_t __bss_start;
extern uint32_t __bss_end;
// Application's main function
extern int main(void);
extern void __libc_init_array(void);
extern void exit(int) __attribute__ ((noreturn, weak));
// ----------------------------------------------------------------------------
// This is the code that gets called when the processor first starts execution
// following a reset event. Only the absolutely necessary set is performed,
// after which the application supplied main() routine is called. Any fancy
// actions (such as making decisions based on the reset cause register, and
// resetting the bits in that register) are left solely in the hands of the
// application.
void
Reset_Handler(void)
{
// startup delay
for (volatile unsigned long i = 0; i < 50000; i++)
{
}
// Copy functions to RAM (.fastcode)
uint32_t* src = &__fastcode_load;
uint32_t* dest = &__fastcode_start;
while (dest < &__fastcode_end)
{
*(dest++) = *(src++);
}
// Copy the data segment initializers from flash to RAM (.data)
src = &__data_load;
dest = &__data_start;
while (dest < &__data_end)
{
*(dest++) = *(src++);
}
// Fill the bss segment with zero (.bss)
dest = &__bss_start;
while (dest < &__bss_end)
{
*(dest++) = 0;
}
// set 2 waitstates & enable flash prefetch
FLASH->ACR = (FLASH->ACR & ~FLASH_ACR_LATENCY) | FLASH_WAIT_STATE_2 | FLASH_ACR_PRFTBE;
// enable clock
// GPIOA-D
RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_IOPDEN;
RCC->APB2RSTR |= RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPBRST | RCC_APB2RSTR_IOPCRST | RCC_APB2RSTR_IOPDRST;
RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPARST | RCC_APB2RSTR_IOPBRST | RCC_APB2RSTR_IOPCRST | RCC_APB2RSTR_IOPDRST);
#if defined(STM32F10X_CL)
// GPIOE
RCC->APB2ENR |= RCC_APB2ENR_IOPEEN;
RCC->APB2RSTR |= RCC_APB2RSTR_IOPERST;
RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPERST);
#elif defined (STM32F10X_HD) || defined (STM32F10X_XL)
// GPIOE-G
RCC->APB2ENR |= RCC_APB2ENR_IOPEEN | RCC_APB2ENR_IOPFEN | RCC_APB2ENR_IOPGEN;
RCC->APB2RSTR |= RCC_APB2RSTR_IOPERST | RCC_APB2RSTR_IOPFRST | RCC_APB2RSTR_IOPGRST;
RCC->APB2RSTR &= ~(RCC_APB2RSTR_IOPERST | RCC_APB2RSTR_IOPFRST | RCC_APB2RSTR_IOPGRST);
#endif
// setup NVIC
// set vector table
const uint32_t offset = 0;
SCB->VTOR = 0x08000000 | (offset & 0x1FFFFF80);
// Lower priority level for all peripheral interrupts to lowest possible
for (uint32_t i = 0; i < NR_INTERRUPTS; i++) {
const uint32_t priority = 0xF;
NVIC->IP[i] = (priority & 0xF) << 4;
}
// Set the PRIGROUP[10:8] bits to
// - 4 bits for pre-emption priority,
// - 0 bits for subpriority
SCB->AIRCR = 0x05FA0000 | 0x300;
// enable clock for alternative functions
RCC->APB2ENR |= RCC_APB2ENR_AFIOEN;
RCC->APB2RSTR |= RCC_APB2RSTR_AFIORST;
RCC->APB2RSTR &= ~RCC_APB2RSTR_AFIORST;
// enable fault handlers
/*SCB->SHCSR |=
SCB_SHCSR_BUSFAULTENA_Msk |
SCB_SHCSR_USGFAULTENA_Msk |
SCB_SHCSR_MEMFAULTENA_Msk;*/
// Call CTORS of static objects
__libc_init_array();
// Call the application's entry point
main();
exit(1);
while (1)
{
}
}
// ----------------------------------------------------------------------------
/**
* @brief Default interrupt handler
*
* This functions gets called if an interrupt handler is not defines. It just
* enters an infinite loop leaving the processor state intact for an debugger
* to be examined.
*/
void
defaultHandler(void)
{
while (1)
{
}
}
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/src/xpcc/architecture/platform/arm7/common/constants.h | // coding: utf-8
// ----------------------------------------------------------------------------
/* Copyright (c) 2011, Roboterclub Aachen e.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Roboterclub Aachen e.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ROBOTERCLUB AACHEN E.V. ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// ----------------------------------------------------------------------------
/**
* \file constants.h
* \brief Register description and constants
*
* This file will be included by C and Assembler code. Therefore it must
* only contain Preprocessor directives.
*
* When called from Assembler the __ASSEMBLER__ define is available.
*/
#ifndef XPCC__CONSTANTS_H
#define XPCC__CONSTANTS_H
/*
* ARM register quick reference:
*
* Name Number ARM Procedure Calling Standard Role
*
* a1 r0 argument 1 / integer result / scratch register / argc
* a2 r1 argument 2 / scratch register / argv
* a3 r2 argument 3 / scratch register / envp
* a4 r3 argument 4 / scratch register
* v1 r4 register variable
* v2 r5 register variable
* v3 r6 register variable
* v4 r7 register variable
* v5 r8 register variable
* sb/v6 r9 static base / register variable
* sl/v7 r10 stack limit / stack chunk handle / reg. variable
* fp r11 frame pointer
* ip r12 scratch register / new-sb in inter-link-unit calls
* sp r13 lower end of current stack frame
* lr r14 link address / scratch register
* pc r15 program counter
*/
/* Standard definitions of Mode bits and Interrupt (I & F) flags in PSRs */
#define ARM_MODE_MASK 0x1F /* lower 5 bits of CPSR */
#define ARM_MODE_USR 0x10 // User Mode
#define ARM_MODE_FIQ 0x11 // Fast Interrupt Mode
#define ARM_MODE_IRQ 0x12 // Interrupt Mode
#define ARM_MODE_SVC 0x13 // Supervisor Mode
#define ARM_MODE_ABT 0x17 // Abort Mode
#define ARM_MODE_UND 0x1B // Unidentified Instruction Mode
#define ARM_MODE_SYS 0x1F // System Mode (uses the same Stack as User Mode)
#define ARM_CPSR_N_BIT (1 << 31)
#define ARM_CPSR_Z_BIT (1 << 30)
#define ARM_CPSR_C_BIT (1 << 29)
#define ARM_CPSR_V_BIT (1 << 28)
#define ARM_CPSR_I_BIT (1 << 7)
#define ARM_CPSR_F_BIT (1 << 6)
#define ARM_CPSR_T_BIT (1 << 5)
#define ARM_IRQ_DISABLE (1 << 7) // when I bit is set, IRQ is disabled
#define ARM_FIQ_DISABLE (1 << 6) // when F bit is set, FIQ is disabled
#define ARM_THUMB_ENABLE (1 << 5) // when T bit is set, Thumb mode is enabled
// constant to pre-fill the stack
#define STACK_FILL 0xaaaaaaaa
#define MAGIC_MARKER 0xdeadbeef
// Registers
#if defined(__ARM_AT91__) || defined(__ARM_LPC2000__)
# define INTERRUPT_BASE_REGISTER 0xFFFFF000
#else
# error "Unknown device family: Check the value of VIC_BASE_REGISTER"
#endif
#endif // XPCC__CONSTANTS_H
|
jrahlf/3D-Non-Contact-Laser-Profilometer | xpcc/src/xpcc/architecture/platform/cortex_m0/lpc/startup/startup.c | <reponame>jrahlf/3D-Non-Contact-Laser-Profilometer
// coding: utf-8
// ----------------------------------------------------------------------------
/* Copyright (c) 2012, Roboterclub Aachen e.V.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Roboterclub Aachen e.V. nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ROBOTERCL<NAME>HEN E.V. ''AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ROBOTERCLUB AACHEN E.V. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// ----------------------------------------------------------------------------
#include <stdint.h>
#include <xpcc_config.hpp>
#include <lpc11xx/cmsis/LPC11xx.h>
#define ALIAS(f) __attribute__ ((weak, alias (#f)))
// Forward declaration of the default handlers. These are aliased.
// When the application defines a handler (with the same name), this will
// automatically take precedence over these weak definitions
void Reset_Handler(void);
void NMI_Handler(void) ALIAS(defaultHandler);
void HardFault_Handler(void) ALIAS(defaultHandler);
void SVCall_Handler(void) ALIAS(defaultHandler);
void PendSV_Handler(void) ALIAS(defaultHandler);
void SysTick_Handler(void) ALIAS(defaultHandler);
// Forward declaration of the specific IRQ handlers. These are aliased
// to the IntDefaultHandler, which is a 'forever' loop. When the application
// defines a handler (with the same name), this will automatically take
// precedence over these weak definitions
void CAN_IRQHandler(void) ALIAS(defaultHandler);
void SSP1_IRQHandler(void) ALIAS(defaultHandler);
void I2C_IRQHandler(void) ALIAS(defaultHandler);
void TIMER16_0_IRQHandler(void) ALIAS(defaultHandler);
void TIMER16_1_IRQHandler(void) ALIAS(defaultHandler);
void TIMER32_0_IRQHandler(void) ALIAS(defaultHandler);
void TIMER32_1_IRQHandler(void) ALIAS(defaultHandler);
void SSP0_IRQHandler(void) ALIAS(defaultHandler);
void UART_IRQHandler(void) ALIAS(defaultHandler);
void ADC_IRQHandler(void) ALIAS(defaultHandler);
void WDT_IRQHandler(void) ALIAS(defaultHandler);
void BOD_IRQHandler(void) ALIAS(defaultHandler);
void PIOINT3_IRQHandler(void) ALIAS(defaultHandler);
void PIOINT2_IRQHandler(void) ALIAS(defaultHandler);
void PIOINT1_IRQHandler(void) ALIAS(defaultHandler);
void PIOINT0_IRQHandler(void) ALIAS(defaultHandler);
void WAKEUP_IRQHandler(void) ALIAS(defaultHandler);
// ----------------------------------------------------------------------------
// The vector table. Note that the proper constructs must be placed on this to
// ensure that it ends up at physical address 0x00000000.
typedef void (* const FunctionPointer)(void);
// defined in the linkerscript
extern uint32_t __stack_end;
#if CORTEX_VECTORS_RAM
// Define the vector table
FunctionPointer flashVectors[4]
__attribute__ ((section(".reset"))) =
{
(FunctionPointer) &__stack_end, // stack pointer
Reset_Handler, // code entry point
NMI_Handler, // NMI handler
HardFault_Handler, // hard fault handler
};
FunctionPointer ramVectors[] __attribute__ ((section(".vectors"))) =
#else
FunctionPointer flashVectors[] __attribute__ ((section(".reset"))) =
#endif
{
(FunctionPointer) &__stack_end, // The initial stack pointer
Reset_Handler, // The reset handler
NMI_Handler, // The NMI handler
HardFault_Handler, // The hard fault handler
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
0, // Reserved
SVCall_Handler, // SVCall handler
0, // Reserved
0, // Reserved
PendSV_Handler, // The PendSV handler
SysTick_Handler, // The SysTick handler
// Wakeup sources for the I/O pins:
// PIO0 (0:11)
// PIO1 (0)
WAKEUP_IRQHandler, // PIO0_0 Wakeup
WAKEUP_IRQHandler, // PIO0_1 Wakeup
WAKEUP_IRQHandler, // PIO0_2 Wakeup
WAKEUP_IRQHandler, // PIO0_3 Wakeup
WAKEUP_IRQHandler, // PIO0_4 Wakeup
WAKEUP_IRQHandler, // PIO0_5 Wakeup
WAKEUP_IRQHandler, // PIO0_6 Wakeup
WAKEUP_IRQHandler, // PIO0_7 Wakeup
WAKEUP_IRQHandler, // PIO0_8 Wakeup
WAKEUP_IRQHandler, // PIO0_9 Wakeup
WAKEUP_IRQHandler, // PIO0_10 Wakeup
WAKEUP_IRQHandler, // PIO0_11 Wakeup
WAKEUP_IRQHandler, // PIO1_0 Wakeup
CAN_IRQHandler, // C_CAN Interrupt
SSP1_IRQHandler, // SPI/SSP1 Interrupt
I2C_IRQHandler, // I2C0
TIMER16_0_IRQHandler, // CT16B0 (16-bit Timer 0)
TIMER16_1_IRQHandler, // CT16B1 (16-bit Timer 1)
TIMER32_0_IRQHandler, // CT32B0 (32-bit Timer 0)
TIMER32_1_IRQHandler, // CT32B1 (32-bit Timer 1)
SSP0_IRQHandler, // SPI/SSP0 Interrupt
UART_IRQHandler, // UART0
0, // Reserved
0, // Reserved
ADC_IRQHandler, // ADC (A/D Converter)
WDT_IRQHandler, // WDT (Watchdog Timer)
BOD_IRQHandler, // BOD (Brownout Detect)
0, // Reserved
PIOINT3_IRQHandler, // PIO INT3
PIOINT2_IRQHandler, // PIO INT2
PIOINT1_IRQHandler, // PIO INT1
PIOINT0_IRQHandler, // PIO INT0
};
// ----------------------------------------------------------------------------
// The following are constructs created by the linker, indicating where the
// the "data" and "bss" segments reside in memory. The initializers for the
// for the "data" segment resides immediately following the "text" segment.
extern uint32_t __fastcode_load;
extern uint32_t __fastcode_start;
extern uint32_t __fastcode_end;
extern uint32_t __data_load;
extern uint32_t __data_start;
extern uint32_t __data_end;
extern uint32_t __bss_start;
extern uint32_t __bss_end;
// Application's main function
extern int main(void);
extern void __xpcc_initialize_memory(void);
extern void __libc_init_array(void);
extern void exit(int) __attribute__ ((noreturn, weak));
// ----------------------------------------------------------------------------
// This is the code that gets called when the processor first starts execution
// following a reset event. Only the absolutely necessary set is performed,
// after which the application supplied main() routine is called. Any fancy
// actions (such as making decisions based on the reset cause register, and
// resetting the bits in that register) are left solely in the hands of the
// application.
void
Reset_Handler(void)
{
// startup delay
for (volatile unsigned long i = 0; i < 50000; i++)
{
}
// Copy functions to RAM (.fastcode)
uint32_t* src = &__fastcode_load;
uint32_t* dest = &__fastcode_start;
while (dest < &__fastcode_end)
{
*(dest++) = *(src++);
}
// Copy the data segment initializers from flash to RAM (.data)
src = &__data_load;
dest = &__data_start;
while (dest < &__data_end)
{
*(dest++) = *(src++);
}
// Fill the bss segment with zero (.bss)
dest = &__bss_start;
while (dest < &__bss_end)
{
*(dest++) = 0;
}
// Enable AHB clock to the GPIO domain.
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 6);
__xpcc_initialize_memory();
// Call C++ library initialization
__libc_init_array();
main();
exit(1);
while (1)
{
}
}
// ----------------------------------------------------------------------------
/**
* @brief Default interrupt handler
*
* This functions gets called if an interrupt handler is not defines. It just
* enters an infinite loop leaving the processor state intact for an debugger
* to be examined.
*/
void
defaultHandler(void)
{
while (1)
{
}
}
|
Crest/upload | upload.c | #include <stdio.h>
#include <string.h>
#include <errno.h>
static const int line_max = 200;
int
main(int argc, const char *argv[])
{
FILE *file = NULL;
int status = 0;
if ( argc < 2 ) {
fprintf(stderr, "usage: %s <file>...\n", argv[1]);
return 1;
}
for ( int i = 1; i < argc && !status; i++ ) {
const char *name = argv[i];
int line_pos = 1;
int line_num = 1;
file = fopen(name, "r");
if ( !file ) {
fprintf(stderr, "*** FAILED TO OPEN %s : %s ***\n", name, strerror(errno));
status = 1;
break;
}
fprintf(stderr, "*** UPLOADING %s ***%s", name, i == 1 ? "\n" : "");
int ch;
while ( !status && (ch = getc_unlocked(file)) != EOF ) {
if ( line_pos > line_max ) {
fprintf(stderr, "\n*** LINE %i OF %s IS TOO LONG ***\n", line_num, name);
status = 1;
break;
}
putchar_unlocked(ch);
if ( ch == '\n' ) {
while ( !status && (ch = getchar_unlocked()) != 0x06 ) {
switch ( ch ) {
case 0x15:
fprintf(stderr, "*** ERROR IN LINE %i OF %s ***\n", line_num, name);
status = 1;
break;
default:
putc_unlocked(ch, stderr);
break;
}
}
line_pos = 1;
line_num++;
} else {
line_pos++;
}
}
if ( status ) {
fprintf(stderr, "\n*** FAILED TO UPLOAD %s ***\n\n", name);
} else {
fprintf(stderr, "\n*** SUCCESSFUL UPLOAD OF %s ***\n\n", name);
}
fclose(file); file = NULL;
}
if ( file ) {
fclose(file);
}
return status;
}
|
Gnaiqing/gStore | Server/Socket.h | <reponame>Gnaiqing/gStore<gh_stars>0
/*
* Socket.h
*
* Created on: 2014-10-14
* Author: hanshuo
*/
#ifndef _SERVER_SOCKET_H
#define _SERVER_SOCKET_H
#include "../Util/Util.h"
class Socket
{
public:
Socket();
~Socket();
bool create();
bool close();
bool bind(const unsigned short _port); //0~65535
bool listen()const;
bool accept(Socket& _new_socket)const;
bool connect(const std::string _hostname, const unsigned short _port);
bool send(const std::string& _msg)const;
int recv(std::string& _msg)const;
bool isValid()const;
static const int MAX_CONNECTIONS = 20;
static const unsigned short DEFAULT_CONNECT_PORT = 3305;
static const std::string DEFAULT_SERVER_IP;
private:
int sock;
sockaddr_in addr;
};
#endif // _SERVER_SOCKET_H
|
Gnaiqing/gStore | Trie/Trie.h | /*===========================================================================
* Filename: Trie.h
* Author: <NAME>
* Mail: <EMAIL>
* Last modified 2018-01-15
* Description:
* This data structure is used to extract common prefixes from a given dataset,
* and compress/uncompress the dataset according to those prefixes.
==============================================================================*/
#include "TrieNode.h"
#include "../Util/Triple.h"
#include "../Util/Util.h"
#include "../Parser/RDFParser.h"
#include <vector>
using namespace std;
class Trie
{
static const int SAMPLE_UPBOUND = 100000;
static const int LOWBOUND = 20;//this param should change with data sets
//SAMPLE_UPBOUND = 1000000, LOWBOUND = 100 for LUBM500M
//SAMPLE_UPBOUND = 100000, LOWBOUND = 20 for DBpediafull
//SAMPLE_UPVOUND = 300000, LOWBOUND = 30 for WatDiv500M
string store_path;
int curID;
TrieNode *root;
vector <string> dictionary;
void addString(string _str, int _ID);
void WriteDownNode(TrieNode *_node, ofstream &_fout, string _str);
void Release(TrieNode *node);
public:
static const int BUILDMODE = 0;
static const int QUERYMODE = 1;
Trie();
Trie(const string _rdf_file, string _store_path);
~Trie();
bool isInitialized();
bool WriteDown();
void Release();
TripleWithObjType Compress(const TripleWithObjType &_in_triple, int MODE);
string Compress(string _str);
bool LoadDictionary();
string Uncompress(const char *_str, const int len);
string Uncompress(const string &_str, const int len);
bool LoadTrie(string dictionary_path);
};
|
RHQNew/RHQCocoapods | Example/RHQCocoapods/RHQViewController.h | //
// RHQViewController.h
// RHQCocoapods
//
// Created by 倩 on 06/14/2021.
// Copyright (c) 2021 倩. All rights reserved.
//
@import UIKit;
@interface RHQViewController : UIViewController
@end
|
RHQNew/RHQCocoapods | Example/RHQCocoapods/RHQRootViewController.h | //
// RHQRootViewController.h
// RHQCocoapods_Example
//
// Created by 倩 on 2021/6/14.
// Copyright © 2021 倩. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface RHQRootViewController : UINavigationController
@end
NS_ASSUME_NONNULL_END
|
RHQNew/RHQCocoapods | Example/RHQCocoapods/RHQAppDelegate.h | //
// RHQAppDelegate.h
// RHQCocoapods
//
// Created by 倩 on 06/14/2021.
// Copyright (c) 2021 倩. All rights reserved.
//
@import UIKit;
@interface RHQAppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@end
|
RHQNew/RHQCocoapods | Example/Pods/Target Support Files/Pods-RHQCocoapods_Tests/Pods-RHQCocoapods_Tests-umbrella.h | <gh_stars>0
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#else
#ifndef FOUNDATION_EXPORT
#if defined(__cplusplus)
#define FOUNDATION_EXPORT extern "C"
#else
#define FOUNDATION_EXPORT extern
#endif
#endif
#endif
FOUNDATION_EXPORT double Pods_RHQCocoapods_TestsVersionNumber;
FOUNDATION_EXPORT const unsigned char Pods_RHQCocoapods_TestsVersionString[];
|
AndrejGajdos/C-assignments | histogram/equalize.c | #include <stdio.h>
#include <stdlib.h>
#include "processing.h"
const size_t INPUT_BUFFER = 1024;
const size_t INPUT_MAX = 255;
void LoadImage(const char *fileName, unsigned char *image, size_t *imgSize);
void SaveImage(const char *fileName, unsigned char *image, size_t imgSize);
/***********************************************************************************/
/***********************************************************************************/
int main(int argc, char *argv[])
{
if(argc != 6)
{
printf("Usage: <program> imageFile maxValue sizeX sizeY threshold");
return 1;
}
const char *image = argv[1];
size_t maxVal = atoi(argv[2]);
size_t sizeX = atoi(argv[3]);
size_t sizeY = atoi(argv[4]);
unsigned char thresh = atoi(argv[5]);
// Here will be the logic loading a input file
size_t imageSize;
size_t histSize = maxVal != 0 ? maxVal+1 : 0;
unsigned char input[INPUT_BUFFER], output[INPUT_BUFFER], binary[INPUT_BUFFER];
unsigned int histogram[INPUT_MAX+1], cumulative[INPUT_MAX+1];
LoadImage(image, input, &imageSize);
//Compute and print the binary image of the input image
Threshold(binary, input, imageSize, thresh);
printf("Input image, range [0, %lu] thresholded with [%u]:\n", maxVal, thresh);
PrintBinaryImage(binary, sizeX, sizeY);
// Compute and print the histogram of the input image
ComputeHistogram(histogram, input, histSize, imageSize);
printf("Input image histogram:\n");
PrintHistogram(histogram, histSize);
// Compute and print the cumulative histogram
ComputeCumulative(cumulative, histogram, histSize);
//PrintHistogram(cumulative, maxVal+1);
// Equalize the image based on the cumulative histogram
Equalize(output, input, cumulative, imageSize, maxVal);
//Compute and print the binary image of the output image
Threshold(binary, output, imageSize, thresh);
printf("Output image, range [0, %lu] thresholded with [%u]:\n", maxVal, thresh);
PrintBinaryImage(binary, sizeX, sizeY);
// Compute and print the histogram of the output image
ComputeHistogram(histogram, output, histSize, imageSize);
printf("Output image histogram:\n");
PrintHistogram(histogram, histSize);
return 0;
}
/***********************************************************************************/
void LoadImage(const char *fileName, unsigned char *image, size_t *imgSize)
{
FILE *file = NULL;
// Open the file
if((file = fopen(fileName, "rt")) == NULL)
{
fprintf(stderr, "Error opening image <%s>!\n", fileName);
exit(2);
}
// Load the pixels
unsigned int pixel;
int count;
*imgSize = 0;
do
{
count = fscanf(file, "%u", &pixel);
if(count == EOF)
break;
image[*imgSize] = (unsigned char)pixel;
(*imgSize)++;
} while(1);
// Close the file
if(file)
fclose(file);
}
/***********************************************************************************/
void SaveImage(const char *fileName, unsigned char *image, size_t imgSize)
{
FILE *file = NULL;
// Open the file
if((file = fopen(fileName, "wt")) == NULL)
{
fprintf(stderr, "Error opening image <%s>!\n", fileName);
exit(3);
}
// Write the pixels
for(size_t i = 0; i < imgSize; i++)
{
fprintf(file, "%u ", image[i]);
}
// Close the file
if(file)
fclose(file);
}
|
AndrejGajdos/C-assignments | priorityQueue/priority_queue.c | <reponame>AndrejGajdos/C-assignments<gh_stars>0
/*
============================================================================
Name : priority_queue.c
Author : 359234
Copyright : <EMAIL>
Description : Queue logic
============================================================================
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "priority_queue.h"
priority_queue create() {
priority_queue queue = {NULL, NULL, 0};
return queue;
}
void push(priority_queue* queue, value_type value, uint remaining_time) {
priority_queue_item* node;
node = malloc(sizeof(priority_queue_item));
memset(node, 0, sizeof(priority_queue_item));
node->value = value;
node->remaining_time = remaining_time;
node->next = NULL;
node->previous = NULL;
if (queue->size == 0)
{
queue->first = node;
queue->last = node;
}
else
{
priority_queue_item* item = queue->first;
while (item != NULL) {
if (node->remaining_time <= item->remaining_time)
{
node->previous = item;
item->next = node;
queue->first = node;
break;
}
if ((node->remaining_time >= item->remaining_time) && (item == queue->last))
{
node->next = item;
item->previous = node;
queue->last = node;
break;
}
if ((node->remaining_time >= item->remaining_time) && (node->remaining_time <= item->previous->remaining_time))
{
node->previous = item->previous;
node->next = item;
item->previous->next = node;
item->previous = node;
break;
}
item = item->previous;
}
}
queue->size++;
}
void pop_top(priority_queue* queue){
if (queue->size > 0) {
priority_queue_item* firstItem = queue->first;
if (queue->size == 1) {
queue->first = NULL;
queue->last = NULL;
} else {
queue->first = queue->first->previous;
queue->first->next = NULL;
}
memset(firstItem, 0, sizeof(priority_queue_item));
free(firstItem);
queue->size--;
}
}
uint top_priority(priority_queue const* queue) {
if(queue->size > 0)
return queue->first->remaining_time;
else
return 0;
}
value_type* top_value(priority_queue const* queue){
if(queue->size > 0)
return &(queue->first->value);
else
return NULL;
}
uint run_top(priority_queue* queue, uint run_time) {
if(queue->size > 0)
{
queue->first->value();
if(queue->first->remaining_time <= run_time)
{
pop_top(queue);
return 0;
}
else {
queue->first->remaining_time -= run_time;
return queue->first->remaining_time;
}
}
else
return 0;
}
void clear(priority_queue* queue) {
if(queue->size > 0)
while (queue->size > 0)
pop_top(queue);
}
priority_queue copy(priority_queue const* q1) {
priority_queue copyQueue = create();
if (q1->size > 0)
{
priority_queue_item* uzolFronty = q1->first;
while(uzolFronty != NULL) {
push(©Queue,uzolFronty->value,uzolFronty->remaining_time);
uzolFronty = uzolFronty->previous;
}
}
return copyQueue;
}
|
AndrejGajdos/C-assignments | base64/myBase64.c | <gh_stars>0
/*
============================================================================
Name : myBase64.c
Author : 359234
Version : 10.3.2010
Copyright : <EMAIL>
Description : Base64 encoding
============================================================================
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// Calculate the power
int MyPow(int base, int exponent) {
int result = 1;
for (int i = 0; i < exponent; i++) {
result *= base;
}
return result;
}
int main(int argc, char *argv[]) {
if(argc > 2) {
printf("Wrong number of arguments!");
return 1;
}
char baseChars[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
//change two last chars
if (argc==2 && strcmp(argv[1], "-URL") == 0) {
baseChars[strlen(baseChars) - 1] = '_';
baseChars[strlen(baseChars) - 2] = '-';
}
int cycle_number = 0; // auxiliary variable
while (1) { // if three chars were entered
unsigned char input = 0; // input char
unsigned char tmp = 0; // auxiliary variable
int binaryTree[24] = {0};
int baseChar = 0; // encoded char
int index = 0; // auxiliary variable
char encoded[6] = {0}; // encoded array
fflush(stdout);
if (cycle_number > 0)
tmp = getchar();
cycle_number++;
input = getchar();
if (input == '\n')
exit(0);
else {
index = 1;
// Conversion one char to binary system
for (int i = 7; i >= 0; --i) {
binaryTree[i] = input % 2;
input = input / 2;
}
// Conversion two or three chars to binary system
for (int j = 1; j < 3 && (input = getchar()) != '\n'; j++) {
if (input != '\n')
index += 1;
for (int i = 7; i >= 0; --i) {
binaryTree[(j * 8) + i] = input % 2;
input = input / 2;
}
}
// Conversion chars from binary system to decimal system using six bites
for (int k = 0; k < 4; ++k) {
for (int i = 0; i < 6; ++i) {
baseChar += binaryTree[(6 * k) + i] * MyPow(2, 5 - i);
}
encoded[k] = baseChars[baseChar];
baseChar = 0;
}
// If two chars were entered last char of output is '='
if ((index == 2) && (argc == 1))
encoded[3] = '=';
// If one char was entered last two chars of output is '='
if ((index == 1) && (argc == 1))
encoded[2] = encoded[3] = '=';
// If two chars were entered, print output
if (argc==2 && strcmp(argv[1], "-URL") == 0 && (index == 2)) {
for (int i = 0; i < 3; i++) {
printf("%c", encoded[i]);
}
}
// If one char was entered, print output
if(argc==2 && strcmp(argv[1], "-URL") == 0 && (index == 1)) {
for (int i = 0; i < 2; i++) {
printf("%c", encoded[i]);
}
}
// If three chars were entered, print output
if(index == 3 || ((index == 1) && (argc == 1)) || ((index == 2) && (argc == 1))) {
for (int i = 0; i < 4; i++) {
printf("%c", encoded[i]);
}
}
if (index != 3) break; // If three chars wasn't entered
if(index == 3) printf("\n");
}
}
printf("\n"); // Put newline to indent program output
return 0;
}
|
AndrejGajdos/C-assignments | histogram/processing.h | <filename>histogram/processing.h
/** @file processing.h*/
/**
* Compute histogram of the given image
*
* @param [out] hist histogram to compute
* @param [in] img input image
* @param [in] histSize histogram size
* @param [in] imgSize image size
* @return nothing
*/
void ComputeHistogram(unsigned int *hist, const unsigned char *img, size_t histSize, size_t imgSize);
/**
* Compute cumulative histogram from the given histogram
*
* @param [out] cumulative histogram to compute
* @param [in] hist input histogram
* @param [in] histSize histogram size
* @return nothing
*/
void ComputeCumulative(unsigned int *cumulative, const unsigned int *hist, size_t histSize);
/**
* Equalize the given image based on the cumulative histogram
*
* @param [out] output image after equalization
* @param [in] input input image
* @param [in] cumulative cumulative histogram of the input image
* @param [in] imgSize image size
* @param [in] maxVal maximal value of the image type
* @return nothing
*/
void Equalize(unsigned char *output, const unsigned char *input, const unsigned int *cumulative, size_t imgSize, size_t maxVal);
/**
* Compute binary image from the given image by thresholding
*
* @param [out] bin computed binary image
* @param [in] img input image
* @param [in] imgSize image size
* @param [in] thresh threshold value to use
* @return nothing
*/
void Threshold(unsigned char *bin, const unsigned char *img, size_t imgSize, unsigned char thresh);
/**
* Prints the given histogram
*
* @param [in] hist histogram to print
* @param [in] histSize histogram size
* @return nothing
*/
void PrintHistogram(const unsigned int *hist, size_t histSize);
/**
* Prints the binary image
*
* @param [in] img binary image to print
* @param [in] sizeX size of the image in the x-dimension
* @param [in] sizeY size of the image in the y-dimension
* @return nothing
*/
void PrintBinaryImage(const unsigned char *img, size_t sizeX, size_t sizeY);
|
AndrejGajdos/C-assignments | histogram/processing.c | <filename>histogram/processing.c<gh_stars>0
/*
============================================================================
Name : processing.c
Author : 359234
Copyright : <EMAIL>
Description : Histogram processing
============================================================================
*/
#include <stdio.h>
#include "processing.h"
#include <string.h>
/***********************************************************************************/
void ComputeHistogram(unsigned int *hist, const unsigned char *img, size_t histSize, size_t imgSize)
{
memset (hist,0,histSize*sizeof(unsigned int));
for(unsigned int i = 0; i < imgSize; i++) {
*(hist + img[i]) += 1;
}
}
/***********************************************************************************/
void ComputeCumulative(unsigned int *cumulative, const unsigned int *hist, size_t histSize)
{
unsigned int tmp = 0;
memset (cumulative,0,histSize*sizeof(unsigned int));
for(unsigned int i = 0; i < histSize; i++) {
tmp += hist[i];
*(cumulative + i) = tmp;
}
}
/***********************************************************************************/
void Equalize(unsigned char *output, const unsigned char *input, const unsigned int *cumulative, size_t imgSize, size_t maxVal)
{
double alpha = (double) maxVal/imgSize;
memset (output,0,imgSize);
for(unsigned int i=0; i < imgSize; i++)
*(output + i) = cumulative[input[i]] * alpha;
}
void Threshold(unsigned char *bin, const unsigned char *img, size_t imgSize, unsigned char thresh)
{
memset (bin,0,imgSize);
for (unsigned int i=0; i < imgSize; i++) {
if (img[i] > thresh)
*(bin+i) = 1;
else
*(bin+i) = 0;
}
}
/***********************************************************************************/
void PrintHistogram(const unsigned int *hist, size_t histSize)
{
unsigned int maxValue = 0;
for(unsigned int j = 1; j< histSize; j++) {
if (hist[0] > hist[j] && (hist[0] > maxValue)) maxValue = hist[0];
if (hist[0] < hist[j] && (hist[j] > maxValue)) maxValue = hist[j];
}
printf(".");
for(unsigned int i = 0; i < histSize; i++)
printf("-");
printf(".\n");
for(unsigned int j = 0; j < maxValue; j++) {
for(unsigned int i = 0; i <= histSize; i++) {
if (i == 0 ) printf("|");
if (i == histSize ) printf("|\n");
if ((i != histSize) && ((hist[i]+j) >= maxValue)) printf("*");
if ((i != histSize) && ((hist[i]+j) < maxValue)) printf(" ");
}
}
printf(".");
for(unsigned int i = 0; i < histSize; i++)
printf("-");
printf(".\n");
printf("\n");
printf("\n");
}
void PrintBinaryImage(const unsigned char *img, size_t sizeX, size_t sizeY)
{
printf(".");
for(unsigned int i = 0; i < sizeX; i++)
printf("-");
printf(".\n");
for(unsigned int j = 0; j < sizeY; j++) {
for(unsigned int i = 0; i <= sizeX; i++) {
if (i == 0) printf ("|");
if (i == sizeX) printf("|\n");
if ((i != sizeX) && (img[(sizeX*j)+i] == 1)) printf("*");
if ((i != sizeX) && ( (img[(sizeX*j)+i] == 0) ) ) printf(" ");
}
}
printf(".");
for(unsigned int i = 0; i < sizeX; i++)
printf("-");
printf(".\n");
printf("\n");
printf("\n");
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.