This commit is contained in:
cfif 2024-12-04 13:10:48 +03:00
commit 3bf706c76e
3 changed files with 129 additions and 0 deletions

38
Inc/Accel.h Normal file
View File

@ -0,0 +1,38 @@
//
// Created by xemon on 23.11.22.
//
#ifndef UVEOS_ON_NATION_ACCEL_H
#define UVEOS_ON_NATION_ACCEL_H
#include <cmsis_os.h>
#include "Accel_QMA6100P.h"
#include "AccelDataFlowInterface.h"
typedef struct {
tAccelQma6100P accel;
tAccelDataFlowInterface accelDataFlow;
osMessageQueueId_t dataQueue;
bool errorDataFlag;
vector3 current;
struct {
osThreadId_t id;
uint32_t stack[256];
StaticTask_t controlBlock;
osThreadAttr_t attr;
} thread;
} tAccel;
void Accel_Init(tAccel *env, tSpiPortIO *accelIO);
void Accel_StartDevice(tAccel *env);
void Accel_StartThread(tAccel *env);
bool Accel_WaitReady(tAccel *env, uint32_t timeout);
#endif //UVEOS_ON_NATION_ACCEL_H

68
Src/Accel.c Normal file
View File

@ -0,0 +1,68 @@
#include <alloca.h>
//
// Created by xemon on 23.11.22.
//
#include <SystemDelayInterface.h>
#include "Accel.h"
#include "CmsisRtosThreadUtils.h"
bool Accel_GetNext(tAccel *env, vector3 *value, uint32_t timeout) {
return osMessageQueueGet(env->dataQueue, value, 0, timeout) == osOK;
}
void Accel_Clear(tAccel *env) {
osMessageQueueReset(env->dataQueue);
}
void Accel_Init(tAccel *env, tSpiPortIO *accelIO) {
AccelQma6100P_Init(&env->accel, accelIO);
InitThreadAtrStatic(&env->thread.attr, "Accel", env->thread.controlBlock, env->thread.stack, osPriorityNormal);
env->thread.id = 0;
env->dataQueue = osMessageQueueNew(128, sizeof(vector3), NULL);
env->accelDataFlow = (tAccelDataFlowInterface) {
.env = env,
.getNext = (accelDataGetNextCall) Accel_GetNext,
.clear = (accelDataClearCall) Accel_Clear,
};
}
void Accel_StartDevice(tAccel *env) {
AccelQma6100P_ConfigureDefaults(&env->accel);
}
bool Accel_WaitReady(tAccel *env, uint32_t timeout) {
uint32_t time_end = SystemGetMs() + timeout;
float len;
do {
len = vector3Len(env->current);
} while ((time_end > SystemGetMs()) && len < 0.1f);
return len > 0.1f;
}
static _Noreturn void Accel_Thread(tAccel *env) {
//todo нужно переделать под таймер и семафор
for (;;) {
if (AccelQma6100P_Read(&env->accel, &env->current)) {
osMessageQueuePut(env->dataQueue, &env->current, 0, 0);
env->errorDataFlag = true;
} else {
env->errorDataFlag = false;
}
SystemDelayMs(1);
}
}
void Accel_StartThread(tAccel *env) {
if (!env->thread.id) {
env->thread.id = osThreadNew((osThreadFunc_t) (Accel_Thread), (void *) (env), &env->thread.attr);
}
}

23
modular.json Normal file
View File

@ -0,0 +1,23 @@
{
"dep": [
{
"type": "git",
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
"repo": "Accel_QMA6100P"
},
{
"type": "git",
"provider": "NAVIGATOR_UVEOS_NATION_TELIT",
"repo": "AccelDataFlowInterface"
}
],
"cmake": {
"inc_dirs": [
"Inc/"
],
"srcs": [
"Src/**.c",
"Src_InitDefaults/**.c"
]
}
}