テスト用のあれこれ共用フォルダ
修訂 | 2608ab505cb65e6c6e71a29f86a663fae23d60c9 (tree) |
---|---|
時間 | 2018-03-03 14:07:04 |
作者 | takemasa <suikan@user...> |
Commiter | takemasa |
Debugger Transmission is migrated to new style.
@@ -22,14 +22,16 @@ | ||
22 | 22 | murasaki::Platform murasaki::platform; |
23 | 23 | murasaki::Debugger * murasaki::debugger; |
24 | 24 | |
25 | +static int counter; | |
25 | 26 | |
26 | - | |
27 | +#if 0 | |
27 | 28 | #define MSG1 "A quick brown fox jumps over the lazy dog." |
29 | +#define MSG2 "The rain in spain is mainly in plain." | |
28 | 30 | |
29 | -static int counter; | |
30 | 31 | static murasaki::DebuggerFifo * test_fifo; |
31 | 32 | static murasaki::AbstractTask * tx_task; |
32 | 33 | static murasaki::LoggingHelpers helpers; |
34 | +#endif | |
33 | 35 | |
34 | 36 | // Initialize the platfrom variables. This have to be doen before |
35 | 37 | // using other murasaki funciton. |
@@ -63,23 +65,27 @@ void InitTestUart(UART_HandleTypeDef * uart_handle, SPI_HandleTypeDef * spi_hand | ||
63 | 65 | |
64 | 66 | // Setting debugger |
65 | 67 | murasaki::debugger = new murasaki::Debugger(murasaki::platform.logger); |
66 | - murasaki::debugger->AutoHistory(); // type any key to show history. | |
67 | - | |
68 | +// murasaki::debugger->AutoHistory(); // type any key to show history. | |
69 | +#if 0 | |
68 | 70 | test_fifo = new murasaki::DebuggerFifo(32); |
69 | 71 | MURASAKI_ASSERT(test_fifo != nullptr); |
70 | 72 | |
71 | 73 | helpers.logger = murasaki::platform.logger; |
72 | 74 | helpers.fifo = test_fifo; |
73 | 75 | |
74 | - tx_task = new murasaki::DebuggerTxTask("Debug_tx", | |
75 | - PLATFORM_CONFIG_DEBUG_TASK_STACK_SIZE, | |
76 | - PLATFORM_CONFIG_DEBUG_TASK_PRIORITY, &helpers); | |
76 | + tx_task = new murasaki::DebuggerTxTask("Debug_tx", // | |
77 | + PLATFORM_CONFIG_DEBUG_TASK_STACK_SIZE, // | |
78 | + PLATFORM_CONFIG_DEBUG_TASK_PRIORITY, // the bigger value is the higer priority | |
79 | + &helpers); | |
77 | 80 | MURASAKI_ASSERT(tx_task != nullptr); |
78 | 81 | |
82 | + tx_task->Start(); | |
79 | 83 | |
80 | 84 | unsigned int copied = test_fifo->Put(reinterpret_cast<const uint8_t *>(MSG1), sizeof(MSG1)); |
81 | - murasaki::debugger->printf("FIFO.Put(), %d data taransfered\n\r", copied); | |
85 | + test_fifo->NotifyData(); | |
82 | 86 | |
87 | + murasaki::debugger->printf("FIFO.Put(), %d data taransfered\n\r", copied); | |
88 | +#endif | |
83 | 89 | |
84 | 90 | } |
85 | 91 |
@@ -89,6 +95,12 @@ void DoTestUart(void) | ||
89 | 95 | { |
90 | 96 | // MURASAKI_ASSERT(counter % 2 == 0, "Odd counter"); |
91 | 97 | #if 0 |
98 | + unsigned int copied = test_fifo->Put(reinterpret_cast<const uint8_t *>(MSG1), sizeof(MSG1)); | |
99 | + test_fifo->NotifyData(); | |
100 | + murasaki::debugger->printf("FIFO.Put(), %d data taransfered\n\r", copied); | |
101 | +#endif | |
102 | + | |
103 | +#if 0 | |
92 | 104 | murasaki::platform.spi_master->Transfer(murasaki::platform.slave_1, tx_buffer, rx_buffer, 1); |
93 | 105 | #endif |
94 | 106 |
@@ -107,7 +119,7 @@ void DoTestUart(void) | ||
107 | 119 | #endif |
108 | 120 | // by murasaki debugging output. You can use this in both task and interrupt context. |
109 | 121 | // non blocking |
110 | -// murasaki::debugger->printf(MSG, counter); | |
122 | + murasaki::debugger->printf(MSG, counter); | |
111 | 123 | |
112 | 124 | } |
113 | 125 |
@@ -152,6 +164,13 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_P) | ||
152 | 164 | { |
153 | 165 | if (GPIO_P == B1_Pin) { |
154 | 166 | counter++; |
167 | +#if 0 | |
168 | + unsigned int copied = test_fifo->Put(reinterpret_cast<const uint8_t *>(MSG2), sizeof(MSG2)); | |
169 | + test_fifo->NotifyData(); | |
170 | + | |
171 | + murasaki::debugger->printf("FIFO.Put(), %d data taransfered\n\r", copied); | |
172 | +#else | |
155 | 173 | murasaki::debugger->printf("Interrupt occurs %d \n\r", counter); |
174 | +#endif | |
156 | 175 | } |
157 | 176 | } |
@@ -21,8 +21,12 @@ Debugger::Debugger(AbstractLogger * logger) | ||
21 | 21 | { |
22 | 22 | // initialize internal variable; |
23 | 23 | MURASAKI_ASSERT(logger != nullptr) |
24 | - logger_ = logger; | |
25 | 24 | |
25 | + auto_history_enabled = false; | |
26 | + auto_history_task_ = nullptr; | |
27 | + | |
28 | +#ifdef OLDIMPLEMENTATION | |
29 | + logger_ = logger; | |
26 | 30 | sem_notify_new_data_ = ::xSemaphoreCreateBinary(); // create semaphore as "empty" state |
27 | 31 | MURASAKI_ASSERT(sem_notify_new_data_); |
28 | 32 |
@@ -30,12 +34,8 @@ Debugger::Debugger(AbstractLogger * logger) | ||
30 | 34 | head_ = 0; |
31 | 35 | tail_ = 0; |
32 | 36 | |
33 | - auto_history_enabled = false; | |
34 | - auto_history_task_ = nullptr; | |
35 | - | |
36 | 37 | for (unsigned int i = 0; i < sizeof(buffer_); i++) |
37 | 38 | buffer_[i] = ' '; |
38 | - | |
39 | 39 | // start the debug task |
40 | 40 | BaseType_t task_result = ::xTaskCreate( |
41 | 41 | Debugger::LaunchTxTask, // task entity; |
@@ -46,11 +46,23 @@ Debugger::Debugger(AbstractLogger * logger) | ||
46 | 46 | &tx_task_ // receive task handle |
47 | 47 | ); |
48 | 48 | MURASAKI_ASSERT(task_result != errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY); |
49 | +#else | |
50 | + helpers_.fifo = new murasaki::DebuggerFifo(PLATFORM_CONFIG_DEBUG_BUFFER_SIZE); | |
51 | + helpers_.logger = logger; | |
49 | 52 | |
53 | + tx_task_ = new murasaki::DebuggerTxTask("DebugTask", // name of task | |
54 | + PLATFORM_CONFIG_DEBUG_TASK_STACK_SIZE, // stack depth | |
55 | + PLATFORM_CONFIG_DEBUG_TASK_PRIORITY, // execusion priority of task | |
56 | + &helpers_ // parameter to task | |
57 | + ); | |
58 | + tx_task_->Start(); | |
59 | + | |
60 | +#endif | |
50 | 61 | } |
51 | 62 | |
52 | 63 | Debugger::~Debugger() |
53 | 64 | { |
65 | +#ifdef OLDIMPLEMENTATION | |
54 | 66 | // Delete task; |
55 | 67 | if (tx_task_ != nullptr) |
56 | 68 | ::vTaskDelete(tx_task_); |
@@ -62,10 +74,13 @@ Debugger::~Debugger() | ||
62 | 74 | // Delete semaphore. |
63 | 75 | if (sem_notify_new_data_ != nullptr) |
64 | 76 | ::vSemaphoreDelete( sem_notify_new_data_); |
77 | +#else | |
78 | +#endif | |
65 | 79 | } |
66 | 80 | |
67 | 81 | void Debugger::printf(const char * fmt, ...) |
68 | 82 | { |
83 | +#ifdef OLDIMPLEMENTATION | |
69 | 84 | // obtain variable parameter list |
70 | 85 | va_list argp; |
71 | 86 |
@@ -101,20 +116,58 @@ void Debugger::printf(const char * fmt, ...) | ||
101 | 116 | ::xSemaphoreGive(sem_notify_new_data_); // if yes |
102 | 117 | else |
103 | 118 | ::xSemaphoreGiveFromISR(sem_notify_new_data_, nullptr); // if no. |
119 | +#else | |
120 | + // obtain variable parameter list | |
121 | + va_list argp; | |
122 | + | |
123 | + MURASAKI_ASSERT(nullptr != fmt);// nullptr check. Perhaps, overkill. | |
124 | + | |
125 | + portDISABLE_INTERRUPTS();// ARM dependent API. OK to use in task and ISR. | |
126 | + { | |
127 | +#if 0 | |
128 | + // Test the remains of task stack in byte. | |
129 | + // To use the uxTaskGetStackHighWaterMark(), Add following to the | |
130 | + // FreeRTOSConfig.h | |
131 | + // #define INCLUDE_uxTaskGetStackHighWaterMark 1 | |
132 | + | |
133 | + ::snprintf((char *) line_, | |
134 | + sizeof(line_) - 1, | |
135 | + "stack remains : %8d bytes. ", | |
136 | + (int) uxTaskGetStackHighWaterMark(tx_task_)); | |
137 | + AppendToBuffer(); | |
138 | +#endif | |
139 | + ::va_start(argp, fmt); | |
140 | + // convert the number with formt string to the line string. | |
141 | + // The string length have to be N - 1. Where N is the length of the destination variable. | |
142 | + ::vsnprintf((char *) line_, sizeof(line_) - 1, fmt, argp); | |
143 | + | |
144 | + ::va_end(argp); | |
145 | + // Append the line to the buffer to be sent. | |
146 | + helpers_.fifo->Put(reinterpret_cast<uint8_t*>(line_), ::strlen(line_)); | |
147 | + | |
148 | + } | |
149 | + portENABLE_INTERRUPTS(); | |
150 | + | |
151 | + // Notify to the consumer task, the new data has come. | |
152 | + helpers_.fifo->NotifyData(); | |
153 | +#endif | |
104 | 154 | |
105 | 155 | } |
106 | 156 | |
107 | 157 | char Debugger::GetchFromTask() |
108 | 158 | { |
109 | 159 | MURASAKI_ASSERT(isTaskContext()); |
110 | - | |
160 | +#ifdef OLDIMPLEMENTATION | |
111 | 161 | return logger_->getCharacter(); // receive successfuly. |
112 | - | |
162 | +#else | |
163 | + return helpers_.logger->getCharacter(); | |
164 | +#endif | |
113 | 165 | } |
114 | 166 | |
115 | 167 | // Assumes this is called only in the critical section. |
116 | 168 | void Debugger::AppendToBuffer() |
117 | 169 | { |
170 | +#ifdef OLDIMPLEMENTATION | |
118 | 171 | unsigned int avairable; |
119 | 172 | |
120 | 173 | // check the avairable area size. Data is append to the head |
@@ -145,7 +198,7 @@ void Debugger::AppendToBuffer() | ||
145 | 198 | if (head_ >= sizeof(buffer_)) |
146 | 199 | head_ = 0; |
147 | 200 | } // end for loop. |
148 | - | |
201 | +#endif | |
149 | 202 | } |
150 | 203 | |
151 | 204 |
@@ -155,6 +208,7 @@ void Debugger::AppendToBuffer() | ||
155 | 208 | */ |
156 | 209 | void Debugger::RePrint() |
157 | 210 | { |
211 | +#ifdef OLDIMPLEMENTATION | |
158 | 212 | MURASAKI_ASSERT(isTaskContext()); |
159 | 213 | |
160 | 214 | taskENTER_CRITICAL(); |
@@ -170,7 +224,7 @@ void Debugger::RePrint() | ||
170 | 224 | |
171 | 225 | // tell there is data |
172 | 226 | ::xSemaphoreGive(sem_notify_new_data_); |
173 | - | |
227 | +#endif | |
174 | 228 | } |
175 | 229 | |
176 | 230 | void Debugger::AutoHistory() |
@@ -232,6 +286,7 @@ void Debugger::LaunchTxTask(void * this_pointer) | ||
232 | 286 | #define BLOCK_SIZE 50 |
233 | 287 | void Debugger::TxTask() |
234 | 288 | { |
289 | +#ifdef OLDIMPLEMENTATION | |
235 | 290 | unsigned int copy_size = 0; |
236 | 291 | uint8_t block[BLOCK_SIZE]; |
237 | 292 |
@@ -275,7 +330,7 @@ void Debugger::TxTask() | ||
275 | 330 | ::xSemaphoreTake(sem_notify_new_data_, 1000 / portTICK_PERIOD_MS ); |
276 | 331 | |
277 | 332 | } // end of while loop. |
278 | - | |
333 | +#endif | |
279 | 334 | } |
280 | 335 | |
281 | 336 | } /* namespace platform */ |
@@ -18,6 +18,13 @@ | ||
18 | 18 | #include "murasaki_config.hpp" |
19 | 19 | #include "abstractlogger.hpp" |
20 | 20 | |
21 | +//#define OLDIMPLEMENTATION | |
22 | + | |
23 | +#ifdef OLDIMPLEMENTATION | |
24 | +#else | |
25 | +#include "debuggerfifo.hpp" | |
26 | +#include "debuggertxtask.hpp" | |
27 | +#endif | |
21 | 28 | |
22 | 29 | namespace murasaki { |
23 | 30 |
@@ -110,6 +117,7 @@ class Debugger | ||
110 | 117 | */ |
111 | 118 | void AutoHistory(); |
112 | 119 | protected: |
120 | +#ifdef OLDIMPLEMENTATION | |
113 | 121 | /** |
114 | 122 | * \brief A pointer to the logger class. |
115 | 123 | */ |
@@ -117,7 +125,6 @@ class Debugger | ||
117 | 125 | /** |
118 | 126 | * @brief For protecting from the double creating of the internal task. |
119 | 127 | */ |
120 | - bool auto_history_enabled; | |
121 | 128 | /** |
122 | 129 | * \brief Transmission notification semaphore. |
123 | 130 | * \details |
@@ -125,19 +132,27 @@ class Debugger | ||
125 | 132 | * notification. Whenever the printf() method added new data to the buffer_, a nothification |
126 | 133 | * is given through this semaphore. |
127 | 134 | */ |
135 | + /** | |
136 | + * \brief Handle to the transmission control task. | |
137 | + */ | |
138 | + TaskHandle_t tx_task_; | |
128 | 139 | SemaphoreHandle_t sem_notify_new_data_; |
129 | 140 | /** |
130 | 141 | * \brief transmission data circular buffer. |
131 | 142 | */ |
132 | 143 | char buffer_[PLATFORM_CONFIG_DEBUG_BUFFER_SIZE]; |
144 | +#else | |
145 | + murasaki::LoggingHelpers helpers_; | |
133 | 146 | /** |
134 | - * \brief temporal data buffer to store the formatted string. | |
147 | + * \brief Handle to the transmission control task. | |
135 | 148 | */ |
136 | - char line_[PLATFORM_CONFIG_DEBUG_LINE_SIZE]; | |
149 | + murasaki::DebuggerTxTask * tx_task_; | |
150 | +#endif | |
151 | + bool auto_history_enabled; | |
137 | 152 | /** |
138 | - * \brief Handle to the transmission control task. | |
153 | + * \brief temporal data buffer to store the formatted string. | |
139 | 154 | */ |
140 | - TaskHandle_t tx_task_; | |
155 | + char line_[PLATFORM_CONFIG_DEBUG_LINE_SIZE]; | |
141 | 156 | /** |
142 | 157 | * @brief Handle to the auto history task. |
143 | 158 | */ |
@@ -78,8 +78,8 @@ class DebuggerFifo : public AbstractFifo | ||
78 | 78 | */ |
79 | 79 | struct LoggingHelpers |
80 | 80 | { |
81 | - AbstractFifo * fifo; | |
82 | - AbstractLogger * logger; | |
81 | + murasaki::DebuggerFifo * fifo; | |
82 | + murasaki::AbstractLogger * logger; | |
83 | 83 | |
84 | 84 | }; |
85 | 85 | } |