Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
herzi
project
bob3
progbob
Commits
9e18cc23
Commit
9e18cc23
authored
Oct 14, 2018
by
Sebastian Neuser
Browse files
Implement BatDis driver
parent
2a820d23
Pipeline
#663
failed with stages
in 1 second
Changes
4
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
BatDis.c
0 → 100644
View file @
9e18cc23
///\file
///\brief Driver for the battery disable in-/output on the ProgBob board
#include
<stdbool.h>
#include
<stdint.h>
#include
<util/delay.h>
#include
"BatDis.h"
#include
"LEDs.h"
///\brief Prescaler for BATDIS sampling
static
uint32_t
counter
=
1
;
///\brief BATDIS sampling disable state
static
bool
sampling_disabled
=
false
;
///\brief Samples BATDIS
///\details Configures BATDIS as input, waits a few microseconds, reads the pin's logic level and
/// sets it back to output mode.
///\returns the BATDIS logical level
static
inline
bool
sample_batdis
(
void
)
{
BATDIS_DDR
&=
~
BATDIS_MASK
;
_delay_us
(
20
);
bool
level
=
(
BATDIS_PIN
&
BATDIS_MASK
)
/
BATDIS_MASK
;
BATDIS_DDR
|=
BATDIS_MASK
;
return
level
;
}
void
batdis_disable_sampling
(
const
bool
disable
)
{
sampling_disabled
=
disable
;
if
(
!
sampling_disabled
)
{
counter
=
1
;
}
}
void
batdis_init
(
void
)
{
BATDIS_DDR
|=
BATDIS_MASK
;
BATDIS_PORT
|=
BATDIS_MASK
;
}
void
batdis_task
(
void
)
{
if
(
sampling_disabled
)
{
return
;
}
--
counter
;
if
(
counter
>
0
)
{
return
;
}
counter
=
BATDIS_SCAN_INTERVAL
;
bool
connected
=
!
sample_batdis
();
uint32_t
color
=
connected
?
LEDS_COLOR_BOB3_CONNECTED
:
LEDS_COLOR_BOB3_NOT_CONNECTED
;
leds_set_color
(
LEDS_LED_RIGHT
,
color
);
}
BatDis.h
0 → 100644
View file @
9e18cc23
///\file
///\brief Driver for the battery disable in-/output on the ProgBob board
#ifndef BATDIS_H
#define BATDIS_H
#include
<stdbool.h>
#include
<stdint.h>
#include
<avr/io.h>
///\brief Bitmask for BATDIS pin
#define BATDIS_MASK (1 << 7)
///\brief DDR register for BATDIS in-/output
#define BATDIS_DDR DDRC
///\brief PORT register for BATDIS in-/output
#define BATDIS_PIN PINC
///\brief PORT register for BATDIS in-/output
#define BATDIS_PORT PORTC
///\brief BATDIS sample interval in [number of invocations]
///\see batdis_task
#define BATDIS_SCAN_INTERVAL 60000
///\brief En-/disables periodic sampling of BATDIS
///\param disable
/// if `true` sampling is disabled
///\see batdis_task
void
batdis_disable_sampling
(
bool
disable
);
///\brief Initializes the BATDIS driver
///\details Configures the BATDIS GPIO as output and sets it high
void
batdis_init
(
void
);
///\brief Periodically samples BATDIS and indicates if a BOB3 board is connected
///\details Temporarily configures the BATDIS GPIO as input and reads its logic state. If the GPIO
/// is pulled low, the right LED's color is set to indicate that a BOB3 board is connected.
///\see BATDIS_SCAN_INTERVAL
///\see batdis_sampling_enabled
void
batdis_task
(
void
);
#endif
Makefile
View file @
9e18cc23
...
...
@@ -18,7 +18,7 @@ F_CPU = 16000000
F_USB
=
$(F_CPU)
OPTIMIZATION
=
s
TARGET
=
ProgBob
SRC
=
$(TARGET)
.c LEDs.c AVRISPDescriptors.c
\
SRC
=
$(TARGET)
.c
BatDis.c
LEDs.c AVRISPDescriptors.c
\
Lib/V2Protocol.c Lib/V2ProtocolParams.c
\
Lib/ISP/ISPProtocol.c Lib/ISP/ISPTarget.c
\
Lib/XPROG/XPROGProtocol.c Lib/XPROG/XPROGTarget.c Lib/XPROG/XMEGANVM.c Lib/XPROG/TINYNVM.c
\
...
...
ProgBob.c
View file @
9e18cc23
...
...
@@ -45,6 +45,7 @@
#include
"Lib/V2Protocol.h"
#include
"AVRISPDescriptors.h"
#include
"BatDis.h"
#include
"LEDs.h"
...
...
@@ -66,6 +67,7 @@ static void avrisp_task(void)
if
(
Endpoint_IsOUTReceived
())
{
if
(
timeout
==
0
)
{
batdis_disable_sampling
(
true
);
leds_disable_fading
(
true
);
leds_set_color
(
LEDS_LED_RIGHT
,
LEDS_COLOR_BOB3_PROGRAMMING
);
}
...
...
@@ -81,6 +83,7 @@ static void avrisp_task(void)
}
--
timeout
;
if
(
timeout
==
0
)
{
batdis_disable_sampling
(
false
);
leds_disable_fading
(
false
);
}
}
...
...
@@ -98,6 +101,7 @@ int main(void)
clock_prescale_set
(
clock_div_1
);
// Hardware initialization
batdis_init
();
leds_init
();
leds_set_color
(
LEDS_LED_LEFT
,
LEDS_COLOR_USB_NOT_READY
);
leds_set_color
(
LEDS_LED_RIGHT
,
LEDS_COLOR_BOB3_NOT_CONNECTED
);
...
...
@@ -111,6 +115,7 @@ int main(void)
{
USB_USBTask
();
avrisp_task
();
batdis_task
();
}
return
0
;
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment