# KE_TASK
[KERNEL]

Task management module. More...

Collaboration diagram for KE_TASK:

## Data Structures
struct | ke_msg_handler
| Element of a message handler table. More...
struct | ke_state_handler
| Element of a state handler table. More...
struct | ke_task_desc
| Task descriptor grouping all information required by the kernel for the scheduling. More...
## Defines
#define | KE_FIRST_MSG(task) ((ke_msg_id_t)((task) << 10))
| Builds the first message ID of a task.
#define | MSG_T(msg) ((ke_task_id_t)((msg) >> 10))
| Returns the task identifier based on a message identifier.
#define | MSG_I(msg) ((msg) & ((1<<10)-1))
| Returns the message index in the task based on a message identifier.
#define | KE_STATE_HANDLER(hdl) {hdl, sizeof(hdl)/sizeof(struct ke_msg_handler)}
| Helps writing the initialization of the state handlers without errors.
#define | KE_STATE_HANDLER_NONE {NULL, 0}
| Helps writing empty states.
## Typedefs
typedef int(* | ke_msg_func_t )(ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id)
| Format of a task message handler function.
## Enumerations
enum | { TASK_NONE = (uint8_t) -1, TASK_MM = 0, TASK_DBG, TASK_SCAN, TASK_TDLS, TASK_SCANU, TASK_ME, TASK_SM, TASK_APM, TASK_BAM, TASK_MESH, TASK_RXU, TASK_LAST_EMB = TASK_RXU, TASK_API, TASK_MAX }
| Tasks types. More...
## Functions
static bool | cmp_dest_id (struct co_list_hdr const *msg, uint32_t dest_id)
| Compare destination task callback.
static void | ke_task_saved_update (ke_task_id_t const ke_task_id)
| Reactivation of saved messages.
void | ke_state_set (ke_task_id_t const id, ke_state_t const state_id)
| Set the state of the task identified by its Task Id.
ke_state_t | ke_state_get (ke_task_id_t const id)
| Retrieve the state of a task.
static ke_msg_func_t | ke_handler_search (ke_msg_id_t const msg_id, struct ke_state_handler const *state_handler)
| Search message handler function matching the msg id.
static ke_msg_func_t | ke_task_handler_get (ke_msg_id_t const msg_id, ke_task_id_t const task_id)
| Retrieve appropriate message handler function of a task.
void | ke_task_schedule (int dummy)
| Task scheduler entry point.
int | ke_msg_discard (ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id)
| Generic message handler to consume message without handling it in the task.
int | ke_msg_save (ke_msg_id_t const msgid, void const *param, ke_task_id_t const dest_id, ke_task_id_t const src_id)
| Generic message handler to consume message without handling it in the task.
__INLINE bool | ke_task_local (ke_task_id_t const id)
| Check if a task is executed on the local platform.
## Variables
static struct ke_task_desc | TASK_DESC [TASK_MAX]
| Table grouping the task descriptors.

## Detailed Description

Task management module.

This module implements the functions used for managing tasks.

## Define Documentation

#define KE_FIRST_MSG | ( | task |  | ) | ((ke_msg_id_t)((task) << 10))

Builds the first message ID of a task.

Parameters:

  `[in]` | task | Task identifier

Returns:
  The identifier of the first message of the task

Definition at line 96 of file ke_task.h.

#define MSG_I | ( | msg |  | ) | ((msg) & ((1<<10)-1))

Returns the message index in the task based on a message identifier.

Parameters:

  `[in]` | msg | Message identifier

Returns:
  The message index in the task

Definition at line 114 of file ke_task.h.

#define MSG_T | ( | msg |  | ) | ((ke_task_id_t)((msg) >> 10))

Returns the task identifier based on a message identifier.

Parameters:

  `[in]` | msg | Message identifier

Returns:
  The identifier of the task this message belongs to

Definition at line 105 of file ke_task.h.

## Enumeration Type Documentation

anonymous enum

Tasks types.

Enumerator:

  TASK_MM | MAC Management task.
  TASK_DBG | DEBUG task.
  TASK_SCAN | SCAN task.
  TASK_TDLS | TDLS task.
  TASK_SCANU | SCAN task.
  TASK_ME | SCAN task.
  TASK_SM | SM task.
  TASK_APM | APM task.
  TASK_BAM | BAM task.
  TASK_MESH | MESH task.
  TASK_RXU | RXU task.

Definition at line 47 of file ke_task.h.

## Function Documentation

static ke_msg_func_t ke_handler_search | ( | ke_msg_id_t const | msg_id,
|  | struct ke_state_handler const * | state_handler |
| ) |  |  | `[static]`

Search message handler function matching the msg id.

Parameters:

  `[in]` | msg_id | Message identifier
  `[in]` | state_handler | Pointer to the state handler

Returns:
  Pointer to the message handler (NULL if not found)

Definition at line 224 of file ke_task.c.

References ASSERT_ERR, ke_msg_handler::func, ke_msg_handler::id, ke_state_handler::msg_cnt, and ke_state_handler::msg_table.

Referenced by ke_task_handler_get().

int ke_msg_discard | ( | ke_msg_id_t const | msgid,
|  | void const * | param,
|  | ke_task_id_t const | dest_id,
|  | ke_task_id_t const | src_id |
| ) |  |  |

Generic message handler to consume message without handling it in the task.

Parameters:

  `[in]` | msgid | Id of the message received (probably unused)
  `[in]` | param | Pointer to the parameters of the message.
  `[in]` | dest_id | TaskId of the receiving task.
  `[in]` | src_id | TaskId of the sending task.

Returns:
  KE_MSG_CONSUMED

int ke_msg_save | ( | ke_msg_id_t const | msgid,
|  | void const * | param,
|  | ke_task_id_t const | dest_id,
|  | ke_task_id_t const | src_id |
| ) |  |  |

Generic message handler to consume message without handling it in the task.

Parameters:

  `[in]` | msgid | Id of the message received (probably unused)
  `[in]` | param | Pointer to the parameters of the message.
  `[in]` | dest_id | TaskId of the receiving task.
  `[in]` | src_id | TaskId of the sending task.

Returns:
  KE_MSG_CONSUMED

ke_state_t ke_state_get | ( | ke_task_id_t const | id | ) |

Retrieve the state of a task.

Parameters:

  `[in]` | id | Task id.

Returns:
  Current state of the task

Referenced by apm_start_cac_req_handler(), apm_start_req_handler(), apm_stop_cac_req_handler(), apm_stop_req_handler(), bam_add_ba_rsp_timeout_ind_handler(), bam_delba_status(), bam_inactivity_timeout_ind_handler(), me_config_monitor_req_handler(), me_set_active_cfm_handler(), me_set_active_req_handler(), me_set_ps_disable_cfm_handler(), me_set_ps_disable_req_handler(), me_set_ps_mode_req_handler(), mm_ba_add_cfm_handler(), mm_ba_del_cfm_handler(), mm_bcn_change_cfm_handler(), mm_bss_param_setting_handler(), mm_chan_ctxt_unlink_cfm_handler(), mm_connection_loss_ind_handler(), mm_force_idle_req_handler(), mm_hw_config_handler(), mm_scan_channel_end_ind_handler(), mm_scan_channel_start_ind_handler(), mm_set_idle_cfm_handler(), mm_set_idle_req_handler(), mm_set_ps_mode_cfm_handler(), mm_set_vif_state_cfm_handler(), mm_sta_add_cfm_handler(), mm_sta_del_cfm_handler(), mm_start_req_handler(), rxu_mgt_ind_handler(), rxu_mgt_route(), scan_cancel_req_handler(), scan_start_req_handler(), scanu_join_cfm_handler(), scanu_start_cfm_handler(), sm_connect_req_handler(), sm_disconnect_req_handler(), sm_external_auth_required_rsp_handler(), sm_frame_tx_cfm_handler(), sm_rsp_timeout_ind_handler(), tdls_cancel_chan_switch_req_handler(), tdls_check_frame_action(), tdls_check_peer_ps(), tdls_check_tdls_channel_switch_response(), and tdls_chsw_time_evt().

void ke_state_set | ( | ke_task_id_t const | id,
|  | ke_state_t const | state_id |
| ) |  |  |

Set the state of the task identified by its Task Id.

In this function we also handle the SAVE service: when a task state changes we try to activate all the messages currently saved in the save queue for the given task identifier.

Parameters:

  `[in]` | id | Identifier of the task instance whose state is going to be modified
  `[in]` | state_id | New State

Referenced by bam_add_ba_rsp_timeout_ind_handler(), bam_create_ba_agg(), bam_inactivity_timeout_ind_handler(), me_config_req_handler(), me_env_init(), me_set_active_cfm_handler(), me_set_active_req_handler(), me_set_ps_disable_req_handler(), me_set_ps_mode_req_handler(), mm_ba_add_cfm_handler(), mm_connection_loss_ind_handler(), mm_force_idle_req_handler(), mm_hw_config_handler(), mm_reset_req_handler(), mm_scan_channel_end_ind_handler(), mm_scan_channel_start_ind_handler(), mm_set_idle_cfm_handler(), mm_set_idle_req_handler(), mm_set_ps_mode_cfm_handler(), mm_start_req_handler(), rxu_mgt_ind_handler(), scanu_join_cfm_handler(), sm_connect_req_handler(), tdls_cancel_chan_switch_req_handler(), tdls_chan_switch_req_handler(), tdls_check_frame_action(), tdls_chsw_req_tx_cfm(), tdls_chsw_rsp_tx_cfm(), tdls_chsw_time_evt(), tdls_chsw_timeout_evt(), tdls_chsw_unsol_rsp_tx_cfm(), tdls_keep_alive_evt(), and tdls_peer_traffic_ind_req_handler().

static ke_msg_func_t ke_task_handler_get | ( | ke_msg_id_t const | msg_id,
|  | ke_task_id_t const | task_id |
| ) |  |  | `[static]`

Retrieve appropriate message handler function of a task.

Parameters:

  `[in]` | msg_id | Message identifier
  `[in]` | task_id | Task instance identifier

Returns:
  Pointer to the message handler (NULL if not found)

Definition at line 254 of file ke_task.c.

References ASSERT_ERR, ke_task_desc::default_handler, ke_handler_search(), KE_IDX_GET, ke_task_local(), KE_TYPE_GET, ke_task_desc::state, and ke_task_desc::state_handler.

__INLINE bool ke_task_local | ( | ke_task_id_t const | id | ) |

Check if a task is executed on the local platform.

Parameters:

  `[in]` | id | Task instance identifier

Returns:
  True if the task is executed on the local platform

Definition at line 176 of file ke_task.h.

References ASSERT_ERR.

Referenced by ipc_emb_kmsg_hdlr(), and ke_task_handler_get().

static void ke_task_saved_update | ( | ke_task_id_t const | ke_task_id | ) | `[static]`

Reactivation of saved messages.

This primitive looks for all the messages destined to the task ke_task_id that have been saved and inserts them into the sent priority queue. These messages will be scheduled at the next scheduler pass.

Parameters:

  `[in]` | ke_task_id | Destination Identifier

Definition at line 118 of file ke_task.c.

References cmp_dest_id(), GLOBAL_INT_DISABLE, GLOBAL_INT_RESTORE, ke_env, KE_EVT_KE_MESSAGE_BIT, ke_evt_set(), ke_queue_extract(), ke_queue_push(), ke_env_tag::queue_saved, and ke_env_tag::queue_sent.

void ke_task_schedule | ( | int | dummy | ) |

Task scheduler entry point.

This function is the scheduler of messages. It tries to get a message from the sent queue, then try to get the appropriate message handler function (from the current state, or the default one). This function is called, then the message is saved or freed.

Parameters:

  `[in]` | dummy | Parameter not used but required to follow the kernel event callback format