implemented saving hwId and restoring to and from NVMC,

removed APP_DEBUG,
removed auto init on reboot
main
Jonas Arnold 4 years ago
parent c3111134bb
commit dfaa138813
  1. 21
      ADIS_tinyK22_SplitFlap/source/application.c
  2. 1
      ADIS_tinyK22_SplitFlap/source/platform.h
  3. 25
      ADIS_tinyK22_SplitFlap/source/splitflap.c

@ -55,20 +55,6 @@ void App_Init(void){
static void App_Task(void* pv){ static void App_Task(void* pv){
McuLog_info("Application Task starting"); McuLog_info("Application Task starting");
bool initSuccess = MultiSplitFlap_MoveAllToZeroPosition();
#ifndef APP_DEBUG
if(initSuccess == false)
{
// end here
for(;;) {}
}
#else
// fake set to ready
((SF_t*)splitflap0)->state = SF_STATE_READY;
((SF_t*)splitflap1)->state = SF_STATE_READY;
#endif
QueueHandle_t cmdQueueHandle = SHELL_GetShellCmdQueueHandle();; QueueHandle_t cmdQueueHandle = SHELL_GetShellCmdQueueHandle();;
Shell_cmd_s cmd; Shell_cmd_s cmd;
char* sentence; char* sentence;
@ -94,7 +80,6 @@ static void App_Task(void* pv){
McuLog_error("Invalid String to Display"); McuLog_error("Invalid String to Display");
} }
break; break;
case Shell_Powerof_rpi:
default: default:
McuLog_error("Not implemented command recieved in App_Task. Command Id was <%i>", (int)cmd.shellCmd); McuLog_error("Not implemented command recieved in App_Task. Command Id was <%i>", (int)cmd.shellCmd);
break; break;
@ -125,7 +110,7 @@ static void App_Task(void* pv){
/* SINGLE SPLIT FLAP TESTING */ /* SINGLE SPLIT FLAP TESTING */
// go through the following letters // go through the following letters
char* letters[] = {"J", "O", "N", "A", "S", "!"}; Flap_t letters[] = {'J', 'O', 'N', 'A', 'S', '!'};
//char* letters[] = { " ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", //char* letters[] = { " ", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K",
// "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", // "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
// "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", // "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
@ -200,7 +185,7 @@ void configureSplitflaps(void){
/* create config instance for splitflap 0 */ /* create config instance for splitflap 0 */
SF_Config_t sf0Config; SF_Config_t sf0Config;
sf0Config.setupIdentifier = 0; sf0Config.setupIdentifier = 0;
sf0Config.hardwareIdentifier = 4; sf0Config.hardwareIdentifier = 10; // default value
sf0Config.magSensorConfig = magSensor0Config; sf0Config.magSensorConfig = magSensor0Config;
sf0Config.motorConfig = motor0Config; sf0Config.motorConfig = motor0Config;
@ -237,7 +222,7 @@ void configureSplitflaps(void){
/* create config instance for splitflap 0 */ /* create config instance for splitflap 0 */
SF_Config_t sf1Config; SF_Config_t sf1Config;
sf1Config.setupIdentifier = 1; sf1Config.setupIdentifier = 1;
sf1Config.hardwareIdentifier = 22; sf1Config.hardwareIdentifier = 20; // default value
sf1Config.magSensorConfig = magSensor1Config; sf1Config.magSensorConfig = magSensor1Config;
sf1Config.motorConfig = motor1Config; sf1Config.motorConfig = motor1Config;

@ -9,7 +9,6 @@
#define PLATFORM_H_ #define PLATFORM_H_
/* SETTINGS */ /* SETTINGS */
//#define APP_DEBUG
#define PL_CONFIG_USE_NVMC (1) #define PL_CONFIG_USE_NVMC (1)
#define PL_CONFIG_USE_MININI (1 && PL_CONFIG_USE_NVMC) #define PL_CONFIG_USE_MININI (1 && PL_CONFIG_USE_NVMC)

@ -20,6 +20,7 @@
#include "McuUtility.h" #include "McuUtility.h"
#include "McuLib.h" #include "McuLib.h"
#include "MotOffsetTable.h" #include "MotOffsetTable.h"
#include "nvmc.h"
#define FLAP_QUEUE_LENGTH (5) /* number of elements in queue */ #define FLAP_QUEUE_LENGTH (5) /* number of elements in queue */
#define FLAP_QUEUE_SELEM_SIZE (sizeof(Flap_t)) /* size of element */ #define FLAP_QUEUE_SELEM_SIZE (sizeof(Flap_t)) /* size of element */
@ -48,12 +49,20 @@ SF_Handle_t SF_Init(SF_Config_t* config){
FLAP_QUEUE_SELEM_SIZE); FLAP_QUEUE_SELEM_SIZE);
splitflap->id = config->setupIdentifier; // copy setup identifier splitflap->id = config->setupIdentifier; // copy setup identifier
splitflap->hwId = config->hardwareIdentifier; // copy hardware identifier splitflap->hwId = config->hardwareIdentifier; // copy hardware identifier
#ifndef APP_DEBUG // when not debugging => set to "not initialized" splitflap->state = SF_STATE_NOT_READY; // set to "not initialized"
splitflap->state = SF_STATE_NOT_READY; #if PL_CONFIG_USE_NVMC
#else // when debugging => set to "initialized" int16_t hwIdFromNvmc = -1;
splitflap->state = SF_STATE_READY; // if there exists a hw id in the NVMC and it is valid
if(NVMC_GetStepperID(config->setupIdentifier, &hwIdFromNvmc) == ERR_OK && hwIdFromNvmc >= 0){
splitflap->hwId = hwIdFromNvmc; // use this
} else{
McuLog_warn("SF_Init: No or invalid HwId found in NVMC for SplitFlap <%i>, storing default ID.", splitflap->id);
// save default stepper id from code to NVMC
if(NVMC_SetStepperID(config->setupIdentifier, config->hardwareIdentifier) != ERR_OK){
McuLog_error("SF_Init: Failed to save hardware ID in NVMC for SplitFlap ID <%i>", config->setupIdentifier);
}
}
#endif #endif
// check if queue was created // check if queue was created
if(splitflap->flapQueue == NULL){ if(splitflap->flapQueue == NULL){
McuLog_error("Flap queue creation failed for Splitflap <%i>", splitflap->id); McuLog_error("Flap queue creation failed for Splitflap <%i>", splitflap->id);
@ -111,6 +120,7 @@ bool SF_MoveMotorToZeroPosition(SF_Handle_t instance){
if(MotOffset_Get(((SF_t*)instance)->hwId, &offsetSteps) == ERR_OK){ if(MotOffset_Get(((SF_t*)instance)->hwId, &offsetSteps) == ERR_OK){
McuLog_info("SF_MoveMotorToZeroPosition found offsetSteps=%i for Splitflap <%i> with hwId=%i", offsetSteps, ((SF_t*)instance)->id, ((SF_t*)instance)->hwId); McuLog_info("SF_MoveMotorToZeroPosition found offsetSteps=%i for Splitflap <%i> with hwId=%i", offsetSteps, ((SF_t*)instance)->id, ((SF_t*)instance)->hwId);
} }
// check if positive offset! // check if positive offset!
if(offsetSteps < 0){ if(offsetSteps < 0){
McuLog_info("SF_MoveMotorToZeroPosition found negative offset for Splitflap with hwId=%i. Offset set to zero.", ((SF_t*)instance)->hwId); McuLog_info("SF_MoveMotorToZeroPosition found negative offset for Splitflap with hwId=%i. Offset set to zero.", ((SF_t*)instance)->hwId);
@ -262,6 +272,11 @@ void SF_MoveToFlapAsync(SF_Handle_t instance, Flap_t flap){
void SF_SetHardwareIdentifier(SF_Handle_t instance, HardwareIdentifier_t identifier){ void SF_SetHardwareIdentifier(SF_Handle_t instance, HardwareIdentifier_t identifier){
((SF_t*)instance)->hwId = identifier; ((SF_t*)instance)->hwId = identifier;
#if PL_CONFIG_USE_NVMC // update hardwareid in NVMC if used
if(NVMC_SetStepperID(((SF_t*)instance)->id, identifier) != ERR_OK){
McuLog_error("SF_SetHardwareIdentifier: Failed to update hardware ID in NVMC for SplitFlap ID <%i>", ((SF_t*)instance)->id);
}
#endif
} }
int32_t SF_GetMotorPosition(SF_Handle_t instance){ int32_t SF_GetMotorPosition(SF_Handle_t instance){

Loading…
Cancel
Save