• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

shared_fooの不要ディレクトリ削除前のもの


Commit MetaInfo

Revision563c3277e232a9ac0a0b6fa31101c9913f2d7b42 (tree)
Time2018-03-03 15:55:47
Authortakemasa <suikan@user...>
Commitertakemasa

Log Message

Removed ifdef

Change Summary

Incremental Difference

--- a/stm32_development/murasaki/murasaki/debugger.cpp
+++ b/stm32_development/murasaki/murasaki/debugger.cpp
@@ -22,31 +22,13 @@ Debugger::Debugger(AbstractLogger * logger)
2222 // initialize internal variable;
2323 MURASAKI_ASSERT(logger != nullptr)
2424
25- auto_history_enabled = false;
26- auto_history_task_ = nullptr;
27-
28-#ifdef OLDIMPLEMENTATION
29- logger_ = logger;
30- sem_notify_new_data_ = ::xSemaphoreCreateBinary(); // create semaphore as "empty" state
31- MURASAKI_ASSERT(sem_notify_new_data_);
32-
33- // set the circular buffer empty.
34- head_ = 0;
35- tail_ = 0;
36-
37- for (unsigned int i = 0; i < sizeof(buffer_); i++)
38- buffer_[i] = ' ';
39- // start the debug task
40- BaseType_t task_result = ::xTaskCreate(
41- Debugger::LaunchTxTask, // task entity;
42- "DebugTask", // name of task
43- PLATFORM_CONFIG_DEBUG_TASK_STACK_SIZE, // stack depth
44- this, // parameter to task
45- PLATFORM_CONFIG_DEBUG_TASK_PRIORITY, // execusion priority of task
46- &tx_task_ // receive task handle
47- );
48- MURASAKI_ASSERT(task_result != errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY);
49-#else
25+
26+ helpers_.fifo = nullptr;
27+ tx_task_ = nullptr;
28+
29+ auto_reprint_enable_ = false;
30+ auto_reprint_task = nullptr;
31+
5032 helpers_.fifo = new murasaki::DebuggerFifo(PLATFORM_CONFIG_DEBUG_BUFFER_SIZE);
5133 helpers_.logger = logger;
5234
@@ -59,66 +41,25 @@ Debugger::Debugger(AbstractLogger * logger)
5941
6042 tx_task_->Start();
6143
62-#endif
6344 }
6445
6546 Debugger::~Debugger()
6647 {
67-#ifdef OLDIMPLEMENTATION
6848 // Delete task;
6949 if (tx_task_ != nullptr)
70- ::vTaskDelete(tx_task_);
50+ delete tx_task_;
7151
7252 // Delete task;
73- if (auto_history_task_ != nullptr)
74- ::vTaskDelete(auto_history_task_);
53+ if (auto_reprint_task != nullptr)
54+ delete auto_reprint_task;
7555
76- // Delete semaphore.
77- if (sem_notify_new_data_ != nullptr)
78- ::vSemaphoreDelete( sem_notify_new_data_);
79-#else
80-#endif
56+ // Delete FIFO
57+ if (helpers_.fifo != nullptr)
58+ delete helpers_.fifo;
8159 }
8260
8361 void Debugger::printf(const char * fmt, ...)
8462 {
85-#ifdef OLDIMPLEMENTATION
86- // obtain variable parameter list
87- va_list argp;
88-
89- MURASAKI_ASSERT(nullptr != fmt); // nullptr check. Perhaps, overkill.
90-
91- portDISABLE_INTERRUPTS(); // ARM dependent API. OK to use in task and ISR.
92- {
93-#if 0
94- // Test the remains of task stack in byte.
95- // To use the uxTaskGetStackHighWaterMark(), Add following to the
96- // FreeRTOSConfig.h
97- // #define INCLUDE_uxTaskGetStackHighWaterMark 1
98-
99- ::snprintf((char *) line_,
100- sizeof(line_) - 1,
101- "stack remains : %8d bytes. ",
102- (int) uxTaskGetStackHighWaterMark(tx_task_));
103- AppendToBuffer();
104-#endif
105- ::va_start(argp, fmt);
106- // convert the number with formt string to the line string.
107- // The string length have to be N - 1. Where N is the length of the destination variable.
108- ::vsnprintf((char *) line_, sizeof(line_) - 1, fmt, argp);
109-
110- ::va_end(argp);
111- // Append the line to the buffer to be sent.
112- AppendToBuffer();
113- }
114- portENABLE_INTERRUPTS();
115-
116- // Notify to the consumer task, the new data has come.
117- if (isTaskContext()) // Are we in the task context?
118- ::xSemaphoreGive(sem_notify_new_data_); // if yes
119- else
120- ::xSemaphoreGiveFromISR(sem_notify_new_data_, nullptr); // if no.
121-#else
12263 // obtain variable parameter list
12364 va_list argp;
12465
@@ -152,56 +93,16 @@ void Debugger::printf(const char * fmt, ...)
15293
15394 // Notify to the consumer task, the new data has come.
15495 helpers_.fifo->NotifyData();
155-#endif
15696
15797 }
15898
15999 char Debugger::GetchFromTask()
160100 {
161101 MURASAKI_ASSERT(isTaskContext());
162-#ifdef OLDIMPLEMENTATION
163- return logger_->getCharacter(); // receive successfuly.
164-#else
102+
165103 return helpers_.logger->getCharacter();
166-#endif
167104 }
168105
169-// Assumes this is called only in the critical section.
170-void Debugger::AppendToBuffer()
171-{
172-#ifdef OLDIMPLEMENTATION
173- unsigned int avairable;
174-
175- // check the avairable area size. Data is append to the head
176- if (head_ > tail_) // there is no wrap around
177- avairable = sizeof(buffer_) - (head_ - tail_);
178- else if (tail_ > head_)
179- avairable = tail_ - head_;
180- else
181- avairable = sizeof(buffer_);
182-
183- // If we fill up buffer entirely, we can not distinguish full and empty from the
184- // comparing tail_ and head_.
185- // This can be fixed if we add new variable "length", but it get complex.
186- // To save this problem, we clip the vacant size by buffsersize-1.
187- if (avairable > 0)
188- avairable--;
189-
190- // clip the line size by available room in the buffer.
191- int line_length = std::min(::strlen((char *) line_), avairable);
192-
193- // Now, we can copy from line to buffer.
194- for (int i = 0; i < line_length; i++) {
195- // newest data is appended to the point of head_
196- buffer_[head_] = line_[i];
197- head_++;
198-
199- // wrap around the head index;
200- if (head_ >= sizeof(buffer_))
201- head_ = 0;
202- } // end for loop.
203-#endif
204-}
205106
206107
207108 /*
@@ -210,46 +111,15 @@ void Debugger::AppendToBuffer()
210111 */
211112 void Debugger::RePrint()
212113 {
213-#ifdef OLDIMPLEMENTATION
214- MURASAKI_ASSERT(isTaskContext());
215-
216- taskENTER_CRITICAL();
217- {
218- // Mark the all old data as "not sent"
219- // By setting the circular buffer length maximumn.
220- tail_ = head_ + 1;
221- // wrap around the tail_index;
222- if (tail_ >= sizeof(buffer_))
223- tail_ = 0;
224- }
225- taskEXIT_CRITICAL();
226-
227- // tell there is data
228- ::xSemaphoreGive(sem_notify_new_data_);
229-#else
230114 helpers_.fifo->ReWind();
231-#endif
232115 }
233116
234117 void Debugger::AutoHistory()
235118 {
236119 MURASAKI_ASSERT(isTaskContext());
237120 // protecting from double task creation
238- if (auto_history_enabled)
121+ if (auto_reprint_enable_)
239122 return;
240-#ifdef OLDIMPLEMENTATION
241-
242- // start the debug task
243- BaseType_t task_result = ::xTaskCreate(Debugger::LaunchAutoHistoryTask, // task entity;
244- "AutoHistoryTask", // name of task
245- PLATFORM_CONFIG_DEBUG_TASK_STACK_SIZE, // stack depth
246- this, // parameter to task
247- PLATFORM_CONFIG_DEBUG_TASK_PRIORITY, // execusion priority of task
248- &auto_history_task_ // receive task handle
249- );
250- MURASAKI_ASSERT(task_result != errCOULD_NOT_ALLOCATE_REQUIRED_MEMORY);
251-
252-#else
253123 auto_reprint_task = new murasaki::DebuggerAutoRePrintTask("DebugTask", // name of task
254124 PLATFORM_CONFIG_DEBUG_TASK_STACK_SIZE, // stack depth
255125 PLATFORM_CONFIG_DEBUG_TASK_PRIORITY, // execusion priority of task
@@ -259,94 +129,8 @@ void Debugger::AutoHistory()
259129
260130 auto_reprint_task->Start();
261131
262-#endif
263- auto_history_enabled = true;
264-}
265-
266-void Debugger::LaunchAutoHistoryTask(void* this_pointer)
267-{
268- MURASAKI_ASSERT(nullptr != this_pointer);
269-
270- // This is "interface class method" to allow to use a private method as task.
271- // The caller passes the "this" pointer as parameter.
272- // The caller is always "Debug" task.
273- // The AutoHistoryTask() is private and task body.
274- static_cast<Debugger *>(this_pointer)->AutoHistoryTask();
275-
276-}
277-
278-void Debugger::AutoHistoryTask()
279-{
280- MURASAKI_ASSERT(isTaskContext());
281- // Task body. Never return.
282- while (true) {
283- // wait for the arraival of inpu
284- GetchFromTask();
285- // flush old data.
286- RePrint();
287- } // end of while loop.
288-
132+ auto_reprint_enable_ = true;
289133 }
290134
291135
292-void Debugger::LaunchTxTask(void * this_pointer)
293-{
294- MURASAKI_ASSERT(nullptr != this_pointer);
295- // This is "interface class method" to allow to use a private method as task.
296- // The caller passes the "this" pointer as parameter.
297- // The caller is always "Debug" task.
298- // The txTask() is private and task body.
299- static_cast<Debugger *>(this_pointer)->TxTask();
300-}
301-
302-#define BLOCK_SIZE 50
303-void Debugger::TxTask()
304-{
305-#ifdef OLDIMPLEMENTATION
306- unsigned int copy_size = 0;
307- uint8_t block[BLOCK_SIZE];
308-
309- // Task body. Never return.
310- while (true) {
311- // To avoid race condition, Take a snapshot of the head_ and tail_ pointer.
312- // head_ could be modified during this task is running but no problem.
313- taskENTER_CRITICAL();
314- {
315- // check whether the data area is wrapped araound at the end of buffer. Note : Data is added to the head.
316- if (head_ > tail_) { // not wrapped around
317- // transmit at largest one block
318- copy_size = std::min(sizeof(block), head_ - tail_);
319- ::memcpy(block, &buffer_[tail_], copy_size);
320- // update tail. Wrap around never occur.
321- tail_ += copy_size;
322- }
323- else if (tail_ > head_) { // wrapped arraound
324- // transmit at largest one block
325- copy_size = std::min(sizeof(block), sizeof(buffer_) - tail_);
326- ::memcpy(block, &buffer_[tail_], copy_size);
327- // update tail.
328- tail_ += copy_size;
329-
330- // if tail_ reaches the end, wrap around.
331- if (tail_ >= sizeof(buffer_))
332- tail_ = 0;
333- }
334- else
335- // head_ == tail_ . Do nothing.
336- copy_size = 0;
337- }
338- taskEXIT_CRITICAL();
339-
340- if (copy_size != 0) // if copied
341- logger_->putMessage((char *) block, copy_size);
342- else
343- // if head_ == tail_
344- // Wait for the arrival of the new data because buffer empty.
345- // To avoid race condition, we use time out.
346- ::xSemaphoreTake(sem_notify_new_data_, 1000 / portTICK_PERIOD_MS );
347-
348- } // end of while loop.
349-#endif
350-}
351-
352136 } /* namespace platform */
--- a/stm32_development/murasaki/murasaki/debugger.hpp
+++ b/stm32_development/murasaki/murasaki/debugger.hpp
@@ -18,14 +18,9 @@
1818 #include "murasaki_config.hpp"
1919 #include "abstractlogger.hpp"
2020
21-//#define OLDIMPLEMENTATION
22-
23-#ifdef OLDIMPLEMENTATION
24-#else
2521 #include "debuggerfifo.hpp"
2622 #include "debuggertxtask.hpp"
2723 #include "debuggerautoreprinttask.hpp"
28-#endif
2924
3025 namespace murasaki {
3126
@@ -118,114 +113,33 @@ class Debugger
118113 */
119114 void AutoHistory();
120115 protected:
121-#ifdef OLDIMPLEMENTATION
122- /**
123- * \brief A pointer to the logger class.
124- */
125- AbstractLogger* logger_;
126- /**
127- * @brief For protecting from the double creating of the internal task.
128- */
129- /**
130- * \brief Transmission notification semaphore.
131- * \details
132- * This semaphoere is initialized as binary semaphore, and applied as data avairable
133- * notification. Whenever the printf() method added new data to the buffer_, a nothification
134- * is given through this semaphore.
135- */
136- /**
137- * \brief Handle to the transmission control task.
138- */
139- TaskHandle_t tx_task_;
140- SemaphoreHandle_t sem_notify_new_data_;
141- /**
142- * \brief transmission data circular buffer.
143- */
144- char buffer_[PLATFORM_CONFIG_DEBUG_BUFFER_SIZE];
145-#else
146116 murasaki::LoggingHelpers helpers_;
147117 /**
148118 * \brief Handle to the transmission control task.
149119 */
150120 murasaki::DebuggerTxTask * tx_task_;
151121
152- murasaki::DebuggerAutoRePrintTask * auto_reprint_task;
153-#endif
154- bool auto_history_enabled;
155- /**
156- * \brief temporal data buffer to store the formatted string.
157- */
158- char line_[PLATFORM_CONFIG_DEBUG_LINE_SIZE];
159122 /**
160123 * @brief Handle to the auto history task.
161124 */
162- TaskHandle_t auto_history_task_;
163- /**
164- * \brief Index of the "next of " newest data in the buffer.
165- * \details
166- * Pointing the location which the next new data will be stored.
167- *
168- * In case of the empty buffer, this index is same with the tail_.
169- */
170- volatile unsigned int head_;
171- /**
172- * \brief Index of the oldest data in the buffer.
173- * \details
174- * Pointing the location where the next data to be read.
175- *
176- * In case of the empty buffer, this index is same with the head_.
177- */
178- volatile unsigned int tail_;
125+ murasaki::DebuggerAutoRePrintTask * auto_reprint_task;
179126
180127 /**
181- * \brief Wrapper of the txTask.
182- * \param this_pointer The this pointer of the caller object have to be passed.
183- * \details
184- *
185- * Wrapper of the txTask() method. The txTask() is the private method. Then, it is
186- * unable to pass to the FreeRTOS API, while we have to pass that to run a task.
187- *
188- * To solve this problem, this wrapper method is declared as class method. The
189- * this pointer have to be passed to the this_pointer parameter.
190- *
191- * This method is dedicated to use in the constructor. User doesn't need to touch
128+ * @brief For protecting from double enabled.
192129 */
193- static void LaunchTxTask(void * this_pointer);
194-
195- /*
196- *
197- * Wrapper of the AutoHistoryTask
198- */
199- static void LaunchAutoHistoryTask(void * this_pointer);
130+ bool auto_reprint_enable_;
200131
201132 /**
202- * \brief Task body
203- * \details
204- * The task bordy of the transmission task. This method is called from launchTxTas(), and
205- * never returns.
206- *
207- * This task test the head_ and tail_ and if the length is not one, try to transmit
208- * the data inside buffer, throuth the uart.
133+ * @brief as receiver for the snprintf()
134+ * @details
135+ * This variable can be local variable of the printf() member function.
136+ * In thiss case, the implementation of the printf() is much easier.
137+ * In the other hand, each task must has enough depth on its task stack.
209138 *
210- * If there is no data, this task wait for the new data to transmit by sem_notify_new_data_
211- * semaphore. In parallel to this waiting, it polls the data buffer length by time out
212- * of semaphore. This polling is essential, because perfect exclusive access and synchronization
213- * is expensive.
214- */
215- void TxTask();
216-
217- /*
218- * Task to watch the receive character and trigger the history.
139+ * Probably, having bigger task for each task doesn't pay, and it may cuase stack overflow bug
140+ * at the debug or assertion. This is not preferable.
219141 */
220- void AutoHistoryTask();
221- /**
222- * \brief Copy the data in line_ to the buffer_
223- * \details
224- * This helper method copies the data from line_ into the buffer. And then, udpate the
225- * head_ index. In case the vacant area is not enough to copy entire data in line_,
226- * This method transfer as long as possible, and returns.
227- */
228- void AppendToBuffer();
142+ char line_[PLATFORM_CONFIG_DEBUG_LINE_SIZE];
229143
230144 };
231145