Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
Nodemcu Firmware
Commits
d0c55876
Commit
d0c55876
authored
Jan 14, 2018
by
devsaurus
Browse files
initialize task ids only once at module open
parent
df930c2d
Changes
4
Hide whitespace changes
Inline
Side-by-side
app/modules/pcm.c
View file @
d0c55876
...
@@ -19,6 +19,9 @@
...
@@ -19,6 +19,9 @@
#define COND_REF(_cond) _cond ? luaL_ref( L, LUA_REGISTRYINDEX ) : LUA_NOREF
#define COND_REF(_cond) _cond ? luaL_ref( L, LUA_REGISTRYINDEX ) : LUA_NOREF
// task handles
task_handle_t
pcm_data_vu_task
,
pcm_data_play_task
,
pcm_start_play_task
;
static
void
dispatch_callback
(
lua_State
*
L
,
int
self_ref
,
int
cb_ref
,
int
returns
)
static
void
dispatch_callback
(
lua_State
*
L
,
int
self_ref
,
int
cb_ref
,
int
returns
)
{
{
if
(
cb_ref
!=
LUA_NOREF
)
{
if
(
cb_ref
!=
LUA_NOREF
)
{
...
@@ -94,7 +97,7 @@ static int pcm_drv_pause( lua_State *L )
...
@@ -94,7 +97,7 @@ static int pcm_drv_pause( lua_State *L )
return
0
;
return
0
;
}
}
static
void
pcm_start_play
_task
(
task_param_t
param
,
uint8
prio
)
static
void
pcm_start_play
(
task_param_t
param
,
uint8
prio
)
{
{
lua_State
*
L
=
lua_getstate
();
lua_State
*
L
=
lua_getstate
();
pud_t
*
pud
=
(
pud_t
*
)
param
;
pud_t
*
pud
=
(
pud_t
*
)
param
;
...
@@ -126,8 +129,8 @@ static int pcm_drv_play( lua_State *L )
...
@@ -126,8 +129,8 @@ static int pcm_drv_play( lua_State *L )
}
}
// schedule actions for play in separate task since drv:play() might have been called
// schedule actions for play in separate task since drv:play() might have been called
// in the callback fn of pcm_data_play
_task
() which in turn gets called when starting play...
// in the callback fn of pcm_data_play() which in turn gets called when starting play...
task_post_low
(
cfg
->
start_play_task
,
(
os_param_t
)
pud
);
task_post_low
(
pcm_
start_play_task
,
(
os_param_t
)
pud
);
return
0
;
return
0
;
}
}
...
@@ -203,10 +206,7 @@ static int pcm_new( lua_State *L )
...
@@ -203,10 +206,7 @@ static int pcm_new( lua_State *L )
cfg
->
bufs
[
0
].
rpos
=
cfg
->
bufs
[
1
].
rpos
=
0
;
cfg
->
bufs
[
0
].
rpos
=
cfg
->
bufs
[
1
].
rpos
=
0
;
cfg
->
bufs
[
0
].
empty
=
cfg
->
bufs
[
1
].
empty
=
TRUE
;
cfg
->
bufs
[
0
].
empty
=
cfg
->
bufs
[
1
].
empty
=
TRUE
;
cfg
->
data_vu_task
=
task_get_id
(
pcm_data_vu_task
);
cfg
->
vu_freq
=
10
;
cfg
->
vu_freq
=
10
;
cfg
->
data_play_task
=
task_get_id
(
pcm_data_play_task
);
cfg
->
start_play_task
=
task_get_id
(
pcm_start_play_task
);
if
(
driver
==
PCM_DRIVER_SD
)
{
if
(
driver
==
PCM_DRIVER_SD
)
{
cfg
->
pin
=
luaL_checkinteger
(
L
,
2
);
cfg
->
pin
=
luaL_checkinteger
(
L
,
2
);
...
@@ -257,6 +257,10 @@ static const LUA_REG_TYPE pcm_map[] = {
...
@@ -257,6 +257,10 @@ static const LUA_REG_TYPE pcm_map[] = {
int
luaopen_pcm
(
lua_State
*
L
)
{
int
luaopen_pcm
(
lua_State
*
L
)
{
luaL_rometatable
(
L
,
"pcm.driver"
,
(
void
*
)
pcm_driver_map
);
// create metatable
luaL_rometatable
(
L
,
"pcm.driver"
,
(
void
*
)
pcm_driver_map
);
// create metatable
pcm_data_vu_task
=
task_get_id
(
pcm_data_vu
);
pcm_data_play_task
=
task_get_id
(
pcm_data_play
);
pcm_start_play_task
=
task_get_id
(
pcm_start_play
);
return
0
;
return
0
;
}
}
...
...
app/pcm/drv_sigma_delta.c
View file @
d0c55876
...
@@ -33,7 +33,7 @@ static void ICACHE_RAM_ATTR drv_sd_timer_isr( os_param_t arg )
...
@@ -33,7 +33,7 @@ static void ICACHE_RAM_ATTR drv_sd_timer_isr( os_param_t arg )
if
(
cfg
->
vu_samples_tmp
>=
cfg
->
vu_req_samples
)
{
if
(
cfg
->
vu_samples_tmp
>=
cfg
->
vu_req_samples
)
{
cfg
->
vu_peak
=
cfg
->
vu_peak_tmp
;
cfg
->
vu_peak
=
cfg
->
vu_peak_tmp
;
task_post_low
(
cfg
->
data_vu_task
,
(
os_param_t
)
cfg
);
task_post_low
(
pcm_
data_vu_task
,
(
os_param_t
)
cfg
);
cfg
->
vu_samples_tmp
=
0
;
cfg
->
vu_samples_tmp
=
0
;
cfg
->
vu_peak_tmp
=
0
;
cfg
->
vu_peak_tmp
=
0
;
...
@@ -44,7 +44,7 @@ static void ICACHE_RAM_ATTR drv_sd_timer_isr( os_param_t arg )
...
@@ -44,7 +44,7 @@ static void ICACHE_RAM_ATTR drv_sd_timer_isr( os_param_t arg )
// buffer data consumed, request to re-fill it
// buffer data consumed, request to re-fill it
buf
->
empty
=
TRUE
;
buf
->
empty
=
TRUE
;
cfg
->
fbuf_idx
=
cfg
->
rbuf_idx
;
cfg
->
fbuf_idx
=
cfg
->
rbuf_idx
;
task_post_high
(
cfg
->
data_play_task
,
(
os_param_t
)
cfg
);
task_post_high
(
pcm_
data_play_task
,
(
os_param_t
)
cfg
);
// switch to next buffer
// switch to next buffer
cfg
->
rbuf_idx
^=
1
;
cfg
->
rbuf_idx
^=
1
;
dbg_platform_gpio_write
(
PLATFORM_GPIO_LOW
);
dbg_platform_gpio_write
(
PLATFORM_GPIO_LOW
);
...
@@ -54,7 +54,7 @@ static void ICACHE_RAM_ATTR drv_sd_timer_isr( os_param_t arg )
...
@@ -54,7 +54,7 @@ static void ICACHE_RAM_ATTR drv_sd_timer_isr( os_param_t arg )
cfg
->
isr_throttled
=
1
;
cfg
->
isr_throttled
=
1
;
dbg_platform_gpio_write
(
PLATFORM_GPIO_LOW
);
dbg_platform_gpio_write
(
PLATFORM_GPIO_LOW
);
cfg
->
fbuf_idx
=
cfg
->
rbuf_idx
;
cfg
->
fbuf_idx
=
cfg
->
rbuf_idx
;
task_post_high
(
cfg
->
data_play_task
,
(
os_param_t
)
cfg
);
task_post_high
(
pcm_
data_play_task
,
(
os_param_t
)
cfg
);
}
}
}
}
...
...
app/pcm/pcm.h
View file @
d0c55876
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#define _PCM_H
#define _PCM_H
#include "task/task.h"
#include "platform.h"
#include "platform.h"
...
@@ -63,8 +64,6 @@ typedef struct {
...
@@ -63,8 +64,6 @@ typedef struct {
// buffer selectors
// buffer selectors
uint8_t
rbuf_idx
;
// read by ISR
uint8_t
rbuf_idx
;
// read by ISR
uint8_t
fbuf_idx
;
// fill by data task
uint8_t
fbuf_idx
;
// fill by data task
// task handles
task_handle_t
data_vu_task
,
data_play_task
,
start_play_task
;
// callback fn refs
// callback fn refs
int
self_ref
;
int
self_ref
;
int
cb_data_ref
,
cb_drained_ref
,
cb_paused_ref
,
cb_stopped_ref
,
cb_vu_ref
;
int
cb_data_ref
,
cb_drained_ref
,
cb_paused_ref
,
cb_stopped_ref
,
cb_vu_ref
;
...
@@ -95,7 +94,10 @@ typedef struct {
...
@@ -95,7 +94,10 @@ typedef struct {
}
pud_t
;
}
pud_t
;
void
pcm_data_vu_task
(
task_param_t
param
,
uint8
prio
);
void
pcm_data_vu
(
task_param_t
param
,
uint8
prio
);
void
pcm_data_play_task
(
task_param_t
param
,
uint8
prio
);
void
pcm_data_play
(
task_param_t
param
,
uint8
prio
);
// task handles
extern
task_handle_t
pcm_data_vu_task
,
pcm_data_play_task
,
pcm_start_play_task
;
#endif
/* _PCM_H */
#endif
/* _PCM_H */
app/pcm/pcm_core.c
View file @
d0c55876
...
@@ -27,7 +27,7 @@ static void dispatch_callback( lua_State *L, int self_ref, int cb_ref, int retur
...
@@ -27,7 +27,7 @@ static void dispatch_callback( lua_State *L, int self_ref, int cb_ref, int retur
}
}
}
}
void
pcm_data_vu
_task
(
task_param_t
param
,
uint8
prio
)
void
pcm_data_vu
(
task_param_t
param
,
uint8
prio
)
{
{
cfg_t
*
cfg
=
(
cfg_t
*
)
param
;
cfg_t
*
cfg
=
(
cfg_t
*
)
param
;
lua_State
*
L
=
lua_getstate
();
lua_State
*
L
=
lua_getstate
();
...
@@ -40,7 +40,7 @@ void pcm_data_vu_task( task_param_t param, uint8 prio )
...
@@ -40,7 +40,7 @@ void pcm_data_vu_task( task_param_t param, uint8 prio )
}
}
}
}
void
pcm_data_play
_task
(
task_param_t
param
,
uint8
prio
)
void
pcm_data_play
(
task_param_t
param
,
uint8
prio
)
{
{
cfg_t
*
cfg
=
(
cfg_t
*
)
param
;
cfg_t
*
cfg
=
(
cfg_t
*
)
param
;
pcm_buf_t
*
buf
=
&
(
cfg
->
bufs
[
cfg
->
fbuf_idx
]);
pcm_buf_t
*
buf
=
&
(
cfg
->
bufs
[
cfg
->
fbuf_idx
]);
...
@@ -85,7 +85,7 @@ void pcm_data_play_task( task_param_t param, uint8 prio )
...
@@ -85,7 +85,7 @@ void pcm_data_play_task( task_param_t param, uint8 prio )
// rerun data callback to get next buffer chunk
// rerun data callback to get next buffer chunk
dbg_platform_gpio_write
(
PLATFORM_GPIO_LOW
);
dbg_platform_gpio_write
(
PLATFORM_GPIO_LOW
);
cfg
->
fbuf_idx
=
other_buf
;
cfg
->
fbuf_idx
=
other_buf
;
pcm_data_play
_task
(
param
,
0
);
pcm_data_play
(
param
,
0
);
}
}
// unthrottle ISR
// unthrottle ISR
cfg
->
isr_throttled
=
0
;
cfg
->
isr_throttled
=
0
;
...
...
Write
Preview
Markdown
is supported
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