FreeCalypso > hg > fc-tourmaline
changeset 294:e17bdedfbf2b
VIBR SWE initial implementation
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 27 Mar 2022 08:46:10 +0000 |
parents | 2d7d95e7f9c2 |
children | e5cfd6362158 |
files | components/vibr configure.sh scripts/config-headers.sh scripts/make-rv-swe-hdr.sh src/cs/services/vibr/vibr_api.c src/cs/services/vibr/vibr_api.h src/cs/services/vibr/vibr_env.c src/cs/services/vibr/vibr_env.h src/cs/services/vibr/vibr_func_i.h src/cs/services/vibr/vibr_handle_message.c src/cs/services/vibr/vibr_messages_i.h src/cs/services/vibr/vibr_pool_size.h src/cs/services/vibr/vibr_process.c src/cs/services/vibr/vibr_struct_i.h src/cs/services/vibr/vibr_task.c targets/c11x.conf targets/c139.conf targets/c155.conf targets/j100.conf targets/pirelli.conf |
diffstat | 20 files changed, 498 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/components/vibr Sun Mar 27 08:46:10 2022 +0000 @@ -0,0 +1,42 @@ +# Building VIBR SWE - an original FreeCalypso addition + +CFLAGS="-mn -mt -o -x -mw -me -pw2" +CPPFLAGS="-DTOOL_CHOICE=0 -D_TMS470" + +# Includes + +CPPFLAGS="$CPPFLAGS -I$SRC/nucleus" +CPPFLAGS="$CPPFLAGS -I.." +CPPFLAGS="$CPPFLAGS -I../config" +CPPFLAGS="$CPPFLAGS -I$SRC/gpf/inc" +CPPFLAGS="$CPPFLAGS -I$SRC/gpf/frame/cust_os" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/system" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/riviera" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/riviera/rv" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/abb" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/armio" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/clkm" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/conf" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/dma" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/dsp_dwnld" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/inth" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/memif" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/rhea" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/security" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/spi" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/timer" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/uart" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_core/ulpd" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/drivers/drv_app" +CPPFLAGS="$CPPFLAGS -I$SRC/cs/services" + +# Source modules + +SRCDIR=$SRC/cs/services/vibr + +cfile_plain $SRCDIR/vibr_api.c +cfile_plain $SRCDIR/vibr_env.c +cfile_plain $SRCDIR/vibr_handle_message.c +cfile_plain $SRCDIR/vibr_process.c +cfile_plain $SRCDIR/vibr_task.c
--- a/configure.sh Sun Mar 27 01:33:02 2022 +0000 +++ b/configure.sh Sun Mar 27 08:46:10 2022 +0000 @@ -52,6 +52,7 @@ RF=12 DISABLE_SLEEP=0 FCHG_STATE=0 +VIBR_STATE=0 RVTMUX_ON_MODEM=0 . "targets/$TARGET.conf" @@ -224,7 +225,7 @@ export CHIPSET DSP RF export AMR L1_DYN_DSP_DWNLD L1_VOICE_MEMO_AMR MELODY_E2 SPEECH_RECO export DISABLE_SLEEP -export FCHG_STATE R2D_STATE +export FCHG_STATE R2D_STATE VIBR_STATE export GPRS MMI SRVC RVTMUX_ON_MODEM export R2D_EMBEDDED_LCD UI_CONFIG export ALLOW_CSIM_GSM SERIAL_DYNAMIC_SWITCH TR_BAUD_CONFIG @@ -400,6 +401,10 @@ lib_link_magic '(BSS_DAR_LIB (.bss))' build_lib etm build_lib lls +if [ "$VIBR_STATE" = 1 ] +then + build_lib vibr +fi # app drivers build_lib abb
--- a/scripts/config-headers.sh Sun Mar 27 01:33:02 2022 +0000 +++ b/scripts/config-headers.sh Sun Mar 27 08:46:10 2022 +0000 @@ -112,6 +112,12 @@ fi export R2D_STATE +if [ -z "$VIBR_STATE" ] +then + VIBR_STATE=1 +fi +export VIBR_STATE + if [ -z "$R2D_EMBEDDED_LCD" ] then R2D_EMBEDDED_LCD=7
--- a/scripts/make-rv-swe-hdr.sh Sun Mar 27 01:33:02 2022 +0000 +++ b/scripts/make-rv-swe-hdr.sh Sun Mar 27 08:46:10 2022 +0000 @@ -44,6 +44,11 @@ echo '#define RVM_RTC_SWE' echo '#define RVM_FFS_SWE' +if [ "$VIBR_STATE" = 1 ] +then + echo '#define RVM_VIBR_SWE' +fi + if [ "$FCBM_STATE" = 1 ] then echo '#define RVM_FCBM_SWE'
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cs/services/vibr/vibr_api.c Sun Mar 27 08:46:10 2022 +0000 @@ -0,0 +1,64 @@ +/* + * The implementation of our external API functions lives here. + */ + +#include "vibr/vibr_api.h" +#include "vibr/vibr_env.h" +#include "vibr/vibr_messages_i.h" +#include "rv/rv_general.h" +#include "rvf/rvf_api.h" +#include "rvm/rvm_use_id_list.h" + +T_RV_RET vibr_pulse_train_start(UINT8 num_pulses, UINT8 vibr_level) +{ + struct vibr_start_msg *msg; + + if (!vibr_env) + return RV_NOT_READY; + if (rvf_get_buf(vibr_env->prim_id, sizeof(struct vibr_start_msg), + (T_RVF_BUFFER **)&msg) == RVF_RED) { + rvf_send_trace( + "rvf_get_buf() failed in vibr_pulse_train_start()", 48, + NULL_PARAM, RV_TRACE_LEVEL_ERROR, VIBR_USE_ID); + return RV_MEMORY_ERR; + } + msg->hdr.msg_id = VIBR_START_REQ; + msg->hdr.src_addr_id = vibr_env->addr_id; + msg->hdr.dest_addr_id = vibr_env->addr_id; + msg->hdr.callback_func = NULL; + msg->num_pulses = num_pulses; + msg->vibr_level = vibr_level; + if (rvf_send_msg(vibr_env->addr_id, msg) != RV_OK) { + rvf_send_trace("vibr_pulse_train_start(): Send failed!", 38, + NULL_PARAM, RV_TRACE_LEVEL_ERROR, VIBR_USE_ID); + rvf_free_buf(msg); + return RV_INTERNAL_ERR; + } + return RV_OK; +} + +T_RV_RET vibr_pulse_train_stop(void) +{ + struct vibr_stop_msg *msg; + + if (!vibr_env) + return RV_NOT_READY; + if (rvf_get_buf(vibr_env->prim_id, sizeof(struct vibr_stop_msg), + (T_RVF_BUFFER **)&msg) == RVF_RED) { + rvf_send_trace( + "rvf_get_buf() failed in vibr_pulse_train_stop()", 47, + NULL_PARAM, RV_TRACE_LEVEL_ERROR, VIBR_USE_ID); + return RV_MEMORY_ERR; + } + msg->hdr.msg_id = VIBR_STOP_REQ; + msg->hdr.src_addr_id = vibr_env->addr_id; + msg->hdr.dest_addr_id = vibr_env->addr_id; + msg->hdr.callback_func = NULL; + if (rvf_send_msg(vibr_env->addr_id, msg) != RV_OK) { + rvf_send_trace("vibr_pulse_train_stop(): Send failed!", 37, + NULL_PARAM, RV_TRACE_LEVEL_ERROR, VIBR_USE_ID); + rvf_free_buf(msg); + return RV_INTERNAL_ERR; + } + return RV_OK; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cs/services/vibr/vibr_api.h Sun Mar 27 08:46:10 2022 +0000 @@ -0,0 +1,16 @@ +/* + * This header file defines the external API of our VIBR SWE, + * callable from other tasks such as UI or AT commands. + */ + +#ifndef __VIBR_API_H +#define __VIBR_API_H + +#include "rv/rv_general.h" + +#define VIBR_LEVEL_MAX 255 + +T_RV_RET vibr_pulse_train_start(UINT8 num_pulses, UINT8 vibr_level); +T_RV_RET vibr_pulse_train_stop(void); + +#endif /* include guard */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cs/services/vibr/vibr_env.c Sun Mar 27 08:46:10 2022 +0000 @@ -0,0 +1,106 @@ +/* + * This module provides the glue to the RiViera environment + * for our VIBR SWE. + */ + +#include "vibr/vibr_env.h" +#include "rv/rv_general.h" +#include "rvf/rvf_api.h" +#include "rvm/rvm_priorities.h" +#include "rvm/rvm_api.h" +#include "rvm/rvm_use_id_list.h" +#include <string.h> + +/* global control block for our SWE */ +struct vibr_env *vibr_env; + +/* Define global pointer to the error function */ +static T_RVM_RETURN (*xxx_error_ft) (T_RVM_NAME swe_name, + T_RVM_RETURN error_cause, + T_RVM_ERROR_TYPE error_type, + T_RVM_STRING error_msg); + +T_RVM_RETURN vibr_get_info (T_RVM_INFO_SWE *infoSWE) +{ + /* SWE info */ + + infoSWE->swe_type = RVM_SWE_TYPE_4; + infoSWE->type_info.type4.swe_use_id = VIBR_USE_ID; + memcpy( infoSWE->type_info.type4.swe_name, "VIBR", 5 ); + + infoSWE->type_info.type4.stack_size = VIBR_STACK_SIZE; + infoSWE->type_info.type4.priority = RVM_VIBR_TASK_PRIORITY; + + /* memory bank info */ + infoSWE->type_info.type4.nb_mem_bank = 1; + + memcpy ((UINT8 *) infoSWE->type_info.type4.mem_bank[0].bank_name, "VIBR_PRIM", 10); + infoSWE->type_info.type4.mem_bank[0].initial_params.size = VIBR_MB_PRIM_SIZE; + infoSWE->type_info.type4.mem_bank[0].initial_params.watermark = VIBR_MB_PRIM_WATERMARK; + + /* linked SWE info: none */ + infoSWE->type_info.type4.nb_linked_swe = 0; + + /* generic functions */ + infoSWE->type_info.type4.set_info = vibr_set_info; + infoSWE->type_info.type4.init = vibr_init; + infoSWE->type_info.type4.core = vibr_core; + infoSWE->type_info.type4.stop = vibr_stop; + infoSWE->type_info.type4.kill = vibr_kill; + + /* Set the return path */ + infoSWE->type_info.type4.return_path.callback_func = NULL; + infoSWE->type_info.type4.return_path.addr_id = 0; + + return RV_OK; +} + +T_RVM_RETURN vibr_set_info(T_RVF_ADDR_ID addr_id, + T_RV_RETURN return_path[], + T_RVF_MB_ID mbId[], + T_RVM_RETURN (*callBackFct) (T_RVM_NAME SWEntName, + T_RVM_RETURN errorCause, + T_RVM_ERROR_TYPE errorType, + T_RVM_STRING errorMsg)) +{ + + T_RVF_MB_STATUS mb_status; + + mb_status = rvf_get_buf(mbId[0],sizeof(struct vibr_env),(void **) &vibr_env); + if (mb_status == RVF_RED) + { + rvf_send_trace("vibr_set_info: rvf_get_buf() failed", 35, + NULL_PARAM, RV_TRACE_LEVEL_ERROR, VIBR_USE_ID); + return (RVM_MEMORY_ERR); + } + memset(vibr_env, 0, sizeof(struct vibr_env)); + + /* store the pointer to the error function */ + xxx_error_ft = callBackFct ; + + /* Store the addr id */ + vibr_env->addr_id = addr_id; + + /* Store the memory bank id */ + vibr_env->prim_id = mbId[0]; + + return RV_OK; +} + +T_RVM_RETURN vibr_init(void) +{ + return RV_OK; +} + +T_RVM_RETURN vibr_stop(void) +{ + return RV_OK; +} + +T_RVM_RETURN vibr_kill(void) +{ + /* free all memory buffer previously allocated */ + rvf_free_buf ((void *) vibr_env); + + return RV_OK; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cs/services/vibr/vibr_env.h Sun Mar 27 08:46:10 2022 +0000 @@ -0,0 +1,41 @@ +/* + * RiViera environment boilerplate header for VIBR SWE + */ + +#ifndef __VIBR_ENV_H__ +#define __VIBR_ENV_H__ + +#include "rvm/rvm_gen.h" +#include "vibr/vibr_struct_i.h" +#include "vibr/vibr_pool_size.h" + +#define VIBR_MAILBOX RVF_TASK_MBOX_0 +#define VIBR_TIMER RVF_TIMER_0 + +/* memory bank size and watermark */ +#define VIBR_MB_PRIM_SIZE VIBR_MB1_SIZE +#define VIBR_MB_PRIM_WATERMARK (VIBR_MB_PRIM_SIZE) + +#define VIBR_MB_PRIM_INC_SIZE 0 +#define VIBR_MB_PRIM_INC_WATERMARK 0 + +extern struct vibr_env *vibr_env; + +/* Prototypes */ + +T_RVM_RETURN vibr_get_info (T_RVM_INFO_SWE *infoSWE); + +T_RVM_RETURN vibr_set_info(T_RVF_ADDR_ID addr_id, + T_RV_RETURN return_path[], + T_RVF_MB_ID mbId[], + T_RVM_RETURN (*callBackFct) (T_RVM_NAME SWEntName, + T_RVM_RETURN errorCause, + T_RVM_ERROR_TYPE errorType, + T_RVM_STRING errorMsg)); + +T_RVM_RETURN vibr_init (void); +T_RVM_RETURN vibr_core (void); +T_RVM_RETURN vibr_stop (void); +T_RVM_RETURN vibr_kill (void); + +#endif /* include guard */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cs/services/vibr/vibr_func_i.h Sun Mar 27 08:46:10 2022 +0000 @@ -0,0 +1,15 @@ +/* + * Declarations of internal functions live here. + */ + +#ifndef __VIBR_FUNC_I +#define __VIBR_FUNC_I + +#include "vibr/vibr_messages_i.h" + +void vibr_process_message(T_RV_HDR *msg_ptr); +void vibr_process_start_req(struct vibr_start_msg *msg); +void vibr_process_stop_req(struct vibr_stop_msg *msg); +void vibr_handle_timer(void); + +#endif /* include guard */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cs/services/vibr/vibr_handle_message.c Sun Mar 27 08:46:10 2022 +0000 @@ -0,0 +1,25 @@ +/* + * Incoming message dispatch for our VIBR task is implemented here. + */ + +#include "vibr/vibr_env.h" +#include "vibr/vibr_func_i.h" +#include "rv/rv_general.h" +#include "rvf/rvf_api.h" +#include "rvm/rvm_use_id_list.h" + +void vibr_process_message(T_RV_HDR *msg_ptr) +{ + switch (msg_ptr->msg_id) { + case VIBR_START_REQ: + vibr_process_start_req((struct vibr_start_msg *) msg_ptr); + return; + case VIBR_STOP_REQ: + vibr_process_stop_req((struct vibr_stop_msg *) msg_ptr); + return; + default: + rvf_send_trace("VIBR task: Received an unknown message", 38, + NULL_PARAM, RV_TRACE_LEVEL_DEBUG_HIGH, + VIBR_USE_ID); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cs/services/vibr/vibr_messages_i.h Sun Mar 27 08:46:10 2022 +0000 @@ -0,0 +1,26 @@ +/* + * In this header file we are going to define our internal messages + * that will be sent to our VIBR task by our API layer. + */ + +#ifndef __VIBR_MESSAGES_I +#define __VIBR_MESSAGES_I + +#include "rv/rv_general.h" + +struct vibr_start_msg { + T_RV_HDR hdr; + UINT8 num_pulses; + UINT8 vibr_level; +}; + +struct vibr_stop_msg { + T_RV_HDR hdr; +}; + +enum vibr_msg_id { + VIBR_START_REQ = 1, + VIBR_STOP_REQ +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cs/services/vibr/vibr_pool_size.h Sun Mar 27 08:46:10 2022 +0000 @@ -0,0 +1,13 @@ +/* + * Pool size definition required for every RiViera SWE + * VIBR is an entirely new FreeCalypso addition + */ + +#ifndef __VIBR_POOL_SIZE_H_ +#define __VIBR_POOL_SIZE_H_ + +#define VIBR_STACK_SIZE (1024) +#define VIBR_MB1_SIZE (1024) + +#define VIBR_POOL_SIZE (VIBR_STACK_SIZE + VIBR_MB1_SIZE) +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cs/services/vibr/vibr_process.c Sun Mar 27 08:46:10 2022 +0000 @@ -0,0 +1,66 @@ +/* + * In this module we are going to implement the main process functions + * for VIBR. + */ + +#include "vibr/vibr_env.h" +#include "vibr/vibr_func_i.h" +#include "rv/rv_general.h" +#include "rvf/rvf_api.h" +#include "rvm/rvm_use_id_list.h" +#include "main/sys_types.h" +#include "buzzer/vibrator.h" + +/* duration of "on" and "off" phases of each vibration cycle */ +#define ON_PHASE_MS 500 +#define OFF_PHASE_MS 500 + +void vibr_process_start_req(struct vibr_start_msg *msg) +{ + vibr_env->vibr_level = msg->vibr_level; + /* start the first pulse */ + HW_vibrator_on(vibr_env->vibr_level); + vibr_env->on_state = TRUE; + rvf_start_timer(VIBR_TIMER, RVF_MS_TO_TICKS(ON_PHASE_MS), FALSE); + if (msg->num_pulses) { + vibr_env->cont_mode = FALSE; + vibr_env->remain_cycles = msg->num_pulses; + } else + vibr_env->cont_mode = TRUE; +} + +void vibr_process_stop_req(struct vibr_stop_msg *msg) +{ + HW_vibrator_off(); + rvf_stop_timer(VIBR_TIMER); +} + +static void on_phase_end(void) +{ + HW_vibrator_off(); + /* got more pulses? */ + if (!vibr_env->cont_mode) { + vibr_env->remain_cycles--; + if (!vibr_env->remain_cycles) + return; /* pulse train finished */ + } + /* time the "off" phase before next pulse */ + vibr_env->on_state = FALSE; + rvf_start_timer(VIBR_TIMER, RVF_MS_TO_TICKS(OFF_PHASE_MS), FALSE); +} + +static void off_phase_end(void) +{ + /* start the next pulse */ + HW_vibrator_on(vibr_env->vibr_level); + vibr_env->on_state = TRUE; + rvf_start_timer(VIBR_TIMER, RVF_MS_TO_TICKS(ON_PHASE_MS), FALSE); +} + +void vibr_handle_timer(void) +{ + if (vibr_env->on_state) + on_phase_end(); + else + off_phase_end(); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cs/services/vibr/vibr_struct_i.h Sun Mar 27 08:46:10 2022 +0000 @@ -0,0 +1,23 @@ +/* + * This header file holds the internal structure definition + * for VIBR SWE. + */ + +#ifndef __VIBR_STRUCT_I +#define __VIBR_STRUCT_I + +#include "rv/rv_general.h" +#include "rvf/rvf_api.h" + +struct vibr_env { + /* RiViera boilerplate */ + T_RVF_ADDR_ID addr_id; + T_RVF_MB_ID prim_id; + /* vibration state */ + UINT8 vibr_level; + BOOL on_state; + BOOL cont_mode; + UINT8 remain_cycles; +}; + +#endif /* include guard */
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/cs/services/vibr/vibr_task.c Sun Mar 27 08:46:10 2022 +0000 @@ -0,0 +1,39 @@ +/* + * Our VIBR task's core function lives here. + */ + +#include "vibr/vibr_env.h" +#include "vibr/vibr_func_i.h" +#include "rv/rv_general.h" +#include "rvf/rvf_api.h" +#include "rvm/rvm_use_id_list.h" + +T_RV_RET vibr_core(void) +{ + BOOLEAN error_occured = FALSE; + T_RV_HDR *msg_ptr; + + /* loop to process messages */ + while (error_occured == FALSE) + { + /* Wait for the necessary events (infinite wait for a msg in the mailbox 0). */ + UINT16 received_event = rvf_wait (0xffff, 0); + + /* If an event related to mailbox 0 is received, then */ + if (received_event & RVF_TASK_MBOX_0_EVT_MASK) + { + /* Read the message in the driver mailbox and delegate action..*/ + msg_ptr = (T_RV_HDR *) rvf_read_mbox(VIBR_MAILBOX); + if (msg_ptr) { + vibr_process_message(msg_ptr); + rvf_free_buf ((void *) msg_ptr); + } + } + + /* Timers */ + if (received_event & RVF_TIMER_0_EVT_MASK) + vibr_handle_timer(); + + } // end of while + return RV_OK; +}
--- a/targets/c11x.conf Sun Mar 27 01:33:02 2022 +0000 +++ b/targets/c11x.conf Sun Mar 27 08:46:10 2022 +0000 @@ -3,4 +3,5 @@ FLASH_SECTOR_SIZE=0x10000 FCHG_STATE=1 +VIBR_STATE=1 RVTMUX_ON_MODEM=1
--- a/targets/c139.conf Sun Mar 27 01:33:02 2022 +0000 +++ b/targets/c139.conf Sun Mar 27 08:46:10 2022 +0000 @@ -3,4 +3,5 @@ FLASH_SECTOR_SIZE=0x10000 FCHG_STATE=1 +VIBR_STATE=1 RVTMUX_ON_MODEM=1
--- a/targets/c155.conf Sun Mar 27 01:33:02 2022 +0000 +++ b/targets/c155.conf Sun Mar 27 08:46:10 2022 +0000 @@ -3,4 +3,5 @@ FLASH_SECTOR_SIZE=0x10000 FCHG_STATE=1 +VIBR_STATE=1 RVTMUX_ON_MODEM=1