huangcm
2025-07-01 676035278781360996553c427a12bf358249ebf7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
*********************************************************************************************************
*                                                AR100 SYSTEM
*                                     AR100 Software System Develop Kits
*                                                daemon module
*
*                                    (c) Copyright 2012-2016, Sunny China
*                                             All Rights Reserved
*
* File    : daemon.c
* By      : Sunny
* Version : v1.0
* Date    : 2012-5-13
* Descript: daemon module.
* Update  : date                auther      ver     notes
*           2012-5-13 15:06:10  Sunny       1.0     Create this file.
*********************************************************************************************************
*/
 
#include "daemon_i.h"
 
/* system daemon vars */
extern u32 debug_level;
 
/* the list of daemon notifier */
static struct notifier *daemon_list;
 
int daemon_register_service(__pNotifier_t pcb)
{
   return notifier_insert(&daemon_list, pcb);
}
 
static s32 startup_state_notify(s32 result)
{
   struct message message;
   u32 arisc_version[13] = {0};
   s32 ret;
 
   LOG("feedback startup result [%d]\n", result);
 
   save_state_flag(REC_HOTPULG | 0xd);
 
   /* initialize message */
   message.type = AR100_STARTUP_NOTIFY;
   message.attr = MESSAGE_ATTR_HARDSYN;
   message.result = result;
   message.count = sizeof(arisc_version) / sizeof(u32);
   message.paras = arisc_version;
 
   /* check the length of SUB_VER */
   if (sizeof(SUB_VER) > sizeof(arisc_version)) {
       ERR("SUB_VER %d is bigger than arisc_version %d\n",
               sizeof(SUB_VER), sizeof(arisc_version));
 
       while(1)
           ;
   }
 
   strcpy((char *)(arisc_version), SUB_VER);
 
   ret = hwmsgbox_send_message(&message, SEND_MSG_TIMEOUT);
   if (ret == OK)
       LOG("send notify succeed\n");
   else
       LOG("send notify failed\n");
 
   save_state_flag(REC_HOTPULG | 0xe);
 
   return OK;
}
 
/*
 * NOTE:
 * this function is not reentrant and only can be used in process context,
 * and msg_paras define as static variable to save stack.
 */
static void message_process_loop(void)
{
   s32 ret;
   struct message message;
   static u32 msg_paras[32];
 
   message.paras = msg_paras;
 
   ret = hwmsgbox_query_message(&message, 0);
   if (ret == OK)
       message_coming_notify(&message);
}
 
static void daemon_main(void)
{
   /* initialize cpu */
   cpu_init();
 
   /* daemon & message & user defined task loop process */
   LOG("daemon service setup...\n");
   while (1) {
       /* message loop process */
       message_process_loop();
 
       /* daemon list process */
       if (((current_time_tick()) % DAEMON_ONCE_TICKS) == 0) {
           /* daemon run one time */
           printk("------------------------------\n");
           LOG("system tick:%d\n", DAEMON_ONCE_TICKS);
           LOG("debug_mask:%d\n", debug_level);
           LOG("uart_buadrate:%d\n", uart_get_baudrate());
           notifier_notify(&daemon_list, DAEMON_RUN_NOTIFY, 0);
       }
 
       /*
        * maybe add user defined task process here
        * refer to daemon list process
        */
   }
}
 
/*
*********************************************************************************************************
*                                       STARTUP ENTRY
*
* Description:  the entry of startup.
*
* Arguments  :  none.
*
* Returns    :  none.
*********************************************************************************************************
*/
void startup_entry(void)
{
   notifier_init();
   save_state_flag(REC_HOTPULG | 0x0);
 
   ccu_init();
   save_state_flag(REC_HOTPULG | 0x1);
 
   pin_init();
   save_state_flag(REC_HOTPULG | 0x2);
 
   save_state_flag(REC_HOTPULG | 0x3);
 
   interrupt_init();
   save_state_flag(REC_HOTPULG | 0x4);
 
   arisc_para_init();
   save_state_flag(REC_HOTPULG | 0x5);
 
   debugger_init();
   save_state_flag(REC_HOTPULG | 0x6);
   LOG("debugger system ok\n");
 
   twi_init();
   LOG("twi driver ok\n");
   save_state_flag(REC_HOTPULG | 0x7);
 
#if CPUS_JTAG_DEBUG_EN
   /* config ar100 jtag pins */
   pin_set_multi_sel(PIN_GRP_PL, 8, 3);
   pin_set_pull     (PIN_GRP_PL, 8, PIN_PULL_UP);
   pin_set_drive    (PIN_GRP_PL, 8, PIN_MULTI_DRIVE_2);
   pin_set_multi_sel(PIN_GRP_PL, 7, 3);
   pin_set_pull     (PIN_GRP_PL, 7, PIN_PULL_UP);
   pin_set_drive    (PIN_GRP_PL, 7, PIN_MULTI_DRIVE_2);
   pin_set_multi_sel(PIN_GRP_PL, 6, 3);
   pin_set_pull     (PIN_GRP_PL, 6, PIN_PULL_UP);
   pin_set_drive    (PIN_GRP_PL, 6, PIN_MULTI_DRIVE_2);
   pin_set_multi_sel(PIN_GRP_PL, 5, 3);
   pin_set_pull     (PIN_GRP_PL, 5, PIN_PULL_UP);
   pin_set_drive    (PIN_GRP_PL, 5, PIN_MULTI_DRIVE_2);
#endif
 
   pmu_init();
   save_state_flag(REC_HOTPULG | 0x8);
   LOG("pmu driver ok\n");
 
   hwmsgbox_init();
   save_state_flag(REC_HOTPULG | 0x9);
   LOG("hwmsgbox driver ok\n");
 
   cpucfg_init();
   save_state_flag(REC_HOTPULG | 0xa);
   LOG("cpucfg driver ok\n");
 
   message_manager_init();
   LOG("message manager ok\n");
 
   timer_init();
   LOG("timer driver ok\n");
 
   standby_init();
   LOG("standby service ok\n");
 
   time_ticks_init();
   LOG("time ticks ok\n");
 
   watchdog_init();
   save_state_flag(REC_HOTPULG | 0xc);
   LOG("watchdog ok\n");
 
   /* feedback the startup state to ac327 */
   startup_state_notify(OK);
   set_paras();
   save_state_flag(REC_HOTPULG | 0xf);
   LOG("startup feedback ok\n");
 
   LOG("ar100 firmware version : %s\n", SUB_VER);
 
   /* enter daemon process main. */
   daemon_main();
 
   /* to avoid daemon main return. */
   ERR("system daemon exit\n");
   while (1)
       ;
}