Exemplo n.º 1
0
// =============================================================================
// boot_IspiGetData
// -----------------------------------------------------------------------------
/// Get one datum.
///
/// This functions gets one element of 32 bits from the ISPI Rx Fifo.
/// If the Fifo was empty at the time #boot_IspiGetData() is called, 0
/// is returned and \c recData is untainted. Otherwise one datum is get
/// from the Fifo and 1 is returned
///
/// @param  recData Pointer to store the received datum.
/// @return Returns the number of received data (1 or 0, if the Fifo is empty).
// =============================================================================
PUBLIC UINT32 boot_IspiGetData(UINT32* recData)
{
    UINT32 nbAvailable;

    // Enter critical section.
    UINT32 status = hwp_sysIrq->SC;

    nbAvailable = GET_BITFIELD(hwp_spi3->status, SPI_RX_LEVEL);
    
    if (nbAvailable > 0)
    {
        *recData = hwp_spi3->rxtx_buffer;
        
        // Exit critical section.
        hwp_sysIrq->SC = status;
        return 1;
    }
    else
    {
        // Exit critical section.
        hwp_sysIrq->SC = status;
        return 0;
    }

}
Exemplo n.º 2
0
static PyObject *
b_get(void *ptr, Py_ssize_t size)
{
    signed char val = *(signed char *)ptr;
    GET_BITFIELD(val, size);
    return PyInt_FromLong(val);
}
Exemplo n.º 3
0
// =============================================================================
// boot_IspiRxFifoLevel
// -----------------------------------------------------------------------------
/// Get data quantity in the Spi Rx FIFO.
///
/// @return The number of 32 bits data items in the Rx FIFO.
// =============================================================================
PUBLIC UINT8 boot_IspiRxFifoLevel(VOID)
{
    UINT8 rxLevel;
    // Get level 
    rxLevel = GET_BITFIELD(hwp_spi3->status, SPI_RX_LEVEL);
    return rxLevel;
}
Exemplo n.º 4
0
// =============================================================================
// boot_UartMonitorGet
// -----------------------------------------------------------------------------
/// Read some bytes and actualizes the checksum.
/// @param data Array where read bytes will be stored
/// @param size Number of bytes to receive.
/// @param checksum Pointer to the value to XOR the read byte to calculate 
/// the checksum.
// =============================================================================
PROTECTED BOOT_UM_ERR_T boot_UartMonitorGet(UINT8* data, UINT32 size, UINT8* checksum)
{
    UINT32 i;
    UINT32 offset = 0;
    UINT32 startTime;
    BOOL    onTime = TRUE;
    
    for (i=0; i<size; i++)
    {
        startTime = hwp_timer->HWTimer_CurVal;
        if (startTime > 0x80000000)
        {
            offset = 0x80000000;
        }
        
        while ((GET_BITFIELD(hwp_uart->status, UART_RX_FIFO_LEVEL) == 0)
               && (onTime = ((hwp_timer->HWTimer_CurVal+offset) < (startTime + offset + BOOT_UART_MONITOR_RX_TIME_OUT))));
        if (!onTime)
        {
            return BOOT_UM_ERR_RX_FAILED;
        }
        
        data[i] = hwp_uart->rxtx_buffer;
        *checksum ^= data[i];
    }
    return BOOT_UM_ERR_NO;
}
Exemplo n.º 5
0
static PyObject *
B_get(void *ptr, Py_ssize_t size)
{
    unsigned char val = *(unsigned char *)ptr;
    GET_BITFIELD(val, size);
    return PyLong_FromLong(val);
}
Exemplo n.º 6
0
// =============================================================================
// boot_UartMonitorSend
// -----------------------------------------------------------------------------
/// Basic sending function.  Done on polling, check
/// TX fifo availability and wait for room if needed.
///
/// @param data Data to send
/// @param length Number of byte to send.
/// @param checksum Pointer to the UINT8 holding the CRC of the frame 
/// this transmitting is as part of.
/// @return #BOOT_UM_ERR_NO or #BOOT_UM_ERR_RESOURCE_TIMEOUT;
// =============================================================================
PROTECTED BOOT_UM_ERR_T boot_UartMonitorSend(UINT8* data, UINT32 length, UINT8* checksum)
{
    UINT32 i;
    UINT32 offset = 0;
    UINT32 startTime;
    BOOL    onTime = TRUE;
    for (i=0 ; i<length ; i++)
    {
        startTime = hwp_timer->HWTimer_CurVal;
        if (startTime > 0x80000000)
        {
            offset = 0x80000000;
        }
        
        // Place in the TX Fifo ?
        while ((GET_BITFIELD(hwp_uart->status, UART_TX_FIFO_SPACE) == 0)
               && (onTime = (hwp_timer->HWTimer_CurVal+offset < startTime + offset + BOOT_UART_MONITOR_TX_TIME_OUT)));
        
        if (!onTime)
        {
            return BOOT_UM_ERR_TX_FAILED;
        }
        
        hwp_uart->rxtx_buffer = data[i];
        *checksum ^= data[i];
    }
    return BOOT_UM_ERR_NO;
}
Exemplo n.º 7
0
// =============================================================================
// boot_IspiSendData
// -----------------------------------------------------------------------------
/// Send one data. 
/// This functions sends one data frame.
/// The number returned is the number of data frames actually sent. 
///
/// @param csId The CS to use to send the data. This cs must be activated before
/// sending data.
/// @param data Frame of data to send.
/// @param read \c TRUE if the response of the device to this sent data is
/// expected to be read later and thus will be put in the read Fifo.
/// @return 1 if the data was sent, 0 otherwise.
// =============================================================================
PUBLIC UINT32 boot_IspiSendData(BOOT_ISPI_CS_T csId, UINT32 data, BOOL read)
{
    UINT32 freeRoom;
    
    // Clear data upper bit to only keep the data frame.
    UINT32 reg = data & ~(SPI_CS_MASK | SPI_READ_ENA_MASK);
    
    // Add CS and read mode bit
    reg |= SPI_CS(csId) | (read?SPI_READ_ENA:0);

    // Enter critical section.
    UINT32 status = hwp_sysIrq->SC;

    // Check FIFO availability.
    freeRoom = GET_BITFIELD(hwp_spi3->status, SPI_TX_SPACE);

    if (freeRoom > 0)
    {
        // Write data.
        hwp_spi3->rxtx_buffer = reg;
        
        // Exit critical section.
        hwp_sysIrq->SC = status;
        return 1;
    }
    else
    {
        // Exit critical section.
        hwp_sysIrq->SC = status;
        return 0;
    }
    
}
Exemplo n.º 8
0
static PyObject *
Q_get(void *ptr, Py_ssize_t size)
{
    unsigned PY_LONG_LONG val;
    memcpy(&val, ptr, sizeof(val));
    GET_BITFIELD(val, size);
    return PyLong_FromUnsignedLongLong(val);
}
Exemplo n.º 9
0
static PyObject *
i_get(void *ptr, Py_ssize_t size)
{
    int val;
    memcpy(&val, ptr, sizeof(val));
    GET_BITFIELD(val, size);
    return PyInt_FromLong(val);
}
Exemplo n.º 10
0
static PyObject *
H_get(void *ptr, Py_ssize_t size)
{
    unsigned short val;
    memcpy(&val, ptr, sizeof(val));
    GET_BITFIELD(val, size);
    return PyLong_FromLong(val);
}
Exemplo n.º 11
0
static PyObject *
l_get(void *ptr, Py_ssize_t size)
{
    long val;
    memcpy(&val, ptr, sizeof(val));
    GET_BITFIELD(val, size);
    return PyLong_FromLong(val);
}
Exemplo n.º 12
0
static PyObject *
q_get_sw(void *ptr, Py_ssize_t size)
{
    PY_LONG_LONG val;
    memcpy(&val, ptr, sizeof(val));
    val = SWAP_8(val);
    GET_BITFIELD(val, size);
    return PyLong_FromLongLong(val);
}
Exemplo n.º 13
0
static PyObject *
l_get_sw(void *ptr, Py_ssize_t size)
{
    long val;
    memcpy(&val, ptr, sizeof(val));
    val = SWAP_LONG(val);
    GET_BITFIELD(val, size);
    return PyInt_FromLong(val);
}
Exemplo n.º 14
0
// =============================================================================
// boot_IspiTxFifoAvail
// -----------------------------------------------------------------------------
/// Get available data spaces in the Spi Tx FIFO.
/// This function returns the available space in the Tx FIFO, as a number
/// of 32 bits data that can be filled into it.
///
/// @return The size of the available space in the Tx FIFO. (In Fifo elements.)
// =============================================================================
PUBLIC UINT8 boot_IspiTxFifoAvail(VOID)
{
    UINT8 freeRoom;
    
    // Get avail level.
    freeRoom = GET_BITFIELD(hwp_spi3->status, SPI_TX_SPACE);

    return freeRoom;
}
Exemplo n.º 15
0
static PyObject *
L_get_sw(void *ptr, Py_ssize_t size)
{
    unsigned long val;
    memcpy(&val, ptr, sizeof(val));
    val = SWAP_LONG(val);
    GET_BITFIELD(val, size);
    return PyLong_FromUnsignedLong(val);
}
Exemplo n.º 16
0
static PyObject *
i_get_sw(void *ptr, Py_ssize_t size)
{
    int val;
    memcpy(&val, ptr, sizeof(val));
    val = SWAP_INT(val);
    GET_BITFIELD(val, size);
    return PyLong_FromLong(val);
}
Exemplo n.º 17
0
// =============================================================================
// boot_HstMonitor
// -----------------------------------------------------------------------------
/// Main host monitor function. Read the command passed to the platform through
/// the Host port and call the host command handler if appropriate.
/// It read the H2P register to execute commands
/// until the Exit command is received (BOOT_HST_MONITOR_END_CMD).
// =============================================================================
PROTECTED BOOT_MONITOR_OP_STATUS_T boot_HstMonitor(VOID)
{

    BOOT_HST_CMD_T hostCommand = 0;

    // Clear the "enter the monitor" host command

    // if a host command present
    if((hostCommand = GET_BITFIELD(hwp_debugHost->h2p_status,
                                   DEBUG_HOST_H2P_STATUS)) != 0)
    {
        // We received a command: we are not waiting anymore but actually acting
        // as a monitor.
        hwp_debugHost->p2h_status   = BOOT_HST_STATUS_NONE;

        switch (hostCommand)
        {
            case BOOT_HST_MONITOR_START_CMD:
                // That command used to be used to enter into the monitor.
                // We now use a boot mode for that, so this command is
                // just used to send the BOOT_HST_MONITOR_START event
                // to acknowledge to the host (eg Remote PC's coolwatcher)
                // that we actually are in the monitor.
                mon_Event(BOOT_HST_MONITOR_START);
                hwp_debugHost->h2p_status = DEBUG_HOST_H2P_STATUS_RST;
                break;

            case BOOT_HST_MONITOR_X_CMD:
                // Execute a command placed in the execution structure.
                // H2P_Status is cleared in the basic handler
                boot_HstCmdBasicHandler();
                break;

            case BOOT_HST_MONITOR_END_CMD:
                // We are required to leave the monitor.
                mon_Event(BOOT_HST_MONITOR_END);
                hwp_debugHost->h2p_status = DEBUG_HOST_H2P_STATUS_RST;
                return BOOT_MONITOR_OP_STATUS_EXIT;

            default:
                // unsupported command
                mon_Event(BOOT_HST_UNSUPPORTED_CMD);
                hwp_debugHost->h2p_status = DEBUG_HOST_H2P_STATUS_RST;
                break;
        }

        // We received a command, possibly unknown, but different from 
        // BOOT_HST_MONITOR_END_CMD;
        return BOOT_MONITOR_OP_STATUS_CONTINUE;
    }
    else
    {
        // No command received.
        return BOOT_MONITOR_OP_STATUS_NONE;
    }
}
Exemplo n.º 18
0
/************************************************
*  函数名称:write_data
*  功能说明:LCD写数据函数
*  参数说明:d为数据,为一个BYTE的数据
*  函数返回:无
*  修改时间:2014-1-14    已经测试
*************************************************/
void  write_data(unsigned char  d)
{
  dcx=1;
  sdi=(GET_BITFIELD(d))->bit7;scl=0;scl=1;
  sdi=(GET_BITFIELD(d))->bit6;scl=0;scl=1;
  sdi=(GET_BITFIELD(d))->bit5;scl=0;scl=1;
  sdi=(GET_BITFIELD(d))->bit4;scl=0;scl=1;
  sdi=(GET_BITFIELD(d))->bit3;scl=0;scl=1;
  sdi=(GET_BITFIELD(d))->bit2;scl=0;scl=1;
  sdi=(GET_BITFIELD(d))->bit1;scl=0;scl=1;
  sdi=(GET_BITFIELD(d))->bit0;scl=0;scl=1;
}
Exemplo n.º 19
0
/************************************************
*  函数名称:write_command
*  功能说明:LCD写指令函数
*  参数说明:c为指令
*  函数返回:无
*  修改时间:2014-1-14    已经测试
*************************************************/
void  write_command(unsigned char  c)
{
  dcx=0;
  sdi=(GET_BITFIELD(c))->bit7;scl=0;scl=1;
  sdi=(GET_BITFIELD(c))->bit6;scl=0;scl=1;
  sdi=(GET_BITFIELD(c))->bit5;scl=0;scl=1;
  sdi=(GET_BITFIELD(c))->bit4;scl=0;scl=1;
  sdi=(GET_BITFIELD(c))->bit3;scl=0;scl=1;
  sdi=(GET_BITFIELD(c))->bit2;scl=0;scl=1;
  sdi=(GET_BITFIELD(c))->bit1;scl=0;scl=1;
  sdi=(GET_BITFIELD(c))->bit0;scl=0;scl=1;
}
Exemplo n.º 20
0
// =============================================================================
// hal_IfcTransferStart
// -----------------------------------------------------------------------------
/// Start an IFC transfer
/// 
/// This is a non blocking function that starts the transfer
/// and returns the hand. 
/// 
/// @param requestId Describe the direction of the tranfer (rx or
/// tx) and the module to or from which data are to be moved.
/// @param memStartAddr. Start address of the buffer where data 
/// to be sent are located or where to put the data read, according
/// to the request defined by the previous parameter
/// @param xferSize Number of bytes to transfer. The maximum size 
/// is 2^20 - 1 bytes.
/// @param ifcMode Mode of the transfer (Autodisable or not, 8 or 32 bits)
/// @return Channel got or HAL_UNKNOWN_CHANNEL.
// =============================================================================
PROTECTED UINT8 hal_IfcTransferStart(HAL_IFC_REQUEST_ID_T requestId, UINT8* memStartAddr, UINT32 xferSize, HAL_IFC_MODE_T ifcMode)
{
    // Check buffer alignment depending on the mode
    if (ifcMode != HAL_IFC_SIZE_8_MODE_MANUAL && ifcMode != HAL_IFC_SIZE_8_MODE_AUTO)
    {
        // Then ifcMode == HAL_IFC_SIZE_32, check word alignment
        HAL_ASSERT(((UINT32)memStartAddr%4) == 0,
            "HAL IFC: 32 bits transfer misaligned 0x@%08X", memStartAddr);
    }
    else
    {
        // ifcMode == HAL_IFC_SIZE_8, nothing to check
    }

    HAL_ASSERT(xferSize < (1<<SYS_IFC_TC_LEN),
        "HAL IFC: Transfer size too large: %d", xferSize);

    UINT32 status = hal_SysEnterCriticalSection();
    UINT8 channel;
    UINT8 i;
    
    // Check the requested id is not currently already used.
    for (i = 0; i < SYS_IFC_STD_CHAN_NB ; i++)
    {
        if (GET_BITFIELD(hwp_sysIfc->std_ch[i].control, SYS_IFC_REQ_SRC) == requestId)
        {
            // This channel is or was used for the requestId request.
            // Check it is still in use.
            HAL_ASSERT((hwp_sysIfc->std_ch[i].status & SYS_IFC_ENABLE) == 0,
                    "HAL: Attempt to use the IFC to deal with a %d"
                    " request still active on channel %d", requestId, i);
        }
    }

    channel = SYS_IFC_CH_TO_USE(hwp_sysIfc->get_ch) ;

    if (channel >= SYS_IFC_STD_CHAN_NB)
    {
        hal_SysExitCriticalSection(status);
        return HAL_UNKNOWN_CHANNEL;
    }

    g_halModuleIfcChannelOwner[channel]     = requestId;
    hwp_sysIfc->std_ch[channel].start_addr  =  (UINT32) memStartAddr;
    hwp_sysIfc->std_ch[channel].tc          =  xferSize;
    hwp_sysIfc->std_ch[channel].control     = (SYS_IFC_REQ_SRC(requestId) 
                                            | ifcMode
#if (CHIP_HAS_ASYNC_TCU)
                                            | SYS_IFC_CH_RD_HW_EXCH
#endif
                                            | SYS_IFC_ENABLE);
    
    hal_SysExitCriticalSection(status);
    return channel;
}
Exemplo n.º 21
0
/**
@details
-# While there is data in memory that has not been written to disk
   -# Write out each of the other parameter values to the temporary #writer_buff
   -# Write #writer_buff to the output file
*/
int Trick::DRBinary::format_specific_write_data(unsigned int writer_offset) {

	unsigned long bf;
	int sbf;
    unsigned int ii ;
    unsigned int len = 0 ;
    char *address = 0 ;

    /* Write out all parameters */
    for (ii = 0; ii < rec_buffer.size() ; ii++) {

        address = rec_buffer[ii]->buffer + ( writer_offset * rec_buffer[ii]->ref->attr->size ) ;

        switch (rec_buffer[ii]->ref->attr->type) {
            case TRICK_CHARACTER:
            case TRICK_UNSIGNED_CHARACTER:
            case TRICK_SHORT:
            case TRICK_UNSIGNED_SHORT:
            case TRICK_BOOLEAN:
            case TRICK_ENUMERATED:
            case TRICK_INTEGER:
            case TRICK_UNSIGNED_INTEGER:
            case TRICK_FLOAT:
            case TRICK_LONG:
            case TRICK_UNSIGNED_LONG:
            case TRICK_LONG_LONG:
            case TRICK_UNSIGNED_LONG_LONG:
            case TRICK_STRUCTURED:
            case TRICK_DOUBLE:
                memcpy(writer_buff + len, address, (size_t)rec_buffer[ii]->ref->attr->size);
                break;

            case TRICK_BITFIELD:
                sbf = GET_BITFIELD(address, rec_buffer[ii]->ref->attr->size,
                 rec_buffer[ii]->ref->attr->index[0].start, rec_buffer[ii]->ref->attr->index[0].size);
                memcpy(writer_buff + len, &sbf, (size_t)rec_buffer[ii]->ref->attr->size);
                break;

            case TRICK_UNSIGNED_BITFIELD:
                bf = GET_UNSIGNED_BITFIELD(address, rec_buffer[ii]->ref->attr->size,
                 rec_buffer[ii]->ref->attr->index[0].start, rec_buffer[ii]->ref->attr->index[0].size);
                memcpy(writer_buff + len, &bf, (size_t)rec_buffer[ii]->ref->attr->size);
                break;

            default:
                break;
        }
        len += rec_buffer[ii]->ref->attr->size ;

    }

    write( fp , writer_buff , len) ;

    return(0) ;
}
Exemplo n.º 22
0
// =============================================================================
// boot_IspiSendDataBuffer
// -----------------------------------------------------------------------------
/// Send a bunch of data. 
/// This functions sends \c length data (Number of 32 bits words) starting from
/// the address \c start_address. These data have previously been prepared to 
/// be sent by using the #BOOT_ISPI_CS() and #BOOT_ISPI_REQ_READ macros.
/// The number returned is the number of data actually sent. (Number of 32 bits
/// items.)
/// In DMA mode, this function returns 0 when no DMA channel is available, it 
/// returns length otherwise.
///
/// @param startAddress Pointer on the buffer to send
/// @param length number of bytes to send (Up to 4 kB).
/// @param mode Mode of the transfer (Direct or DMA).
/// @return When in DMA mode, returns 0 if no DMA channel is available. \n
///         In direct mode or DMA mode with an available channel, returns the 
///         number of data (32 bits words) sent.
// =============================================================================
PUBLIC UINT32 boot_IspiSendDataBuffer(CONST UINT32* startAddress, UINT32 length, BOOT_ISPI_TRANSFERT_MODE_T mode)
{
    // FIXME Add a kind of semaphore to ensure there is no concurrent access.
    UINT32 i;
    UINT32 freeRoom;

    if (mode == BOOT_ISPI_DIRECT_POLLING)
    {
        // -----------------------------
        // DIRECT TRANSFER
        // -----------------------------
        // Enter critical section.
        UINT32 status = hwp_sysIrq->SC;
    
        freeRoom = GET_BITFIELD(hwp_spi3->status, SPI_TX_SPACE);

        if (freeRoom > length)
        {
            freeRoom = length;
        }

        //  Send data byte by byte. 
        for (i = 0; i < freeRoom; i++)
        {
            hwp_spi3->rxtx_buffer = *(startAddress + i);
        }
    
        // Exit critical section.
        hwp_sysIrq->SC = status;
        return freeRoom;
    }
    else
    {
        // -----------------------------
        // DMA TRANSFER
        // -----------------------------
        // We transfer 32 bits items (4 bytes)
        g_bootIspiProperties.txIfcCh = boot_IspiIfcTransferStart(BOOT_ISPI_IFC_REQ_TX,
                                            (UINT32*)startAddress, length*4);

        // get IFC channel and start if any available
        if (g_bootIspiProperties.txIfcCh == BOOT_ISPI_IFC_UNKNOWN_CHANNEL)
        {
            // No channel available.
            // No data received.
            return 0;
        }
        else
        {
            // all data will be fetched.
            return length;
        }
    }
}
Exemplo n.º 23
0
// =============================================================================
// boot_IspiGetDataBuffer
// -----------------------------------------------------------------------------
/// Get a bunch of data. 
///
/// This functions gets \c length 32 bits data from the ISPI and stores them
/// starting from the address \c destAddress. The number returned is the number
/// of 32-bits data item actually received. In DMA mode, this function returns
/// 0 when no DMA channel is available. It returns length otherwise.
///
/// @param destAddress Pointer on the buffer to store received data
/// @param length Number of byte to receive.
/// @param mode Mode of the transfer (Direct or DMA).
/// @return When in DMA mode, returns 0 if no DMA channel is available. \n
///         In direct mode or DMA mode with an available channel, returns the 
///         number of received 32 bits data. 
// =============================================================================
PUBLIC UINT32 boot_IspiGetDataBuffer(UINT32* destAddress, UINT32 length, BOOT_ISPI_TRANSFERT_MODE_T mode)
{
    UINT32 i;
    UINT32 nbAvailable;

    if (mode == BOOT_ISPI_DIRECT_POLLING)
    {
        // -----------------------------
        // DIRECT TRANSFER
        // -----------------------------
        // Enter critical section.
        UINT32 status = hwp_sysIrq->SC;

        nbAvailable = GET_BITFIELD(hwp_spi3->status, SPI_RX_LEVEL);
        
        if (nbAvailable > length)
        {
            nbAvailable = length;
        }

        //  Get data byte by byte. 
        for (i = 0; i < nbAvailable; i++)
        {
            *(destAddress + i) = hwp_spi3->rxtx_buffer;
        }

        // Exit critical section.
        hwp_sysIrq->SC = status;
        return nbAvailable;
    }
    else
    {
        // -----------------------------
        // DMA TRANSFER
        // -----------------------------
        // We transfer 32 bits items (4 bytes)
        g_bootIspiProperties.rxIfcCh = boot_IspiIfcTransferStart(BOOT_ISPI_IFC_REQ_RX,
                                            destAddress, length*4);
        
        // Get IFC channel and start if any available
        if (g_bootIspiProperties.rxIfcCh == BOOT_ISPI_IFC_UNKNOWN_CHANNEL)
        {
            // No channel available.
            // No data received.
            return 0;
        }
        else
        {
            // All data will be fetched.
            return length;
        }
    }
}
Exemplo n.º 24
0
// =============================================================================
// boot_IspiIfcChannelRelease
// -----------------------------------------------------------------------------
/// Force the release of a channel owned by a request.
/// 
/// The channel is only released if the specified request
/// owns the channel.
/// 
/// @param requestId Describe the direction of the tranfer (rx or
/// tx) and the module to or from which data are to be moved. 
/// @param channel Channel to release
// =============================================================================
PRIVATE VOID boot_IspiIfcChannelRelease(UINT32 requestId, UINT8 channel)
{
    UINT32 status;

    // Here, we consider the transfer as previously finished.
    if (channel == BOOT_ISPI_IFC_UNKNOWN_CHANNEL) return;

    status = hwp_sysIrq->SC;
    if (GET_BITFIELD(hwp_sysIfc->std_ch[channel].control, SYS_IFC_REQ_SRC) == requestId)
    {
        // Disable this channel.
        hwp_sysIfc->std_ch[channel].control = (SYS_IFC_REQ_SRC(requestId)
                                            | SYS_IFC_CH_RD_HW_EXCH
                                            | SYS_IFC_DISABLE);
        hwp_sysIfc->std_ch[channel].tc =  0;
    }
    hwp_sysIrq->SC = status;
}
Exemplo n.º 25
0
// =============================================================================
// boot_IspiTxFinished
// -----------------------------------------------------------------------------
/// Check if the last transfer is done.
/// This function returns \c TRUE when the transmit FIFO is empty and when the 
/// last byte is completely sent. It should be called before closing the ISPI if 
/// the last bytes of the transfer are important.\n
/// This function should not be called between transfers, in direct or DMA mode. 
/// The @link #boot_IspiTxFifoLevel FIFO level @endlink for direct mode and the 
/// @link #boot_IspiTxDmaDone DMA done indication @endlink for DMA allow 
/// for a more optimized transmission.
///
/// @return \c TRUE if the last tranfer is done and the Tx FIFO empty.\n
///         \c FALSE otherwise. 
// =============================================================================
PUBLIC BOOL boot_IspiTxFinished(VOID)
{
    UINT32 spiStatus;
                                
    spiStatus = hwp_spi3->status;

    // If ISPI FSM is active and the TX Fifo is empty
    // (ie available space == Fifo size), the tf is not done 
    if ((!(hwp_spi3->status & SPI_ACTIVE_STATUS))
            && (SPI_TX_FIFO_SIZE == GET_BITFIELD(spiStatus, SPI_TX_SPACE)))
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}
Exemplo n.º 26
0
PRIVATE VOID boot_UsbConfig(VOID)
{
    UINT8                i;
    UINT16               addr;
    UINT8                dir;

    // Nb EP
    g_BootUsbVar.NbEp = GET_BITFIELD(hwp_usbc->GHWCFG2, USBC_NUMDEVEPS);
    g_BootUsbVar.NbEp++;

    // Rx Fifo Size
    hwp_usbc->GRXFSIZ    = RXFIFOSIZE;
    addr                 = RXFIFOSIZE;

    // EP direction and Tx fifo configuration
    hwp_usbc->GNPTXFSIZ  = USBC_NPTXFSTADDR(addr) | USBC_NPTXFDEPS(TXFIFOSIZE);
    addr                += TXFIFOSIZE;

    for(i = 1; i < g_BootUsbVar.NbEp; i++)
    {
        dir = EPDIR(i);
        if(dir == EPIN || dir == EPINOUT)
        {
            hwp_usbc->DIEPTXF[i-1].DIEnPTXF  =
                USBC_IENPNTXFSTADDR(addr) | USBC_INEPNTXFDEP(TXFIFOSIZE);
            addr                            += TXFIFOSIZE;
        }
    }


    hwp_usbc->GAHBCFG  = USBC_DMAEN | USBC_HBSTLEN(INCR4);
    hwp_usbc->GAHBCFG |= USBC_GLBLINTRMSK;
    hwp_usbc->GUSBCFG |= USBC_PHYIF | USBC_USBTRDTIM(5);

    hwp_usbc->DCFG    &= ~(USBC_DEVSPD_MASK  | USBC_PERFRINT_MASK);
    // Configure FS USB 1.1 Phy
    hwp_usbc->DCFG    |= USBC_DEVSPD(3);

    hwp_usbc->GINTMSK |= USBC_USBRST | USBC_ENUMDONE
        | USBC_ERLYSUSP | USBC_USBSUSP;
}
Exemplo n.º 27
0
// =============================================================================
// boot_HstUartSend
// -----------------------------------------------------------------------------
/// Basic sending function.  Done on polling, check
/// TX fifo availability and wait for room if needed.
///
/// @param data Data to send
/// @param length Number of byte to send.
/// @param checksum Pointer to the UINT8 holding the CRC of the frame 
/// this transmitting is as part of.
/// @return #BOOT_UM_ERR_NO or #BOOT_UM_ERR_RESOURCE_TIMEOUT;
// =============================================================================
PROTECTED BOOT_UM_ERR_T boot_HstUartSend(UINT8* data, UINT32 length, UINT8* checksum)
{
    UINT32 i;
    UINT32 startTime;
    BOOL    onTime = TRUE;
    for (i=0 ; i<length ; i++)
    {
        startTime = hwp_timer->HWTimer_CurVal;
        
        // Place in the TX Fifo ?
        while ((GET_BITFIELD(hwp_debugUart->status, DEBUG_UART_TX_FIFO_LEVEL) == DEBUG_UART_TX_FIFO_SIZE)
               && (onTime = ((hwp_timer->HWTimer_CurVal - startTime) < BOOT_UART_MONITOR_TX_TIME_OUT)));
        
        if (!onTime)
        {
            return BOOT_UM_ERR_TX_FAILED;
        }
        
        hwp_debugUart->rxtx_buffer = data[i];
        *checksum ^= data[i];
    }
    return BOOT_UM_ERR_NO;
}
Exemplo n.º 28
0
PRIVATE UINT8 boot_UsbContinueTransfert(UINT8 ep)
{
    UINT8               epNum;
    REG32*              regSize;
    REG32*              regCtl;

    epNum = HAL_USB_EP_NUM(ep);

    if(HAL_USB_IS_EP_DIRECTION_IN(ep))
    {
        if(g_BootUsbVar.InTransfert[epNum].size <= 0)
        {
            return(1);
        }
        if(!(g_BootUsbVar.EpFlag & (1<<epNum)))
        {
            if(g_BootUsbVar.InTransfert[epNum].size >= HAL_USB_MPS)
            {
                if(epNum == 0)
                {
                    regSize = &hwp_usbc->DIEPTSIZ0;
                    regCtl  = &hwp_usbc->DIEPCTL0;
                }
                else
                {
                    regSize = &hwp_usbc->DIEPnCONFIG[epNum-1].DIEPTSIZ;
                    regCtl  = &hwp_usbc->DIEPnCONFIG[epNum-1].DIEPCTL;
                }

                *regSize = USBC_IEPXFERSIZE(g_BootUsbVar.InTransfert[epNum].size
                                            % HAL_USB_MPS) | USBC_IEPPKTCNT(1);
                *regCtl |= USBC_EPENA | USBC_CNAK;

                g_BootUsbVar.InTransfert[epNum].size = 1;
                return(0);
            }
        }
        g_BootUsbVar.InTransfert[epNum].size  = 0;
    }
    else
    {
        if(g_BootUsbVar.OutTransfert[epNum].size <= 0)
        {
            return(1);
        }

        if(epNum == 0)
        {
            regSize = &hwp_usbc->DOEPTSIZ0;
        }
        else
        {
            regSize = &hwp_usbc->DOEPnCONFIG[epNum-1].DOEPTSIZ;
        }

        g_BootUsbVar.OutTransfert[epNum].size -=
            GET_BITFIELD(*regSize, USBC_OEPXFERSIZE);
        g_BootUsbVar.OutTransfert[epNum].size  =
            -g_BootUsbVar.OutTransfert[epNum].size;
        if(g_BootUsbVar.OutTransfert[epNum].size > 0)
        {
            g_BootUsbVar.OutTransfert[epNum].size = 0;
        }
    }

    return(1);
}
Exemplo n.º 29
0
int ref_to_value(REF2 * R, V_DATA * V)
{

    char *cp;
    unsigned char *ucp;
    char **cpp;
#ifndef __Lynx__
    wchar_t **wcpp;
#endif
    short *shp;
    int *ip;
    long *lp;
    float *fp;
    double *dp;
    long long *llp;
    int bf;
    unsigned int ubf;
    int type;

    char *address = 0;

    /* 
     * This function is called from within the YACC parser. 
     * This function relies on the REF data structure to be filled -- 
     * YACC fills part of the REF struct and ref_attributes() fills 
     * the rest.
     *
     * This function will get the value of the parameter pointed by REF and
     * returns the value in param_right_ret.
     */

    /* I'm trying to keep from casting integer values to doubles and back again, esp.  for long longs, for they could
       get changed in all of the conversions */

//    if (R->deprecated) {
//        /* Removed input_processor as a parameter to ref_to_value for simplification but that means we no longer know
//           what I->print_deprecated is. Heck with it -- always print out this warning here. */
//        //send_hs(stderr, "\nWARNING: Deprecated variable referenced:\n"
//        //        "%s\nReturning value = 0.\n", R->reference);
//        V->type = R->attr->type;
//        V->value.ll = 0;
//        return (MM_NO_ERROR);
//    }

    type = R->attr->type;
    /* treat C++ bool reference as an unsigned char */
    if (type == TRICK_BOOLEAN) {
        type = TRICK_UNSIGNED_CHARACTER;
    }
    address = R->address;

//    if ((R->num_index < R->attr->num_index - 1) || ((R->address_req == 0) && (R->num_index < R->attr->num_index))) {
//        type = VOID_PTR;
//    }

    V->type = type;

    switch (type) {
        case TRICK_VOID_PTR:
            //if ((R->num_index < R->attr->num_index - 1) || ((R->address_req == 0) && (R->num_index < R->attr->num_index))) {
            //    V->value.vp = address;
            //} else {
                V->value.vp = *(void **) address;
            // }
            break;

        case TRICK_CHARACTER:
            cp = address;
            V->value.c = *cp;
            break;

        case TRICK_UNSIGNED_CHARACTER:
#if ( __linux | __sgi )
        case TRICK_BOOLEAN:
#endif
            ucp = (unsigned char *) address;
            V->value.c = (char) *ucp;
            break;

        case TRICK_STRING:
            cpp = (char **) address;
            V->value.cp = *cpp;
            break;

        case TRICK_WSTRING:
#ifndef __Lynx__
            wcpp = (wchar_t **) address;
            V->value.wcp = *wcpp;
#endif
            break;
        case TRICK_SHORT:
        case TRICK_UNSIGNED_SHORT:
            shp = (short *) address;
            V->value.s = *shp;
            V->type = TRICK_SHORT;
            break;

        case TRICK_INTEGER:
        case TRICK_ENUMERATED:
        case TRICK_UNSIGNED_INTEGER:
#if ( __sun | __APPLE__ )
        case TRICK_BOOLEAN:
#endif
            ip = (int *) address;
            V->value.i = *ip;
            break;

        case TRICK_LONG:
        case TRICK_UNSIGNED_LONG:
            lp = (long *) address;
            V->value.ll = (long long) *lp;
            break;

        case TRICK_FLOAT:
            fp = (float *) address;
            V->value.f = *fp;
            break;

        case TRICK_DOUBLE:
            dp = (double *) address;
            V->value.d = *dp;
            V->type = TRICK_DOUBLE;
            break;

        case TRICK_LONG_LONG:
        case TRICK_UNSIGNED_LONG_LONG:
            llp = (long long *) address;
            V->value.ll = *llp;
            V->type = TRICK_LONG_LONG;
            break;

        case TRICK_BITFIELD:
            bf = GET_BITFIELD(address, R->attr->size, R->attr->index[0].start, R->attr->index[0].size);
            if (R->attr->size == sizeof(int)) {
            } else if (R->attr->size == sizeof(short)) {
            } else if (R->attr->size == sizeof(char)) {
            } else {
                // ERROR
            }
            // TODO: always integer? or should we return short or char for those types?
            V->value.i = bf;
            V->type = TRICK_INTEGER;
            break;

        case TRICK_UNSIGNED_BITFIELD:
            ubf = GET_UNSIGNED_BITFIELD(address, R->attr->size, R->attr->index[0].start, R->attr->index[0].size);
            // TODO: always integer? or should we return short or char for those types?
            V->value.i = (int) ubf;
            V->type = TRICK_UNSIGNED_INTEGER;
            break;

    }

    return (MM_OK);

}
int Trick::VariableServerThread::write_binary_data( int Start, char *buf1, int PacketNum ) {
    int i;
    int ret ;
    int HeaderSize, MessageSize;
    int NumVariablesProcessed;
    unsigned int msg_type , offset, len ;
    unsigned int size ;
    unsigned int swap_int ;
    char * address = 0 ;
    char* param_name;

    //remove warning for unused PacketNum... to be deleted.
    (void)PacketNum ;

    /* start the offset 4 bytes into the message, we'll subtract the sizeof offset at the end */
    offset = sizeof(msg_type) + sizeof(offset) ;

    /* if we are here the msg_type is good, so send a 0, swapped or not 0 is still 0 */
    msg_type = VS_VAR_LIST ;
    memcpy(buf1, &msg_type , sizeof(msg_type)) ;
    HeaderSize = sizeof(msg_type);

    offset += sizeof(unsigned int) ;
    HeaderSize += sizeof(unsigned int);

    for (i = Start; i < (int)vars.size() ; i++) {

        // data to send was copied to buffer in copy_sim_data
        address = (char *)vars[i]->buffer_out;
        size = vars[i]->size ;

        param_name = vars[i]->ref->reference;
        len = strlen(param_name)  ;
        // when var_binary_nonames, do not put the variable names into the message to be sent
        if (binary_data_nonames) {
            MessageSize = sizeof(int) + sizeof(size) + size ;
        } else {
            MessageSize = sizeof(len) + len + sizeof(int) + sizeof(size) + size ;
        }

        /* make sure this message will fit in a packet by itself */
        if ( (HeaderSize + MessageSize) > MAX_MSG_LEN ) {
            message_publish(MSG_WARNING, "%p Variable Server buffer[%d] too small (need %d) for symbol %s, SKIPPING IT.\n",
                            &connection, MAX_MSG_LEN,
                            (int)(HeaderSize + MessageSize),
                            vars[i]->ref->reference );
            continue;
        }

        if ( (offset + MessageSize) < MAX_MSG_LEN ) {
            if (byteswap) {
                if (!binary_data_nonames) {
                    swap_int = trick_byteswap_int((int)len) ;
                    memcpy(&buf1[offset] , &swap_int , sizeof(len)) ;
                    offset += sizeof(len) ;

                    memcpy(&buf1[offset] , param_name , (size_t)len) ;
                    offset += len ;
                }

                swap_int = trick_byteswap_int(vars[i]->ref->attr->type) ;
                memcpy(&buf1[offset] , &swap_int , sizeof(int)) ;
                offset += sizeof(int) ;

                swap_int = trick_byteswap_int((int)size) ;
                memcpy(&buf1[offset] , &swap_int , sizeof(size)) ;
                offset += sizeof(size) ;

                /* TODO: There is a bug here, this call will want to swap the entire buffer, we may not have the whole buffer */
                trick_bswap_buffer(&buf1[offset], address, vars[i]->ref->attr, 1);
                offset += size ;
            }
            else {
                int temp_i ;
                unsigned int temp_ui ;

                if (!binary_data_nonames) {
                    memcpy(&buf1[offset] , &len , sizeof(len)) ;
                    offset += sizeof(len) ;

                    memcpy(&buf1[offset] , param_name , (size_t)len) ;
                    offset += len ;
                }

                memcpy(&buf1[offset] , &vars[i]->ref->attr->type , sizeof(int)) ;
                offset += sizeof(int) ;

                memcpy(&buf1[offset] , &size , sizeof(size)) ;
                offset += sizeof(size) ;

                switch ( vars[i]->ref->attr->type ) {
                    case TRICK_BITFIELD:
                        temp_i = GET_BITFIELD(address , vars[i]->ref->attr->size ,
                          vars[i]->ref->attr->index[0].start, vars[i]->ref->attr->index[0].size) ;
                        memcpy(&buf1[offset] , &temp_i , (size_t)size) ;
                    break ;
                    case TRICK_UNSIGNED_BITFIELD:
                        temp_ui = GET_UNSIGNED_BITFIELD(address , vars[i]->ref->attr->size ,
                                vars[i]->ref->attr->index[0].start, vars[i]->ref->attr->index[0].size) ;
                        memcpy(&buf1[offset] , &temp_ui , (size_t)size) ;
                    break ;
                    case TRICK_NUMBER_OF_TYPES:
                        // TRICK_NUMBER_OF_TYPES is an error case
                        temp_i = 0 ;
                        memcpy(&buf1[offset] , &temp_i , (size_t)size) ;
                    break ; 
                    default:
                        memcpy(&buf1[offset] , address , (size_t)size) ;
                    break ;
                }
                offset += size ;
            }
        }
        else {
            /* indicate that we're over the maximum size */
            if (debug >= 2) {
                message_publish(MSG_DEBUG, "%p tag=<%s> var_server buffer[%d] too small (need %d), sending multiple binary packets.\n",
                        &connection, connection.client_tag, MAX_MSG_LEN,
                        (int)(offset + MessageSize) );
            }
            break ;
        }
    }

    /* adjust the header with the correct information reflecting what has been accomplished */
    NumVariablesProcessed = i - Start;

    offset -= sizeof(offset) ;
    if (byteswap) {
        swap_int = trick_byteswap_int((int)offset) ;
        memcpy(buf1 + sizeof(msg_type) , &swap_int , sizeof(offset)) ;

        swap_int = trick_byteswap_int( NumVariablesProcessed ) ;
        memcpy( buf1 + sizeof(msg_type) + sizeof(offset), &swap_int , sizeof(swap_int)) ;
    }
    else {
        memcpy(buf1 + sizeof(msg_type) , &offset , sizeof(offset)) ;
        memcpy( buf1 + sizeof(msg_type) + sizeof(offset), &NumVariablesProcessed , sizeof( NumVariablesProcessed )) ;
    }

    if (debug >= 2) {
        message_publish(MSG_DEBUG, "%p tag=<%s> var_server sending %u binary bytes containing %d variables.\n", &connection,
                connection.client_tag, (unsigned int)(offset + sizeof(offset)), NumVariablesProcessed);
    }

    len = offset + sizeof(msg_type) ;
    ret = tc_write(&connection, (char *) buf1, len);
    if ( ret != (int)len ) {
        return(-1) ;
    }

    /* return the index to the next symbol to send or V->num_vars if all done */
    return i;
}