ISF  2.1
Intelligent Sensing Framework for Kinetis with Processor Expert
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
bus_management.c File Reference

Implements the ISF bus management functionality. This file is internal ISF code. More...

#include "isf_target.h"
#include "isf.h"
#include "lwevent.h"
#include "lwsem.h"
#include "mutex.h"
#include "fsl_pit_driver.h"
#include "isf_bm.h"
#include "bm_timer.h"
#include "bm_internal.h"
#include "cortex.h"
Include dependency graph for bus_management.c:

Go to the source code of this file.

Macros

#define BM_TOKEN_STARTING_VAL   (0x100)
 
#define PTE20   (1 << 20)
 
#define PTE21   (1 << 21)
 
#define PTE22   (1 << 22)
 

Functions

void isr_bm_callback_tmr (pointer dummy)
 
isf_status_t bm_init (void)
 Bus management initialization
. More...
 
void task_bm (uint32 initial_data)
 Bus Manager Task - main task to handle communication
via mailboxes with the host. More...
 
uint32 bm_update_cb_list (void)
 
int bm_find_cb (bm_callback_token_t aToken)
 Find the callback associated with the given a token.
. More...
 
bm_callback_token_t bm_generate_token (void)
 Bus management generate token. This token generator assigns one bit out of 32 bits as a token value.
. More...
 
void bm_sort_cb_list (void)
 Sort the callback list based on period in ascending order (callback with smallest period is first in the array).
. More...
 
void bm_reset_period (void)
 
uint32 bm_find_smallest_active_period (int8 period_type)
 Find the smallest current period.
. More...
 
bm_callback_token_t bm_register_periodic_callback (isf_duration_t aPeriod, bm_callback_t *pCallback, void *pCbData)
 This API schedules a callback at the specified period. More...
 
isf_status_t bm_unregister_callback (bm_callback_token_t aToken)
 This API unregisters one or more callbacks. More...
 
uint32 bm_get_num_callback (void)
 This API returns the number of callbacks registered. More...
 
isf_status_t bm_start (boolean aSync, bm_callback_token_t aTokens)
 This API sets one or more callback(s) to the active state. More...
 
isf_status_t bm_stop (bm_callback_token_t aTokens)
 This API stops one or more callback(s) by setting them to the inactive state. More...
 
void SetPortE_Gpio (uint32 gpio_mask, uint8 hilow)
 
void swdelay (int32 cnt)
 
uint32 bm_powerdown (void)
 Prepare bm for powerdown state. Called by power manager.
. More...
 
boolean bm_statechange_query (void)
 Tells caller if there a change in the state of the
bus manager. Change could be: More...
 
void bm_statechange_reset (void)
 Reset the state change. More...
 
boolean bm_cb_occurred_query (void)
 Tells caller if a callback was scheduled to be called since setting bus manager for powerdown mode. More...
 
boolean bm_active_cb_query (void)
 Tells caller if there are active callbacks.
. More...
 

Variables

BM_STATIC LWEVENT_STRUCT event_bm_callback
 
BM_STATIC LWSEM_STRUCT sema_bm_access
 
BM_STATIC BM_VOLATILE
bm_cb_config_t
gpBm_cb_list [MAX_BM_CALLBACKS]
 
BM_STATIC BM_VOLATILE boolean gBm_firsttime_flag = FALSE
 
BM_STATIC BM_VOLATILE boolean gBm_state_change = FALSE
 
BM_STATIC BM_VOLATILE boolean gBm_cb_occurred = FALSE
 
bm_t bm
 
uint32 bmPITInstance
 
uint32 bmRolloverPeriod
 

Detailed Description

Implements the ISF bus management functionality. This file is internal ISF code.

Definition in file bus_management.c.

Macro Definition Documentation

#define BM_TOKEN_STARTING_VAL   (0x100)

Definition at line 35 of file bus_management.c.

#define PTE20   (1 << 20)

Definition at line 516 of file bus_management.c.

Referenced by isr_bm_callback_tmr().

#define PTE21   (1 << 21)

Definition at line 517 of file bus_management.c.

Referenced by isr_bm_callback_tmr().

#define PTE22   (1 << 22)

Definition at line 518 of file bus_management.c.

Referenced by isr_bm_callback_tmr().

Function Documentation

boolean bm_active_cb_query ( void  )

Tells caller if there are active callbacks.
.

Returns
TRUE if there are active callbacks. FALSE otherwise.
Errors:

Constraints:

Reentrant: No.
Link Libraries:

See also

Definition at line 1085 of file bus_management.c.

References bm_t::cb_token_active_mask, FALSE, sema_bm_access, and TRUE.

boolean bm_cb_occurred_query ( void  )

Tells caller if a callback was scheduled to be called since setting bus manager for powerdown mode.

Returns
TRUE if there was a state change FALSE otherwise.
Errors:

Constraints:

Reentrant: No.
Link Libraries:

See also

Definition at line 1061 of file bus_management.c.

References gBm_cb_occurred.

int bm_find_cb ( bm_callback_token_t  aToken)

Find the callback associated with the given a token.
.

Parameters
aToken- [in] Token of callback to search for
Returns
Index of the list of callbacks that points to the one with matching token value. Most signficant bit is set (negative return value) if no matching token was found.
Errors:

Constraints:

Reentrant: No.
Link Libraries:

See also

Definition at line 838 of file bus_management.c.

References bm_t::cb_list_cur_cnt, and gpBm_cb_list.

Referenced by bm_unregister_callback().

Here is the caller graph for this function:

uint32 bm_find_smallest_active_period ( int8  period_type)

Find the smallest current period.
.

Returns
Smallest current period found in the callback list.
Errors:

Constraints:

Reentrant: No.
Link Libraries:

See also

Definition at line 872 of file bus_management.c.

References BM_FULL_PERIOD, bmRolloverPeriod, bm_t::cb_list_cur_cnt, bm_t::cb_token_active_mask, bm_cb_config_t::Cur_period, gpBm_cb_list, MAX_BM_PERIOD_USEC, bm_cb_config_t::nToken, and bm_cb_config_t::Period.

Referenced by bm_update_cb_list().

Here is the caller graph for this function:

bm_callback_token_t bm_generate_token ( void  )

Bus management generate token. This token generator assigns one bit out of 32 bits as a token value.
.

Returns
BM_TOKEN_STARTING_VAL to BM_TOKEN_VAL_MAX if successful 0 for failure (all tokens used up).
Errors:

Constraints:
The maximum number of callbacks that this token generator can handle is 32. Each bit in a 32bit variable is assigned to one callback.
The callback current count variable bm.cb_list_cur_cnt should have the current count value before the new callback is added. For example if this is the first callback being registered, then bm.cb_list_cur_cnt should be 0 when this function is called. The caller then increments bm.cb_list_cur_cnt after this function returns the new token.
Reentrant: No.
Link Libraries:

See also

Definition at line 728 of file bus_management.c.

References bm_t::cb_token_registered_mask, and MAX_BM_CALLBACKS.

Referenced by bm_register_periodic_callback().

Here is the caller graph for this function:

uint32 bm_get_num_callback ( void  )

This API returns the number of callbacks registered.

The number of registered callbacks is returned regardless of their state, active or inactive.

Returns
bm_get_num_callback() returns a value of type uint32 providing the number of callbacks currently registered with the Bus Manager whether they are in the active or inactive state.
Constraints:
None
Reentrant: Yes
Link Libraries:
isf_core.lib

Definition at line 230 of file bus_management.c.

References bm_t::cb_list_cur_cnt, and sema_bm_access.

isf_status_t bm_init ( void  )

Bus management initialization
.

This API initializes the Bus Manager.

Returns
ISF_SUCCESS if initialization is successful. ISF_ERR_LIB_INIT if initialization failed.
Errors:

Constraints:

Reentrant: No.
Link Libraries:

See also

Definition at line 409 of file bus_management.c.

References BM_PIPELINE_STAGES, bm_timer_init(), bm_t::cb_events, bm_t::cb_list_cur_cnt, bm_t::cb_token_active_mask, bm_t::cb_token_registered_mask, event_bm_callback, FALSE, gpBm_cb_list, ISF_SUCCESS, bm_t::pipeline_index, sema_bm_access, and TIMER_TPM_INIT.

Referenced by isf_lib_init().

Here is the call graph for this function:

Here is the caller graph for this function:

uint32 bm_powerdown ( void  )

Prepare bm for powerdown state. Called by power manager.
.

Returns
Remaining time to next callback scheduled in microseconds.
Errors:

Constraints:

Reentrant: No.
Link Libraries:

See also

Definition at line 937 of file bus_management.c.

References bmPITInstance, bm_t::cb_token_active_mask, FALSE, gBm_cb_occurred, gBm_state_change, pit_timer_stop(), and bm_t::time_keeper_usec.

Here is the call graph for this function:

bm_callback_token_t bm_register_periodic_callback ( isf_duration_t  aPeriod,
bm_callback_t apCallback,
void *  apCbData 
)

This API schedules a callback at the specified period.

The Bus Manager schedules periodic sensor data automatically. It allows a registered callback to be automatically invoked at the specified period. Multiple callbacks registered for the same frequency are executed serially by the Bus Manager. If registration of the callback is successful, the callback is set to the inactive state. The API function bm_start() can be called to make the callback active.

Parameters
[in]aPeriodThe period (1/frequency) between successive callback invocations in microseconds.
[in]apCallbackThe pointer to the callback function to be registered.
[in]apCbDataThe pointer passed to the callback function each time it is invoked. This pointer may be used to pass specific data to the callback function.
Returns
bm_register_periodic_callback() returns a token of type bm_callback_token_t if the callback registration is successful.
Return values
COMM_ERROR_NULL_PTRThis error value and the most significant bit of the macro BM_ERROR is returned if the callback function pointer is NULL.
COMM_ERROR_NOEXISTThis error value and the most significant bit of the macro BM_ERROR is returned if either of the following conditions are true:
Constraints:
The following constraints must be observed when using this function. If these constraints are not met, this API returns an error.
  • aPeriod must be within the valid range of MIN_BM_PERIOD_USEC to MAX_BM_PERIOD_USEC for the bus being initialized.
  • apCallback callback function pointer must not be NULL.
  • The number of callbacks registered must not exceed the maximum specified by MAX_BM_CALLBACKS.
Reentrant: Yes
Link Libraries:
isf_core.lib

Definition at line 90 of file bus_management.c.

References BM_ALLOC_MEM_ZERO, BM_ERROR, bm_generate_token(), bm_sort_cb_list(), bm_t::cb_list_cur_cnt, bm_t::cb_token_registered_mask, COMM_ERROR_NOEXIST, COMM_ERROR_NULL_PTR, bm_cb_config_t::Cur_period, gBm_state_change, gpBm_cb_list, MAX_BM_CALLBACKS, MAX_BM_PERIOD_USEC, MIN_BM_PERIOD_USEC, bm_cb_config_t::nToken, bm_cb_config_t::pCallback, bm_cb_config_t::pCbData, bm_cb_config_t::Period, sema_bm_access, and TRUE.

Referenced by fsl_fxas21002_i2cspi_3D_gyro_Configure(), fsl_fxls8471_i2cspi_3D_accel_Configure(), fsl_fxos8700_i2cspi_6D_AccMag_Configure(), fsl_mag3110_i2c_3D_mag_Configure(), fsl_mma865x_i2c_3D_accel_Configure(), and fsl_mpl3115_i2c_1D_press_Configure().

Here is the call graph for this function:

Here is the caller graph for this function:

void bm_reset_period ( void  )

Definition at line 373 of file bus_management.c.

References bm_t::cb_list_cur_cnt, bm_cb_config_t::Cur_period, gpBm_cb_list, and bm_cb_config_t::Period.

Referenced by bm_start().

Here is the caller graph for this function:

void bm_sort_cb_list ( void  )

Sort the callback list based on period in ascending order (callback with smallest period is first in the array).
.

Returns

Errors:

Constraints:

Reentrant: No.
Link Libraries:

See also

Definition at line 770 of file bus_management.c.

References bm_t::cb_list_cur_cnt, and gpBm_cb_list.

Referenced by bm_register_periodic_callback().

Here is the caller graph for this function:

isf_status_t bm_start ( boolean  aSync,
bm_callback_token_t  aTokens 
)

This API sets one or more callback(s) to the active state.

The start operation sets the callback(s) associated with the specified token values to the active state. A callback in the active state is invoked at its specified period. Multiple callbacks are specified by performing a logical OR of the token values. Any callbacks specified by this API call already in the active state, remain in the active state and their current timings are not affected. In addition to setting callbacks to the active state, this API can also synchronize the callback timings. The timings of all the active callbacks are reset to start running at the same time reference. The bm_stop() API call changes a callback to the inactive state.

Parameters
[in]aSyncThe parameter is set to TRUE to reset the timings of the active callbacks and start them running at the same time reference. The parameter is set to FALSE to leave all active callback timings as they are.
[in]aTokensThis parameter specifies the token value(s) of callback(s) to be set to the active state. More than one callback is specified by performing a logical OR of the token values associated with the registered callbacks.
Returns
isf_status_t bm_start() returns a value of type isf_status_t providing the status of the start operation.
Return values
ISF_SUCCESSThis value is returned if the callback(s) is set to the active state successfully.
COMM_ERROR_NOEXISTThis value is returned if at least one of the token values specified is invalid because it is not associated with a registered callback.
Constraints:
The following constraints must be observed when using this function. If these constraints are not met, this API returns an error.
  • aTokens value must be associated with the registered callback(s).
Reentrant: Yes
Link Libraries:
isf_core.lib
See also
bm_stop()

Definition at line 248 of file bus_management.c.

References BM_ALL_TOKENS, BM_ERROR, bm_reset_period(), bm_update_cb_list(), bmPITInstance, bm_t::cb_events, bm_t::cb_list_cur_cnt, bm_t::cb_token_active_mask, bm_t::cb_token_registered_mask, COMM_ERROR_NOEXIST, FALSE, ISF_SUCCESS, PitUserConfig::isInterruptEnabled, bm_t::pipeline_index, pit_hal_clear_interrupt_flag(), pit_hal_timer_reset(), pit_init_channel(), pit_init_module(), pit_set_timer_period_us(), pit_timer_start(), pit_timer_stop(), sema_bm_access, bm_t::time_keeper_usec, and TRUE.

Referenced by fsl_fxas21002_i2cspi_3D_gyro_StartData(), fsl_fxls8471_i2cspi_3D_accel_StartData(), fsl_fxos8700_i2cspi_6D_AccMag_StartData(), fsl_mag3110_i2c_3D_mag_StartData(), fsl_mma865x_i2c_3D_accel_StartData(), and fsl_mpl3115_i2c_1D_press_StartData().

Here is the call graph for this function:

Here is the caller graph for this function:

boolean bm_statechange_query ( void  )

Tells caller if there a change in the state of the
bus manager. Change could be:

  • New registerd callback(s)
  • Unregister of callback(s)
  • Change of start to stop state

Note that this function is typically called by the power manager (at lowest priority) in ilde mode and all other tasks are blocked. Which means we do not need to protect the read with semaphores and incur latency associated with it.

Returns
TRUE if there was a state change FALSE otherwise.
Errors:

Constraints:

Reentrant: No.
Link Libraries:

See also

Definition at line 1001 of file bus_management.c.

References gBm_state_change.

void bm_statechange_reset ( void  )

Reset the state change.

Errors:

Constraints:

Reentrant: No.
Link Libraries:

See also

Definition at line 1028 of file bus_management.c.

References FALSE, gBm_state_change, and sema_bm_access.

isf_status_t bm_stop ( bm_callback_token_t  aTokens)

This API stops one or more callback(s) by setting them to the inactive state.

The stop operation sets the the callback(s) associated with the specified token values to the inactive state. A callback in the inactive state is not invoked. Multiple callbacks are specified by performing a logical OR of the token values. Any callbacks specified by this API call already inactive will remain in the inactive state. To change a callback to the active state, the bm_start() API call is used.

Parameters
[in]aTokensThis parameter specifies the token value(s) of callback(s) to be set to the inactive state. More than one callback is specified by performing a logical OR of the token values associated with the registered callbacks.
Returns
isf_status_t bm_stop()returns a value of type isf_status_t providing the status of the stop operation.
Return values
ISF_SUCCESSThe callback(s) stopped successfully.
COMM_ERROR_NOEXISTAt least one of the token values specified is invalid because it is not associated with a registered callback.
Constraints:
The following constraints must be observed when using this function. If these constraints are not met, this API returns an error.
  • aTokens value must be associated with registered callback(s).
Reentrant: Yes
Link Libraries:
isf_core.lib
See also
bm_start()

Definition at line 321 of file bus_management.c.

References BM_ALL_TOKENS, BM_ERROR, bm_t::cb_list_cur_cnt, bm_t::cb_token_active_mask, bm_t::cb_token_registered_mask, COMM_ERROR_NOEXIST, gBm_state_change, ISF_SUCCESS, sema_bm_access, and TRUE.

Referenced by fsl_fxas21002_i2cspi_3D_gyro_EndData(), fsl_fxls8471_i2cspi_3D_accel_EndData(), fsl_fxos8700_i2cspi_6D_AccMag_EndData(), fsl_mag3110_i2c_3D_mag_EndData(), fsl_mma865x_i2c_3D_accel_EndData(), and fsl_mpl3115_i2c_1D_press_EndData().

Here is the caller graph for this function:

isf_status_t bm_unregister_callback ( bm_callback_token_t  aTokens)

This API unregisters one or more callbacks.

The Bus Manager allows the removal of a registered callback. After a call to this function, unregistered callbacks no longer exist. To specify the callback to be unregistered, the token returned by bm_register_periodic_callback() is passed to bm_unregister_callback(). Multiple callbacks can be specified by performing a logical OR of the token values. The callback can be in the active or inactive state when it is unregistered.

Parameters
[in]aTokensThis parameter specifies the token value(s) of the callback(s) that are to be unregistered. More than one callback is specified by performing a logical OR of the token values associated with the registered callbacks.
Returns
bm_unregister_callback() returns a value of type isf_status_t indicating the status of the unregister operation.
Return values
ISF_SUCCESSThis value is returned if the callbacks unregistered successfully.
COMM_ERROR_NOEXISTThis value is returned if at least one of the token values specified in aTokens is invalid because it is not associated with a registered callback.
Constraints:
The following constraints must be observed when using this function. If these constraints are not met, this API returns an error.
  • aTokens value must be associated with registered callback(s).
Reentrant: Yes
Link Libraries:
isf_core.lib
See also
bm_register_periodic_callback()

Definition at line 170 of file bus_management.c.

References BM_ERROR, bm_find_cb(), BM_FREE_MEM, bm_t::cb_list_cur_cnt, bm_t::cb_token_active_mask, bm_t::cb_token_registered_mask, COMM_ERROR_NOEXIST, gBm_state_change, gpBm_cb_list, ISF_SUCCESS, sema_bm_access, and TRUE.

Referenced by fsl_fxas21002_i2cspi_3D_gyro_Shutdown(), fsl_fxls8471_i2cspi_3D_accel_Shutdown(), fsl_fxos8700_i2cspi_6D_AccMag_Shutdown(), fsl_mag3110_i2c_3D_mag_Shutdown(), fsl_mma865x_i2c_3D_accel_Shutdown(), and fsl_mpl3115_i2c_1D_press_Shutdown().

Here is the call graph for this function:

Here is the caller graph for this function:

uint32 bm_update_cb_list ( void  )

Definition at line 457 of file bus_management.c.

References BM_CURRENT_PERIOD, bm_find_smallest_active_period(), BM_MINIMUM_CB_TIMELEFT_USEC, bm_t::cb_list_cur_cnt, bm_t::cb_token_active_mask, bm_cb_config_t::Cur_period, gpBm_cb_list, bm_cb_config_t::Period, and bm_t::time_keeper_usec.

Referenced by bm_start(), and isr_bm_callback_tmr().

Here is the call graph for this function:

Here is the caller graph for this function:

void isr_bm_callback_tmr ( pointer  dummy)
void SetPortE_Gpio ( uint32  gpio_mask,
uint8  hilow 
)

Referenced by isr_bm_callback_tmr().

Here is the caller graph for this function:

void swdelay ( int32  cnt)

Referenced by isr_bm_callback_tmr().

Here is the caller graph for this function:

void task_bm ( uint32  initial_data)

Bus Manager Task - main task to handle communication
via mailboxes with the host.

Parameters
initial_data- value passed in when task is created, not used.
Returns
None
Errors:

Constraints:

Reentrant: No.
Link Libraries:

See also
main.c/MQX_template_list[]

Definition at line 643 of file bus_management.c.

References bm_t::cb_token_active_mask, event_bm_callback, FALSE, gpBm_cb_list, bm_cb_config_t::pCallback, and TIMER_TPM_GET_CNT.

Referenced by TaskBusManager_task().

Here is the caller graph for this function:

Variable Documentation

bm_t bm

Definition at line 46 of file bus_management.c.

BM_STATIC LWEVENT_STRUCT event_bm_callback

Definition at line 37 of file bus_management.c.

Referenced by bm_init(), isr_bm_callback_tmr(), and task_bm().

BM_STATIC BM_VOLATILE boolean gBm_cb_occurred = FALSE

Definition at line 43 of file bus_management.c.

Referenced by bm_cb_occurred_query(), bm_powerdown(), and isr_bm_callback_tmr().

BM_STATIC BM_VOLATILE boolean gBm_firsttime_flag = FALSE

Definition at line 41 of file bus_management.c.