Added Interlock
Fixed PID regulation functionality git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@250 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
@@ -214,7 +214,8 @@ ErrorStatus ADCChannel_read(const struct AdcChannel* self, uint16_t* value)
|
||||
if (self->parent->useRanks)
|
||||
{
|
||||
// Rank starts with 1 - must be reduced by one in order tu be used as index
|
||||
*value = self->parent->channelValue[self->Rank - 1];
|
||||
// *value = self->parent->channelValue[self->Rank - 1];
|
||||
*value = self->parent->channelValue[self->channel];
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
#include "Logger.h"
|
||||
|
||||
#include "platform.h"
|
||||
#include "Interlock.h"
|
||||
#include "internalADC.h"
|
||||
#include "gpio.h"
|
||||
#include "PCBA.h"
|
||||
@@ -122,10 +123,10 @@ static struct Keypad _keypad = {.initialized = false};
|
||||
static struct Gpio _ledGreen = {.initialized = false};
|
||||
static struct Gpio _ledOrange = {.initialized = false};
|
||||
static struct Gpio _power6v5Enable = {.initialized = false};
|
||||
static struct Gpio _interlock1 = {.initialized = false};
|
||||
static struct Gpio _interlock2 = {.initialized = false};
|
||||
static struct Gpio _tesla1 = {.initialized = false};
|
||||
static struct Gpio _tesla2 = {.initialized = false};
|
||||
static struct Gpio _interlockNO = {.initialized = false};
|
||||
static struct Gpio _interlockNC = {.initialized = false};
|
||||
static struct Gpio _teslaNO = {.initialized = false};
|
||||
static struct Gpio _teslaNC = {.initialized = false};
|
||||
static struct Gpio _solenoid = {.initialized = false};
|
||||
static struct Gpio _mcp0Relay = {.initialized = false};
|
||||
static struct Gpio _mcp1Relay = {.initialized = false};
|
||||
@@ -133,7 +134,9 @@ static struct Gpio _mcp2Relay = {.initialized = false};
|
||||
static struct Gpio _cat0Relay = {.initialized = false};
|
||||
static struct Gpio _cat1Relay = {.initialized = false};
|
||||
static struct Gpio _cat2Relay = {.initialized = false};
|
||||
static struct Gpio _teslaLock = {.initialized = false};
|
||||
|
||||
static struct Interlock _interlock = {.initialized = false};
|
||||
static struct Interlock _teslalock = {.initialized = false};
|
||||
|
||||
|
||||
// The following pointers are for export (see platform.h) and external use.
|
||||
@@ -167,10 +170,10 @@ struct Keypad* const keypad = &_keypad;
|
||||
struct Gpio* const ledGreen = &_ledGreen;
|
||||
struct Gpio* const ledOrange = &_ledOrange;
|
||||
struct Gpio* const power6v5Enable = & _power6v5Enable;
|
||||
struct Gpio* const interlock1 = &_interlock1;
|
||||
struct Gpio* const interlock2 = &_interlock2;
|
||||
struct Gpio* const tesla1 = &_tesla1;
|
||||
struct Gpio* const tesla2 = &_tesla2;
|
||||
struct Gpio* const interlockNO = &_interlockNO;
|
||||
struct Gpio* const interlockNC = &_interlockNC;
|
||||
struct Gpio* const teslaNO = &_teslaNO;
|
||||
struct Gpio* const teslaNC = &_teslaNC;
|
||||
struct Gpio* const solenoid = & _solenoid;
|
||||
struct Gpio* const mcp0Relay = &_mcp0Relay;
|
||||
struct Gpio* const mcp1Relay = &_mcp1Relay;
|
||||
@@ -178,7 +181,9 @@ struct Gpio* const mcp2Relay = &_mcp2Relay;
|
||||
struct Gpio* const cat0Relay = &_cat0Relay;
|
||||
struct Gpio* const cat1Relay = &_cat1Relay;
|
||||
struct Gpio* const cat2Relay = &_cat2Relay;
|
||||
struct Gpio* const teslaLock = &_teslaLock;
|
||||
|
||||
struct Interlock* const interlock = &_interlock;
|
||||
struct Interlock* const teslalock = &_teslalock;
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function declarations
|
||||
@@ -187,6 +192,7 @@ struct Gpio* const teslaLock = &_teslaLock;
|
||||
static ErrorStatus initClocks(void);
|
||||
static ErrorStatus initIO (void);
|
||||
static T_PL_GPIO configureGPIO (GPIO_TypeDef* gpioTypeDef, GPIOMode_TypeDef gpioMode, GPIOSpeed_TypeDef gpioSpeed, uint16_t gpioPin);
|
||||
static EXTI_InitTypeDef configureEXTI (uint32_t line, EXTIMode_TypeDef mode, EXTITrigger_TypeDef trigger, FunctionalState command);
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Function definitions
|
||||
@@ -256,17 +262,17 @@ ErrorStatus initPlatform(void)
|
||||
struct AdcChannelParameters acParameters;
|
||||
acParameters.channel = ADC_Channel_1;
|
||||
acParameters.Rank = 1;
|
||||
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
||||
acParameters.ADC_SampleTime = ADC_SampleTime_239Cycles5;
|
||||
ADCChannel_construct(&adc1->channel[1], adc1, &acParameters);
|
||||
|
||||
acParameters.channel = ADC_Channel_2;
|
||||
acParameters.Rank = 2;
|
||||
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
||||
acParameters.ADC_SampleTime = ADC_SampleTime_239Cycles5;
|
||||
ADCChannel_construct(&adc1->channel[2], adc1, &acParameters);
|
||||
|
||||
acParameters.channel = ADC_Channel_0;
|
||||
acParameters.Rank = 3;
|
||||
acParameters.ADC_SampleTime = ADC_SampleTime_55Cycles5;
|
||||
acParameters.ADC_SampleTime = ADC_SampleTime_239Cycles5;
|
||||
ADCChannel_construct(&adc1->channel[0], adc1, &acParameters);
|
||||
|
||||
ADC_setDMAStatus(adc1, ENABLE);
|
||||
@@ -378,10 +384,23 @@ ErrorStatus initPlatform(void)
|
||||
GPIO_construct(ledOrange, OUTPUT, ledOrange->gpio);
|
||||
// 6V5 Power Enable
|
||||
GPIO_construct(power6v5Enable, OUTPUT, power6v5Enable->gpio);
|
||||
// Interlock1
|
||||
GPIO_construct(interlock1, INPUT, interlock1->gpio);
|
||||
// Interlock2
|
||||
GPIO_construct(interlock2, INPUT, interlock2->gpio);
|
||||
|
||||
IRQ_setInterruptProperties(EXTI0_IRQn, 12, 0, ENABLE);
|
||||
IRQ_setInterruptProperties(EXTI1_IRQn, 12, 0, ENABLE);
|
||||
// InterlockNO
|
||||
EXTI_InitTypeDef intNOEXTI; // = configureEXTI(EXTI_Line0, EXTI_Mode_Interrupt, EXTI_Trigger_Rising_Falling, ENABLE);
|
||||
intNOEXTI.EXTI_Line = EXTI_Line0;
|
||||
intNOEXTI.EXTI_Mode = EXTI_Mode_Interrupt;
|
||||
intNOEXTI.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
|
||||
intNOEXTI.EXTI_LineCmd = ENABLE;
|
||||
EXTI_Init(&intNOEXTI);
|
||||
GPIO_construct(interlockNO, INPUT, interlockNO->gpio);
|
||||
// InterlockNC
|
||||
EXTI_InitTypeDef intNCEXTI = configureEXTI(EXTI_Line1, EXTI_Mode_Interrupt, EXTI_Trigger_Rising_Falling, ENABLE);
|
||||
GPIO_construct(interlockNC, INPUT, interlockNC->gpio);
|
||||
|
||||
// Interlock_construct(interlock, interlockNO, intNOEXTI, interlockNC, intNCEXTI);
|
||||
|
||||
// Solenoid
|
||||
GPIO_construct(solenoid, OUTPUT, solenoid->gpio);
|
||||
if (PCBA_getInstance()->pcba == CathodeMCP)
|
||||
@@ -402,9 +421,16 @@ ErrorStatus initPlatform(void)
|
||||
if (PCBA_getInstance()->pcba == Tesla)
|
||||
{
|
||||
// Tesla Lock
|
||||
GPIO_construct(teslaLock, INPUT, teslaLock->gpio);
|
||||
EXTI_InitTypeDef teslaNOEXTI = configureEXTI(EXTI_Line9, EXTI_Mode_Interrupt, EXTI_Trigger_Rising_Falling, DISABLE);
|
||||
GPIO_construct(teslaNO, INPUT, teslaNO->gpio);
|
||||
EXTI_InitTypeDef teslaNCEXTI = configureEXTI(EXTI_Line10, EXTI_Mode_Interrupt, EXTI_Trigger_Rising_Falling, DISABLE);
|
||||
GPIO_construct(teslaNC, INPUT, teslaNC->gpio);
|
||||
|
||||
Interlock_construct(teslalock, teslaNO, teslaNOEXTI, teslaNC, teslaNCEXTI);
|
||||
}
|
||||
|
||||
// Interlock_setEXTI(interlock, ENABLE);
|
||||
|
||||
}
|
||||
|
||||
return returnValue;
|
||||
@@ -730,9 +756,11 @@ static ErrorStatus initIO (void)
|
||||
// 6V5 enable -> PE12 output
|
||||
power6v5Enable->gpio = configureGPIO(GPIOE, GPIO_Mode_Out_PP, GPIO_Speed_50MHz, GPIO_Pin_12);
|
||||
// Interlock1 - PB0 input
|
||||
interlock1->gpio = configureGPIO(GPIOB, GPIO_Mode_IN_FLOATING, GPIO_Speed_50MHz, GPIO_Pin_0);
|
||||
interlockNO->gpio = configureGPIO(GPIOB, GPIO_Mode_IPU, GPIO_Speed_50MHz, GPIO_Pin_0);
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource0);
|
||||
// Interlock2 - PB1 input
|
||||
interlock2->gpio = configureGPIO(GPIOB, GPIO_Mode_IN_FLOATING, GPIO_Speed_50MHz, GPIO_Pin_1);
|
||||
interlockNC->gpio = configureGPIO(GPIOB, GPIO_Mode_IPU, GPIO_Speed_50MHz, GPIO_Pin_1);
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource1);
|
||||
// Solenoid - PB5 output
|
||||
solenoid->gpio = configureGPIO(GPIOB, GPIO_Mode_Out_PP, GPIO_Speed_50MHz, GPIO_Pin_5);
|
||||
|
||||
@@ -755,7 +783,10 @@ static ErrorStatus initIO (void)
|
||||
if (PCBA_getInstance()->pcba == Tesla)
|
||||
{
|
||||
// Tesla lock PB10 output
|
||||
teslaLock->gpio = configureGPIO(GPIOB, GPIO_Mode_IN_FLOATING, GPIO_Speed_50MHz, GPIO_Pin_10);
|
||||
teslaNO->gpio = configureGPIO(GPIOB, GPIO_Mode_IN_FLOATING, GPIO_Speed_50MHz, GPIO_Pin_9);
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);
|
||||
teslaNC->gpio = configureGPIO(GPIOB, GPIO_Mode_IN_FLOATING, GPIO_Speed_50MHz, GPIO_Pin_10);
|
||||
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource10);
|
||||
}
|
||||
|
||||
|
||||
@@ -776,3 +807,44 @@ static T_PL_GPIO configureGPIO (GPIO_TypeDef* gpioTypeDef, GPIOMode_TypeDef gpio
|
||||
|
||||
return gpio;
|
||||
}
|
||||
|
||||
static EXTI_InitTypeDef configureEXTI (uint32_t line, EXTIMode_TypeDef mode, EXTITrigger_TypeDef trigger, FunctionalState command)
|
||||
{
|
||||
EXTI_InitTypeDef EXTI_InitStruct;
|
||||
|
||||
EXTI_InitStruct.EXTI_Line = line;
|
||||
EXTI_InitStruct.EXTI_Mode = mode;
|
||||
EXTI_InitStruct.EXTI_Trigger = trigger;
|
||||
EXTI_InitStruct.EXTI_LineCmd = command;
|
||||
EXTI_Init(&EXTI_InitStruct);
|
||||
|
||||
return EXTI_InitStruct;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void EXTI0_IRQHandler(void)
|
||||
{
|
||||
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
|
||||
|
||||
EXTI_ClearITPendingBit(EXTI_Line0);
|
||||
GPIO_setValue(ledGreen, true);
|
||||
LOGGER_ERROR_ISR(mainLog, "EXTI0 IRQ TRIGGERED");
|
||||
|
||||
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
|
||||
void EXTI1_IRQHandler(void)
|
||||
{
|
||||
static signed portBASE_TYPE higherPriorityTaskWoken = pdFALSE;
|
||||
|
||||
EXTI_ClearITPendingBit(EXTI_Line1);
|
||||
LOGGER_ERROR_ISR(mainLog, "EXTI1 IRQ TRIGGERED");
|
||||
|
||||
portEND_SWITCHING_ISR(higherPriorityTaskWoken);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user