test_trace.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058
  1. #include <stddef.h>
  2. #include <stdint.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdarg.h>
  6. #include "unity.h"
  7. #include "driver/timer.h"
  8. #include "soc/cpu.h"
  9. #include "freertos/FreeRTOS.h"
  10. #include "freertos/semphr.h"
  11. #include "freertos/task.h"
  12. #if CONFIG_ESP32_APPTRACE_ENABLE == 1
  13. #include "esp_app_trace.h"
  14. #include "esp_app_trace_util.h"
  15. #define ESP_APPTRACE_TEST_USE_PRINT_LOCK 0
  16. #define ESP_APPTRACE_TEST_PRN_WRERR_MAX 5
  17. #define ESP_APPTRACE_TEST_BLOCKS_BEFORE_CRASH 100
  18. #define ESP_APPTRACE_TEST_BLOCK_SIZE 1024
  19. #define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE
  20. #include "esp_log.h"
  21. const static char *TAG = "esp_apptrace_test";
  22. #if ESP_APPTRACE_TEST_USE_PRINT_LOCK == 1
  23. #define ESP_APPTRACE_TEST_LOG( format, ... ) \
  24. do { \
  25. BaseType_t ret; \
  26. if (xPortInIsrContext()) \
  27. ret = xSemaphoreTakeFromISR(s_print_lock, NULL); \
  28. else \
  29. ret = xSemaphoreTake(s_print_lock, portMAX_DELAY); \
  30. if (ret == pdTRUE) { \
  31. ets_printf(format, ##__VA_ARGS__); \
  32. if (xPortInIsrContext()) \
  33. xSemaphoreGiveFromISR(s_print_lock, NULL); \
  34. else \
  35. xSemaphoreGive(s_print_lock); \
  36. } \
  37. } while(0)
  38. #else
  39. #define ESP_APPTRACE_TEST_LOG( format, ... ) \
  40. do { \
  41. ets_printf(format, ##__VA_ARGS__); \
  42. } while(0)
  43. #endif
  44. #define ESP_APPTRACE_TEST_LOG_LEVEL( _L_, level, format, ... ) \
  45. do { \
  46. if (LOG_LOCAL_LEVEL >= level) { \
  47. ESP_APPTRACE_TEST_LOG(LOG_FORMAT(_L_, format), esp_log_early_timestamp(), TAG, ##__VA_ARGS__); \
  48. } \
  49. } while(0)
  50. #define ESP_APPTRACE_TEST_LOGE( format, ... ) ESP_APPTRACE_TEST_LOG_LEVEL(E, ESP_LOG_ERROR, format, ##__VA_ARGS__)
  51. #define ESP_APPTRACE_TEST_LOGW( format, ... ) ESP_APPTRACE_TEST_LOG_LEVEL(W, ESP_LOG_WARN, format, ##__VA_ARGS__)
  52. #define ESP_APPTRACE_TEST_LOGI( format, ... ) ESP_APPTRACE_TEST_LOG_LEVEL(I, ESP_LOG_INFO, format, ##__VA_ARGS__)
  53. #define ESP_APPTRACE_TEST_LOGD( format, ... ) ESP_APPTRACE_TEST_LOG_LEVEL(D, ESP_LOG_DEBUG, format, ##__VA_ARGS__)
  54. #define ESP_APPTRACE_TEST_LOGV( format, ... ) ESP_APPTRACE_TEST_LOG_LEVEL(V, ESP_LOG_VERBOSE, format, ##__VA_ARGS__)
  55. #define ESP_APPTRACE_TEST_LOGO( format, ... ) ESP_APPTRACE_TEST_LOG_LEVEL(E, ESP_LOG_NONE, format, ##__VA_ARGS__)
  56. static void esp_apptrace_test_timer_init(int timer_group, int timer_idx, uint32_t period)
  57. {
  58. timer_config_t config;
  59. uint64_t alarm_val = (period * (TIMER_BASE_CLK / 1000000UL)) / 2;
  60. config.alarm_en = 1;
  61. config.auto_reload = 1;
  62. config.counter_dir = TIMER_COUNT_UP;
  63. config.divider = 2; //Range is 2 to 65536
  64. config.intr_type = TIMER_INTR_LEVEL;
  65. config.counter_en = TIMER_PAUSE;
  66. /*Configure timer*/
  67. timer_init(timer_group, timer_idx, &config);
  68. /*Stop timer counter*/
  69. timer_pause(timer_group, timer_idx);
  70. /*Load counter value */
  71. timer_set_counter_value(timer_group, timer_idx, 0x00000000ULL);
  72. /*Set alarm value*/
  73. timer_set_alarm_value(timer_group, timer_idx, alarm_val);
  74. /*Enable timer interrupt*/
  75. timer_enable_intr(timer_group, timer_idx);
  76. }
  77. #if CONFIG_SYSVIEW_ENABLE == 0
  78. #define ESP_APPTRACE_TEST_WRITE(_b_, _s_) esp_apptrace_write(ESP_APPTRACE_DEST_TRAX, _b_, _s_, ESP_APPTRACE_TMO_INFINITE)
  79. #define ESP_APPTRACE_TEST_WRITE_FROM_ISR(_b_, _s_) esp_apptrace_write(ESP_APPTRACE_DEST_TRAX, _b_, _s_, 0UL)
  80. #define ESP_APPTRACE_TEST_WRITE_NOWAIT(_b_, _s_) esp_apptrace_write(ESP_APPTRACE_DEST_TRAX, _b_, _s_, 0)
  81. typedef struct {
  82. uint8_t *buf;
  83. uint32_t buf_sz;
  84. uint8_t mask;
  85. uint32_t period; // trace write period in us
  86. uint32_t wr_err;
  87. uint32_t wr_cnt;
  88. } esp_apptrace_test_gen_data_t;
  89. typedef struct {
  90. int group;
  91. int id;
  92. void (*isr_func)(void *);
  93. esp_apptrace_test_gen_data_t data;
  94. } esp_apptrace_test_timer_arg_t;
  95. typedef struct {
  96. int nowait;
  97. int core;
  98. int prio;
  99. void (*task_func)(void *);
  100. esp_apptrace_test_gen_data_t data;
  101. volatile int stop;
  102. SemaphoreHandle_t done;
  103. uint32_t timers_num;
  104. esp_apptrace_test_timer_arg_t *timers;
  105. } esp_apptrace_test_task_arg_t;
  106. typedef struct {
  107. uint32_t tasks_num;
  108. esp_apptrace_test_task_arg_t *tasks;
  109. } esp_apptrace_test_cfg_t;
  110. #if ESP_APPTRACE_TEST_USE_PRINT_LOCK == 1
  111. static SemaphoreHandle_t s_print_lock;
  112. #endif
  113. static uint64_t esp_apptrace_test_ts_get();
  114. static void esp_apptrace_test_timer_isr(void *arg)
  115. {
  116. esp_apptrace_test_timer_arg_t *tim_arg = (esp_apptrace_test_timer_arg_t *)arg;
  117. uint32_t *ts = (uint32_t *)(tim_arg->data.buf + sizeof(uint32_t));
  118. *ts = (uint32_t)esp_apptrace_test_ts_get();
  119. memset(tim_arg->data.buf + 2 * sizeof(uint32_t), tim_arg->data.wr_cnt & tim_arg->data.mask, tim_arg->data.buf_sz - 2 * sizeof(uint32_t));
  120. int res = ESP_APPTRACE_TEST_WRITE_FROM_ISR(tim_arg->data.buf, tim_arg->data.buf_sz);
  121. if (res != ESP_OK) {
  122. } else {
  123. if (0) {
  124. ets_printf("tim-%d-%d: Written chunk%d %d bytes, %x\n",
  125. tim_arg->group, tim_arg->id, tim_arg->data.wr_cnt, tim_arg->data.buf_sz, tim_arg->data.wr_cnt & tim_arg->data.mask);
  126. }
  127. tim_arg->data.wr_err = 0;
  128. }
  129. tim_arg->data.wr_cnt++;
  130. if (tim_arg->group == 0) {
  131. if (tim_arg->id == 0) {
  132. TIMERG0.int_clr_timers.t0 = 1;
  133. TIMERG0.hw_timer[0].update = 1;
  134. TIMERG0.hw_timer[0].config.alarm_en = 1;
  135. } else {
  136. TIMERG0.int_clr_timers.t1 = 1;
  137. TIMERG0.hw_timer[1].update = 1;
  138. TIMERG0.hw_timer[1].config.alarm_en = 1;
  139. }
  140. }
  141. if (tim_arg->group == 1) {
  142. if (tim_arg->id == 0) {
  143. TIMERG1.int_clr_timers.t0 = 1;
  144. TIMERG1.hw_timer[0].update = 1;
  145. TIMERG1.hw_timer[0].config.alarm_en = 1;
  146. } else {
  147. TIMERG1.int_clr_timers.t1 = 1;
  148. TIMERG1.hw_timer[1].update = 1;
  149. TIMERG1.hw_timer[1].config.alarm_en = 1;
  150. }
  151. }
  152. }
  153. static void esp_apptrace_test_timer_isr_crash(void *arg)
  154. {
  155. esp_apptrace_test_timer_arg_t *tim_arg = (esp_apptrace_test_timer_arg_t *)arg;
  156. if (tim_arg->group == 0) {
  157. if (tim_arg->id == 0) {
  158. TIMERG0.int_clr_timers.t0 = 1;
  159. TIMERG0.hw_timer[0].update = 1;
  160. TIMERG0.hw_timer[0].config.alarm_en = 1;
  161. } else {
  162. TIMERG0.int_clr_timers.t1 = 1;
  163. TIMERG0.hw_timer[1].update = 1;
  164. TIMERG0.hw_timer[1].config.alarm_en = 1;
  165. }
  166. }
  167. if (tim_arg->group == 1) {
  168. if (tim_arg->id == 0) {
  169. TIMERG1.int_clr_timers.t0 = 1;
  170. TIMERG1.hw_timer[0].update = 1;
  171. TIMERG1.hw_timer[0].config.alarm_en = 1;
  172. } else {
  173. TIMERG1.int_clr_timers.t1 = 1;
  174. TIMERG1.hw_timer[1].update = 1;
  175. TIMERG1.hw_timer[1].config.alarm_en = 1;
  176. }
  177. }
  178. if (tim_arg->data.wr_cnt < ESP_APPTRACE_TEST_BLOCKS_BEFORE_CRASH) {
  179. uint32_t *ts = (uint32_t *)(tim_arg->data.buf + sizeof(uint32_t));
  180. *ts = (uint32_t)esp_apptrace_test_ts_get();//xthal_get_ccount();//xTaskGetTickCount();
  181. memset(tim_arg->data.buf + 2 * sizeof(uint32_t), tim_arg->data.wr_cnt & tim_arg->data.mask, tim_arg->data.buf_sz - 2 * sizeof(uint32_t));
  182. int res = ESP_APPTRACE_TEST_WRITE_FROM_ISR(tim_arg->data.buf, tim_arg->data.buf_sz);
  183. if (res != ESP_OK) {
  184. ets_printf("tim-%d-%d: Failed to write trace %d %x!\n", tim_arg->group, tim_arg->id, res, tim_arg->data.wr_cnt & tim_arg->data.mask);
  185. } else {
  186. ets_printf("tim-%d-%d: Written chunk%d %d bytes, %x\n",
  187. tim_arg->group, tim_arg->id, tim_arg->data.wr_cnt, tim_arg->data.buf_sz, tim_arg->data.wr_cnt & tim_arg->data.mask);
  188. tim_arg->data.wr_cnt++;
  189. }
  190. } else {
  191. uint32_t *ptr = 0;
  192. *ptr = 1000;
  193. }
  194. }
  195. static void esp_apptrace_dummy_task(void *p)
  196. {
  197. esp_apptrace_test_task_arg_t *arg = (esp_apptrace_test_task_arg_t *) p;
  198. int res, flags = 0, i;
  199. timer_isr_handle_t *inth = NULL;
  200. TickType_t tmo_ticks = arg->data.period / (1000 * portTICK_PERIOD_MS);
  201. ESP_APPTRACE_TEST_LOGI("%x: run dummy task (period %u us, %u timers)", xTaskGetCurrentTaskHandle(), arg->data.period, arg->timers_num);
  202. if (arg->timers_num > 0) {
  203. inth = pvPortMalloc(arg->timers_num * sizeof(timer_isr_handle_t));
  204. if (!inth) {
  205. ESP_APPTRACE_TEST_LOGE("Failed to alloc timer ISR handles!");
  206. goto on_fail;
  207. }
  208. memset(inth, 0, arg->timers_num * sizeof(timer_isr_handle_t));
  209. for (int i = 0; i < arg->timers_num; i++) {
  210. esp_apptrace_test_timer_init(arg->timers[i].group, arg->timers[i].id, arg->timers[i].data.period);
  211. res = timer_isr_register(arg->timers[i].group, arg->timers[i].id, arg->timers[i].isr_func, &arg->timers[i], flags, &inth[i]);
  212. if (res != ESP_OK) {
  213. ESP_APPTRACE_TEST_LOGE("Failed to timer_isr_register (%d)!", res);
  214. goto on_fail;
  215. }
  216. *(uint32_t *)arg->timers[i].data.buf = (uint32_t)inth[i] | (1 << 31);
  217. ESP_APPTRACE_TEST_LOGI("%x: start timer %x period %u us", xTaskGetCurrentTaskHandle(), inth[i], arg->timers[i].data.period);
  218. res = timer_start(arg->timers[i].group, arg->timers[i].id);
  219. if (res != ESP_OK) {
  220. ESP_APPTRACE_TEST_LOGE("Failed to timer_start (%d)!", res);
  221. goto on_fail;
  222. }
  223. }
  224. }
  225. i = 0;
  226. while (!arg->stop) {
  227. ESP_APPTRACE_TEST_LOGD("%x: dummy task work %d.%d", xTaskGetCurrentTaskHandle(), xPortGetCoreID(), i++);
  228. if (tmo_ticks) {
  229. vTaskDelay(tmo_ticks);
  230. }
  231. }
  232. on_fail:
  233. if (inth) {
  234. for (int i = 0; i < arg->timers_num; i++) {
  235. timer_pause(arg->timers[i].group, arg->timers[i].id);
  236. timer_disable_intr(arg->timers[i].group, arg->timers[i].id);
  237. if (inth[i]) {
  238. esp_intr_free(inth[i]);
  239. }
  240. }
  241. vPortFree(inth);
  242. }
  243. xSemaphoreGive(arg->done);
  244. vTaskDelay(1);
  245. vTaskDelete(NULL);
  246. }
  247. static void esp_apptrace_test_task(void *p)
  248. {
  249. esp_apptrace_test_task_arg_t *arg = (esp_apptrace_test_task_arg_t *) p;
  250. int res, flags = 0;
  251. timer_isr_handle_t *inth = NULL;
  252. TickType_t tmo_ticks = arg->data.period / (1000 * portTICK_PERIOD_MS);
  253. ESP_APPTRACE_TEST_LOGI("%x: run (period %u us, stamp mask %x, %u timers)", xTaskGetCurrentTaskHandle(), arg->data.period, arg->data.mask, arg->timers_num);
  254. if (arg->timers_num > 0) {
  255. inth = pvPortMalloc(arg->timers_num * sizeof(timer_isr_handle_t));
  256. if (!inth) {
  257. ESP_APPTRACE_TEST_LOGE("Failed to alloc timer ISR handles!");
  258. goto on_fail;
  259. }
  260. memset(inth, 0, arg->timers_num * sizeof(timer_isr_handle_t));
  261. for (int i = 0; i < arg->timers_num; i++) {
  262. esp_apptrace_test_timer_init(arg->timers[i].group, arg->timers[i].id, arg->timers[i].data.period);
  263. res = timer_isr_register(arg->timers[i].group, arg->timers[i].id, arg->timers[i].isr_func, &arg->timers[i], flags, &inth[i]);
  264. if (res != ESP_OK) {
  265. ESP_APPTRACE_TEST_LOGE("Failed to timer_isr_register (%d)!", res);
  266. goto on_fail;
  267. }
  268. *(uint32_t *)arg->timers[i].data.buf = ((uint32_t)inth[i]) | (1 << 31) | (xPortGetCoreID() ? 0x1 : 0);
  269. ESP_APPTRACE_TEST_LOGI("%x: start timer %x period %u us", xTaskGetCurrentTaskHandle(), inth[i], arg->timers[i].data.period);
  270. res = timer_start(arg->timers[i].group, arg->timers[i].id);
  271. if (res != ESP_OK) {
  272. ESP_APPTRACE_TEST_LOGE("Failed to timer_start (%d)!", res);
  273. goto on_fail;
  274. }
  275. }
  276. }
  277. *(uint32_t *)arg->data.buf = (uint32_t)xTaskGetCurrentTaskHandle() | (xPortGetCoreID() ? 0x1 : 0);
  278. arg->data.wr_cnt = 0;
  279. arg->data.wr_err = 0;
  280. while (!arg->stop) {
  281. uint32_t *ts = (uint32_t *)(arg->data.buf + sizeof(uint32_t));
  282. *ts = (uint32_t)esp_apptrace_test_ts_get();
  283. memset(arg->data.buf + 2 * sizeof(uint32_t), arg->data.wr_cnt & arg->data.mask, arg->data.buf_sz - 2 * sizeof(uint32_t));
  284. // ESP_APPTRACE_TEST_LOGD("%x:%x: Write chunk%d %d bytes, %x", xTaskGetCurrentTaskHandle(), *ts, arg->data.wr_cnt, arg->data.buf_sz, arg->data.wr_cnt & arg->data.mask);
  285. if (arg->nowait) {
  286. res = ESP_APPTRACE_TEST_WRITE_NOWAIT(arg->data.buf, arg->data.buf_sz);
  287. } else {
  288. res = ESP_APPTRACE_TEST_WRITE(arg->data.buf, arg->data.buf_sz);
  289. }
  290. if (res) {
  291. if (1){//arg->data.wr_err++ < ESP_APPTRACE_TEST_PRN_WRERR_MAX) {
  292. ESP_APPTRACE_TEST_LOGE("%x: Failed to write trace %d %x!", xTaskGetCurrentTaskHandle(), res, arg->data.wr_cnt & arg->data.mask);
  293. if (arg->data.wr_err == ESP_APPTRACE_TEST_PRN_WRERR_MAX) {
  294. ESP_APPTRACE_TEST_LOGE("\n");
  295. }
  296. }
  297. } else {
  298. if (0) {
  299. ESP_APPTRACE_TEST_LOGD("%x:%x: Written chunk%d %d bytes, %x", xTaskGetCurrentTaskHandle(), *ts, arg->data.wr_cnt, arg->data.buf_sz, arg->data.wr_cnt & arg->data.mask);
  300. }
  301. arg->data.wr_err = 0;
  302. }
  303. arg->data.wr_cnt++;
  304. if (tmo_ticks) {
  305. vTaskDelay(tmo_ticks);
  306. }
  307. }
  308. on_fail:
  309. if (inth) {
  310. for (int i = 0; i < arg->timers_num; i++) {
  311. timer_pause(arg->timers[i].group, arg->timers[i].id);
  312. timer_disable_intr(arg->timers[i].group, arg->timers[i].id);
  313. if (inth[i]) {
  314. esp_intr_free(inth[i]);
  315. }
  316. }
  317. vPortFree(inth);
  318. }
  319. xSemaphoreGive(arg->done);
  320. vTaskDelay(1);
  321. vTaskDelete(NULL);
  322. }
  323. static void esp_apptrace_test_task_crash(void *p)
  324. {
  325. esp_apptrace_test_task_arg_t *arg = (esp_apptrace_test_task_arg_t *) p;
  326. int res, i;
  327. ESP_APPTRACE_TEST_LOGE("%x: run (period %u us, stamp mask %x, %u timers)", xTaskGetCurrentTaskHandle(), arg->data.period, arg->data.mask, arg->timers_num);
  328. arg->data.wr_cnt = 0;
  329. *(uint32_t *)arg->data.buf = (uint32_t)xTaskGetCurrentTaskHandle();
  330. for (i = 0; i < ESP_APPTRACE_TEST_BLOCKS_BEFORE_CRASH; i++) {
  331. uint32_t *ts = (uint32_t *)(arg->data.buf + sizeof(uint32_t));
  332. *ts = (uint32_t)esp_apptrace_test_ts_get();
  333. memset(arg->data.buf + sizeof(uint32_t), arg->data.wr_cnt & arg->data.mask, arg->data.buf_sz - sizeof(uint32_t));
  334. res = ESP_APPTRACE_TEST_WRITE(arg->data.buf, arg->data.buf_sz);
  335. if (res) {
  336. ESP_APPTRACE_TEST_LOGE("%x: Failed to write trace %d %x!", xTaskGetCurrentTaskHandle(), res, arg->data.wr_cnt & arg->data.mask);
  337. } else {
  338. ESP_APPTRACE_TEST_LOGD("%x: Written chunk%d %d bytes, %x", xTaskGetCurrentTaskHandle(), arg->data.wr_cnt, arg->data.buf_sz, arg->data.wr_cnt & arg->data.mask);
  339. }
  340. arg->data.wr_cnt++;
  341. }
  342. vTaskDelay(500);
  343. uint32_t *ptr = 0;
  344. *ptr = 1000;
  345. xSemaphoreGive(arg->done);
  346. vTaskDelay(1);
  347. vTaskDelete(NULL);
  348. }
  349. static int s_ts_timer_group, s_ts_timer_idx;
  350. static uint64_t esp_apptrace_test_ts_get()
  351. {
  352. uint64_t ts = 0;
  353. timer_get_counter_value(s_ts_timer_group, s_ts_timer_idx, &ts);
  354. return ts;
  355. }
  356. static void esp_apptrace_test_ts_init(int timer_group, int timer_idx)
  357. {
  358. timer_config_t config;
  359. //uint64_t alarm_val = period * (TIMER_BASE_CLK / 1000000UL);
  360. ESP_APPTRACE_TEST_LOGI("Use timer%d.%d for TS", timer_group, timer_idx);
  361. s_ts_timer_group = timer_group;
  362. s_ts_timer_idx = timer_idx;
  363. config.alarm_en = 0;
  364. config.auto_reload = 0;
  365. config.counter_dir = TIMER_COUNT_UP;
  366. config.divider = 2; //Range is 2 to 65536
  367. config.counter_en = 0;
  368. /*Configure timer*/
  369. timer_init(timer_group, timer_idx, &config);
  370. /*Load counter value */
  371. timer_set_counter_value(timer_group, timer_idx, 0x00000000ULL);
  372. /*Enable timer interrupt*/
  373. timer_start(timer_group, timer_idx);
  374. }
  375. static void esp_apptrace_test_ts_cleanup()
  376. {
  377. timer_config_t config;
  378. config.alarm_en = 0;
  379. config.auto_reload = 0;
  380. config.counter_dir = TIMER_COUNT_UP;
  381. config.divider = 2; //Range is 2 to 65536
  382. config.counter_en = 0;
  383. /*Configure timer*/
  384. timer_init(s_ts_timer_group, s_ts_timer_idx, &config);
  385. }
  386. static void esp_apptrace_test(esp_apptrace_test_cfg_t *test_cfg)
  387. {
  388. int i, k;
  389. int tims_in_use[TIMER_GROUP_MAX][TIMER_MAX] = {{0, 0}, {0, 0}};
  390. esp_apptrace_test_task_arg_t dummy_task_arg[1];
  391. memset(dummy_task_arg, 0, sizeof(dummy_task_arg));
  392. dummy_task_arg[0].core = 0;
  393. dummy_task_arg[0].prio = 3;
  394. dummy_task_arg[0].task_func = esp_apptrace_test_task_crash;
  395. dummy_task_arg[0].data.buf = NULL;
  396. dummy_task_arg[0].data.buf_sz = 0;
  397. dummy_task_arg[0].data.period = 500000;
  398. dummy_task_arg[0].timers_num = 0;
  399. dummy_task_arg[0].timers = NULL;
  400. #if ESP_APPTRACE_TEST_USE_PRINT_LOCK == 1
  401. s_print_lock = xSemaphoreCreateBinary();
  402. if (!s_print_lock) {
  403. ets_printf("%s: Failed to create print lock!", TAG);
  404. return;
  405. }
  406. xSemaphoreGive(s_print_lock);
  407. #else
  408. #endif
  409. for (i = 0; i < test_cfg->tasks_num; i++) {
  410. test_cfg->tasks[i].data.mask = 0xFF;
  411. test_cfg->tasks[i].stop = 0;
  412. test_cfg->tasks[i].done = xSemaphoreCreateBinary();
  413. if (!test_cfg->tasks[i].done) {
  414. ESP_APPTRACE_TEST_LOGE("Failed to create task completion semaphore!");
  415. goto on_fail;
  416. }
  417. for (k = 0; k < test_cfg->tasks[i].timers_num; k++) {
  418. test_cfg->tasks[i].timers[k].data.mask = 0xFF;
  419. tims_in_use[test_cfg->tasks[i].timers[k].group][test_cfg->tasks[i].timers[k].id] = 1;
  420. }
  421. }
  422. int found = 0;
  423. for (i = 0; i < TIMER_GROUP_MAX; i++) {
  424. for (k = 0; k < TIMER_MAX; k++) {
  425. if (!tims_in_use[i][k]) {
  426. ESP_APPTRACE_TEST_LOGD("Found timer%d.%d", i, k);
  427. found = 1;
  428. break;
  429. }
  430. }
  431. if (found) {
  432. break;
  433. }
  434. }
  435. if (!found) {
  436. ESP_APPTRACE_TEST_LOGE("No free timer for TS!");
  437. goto on_fail;
  438. }
  439. esp_apptrace_test_ts_init(i, k);
  440. for (int i = 0; i < test_cfg->tasks_num; i++) {
  441. char name[30];
  442. TaskHandle_t thnd;
  443. sprintf(name, "apptrace_test%d", i);
  444. xTaskCreatePinnedToCore(test_cfg->tasks[i].task_func, name, 2048, &test_cfg->tasks[i], test_cfg->tasks[i].prio, &thnd, test_cfg->tasks[i].core);
  445. ESP_APPTRACE_TEST_LOGI("Created task %x", thnd);
  446. }
  447. xTaskCreatePinnedToCore(esp_apptrace_dummy_task, "dummy0", 2048, &dummy_task_arg[0], dummy_task_arg[0].prio, NULL, 0);
  448. #if CONFIG_FREERTOS_UNICORE == 0
  449. xTaskCreatePinnedToCore(esp_apptrace_dummy_task, "dummy1", 2048, &dummy_task_arg[0], dummy_task_arg[0].prio, NULL, 1);
  450. #endif
  451. for (int i = 0; i < test_cfg->tasks_num; i++) {
  452. //arg1.stop = 1;
  453. xSemaphoreTake(test_cfg->tasks[i].done, portMAX_DELAY);
  454. }
  455. on_fail:
  456. for (int i = 0; i < test_cfg->tasks_num; i++) {
  457. if (test_cfg->tasks[i].done) {
  458. vSemaphoreDelete(test_cfg->tasks[i].done);
  459. }
  460. }
  461. esp_apptrace_test_ts_cleanup();
  462. #if ESP_APPTRACE_TEST_USE_PRINT_LOCK == 1
  463. vSemaphoreDelete(s_print_lock);
  464. #else
  465. #endif
  466. }
  467. static esp_apptrace_test_task_arg_t s_test_tasks[4];
  468. static esp_apptrace_test_timer_arg_t s_test_timers[2];
  469. static uint8_t s_bufs[6][ESP_APPTRACE_TEST_BLOCK_SIZE];
  470. TEST_CASE("App trace test (1 task + 1 crashed timer ISR @ 1 core)", "[trace][ignore]")
  471. {
  472. esp_apptrace_test_cfg_t test_cfg = {
  473. .tasks_num = 1,
  474. .tasks = s_test_tasks,
  475. };
  476. memset(s_test_timers, 0, sizeof(s_test_timers));
  477. memset(s_test_tasks, 0, sizeof(s_test_tasks));
  478. s_test_timers[0].group = TIMER_GROUP_0;
  479. s_test_timers[0].id = TIMER_0;
  480. s_test_timers[0].isr_func = esp_apptrace_test_timer_isr_crash;
  481. s_test_timers[0].data.buf = s_bufs[0];
  482. s_test_timers[0].data.buf_sz = sizeof(s_bufs[0]);
  483. s_test_timers[0].data.period = 1000;
  484. s_test_tasks[0].core = 0;
  485. s_test_tasks[0].prio = 3;
  486. s_test_tasks[0].task_func = esp_apptrace_dummy_task;
  487. s_test_tasks[0].data.buf = NULL;
  488. s_test_tasks[0].data.buf_sz = 0;
  489. s_test_tasks[0].data.period = 1000000;
  490. s_test_tasks[0].timers_num = 1;
  491. s_test_tasks[0].timers = s_test_timers;
  492. esp_apptrace_test(&test_cfg);
  493. }
  494. TEST_CASE("App trace test (1 crashed task)", "[trace][ignore]")
  495. {
  496. esp_apptrace_test_task_arg_t s_test_tasks[1];
  497. esp_apptrace_test_cfg_t test_cfg = {
  498. .tasks_num = 1,
  499. .tasks = s_test_tasks,
  500. };
  501. memset(s_test_tasks, 0, sizeof(s_test_tasks));
  502. s_test_tasks[0].core = 0;
  503. s_test_tasks[0].prio = 3;
  504. s_test_tasks[0].task_func = esp_apptrace_test_task_crash;
  505. s_test_tasks[0].data.buf = s_bufs[0];
  506. s_test_tasks[0].data.buf_sz = sizeof(s_bufs[0]);
  507. s_test_tasks[0].data.period = 6000;
  508. s_test_tasks[0].timers_num = 0;
  509. s_test_tasks[0].timers = NULL;
  510. esp_apptrace_test(&test_cfg);
  511. }
  512. #if CONFIG_FREERTOS_UNICORE == 0
  513. TEST_CASE("App trace test (2 tasks + 1 timer @ each core", "[trace][ignore]")
  514. {
  515. int ntask = 0;
  516. esp_apptrace_test_cfg_t test_cfg = {
  517. .tasks_num = 4,
  518. .tasks = s_test_tasks,
  519. };
  520. memset(s_test_tasks, 0, sizeof(s_test_tasks));
  521. memset(s_test_timers, 0, sizeof(s_test_timers));
  522. s_test_timers[0].group = TIMER_GROUP_0;
  523. s_test_timers[0].id = TIMER_0;
  524. s_test_timers[0].isr_func = esp_apptrace_test_timer_isr;
  525. s_test_timers[0].data.buf = s_bufs[0];
  526. s_test_timers[0].data.buf_sz = sizeof(s_bufs[0]);
  527. s_test_timers[0].data.period = 150;
  528. s_test_timers[1].group = TIMER_GROUP_1;
  529. s_test_timers[1].id = TIMER_0;
  530. s_test_timers[1].isr_func = esp_apptrace_test_timer_isr;
  531. s_test_timers[1].data.buf = s_bufs[1];
  532. s_test_timers[1].data.buf_sz = sizeof(s_bufs[1]);
  533. s_test_timers[1].data.period = 150;
  534. s_test_tasks[ntask].core = 0;
  535. s_test_tasks[ntask].prio = 4;
  536. s_test_tasks[ntask].task_func = esp_apptrace_test_task;
  537. s_test_tasks[ntask].data.buf = s_bufs[2];
  538. s_test_tasks[ntask].data.buf_sz = sizeof(s_bufs[2]);
  539. s_test_tasks[ntask].data.period = 1000;
  540. s_test_tasks[ntask].timers_num = 1;
  541. s_test_tasks[ntask].timers = &s_test_timers[0];
  542. ntask++;
  543. s_test_tasks[ntask].core = 0;
  544. s_test_tasks[ntask].prio = 3;
  545. s_test_tasks[ntask].task_func = esp_apptrace_test_task;
  546. s_test_tasks[ntask].data.buf = s_bufs[3];
  547. s_test_tasks[ntask].data.buf_sz = sizeof(s_bufs[3]);
  548. s_test_tasks[ntask].data.period = 0;
  549. s_test_tasks[ntask].timers_num = 0;
  550. s_test_tasks[ntask].timers = NULL;
  551. ntask++;
  552. s_test_tasks[ntask].core = 1;
  553. s_test_tasks[ntask].prio = 4;
  554. s_test_tasks[ntask].task_func = esp_apptrace_test_task;
  555. s_test_tasks[ntask].data.buf = s_bufs[4];
  556. s_test_tasks[ntask].data.buf_sz = sizeof(s_bufs[4]);
  557. s_test_tasks[ntask].data.period = 1000;
  558. s_test_tasks[ntask].timers_num = 1;
  559. s_test_tasks[ntask].timers = &s_test_timers[1];
  560. ntask++;
  561. s_test_tasks[ntask].core = 1;
  562. s_test_tasks[ntask].prio = 3;
  563. s_test_tasks[ntask].task_func = esp_apptrace_test_task;
  564. s_test_tasks[ntask].data.buf = s_bufs[5];
  565. s_test_tasks[ntask].data.buf_sz = sizeof(s_bufs[5]);
  566. s_test_tasks[ntask].data.period = 0;
  567. s_test_tasks[ntask].timers_num = 0;
  568. s_test_tasks[ntask].timers = NULL;
  569. ntask++;
  570. esp_apptrace_test(&test_cfg);
  571. }
  572. #endif
  573. TEST_CASE("App trace test (1 task + 1 timer @ 1 core)", "[trace][ignore]")
  574. {
  575. esp_apptrace_test_cfg_t test_cfg = {
  576. .tasks_num = 1,
  577. .tasks = s_test_tasks,
  578. };
  579. memset(s_test_timers, 0, sizeof(s_test_timers));
  580. memset(s_test_tasks, 0, sizeof(s_test_tasks));
  581. s_test_timers[0].group = TIMER_GROUP_0;
  582. s_test_timers[0].id = TIMER_0;
  583. s_test_timers[0].isr_func = esp_apptrace_test_timer_isr;
  584. s_test_timers[0].data.buf = s_bufs[0];
  585. s_test_timers[0].data.buf_sz = sizeof(s_bufs[0]);
  586. s_test_timers[0].data.period = 150;
  587. s_test_tasks[0].core = 0;
  588. s_test_tasks[0].prio = 3;
  589. s_test_tasks[0].task_func = esp_apptrace_test_task;
  590. s_test_tasks[0].data.buf = s_bufs[1];
  591. s_test_tasks[0].data.buf_sz = sizeof(s_bufs[1]);
  592. s_test_tasks[0].data.period = 0;
  593. s_test_tasks[0].timers_num = 1;
  594. s_test_tasks[0].timers = s_test_timers;
  595. esp_apptrace_test(&test_cfg);
  596. }
  597. #if CONFIG_FREERTOS_UNICORE == 0
  598. TEST_CASE("App trace test (2 tasks (nowait): 1 @ each core)", "[trace][ignore]")
  599. {
  600. esp_apptrace_test_cfg_t test_cfg = {
  601. .tasks_num = 2,
  602. .tasks = s_test_tasks,
  603. };
  604. memset(s_test_tasks, 0, sizeof(s_test_tasks));
  605. s_test_tasks[0].nowait = 1;
  606. s_test_tasks[0].core = 0;
  607. s_test_tasks[0].prio = 3;
  608. s_test_tasks[0].task_func = esp_apptrace_test_task;
  609. s_test_tasks[0].data.buf = s_bufs[0];
  610. s_test_tasks[0].data.buf_sz = sizeof(s_bufs[0]);
  611. s_test_tasks[0].data.period = 6700;
  612. s_test_tasks[0].timers_num = 0;
  613. s_test_tasks[0].timers = NULL;
  614. s_test_tasks[1].nowait = 1;
  615. s_test_tasks[1].core = 1;
  616. s_test_tasks[1].prio = 3;
  617. s_test_tasks[1].task_func = esp_apptrace_test_task;
  618. s_test_tasks[1].data.buf = s_bufs[1];
  619. s_test_tasks[1].data.buf_sz = sizeof(s_bufs[1]);
  620. s_test_tasks[1].data.period = 6700;
  621. s_test_tasks[1].timers_num = 0;
  622. s_test_tasks[1].timers = NULL;
  623. esp_apptrace_test(&test_cfg);
  624. }
  625. TEST_CASE("App trace test (2 tasks: 1 @ each core)", "[trace][ignore]")
  626. {
  627. esp_apptrace_test_cfg_t test_cfg = {
  628. .tasks_num = 2,
  629. .tasks = s_test_tasks,
  630. };
  631. memset(s_test_tasks, 0, sizeof(s_test_tasks));
  632. s_test_tasks[0].core = 0;
  633. s_test_tasks[0].prio = 3;
  634. s_test_tasks[0].task_func = esp_apptrace_test_task;
  635. s_test_tasks[0].data.buf = s_bufs[0];
  636. s_test_tasks[0].data.buf_sz = sizeof(s_bufs[0]);
  637. s_test_tasks[0].data.period = 0;
  638. s_test_tasks[0].timers_num = 0;
  639. s_test_tasks[0].timers = NULL;
  640. s_test_tasks[1].core = 1;
  641. s_test_tasks[1].prio = 3;
  642. s_test_tasks[1].task_func = esp_apptrace_test_task;
  643. s_test_tasks[1].data.buf = s_bufs[1];
  644. s_test_tasks[1].data.buf_sz = sizeof(s_bufs[1]);
  645. s_test_tasks[1].data.period = 0;
  646. s_test_tasks[1].timers_num = 0;
  647. s_test_tasks[1].timers = NULL;
  648. esp_apptrace_test(&test_cfg);
  649. }
  650. #endif
  651. TEST_CASE("App trace test (1 task)", "[trace][ignore]")
  652. {
  653. esp_apptrace_test_cfg_t test_cfg = {
  654. .tasks_num = 1,
  655. .tasks = s_test_tasks,
  656. };
  657. memset(s_test_tasks, 0, sizeof(s_test_tasks));
  658. s_test_tasks[0].core = 0;
  659. s_test_tasks[0].prio = 3;
  660. s_test_tasks[0].task_func = esp_apptrace_test_task;
  661. s_test_tasks[0].data.buf = s_bufs[0];
  662. s_test_tasks[0].data.buf_sz = sizeof(s_bufs[0]);
  663. s_test_tasks[0].data.period = 0;
  664. s_test_tasks[0].timers_num = 0;
  665. s_test_tasks[0].timers = NULL;
  666. esp_apptrace_test(&test_cfg);
  667. }
  668. static int esp_logtrace_printf(const char *fmt, ...)
  669. {
  670. va_list ap;
  671. va_start(ap, fmt);
  672. int ret = esp_apptrace_vprintf_to(ESP_APPTRACE_DEST_TRAX, ESP_APPTRACE_TMO_INFINITE, fmt, ap);
  673. va_end(ap);
  674. return ret;
  675. }
  676. typedef struct {
  677. SemaphoreHandle_t done;
  678. uint32_t work_count;
  679. } esp_logtrace_task_t;
  680. static void esp_logtrace_task(void *p)
  681. {
  682. esp_logtrace_task_t *arg = (esp_logtrace_task_t *) p;
  683. ESP_APPTRACE_TEST_LOGI("%x: run log test task", xTaskGetCurrentTaskHandle());
  684. int i = 0;
  685. while (1) {
  686. esp_logtrace_printf("sample print %lx %hx %c\n", 2 * i + 0x10, 2 * i + 0x20, (2 * i + 0x30) & 0xFF);
  687. esp_logtrace_printf("sample print %lx %hx %c %lu %hu %d %d %d %d\n", i, i + 0x10, (i + 0x20) & 0xFF, i + 0x30, i + 0x40, i + 0x50, i + 0x60, i + 0x70, i + 0x80);
  688. ESP_LOGI(TAG, "%p: sample print 1", xTaskGetCurrentTaskHandle());
  689. ESP_LOGI(TAG, "%p: sample print 2 %u", xTaskGetCurrentTaskHandle(), (unsigned)i);
  690. ESP_LOGI(TAG, "%p: sample print 4 %c", xTaskGetCurrentTaskHandle(), ((i & 0xFF) % 95) + 32);
  691. ESP_LOGI(TAG, "%p: sample print 5 %f", xTaskGetCurrentTaskHandle(), 1.0);
  692. ESP_LOGI(TAG, "%p: sample print 6 %f", xTaskGetCurrentTaskHandle(), 3.45);
  693. ESP_LOGI(TAG, "%p: logtrace task work %d.%d", xTaskGetCurrentTaskHandle(), xPortGetCoreID(), i);
  694. if (++i == 10000) {
  695. break;
  696. }
  697. }
  698. esp_err_t ret = esp_apptrace_flush(ESP_APPTRACE_DEST_TRAX, ESP_APPTRACE_TMO_INFINITE);
  699. if (ret != ESP_OK) {
  700. ESP_APPTRACE_TEST_LOGE("Failed to flush printf buf (%d)!", ret);
  701. }
  702. ESP_APPTRACE_TEST_LOGI("%x: finished", xTaskGetCurrentTaskHandle());
  703. xSemaphoreGive(arg->done);
  704. vTaskDelay(1);
  705. vTaskDelete(NULL);
  706. }
  707. TEST_CASE("Log trace test (2 tasks)", "[trace][ignore]")
  708. {
  709. TaskHandle_t thnd;
  710. esp_logtrace_task_t arg1 = {
  711. .done = xSemaphoreCreateBinary(),
  712. };
  713. esp_logtrace_task_t arg2 = {
  714. .done = xSemaphoreCreateBinary(),
  715. };
  716. xTaskCreatePinnedToCore(esp_logtrace_task, "logtrace0", 2048, &arg1, 3, &thnd, 0);
  717. ESP_APPTRACE_TEST_LOGI("Created task %x", thnd);
  718. #if CONFIG_FREERTOS_UNICORE == 0
  719. xTaskCreatePinnedToCore(esp_logtrace_task, "logtrace1", 2048, &arg2, 3, &thnd, 1);
  720. #else
  721. xTaskCreatePinnedToCore(esp_logtrace_task, "logtrace1", 2048, &arg2, 3, &thnd, 0);
  722. #endif
  723. ESP_APPTRACE_TEST_LOGI("Created task %x", thnd);
  724. xSemaphoreTake(arg1.done, portMAX_DELAY);
  725. vSemaphoreDelete(arg1.done);
  726. xSemaphoreTake(arg2.done, portMAX_DELAY);
  727. vSemaphoreDelete(arg2.done);
  728. }
  729. #else
  730. typedef struct {
  731. int group;
  732. int timer;
  733. int flags;
  734. uint32_t id;
  735. } esp_sysviewtrace_timer_arg_t;
  736. typedef struct {
  737. SemaphoreHandle_t done;
  738. SemaphoreHandle_t *sync;
  739. esp_sysviewtrace_timer_arg_t *timer;
  740. uint32_t work_count;
  741. uint32_t sleep_tmo;
  742. uint32_t id;
  743. } esp_sysviewtrace_task_arg_t;
  744. static void esp_sysview_test_timer_isr(void *arg)
  745. {
  746. esp_sysviewtrace_timer_arg_t *tim_arg = (esp_sysviewtrace_timer_arg_t *)arg;
  747. //ESP_APPTRACE_TEST_LOGI("tim-%d: IRQ %d/%d\n", tim_arg->id, tim_arg->group, tim_arg->timer);
  748. if (tim_arg->group == 0) {
  749. if (tim_arg->timer == 0) {
  750. TIMERG0.int_clr_timers.t0 = 1;
  751. TIMERG0.hw_timer[0].update = 1;
  752. TIMERG0.hw_timer[0].config.alarm_en = 1;
  753. } else {
  754. TIMERG0.int_clr_timers.t1 = 1;
  755. TIMERG0.hw_timer[1].update = 1;
  756. TIMERG0.hw_timer[1].config.alarm_en = 1;
  757. }
  758. }
  759. if (tim_arg->group == 1) {
  760. if (tim_arg->timer == 0) {
  761. TIMERG1.int_clr_timers.t0 = 1;
  762. TIMERG1.hw_timer[0].update = 1;
  763. TIMERG1.hw_timer[0].config.alarm_en = 1;
  764. } else {
  765. TIMERG1.int_clr_timers.t1 = 1;
  766. TIMERG1.hw_timer[1].update = 1;
  767. TIMERG1.hw_timer[1].config.alarm_en = 1;
  768. }
  769. }
  770. }
  771. static void esp_sysviewtrace_test_task(void *p)
  772. {
  773. esp_sysviewtrace_task_arg_t *arg = (esp_sysviewtrace_task_arg_t *) p;
  774. volatile uint32_t tmp = 0;
  775. timer_isr_handle_t inth;
  776. printf("%x: run sysview task\n", (uint32_t)xTaskGetCurrentTaskHandle());
  777. if (arg->timer) {
  778. esp_err_t res = timer_isr_register(arg->timer->group, arg->timer->timer, esp_sysview_test_timer_isr, arg->timer, arg->timer->flags, &inth);
  779. if (res != ESP_OK) {
  780. printf("%x: failed to register timer ISR\n", (uint32_t)xTaskGetCurrentTaskHandle());
  781. }
  782. else {
  783. res = timer_start(arg->timer->group, arg->timer->timer);
  784. if (res != ESP_OK) {
  785. printf("%x: failed to start timer\n", (uint32_t)xTaskGetCurrentTaskHandle());
  786. }
  787. }
  788. }
  789. int i = 0;
  790. while (1) {
  791. static uint32_t count;
  792. printf("%d", arg->id);
  793. if((++count % 80) == 0)
  794. printf("\n");
  795. if (arg->sync) {
  796. xSemaphoreTake(*arg->sync, portMAX_DELAY);
  797. }
  798. for (uint32_t k = 0; k < arg->work_count; k++) {
  799. tmp++;
  800. }
  801. vTaskDelay(arg->sleep_tmo/portTICK_PERIOD_MS);
  802. i++;
  803. if (arg->sync) {
  804. xSemaphoreGive(*arg->sync);
  805. }
  806. }
  807. ESP_APPTRACE_TEST_LOGI("%x: finished", xTaskGetCurrentTaskHandle());
  808. xSemaphoreGive(arg->done);
  809. vTaskDelay(1);
  810. vTaskDelete(NULL);
  811. }
  812. TEST_CASE("SysView trace test 1", "[trace][ignore]")
  813. {
  814. TaskHandle_t thnd;
  815. esp_sysviewtrace_timer_arg_t tim_arg1 = {
  816. .group = TIMER_GROUP_1,
  817. .timer = TIMER_1,
  818. .flags = ESP_INTR_FLAG_SHARED,
  819. .id = 0,
  820. };
  821. esp_sysviewtrace_task_arg_t arg1 = {
  822. .done = xSemaphoreCreateBinary(),
  823. .sync = NULL,
  824. .work_count = 10000,
  825. .sleep_tmo = 1,
  826. .timer = &tim_arg1,
  827. .id = 0,
  828. };
  829. esp_sysviewtrace_timer_arg_t tim_arg2 = {
  830. .group = TIMER_GROUP_1,
  831. .timer = TIMER_0,
  832. .flags = 0,
  833. .id = 1,
  834. };
  835. esp_sysviewtrace_task_arg_t arg2 = {
  836. .done = xSemaphoreCreateBinary(),
  837. .sync = NULL,
  838. .work_count = 10000,
  839. .sleep_tmo = 1,
  840. .timer = &tim_arg2,
  841. .id = 1,
  842. };
  843. esp_apptrace_test_timer_init(TIMER_GROUP_1, TIMER_1, 500);
  844. esp_apptrace_test_timer_init(TIMER_GROUP_1, TIMER_0, 100);
  845. xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svtrace0", 2048, &arg1, 3, &thnd, 0);
  846. ESP_APPTRACE_TEST_LOGI("Created task %x", thnd);
  847. #if CONFIG_FREERTOS_UNICORE == 0
  848. xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svtrace1", 2048, &arg2, 5, &thnd, 1);
  849. #else
  850. xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svtrace1", 2048, &arg2, 5, &thnd, 0);
  851. #endif
  852. ESP_APPTRACE_TEST_LOGI("Created task %x", thnd);
  853. xSemaphoreTake(arg1.done, portMAX_DELAY);
  854. vSemaphoreDelete(arg1.done);
  855. xSemaphoreTake(arg2.done, portMAX_DELAY);
  856. vSemaphoreDelete(arg2.done);
  857. }
  858. TEST_CASE("SysView trace test 2", "[trace][ignore]")
  859. {
  860. TaskHandle_t thnd;
  861. esp_sysviewtrace_timer_arg_t tim_arg1 = {
  862. .group = TIMER_GROUP_1,
  863. .timer = TIMER_1,
  864. .flags = ESP_INTR_FLAG_SHARED,
  865. .id = 0,
  866. };
  867. esp_sysviewtrace_task_arg_t arg1 = {
  868. .done = xSemaphoreCreateBinary(),
  869. .sync = NULL,
  870. .work_count = 10000,
  871. .sleep_tmo = 1,
  872. .timer = &tim_arg1,
  873. .id = 0,
  874. };
  875. esp_sysviewtrace_timer_arg_t tim_arg2 = {
  876. .group = TIMER_GROUP_1,
  877. .timer = TIMER_0,
  878. .flags = 0,
  879. .id = 1,
  880. };
  881. esp_sysviewtrace_task_arg_t arg2 = {
  882. .done = xSemaphoreCreateBinary(),
  883. .sync = NULL,
  884. .work_count = 10000,
  885. .sleep_tmo = 1,
  886. .timer = &tim_arg2,
  887. .id = 1,
  888. };
  889. SemaphoreHandle_t test_sync = xSemaphoreCreateBinary();
  890. xSemaphoreGive(test_sync);
  891. esp_sysviewtrace_task_arg_t arg3 = {
  892. .done = xSemaphoreCreateBinary(),
  893. .sync = &test_sync,
  894. .work_count = 1000,
  895. .sleep_tmo = 1,
  896. .timer = NULL,
  897. .id = 2,
  898. };
  899. esp_sysviewtrace_task_arg_t arg4 = {
  900. .done = xSemaphoreCreateBinary(),
  901. .sync = &test_sync,
  902. .work_count = 10000,
  903. .sleep_tmo = 1,
  904. .timer = NULL,
  905. .id = 3,
  906. };
  907. esp_apptrace_test_timer_init(TIMER_GROUP_1, TIMER_1, 500);
  908. esp_apptrace_test_timer_init(TIMER_GROUP_1, TIMER_0, 100);
  909. xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svtrace0", 2048, &arg1, 3, &thnd, 0);
  910. printf("Created task %x\n", (uint32_t)thnd);
  911. #if CONFIG_FREERTOS_UNICORE == 0
  912. xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svtrace1", 2048, &arg2, 4, &thnd, 1);
  913. #else
  914. xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svtrace1", 2048, &arg2, 4, &thnd, 0);
  915. #endif
  916. printf("Created task %x\n", (uint32_t)thnd);
  917. xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svsync0", 2048, &arg3, 3, &thnd, 0);
  918. printf("Created task %x\n", (uint32_t)thnd);
  919. #if CONFIG_FREERTOS_UNICORE == 0
  920. xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svsync1", 2048, &arg4, 5, &thnd, 1);
  921. #else
  922. xTaskCreatePinnedToCore(esp_sysviewtrace_test_task, "svsync1", 2048, &arg4, 5, &thnd, 0);
  923. #endif
  924. printf("Created task %x\n", (uint32_t)thnd);
  925. xSemaphoreTake(arg1.done, portMAX_DELAY);
  926. vSemaphoreDelete(arg1.done);
  927. xSemaphoreTake(arg2.done, portMAX_DELAY);
  928. vSemaphoreDelete(arg2.done);
  929. xSemaphoreTake(arg3.done, portMAX_DELAY);
  930. vSemaphoreDelete(arg3.done);
  931. xSemaphoreTake(arg4.done, portMAX_DELAY);
  932. vSemaphoreDelete(arg4.done);
  933. vSemaphoreDelete(test_sync);
  934. }
  935. #endif
  936. #endif