Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ wrapper 18.2.1 #11

Open
wants to merge 9 commits into
base: master-18.2.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions common/ports/ARMCMx/compilers/GCC/rules_code_cortexm0.ld
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ SECTIONS
PROVIDE(__startup_start = .);
KEEP(*(.vectors))
PROVIDE(__startup_end = .);
} > VECTORS_FLASH AT > VECTORS_FLASH_LMA
} > VECTORS_RAM AT > VECTORS_FLASH_LMA

.xtors : ALIGN(4)
{
Expand All @@ -39,7 +39,7 @@ SECTIONS
__fini_array_end = .;
} > XTORS_FLASH AT > XTORS_FLASH_LMA

.initcall ALIGN(16)
.initcall : ALIGN(16)
{
__module_initcall_start = .;
KEEP(*(SORT(.initcall.*)))
Expand Down
6 changes: 3 additions & 3 deletions common/ports/ARMCMx/compilers/GCC/rules_cortexm0.ld
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* Stack rules inclusion.*/
INCLUDE rules_stacks.ld

/* Code rules inclusion.*/
INCLUDE rules_code_cortexm0.ld

/* Stack rules inclusion.*/
INCLUDE rules_stacks.ld

/* Data rules inclusion.*/
INCLUDE rules_data.ld
33 changes: 33 additions & 0 deletions various/cpp_wrappers/module.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "ch.hpp"

#ifndef Module_H_
#define Module_H_

namespace qos {

class Module
{
public:
Module(){}
virtual void Init() = 0;
virtual void Start() = 0;
virtual void Shutdown() = 0;
};

}

#endif /* QOS_H_ */
44 changes: 44 additions & 0 deletions various/cpp_wrappers/module_init_cpp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#ifndef MODULE_INIT_CPP_H_
#define MODULE_INIT_CPP_H_

#include "module_init.h"

namespace qos {
template<typename T>
class ModuleInit
{
public:
static void Init()
{
T::GetInstance()->Init();
}

static void Start()
{
T::GetInstance()->Start();
}

static void Shutdown()
{
T::GetInstance()->Shutdown();
}
};

}


#endif /* MODULE_INIT_CPP_H_ */
20 changes: 20 additions & 0 deletions various/cpp_wrappers/qos.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "qos.h"


namespace qos {

}
25 changes: 25 additions & 0 deletions various/cpp_wrappers/qos.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "ch.hpp"

#ifndef QOS_H_
#define QOS_H_

namespace qos {


}

#endif /* QOS_H_ */
4 changes: 4 additions & 0 deletions various/cpp_wrappers/qoscpp.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# C++ wrapper files.
QOSCPPSRC = $(QOS_DIR)/various/cpp_wrappers/qos.cpp

QOSCPPINC = $(QOS_DIR)/various/cpp_wrappers/
36 changes: 36 additions & 0 deletions various/cpp_wrappers/singleton.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "ch.hpp"

#ifndef _SINGLETON_H_
#define _SINGLETON_H_

namespace qos {

template <typename T>
class Singleton
{
public:
static T* GetInstance()
{
return &instance;
}

protected:
static T instance;
};
}

#endif /* _SINGLETON_H_ */
72 changes: 72 additions & 0 deletions various/cpp_wrappers/threadedmodule.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "ch.hpp"
#include "module.h"

#ifndef THREADED_MODULE_H_
#define THREADED_MODULE_H_

namespace qos {

template <int N>
class ThreadedModule : public Module
{
public:

virtual void Start()
{
m_moduleThread.SetModule(this);
m_moduleThread.start(GetThreadPrio());
}

virtual void Shutdown()
{
m_moduleThread.shouldTerminate();
}

protected:
virtual tprio_t GetThreadPrio() const = 0;

virtual void ThreadMain() = 0;

class ModuleThread : public chibios_rt::BaseStaticThread<N>
{
public:
ModuleThread() :
module(NULL)
{

}

void SetModule(ThreadedModule* mod)
{
module = mod;
}

protected:
virtual void main()
{
module->ThreadMain();
}

private:
ThreadedModule* module;
};

ModuleThread m_moduleThread;
};
}

#endif /* THREADED_MODULE_H_ */