Перенос на новую организацию GONEC

This commit is contained in:
cfif 2025-01-24 13:22:32 +03:00
commit dd8f463721
3 changed files with 310 additions and 0 deletions

96
Inc/UserIndication.h Normal file
View File

@ -0,0 +1,96 @@
/*
* UserIndication.h
*
* Created on: Oct 29, 2022
* Author: xemon
*/
#ifndef USER_INDICATION_INC_USERINDICATION_H_
#define USER_INDICATION_INC_USERINDICATION_H_
#include <cmsis_os.h>
#include <BaseTypes.h>
#include <GpioPinInterface.h>
//#include <EraGlonassUveos_Indicatior.h>
typedef struct {
tGpioPin red;
tGpioPin green;
} tRedGreenLed;
typedef struct {
tGpioPin red;
tGpioPin green;
tGpioPin blue;
} tOnBoardLed;
typedef enum {
DEVICE_MODE_STARTUP = 0,
DEVICE_MODE_TESTING = 1,
DEVICE_MODE_WAIT_GSM_BOOT = 2,
DEVICE_MODE_ERROR_FLASH = 3,
DEVICE_MODE_ERROR_GSM = 4,
DEVICE_MODE_ERROR_CODEC = 5,
DEVICE_MODE_FAILURE = 6,
DEVICE_MODE_ERROR_ON_INIT_TEST1 = 7,
DEVICE_MODE_ERROR_ON_INIT_TEST2 = 8,
DEVICE_MODE_UVEOS_ERA_WAIT_GNSS = 9,
DEVICE_MODE_UVEOS_ERA_GNSS_READY = 10,
DEVICE_MODE_UVEOS_CALL_INITIATE = 11,
DEVICE_MODE_UVEOS_DIALING = 12,
DEVICE_MODE_UVEOS_MSD_TRANSMIT = 13,
DEVICE_MODE_UVEOS_SMS_TRANSMIT = 14,
DEVICE_MODE_UVEOS_CALL_ACTIVE = 15,
DEVICE_MODE_UVEOS_CALL_FAILURE = 16,
DEVICE_MODE_UVEOS_PASSIVE = 17,
DEVICE_MODE_UVEOS_IN_CALL = 18,
DEVICE_MODE_UVEOS_GARAG_MODE = 19,
} eDeviceModes;
typedef struct {
// tRedGreenLed *uiuLed; //User Interface Unit (Блок интерфейса пользователя/БИП)
// tOnBoardLed *onBoardLed;
eDeviceModes mode;
tStringLink currentModeName;
// tEraGlonassUveosIndicator uveosIndicator;
uint8_t tick;
struct {
osThreadId_t id;
uint32_t stack[128];
StaticTask_t controlBlock;
osThreadAttr_t attr;
} thread;
} tUserIndication;
void UserIndication_Init(
tUserIndication *env,
eDeviceModes initMode
// tRedGreenLed *uiuLed,
// tOnBoardLed *onBoardLed
);
void UserIndication_SetMode(tUserIndication *env, eDeviceModes mode);
void UserIndication_StartThread(tUserIndication *env);
void UserIndication_StopThread(tUserIndication *env);
static const uint8_t UIU_OFF = (0);
static const uint8_t UIU_RED = (0x1 << 0);
static const uint8_t UIU_GREEN = (0x1 << 1);
static const uint8_t UIU_ORANGE = UIU_GREEN | UIU_RED;
void UserIndication_Uiu(tUserIndication *env, uint8_t value);
#endif /* USER_INDICATION_INC_USERINDICATION_H_ */

197
Src/UserIndication.c Normal file
View File

@ -0,0 +1,197 @@
/*
* UserIndication.c
*
* Created on: Jun 3, 2021
* Author: zemon
*/
#include "UserIndication.h"
#include <SystemDelayInterface.h>
#include <CmsisRtosThreadUtils.h>
//static void UserIndication_SetModeUveos(tUserIndication *env, tEraGlonassUveosStatus mode);
static void UserIndication_OnBoard(tUserIndication *env, uint8_t flags);
static void UserIndication_Update(tUserIndication *env);
static const uint8_t BOARD_OFF = (0);
static const uint8_t BOARD_RED = (0x1 << 0);
static const uint8_t BOARD_GREEN = (0x1 << 1);
static const uint8_t BOARD_BLUE = (0x1 << 2);
void UserIndication_Init(
tUserIndication *env,
eDeviceModes initMode
// tRedGreenLed *uiuLed,
// tOnBoardLed *onBoardLed
) {
// env->uiuLed = uiuLed;
// env->onBoardLed = onBoardLed;
env->mode = initMode;
UserIndication_Update(env);
// env->uveosIndicator.env = env;
// env->uveosIndicator.show = (void *) UserIndication_SetModeUveos;
InitThreadAtrStatic(&env->thread.attr, "Indication", env->thread.controlBlock, env->thread.stack, osPriorityNormal);
env->thread.id = 0;
}
void UserIndication_SetMode(tUserIndication *env, eDeviceModes mode) {
if (env->mode != mode) {
env->mode = mode;
UserIndication_Update(env);
}
}
#define UVEOS_TO_DEV_MODE(NAME) case UVEOS_STATUS_##NAME: UserIndication_SetMode(env, DEVICE_MODE_UVEOS_##NAME); return;
/*
static void UserIndication_SetModeUveos(tUserIndication *env, tEraGlonassUveosStatus mode) {
switch (mode) {
UVEOS_TO_DEV_MODE(CALL_INITIATE)
UVEOS_TO_DEV_MODE(DIALING)
UVEOS_TO_DEV_MODE(MSD_TRANSMIT)
UVEOS_TO_DEV_MODE(SMS_TRANSMIT)
UVEOS_TO_DEV_MODE(CALL_ACTIVE)
UVEOS_TO_DEV_MODE(CALL_FAILURE)
default:
break;
}
}
*/
//
////лучше использовать конкретные значения UIU_GREEN/UIU_RED/UIU_ORANGE
////одновременное использование через | даст оражевый цвет индикатора БИП в любом случае
//void UserIndication_Uiu(tUserIndication *env, uint8_t value) {
// GpioPinSet(&env->uiuLed->red, value & BOARD_RED);
// GpioPinSet(&env->uiuLed->green, value & BOARD_GREEN);
//}
//
////можно использовать несколько флагов через | чтобы включит одновремнно разные светодиоды
////например BOARD_GREEN| BOARD_RED включит красный и зеленый светодиоды на блоке
//static void UserIndication_OnBoard(tUserIndication *env, uint8_t flags) {
// GpioPinSet(&env->onBoardLed->red, flags & BOARD_RED);
// GpioPinSet(&env->onBoardLed->green, flags & BOARD_GREEN);
// GpioPinSet(&env->onBoardLed->blue, flags & BOARD_BLUE);
//}
void UserIndication_UiuError(tUserIndication *env) {
UserIndication_Uiu(env, UIU_RED);
}
tStringStatic eDeviceModesNames[] = {
StringStaticInit("Запуск"),
StringStaticInit("Тестирование"),
StringStaticInit("Ожидание загрузки GSM"),
StringStaticInit("Ошибка памяти"),
StringStaticInit("Ошибка GSM"),
StringStaticInit("Ошибка Кодека"),
StringStaticInit("Обнаружен сбой"),
StringStaticInit("Ошибка начального тестирования 1"),
StringStaticInit("Ошибка начального тестирования 2"),
StringStaticInit("ЭРА (нет ГНСС)"),
StringStaticInit("ЭРА"),
StringStaticInit("Экстренный вызов (подготовка)"),
StringStaticInit("Дозвон"),
StringStaticInit("Отправка МНД"),
StringStaticInit("Отправка SMS"),
StringStaticInit("Голосовое соединение"),
StringStaticInit("Ошибка соединения"),
StringStaticInit("Пассивный режим"),
StringStaticInit("Входящий вызов"),
StringStaticInit("Режим гараж"),
};
//void UserIndicationUpdateLed(tUserIndication *env) {
//
// switch (env->mode) {
// case DEVICE_MODE_STARTUP: {
// bool blink = env->tick < 5;
// UserIndication_Uiu(env, blink ? UIU_RED : UIU_OFF);
// UserIndication_OnBoard(env, blink ? (BOARD_RED) : BOARD_OFF);
// break;
// }
//
// case DEVICE_MODE_ERROR_GSM: {
// UserIndication_Uiu(env, UIU_RED);
// UserIndication_OnBoard(env, BOARD_BLUE);
// break;
// }
// case DEVICE_MODE_ERROR_CODEC: {
// UserIndication_Uiu(env, UIU_RED);
// UserIndication_OnBoard(env, BOARD_GREEN);
// break;
// }
// case DEVICE_MODE_ERROR_FLASH: {
// UserIndication_Uiu(env, UIU_RED);
// UserIndication_OnBoard(env, BOARD_RED);
// break;
// }
//
// case DEVICE_MODE_WAIT_GSM_BOOT: {
// UserIndication_Uiu(env, UIU_GREEN);
// UserIndication_OnBoard(env, BOARD_GREEN | ((env->tick < 5) ? BOARD_BLUE : BOARD_OFF));
// break;
// }
//
// case DEVICE_MODE_UVEOS_ERA_WAIT_GNSS: {
// bool blink = env->tick < 5;
// UserIndication_Uiu(env, blink ? UIU_GREEN : UIU_OFF);
// UserIndication_OnBoard(env, blink ? (BOARD_GREEN) : BOARD_OFF);
// break;
// }
//
// case DEVICE_MODE_UVEOS_ERA_GNSS_READY: {
// bool blink = env->tick < 5;
// UserIndication_Uiu(env, UIU_GREEN);
// UserIndication_OnBoard(env, BOARD_BLUE | (blink ? (BOARD_GREEN) : BOARD_OFF));
// break;
// }
//
// default: {
// bool blink = env->tick < 5;
// UserIndication_Uiu(env, blink ? UIU_RED : UIU_OFF);
// UserIndication_OnBoard(env, blink ? (BOARD_RED) : BOARD_OFF);
// }
// }
//
//}
static void UserIndication_Update(tUserIndication *env) {
env->currentModeName = StringStaticGetLink(&eDeviceModesNames[env->mode]);
// UserIndicationUpdateLed(env);
env->tick = ((env->tick + 1) % 10);
}
static _Noreturn void UserIndication_Thread(tUserIndication *env) {
for (;;) {
UserIndication_Update(env);
SystemDelayMs(100);
}
}
void UserIndication_StartThread(tUserIndication *env) {
if (!env->thread.id) {
env->thread.id = osThreadNew((osThreadFunc_t) (UserIndication_Thread), (void *) (env), &env->thread.attr);
} else {
osThreadResume(env->thread.id);
}
}
void UserIndication_StopThread(tUserIndication *env) {
if (env->thread.id) {
osThreadSuspend(env->thread.id);
}
}

17
modular.json Normal file
View File

@ -0,0 +1,17 @@
{
"dep": [
{
"type": "git",
"provider": "GONEC",
"repo": "GpioPinInterface"
}
],
"cmake": {
"inc_dirs": [
"Inc"
],
"srcs": [
"Src/**.c"
]
}
}