Example #1
0
static boolean Ifx_Shell_writeResult(Ifx_Shell *shell, Ifx_SizeT Code)
{
    Ifx_SizeT length = sizeof(Code);
    boolean   result = IfxStdIf_DPipe_write(shell->io, &Code, &length, TIME_INFINITE);

    IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, result != FALSE);

    return result;
}
void IfxStdIf_DPipe_print(IfxStdIf_DPipe *stdif, pchar format, ...)
{
    if (!stdif->txDisabled)
    {
        char      message[STDIF_DPIPE_MAX_PRINT_SIZE + 1];
        Ifx_SizeT count;
        va_list   args;
        va_start(args, format);
        vsprintf((char *)message, format, args);
        va_end(args);
        count = (Ifx_SizeT)strlen(message);
        IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, count < STDIF_DPIPE_MAX_PRINT_SIZE);
        //return
        IfxStdIf_DPipe_write(stdif, (void *)message, &count, TIME_INFINITE);
    }
    else
    {
        //return TRUE;
    }
}
Example #3
0
void Ifx_Shell_process(Ifx_Shell *shell)
{
    Ifx_SizeT          i, j;           /* Loop variables */
    Ifx_SizeT          count;
    Ifx_SizeT          readCount;
    boolean            NormalKeyPress; /* Indicates if this is a normal keypress, i.e. not part of an escape code */

    Ifx_Shell_CmdLine *Cmd         = &shell->cmd;
    char              *inputbuffer = shell->locals.inputbuffer;
    char              *cmdStr      = shell->locals.cmdStr;
    char             **CmdHistory  = shell->cmdHistory;

    if (shell->control.enabled == 0)
    {
        return;
    }

    if ((shell->protocol.object != NULL_PTR) && (shell->protocol.started != FALSE))
    {
        shell->protocol.execute(shell->protocol.object);
    }
    else
    {
        /**** NORMAL MODE ****/

        /********************************************************************************/
        /* Read all characters until enter inclusive.                                   */
        /* If the command is bigger than IFX_SHELL_CMD_SIZE, the command is ignored.    */
        /*                                                                              */
        /* Escape sequences are handled by a state machine.                             */
        /* The following escape sequences (prefix "ESC [") are supported:               */
        /*                                                                              */
        /* A  - up      B - down       C - right     D - left                           */
        /* 1~ - HOME   2~ - INSERT    3~ - DELETE   5~ - END                            */
        /*                                                                              */
        /* Backspace ('\b') is also supported.                                          */
        /********************************************************************************/

        count     = 0;
        readCount = IFX_SHELL_CMD_LINE_SIZE - count;
        IfxStdIf_DPipe_read(shell->io, &inputbuffer[count], &readCount, TIME_NULL);
        count    += readCount;

        for (i = 0; i < count; i++)
        {
            /* By default, we assume character is part of escape sequence */
            NormalKeyPress = FALSE;

            /* Process key pressed */
            switch (inputbuffer[i])
            {
            /* New line (ENTER) */
            case '\n':
            case '\r':
                /* Print new line to terminal if requested */
                IFX_SHELL_IF_ECHO(IfxStdIf_DPipe_print(shell->io, ENDL))

                /* Execute command if length is valid - i.e. not an over-full buffer
                 * (prevents attempted execution of junk) */
                if (Cmd->length < IFX_SHELL_CMD_LINE_SIZE)
                {
                    cmdStr[Cmd->length] = IFX_SHELL_NULL_CHAR;  /* Terminate cmdStr */

                    if (Cmd->historyAdd != FALSE)
                    {
                        /* Shuffle history up */
                        for (j = IFX_SHELL_CMD_HISTORY_SIZE - 1; j > 0; j--)
                        {
                            /* Copy text */
                            strncpy(CmdHistory[j], CmdHistory[j - 1], IFX_SHELL_CMD_LINE_SIZE);
                        }

                        /* Copy in new entry */
                        strncpy(CmdHistory[0], cmdStr, IFX_SHELL_CMD_LINE_SIZE);
                    }

                    /* Execute command */
                    Ifx_Shell_execute(shell, cmdStr);
                }

                /* Show prompt if in main shell */
                if (shell->control.showPrompt != 0)
                {
                    IfxStdIf_DPipe_print(shell->io, IFX_SHELL_PROMPT);
                }

                /* Reset command line buffer length */
                Cmd->length = 0;

                /* Reset command line buffer cursor position */
                Cmd->cursor = 0;

                /* Clear flag */
                Cmd->historyAdd = FALSE;

                /* Ensure we're not in command history list */
                Cmd->historyItem = IFX_SHELL_CMD_HISTORY_NO_ITEM;
                break;

            /* Backspace (may occur in middle of text if cursor location is not at end) */
            case '\b':

                if (Cmd->cursor > 0)
                {
                    /* Update on screen */
                    if (shell->control.echo != 0)
                    {
                        /* Move left one character */
                        IfxStdIf_DPipe_print(shell->io, "\b");

                        /* Update line with new characters */
                        for (j = Cmd->cursor; j < Cmd->length; j++)
                        {
                            IfxStdIf_DPipe_print(shell->io, "%c", cmdStr[j]);
                        }

                        /* Write over duplicated character at end */
                        IfxStdIf_DPipe_print(shell->io, " ");
                        IFX_SHELL_WRITE_BACKSPACES((Cmd->length - Cmd->cursor) + 1)
                    }

                    /* Update in command line variable. Shuffle text left */
                    strncpy(&cmdStr[Cmd->cursor - 1], &cmdStr[Cmd->cursor], Cmd->length - Cmd->cursor);

                    /* Terminate string at end of shorter string */
                    cmdStr[Cmd->length - 1] = IFX_SHELL_NULL_CHAR;

                    Cmd->length--;
                    Cmd->cursor--;

                    /* Command line has been modified */
                    Cmd->historyAdd = TRUE;
                }

                break;

            /* Escape character */
            case '\x1B':       /*'\x1B': */
                shell->locals.cmdState = IFX_SHELL_CMD_STATE_ESCAPE;
                break;

            /* '[' - check to see if this is second part of an escape sequence */
            case '[':

                if (shell->locals.cmdState == IFX_SHELL_CMD_STATE_ESCAPE)
                {
                    /* ESC [ pressed */
                    shell->locals.cmdState = IFX_SHELL_CMD_STATE_ESCAPE_BRACKET;
                }
                else
                {
                    NormalKeyPress = TRUE;
                }

                break;

            /* Check for supported characters in escape sequences ( ESC [ A/B/C/D ) */
            case 'A':
            case 'B':
            case 'C':
            case 'D':

                if (shell->locals.cmdState == IFX_SHELL_CMD_STATE_ESCAPE_BRACKET)
                {
                    /* Process arrow keys */
                    Ifx_Shell_cmdEscapeProcess(shell, inputbuffer[i], 0);

                    /* End of escape sequence */
                    shell->locals.cmdState = IFX_SHELL_CMD_STATE_NORMAL;
                }
                else
                {
                    NormalKeyPress = TRUE;
                }

                break;

            /* Check for supported characters in escape sequences (ESC [ 2/4/5 ~) */
            case '1':
            case '2':
            case '3':
            case '4':

                if (shell->locals.cmdState == IFX_SHELL_CMD_STATE_ESCAPE_BRACKET)
                {
                    /* Store number for use once complete escape sequence is confirmed (below) */
                    shell->locals.escBracketNum = inputbuffer[i];
                    shell->locals.cmdState      = IFX_SHELL_CMD_STATE_ESCAPE_BRACKET_NUMBER;
                }
                else
                {
                    NormalKeyPress = TRUE;
                }

                break;

            /* Check for supported characters in escape sequences (ESC [ 2/4/5 ~) */
            case '~':

                if (shell->locals.cmdState == IFX_SHELL_CMD_STATE_ESCAPE_BRACKET_NUMBER)
                {
                    /* Process home/delete/end */
                    Ifx_Shell_cmdEscapeProcess(shell, shell->locals.escBracketNum, '~');

                    /* End of escape sequence */
                    shell->locals.cmdState = IFX_SHELL_CMD_STATE_NORMAL;
                }
                else
                {
                    NormalKeyPress = TRUE;
                }

                break;

            /* Normal character - add to command string */
            default:
                NormalKeyPress = TRUE;
                break;
            }

            IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, Cmd->length >= Cmd->cursor);    /* Sanity check */

            /* If this was a normal key press (not part of an escape sequence),
             * add it to the command string */
            if (NormalKeyPress != FALSE)
            {
                /* Ensure state machine is reset */
                shell->locals.cmdState = IFX_SHELL_CMD_STATE_NORMAL;

                /* If not filled buffer, add in this character */
                if (Cmd->length < (IFX_SHELL_CMD_LINE_SIZE - 1))
                {
                    /* Command line has been modified */
                    Cmd->historyAdd = TRUE;

                    /* Copy into command line */
                    cmdStr[Cmd->cursor] = inputbuffer[i];
                    Cmd->cursor++;

                    /* Update length of buffer */
                    Cmd->length = __max(Cmd->length, Cmd->cursor);

                    if (shell->control.echo != 0)
                    {
                        /* echo character to shell output if requested */
                        shell->locals.echo[0] = inputbuffer[i];
                        IfxStdIf_DPipe_print(shell->io, shell->locals.echo);
                    }
                }
                else
                {
                    /* Line too long - ignore further characters */
                    Cmd->historyAdd = FALSE;    /* Invalid command line */
                }
            }
        }
    }
boolean IfxGtm_Tom_Timer_init(IfxGtm_Tom_Timer *driver, IfxGtm_Tom_Timer_Config *config)
{
    boolean                result = TRUE;
    IfxGtm_Tom_Timer_Base *base   = &driver->base;
    uint16                 maskShift;

    IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, config->base.countDir == IfxStdIf_Timer_CountDir_up);    /* only this mode is supported */

    driver->gtm          = config->gtm;
    driver->tomIndex     = config->tom;
    driver->tom          = &config->gtm->TOM[config->tom];
    driver->timerChannel = config->timerChannel;
    base->triggerEnabled = config->base.trigger.enabled;

    if (base->triggerEnabled)
    {
        driver->triggerChannel = config->triggerOut->channel;
    }
    else
    {
        driver->triggerChannel = driver->timerChannel; // Set to timer channel to disable its use
    }

    if (config->timerChannel <= 7)
    {
        driver->tgc[0] = IfxGtm_Tom_Ch_getTgcPointer(driver->tom, 0);
        driver->tgc[1] = IfxGtm_Tom_Ch_getTgcPointer(driver->tom, 1);
    }
    else
    {
        driver->tgc[0] = IfxGtm_Tom_Ch_getTgcPointer(driver->tom, 1);
        driver->tgc[1] = NULL_PTR; /* NOTE currently no concatenation between TOMs */
    }

    driver->channelsMask[1]                  = 0;
    driver->tgcGlobalControlApplyUpdate[1]   = 0;
    driver->tgcGlobalControlDisableUpdate[1] = 0;

    /* Initialize the timer part */
    /* FIXME add IfxGtm_Tom_Ch_configurePwmMode() and use it */
    IfxGtm_Tom_Ch_setClockSource(driver->tom, driver->timerChannel, config->clock);
    IfxGtm_Tom_Ch_setTriggerOutput(driver->tom, driver->timerChannel, IfxGtm_Tom_Ch_OutputTrigger_generate);

    IfxGtm_Tom_Timer_updateInputFrequency(driver);

    if ((config->base.minResolution > 0) && ((1.0 / base->clockFreq) > config->base.minResolution))
    {
        result = FALSE;
        IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, FALSE);
    }
    else
    {}

    IfxGtm_Tom_Timer_setFrequency(driver, config->base.frequency);
    driver->offset = IfxStdIf_Timer_sToTick(driver->base.clockFreq, 1.0 / config->base.frequency * config->base.startOffset);

    IfxGtm_Tom_Ch_setCounterValue(driver->tom, driver->timerChannel, driver->offset);

    /* Initialize the trigger part */
    maskShift = (config->timerChannel <= 7) ? 0 : 8;
    IfxGtm_Tom_Timer_addToChannelMask(driver, driver->timerChannel);

    if (base->triggerEnabled)
    {
        IfxGtm_Tom_Ch triggerChannel     = driver->triggerChannel;
        uint16        triggerChannelMask = 1 << (triggerChannel - maskShift);
        /* TO DO: enable the trigger to be not in the same TGC group as the timer */

        IfxGtm_Tom_Ch_setSignalLevel(driver->tom, triggerChannel, config->base.trigger.risingEdgeAtPeriod ? Ifx_ActiveState_high : Ifx_ActiveState_low);
        IfxGtm_Tom_Ch_setCounterValue(driver->tom, triggerChannel, driver->offset);

        if (triggerChannel != driver->timerChannel)
        {
            /* FIXME add IfxGtm_Tom_Ch_configurePwmMode() and use it */
            IfxGtm_Tom_Ch_setResetSource(driver->tom, triggerChannel, IfxGtm_Tom_Ch_ResetEvent_onTrigger);
            IfxGtm_Tom_Ch_setClockSource(driver->tom, triggerChannel, config->clock);
            IfxGtm_Tom_Ch_setTriggerOutput(driver->tom, triggerChannel, IfxGtm_Tom_Ch_OutputTrigger_forward);
            IfxGtm_Tom_Tgc_enableChannels(driver->tgc[0], triggerChannelMask, 0, FALSE);
            IfxGtm_Tom_Timer_addToChannelMask(driver, driver->triggerChannel);
        }
        else
        {}

        /* Signal must go out of the GTM even if the port outpout is not enabled */
        IfxGtm_Tom_Tgc_enableChannelsOutput(driver->tgc[0], triggerChannelMask, 0, FALSE);

        if (config->base.trigger.outputEnabled)
        {
            /* Initialize the port */
            IfxGtm_PinMap_setTomTout(config->triggerOut, config->base.trigger.outputMode, config->base.trigger.outputDriver);
        }
        else
        {}

        IfxGtm_Tom_Timer_setTrigger(driver, config->base.trigger.triggerPoint);
    }
    else
    {}

    /* Interrupt configuration */
    {
        volatile Ifx_SRC_SRCR *src;
        boolean                timerHasIrq   = config->base.isrPriority > 0;
        boolean                triggerHasIrq = (config->base.trigger.isrPriority > 0) && base->triggerEnabled;

        if (driver->triggerChannel == driver->timerChannel)
        {
            IfxGtm_Tom_Ch_setNotification(driver->tom, driver->timerChannel, timerHasIrq ? config->irqModeTimer : config->irqModeTrigger, timerHasIrq, triggerHasIrq);
            src = IfxGtm_Tom_Ch_getSrcPointer(driver->gtm, config->tom, driver->timerChannel);
            IfxSrc_init(src, timerHasIrq ? config->base.isrProvider : config->base.trigger.isrProvider, timerHasIrq ? config->base.isrPriority : config->base.trigger.isrPriority);
            /* FIXME ADD warning on interrupt setting in case timer and trigger uses the same channels or different channels, and in case only timer or trigger or both generates interrupts */
            IfxSrc_enable(src);
        }
        else
        {
            IfxGtm_IrqMode irqMode = IfxGtm_IrqMode_pulseNotify;

            if (timerHasIrq)
            {
                IfxGtm_Tom_Ch_setNotification(driver->tom, driver->timerChannel, irqMode, TRUE, FALSE);
                src = IfxGtm_Tom_Ch_getSrcPointer(driver->gtm, config->tom, driver->timerChannel);
                IfxSrc_init(src, config->base.isrProvider, config->base.isrPriority);
                IfxSrc_enable(src);
            }

            if (triggerHasIrq)
            {
                IfxGtm_Tom_Ch_setNotification(driver->tom, driver->triggerChannel, irqMode, FALSE, TRUE);
                src = IfxGtm_Tom_Ch_getSrcPointer(driver->gtm, config->tom, driver->triggerChannel);
                IfxSrc_init(src, config->base.trigger.isrProvider, config->base.trigger.isrPriority);
                IfxSrc_enable(src);
            }
        }
    }

    /* Transfer the shadow registers */
    IfxGtm_Tom_Tgc_setChannelsForceUpdate(driver->tgc[0], driver->channelsMask[0], 0, 0, 0);
    IfxGtm_Tom_Tgc_trigger(driver->tgc[0]);
    IfxGtm_Tom_Tgc_setChannelsForceUpdate(driver->tgc[0], 0, driver->channelsMask[0], 0, 0);
    return result;
}
Example #5
0
boolean IfxGtm_Trig_toVadc(Ifx_GTM *gtm, IfxGtm_Trig_AdcGroup adcGroup, IfxGtm_Trig_AdcTrig adcTrig, IfxGtm_Trig_AdcTrigSource source, IfxGtm_Trig_AdcTrigChannel channel)
{
    CONST_CFG IfxGtm_Trig_AdcTrig_Table *table = NULL_PTR;
    uint8                                config;

    boolean                              result;

    switch (adcGroup)
    {
    case IfxGtm_Trig_AdcGroup_0:
    case IfxGtm_Trig_AdcGroup_1:
    case IfxGtm_Trig_AdcGroup_2:
        table = &IfxGtm_Trig_AdcTrig_tableAdc0_1_2;
        break;
    case IfxGtm_Trig_AdcGroup_3:
    case IfxGtm_Trig_AdcGroup_4:
        table = &IfxGtm_Trig_AdcTrig_tableAdc3_4;
        break;
    case IfxGtm_Trig_AdcGroup_5:
    case IfxGtm_Trig_AdcGroup_6:
    case IfxGtm_Trig_AdcGroup_7:
        table = &IfxGtm_Trig_AdcTrig_tableAdc5_6_7;
        break;
    case IfxGtm_Trig_AdcGroup_8:
        table = &IfxGtm_Trig_AdcTrig_tableAdc8;
        break;
    default:
        break;
    }

    if (table != NULL_PTR)
    {
        config = table->trigger[adcTrig].source[source].channel[channel].config;
        result = config != 0xFF;
        uint32 mask = 0xFU << (adcGroup * 4);

        if (adcGroup < IfxGtm_Trig_AdcGroup_8)
        {
            switch (adcTrig)
            {
            case IfxGtm_Trig_AdcTrig_0:
                __ldmst_c(&(gtm->ADCTRIG0OUT0.U), mask, config << (adcGroup * 4));
                break;
            case IfxGtm_Trig_AdcTrig_1:
                __ldmst_c(&(gtm->ADCTRIG1OUT0.U), mask, config << (adcGroup * 4));
                break;
            default:
                result = FALSE;
                break;
            }
        }
        else
        {
            switch (adcTrig)
            {
            case IfxGtm_Trig_AdcTrig_0:
                __ldmst_c(&(gtm->ADCTRIG0OUT1.U), mask, config << (adcGroup * 4));
                break;
            case IfxGtm_Trig_AdcTrig_1:
                __ldmst_c(&(gtm->ADCTRIG1OUT1.U), mask, config << (adcGroup * 4));
                break;
            default:
                result = FALSE;
                break;
            }
        }
    }
    else
    {
        result = FALSE;
    }

    IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, result);

    return result;
}
boolean IfxGtm_Atom_PwmHl_init(IfxGtm_Atom_PwmHl *driver, const IfxGtm_Atom_PwmHl_Config *config)
{
    boolean            result       = TRUE;
    uint16             channelMask;
    uint16             channelsMask = 0;
    uint32             channelIndex;

    IfxGtm_Atom_Timer *timer = config->timer;

    /* driver.base must be at offset 0 to be compatible with the standard interface PwmHl */
    IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, offsetof(IfxGtm_Atom_PwmHl, base) == 0);

    driver->base.mode             = Ifx_Pwm_Mode_init;
    driver->timer                 = timer;
    driver->base.setMode          = 0;
    driver->base.inverted         = FALSE;
    driver->base.ccxActiveState   = config->base.ccxActiveState;
    driver->base.coutxActiveState = config->base.coutxActiveState;
    driver->base.channelCount     = config->base.channelCount;

    IfxGtm_Atom_PwmHl_setDeadtime(driver, config->base.deadtime);
    IfxGtm_Atom_PwmHl_setMinPulse(driver, config->base.minPulse);

    driver->atom = &(timer->gtm->ATOM[config->atom]);
    /* Only one AGC */
    driver->agc  = (Ifx_GTM_ATOM_AGC *)&driver->atom->AGC.GLB_CTRL;

    IFX_ASSERT(IFX_VERBOSE_LEVEL_ERROR, config->base.channelCount <= IFXGTM_ATOM_PWMHL_MAX_NUM_CHANNELS);

    IfxGtm_Cmu_Clk clock = IfxGtm_Atom_Ch_getClockSource(timer->atom, timer->timerChannel);

    for (channelIndex = 0; channelIndex < config->base.channelCount; channelIndex++)
    {
        IfxGtm_Atom_Ch channel;
        /* CCX */
        channel                   = config->ccx[channelIndex]->channel;
        driver->ccx[channelIndex] = channel;
        channelMask               = 1 << channel;
        channelsMask             |= channelMask;

        /* Initialize the timer part */
        IfxGtm_Atom_Ch_configurePwmMode(driver->atom, channel, clock,
            driver->base.inverted ? config->base.ccxActiveState :
            IfxGtm_Atom_PwmHl_invertActiveState(config->base.ccxActiveState),
            IfxGtm_Atom_Ch_ResetEvent_onTrigger, IfxGtm_Atom_Ch_OutputTrigger_forward);

        /* Initialize the port */
        IfxGtm_PinMap_setAtomTout(config->ccx[channelIndex],
            config->base.outputMode, config->base.outputDriver);

        /* COUTX */
        channel                     = config->coutx[channelIndex]->channel;
        driver->coutx[channelIndex] = channel;
        channelMask                 = 1 << channel;
        channelsMask               |= channelMask;

        /* Initialize the timer part */
        IfxGtm_Atom_Ch_configurePwmMode(driver->atom, channel, clock,
            driver->base.inverted ?
            IfxGtm_Atom_PwmHl_invertActiveState(config->base.coutxActiveState)
            : config->base.coutxActiveState,
            IfxGtm_Atom_Ch_ResetEvent_onTrigger, IfxGtm_Atom_Ch_OutputTrigger_forward);

        /* Initialize the port */
        IfxGtm_PinMap_setAtomTout(config->coutx[channelIndex],
            config->base.outputMode, config->base.outputDriver);
    }

    IfxGtm_Atom_Agc_enableChannelsOutput(driver->agc, channelsMask, 0, TRUE);
    IfxGtm_Atom_Agc_enableChannels(driver->agc, channelsMask, 0, TRUE);

    IfxGtm_Atom_PwmHl_setMode(driver, Ifx_Pwm_Mode_off);

    Ifx_TimerValue tOn[IFXGTM_ATOM_PWMHL_MAX_NUM_CHANNELS] = {0};
    IfxGtm_Atom_PwmHl_updateOff(driver, tOn); /* tOn do not need defined values */

    /* Transfer the shadow registers */
    IfxGtm_Atom_Agc_setChannelsForceUpdate(driver->agc, channelsMask, 0, 0, 0);
    IfxGtm_Atom_Agc_trigger(driver->agc);
    IfxGtm_Atom_Agc_setChannelsForceUpdate(driver->agc, 0, channelsMask, 0, 0);

    /* Enable timer to update the channels */

    for (channelIndex = 0; channelIndex < driver->base.channelCount; channelIndex++)
    {
        IfxGtm_Atom_Timer_addToChannelMask(timer, 1 << driver->ccx[channelIndex]);
        IfxGtm_Atom_Timer_addToChannelMask(timer, 1 << driver->coutx[channelIndex]);
    }

    return result;
}