Пример #1
1
T_uezError Network_lwIP_SocketConnect(
    void *aWorkspace,
    T_uezNetworkSocket aSocket,
    T_uezNetworkAddr *aAddr,
    TUInt16 aPort)
{
    T_Network_lwIP_Workspace *p = (T_Network_lwIP_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_NONE;
    T_lwIPSocket *p_socket = p->iSockets + aSocket;
    struct ip_addr ip;

    // Only valid sockets
    if ((aSocket == 0) || (aSocket > NETWORK_LWIP_NUM_SOCKETS))
        return UEZ_ERROR_HANDLE_INVALID;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    if (p_socket->iState == SOCKET_STATE_FREE) {
        error = UEZ_ERROR_HANDLE_INVALID;
    } else {
        IP4_ADDR(&ip, aAddr->v4[0], aAddr->v4[1], aAddr->v4[2], aAddr->v4[3]);

        error = IConvertErrorCode(netconn_connect(p_socket->iNetconn, &ip,
                                  aPort));
        if (error == UEZ_ERROR_NONE)
            p_socket->iFlags |= SOCKET_FLAG_CONNECTED;

    }
    UEZSemaphoreRelease(p->iSem);

    return error;
}
/*---------------------------------------------------------------------------*
 * Routine:  Flash_Renesas_RX63N_Read
 *---------------------------------------------------------------------------*
 * Description:
 *      Read bytes out of the Flash.
 * Inputs:
 *      void *aW                    -- Workspace
 *      TUInt32 aOffset             -- Byte Offset address into flash to read
 *      TUInt8 *aBuffer             -- Pointer to buffer to receive data
 *      TUInt32 aNumBytes           -- Number of bytes to read
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError Flash_Renesas_RX63N_Read(
        void *aWorkspace,
        TUInt32 aOffset,
        TUInt8 *aBuffer,
        TUInt32 aNumBytes)
{
    T_Flash_Renesas_RX63N_Workspace *p = (T_Flash_Renesas_RX63N_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_NONE;
	//TUInt8* Temp;
    // Make sure its not in a programming mode.
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
	
	IExitProgramMode(p);
	current_mode = READ_MODE;

    // The memory is now accessible, copy the data over
	// Simple copy with check to see if the requested area is within the data flash
	if((void *)(((volatile TUInt8 *)p->iBaseAddr)+aOffset)>=(void*)DF_ADDRESS && 
		(void *)(((volatile TUInt8 *)p->iBaseAddr)+aOffset)<=(void*)(DF_ADDRESS+DF_NUM_BLOCKS*DF_BLOCK_SIZE))
	{
		memcpy(aBuffer, (void *)(((volatile TUInt8 *)p->iBaseAddr)+aOffset), aNumBytes);
	}
	else{
        UEZSemaphoreRelease(p->iSem);
		return UEZ_ERROR_OUT_OF_RANGE;
	}

    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #3
0
/*---------------------------------------------------------------------------*
 * Routine: SetLevel
 *---------------------------------------------------------------------------*
 * Description: 
 *      Set the gain of the audio amp to the desired level
 * Inputs:
 *      void *aWorkspace
 *      TUInt8 aLevel             --new level to set the amp to
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError AudioAmp_LM48110_SetLevel(void *aWorkSpace, TUInt8 aLevel)
{
    T_AudioAmp_LM48110_Workspace *p = (T_AudioAmp_LM48110_Workspace *)aWorkSpace;
    T_uezDevice i2c;
    TUInt8 data[5] = { 0x1C, //Turn on both inputs
                       0x20, //Mask for Diagnostic
                       0x40, //Mask for Fault
    };
    TUInt8 setLevel;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    p->iLevel = aLevel;
    setLevel = ((p->iLevel * (p->iMaxLevel - p->iMinLevel))/0xFF) + p->iMinLevel;

    data[3] = (VOLUME_1_MASK | setLevel);
    data[4] = (VOLUME_2_MASK | setLevel);

    if(!p->iIsMuted){
        if(UEZI2COpen(p->iI2CBus, &i2c) == UEZ_ERROR_NONE){
            UEZI2CWrite(i2c, LM48100_ADDR, LM48100_SPEED, data, 5, 100);//UEZ_TIMEOUT_INFINITE);
            UEZI2CClose(i2c);
        }
    }

    UEZSemaphoreRelease(p->iSem);
    return UEZ_ERROR_NONE;
}
Пример #4
0
/*---------------------------------------------------------------------------*
 * Routine:  LED_Generic_GPIO_Off
 *---------------------------------------------------------------------------*
 * Description:
 *      Get the current PCA9551 LEDBank reading
 * Inputs:
 *      void *aW                    -- Workspace
 *      T_uezTimeDate *aTimeDate    -- Time and date returned
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError LED_Generic_GPIO_Off(void *aWorkspace, TUInt32 aLEDs)
{
    T_LED_Generic_GPIO_Workspace *p =
        (T_LED_Generic_GPIO_Workspace *)aWorkspace;
    TUInt32 bitMask;
    TUInt8 i;
    T_LEDGPIOEntry *p_entry;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
    p_entry = p->iEntries;
    for (i = 0, bitMask = 1; i < p->iNumEntries; i++, bitMask <<= 1, p_entry++) {
        // Set the bits to on if bit is set
        if (aLEDs & bitMask) {
            p_entry->iLEDState = STATE_OFF;
            if (p_entry->iIsHighTrue) {
                (*p_entry->iGPIOPort)->Clear(p_entry->iGPIOPort, (1
                    << p_entry->iGPIOPinIndex));
            } else {
                (*p_entry->iGPIOPort)->Set(p_entry->iGPIOPort, (1
                    << p_entry->iGPIOPinIndex));
            }
            (*p_entry->iGPIOPort)->SetOutputMode(p_entry->iGPIOPort, (1
                << p_entry->iGPIOPinIndex));
        }
    }
    UEZSemaphoreRelease(p->iSem);

    return UEZ_ERROR_NONE;
}
Пример #5
0
 /*---------------------------------------------------------------------------*/
static TBool IHandleForward(WM_MESSAGE * pMsg, int aNCode, int aID)
{
    T_ImageMessage message;
    TUInt32 *tempPointer;

    if (aNCode == WM_NOTIFICATION_RELEASED) {
        UEZSemaphoreGrab(G_LoadingSemaphore, UEZ_TIMEOUT_INFINITE);
        tempPointer = G_PreviousImage;
        G_PreviousImage = G_CurrentImage;
        G_CurrentImage = G_NextImage;
        G_NextImage = tempPointer;
        if (G_CurrentImage_Number < G_NumImagesOnCard){
            G_CurrentImage_Number++;
        } else {
            G_CurrentImage_Number = 1;
        }
        UEZSemaphoreRelease(G_LoadingSemaphore);

        message = IMAGE_ADVANCED;
        UEZQueueSend(G_ImageLoadQueue,
                (void*)&message,
                50);
        WM_InvalidateWindow(pMsg->hWin);
        IHideButtonsAndText(pMsg);
    }
    return EFalse;
}
Пример #6
0
/*---------------------------------------------------------------------------*
 * Routine: SetLevel
 *---------------------------------------------------------------------------*
 * Description: 
 *      Set the gain of the audio amp to the desired level
 * Inputs:
 *      void *aWorkspace
 *      TUInt8 aLevel             --new level to set the amp to
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError AudioAmp_WM8731_SetLevel(void *aWorkSpace, TUInt8 aLevel)
{
    T_AudioAmp_WM8731_Workspace *p = (T_AudioAmp_WM8731_Workspace *)aWorkSpace;
    T_uezDevice i2c;
    TUInt8 data[4];
    TUInt8 setLevel;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
    p->iLevel = aLevel;
    setLevel = ((p->iLevel * (p->iMaxLevel - p->iMinLevel))/0xFF) + p->iMinLevel;
    if(!p->iIsMuted){
        if(UEZI2COpen(p->iI2CBus, &i2c) == UEZ_ERROR_NONE){
            data[0] = WM8731_LOUT1V;
            data[1] = (0 << 7) |  //RZCEN
                    setLevel; //VOL
            UEZI2CWrite(i2c, WM8731_ADDR, WM8731_I2C_Speed, data, 2, 100);
            data[0] = WM8731_ROUT1V;
            data[1] = (0 << 7) |  //RZCEN
                    setLevel; //VOL
            UEZI2CWrite(i2c, WM8731_ADDR, WM8731_I2C_Speed, data, 3, 100);
            UEZI2CClose(i2c);
        }
    }
    UEZSemaphoreRelease(p->iSem);
    return UEZ_ERROR_NONE;
}
Пример #7
0
/*---------------------------------------------------------------------------*
 * Routine:  Flash_NXP_LPC17xx_40xx_Read
 *---------------------------------------------------------------------------*
 * Description:
 *      Read bytes out of the Flash.
 * Inputs:
 *      void *aW                    -- Workspace
 *      TUInt32 aOffset             -- Byte Offset address into flash to read
 *      TUInt8 *aBuffer             -- Pointer to buffer to receive data
 *      TUInt32 aNumBytes           -- Number of bytes to read
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError Flash_NXP_LPC17xx_40xx_Read(
    void *aWorkspace,
    TUInt32 aOffset,
    TUInt8 *aBuffer,
    TUInt32 aNumBytes)
{
    T_Flash_NXP_LPC17xx_40xx_Workspace *p =
        (T_Flash_NXP_LPC17xx_40xx_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_NONE;

    // Make sure its not in a programming mode.
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    ILPC17xx_40xx_IAP_End();

    // The memory is now accessible, copy the data over
    // Simple copy with check to see if the requested area is within the data flash
    if ((aOffset + (TUInt32)aNumBytes) <= (512 * 1024)) {
        memcpy(aBuffer, (void *)(aOffset), aNumBytes);
    } else {
        return UEZ_ERROR_OUT_OF_RANGE;
    }

    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #8
0
/*---------------------------------------------------------------------------*
 * Routine:  Flash_NXP_LPC17xx_40xx_Write
 *---------------------------------------------------------------------------*
 * Description:
 *      Write bytes into the Flash
 * Inputs:
 *      void *aW                    -- Workspace
 *      TUInt32 aOffset             -- Byte Offset into flash to write
 *      TUInt8 *aBuffer             -- Pointer to buffer of data
 *      TUInt32 aNumBytes           -- Number of bytes to write
 * Outputs:
 *      T_uezError                  -- Error code.  Returns
 *                                      UEZ_ERROR_BAD_ALIGNMENT if offset
 *                                      or number of bytes
 *                                      is not on word boundary.
 *---------------------------------------------------------------------------*/
T_uezError Flash_NXP_LPC17xx_40xx_Write(
    void *aWorkspace,
    TUInt32 aOffset,
    TUInt8 *aBuffer,
    TUInt32 aNumBytes)
{
    T_Flash_NXP_LPC17xx_40xx_Workspace *p =
        (T_Flash_NXP_LPC17xx_40xx_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_NONE;

    // Let's do it
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    // Write the given block of data to the given address
    // Cut up the write command into blocks of BLOCK_SIZE size.
    // Keep doing this until all the bytes are processed
    while (aNumBytes) {
        error = IIAPWrite(&aOffset, &aBuffer, &aNumBytes);
        if (error != UEZ_ERROR_NONE)
            break;
    }

    UEZSemaphoreRelease(p->iSem);

    return error;
}
/*---------------------------------------------------------------------------*
 * Routine:  Serial_GenericHalfDuplex_Write
 *---------------------------------------------------------------------------*
 * Description:
 *      Write data out the serial port or timeout trying.  If a timeout,
 *      the number of bytes written is reported.
 * Inputs:
 *      void *aWorkspace          -- This serial GenericHalfDuplex workspace
 *      TUInt8 *aData             -- Data to send
 *      TUInt32 aNumBytes         -- Number of bytes to read.
 *      TUInt32 *aNumBytesWritten -- Number of bytes actually written.  If
 *                                   timeout occurs, this value is less than
 *                                   aNumBytes.
 * Outputs:
 *      T_uezError                 -- Error code.  UEZ_ERROR_TIMEOUT is returned
 *                                   if timeout occurs trying to write
 *                                   the full amount and not enough room was
 *                                   available.  UEZ_ERROR_NONE is reported if
 *                                   all data is written.
 *---------------------------------------------------------------------------*/
T_uezError Serial_GenericHalfDuplex_Write(
            void *aWorkspace, 
            TUInt8 *aData, 
            TUInt32 aNumBytes, 
            TUInt32 *aNumBytesWritten,
            TUInt32 aTimeout)
{
    // Decrement use count.  Are we done?
    T_Serial_GenericHalfDuplex_Workspace *p = (T_Serial_GenericHalfDuplex_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_NONE;
    TUInt32 i;

    for (i=0; i<aNumBytes; i++)  {
        // Send bytes one at a time
        UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

        // Don't let interrupts occur while we do this one
        (*p->iSerial)->Deactivate((T_halWorkspace *)p->iSerial);

        // Are we currently busy sending data?
        if (p->iTxBusy) {
            // Yes, busy, stuff another byte into the end of the queue
            error = UEZQueueSend(p->iQueueSend, aData, aTimeout);
        } else {
            // Transmit is not busy yet.  But we're about to be

            // Start driving again
            if (p->iDriveEnablePort) {
                if (p->iDriveEnablePolarity) {
                    (*p->iDriveEnablePort)->Set(p->iDriveEnablePort, p->iDriveEnablePin);
                } else {
                    (*p->iDriveEnablePort)->Clear(p->iDriveEnablePort, p->iDriveEnablePin);
                }
            }

            // Declare transmit busy
            p->iTxBusy = ETrue;
            UEZSemaphoreGrab(p->iSemEmpty, 0);
            p->iDidOutput = ETrue;
            error = (*p->iSerial)->OutputByte((T_halWorkspace *)p->iSerial, *aData);
        }
        (*p->iSerial)->Activate((T_halWorkspace *)p->iSerial);

        UEZSemaphoreRelease(p->iSem);

        // Report any errors up to this point
        if (error)
            break;

        // Next byte
        aData++;
    }

    // Report how many bytes we did get
    if (aNumBytesWritten)
        *aNumBytesWritten = i;
    
    // Report final error
    return error;
}
Пример #10
0
/*---------------------------------------------------------------------------*
 * Routine:  Network_lwIP_Scan
 *---------------------------------------------------------------------------*
 * Description:
 *      Start a scan and setup a callback routine for receiving events.
 * Inputs:
 *      void *aWorkspace -- Workspace
 *      T_uezNetworkScanCallback *aCallback -- Routine to call when a scan is
 *          found or the scan is complete
 *      void *aCallbackWorkspace -- Workspace to use with the callback
 *      char *aScanSSID -- ID to scan under (null string if none)
 *      TUInt32 aTimeout -- Total time in ms to attempt scan before timing out.
 * Outputs:
 *      T_uezError -- Error code
 *---------------------------------------------------------------------------*/
T_uezError Network_lwIP_Scan(
    void *aWorkspace,
    TUInt32 aChannelNumber,
    const char *aScanSSID,
    T_uezNetworkScanCallback aCallback,
    void *aCallbackWorkspace,
    TUInt32 aTimeout)
{
    T_Network_lwIP_Workspace *p = (T_Network_lwIP_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_NONE;
    T_uezNetworkInfo scanInfo;

    PARAM_NOT_USED(aCallback);
    PARAM_NOT_USED(aCallbackWorkspace);

    // Doing a scan is an exclusive command.  Nothing else can be
    // processing.
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    scanInfo.iRSSILevel = 0;
    scanInfo.iSecurityMode = UEZ_NETWORK_SECURITY_MODE_OPEN;
    scanInfo.iChannel = 0;
    strcpy(scanInfo.iName, "lwIP");
    p->iInfo = scanInfo;
    p->iScanStatus = UEZ_NETWORK_SCAN_STATUS_COMPLETE;

    if (aCallback) {
        aCallback(aCallbackWorkspace, &scanInfo);
    }

    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #11
0
/*---------------------------------------------------------------------------*
 * Routine:  PWM_Generic_SetMatchRegister
 *---------------------------------------------------------------------------*
 * Description:
 *      Configure one of the several match registers for this PWM bank.
 * Outputs:
 *      void *aWorkspace        -- PWM's workspace
 *      TUInt8 aMatchRegister   -- Index to match register (0-7)
 *      TUInt32 aMatchPoint     -- Number of PWM cycles until match
 *      TBool aDoInterrupt      -- ETrue if want an interrupt, else EFalse
 *                                  (NOTE: Interrupts currently not 
 *                                  implemented)
 *      TBool aDoCounterReset   -- ETrue if counter for this PWM bank is
 *                                  to be reset on match.
 *      TBool aDoStop           -- ETrue if counter is to be stopped
 *                                  when match occurs.
 *---------------------------------------------------------------------------*/
static T_uezError PWM_Generic_SetMatchRegister(
        void *aWorkspace, 
        TUInt8 aMatchRegister,
        TUInt32 aMatchPoint,
        TBool aDoInterrupt,
        TBool aDoCounterReset,
        TBool aDoStop)
{
    T_PWM_Generic_Workspace *p = (T_PWM_Generic_Workspace *)aWorkspace;
    T_uezError error;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    error = (*p->iPWM)->SetMatchRegister(
                p->iPWM, 
                aMatchRegister, 
                aMatchPoint, 
                aDoInterrupt, 
                aDoCounterReset, 
                aDoStop);

    UEZSemaphoreRelease(p->iSem);

    return error;
}
/*---------------------------------------------------------------------------*
 * Routine:  Button_NXP_PCA9551_Blink
 *---------------------------------------------------------------------------*
 * Description:
 *      Blink the given Buttons with the blink register.
 * Inputs:
 *      void *aW                    -- Workspace
 *      TUInt32 aBlinkReg           -- Blink register used to control blink
 *      TUInt32 aButtons               -- Bit mask of Buttons to blink
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError Button_NXP_PCA9551_Blink(
        void *aWorkspace, 
        TUInt32 aBlinkReg,
        TUInt32 aButtons)
{
    T_Button_NXP_PCA9551_Workspace *p = (T_Button_NXP_PCA9551_Workspace *)aWorkspace;
    TUInt8 i;
    TUInt32 bitMask;
    T_uezError error;
    TUInt8 state = STATE_BLINK0;
    if (aBlinkReg)
        state = STATE_BLINK1;

    // Allow only one transfer at a time
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    for (i=0, bitMask=1; i<8; i++, bitMask<<=1) {
        // Set the bits to on if bit is set
        if (aButtons & bitMask)
            p->iButtonsState[i] = state;
    }

    // Update the Buttons state
    error = IUpdateButtons(p);

    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #13
0
T_uezError Network_lwIP_SocketClose(
    void *aWorkspace,
    T_uezNetworkSocket aSocket)
{
    T_Network_lwIP_Workspace *p = (T_Network_lwIP_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_UNKNOWN;
    T_lwIPSocket *p_socket = p->iSockets + aSocket;

    // Only valid sockets
    if ((aSocket == 0) || (aSocket > NETWORK_LWIP_NUM_SOCKETS))
        return UEZ_ERROR_HANDLE_INVALID;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    if (p_socket->iState == SOCKET_STATE_FREE) {
        error = UEZ_ERROR_HANDLE_INVALID;
    } else if ((p_socket->iFlags & SOCKET_FLAG_CONNECTED) == 0) {
        error = UEZ_ERROR_NOT_OPEN;
    } else {
        // Delete any receive buffers still open
        if (p_socket->iReceiveNetBuf) {
            netbuf_delete(p_socket->iReceiveNetBuf);
        }
        p_socket->iReceiveData = 0;
        p_socket->iReceiveLength = 0;
        p_socket->iReceiveRemaining = 0;
        p_socket->iReceiveNetBuf = 0;
        p_socket->iFlags = 0;
        error = IConvertErrorCode(netconn_close(p_socket->iNetconn));
    }

    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #14
0
/*---------------------------------------------------------------------------*
 * Routine:  RTC_PCF8563_Get
 *---------------------------------------------------------------------------*
 * Description:
 *      Get the current RTC clock reading.
 * Inputs:
 *      void *aW                    -- Workspace
 *      T_uezTimeDate *aTimeDate    -- Time and date returned
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError RTC_PCF8563_Get(void *aWorkspace, T_uezTimeDate *aTimeDate)
{
    T_uezError error;
    T_RTC_PCF8563_Workspace *p = (T_RTC_PCF8563_Workspace *)aWorkspace;
    I2C_Request r;
    TUInt8 data[16];
    TUInt8 reg0[1] = {0x00};

    r.iAddr = PCF8563_I2C_ADDR;
    r.iSpeed = PCF8563_I2C_SPEED;
    r.iWriteData = reg0;
    r.iWriteLength = 1;
    r.iWriteTimeout = UEZ_TIMEOUT_INFINITE;
    r.iReadData = data;
    r.iReadLength = 16;
    r.iReadTimeout = UEZ_TIMEOUT_INFINITE;  // wait until bus ready

    // Allow only one transfer at a time
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    error = (*p->iI2C)->ProcessRequest(p->iI2C, &r);
    if (!error) {
        aTimeDate->iTime.iSecond = IBCDToDecimal(data[2] & 0x7F);
        aTimeDate->iTime.iMinute = IBCDToDecimal(data[3] & 0x7F);
        aTimeDate->iTime.iHour = IBCDToDecimal(data[4] & 0x3F);
        aTimeDate->iDate.iMonth = IBCDToDecimal(data[7] & 0x1F);
        aTimeDate->iDate.iDay = IBCDToDecimal(data[5] & 0x3F);
        aTimeDate->iDate.iYear = 2000+IBCDToDecimal(data[8] & 0xFF);
    }

    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #15
0
T_uezError Network_lwIP_SocketDelete(
    void *aWorkspace,
    T_uezNetworkSocket aSocket)
{
    T_Network_lwIP_Workspace *p = (T_Network_lwIP_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_NONE;
    T_lwIPSocket *p_socket = p->iSockets + aSocket;

    // Only valid sockets
    if ((aSocket == 0) || (aSocket > NETWORK_LWIP_NUM_SOCKETS))
        return UEZ_ERROR_HANDLE_INVALID;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
    if (p_socket->iState == SOCKET_STATE_FREE) {
        error = UEZ_ERROR_HANDLE_INVALID;
    } else if ((p_socket->iFlags & SOCKET_FLAG_CONNECTED) != 0) {
        error = UEZ_ERROR_MUST_CLOSE_FIRST;
    } else {
        netconn_delete(p_socket->iNetconn);
        ISocketFree(p, aSocket);
    }
    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #16
0
T_uezError Network_lwIP_SocketListen(
    void *aWorkspace,
    T_uezNetworkSocket aSocket)
{
    T_Network_lwIP_Workspace *p = (T_Network_lwIP_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_UNKNOWN;
    T_lwIPSocket *p_socket = p->iSockets + aSocket;

    // Only valid sockets
    if ((aSocket == 0) || (aSocket > NETWORK_LWIP_NUM_SOCKETS))
        return UEZ_ERROR_HANDLE_INVALID;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
    if (p_socket->iState == SOCKET_STATE_FREE) {
        error = UEZ_ERROR_HANDLE_INVALID;
    } else {
        error = IConvertErrorCode(netconn_listen(p_socket->iNetconn));
        if (error == UEZ_ERROR_NONE) {
            p_socket->iState = SOCKET_STATE_LISTENING;
        }
    }
    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #17
0
T_uezError RTC_PCF8563_SetClockOutHz(
        void *aWorkspace,
        TUInt32 aHertz)
{
    T_uezError error = UEZ_ERROR_NOT_SUPPORTED;
    T_RTC_PCF8563_Workspace *p = (T_RTC_PCF8563_Workspace *)aWorkspace;
    TUInt8 value;
    typedef struct { TUInt32 iHertz; TUInt8 iControl; } T_pcf8563_clockOut;
    const T_pcf8563_clockOut clockOutLookupTable[] = {
        { 32768, CLKOUT_FE|0 },
        { 1024, CLKOUT_FE|1 },
        { 32, CLKOUT_FE|2 },
        { 1, CLKOUT_FE|3 },
        { 0, 0 },
    };
    TUInt32 i;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    // Look in the above table and if found, change the value
    // otherwise, fall through and report NOT_SUPPORTED
    for (i=0; i<ARRAY_COUNT(clockOutLookupTable); i++) {
        if (clockOutLookupTable[i].iHertz == aHertz) {
            error = RTC_PCF8563_ReadReg(p, CLKOUT_control, &value);
            value &= ~0x83;
            if (error == UEZ_ERROR_NONE)
                error = RTC_PCF8563_WriteReg(p, CLKOUT_control, value|clockOutLookupTable[i].iControl);
            break;
        }
    }

    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #18
0
/*---------------------------------------------------------------------------*
 * Routine:  Network_lwIP_Join
 *---------------------------------------------------------------------------*
 * Description:
 *      Join a network access point
 * Inputs:
 *      void *aWorkspace -- Workspace
 *      char *aJoinName -- Name of network to join
 *      char *aJoinPassword -- Password for access (or empty string for none)
 *      TUInt32 aTimeout -- Time out until abort join
 * Outputs:
 *      T_uezError -- Error code
 *---------------------------------------------------------------------------*/
T_uezError Network_lwIP_Join(
    void *aWorkspace,
    const char *aJoinName,
    const char *aJoinPassword,
    TUInt32 aTimeout)
{
    T_Network_lwIP_Workspace *p = (T_Network_lwIP_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_NONE;

    // Doing a join is an exclusive command.  Nothing else can be
    // processing.
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    // You can only join the group "lwIP"
    if (strcmp(aJoinName, "lwIP")) {
        error = UEZ_ERROR_NOT_FOUND;
        p->iJoinStatus = UEZ_NETWORK_JOIN_STATUS_FAIL;
    } else {
        // Passwords are ignored
        // Right name
        p->iJoinStatus = UEZ_NETWORK_JOIN_STATUS_SUCCESS;
        error = UEZ_ERROR_NONE;
    }

    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #19
0
/*---------------------------------------------------------------------------*
 * Routine:  Flash_Renesas_RX63N_BlockErase
 *---------------------------------------------------------------------------*
 * Description:
 *      Erase one ore more blocks in the given location
 * Inputs:
 *      void *aW                    -- Workspace
 *      TUInt32 aAddress            -- Base address into device to write
 *      TUInt8 *aBuffer             -- Pointer to buffer of data
 *      TUInt32 aNumBytes           -- Number of bytes to write
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError Flash_Renesas_RX63N_BlockErase(
        void *aWorkspace,
        TUInt32 aBlockNum,
        TUInt32 aNumBytes)
{
    T_Flash_Renesas_RX63N_Workspace *p = (T_Flash_Renesas_RX63N_Workspace *)aWorkspace;
    
    T_uezError error = UEZ_ERROR_NONE;
    
	if(aNumBytes!= DF_BLOCK_SIZE)
	{
		error = UEZ_ERROR_NOT_ENOUGH_DATA;
		
	}else{
	
    	IEnsureChipInfo(aWorkspace);

 	   	// Let's do it
    	UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    	error = (T_uezError)R_FlashErase((TUInt8)aBlockNum);		//<<---- Check for Error Here

    	// Go ahead and force out of program mode
    	IExitProgramMode(p);

    	// Done erasing, resume normal control
    	UEZSemaphoreRelease(p->iSem);
	}

    return error;
}
Пример #20
0
/*---------------------------------------------------------------------------*
 * Routine:  Serial_GenericHalfDuplex_Flush
 *---------------------------------------------------------------------------*
 * Description:
 *      Write data out the serial port or timeout trying.  If a timeout,
 *      the number of bytes written is reported.
 * Inputs:
 *      void *aWorkspace          -- This serial generic workspace
 *      TUInt32 aTimeout          -- Timeout to wait for flush to finish
 * Outputs:
 *      T_uezError                 -- Error code.  UEZ_ERROR_TIMEOUT is returned
 *                                   if timeout occurs trying to write
 *                                   the full amount and not enough room was
 *                                   available.  UEZ_ERROR_NONE is reported if
 *                                   all data is written.
 *---------------------------------------------------------------------------*/
T_uezError Serial_GenericHalfDuplex_Flush(void *aWorkspace)
{
    // Decrement use count.  Are we done?
    T_Serial_GenericHalfDuplex_Workspace *p =   
        (T_Serial_GenericHalfDuplex_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_NONE;
    
    // Send bytes one at a time
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    // Don't let interrupts occur while we do this one
    (*p->iSerial)->Deactivate((T_halWorkspace *)p->iSerial);

    // Are we currently busy sending data?
    if (p->iTxBusy) {
        (*p->iSerial)->Activate((T_halWorkspace *)p->iSerial);
        // Yes, busy, wait for it to flush
        error = UEZSemaphoreGrab(p->iSemEmpty, UEZ_TIMEOUT_INFINITE);
    } else {
        (*p->iSerial)->Activate((T_halWorkspace *)p->iSerial);
        // Transmit is not busy yet.  But we're about to be
    }

    UEZSemaphoreRelease(p->iSem);

    // Report final error
    return error;
}
Пример #21
0
/*---------------------------------------------------------------------------*
 * Routine:  RTC_PCF8563_Validate
 *---------------------------------------------------------------------------*
 * Description:
 *      Validate the current RTC date and time.  If the date or time is
 *      invalid, reset to the given time and date.  If no date and time is
 *      given, just report that the RTC is invalid by returning
 *      UEZ_ERROR_INVALID.
 * Inputs:
 *      void *aW                    -- Workspace
 *      const T_uezTimeDate *aTimeDate -- Time and date to set to
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError RTC_PCF8563_Validate(
        void *aWorkspace,
        const T_uezTimeDate *aTimeDate)
{
    T_RTC_PCF8563_Workspace *p = (T_RTC_PCF8563_Workspace *)aWorkspace;
    T_uezError error;
    T_uezError ret_error = UEZ_ERROR_NONE;
    TUInt8 vlsec;

    // Allow only one transfer at a time
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    // Do the read
    error = RTC_PCF8563_ReadReg(p, VL_seconds, &vlsec);
    if (error) {
        // An error occurred in the communication to the part
        // Stop and return this error
        UEZSemaphoreRelease(p->iSem);
        return error;
    }

    // Is the data still got integrity?
    // (check high bit of VL_seconds)
    if (vlsec & 0x80) {
        // Integrity of data is bad
        ret_error = UEZ_ERROR_INVALID;

        // Was a new time/date setup passed in?
        if (aTimeDate) {
            // Set the time and date (without using semaphores since
            // we already have captured the semaphore)
            error = RTC_PCF8563_LowLevelSet(aWorkspace, aTimeDate);

            // Report any problems setting the time/date
            if (error) {
                UEZSemaphoreRelease(p->iSem);
                return error;
            }
        }
    }

    UEZSemaphoreRelease(p->iSem);

    // Return if we were invalid or not
    return ret_error;
}
Пример #22
0
/*---------------------------------------------------------------------------*
 * Routine:  Temperature_AnalogDevices_ADT7420_Read
 *---------------------------------------------------------------------------*
 * Description:
 *      Get the current ADT7420 temperature reading
 * Inputs:
 *      void *aW                    -- Workspace
 *      T_uezTimeDate *aTimeDate    -- Time and date returned
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError Temperature_AnalogDevices_ADT7420_Read(
    void *aWorkspace,
    TInt32 *aTemperature)
{
    T_uezError error = UEZ_ERROR_NONE;
    T_Temperature_AnalogDevices_ADT7420_Workspace *p =
        (T_Temperature_AnalogDevices_ADT7420_Workspace *)aWorkspace;
    I2C_Request r;
    TUInt8 data[2];
    TUInt8 reg0[2] = { 0x00, 0x00 };
    TInt32 v;

    // Allow only one transfer at a time
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
    if (!p->iConfigured) {
        r.iAddr = p->iI2CAddr;
        r.iSpeed = ADT7420_I2C_SPEED;
        r.iWriteData = reg0;
        r.iWriteLength = 2;
        r.iWriteTimeout = UEZ_TIMEOUT_INFINITE;
        r.iReadData = 0;
        r.iReadLength = 0;
        r.iReadTimeout = 0;
        p->iConfigured = ETrue;
        reg0[0] = ADT7420_CONFIG_REG;
        reg0[1] = 0;
        error = (*p->iI2C)->ProcessRequest(p->iI2C, &r);
    }
    if (error) {
        UEZSemaphoreRelease(p->iSem);
        return error;
    }

    r.iAddr = p->iI2CAddr;
    r.iSpeed = ADT7420_I2C_SPEED;
    r.iWriteData = reg0;
    r.iWriteLength = 1;
    r.iWriteTimeout = UEZ_TIMEOUT_INFINITE;
    r.iReadData = data;
    r.iReadLength = 2;
    r.iReadTimeout = UEZ_TIMEOUT_INFINITE; // wait until bus ready
    reg0[0] = ADT7420_TEMP_MSB_REG;

    error = (*p->iI2C)->ProcessRequest(p->iI2C, &r);
    if (!error) {
        // This temperature sensor is 11 bits up to about 125 C.
        // 3 bits are fraction, 7 bits are integer, and 1 sign bit

        // Put in the highest bits (masking off unused bits)
        v = (TInt32)((((data[0] << 8) | ((data[1]) << 0)) & 0xFFF8) << 16);

        // Now shift down to sign extend and get final result in 16.15 format
        v >>= 7;

        *aTemperature = (TInt32)v;
    }
Пример #23
0
T_uezError Network_lwIP_InfrastructureBringUp(void *aWorkspace)
{
    T_Network_lwIP_Workspace *p = (T_Network_lwIP_Workspace *)aWorkspace;
    T_uezError error;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
    error = IStartup(p, &p->iInfrastructureSettings);
    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #24
0
/*---------------------------------------------------------------------------*
 * Routine:  RTC_PCF8563_Set
 *---------------------------------------------------------------------------*
 * Description:
 *      Set the current RTC clock.
 * Inputs:
 *      void *aW                    -- Workspace
 *      const T_uezTimeDate *aTimeDate -- Time and date to set to
 * Outputs:
 *      T_uezError                   -- Error code
 *---------------------------------------------------------------------------*/
T_uezError RTC_PCF8563_Set(void *aWorkspace, const T_uezTimeDate *aTimeDate)
{
    T_RTC_PCF8563_Workspace *p = (T_RTC_PCF8563_Workspace *)aWorkspace;
    T_uezError error;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
    error = RTC_PCF8563_LowLevelSet(p, aTimeDate);
    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #25
0
/*---------------------------------------------------------------------------*
 * Routine:  Network_lwIP_Open
 *---------------------------------------------------------------------------*
 * Description:
 *      Open up a new network user
 * Inputs:
 *      void *aWorkspace -- Workspace
 * Outputs:
 *      T_uezError -- Error code
 *---------------------------------------------------------------------------*/
T_uezError Network_lwIP_Open(void *aWorkspace)
{
    T_Network_lwIP_Workspace *p = (T_Network_lwIP_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_NONE;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
    p->iNumOpen++;
    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #26
0
/*---------------------------------------------------------------------------*
 * Routine:  RTC_Generic_Validate
 *---------------------------------------------------------------------------*
 * Description:
 *      Normally, validate the current RTC date and time for integrity
 *      if the power has been out.  For generic usage, we'll always assume
 *      that the RTC is NOT valid and set it to the given setting.
 * Inputs:
 *      void *aW                    -- Workspace
 *      const T_uezTimeDate *aTimeDate -- Time and date to set to
 * Outputs:
 *      T_uezError                   -- Error code, always UEZ_ERROR_INVALID
 *---------------------------------------------------------------------------*/
static T_uezError RTC_Generic_Validate(
        void *aWorkspace, 
        const T_uezTimeDate *aTimeDate)
{
    T_RTC_Generic_Workspace *p = (T_RTC_Generic_Workspace *)aWorkspace;
    T_uezError error;

    // If the HAL driver has a Validate command, go ahead and use that
    // otherwise, assume its invalid
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
    if ((*p->iRTC)->Validate) {
        error = (*p->iRTC)->Validate(p->iRTC, aTimeDate);
        UEZSemaphoreRelease(p->iSem);
    } else {
        UEZSemaphoreRelease(p->iSem);
        RTC_Generic_Set(aWorkspace, aTimeDate);
        error = UEZ_ERROR_INVALID;
    }

    return error;
}
Пример #27
0
T_uezError Network_lwIP_InfrastructureConfigure(
    void *aWorkspace,
    T_uezNetworkSettings *aSettings)
{
    T_Network_lwIP_Workspace *p = (T_Network_lwIP_Workspace *)aWorkspace;

    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
    p->iInfrastructureSettings = *aSettings;
    UEZSemaphoreRelease(p->iSem);

    return UEZ_ERROR_NONE;
}
/*---------------------------------------------------------------------------*
 * Routine:  ST_Accelo_LIS3LV02DQ_I2C_ReadXYZ
 *---------------------------------------------------------------------------*
 * Description:
 *      Try to get the XYZ reading of the accelerometer
 * Inputs:
 *      void *aW                    -- Workspace
 *      AccelerometerReading *aReading -- Place to store reading
 *      TUInt32 aTimeout            -- Time to wait until reading is ready
 * Outputs:
 *      T_uezError                  -- Error code, UEZ_ERROR_TIMEOUT if no
 *                                      reading.
 *---------------------------------------------------------------------------*/
T_uezError ST_Accelo_LIS3LV02DQ_I2C_ReadXYZ(
        void *aWorkspace, 
        AccelerometerReading *aReading,
        TUInt32 aTimeout)
{
    TUInt32 i;
    TUInt8 status;

    T_uezError error;
    T_ST_Accelo_LIS3LV02DQ_I2C_Workspace *p = 
        (T_ST_Accelo_LIS3LV02DQ_I2C_Workspace *)aWorkspace;
    static TUInt8 accdata[18];

    aReading->iX = 0;
    aReading->iY = 0;
    aReading->iZ = 0;

    // Allow only one transfer at a time
    error = UEZSemaphoreGrab(p->iSem, aTimeout);
    if (error)
        return error;

    for (i=0; i<10; i++) { // try 10 times
        memset(accdata, 0xCC, sizeof(accdata));
        error = IReadData(p, accdata, 0x27, 7, 100);
        status = accdata[0];
        if (status & (1<<3)) {
            aReading->iX = ICalcG(accdata[2], accdata[1]);
            aReading->iY = ICalcG(accdata[4], accdata[3]);
            aReading->iZ = ICalcG(accdata[6], accdata[5]);
            p->iLastReading = *aReading;
            break;  // break if successful 
        }
        UEZTaskDelay(2);
/*
Array Contents After Read
accdata[0] - STATUS_REG (0x27)
accdata[1] - OUTX_L     (0x28)
accdata[2] - OUTX_H     (0x29)
accdata[3] - OUTY_L     (0x2A)
accdata[4] - OUTY_H     (0x2B)
accdata[5] - OUTZ_L     (0x2C)
accdata[6] - OUTZ_H     (0x2D)
*/
    }
    if (i==10) {
        *aReading = p->iLastReading;
    }
    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #29
0
T_uezError Network_lwIP_SocketWrite(
    void *aWorkspace,
    T_uezNetworkSocket aSocket,
    void *aData,
    TUInt32 aNumBytes,
    TBool aFlush,
    TUInt32 aTimeout)
{
    T_Network_lwIP_Workspace *p = (T_Network_lwIP_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_UNKNOWN;
    T_lwIPSocket *p_socket = p->iSockets + aSocket;
    TUInt16 numWrite;
    PARAM_NOT_USED(aTimeout);

    if ((aSocket == 0) || (aSocket > NETWORK_LWIP_NUM_SOCKETS))
        return UEZ_ERROR_HANDLE_INVALID;
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);

    if (p_socket->iState == SOCKET_STATE_FREE) {
        error = UEZ_ERROR_HANDLE_INVALID;
    } else if ((p_socket->iFlags & SOCKET_FLAG_CONNECTED) == 0) {
        error = UEZ_ERROR_NOT_OPEN;
    } else {
        while (aNumBytes) {
            // Send data up to a 16-bit value
            if (aNumBytes > 0xFFFF)
                numWrite = 0xFFFF;
            else
                numWrite = (TUInt16)aNumBytes;
            aNumBytes -= numWrite;

            // Clean up any previous timeout errors
            if (p_socket->iNetconn->err == ERR_TIMEOUT)
                p_socket->iNetconn->err = ERR_OK;
            // Write out this segment (noting if there is data past this one)
            error
                = IConvertErrorCode(netconn_write(p_socket->iNetconn, aData,
                                                  numWrite, NETCONN_COPY | ((aFlush) ? 0
                                                          : NETCONN_MORE)));
            // Stop on any errors
            if (error != UEZ_ERROR_NONE)
                break;

            aData = (void *)(((char *)aData) + numWrite);
        }
    }

    UEZSemaphoreRelease(p->iSem);

    return error;
}
Пример #30
0
/*---------------------------------------------------------------------------*
 * Routine:  Flash_Renesas_RX63N_Write
 *---------------------------------------------------------------------------*
 * Description:
 *      Write bytes into the Flash
 * Inputs:
 *      void *aW                    -- Workspace
 *      TUInt32 aOffset             -- Byte Offset into flash to write
 *      TUInt8 *aBuffer             -- Pointer to buffer of data
 *      TUInt32 aNumBytes           -- Number of bytes to write
 * Outputs:
 *      T_uezError                  -- Error code.  Returns
 *                                      UEZ_ERROR_BAD_ALIGNMENT if offset
 *                                      or number of bytes
 *                                      is not on word boundary.
 *---------------------------------------------------------------------------*/
T_uezError Flash_Renesas_RX63N_Write(
        void *aWorkspace,
        TUInt32 aOffset,
        TUInt8 *aBuffer,
        TUInt32 aNumBytes)
{
    T_Flash_Renesas_RX63N_Workspace *p = (T_Flash_Renesas_RX63N_Workspace *)aWorkspace;
    T_uezError error = UEZ_ERROR_NONE;
	TUInt8 padBuffer[256];
	TUInt8 ret = 0;
	TUInt8* flash_ptr = (TUInt8*)(p->iBaseAddr) + aOffset;
	// Let's do it
    UEZSemaphoreGrab(p->iSem, UEZ_TIMEOUT_INFINITE);
	
	memset(padBuffer, 0x00, 256);
	memcpy((void*)padBuffer, (void*)aBuffer, aNumBytes);
    while (1) {
    	/* Check if number of bytes is greater than 256 */
        if (aNumBytes > 256)
        {
            /* Number of bytes to write too high, set error flag to 1 */
            error = UEZ_ERROR_READ_WRITE_ERROR;
            break;
        }
        /* Check if number of bytes to write is a multiple of 8 */
        else if (aNumBytes % 8u)
        {
            /* Pad the data to write so it makes up to the nearest multiple of 8 */
            aNumBytes += 8u - (aNumBytes % 8u);
        }
	

    	// Passing the both the addresses, total offset and buffer(from where we want to write), as a value!!
    	error = (T_uezError)R_FlashWrite(((TUInt32)(p->iBaseAddr)+aOffset), (TUInt32)padBuffer,(TUInt16)aNumBytes ); //<<---- Check for error here
    
    	if(error) {
    		error = UEZ_ERROR_READ_WRITE_ERROR;
            break;
        }
	
    	ret = memcmp(aBuffer, flash_ptr, aNumBytes);
    	if(ret!=0) {
    		error = UEZ_ERROR_READ_WRITE_ERROR;
            break;
        }
        break;
    }
	UEZSemaphoreRelease(p->iSem);

    return error;
}