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
| #include "systemview_task.h"
#define SYSVIEW_SINGLE_TX 256
TaskHandle_t system_view_notify;
STATIC_MEM_TASK_ALLOC(systemview_task, SYSTEMVIEW_TASK_STACKSIZE); static void SystemViewTask(void *param);
uint8_t hello_message[32] = { 'S', 'E', 'G', 'G', 'E', 'R', ' ', 'S', 'y', 's', 't', 'e', 'm', 'V', 'i', 'e', 'w', ' ', 'V', '0' + SEGGER_SYSVIEW_MAJOR, '.', '0' + (SEGGER_SYSVIEW_MINOR / 10), '0' + (SEGGER_SYSVIEW_MINOR % 10), '.', '0' + (SEGGER_SYSVIEW_REV / 10), '0' + (SEGGER_SYSVIEW_REV % 10), '\0', 0, 0, 0, 0, 0};
void SystemViewLaunch(void) {
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; DWT->CYCCNT = 0; DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
SEGGER_SYSVIEW_Conf();
STATIC_MEM_TASK_CREATE(systemview_task, SystemViewTask, "SystemViewTask", NULL, SYSTEMVIEW_TASK_PRI); }
void SystemViewTask(void *param) { system_view_notify = xTaskGetCurrentTaskHandle();
// 获取Channel ID int channel_id = SEGGER_SYSVIEW_GetChannelID();
//发送HELLO包 HAL_UART_Transmit_DMA(&huart1, hello_message, 32);
uint8_t rx_buf; uint8_t tx_buf[SYSVIEW_SINGLE_TX]; uint32_t notify_flag; bool dma_in_progress = true; TickType_t prev_send;
//启动记录 SEGGER_SYSVIEW_Start();
while (1) { if (xTaskNotifyWait(0x00, 0x03, ¬ify_flag, pdMS_TO_TICKS(400)) == pdTRUE) { if (notify_flag & 0x01) { SEGGER_RTT_WriteDownBufferNoLock(channel_id, &rx_buf, 0x01); HAL_UART_Receive_IT(&huart1, &rx_buf, 0x01); } else if (notify_flag & 0x02) { if (dma_in_progress) { dma_in_progress = false; prev_send = xTaskGetTickCount(); } } }
if (dma_in_progress == false && xTaskGetTickCount() - prev_send >= pdMS_TO_TICKS(400)) { unsigned int tx_length = SEGGER_RTT_GetBytesInBuffer(channel_id); if (tx_length >= SYSVIEW_SINGLE_TX) { uint32_t num = SEGGER_RTT_ReadUpBufferNoLock(channel_id, tx_buf, SYSVIEW_SINGLE_TX); HAL_UART_Transmit_DMA(&huart1, tx_buf, num); } else if (tx_length != 0) { uint32_t num = SEGGER_RTT_ReadUpBufferNoLock(channel_id, tx_buf, tx_length); HAL_UART_Transmit_DMA(&huart1, tx_buf, num); } dma_in_progress = true; }
} }
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { if (huart->Instance == USART1) { BaseType_t higher_woken = pdFALSE; xTaskNotifyFromISR(system_view_notify, 0x01, eSetBits, &higher_woken); portYIELD_FROM_ISR(higher_woken); } }
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) { if (huart->Instance == USART1) { BaseType_t higher_woken = pdFALSE; xTaskNotifyFromISR(system_view_notify, 0x02, eSetBits, &higher_woken); portYIELD_FROM_ISR(higher_woken); } }
|