Add statemachine module and use it in new bridge driver module.
This commit is contained in:
parent
4ca7afbb6f
commit
34cc8b4eb8
125
src/bridge.c
Normal file
125
src/bridge.c
Normal file
@ -0,0 +1,125 @@
|
||||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#include "bridge.h"
|
||||
#include "statemachine.h"
|
||||
#include "pins.h"
|
||||
|
||||
bdg_sm_state_t bridge_state;
|
||||
|
||||
sm_trans_t bridge_sm_transitions[] =
|
||||
{
|
||||
{
|
||||
.from_state = HB1_GND_ON,
|
||||
.to_state = HB1_PWR_ON,
|
||||
.trans_fct = brdg_Hb1PowerOn
|
||||
},
|
||||
{
|
||||
.from_state = HB1_PWR_ON,
|
||||
.to_state = HB1_PWR_OFF,
|
||||
.trans_fct = brdg_Hb1PowerOff
|
||||
},
|
||||
{
|
||||
.from_state = HB1_PWR_OFF,
|
||||
.to_state = HB2_GND_ON,
|
||||
.trans_fct = brdg_Hb2GndOn
|
||||
},
|
||||
{
|
||||
.from_state = HB2_GND_ON,
|
||||
.to_state = HB2_PWR_ON,
|
||||
.trans_fct = brdg_Hb2PowerOn
|
||||
},
|
||||
{
|
||||
.from_state = HB2_PWR_ON,
|
||||
.to_state = HB2_PWR_OFF,
|
||||
.trans_fct = brdg_Hb2PowerOff
|
||||
},
|
||||
{
|
||||
.from_state = HB2_PWR_OFF,
|
||||
.to_state = HB2_GND_ON,
|
||||
.trans_fct = brdg_Hb2GndOn
|
||||
}
|
||||
};
|
||||
|
||||
sm_t bridge_statemachine = {
|
||||
.current_state = HB1_PWR_OFF,
|
||||
.transitions = bridge_sm_transitions
|
||||
};
|
||||
|
||||
void adsf()
|
||||
{
|
||||
switch (bridge_state)
|
||||
{
|
||||
case HB1_GND_ON:
|
||||
setPin(&PORTB, PB6);
|
||||
unsetPin(&PORTB, PB4);
|
||||
_delay_us(10);
|
||||
bridge_state = HB1_PWR_ON;
|
||||
break;
|
||||
|
||||
case HB1_PWR_ON:
|
||||
setPin(&PORTB, PB7);
|
||||
_delay_us(9980);
|
||||
bridge_state = HB1_PWR_OFF;
|
||||
break;
|
||||
|
||||
case HB1_PWR_OFF:
|
||||
unsetPin(&PORTB, PB7);
|
||||
_delay_us(100);
|
||||
bridge_state = HB2_GND_ON;
|
||||
break;
|
||||
|
||||
case HB2_GND_ON:
|
||||
setPin(&PORTB, PB4);
|
||||
unsetPin(&PORTB, PB6);
|
||||
_delay_us(10);
|
||||
bridge_state = HB2_PWR_ON;
|
||||
break;
|
||||
|
||||
case HB2_PWR_ON:
|
||||
setPin(&PORTB, PB5);
|
||||
_delay_us(9980);
|
||||
bridge_state = HB2_PWR_OFF;
|
||||
break;
|
||||
|
||||
case HB2_PWR_OFF:
|
||||
unsetPin(&PORTB, PB5);
|
||||
_delay_us(100);
|
||||
bridge_state = HB1_GND_ON;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void brdg_Hb1GndOn(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void brdg_Hb1PowerOn(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void brdg_Hb1PowerOff(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void brdg_Hb2GndOn(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void brdg_Hb2PowerOn(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void brdg_Hb2PowerOff(void)
|
||||
{
|
||||
|
||||
}
|
17
src/include/bridge.h
Normal file
17
src/include/bridge.h
Normal file
@ -0,0 +1,17 @@
|
||||
typedef enum
|
||||
{
|
||||
HB1_GND_ON,
|
||||
HB1_PWR_ON,
|
||||
HB1_PWR_OFF,
|
||||
HB2_GND_ON,
|
||||
HB2_PWR_ON,
|
||||
HB2_PWR_OFF
|
||||
} bdg_sm_state_t;
|
||||
|
||||
|
||||
void brdg_Hb1GndOn(void);
|
||||
void brdg_Hb1PowerOn(void);
|
||||
void brdg_Hb1PowerOff(void);
|
||||
void brdg_Hb2GndOn(void);
|
||||
void brdg_Hb2PowerOn(void);
|
||||
void brdg_Hb2PowerOff(void);
|
16
src/include/statemachine.h
Normal file
16
src/include/statemachine.h
Normal file
@ -0,0 +1,16 @@
|
||||
typedef int sm_state_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
sm_state_t from_state;
|
||||
sm_state_t to_state;
|
||||
void (*trans_fct)(void);
|
||||
} sm_trans_t;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
sm_state_t current_state;
|
||||
sm_trans_t *transitions;
|
||||
} sm_t;
|
||||
|
||||
void sm_handleTransition(sm_t *statemachine, sm_state_t to);
|
6
src/statemachine.c
Normal file
6
src/statemachine.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include "statemachine.h"
|
||||
|
||||
void sm_handleTransition(sm_t *statemachine, sm_state_t to)
|
||||
{
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user