FreeCalypso > hg > fc-tourmaline
comparison src/cs/services/buzm/buzm_api.c @ 297:8dfdf88d632f
BUZM SWE initial implementation
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 29 Mar 2022 03:45:41 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
296:a927f030a4e0 | 297:8dfdf88d632f |
---|---|
1 /* | |
2 * The implementation of our external API functions lives here. | |
3 */ | |
4 | |
5 #include "buzm/buzm_api.h" | |
6 #include "buzm/buzm_env.h" | |
7 #include "buzm/buzm_messages_i.h" | |
8 #include "rv/rv_general.h" | |
9 #include "rvf/rvf_api.h" | |
10 #include "rvm/rvm_use_id_list.h" | |
11 #include "ffs/ffs_api.h" | |
12 | |
13 T_RV_RET buzm_play_melody(const char *pathname, UINT8 volume, BOOL loop) | |
14 { | |
15 struct buzm_start_msg *msg; | |
16 T_FFS_FD fd; | |
17 | |
18 if (!buzm_env) | |
19 return RV_NOT_READY; | |
20 if (volume < BUZM_VOLUME_MIN || volume > BUZM_VOLUME_MAX) | |
21 return RV_INVALID_PARAMETER; | |
22 fd = ffs_open(pathname, FFS_O_RDONLY); | |
23 if (fd <= 0) | |
24 return RV_INVALID_PARAMETER; | |
25 if (rvf_get_buf(buzm_env->prim_id, sizeof(struct buzm_start_msg), | |
26 (T_RVF_BUFFER **)&msg) == RVF_RED) { | |
27 rvf_send_trace( | |
28 "rvf_get_buf() failed in buzm_play_melody()", 42, | |
29 NULL_PARAM, RV_TRACE_LEVEL_ERROR, BUZM_USE_ID); | |
30 ffs_close(fd); | |
31 return RV_MEMORY_ERR; | |
32 } | |
33 msg->hdr.msg_id = BUZM_START_REQ; | |
34 msg->hdr.src_addr_id = buzm_env->addr_id; | |
35 msg->hdr.dest_addr_id = buzm_env->addr_id; | |
36 msg->hdr.callback_func = NULL; | |
37 msg->fd = fd; | |
38 msg->volume = volume; | |
39 msg->loop = loop; | |
40 if (rvf_send_msg(buzm_env->addr_id, msg) != RV_OK) { | |
41 rvf_send_trace("buzm_play_melody(): Send failed!", 32, | |
42 NULL_PARAM, RV_TRACE_LEVEL_ERROR, BUZM_USE_ID); | |
43 rvf_free_buf(msg); | |
44 ffs_close(fd); | |
45 return RV_INTERNAL_ERR; | |
46 } | |
47 return RV_OK; | |
48 } | |
49 | |
50 T_RV_RET buzm_stop_melody(void) | |
51 { | |
52 struct buzm_stop_msg *msg; | |
53 | |
54 if (!buzm_env) | |
55 return RV_NOT_READY; | |
56 if (rvf_get_buf(buzm_env->prim_id, sizeof(struct buzm_stop_msg), | |
57 (T_RVF_BUFFER **)&msg) == RVF_RED) { | |
58 rvf_send_trace( | |
59 "rvf_get_buf() failed in buzm_stop_melody()", 42, | |
60 NULL_PARAM, RV_TRACE_LEVEL_ERROR, BUZM_USE_ID); | |
61 return RV_MEMORY_ERR; | |
62 } | |
63 msg->hdr.msg_id = BUZM_STOP_REQ; | |
64 msg->hdr.src_addr_id = buzm_env->addr_id; | |
65 msg->hdr.dest_addr_id = buzm_env->addr_id; | |
66 msg->hdr.callback_func = NULL; | |
67 if (rvf_send_msg(buzm_env->addr_id, msg) != RV_OK) { | |
68 rvf_send_trace("buzm_stop_melody(): Send failed!", 32, | |
69 NULL_PARAM, RV_TRACE_LEVEL_ERROR, BUZM_USE_ID); | |
70 rvf_free_buf(msg); | |
71 return RV_INTERNAL_ERR; | |
72 } | |
73 return RV_OK; | |
74 } |