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
François Revol
firmware
Commits
3e886c50
Verified
Commit
3e886c50
authored
Aug 20, 2019
by
Rahix
Browse files
feat(light-sensor): Add ADC locking
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
abe89091
Changes
2
Hide whitespace changes
Inline
Side-by-side
epicardium/modules/light_sensor.c
View file @
3e886c50
#include
"FreeRTOS.h"
#include
"timers.h"
#include
"led.h"
#include
"epicardium.h"
#include
"modules/log.h"
#include
"modules/modules.h"
#include
"mxc_config.h"
#include
"led.h"
#include
"adc.h"
#include
"gpio.h"
#include
<errno.h>
#include
"FreeRTOS.h"
#include
"timers.h"
#define READ_FREQ pdMS_TO_TICKS(100)
...
...
@@ -25,12 +29,25 @@ static int light_sensor_init()
static
void
readAdcCallback
()
{
if
(
hwlock_acquire
(
HWLOCK_ADC
,
0
)
!=
0
)
{
/* Can't do much about this here ... Retry next time */
return
;
}
ADC_StartConvert
(
ADC_CH_7
,
0
,
0
);
ADC_GetData
(
&
last_value
);
hwlock_release
(
HWLOCK_ADC
);
}
int
epic_light_sensor_run
()
{
int
ret
=
0
;
if
(
hwlock_acquire
(
HWLOCK_ADC
,
pdMS_TO_TICKS
(
500
))
!=
0
)
{
return
-
EBUSY
;
}
light_sensor_init
();
if
(
!
poll_timer
)
{
...
...
@@ -47,10 +64,12 @@ int epic_light_sensor_run()
}
if
(
xTimerIsTimerActive
(
poll_timer
)
==
pdFALSE
)
{
if
(
xTimerStart
(
poll_timer
,
0
)
!=
pdPASS
)
{
ret
urn
-
EBUSY
;
ret
=
-
EBUSY
;
}
}
return
0
;
hwlock_release
(
HWLOCK_ADC
);
return
ret
;
}
int
epic_light_sensor_stop
()
...
...
@@ -63,6 +82,7 @@ int epic_light_sensor_stop()
if
(
xTimerStop
(
poll_timer
,
0
)
!=
pdPASS
)
{
return
-
EBUSY
;
}
return
0
;
}
...
...
epicardium/modules/modules.h
View file @
3e886c50
...
...
@@ -42,6 +42,7 @@ void hwlock_init(void);
enum
hwlock_periph
{
HWLOCK_I2C
=
0
,
HWLOCK_ADC
,
_HWLOCK_MAX
,
};
...
...
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