This commit is contained in:
philsson 2016-10-11 18:04:16 +02:00
commit 26ab9475d5
13 changed files with 1138 additions and 254 deletions

View File

@ -23,7 +23,6 @@
#define SCHEDULER_H_
#include <stdint.h>
#include <stdbool.h>
#include "stm32f4xx_revo.h"
#define taskAgeCycleCounterSize 16
@ -92,6 +91,7 @@ typedef enum
TASK_ACCELEROMETER,
TASK_ATTITUDE,
TASK_RX,
TASK_RX_CLI,
TASK_SERIAL,
TASK_BATTERY,
#ifdef BARO

View File

@ -34,6 +34,8 @@ void systemTaskAccelerometer(void);
void systemTaskAttitude(void);
void systemTaskRx(void);
bool systemTaskRxCheck(uint32_t currentDeltaTime);
void systemTaskRxCli(void);
bool systemTaskRxCliCheck(uint32_t currentDeltaTime);
void systemTaskSerial(void);
void systemTaskBattery(void);
void systemTaskBaro(void);

View File

@ -1,21 +1,59 @@
/*
* cli.h
*
* Created on: 30 sep. 2016
* Author: holmis
*/
/**********************************************************************
* NAME: cli.h *
* AUTHOR: Jonas Holmberg *
* PURPOSE: Provide the ability to change some values by use of *
* command line interface. *
* INFORMATION: By some predefined commands values can be changed in *
* the system by writing in a serial communication *
* terminal that runs on usart. It also has the ability *
* to save the value changes to EEPROM and reset all *
* values. The system can also be reseted and rebooted. *
* *
* GLOBAL VARIABLES: *
* Variable Type Description *
* -------- ---- ----------- *
* cliUsart Usart_profile The handler to the usart used by the cli* *
**********************************************************************/
#ifndef CONFIG_CLI_H_
#define CONFIG_CLI_H_
#include "drivers/usart.h"
/* The handler to the usart that is used by the CLI */
extern usart_profile cliUsart;
/***********************************************************************
* BRIEF: Call will start the cli loop *
* BRIEF: Call will start the cli loop *
* INFORMATION: Should be invoked if you want to start the cli loop, *
* will try to read instructions until told to stop. *
* Will not be part of the regular scheduler loop. *
***********************************************************************/
void cliRun();
/***********************************************************************
* BRIEF: Initiates the CLI *
* INFORMATION: The function initiates the CLI. To do this it will need *
* a usart that it should receive its commands from. *
***********************************************************************/
void cliInit(USART_TypeDef* usart);
/***********************************************************************
* BRIEF: Function that checks if the CLI asigned usart has a new *
* message that can be read. *
* INFORMATION: If there is a new message in the designated usart the *
* function will return true, otherwise false. *
***********************************************************************/
bool cliHasMessage();
/***********************************************************************
* BRIEF: Reads a cahracter from the usart and checks if it *
* is the start character for the CLI. *
* INFORMATION: Will read a character from the usart and compare if it *
* is the character that needs to be read to start the CLI *
***********************************************************************/
bool cliShouldRun();
#endif /* CONFIG_CLI_H_ */

View File

@ -19,6 +19,7 @@
#define CONFIG_EEPROM_H_
#include "stm32f4xx.h"
#include "stm32f4xx_revo.h"
/* Macros used to check if a define has no value assigned */
#define DO_EXPAND(VAL) VAL ## 1
@ -146,6 +147,36 @@ typedef enum {
EEPROM_ADC_SCALES,
EEPROM_UART1_RX_INV,
/* Period values for tasks */
EEPROM_PERIOD_SYSTEM,
EEPROM_PERIOD_GYROPID,
EEPROM_PERIOD_ACCELEROMETER,
EEPROM_PERIOD_ATTITUDE,
EEPROM_PERIOD_RX,
EEPROM_PERIOD_RX_CLI,
EEPROM_PERIOD_SERIAL,
EEPROM_PERIOD_BATTERY,
#ifdef BARO
EEPROM_PERIOD_BARO,
#endif
#ifdef COMPASS
EEPROM_PERIOD_COMPASS,
#endif
#ifdef GPS
EEPROM_PERIOD_GPS,
#endif
#ifdef SONAR
EEPROM_PERIOD_SONAR,
#endif
#if defined(BARO) || defined(SONAR)
EEPROM_PERIOD_ALTITUDE,
#endif
#if BEEPER
EEPROM_PERIOD_BEEPER
#endif
/* Counts the amount of system settings */
EEPROM_SYS_COUNT
} EEPROM_SYS_ID_t;
@ -199,6 +230,13 @@ void setActiveProfile(ACTIVE_PROFILE profile);
***********************************************************************/
void resetEEPROM(void);
/***********************************************************************
* BRIEF: Erases the eeprom and reboots *
* INFORMATION: Erases the eeprom sector and reboots the system so that *
* the default values set in the code will replace the values. *
***********************************************************************/
void defaultEEPROM(void);
/***********************************************************************
* BRIEF: Gets the address of a value from an id *
* INFORMATION: Gets the address of a dataPtr based on a given ID.
@ -207,4 +245,10 @@ void resetEEPROM(void);
***********************************************************************/
void * getDataAddresFromID(uint16_t id, uint8_t dataType);
/***********************************************************************
* BRIEF: Gets the current profile value *
* INFORMATION: Will return a simple int value of the active profile *
***********************************************************************/
int getActiveProfile();
#endif /* CONFIG_EEPROM_H_ */

View File

@ -132,19 +132,21 @@
//#define USE_DEBUG_TASKS //Only to be used when testing scheduler, not when intending to run the whole system
#define USE_TASK_AGE_CYCLE_STATISTICS
/* EEPROM */
//#define USE_DEBUG_EEPROM
/* Baro */
//#define BARO
#define BARO
#define MPU6000_NSS_PIN GPIO_PIN_4
#define MPU6000_NSS_PORT GPIOA
/* Compass */
//#define COMPASS
#define COMPASS
/* GPS */
//#define GPS
#define GPS
/* Sonar */

View File

@ -23,6 +23,51 @@
#include <stdint.h>
#include "stm32f4xx_it.h"
#define maxStringSize_CLI 100 //Max sting size used for the messages in the CLI
typedef char typeString[maxStringSize_CLI];
typedef struct typeStringArr { char val[maxStringSize_CLI]; } typeStringArr;
/***********************************************************************
* BRIEF: Calculates the length of a string(char[])
* INFORMATION: Calculates the number of characters in a char arr
***********************************************************************/
uint16_t calculateStringLength (const char * src, int maxSize);
/***********************************************************************
* BRIEF: Gives the length of a typestring *
* INFORMATION: Calculates the number of characters in a typestring. *
* Essentially it calculates the number of strings in an *
* string array. *
***********************************************************************/
uint32_t calculateTypeStringLength(typeString arr[], int maxSize);
/***********************************************************************
* BRIEF: Checks if a string consists of numbers
* INFORMATION: Given a string of numbers it will check if it is a number
* by comparing to the ascii table
***********************************************************************/
bool isStringNumbers(char * msg);
/***********************************************************************
* BRIEF: Parses a string of numbers to int
* INFORMATION: Parses a string of numbers to a 64-bit integer.
***********************************************************************/
uint64_t parseToInt64(char * msg);
/***********************************************************************
* BRIEF: Tries to split a string on whitespace
* INFORMATION: Splits a string on whitespace and places it in dst
***********************************************************************/
bool splitStringWhitespace(char * src, typeString dst[], uint16_t stringSize, uint16_t arraySize);
/***********************************************************************
* BRIEF: Finds previous whitespace in a string
* INFORMATION: Given a string and start index it will try to find
* one whitespace counting downwards.
***********************************************************************/
int FindPreviousWhiteSpaceIndex(char * msg, int startIndex);
/***********************************************************************
* BRIEF: Sums elements of array until index of second arg *
* INFORMATION: Returns the sum *

View File

@ -19,7 +19,6 @@
* *
***************************************************************************/
#include "stm32f4xx_revo.h"
#include "Scheduler/scheduler.h"
#include "Scheduler/tasks.h"
#include "drivers/system_clock.h"
@ -333,6 +332,8 @@ void initSchedulerTasks(void)
enableTask(TASK_RX, true);
enableTask(TASK_RX_CLI, true);
enableTask(TASK_SERIAL, true);
enableTask(TASK_BATTERY, true);

View File

@ -75,6 +75,15 @@ task_t SystemTasks[TASK_COUNT] =
.staticPriority = PRIORITY_HIGH,
},
[TASK_RX_CLI] =
{
.taskName = "RXCLI",
.taskFunction = systemTaskRxCli, //Event handler function, will check if a message is obtainable
.checkEventTriggered = systemTaskRxCliCheck,
.desiredPeriod = GetUpdateRateHz(50), //Standard scheduling should not be used if event based, used as fail safe
.staticPriority = PRIORITY_HIGH,
},
[TASK_SERIAL] =
{
.taskName = "SERIAL",

File diff suppressed because it is too large Load Diff

View File

@ -19,6 +19,8 @@
#include "drivers/uart1_inverter.h"
#include "system_variables.h"
#include "utilities.h"
#include "stm32f4xx_revo.h"
#include "Scheduler/scheduler.h"
/* Reads the EEPROM version from EEPROM - Is compared to EEPROM_SYS_VERSION */
uint8_t stored_eeprom_identifier;
@ -87,9 +89,106 @@ EEPROM_DATA_t eeprom_sys_Arr[EEPROM_SYS_COUNT] = {
},
[EEPROM_UART1_RX_INV] =
{
.size = sizeof(bool),
.dataPtr = &uart1_rx_inverter,
}
.size = sizeof(bool),
.dataPtr = &uart1_rx_inverter,
},
[EEPROM_PERIOD_SYSTEM] =
{
.size = sizeof(SystemTasks[TASK_SYSTEM].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_SYSTEM].desiredPeriod),
},
[EEPROM_PERIOD_GYROPID] =
{
.size = sizeof(SystemTasks[TASK_GYROPID].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_GYROPID].desiredPeriod),
},
[EEPROM_PERIOD_ACCELEROMETER] =
{
.size = sizeof(SystemTasks[TASK_ACCELEROMETER].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_ACCELEROMETER].desiredPeriod),
},
[EEPROM_PERIOD_ATTITUDE] =
{
.size = sizeof(SystemTasks[TASK_ATTITUDE].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_ATTITUDE].desiredPeriod),
},
[EEPROM_PERIOD_RX] =
{
.size = sizeof(SystemTasks[TASK_RX].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_RX].desiredPeriod),
},
[EEPROM_PERIOD_RX_CLI] =
{
.size = sizeof(SystemTasks[TASK_RX_CLI].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_RX_CLI].desiredPeriod),
},
[EEPROM_PERIOD_SERIAL] =
{
.size = sizeof(SystemTasks[TASK_SERIAL].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_SERIAL].desiredPeriod),
},
[EEPROM_PERIOD_BATTERY] =
{
.size = sizeof(SystemTasks[TASK_BATTERY].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_BATTERY].desiredPeriod),
},
#ifdef BARO
[EEPROM_PERIOD_BARO] =
{
.size = sizeof(SystemTasks[TASK_BARO].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_BARO].desiredPeriod),
},
#endif
#ifdef COMPASS
[EEPROM_PERIOD_COMPASS] =
{
.size = sizeof(SystemTasks[TASK_COMPASS].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_COMPASS].desiredPeriod),
},
#endif
#ifdef GPS
[EEPROM_PERIOD_GPS] =
{
.size = sizeof(SystemTasks[TASK_GPS].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_GPS].desiredPeriod),
},
#endif
#ifdef SONAR
[EEPROM_PERIOD_SONAR] =
{
.size = sizeof(SystemTasks[TASK_SONAR].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_SONAR].desiredPeriod),
},
#endif
#if defined(BARO) || defined(SONAR)
[EEPROM_PERIOD_ALTITUDE] =
{
.size = sizeof(SystemTasks[TASK_ALTITUDE].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_ALTITUDE].desiredPeriod),
},
#endif
#if BEEPER
[EEPROM_PERIOD_BEEPER] =
{
.size = sizeof(SystemTasks[TASK_BEEPER].desiredPeriod),
.dataPtr = &(SystemTasks[TASK_BEEPER].desiredPeriod),
},
#endif
};
/* Data pointers and sizes for profile content */
@ -301,7 +400,11 @@ bool scanEEPROM(void)
// ERROR!!! CORRUPT EEPROM, RESETTING
calculated_crc = old_crc;
#ifdef USE_DEBUG_EEPROM
Error_Handler();
#endif
resetEEPROM(); // Reinitialize eeprom with default values.
return true /* false */;
@ -443,3 +546,20 @@ void * getDataAddresFromID(uint16_t id, uint8_t dataType)
}
return toReturn;
}
void defaultEEPROM(void)
{
//Erase the secotr
HAL_FLASH_Unlock();
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_OPERR | FLASH_FLAG_WRPERR | FLASH_FLAG_PGAERR | FLASH_FLAG_PGSERR );
FLASH_Erase_Sector(EEPROM_SECTOR_ERASE, VOLTAGE_RANGE_3);
HAL_FLASH_Lock();
//Reboot the system
HAL_NVIC_SystemReset();
}
int getActiveProfile()
{
return active_profile;
}

View File

@ -40,6 +40,11 @@ void init_system()
//Configure the clock
system_clock_config();
/* read saved variables from eeprom */
readEEPROM();
//initialize the CLI
cliInit(USART1);
#ifdef USE_LEDS
//Initialize the on board leds
@ -91,6 +96,7 @@ int main(void)
//Initialize the scheduler, add all the tasks that should run to the ready queue of the scheduler
initScheduler();
while (1)
{
//Run the scheduler, responsible for distributing all the work of the running system

View File

@ -33,6 +33,8 @@
#include "drivers/motors.h"
#include "drivers/pwm.h"
#include "drivers/system_clock.h"
#include "config/eeprom.h"
#include "config/cli.h"
#include "drivers/sbus.h"
@ -45,6 +47,8 @@ void systemTaskGyroPid(void)
void systemTaskAccelerometer(void)
{
//update the accelerometer data
uint8_t c = 97;
usart_transmit(&cliUsart, &c, 1, 1000000000);
}
void systemTaskAttitude(void)
@ -64,18 +68,38 @@ bool systemTaskRxCheck(uint32_t currentDeltaTime)
//This task is what is controlling the event activation of the systemTaskRx
//check if there is anything that has be received.
return sbus_frame_available();
}
void systemTaskRxCli(void)
{
/* Check if CLI should be activated */
if (cliShouldRun() == true)
cliRun();
}
bool systemTaskRxCliCheck(uint32_t currentDeltaTime)
{
/* First check if any value has been sent to the cli usart.
* We dont care about the delta time for this since if this
* has received something we should always check we dont care about
* the loop times. */
return cliHasMessage();
return false;
}
void systemTaskSerial(void)
{
uint8_t c = 115;
usart_transmit(&cliUsart, &c, 1, 1000000000);
}
void systemTaskBattery(void)
{
//Keep track of the battery level of the system
uint8_t c = 98;
usart_transmit(&cliUsart, &c, 1, 1000000000);
}
void systemTaskBaro(void)

View File

@ -13,6 +13,173 @@
#include "utilities.h"
/***********************************************************************
* BRIEF: Calculates the length of a string(char[])
* INFORMATION: Calculates the number of characters in a char arr
***********************************************************************/
uint16_t calculateStringLength (const char * src, int maxSize)
{
uint16_t toReturn = 0;
for(int i = 0; src[i] != 0 ; i++)
{
toReturn ++;
}
return toReturn;
}
/***********************************************************************
* BRIEF: Gives the length of a typestring *
* INFORMATION: Calculates the number of characters in a typestring. *
* Essentially it calculates the number of strings in an *
* string array. *
***********************************************************************/
uint32_t calculateTypeStringLength(typeString arr[], int maxSize)
{
int i = 0;
for(i = 0; i < maxSize && arr[i][0] != 0; i++);
return i;
}
/***********************************************************************
* BRIEF: Checks if a string consists of numbers
* INFORMATION: Given a string of numbers it will check if it is a number
* by comparing to the ascii table
***********************************************************************/
bool isStringNumbers(char * msg)
{
char c;
int i = 0;
while(c = msg[i], c != 0)
{
if (c >= 48 && c <= 57)
i++;
else
return false;
}
return true;
}
/***********************************************************************
* BRIEF: Parses a string of numbers to int
* INFORMATION: Parses a string of numbers to a 64-bit integer.
***********************************************************************/
uint64_t parseToInt64(char * msg)
{
uint64_t toReturn = 0;
uint64_t multiplier = 1;
int i;
//Count the number of values in the char
for(i = 0; msg[i+1] != 0; i++);
//iter each value from the back
for (;i >= 0; i--)
{
//switch each number value
switch((uint8_t)msg[i])
{
case 48: //0
toReturn = toReturn + 0 * multiplier;
break;
case 49: //1
toReturn = toReturn + 1 * multiplier;
break;
case 50: //2
toReturn = toReturn + 2 * multiplier;
break;
case 51: //3
toReturn = toReturn + 3 * multiplier;
break;
case 52: //4
toReturn = toReturn + 4 * multiplier;
break;
case 53: //5
toReturn = toReturn + 5 * multiplier;
break;
case 54: //6
toReturn = toReturn + 6 * multiplier;
break;
case 55: //7
toReturn = toReturn + 7 * multiplier;
break;
case 56: //8
toReturn = toReturn + 8 * multiplier;
break;
case 57: //9
toReturn = toReturn + 9 * multiplier;
break;
}
multiplier = multiplier * 10;
}
return toReturn;
}
/***********************************************************************
* BRIEF: Tries to split a string on whitespace
* INFORMATION: Splits a string on whitespace and places it in dst
***********************************************************************/
bool splitStringWhitespace(char * src, typeString dst[], uint16_t stringSize, uint16_t arraySize)
{
char currentChar;
uint32_t iterator = 0; //iterates through the string
uint32_t arrayIterator = 0; //iterates through the array positioning
uint32_t arrayStringIterator = 0; //iterates through the string inside the array
//Loop through the values in src, until we find \r(enter) or null
while(currentChar = src[iterator], currentChar != '\r' && currentChar != 0 )
{
//check if whitespace
if (currentChar == ' ')
{
//increase the array iterator
arrayIterator ++;
if (arrayIterator >= arraySize) //check that its not to large
{
//usart_send("To many words in the command");
return false;
}
arrayStringIterator = 0;
goto increment; //continue to the next iteration, with a goto the increment
}
dst[arrayIterator][arrayStringIterator] = src[iterator]; //set the char to the correct array position
arrayStringIterator ++;
if (arrayStringIterator >=stringSize)
{
return false;
}
//Goto statement to jump to the incrementation
increment:
iterator ++; //increment iterator
}
return true;
}
/***********************************************************************
* BRIEF: Finds previous whitespace in a string
* INFORMATION: Given a string and start index it will try to find
* one whitespace counting downwards.
***********************************************************************/
int FindPreviousWhiteSpaceIndex(char * msg, int startIndex)
{
int toReturn = 0;
for (int i = startIndex; i >= 0; i--)
{
if(msg[i] == ' ')
{
toReturn = i;
break;
}
}
return toReturn;
}
/***********************************************************************
* BRIEF: Sums elements of array until index of second arg *
* INFORMATION: Returns the sum *