blob: 14149bde04f2169208f47236aaeb0b1c848fbd67 [file] [log] [blame]
rjw6c1fd8f2022-11-30 14:33:01 +08001#include <string.h>
2#include "nvram_msgid.h"
3
4#include "kal_general_types.h"
5#include "kal_public_defs.h"
6#include "kal_public_api.h"
7#include "kal_trace.h"
8
9#include "syscomp_config.h"
10#include "task_config.h"
11#include "sysconf_statistics.h" /* stack_statistics_struct */
12
13#include "nvram_enums.h"
14#include "nvram_struct.h"
15#include "nvram_data_items.h"
16#include "drv_sap.h"
17
18#include "tst_msgid.h"
19#include "tst_sap.h"
20
21void nvtest_main(ilm_struct *ilm_ptr)
22{
23 NVRAM_EXT_ASSERT(ilm_ptr != NULL,(kal_uint32)ilm_ptr,NVRAM_LOC_ILM_PTR_IS_NULL_2, 0);
24
25 if (ilm_ptr != NULL)
26 {
27 if (ilm_ptr->msg_id == MSG_ID_NVRAM_READ_CNF) {
28 nvram_read_cnf_struct *read_cnf;
29 kal_uint8 *data_ptr;
30 kal_uint16 data_len;
31
32 read_cnf = (nvram_read_cnf_struct *)ilm_ptr->local_para_ptr;
33 data_ptr = get_peer_buff_pdu(ilm_ptr->peer_buff_ptr, &data_len);
34 kal_prompt_trace(MOD_NVTEST, "Got Read CNF from NVRAM, [LID=%d, Index=%d, Len=%d]",
35 read_cnf->file_idx, read_cnf->para, read_cnf->length);
36 } else if (ilm_ptr->msg_id == MSG_ID_TST_INJECT_STRING) {
37 tst_module_string_inject_struct *tst_inject = (tst_module_string_inject_struct*) ilm_ptr->local_para_ptr;
38 if (strncmp((kal_char*) tst_inject->string, "reg", 3) == 0 || strncmp((kal_char*) tst_inject->string, "REG", 3) == 0 )
39 {
40 kal_prompt_trace(MOD_NVTEST, "Test Reg NVRAM Monitor, index=%d, inject string=%s", tst_inject->index , tst_inject->string);
41 nvram_mon_reg_notify(tst_inject->index, 1, 1);
42 }
43 else if (strncmp((kal_char*) tst_inject->string, "dereg", 5) == 0 || strncmp((kal_char*) tst_inject->string, "DEREG", 5) == 0 )
44 {
45 kal_prompt_trace(MOD_NVTEST, "Test Dereg NVRAM Monitor, index=%d, inject string=%s", tst_inject->index , tst_inject->string);
46 nvram_mon_dereg_notify(tst_inject->index, 1, 1);
47 }
48 }
49 }
50}
51
52void nvtest_task_main(task_entry_struct *task_entry_ptr)
53{
54 ilm_struct current_ilm;
55 kal_set_active_module_id(MOD_NVTEST);
56
57 while(1) {
58 msg_receive_extq(&current_ilm);
59 nvtest_main(&current_ilm);
60 destroy_ilm(&current_ilm);
61 }
62}
63
64void nvram_mon_reg_notify(nvram_lid_enum lid, kal_uint16 rec_idx, kal_uint16 rec_amt)
65{
66 nvram_read_req_struct *read_req = (nvram_read_req_struct *)construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
67
68 read_req->file_idx = lid;
69 read_req->para = rec_idx;
70 read_req->rec_amount = rec_amt;
71
72 msg_send5(MOD_NVTEST, MOD_NVRAM, NVTEST_SAP, MSG_ID_NVRAM_REG_NOTIFY_REQ, (local_para_struct *)read_req);
73}
74
75void nvram_mon_dereg_notify(nvram_lid_enum lid, kal_uint16 rec_idx, kal_uint16 rec_amt)
76{
77 nvram_read_req_struct *read_req = (nvram_read_req_struct *)construct_local_para(sizeof(nvram_read_req_struct), TD_CTRL);
78
79 read_req->file_idx = lid;
80 read_req->para = rec_idx;
81 read_req->rec_amount = rec_amt;
82
83 msg_send5(MOD_NVTEST, MOD_NVRAM, NVTEST_SAP, MSG_ID_NVRAM_DEREG_NOTIFY_REQ, (local_para_struct *)read_req);
84}
85
86
87kal_bool nvtest_init(void)
88{
89 nvram_mon_reg_notify(NVRAM_EF_CB_CH_INFO_LID, 1, 1);
90 return KAL_TRUE;
91}
92
93kal_bool nvtest_reset(void)
94{
95 return KAL_TRUE;
96}
97
98kal_bool nvtest_create(comptask_handler_struct **handle)
99{
100 static const comptask_handler_struct nvram_handler_info =
101 {
102 nvtest_task_main, /* task entry function */
103 nvtest_init, /* task initialization function */
104 nvtest_reset /* task reset handler */
105 };
106
107 *handle = (comptask_handler_struct*) & nvram_handler_info;
108 return KAL_TRUE;
109}
110