C2A_Core
app_manager.c
[詳解]
1 #pragma section REPRO
2 #include "app_manager.h"
4 
5 #include <string.h> // for memcpy
6 
7 #include "../../Applications/nop.h"
8 #include "../EventManager/event_logger.h"
9 #include "../TimeManager/time_manager.h"
10 #include "../WatchdogTimer/watchdog_timer.h"
12 #include "../../Library/print.h" // for Printf
13 #include "../../Library/endian.h"
14 #include "../../TlmCmd/common_cmd_packet_util.h"
15 
16 static AM_ACK AM_initialize_app_(size_t id);
17 static AM_ACK AM_execute_app_(size_t id);
18 
21 
22 void AM_initialize(void)
23 {
24  int i;
25 
26  for (i = 0; i < AM_MAX_APPS; ++i)
27  {
29  }
30 
31  // テレメトリページ番号を0に初期化。
33 }
34 
36  const AppInfo* ai)
37 {
38  if (id >= AM_MAX_APPS)
39  {
41  return AM_INVALID_ID;
42  }
43 
44  app_manager_.ais[id] = *ai;
45  return AM_SUCCESS;
46 }
47 
49 {
50  size_t i;
51 
52  for (i = 0; i < AM_MAX_APPS; ++i)
53  {
55  }
56 }
57 
59 {
60  const uint8_t* param = CCP_get_param_head(packet);
61  size_t id;
62  AppInfo ai;
63 
64  // パラメータを読み出し。
65  ENDIAN_memcpy(&id, param, 4);
66  ENDIAN_memcpy(&ai.initializer, param + 4, 4);
67  ENDIAN_memcpy(&ai.entry_point, param + 8, 4);
68 
69  ai.name = "SPECIAL";
70  ai.prev = 0;
71  ai.max = 0;
72  ai.min = 0xffffffff;
73 
74  switch (AM_register_ai(id, &ai))
75  {
76  case AM_SUCCESS:
78  case AM_INVALID_ID:
80  default:
82  }
83 }
84 
86 {
87  size_t id = AM_MAX_APPS;
88 
89  // パラメータ読み出し。
90  ENDIAN_memcpy(&id, CCP_get_param_head(packet), 4);
91 
92  switch (AM_initialize_app_(id))
93  {
94  case AM_SUCCESS:
95  case AM_NOT_REGISTERED:
97  case AM_INVALID_ID:
99  default:
101  }
102 }
103 
104 static AM_ACK AM_initialize_app_(size_t id)
105 {
106 #ifndef SILS_FW
107  ObcTime start, finish;
108 #endif
109 
110  if (id >= AM_MAX_APPS)
111  {
113  return AM_INVALID_ID;
114  }
115  else if (app_manager_.ais[id].initializer == NULL)
116  {
117  return AM_NOT_REGISTERED;
118  }
119 
120 #ifdef SILS_FW
122 #else
126 
127  // 処理時間情報アップデート
128  app_manager_.ais[id].init_duration = OBCT_diff_in_step(&start, &finish);
129 #endif
130 
131  WDT_clear_wdt();
132  Printf("App: %s Init Complete !!\n", app_manager_.ais[id].name);
133  return AM_SUCCESS;
134 }
135 
137 {
138  size_t id = AM_MAX_APPS;
139 
140  // パラメータ読み出し。
141  ENDIAN_memcpy(&id, CCP_get_param_head(packet), 4);
142 
143  switch (AM_execute_app_(id))
144  {
145  case AM_SUCCESS:
147  case AM_INVALID_ID:
148  case AM_NOT_REGISTERED:
150  default:
152  }
153 }
154 
155 static AM_ACK AM_execute_app_(size_t id)
156 {
157 #ifndef SILS_FW
158  ObcTime start, finish;
159 #endif
160 
161  if (id >= AM_MAX_APPS)
162  {
164  return AM_INVALID_ID;
165  }
166  else if (app_manager_.ais[id].entry_point == NULL)
167  {
169  return AM_NOT_REGISTERED;
170  }
171 
172 #ifdef SILS_FW
174 #else
175  start = TMGR_get_master_clock();
177  finish = TMGR_get_master_clock();
178 
179  // 処理時間情報アップデート
180  app_manager_.ais[id].prev = OBCT_diff_in_step(&start, &finish);
181 
182  if (app_manager_.ais[id].max < app_manager_.ais[id].prev)
183  {
185  }
186 
187  if (app_manager_.ais[id].min > app_manager_.ais[id].prev)
188  {
190  }
191 
192 #endif
193 
194  return AM_SUCCESS;
195 }
196 
198 {
199  uint8_t page;
200 
201  page = CCP_get_param_head(packet)[0];
202 
203  if (page >= AM_TLM_PAGE_MAX)
204  {
205  // ページ番号がコマンドテーブル範囲外
207  }
208 
209  app_manager_.page_no = page;
211 }
212 
214 {
215  int i;
216  (void)packet;
217 
218  for (i = 0; i < AM_MAX_APPS; ++i)
219  {
220  app_manager_.ais[i].prev = 0;
221  app_manager_.ais[i].max = 0;
222  app_manager_.ais[i].min = 0xffffffff;
223  }
224 
226 }
227 
228 
229 #pragma section
static AM_ACK AM_initialize_app_(size_t id)
Definition: app_manager.c:104
CCP_CmdRet Cmd_AM_INITIALIZE_APP(const CommonCmdPacket *packet)
Definition: app_manager.c:85
const AppManager *const app_manager
Definition: app_manager.c:20
CCP_CmdRet Cmd_AM_EXECUTE_APP(const CommonCmdPacket *packet)
Definition: app_manager.c:136
void AM_initialize_all_apps(void)
Definition: app_manager.c:48
AM_ACK AM_register_ai(size_t id, const AppInfo *ai)
Definition: app_manager.c:35
void AM_initialize(void)
Definition: app_manager.c:22
CCP_CmdRet Cmd_AM_REGISTER_APP(const CommonCmdPacket *packet)
Definition: app_manager.c:58
CCP_CmdRet Cmd_AM_CLEAR_APP_INFO(const CommonCmdPacket *packet)
Definition: app_manager.c:213
static AppManager app_manager_
Definition: app_manager.c:19
static AM_ACK AM_execute_app_(size_t id)
Definition: app_manager.c:155
CCP_CmdRet Cmd_AM_SET_PAGE_FOR_TLM(const CommonCmdPacket *packet)
Definition: app_manager.c:197
AM_ACK
Definition: app_manager.h:22
@ AM_SUCCESS
Definition: app_manager.h:23
@ AM_INVALID_ID
Definition: app_manager.h:24
@ AM_NOT_REGISTERED
Definition: app_manager.h:25
#define AM_MAX_APPS
登録できる最大AppInfo数,これは登録できる最大アプリ数と等しい
Definition: app_manager.h:11
#define AM_TLM_PAGE_MAX
AMのAppInfoテーブルのページ数(ページネーション用)
Definition: app_manager.h:10
コマンド定義
@ CCP_EXEC_SUCCESS
@ CCP_EXEC_ILLEGAL_PARAMETER
コマンド実行時のパラメタエラー
@ CCP_EXEC_ILLEGAL_CONTEXT
コマンド実行時のその他のエラー
const uint8_t * CCP_get_param_head(const CommonCmdPacket *packet)
先頭のパラメタのポインタを取得
CCP_CmdRet CCP_make_cmd_ret_without_err_code(CCP_EXEC_STS exec_sts)
コマンド返り値である CCP_CmdRet を作成(エラーコード不使用版)
void * ENDIAN_memcpy(void *dest, const void *src, size_t size)
エンディアンを考慮した memcpy
Definition: endian.c:11
EL_ACK EL_record_event(EL_GROUP group, uint32_t local, EL_ERROR_LEVEL err_level, uint32_t note)
イベント (EL_Event) を記録
Definition: event_logger.c:269
@ EL_CORE_GROUP_APP_MANAGER
Definition: event_logger.h:210
@ EL_ERROR_LEVEL_LOW
Definition: event_logger.h:266
EL_GROUP
event_logger の Event Group の user 定義部分
AppInfo NOP_create_app(void)
Definition: nop.c:14
step_t OBCT_diff_in_step(const ObcTime *before, const ObcTime *after)
ObcTime の引き算を step 単位で行う
Definition: obc_time.c:146
Switch the build settings between your real OBC and SILS
void Printf(const char *format,...)
Definition: print.c:9
step_t prev
アプリ実行処理時間(直近)
Definition: app_info.h:14
step_t min
アプリ実行処理時間(最小値)
Definition: app_info.h:15
const char * name
アプリ名 (C2A 内部では使用されていない )
Definition: app_info.h:12
void(* entry_point)(void)
アプリ実行関数(エントリーポイント)
Definition: app_info.h:18
step_t max
アプリ実行処理時間(最大値)
Definition: app_info.h:16
step_t init_duration
アプリ初期化処理時間
Definition: app_info.h:13
void(* initializer)(void)
アプリ初期化関数
Definition: app_info.h:17
AppInfo ais[AM_MAX_APPS]
Definition: app_manager.h:17
コマンド返り値
Space Packet (コマンド用)
OBCの時刻情報を保持する構造体
Definition: obc_time.h:18
ObcTime TMGR_get_master_clock(void)
現在の master_clock_ を取得する
Definition: time_manager.c:80
ObcTime TMGR_get_master_clock_from_boot(void)
初期化にかかった時間も加算した master_clock_ を返す
Definition: time_manager.c:92
void WDT_clear_wdt(void)
WDTのクリア