A SystemC productivity library for virtual platform development utilizing SCV and TLM2.0 https://www.minres.com/#opensource

time2tick.h 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*******************************************************************************
  2. * Copyright 2018 MINRES Technologies GmbH
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *******************************************************************************/
  16. #ifndef _SCC_TIME2TICK_H_
  17. #define _SCC_TIME2TICK_H_
  18. #include "utilities.h"
  19. namespace scc {
  20. /**
  21. * translate a tick-less clock (sc_time based) to boolean clock
  22. */
  23. struct time2tick : public sc_core::sc_module {
  24. //! yes, we have processes
  25. SC_HAS_PROCESS(time2tick);// NOLINT
  26. //! the clock input
  27. sc_core::sc_in<sc_core::sc_time> clk_i;
  28. //! the clock output
  29. sc_core::sc_out<bool> clk_o;
  30. /**
  31. * the constructor
  32. *
  33. * @param nm
  34. */
  35. explicit time2tick(sc_core::sc_module_name nm)
  36. : sc_core::sc_module(nm) {
  37. SC_THREAD(clocker);
  38. }
  39. private:
  40. sc_core::sc_time clk_period;
  41. void clocker() {
  42. while (true) {
  43. auto t = clk_i.read();
  44. if (t == sc_core::SC_ZERO_TIME) {
  45. wait(clk_i.value_changed_event());
  46. t = clk_i.read();
  47. }
  48. clk_o = true;
  49. wait(t / 2);
  50. clk_o = false;
  51. wait(t - t / 2);
  52. }
  53. }
  54. };
  55. }
  56. #endif /* _SCC_TIME2TICK_H_ */