aboutsummaryrefslogtreecommitdiffstats
path: root/os/various/ch.cpp
blob: 2b23768d780d370c619e9e9b6c0c3cb577b025d3 (plain)
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
pre { line-height: 125%; margin: 0; }
td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight { background: #ffffff; }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
entity tb_iassoc01 is
end tb_iassoc01;

library ieee;
use ieee.std_logic_1164.all;

architecture behav of tb_iassoc01 is
  signal a : natural;
  signal b : natural;
  signal res : natural;
begin
  dut: entity work.iassoc01
    port map (a, b, res);

  process
  begin
    a <= 1;
    b <= 5;
    wait for 1 ns;
    assert res = 6 severity failure;

    a <= 197;
    b <= 203;
    wait for 1 ns;
    assert res = 400 severity failure;

    wait;
  end process;
end behav;
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
/*
    ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
                 2011 Giovanni Di Sirio.

    This file is part of ChibiOS/RT.

    ChibiOS/RT is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.

    ChibiOS/RT is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
/**
 * @file    ch.cpp
 * @brief   C++ wrapper code.
 *
 * @addtogroup cpp_library
 * @{
 */

#include "ch.hpp"

namespace chibios_rt {

  /*------------------------------------------------------------------------*
   * chibios_rt::System                                                     *
   *------------------------------------------------------------------------*/
  void System::Init(void) {

    chSysInit();
  }

  void System::Lock(void) {

    chSysLock();
  }

  void System::Unlock(void) {

    chSysUnlock();
  }

  systime_t System::GetTime(void) {

    return chTimeNow();
  }

  /*------------------------------------------------------------------------*
   * chibios_rt::Timer                                                      *
   *------------------------------------------------------------------------*/
  void Timer::Set(systime_t time, vtfunc_t vtfunc, void *par) {

    chVTSetI(&timer, time, vtfunc, par);
  }

  void Timer::Reset() {

    chVTResetI(&timer);
  }

  bool Timer::IsArmed(void) {

    return chVTIsArmedI(&timer);
  }

  /*------------------------------------------------------------------------*
   * chibios_rt::BaseThread                                                 *
   *------------------------------------------------------------------------*/
  static msg_t thdstart(void *arg) {

    return ((BaseThread *)arg)->Main();
  }

  BaseThread::BaseThread(void *workspace, size_t wsize, tprio_t prio) {

    thread_ref = chThdCreateStatic(workspace, wsize, prio, thdstart, this);
  }

  void BaseThread::Exit(msg_t msg) {

    chThdExit(msg);
  }

#if CH_USE_WAITEXIT
  msg_t BaseThread::Wait(void) {

    return chThdWait(thread_ref);
  }
#endif /* CH_USE_WAITEXIT */

  void BaseThread::SetPriority(tprio_t newprio) {

    chThdSetPriority(newprio);
  }

  void BaseThread::Resume(void) {

    chThdResume(thread_ref);
  }

  void BaseThread::Terminate(void) {

    chThdTerminate(thread_ref);
  }

  void BaseThread::Sleep(systime_t n) {

    chThdSleep(n);
  }

  void BaseThread::SleepUntil(systime_t time) {

    chThdSleepUntil(time);
  }

#if CH_USE_MESSAGES
  msg_t BaseThread::SendMessage(::Thread* tp, msg_t msg) {

    return chMsgSend(tp, msg);
  }

  msg_t BaseThread::SendMessage(msg_t msg) {

    return chMsgSend(thread_ref, msg);
  }

  Thread *BaseThread::WaitMessage(void) {

    return chMsgWait();
  }

  msg_t BaseThread::GetMessage(Thread* tp) {

    return chMsgGet(tp);
  }

  void BaseThread::ReleaseMessage(Thread* tp, msg_t msg) {

    chMsgRelease(tp, msg);
  }

  bool BaseThread::IsPendingMessage(void) {

    return chMsgIsPendingI(currp);
  }
#endif /* CH_USE_MESSAGES */

  msg_t BaseThread::Main(void) {

    return 0;
  }

#if CH_USE_SEMAPHORES
  /*------------------------------------------------------------------------*
   * chibios_rt::Semaphore                                                  *
   *------------------------------------------------------------------------*/
  Semaphore::Semaphore(cnt_t n) {

    chSemInit(&sem, n);
  }

  void Semaphore::Reset(cnt_t n) {

    chSemReset(&sem, n);
  }

  msg_t Semaphore::Wait(void) {

    return chSemWait(&sem);
  }

  msg_t Semaphore::WaitTimeout(systime_t time) {

    return chSemWaitTimeout(&sem, time);
  }

  void Semaphore::Signal(void) {

    chSemSignal(&sem);
  }

#if CH_USE_SEMSW
  msg_t Semaphore::SignalWait(Semaphore *ssem, Semaphore *wsem) {

    return chSemSignalWait(&ssem->sem, &wsem->sem);
  }
#endif /* CH_USE_SEMSW */
#endif /* CH_USE_SEMAPHORES */

#if CH_USE_MUTEXES
  /*------------------------------------------------------------------------*
   * chibios_rt::Mutex                                                      *
   *------------------------------------------------------------------------*/
  Mutex::Mutex(void) {

    chMtxInit(&mutex);
  }

  bool Mutex::TryLock(void) {

    return chMtxTryLock(&mutex);
  }

  void Mutex::Lock(void) {

    chMtxLock(&mutex);
  }

  void Mutex::Unlock(void) {

    chMtxUnlock();
  }

  void UnlockAll(void) {

    chMtxUnlockAll();
  }

#if CH_USE_CONDVARS
  /*------------------------------------------------------------------------*
   * chibios_rt::CondVar                                                    *
   *------------------------------------------------------------------------*/
  CondVar::CondVar(void) {

    chCondInit(&condvar);
  }

  void CondVar::Signal(void) {

    chCondSignal(&condvar);
  }

  void CondVar::Broadcast(void) {

    chCondBroadcast(&condvar);
  }

  msg_t CondVar::Wait(void) {

    return chCondWait(&condvar);
  }

#if CH_USE_CONDVARS_TIMEOUT
  msg_t CondVar::WaitTimeout(systime_t time) {

    return chCondWaitTimeout(&condvar, time);
  }
#endif /* CH_USE_CONDVARS_TIMEOUT */
#endif /* CH_USE_CONDVARS */
#endif /* CH_USE_MUTEXES */

#if CH_USE_EVENTS
  /*------------------------------------------------------------------------*
   * chibios_rt::Event                                                      *
   *------------------------------------------------------------------------*/
  Event::Event(void) {

    chEvtInit(&event);
  }

  void Event::Register(EventListener *elp, eventid_t eid) {

    chEvtRegister(&event,elp, eid);
  }

  void Event::RegisterMask(EventListener *elp, eventmask_t emask) {

    chEvtRegisterMask(&event,elp, emask);
  }

  void Event::Unregister(EventListener *elp) {

    chEvtUnregister(&event, elp);
  }

  void Event::Broadcast(void) {

    chEvtBroadcast(&event);
  }

  eventmask_t Event::ClearFlags(eventmask_t mask) {

    return chEvtClearFlags(mask);
  }

  eventmask_t Event::AddFlags(eventmask_t mask) {

    return chEvtAddFlags(mask);
  }

  void Event::Dispatch(const evhandler_t handlers[], eventmask_t mask) {

    chEvtDispatch(handlers, mask);
  }

  eventmask_t Event::WaitOne(eventmask_t ewmask) {

    return chEvtWaitOne(ewmask);
  }

  eventmask_t Event::WaitAny(eventmask_t ewmask) {

    return chEvtWaitAny(ewmask);
  }

  eventmask_t Event::WaitAll(eventmask_t ewmask) {

    return chEvtWaitAll(ewmask);
  }

#if CH_USE_EVENTS_TIMEOUT
  eventmask_t Event::WaitOneTimeout(eventmask_t ewmask, systime_t time) {

    return chEvtWaitOneTimeout(ewmask, time);
  }

  eventmask_t Event::WaitAnyTimeout(eventmask_t ewmask, systime_t time) {

    return chEvtWaitAnyTimeout(ewmask, time);
  }

  eventmask_t Event::WaitAllTimeout(eventmask_t ewmask, systime_t time) {

    return chEvtWaitAllTimeout(ewmask, time);
  }
#endif /* CH_USE_EVENTS_TIMEOUT */
#endif /* CH_USE_EVENTS */
}

/** @} */