Exemple #1
0
int svc_send_event(enum svc_event event, void *parameter0, void *parameter1, void *parameter2) {
    llvdbg("event: %s (%d), %p %p %p\n",
         svc_event_to_string(event), event,
         parameter0,
         parameter1,
         parameter2);

    struct svc_work *svc_work = (struct svc_work *)kmm_zalloc(sizeof(*svc_work));
    if (!svc_work) {
        lldbg("ERROR: failed to alloc work: errno=%d\n", get_errno());
        return -1;
    }

    svc_work->svc = &g_svc;
    svc_work->event = event;
    svc_work->parameter0 = parameter0;
    svc_work->parameter1 = parameter1;
    svc_work->parameter2 = parameter2;

    int ret = work_queue(HPWORK, &svc_work->work, svc_work_callback, svc_work, 0 /* delay */);
    if (ret) {
        lldbg("ERROR: failed to queue work: errno=%d\n", get_errno());
        return ret;
    }

    return ret;
}
Exemple #2
0
/**
 * @fn                  :tc_libc_misc_llvdbg
 * @brief               :This is intended for general debug output that is normally suppressed.
 * @scenario            :When debug out is required with all details
 * @API's covered       :llvdbg
 * @Preconditions       :None
 * @Postconditions      :None
 * @Return              :void
 */
static void tc_libc_misc_llvdbg(void)
{
	int ret_chk = -1;
	const char *msg_output = "tc_libc_misc_llvdbg: Examples";
	/*
	   in debug.h file llvdbg is defined as :
	   # define EXTRA_FMT "%s: "
	   # define EXTRA_ARG ,__FUNCTION__
	   # define llvdbg(format, ...) \
	   lowsyslog(LOG_DEBUG, EXTRA_FMT format EXTRA_ARG, ##__VA_ARGS__)
	 */

	/* Message displayed is:  "tc_libc_misc_llvdbg: Examples" */

	usleep(USEC_100);
	ret_chk = llvdbg("Examples");
	TC_ASSERT_EQ("llvdbg", ret_chk, strlen(msg_output));

	TC_SUCCESS_RESULT();
}
Exemple #3
0
static void up_idlepm(void)
{
  static enum pm_state_e oldstate = PM_NORMAL;
  enum pm_state_e newstate;
  irqstate_t flags;
  int ret;

  /* Decide, which power saving level can be obtained */

  newstate = pm_checkstate();

  /* Check for state changes */

  if (newstate != oldstate)
    {
      flags = irqsave();

      /* Perform board-specific, state-dependent logic here */

      llvdbg("newstate= %d oldstate=%d\n", newstate, oldstate);

      /* Then force the global state change */

      ret = pm_changestate(newstate);
      if (ret < 0)
        {
          /* The new state change failed, revert to the preceding state */

          (void)pm_changestate(oldstate);
        }
      else
        {
          /* Save the new state */

          oldstate = newstate;
        }

      /* MCU-specific power management logic */

      switch (newstate)
        {
        case PM_NORMAL:
          break;

        case PM_IDLE:
          break;

        case PM_STANDBY:
          lpc43_pmstandby(true);
          break;

        case PM_SLEEP:
          (void)lpc43_pmsleep();
          break;

        default:
          break;
        }

      irqrestore(flags);
    }
}
Exemple #4
0
static void stm32_idlepm(void)
{
  static enum pm_state_e oldstate = PM_NORMAL;
  enum pm_state_e newstate;
  int ret;

  /* The following is logic that is done after the wake-up from PM_STANDBY
   * state.  It decides whether to go back to the PM_NORMAL or to the deeper
   * power-saving mode PM_SLEEP:  If the alarm expired with no "normal"
   * wake-up event, then PM_SLEEP is entered.
   *
   * Logically, this code belongs at the end of the PM_STANDBY case below,
   * does not work in the position for some unkown reason.
   */

  if (oldstate == PM_STANDBY)
    {
      /* Were we awakened by the alarm? */

#ifdef CONFIG_RTC_ALARM
      if (g_alarmwakeup)
        {
          /* Yes.. Go to SLEEP mode */

          newstate = PM_SLEEP;
        }
      else
#endif
        {
          /* Resume normal operation */

          newstate = PM_NORMAL;
        }
    }
  else
    {
      /* Let the PM system decide, which power saving level can be obtained */

      newstate = pm_checkstate();
    }

  /* Check for state changes */

  if (newstate != oldstate)
    {
      llvdbg("newstate= %d oldstate=%d\n", newstate, oldstate);

      sched_lock();

      /* Force the global state change */

      ret = pm_changestate(newstate);
      if (ret < 0)
        {
          /* The new state change failed, revert to the preceding state */

          (void)pm_changestate(oldstate);

          /* No state change... */

          goto errout;
        }

      /* Then perform board-specific, state-dependent logic here */

      switch (newstate)
        {
        case PM_NORMAL:
          {
            /* If we just awakened from PM_STANDBY mode, then reconfigure
             * clocking.
             */

            if (oldstate == PM_STANDBY)
              {
                /* Re-enable clocking */

                stm32_clockenable();

                /* The system timer was disabled while in PM_STANDBY or
                 * PM_SLEEP modes.  But the RTC has still be running:  Reset
                 * the system time the current RTC time.
                 */

#ifdef CONFIG_RTC
                clock_synchronize();
#endif
              }
          }
          break;

        case PM_IDLE:
          {
          }
          break;

        case PM_STANDBY:
          {
            /* Set the alarm as an EXTI Line */

#ifdef CONFIG_RTC_ALARM
            stm32_rtc_alarm(CONFIG_PM_ALARM_SEC, CONFIG_PM_ALARM_NSEC, true);
#endif
            /* Wait 10ms */

            up_mdelay(10);

            /* Enter the STM32 stop mode */

            (void)stm32_pmstop(false);

            /* We have been re-awakened by some even:  A button press?
             * An alarm?  Cancel any pending alarm and resume the normal
             * operation.
             */

#ifdef CONFIG_RTC_ALARM
            stm32_exti_cancel();
            ret = stm32_rtc_cancelalarm();
            if (ret < 0)
              {
                lldbg("Warning: Cancel alarm failed\n");
              }
#endif
            /* Note:  See the additional PM_STANDBY related logic at the
             * beginning of this function.  That logic is executed after
             * this point.
             */
          }
          break;

        case PM_SLEEP:
          {
            /* We should not return from standby mode.  The only way out
             * of standby is via the reset path.
             */

            /* Configure the RTC alarm to Auto Reset the system */

#ifdef CONFIG_PM_SLEEP_WAKEUP
            stm32_rtc_alarm(CONFIG_PM_SLEEP_WAKEUP_SEC, CONFIG_PM_SLEEP_WAKEUP_NSEC, false);
#endif
            /* Wait 10ms */

            up_mdelay(10);

            /* Enter the STM32 standby mode */

            (void)stm32_pmstandby();
          }
          break;

        default:
          break;
        }

      /* Save the new state */

      oldstate = newstate;

errout:
      sched_unlock();
    }
}
Exemple #5
0
/* IMPORTANT:
 * The UniPro event handler callback runs in the context of the UniPro IRQ. */
static void unipro_evt_handler(enum unipro_event evt)
{
    uint32_t rc;
    uint32_t v = 0;
    int err;

    llvdbg("event=%d\n", evt);

    switch (evt) {
    case UNIPRO_EVT_LUP_DONE:
        svc_send_event(SVC_EVENT_UNIPRO_LINK_UP, 0, 0, 0);
        break;
    case UNIPRO_EVT_LINK_LOST:
        rc = unipro_attr_local_read(TSB_DME_LINKLOSTIND, &v, 0);
        llvdbg("rc=%d, lost_ind=%x\n", rc, v);

        if (v & 0x1) {
            svc_send_event(SVC_EVENT_UNIPRO_LINK_DOWN,
                (void *)(unsigned int)0,
                (void *)(unsigned int)0,
                (void *)(unsigned int)0);
        }

        break;
    case UNIPRO_EVT_PWRMODE:
        if (g_svc.gearbox) {
            uint32_t pmi_val0 = 0;
            rc = unipro_attr_read(TSB_DME_POWERMODEIND, &pmi_val0, 0, 0);
            llvdbg("rc=%d, pmi0=%x\n", rc, pmi_val0);

            uint32_t pmi_val1 = 0;
            rc = unipro_attr_read(TSB_DME_POWERMODEIND, &pmi_val1, 0, 1);
            llvdbg("rc=%d, pmi1=%x\n", rc, pmi_val1);

            if (pmi_val0 == 2 && pmi_val1 == 4) {
                llvdbg("Powermode change successful\n");
                err = 0;
            } else {
                llvdbg("Powermode change failed\n");
                err = -1;
            }

            svc_send_event(SVC_EVENT_GEAR_SHIFT_DONE,
                (void *)(unsigned int)err,
                (void *)(unsigned int)0,
                (void *)(unsigned int)0);
        }
        break;
    case UNIPRO_EVT_PHY_ERROR:
        rc = unipro_attr_local_read(TSB_DME_ERRORPHYIND, &v, 0);
        v &= 1;
        if (v) {
            llvdbg("rc=%d, phy err=%x\n", rc, v);
            _svc_bitmask_to_stats(&g_unipro_stats.phy_lane_err, v);
        }
        break;
    case UNIPRO_EVT_PA_ERROR:
        rc = unipro_attr_local_read(TSB_DME_ERRORPAIND, &v, 0);
        v &= 0x3;
        if (v) {
            llvdbg("rc=%d, pa err=%x\n", rc, v);
            _svc_bitmask_to_stats(&g_unipro_stats.pa_lane_reset_tx, v);
        }
        break;
    case UNIPRO_EVT_D_ERROR:
        rc = unipro_attr_local_read(TSB_DME_ERRORDIND, &v, 0);
        v &= 0x7fff;
        if (v) {
            llvdbg("rc=%d, d err=%x\n", rc, v);
            _svc_bitmask_to_stats(&g_unipro_stats.d_nac_received, v);
        }
        break;
    case UNIPRO_EVT_N_ERROR:
        rc = unipro_attr_local_read(TSB_DME_ERRORNIND, &v, 0);
        v &= 0x7;
        if (v) {
            llvdbg("rc=%d, n err=%x\n", rc, v);
            _svc_bitmask_to_stats(&g_unipro_stats.n_unsupported_header_type, v);
        }
        break;
    case UNIPRO_EVT_T_ERROR:
        rc = unipro_attr_local_read(TSB_DME_ERRORTIND, &v, 0);
        v &= 0x7f;
        if (v) {
            llvdbg("rc=%d, t err=%x\n", rc, v);
            _svc_bitmask_to_stats(&g_unipro_stats.t_unsupported_header_type, v);
        }
        break;
    case UNIPRO_EVT_PAINIT_ERROR: {
        bool lost = false;

        rc = unipro_attr_local_read(TSB_DME_ERRORPHYIND, &v, 0);
        v &= 0x1;
        if (v) {
            llvdbg("rc=%d, phy err=%x\n", rc, v);
            _svc_bitmask_to_stats(&g_unipro_stats.phy_lane_err, v);
            lost = true;
        }

        rc = unipro_attr_local_read(TSB_DME_ERRORPAIND, &v, 0);
        v &= 0x3;
        if (v) {
            llvdbg("rc=%d, pa err=%x\n", rc, v);
            _svc_bitmask_to_stats(&g_unipro_stats.pa_lane_reset_tx, v);
            lost = true;
        }

        rc = unipro_attr_local_read(TSB_DME_ERRORDIND, &v, 0);
        v &= 0x7fff;
        if (v) {
            llvdbg("rc=%d, d err=%x\n", rc, v);
            _svc_bitmask_to_stats(&g_unipro_stats.d_nac_received, v);
            lost = true;
        }

        if (lost) {
            llvdbg("Link lost\n");
            svc_send_event(SVC_EVENT_UNIPRO_LINK_DOWN,
                (void *)(unsigned int)0,
                (void *)(unsigned int)0,
                (void *)(unsigned int)0);
        }

        break;
    }
    case UNIPRO_EVT_MAILBOX: {
        v = TSB_MAIL_RESET;
        rc = unipro_attr_local_read(TSB_MAILBOX, &v, 0);
        llvdbg("rc=%d, mbox_val=%d\n", rc, v);

        if (rc) {
        }

#if CONFIG_UNIPRO_P2P_APBA
        if (v == TSB_MAIL_READY_OTHER) {
            llvdbg("Mod detected\n");
            svc_send_event(SVC_EVENT_MOD_DETECTED,
                (void *)(unsigned int)0,
                (void *)(unsigned int)0,
                (void *)(unsigned int)0);
        } else {
            // TODO: Handle error case.
            llvdbg("Mod NOT detected\n");
        }
#elif CONFIG_UNIPRO_P2P_APBE
        llvdbg("Connected cport %d\n", v-1);
        svc_send_event(SVC_EVENT_CPORTS_DONE, (void *)(v-1), 0, 0);
#endif

        break;
    }
    default:
        break;
    }

    vdbg("done\n");
}