log_output_syst.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
  1. /*
  2. * Copyright (c) 2019 Intel corporation
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <init.h>
  7. #include <stdio.h>
  8. #include <ctype.h>
  9. #include <kernel.h>
  10. #include <mipi_syst.h>
  11. #include <sys/__assert.h>
  12. #include <logging/log.h>
  13. #include <logging/log_ctrl.h>
  14. #include <logging/log_output.h>
  15. static struct mipi_syst_header log_syst_header;
  16. static struct mipi_syst_handle log_syst_handle;
  17. #if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA)
  18. #if defined(CONFIG_MIPI_SYST_STP)
  19. static mipi_syst_u16 master = 128;
  20. static mipi_syst_u16 channel = 1;
  21. static struct stp_writer_data writer_state;
  22. #elif !defined(CONFIG_MIPI_SYST_RAW_DATA)
  23. static const char pattern[] = "SYS-T RAW DATA: ";
  24. static const char valToHex[] = "0123456789ABCDEF";
  25. #endif
  26. static int out_func(int c, void *ctx)
  27. {
  28. const struct log_output *out_ctx = (const struct log_output *)ctx;
  29. out_ctx->buf[out_ctx->control_block->offset] = (uint8_t)c;
  30. out_ctx->control_block->offset++;
  31. __ASSERT_NO_MSG(out_ctx->control_block->offset <= out_ctx->size);
  32. if (out_ctx->control_block->offset == out_ctx->size) {
  33. log_output_flush(out_ctx);
  34. }
  35. return 0;
  36. }
  37. #if defined(CONFIG_MIPI_SYST_STP)
  38. static void stp_write_putNibble(struct mipi_syst_handle *systh,
  39. struct stp_writer_data *p, mipi_syst_u8 n)
  40. {
  41. p->current |= (n << 4);
  42. p->byteDone = !p->byteDone;
  43. if (p->byteDone) {
  44. out_func(p->current, systh->systh_platform.log_output);
  45. p->current = 0;
  46. } else {
  47. p->current >>= 4;
  48. }
  49. }
  50. static void stp_write_flush(struct mipi_syst_handle *systh,
  51. struct stp_writer_data *p)
  52. {
  53. if (!p->byteDone) {
  54. stp_write_putNibble(systh, p, 0);
  55. }
  56. }
  57. static void stp_write_d4(struct mipi_syst_handle *systh,
  58. struct stp_writer_data *p, mipi_syst_u8 v)
  59. {
  60. stp_write_putNibble(systh, p, v);
  61. }
  62. static void stp_write_payload8(struct mipi_syst_handle *systh,
  63. struct stp_writer_data *p, mipi_syst_u8 v)
  64. {
  65. stp_write_d4(systh, p, v);
  66. stp_write_d4(systh, p, v>>4);
  67. }
  68. static void stp_write_payload16(struct mipi_syst_handle *systh,
  69. struct stp_writer_data *p, mipi_syst_u16 v)
  70. {
  71. stp_write_payload8(systh, p, (mipi_syst_u8)v);
  72. stp_write_payload8(systh, p, (mipi_syst_u8)(v>>8));
  73. }
  74. static void stp_write_payload32(struct mipi_syst_handle *systh,
  75. struct stp_writer_data *p, mipi_syst_u32 v)
  76. {
  77. stp_write_payload16(systh, p, (mipi_syst_u16)v);
  78. stp_write_payload16(systh, p, (mipi_syst_u16)(v>>16));
  79. }
  80. static void stp_write_payload64(struct mipi_syst_handle *systh,
  81. struct stp_writer_data *p, mipi_syst_u64 v)
  82. {
  83. stp_write_payload32(systh, p, (mipi_syst_u32)v);
  84. stp_write_payload32(systh, p, (mipi_syst_u32)(v>>32));
  85. }
  86. static mipi_syst_u64 deltaTime(struct stp_writer_data *p)
  87. {
  88. mipi_syst_u64 delta;
  89. delta = mipi_syst_get_epoch() - p->timestamp;
  90. return delta * 60;
  91. }
  92. static void stp_write_d32mts(struct mipi_syst_handle *systh,
  93. struct stp_writer_data *p, mipi_syst_u32 v)
  94. {
  95. stp_write_d4(systh, p, 0xA);
  96. stp_write_payload32(systh, p, v);
  97. stp_write_d4(systh, p, 0xE);
  98. stp_write_payload64(systh, p, deltaTime(p));
  99. }
  100. static void stp_write_d64mts(struct mipi_syst_handle *systh,
  101. struct stp_writer_data *p, mipi_syst_u64 v)
  102. {
  103. stp_write_d4(systh, p, 0xB);
  104. stp_write_payload64(systh, p, v);
  105. stp_write_d4(systh, p, 0xE);
  106. stp_write_payload64(systh, p, deltaTime(p));
  107. }
  108. static void stp_write_d32ts(struct mipi_syst_handle *systh,
  109. struct stp_writer_data *p, mipi_syst_u32 v)
  110. {
  111. stp_write_d4(systh, p, 0xF);
  112. stp_write_d4(systh, p, 0x6);
  113. stp_write_payload32(systh, p, v);
  114. stp_write_d4(systh, p, 0xE);
  115. stp_write_payload64(systh, p, deltaTime(p));
  116. }
  117. static void stp_write_d8(struct mipi_syst_handle *systh,
  118. struct stp_writer_data *p, mipi_syst_u8 v)
  119. {
  120. stp_write_d4(systh, p, 0x4);
  121. stp_write_payload8(systh, p, v);
  122. }
  123. static void stp_write_d16(struct mipi_syst_handle *systh,
  124. struct stp_writer_data *p, mipi_syst_u16 v)
  125. {
  126. stp_write_d4(systh, p, 0x5);
  127. stp_write_payload16(systh, p, v);
  128. }
  129. static void stp_write_d32(struct mipi_syst_handle *systh,
  130. struct stp_writer_data *p, mipi_syst_u32 v)
  131. {
  132. stp_write_d4(systh, p, 0x6);
  133. stp_write_payload32(systh, p, v);
  134. }
  135. #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO)
  136. static void stp_write_d64(struct mipi_syst_handle *systh,
  137. struct stp_writer_data *p, mipi_syst_u64 v)
  138. {
  139. stp_write_d4(systh, p, 0x7);
  140. stp_write_payload64(systh, p, v);
  141. }
  142. #endif
  143. static void stp_write_flag(struct mipi_syst_handle *systh,
  144. struct stp_writer_data *p)
  145. {
  146. stp_write_d4(systh, p, 0xF);
  147. stp_write_d4(systh, p, 0xE);
  148. }
  149. static void stp_write_async(struct mipi_syst_handle *systh,
  150. struct stp_writer_data *p)
  151. {
  152. for (int i = 0; i < 21; ++i) {
  153. stp_write_d4(systh, p, 0xF);
  154. }
  155. stp_write_d4(systh, p, 0x0);
  156. }
  157. static void stp_write_version(struct mipi_syst_handle *systh,
  158. struct stp_writer_data *p)
  159. {
  160. stp_write_d4(systh, p, 0xF);
  161. stp_write_d4(systh, p, 0x0);
  162. stp_write_d4(systh, p, 0x0);
  163. stp_write_d4(systh, p, 0x3);
  164. p->master = 0;
  165. p->channel = 0;
  166. }
  167. static void stp_write_freq(struct mipi_syst_handle *systh,
  168. struct stp_writer_data *p)
  169. {
  170. stp_write_d4(systh, p, 0xF);
  171. stp_write_d4(systh, p, 0x0);
  172. stp_write_d4(systh, p, 0x8);
  173. stp_write_payload32(systh, p, 60 * 1000 * 1000);
  174. }
  175. static void stp_write_setMC(struct mipi_syst_handle *systh,
  176. struct stp_writer_data *p,
  177. mipi_syst_u16 master,
  178. mipi_syst_u16 channel)
  179. {
  180. if (!(p->recordCount++ % 20)) {
  181. stp_write_async(systh, p);
  182. stp_write_version(systh, p);
  183. stp_write_freq(systh, p);
  184. }
  185. if (p->master != master) {
  186. stp_write_d4(systh, p, 0xF);
  187. stp_write_d4(systh, p, 0x1);
  188. stp_write_payload16(systh, p, master);
  189. p->master = master;
  190. p->channel = 0;
  191. }
  192. if (p->channel != channel) {
  193. stp_write_d4(systh, p, 0xF);
  194. stp_write_d4(systh, p, 0x3);
  195. stp_write_payload16(systh, p, channel);
  196. p->channel = channel;
  197. }
  198. }
  199. #else
  200. static void write_raw(struct mipi_syst_handle *systh, const void *p, int n)
  201. {
  202. int i;
  203. uint8_t c;
  204. #if defined(MIPI_SYST_BIG_ENDIAN)
  205. for (i = n - 1; i >= 0; --i) {
  206. #else
  207. for (i = 0; i < n; ++i) {
  208. #endif
  209. c = ((const uint8_t *)p)[i];
  210. #if defined(CONFIG_MIPI_SYST_RAW_DATA)
  211. out_func(c, systh->systh_platform.log_output);
  212. #else
  213. out_func(valToHex[c >> 0x4], systh->systh_platform.log_output);
  214. out_func(valToHex[c & 0xF], systh->systh_platform.log_output);
  215. #endif
  216. }
  217. }
  218. #endif
  219. static void write_d8(struct mipi_syst_handle *systh, uint8_t v)
  220. {
  221. #if defined(CONFIG_MIPI_SYST_STP)
  222. struct stp_writer_data *writer =
  223. systh->systh_header->systh_platform.stpWriter;
  224. stp_write_d8(systh, writer, v);
  225. #else
  226. write_raw(systh, &v, sizeof(v));
  227. #endif
  228. }
  229. static void write_d16(struct mipi_syst_handle *systh, uint16_t v)
  230. {
  231. #if defined(CONFIG_MIPI_SYST_STP)
  232. struct stp_writer_data *writer =
  233. systh->systh_header->systh_platform.stpWriter;
  234. stp_write_d16(systh, writer, v);
  235. #else
  236. write_raw(systh, &v, sizeof(v));
  237. #endif
  238. }
  239. static void write_d32(struct mipi_syst_handle *systh, uint32_t v)
  240. {
  241. #if defined(CONFIG_MIPI_SYST_STP)
  242. struct stp_writer_data *writer =
  243. systh->systh_header->systh_platform.stpWriter;
  244. stp_write_d32(systh, writer, v);
  245. #else
  246. write_raw(systh, &v, sizeof(v));
  247. #endif
  248. }
  249. #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO)
  250. static void write_d64(struct mipi_syst_handle *systh, uint64_t v)
  251. {
  252. #if defined(CONFIG_MIPI_SYST_STP)
  253. struct stp_writer_data *writer =
  254. systh->systh_header->systh_platform.stpWriter;
  255. stp_write_d64(systh, writer, v);
  256. #else
  257. write_raw(systh, &v, sizeof(v));
  258. #endif
  259. }
  260. #endif
  261. static void write_d32ts(struct mipi_syst_handle *systh, uint32_t v)
  262. {
  263. #if defined(CONFIG_MIPI_SYST_STP)
  264. struct stp_writer_data *writer =
  265. systh->systh_header->systh_platform.stpWriter;
  266. stp_write_setMC(systh, writer,
  267. systh->systh_platform.master,
  268. systh->systh_platform.channel);
  269. stp_write_d32ts(systh, writer, v);
  270. #elif defined(CONFIG_MIPI_SYST_RAW_DATA)
  271. ARG_UNUSED(systh);
  272. write_raw(systh, &v, sizeof(v));
  273. #else
  274. for (int i = 0; i < strlen(pattern); i++) {
  275. out_func(pattern[i], systh->systh_platform.log_output);
  276. }
  277. write_raw(systh, &v, sizeof(v));
  278. #endif
  279. }
  280. static void write_d32mts(struct mipi_syst_handle *systh, mipi_syst_u32 v)
  281. {
  282. #if defined(CONFIG_MIPI_SYST_STP)
  283. struct stp_writer_data *writer =
  284. systh->systh_header->systh_platform.stpWriter;
  285. stp_write_setMC(systh, writer,
  286. systh->systh_platform.master,
  287. systh->systh_platform.channel);
  288. stp_write_d32mts(systh, writer, v);
  289. #else
  290. ARG_UNUSED(systh);
  291. ARG_UNUSED(v);
  292. #endif
  293. }
  294. static void write_d64mts(struct mipi_syst_handle *systh, mipi_syst_u64 v)
  295. {
  296. #if defined(CONFIG_MIPI_SYST_STP)
  297. struct stp_writer_data *writer =
  298. systh->systh_header->systh_platform.stpWriter;
  299. stp_write_setMC(systh, writer,
  300. systh->systh_platform.master,
  301. systh->systh_platform.channel);
  302. stp_write_d64mts(systh, writer, v);
  303. #else
  304. ARG_UNUSED(systh);
  305. ARG_UNUSED(v);
  306. #endif
  307. }
  308. static void write_flag(struct mipi_syst_handle *systh)
  309. {
  310. #if defined(CONFIG_MIPI_SYST_STP)
  311. struct stp_writer_data *writer =
  312. systh->systh_header->systh_platform.stpWriter;
  313. stp_write_flag(systh, writer);
  314. stp_write_flush(systh, writer);
  315. #elif defined(CONFIG_MIPI_SYST_RAW_DATA)
  316. ARG_UNUSED(systh);
  317. #else
  318. uint32_t flag = systh->systh_platform.flag;
  319. if ((flag & LOG_OUTPUT_FLAG_CRLF_NONE) != 0U) {
  320. return;
  321. }
  322. if ((flag & LOG_OUTPUT_FLAG_CRLF_LFONLY) != 0U) {
  323. out_func('\n', systh->systh_platform.log_output);
  324. } else {
  325. out_func('\r', systh->systh_platform.log_output);
  326. out_func('\n', systh->systh_platform.log_output);
  327. }
  328. #endif
  329. }
  330. #endif
  331. #if defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP)
  332. mipi_syst_u64 mipi_syst_get_epoch(void)
  333. {
  334. return k_uptime_ticks();
  335. }
  336. #endif
  337. static void update_systh_platform_data(struct mipi_syst_handle *handle,
  338. const struct log_output *log_output,
  339. uint32_t flag)
  340. {
  341. #if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA)
  342. handle->systh_platform.flag = (mipi_syst_u32)flag;
  343. handle->systh_platform.log_output = (struct log_output *)log_output;
  344. #endif
  345. }
  346. #if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA)
  347. /*
  348. * Platform specific SyS-T handle initialization hook function
  349. *
  350. * @param systh pointer to the SyS-T handle structure
  351. */
  352. static void platform_handle_init(struct mipi_syst_handle *systh)
  353. {
  354. #if defined(CONFIG_MIPI_SYST_STP)
  355. if (channel > 127) {
  356. ++master;
  357. channel = 1;
  358. }
  359. systh->systh_platform.channel = channel++;
  360. systh->systh_platform.master = master;
  361. #endif
  362. #if defined(MIPI_SYST_PCFG_LENGTH_FIELD)
  363. MIPI_SYST_ENABLE_HANDLE_LENGTH(systh, 1);
  364. #endif
  365. #if defined(MIPI_SYST_PCFG_ENABLE_TIMESTAMP)
  366. MIPI_SYST_ENABLE_HANDLE_TIMESTAMP(systh, 1);
  367. #endif
  368. }
  369. static void platform_handle_release(struct mipi_syst_handle *systh)
  370. {
  371. ARG_UNUSED(systh);
  372. }
  373. #endif
  374. /*
  375. * Platform specific global state initialization hook function
  376. *
  377. * @param systh pointer to the new SyS-T handle structure
  378. * @param platform_data user defined data for the init function.
  379. *
  380. */
  381. static void mipi_syst_platform_init(struct mipi_syst_header *systh,
  382. const void *platform_data)
  383. {
  384. #if defined(CONFIG_MIPI_SYST_STP)
  385. writer_state.byteDone = 0;
  386. writer_state.current = 0;
  387. writer_state.master = 0;
  388. writer_state.channel = 0;
  389. writer_state.recordCount = 0;
  390. writer_state.timestamp = mipi_syst_get_epoch();
  391. systh->systh_platform.stpWriter = &writer_state;
  392. #endif
  393. #if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_HANDLE_DATA)
  394. systh->systh_inith = platform_handle_init;
  395. systh->systh_releaseh = platform_handle_release;
  396. #endif
  397. #if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA)
  398. systh->systh_platform.write_d8 = write_d8;
  399. systh->systh_platform.write_d16 = write_d16;
  400. systh->systh_platform.write_d32 = write_d32;
  401. #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_IO)
  402. systh->systh_platform.write_d64 = write_d64;
  403. #endif
  404. systh->systh_platform.write_d32ts = write_d32ts;
  405. systh->systh_platform.write_d32mts = write_d32mts;
  406. systh->systh_platform.write_d64mts = write_d64mts;
  407. systh->systh_platform.write_flag = write_flag;
  408. #endif
  409. }
  410. /*
  411. * 0 MIPI_SYST_SEVERITY_MAX no assigned severity
  412. * 1 MIPI_SYST_SEVERITY_FATAL critical error level
  413. * 2 MIPI_SYST_SEVERITY_ERROR error message level
  414. * 3 MIPI_SYST_SEVERITY_WARNING warning message level
  415. * 4 MIPI_SYST_SEVERITY_INFO information message level
  416. * 5 MIPI_SYST_SEVERITY_USER1 user defined level 5
  417. * 6 MIPI_SYST_SEVERITY_USER2 user defined level 6
  418. * 7 MIPI_SYST_SEVERITY_DEBUG debug information level
  419. */
  420. static uint32_t level_to_syst_severity(uint32_t level)
  421. {
  422. uint32_t ret;
  423. switch (level) {
  424. case LOG_LEVEL_NONE:
  425. ret = 0U;
  426. break;
  427. case LOG_LEVEL_ERR:
  428. ret = 2U;
  429. break;
  430. case LOG_LEVEL_WRN:
  431. ret = 3U;
  432. break;
  433. case LOG_LEVEL_INF:
  434. ret = 4U;
  435. break;
  436. case LOG_LEVEL_DBG:
  437. ret = 7U;
  438. break;
  439. default:
  440. ret = 7U;
  441. break;
  442. }
  443. return ret;
  444. }
  445. static void std_print(struct log_msg *msg,
  446. const struct log_output *log_output)
  447. {
  448. const char *str = log_msg_str_get(msg);
  449. uint32_t nargs = log_msg_nargs_get(msg);
  450. uint32_t *args = alloca(sizeof(uint32_t)*nargs);
  451. uint32_t severity = level_to_syst_severity(log_msg_level_get(msg));
  452. for (int i = 0; i < nargs; i++) {
  453. args[i] = log_msg_arg_get(msg, i);
  454. }
  455. switch (log_msg_nargs_get(msg)) {
  456. case 0:
  457. MIPI_SYST_PRINTF(&log_syst_handle, severity, str);
  458. break;
  459. case 1:
  460. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0]);
  461. break;
  462. case 2:
  463. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  464. args[1]);
  465. break;
  466. case 3:
  467. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  468. args[1], args[2]);
  469. break;
  470. case 4:
  471. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  472. args[1], args[2], args[3]);
  473. break;
  474. case 5:
  475. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  476. args[1], args[2], args[3], args[4]);
  477. break;
  478. case 6:
  479. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  480. args[1], args[2], args[3], args[4], args[5]);
  481. break;
  482. case 7:
  483. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  484. args[1], args[2], args[3], args[4], args[5],
  485. args[6]);
  486. break;
  487. case 8:
  488. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  489. args[1], args[2], args[3], args[4], args[5],
  490. args[6], args[7]);
  491. break;
  492. case 9:
  493. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  494. args[1], args[2], args[3], args[4], args[5],
  495. args[6], args[7], args[8]);
  496. break;
  497. case 10:
  498. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  499. args[1], args[2], args[3], args[4], args[5],
  500. args[6], args[7], args[8], args[9]);
  501. break;
  502. case 11:
  503. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  504. args[1], args[2], args[3], args[4], args[5],
  505. args[6], args[7], args[8], args[9], args[10]);
  506. break;
  507. case 12:
  508. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  509. args[1], args[2], args[3], args[4], args[5],
  510. args[6], args[7], args[8], args[9], args[10],
  511. args[11]);
  512. break;
  513. case 13:
  514. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  515. args[1], args[2], args[3], args[4], args[5],
  516. args[6], args[7], args[8], args[9], args[10],
  517. args[11], args[12]);
  518. break;
  519. case 14:
  520. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  521. args[1], args[2], args[3], args[4], args[5],
  522. args[6], args[7], args[8], args[9], args[10],
  523. args[11], args[12], args[13]);
  524. break;
  525. case 15:
  526. MIPI_SYST_PRINTF(&log_syst_handle, severity, str, args[0],
  527. args[1], args[2], args[3], args[4], args[5],
  528. args[6], args[7], args[8], args[9], args[10],
  529. args[11], args[12], args[13], args[14]);
  530. break;
  531. default:
  532. /* Unsupported number of arguments. */
  533. __ASSERT_NO_MSG(true);
  534. break;
  535. }
  536. }
  537. static void raw_string_print(struct log_msg *msg,
  538. const struct log_output *log_output)
  539. {
  540. char buf[CONFIG_LOG_STRDUP_MAX_STRING + 1];
  541. size_t length = CONFIG_LOG_STRDUP_MAX_STRING;
  542. uint32_t severity = level_to_syst_severity(log_msg_level_get(msg));
  543. log_msg_hexdump_data_get(msg, buf, &length, 0);
  544. buf[length] = '\0';
  545. MIPI_SYST_PRINTF(&log_syst_handle, severity, buf);
  546. }
  547. static void hexdump_print(struct log_msg *msg,
  548. const struct log_output *log_output)
  549. {
  550. char buf[CONFIG_LOG_STRDUP_MAX_STRING + 1];
  551. size_t length = CONFIG_LOG_STRDUP_MAX_STRING;
  552. uint32_t severity = level_to_syst_severity(log_msg_level_get(msg));
  553. log_msg_hexdump_data_get(msg, buf, &length, 0);
  554. MIPI_SYST_WRITE(&log_syst_handle, severity, 0x1A, buf, length);
  555. }
  556. void log_output_msg_syst_process(const struct log_output *log_output,
  557. struct log_msg *msg, uint32_t flag)
  558. {
  559. uint8_t level = (uint8_t)log_msg_level_get(msg);
  560. bool raw_string = (level == LOG_LEVEL_INTERNAL_RAW_STRING);
  561. update_systh_platform_data(&log_syst_handle, log_output, flag);
  562. if (log_msg_is_std(msg)) {
  563. std_print(msg, log_output);
  564. } else if (raw_string) {
  565. raw_string_print(msg, log_output);
  566. } else {
  567. hexdump_print(msg, log_output);
  568. }
  569. }
  570. void log_output_string_syst_process(const struct log_output *log_output,
  571. struct log_msg_ids src_level,
  572. const char *fmt, va_list ap, uint32_t flag)
  573. {
  574. uint8_t str[CONFIG_LOG_STRDUP_MAX_STRING];
  575. size_t length = CONFIG_LOG_STRDUP_MAX_STRING;
  576. uint32_t severity = level_to_syst_severity((uint32_t)src_level.level);
  577. length = vsnprintk(str, length, fmt, ap);
  578. str[length] = '\0';
  579. update_systh_platform_data(&log_syst_handle, log_output, flag);
  580. MIPI_SYST_PRINTF(&log_syst_handle, severity, str);
  581. }
  582. void log_output_hexdump_syst_process(const struct log_output *log_output,
  583. struct log_msg_ids src_level,
  584. const uint8_t *data, uint32_t length, uint32_t flag)
  585. {
  586. uint32_t severity = level_to_syst_severity((uint32_t)src_level.level);
  587. update_systh_platform_data(&log_syst_handle, log_output, flag);
  588. MIPI_SYST_WRITE(&log_syst_handle, severity, 0x1A, data, length);
  589. }
  590. static int syst_init(const struct device *arg)
  591. {
  592. ARG_UNUSED(arg);
  593. MIPI_SYST_INIT_STATE(&log_syst_header,
  594. mipi_syst_platform_init, (void *)0);
  595. MIPI_SYST_INIT_HANDLE_STATE(&log_syst_header,
  596. &log_syst_handle, NULL);
  597. return 0;
  598. }
  599. SYS_INIT(syst_init, POST_KERNEL, 0);