Milos RTOS v0.3.4a
Real Time Operating System
Functions
Collaboration diagram for Functions:

Functions

i32 __serialIOCtl (__PDEVICE dv, u32 cmd, u32 param, __PVOID data, u32 len)
 Device Input/Output control function.
i32 __serialInit (__PDEVICE dv, __PVOID params)
 Initialization.
i32 __serialDeinit (__PDEVICE dv)
 Serial device driver de-initialization.
i32 __serialOpen (__PDEVICE dv, u32 baudrate)
 Serial device driver open function.
i32 __serialClose (__PDEVICE dv)
 Serial device driver close function.
i32 __serialSize (__PDEVICE dv, u8 mode)
 Returns the count of the serial unsent/unread bytes.
i32 __serialRead (__PDEVICE dv, __PVOID buf, u16 qty)
 Serial device driver read function.
i32 __serialFlush (__PDEVICE dv)
 Serial device driver flush function.
i32 __serialWrite (__PDEVICE dv, __CONST __PVOID buf, u16 qty)
 Serial device driver write function.

Function Documentation

i32 __serialIOCtl ( __PDEVICE  dv,
u32  cmd,
u32  param,
__PVOID  data,
u32  len 
)

Device Input/Output control function.

Called from __deviceIOCtl().

Parameters:
dvPointer to a device.
cmdCommand code to execute. One of the following values:
  • __IOCTL_SETSPEED Sets the baudrate from the param parameter.
  • __IOCTL_GETSPEED Writes the current baudrate in the data parameter.
  • __IOCTL_SETRXTIMEOUT Sets the RX timeout from the param parameter.
  • __IOCTL_SETTXTIMEOUT Sets the TX timeout from the param parameter.
  • __IOCTL_ECHO_ONOFF Enables or disables the character echo on the serial port (param = non-zero to enable echo, param = 0 to disable echo).
  • __IOCTL_ECHO Returns non-zero if the echo is enabled, otherwise 0.
  • __IOCTL_SETSTOPBITS Set the stop bits. The value will be read from the param parameter and can be any of the Stop bits values.
  • __IOCTL_SETPARITY Set the parity. The value will be read from the param parameter and can be any of the Parity values.
  • __IOCTL_SETBITLENGHT Set the bit length. The value will be read from the param parameter and can be any of the Length values.
  • __IOCTL_SETFLOWCONTROL Set the flow control. The value will be read from the param parameter and can be any of the Flow control values.
Parameters:
paramInput parameter.
dataOptional data pointer.
lenLength of data.
Returns:
__DEV_OK on success, __DEV_ERROR on error, __DEV_UNK_IOCTL if the IO control code is not implemented.

Definition at line 93 of file serial.c.

{
    pu32 lpar = data;
    __PSERIAL_PDB   pd = dv->dv_pdb;
    
    switch(cmd)
    {
        case __IOCTL_SETSPEED:
            (dv->dv_plat_ioctl)(dv, __SERIAL_PLAT_SET_BAUDRATE, param,
                                __NULL, 0, __NULL, 0);
            pd->pd_baud = param;
            return __DEV_OK;

        case __IOCTL_GETSPEED:
            *lpar = pd->pd_baud = param;
            return __DEV_OK;

        case __IOCTL_SETRXTIMEOUT:
            pd->pd_rxtmo = (u16) param;
            return __DEV_OK;

        case __IOCTL_SETTXTIMEOUT:
            pd->pd_txtmo = (u16) param;
            return __DEV_OK;

        case __IOCTL_ECHO_ONOFF:
            pd->pd_echo = (u8) param;
            return __DEV_OK;

        case __IOCTL_ECHO:
            return pd->pd_echo;

        case __IOCTL_SETSTOPBITS:
            pd->pd_mode &= ~__SERIAL_STOPBITS_MASK;
            pd->pd_mode |= param;

            return ((dv->dv_plat_ioctl)
                    (dv,    __SERIAL_PLAT_SET_STOP_BITS, param, __NULL, 0, __NULL, 0));

        case __IOCTL_SETPARITY:
            pd->pd_mode &= ~__SERIAL_PARITY_MASK;
            pd->pd_mode |= param;

            return ((dv->dv_plat_ioctl)
                    (dv, __SERIAL_PLAT_SET_PARITY, param, __NULL, 0, __NULL, 0));

        case __IOCTL_SETBITLENGHT:
            pd->pd_mode &= ~__SERIAL_LENGTH_MASK;
            pd->pd_mode |= param;

            return ((dv->dv_plat_ioctl)
                    (dv, __SERIAL_PLAT_SET_LENGTH, param, __NULL, 0, __NULL, 0));

        case __IOCTL_SETFLOWCONTROL:
            pd->pd_mode &= ~__SERIAL_FLOW_MASK;
            pd->pd_mode |= param;

            return ((dv->dv_plat_ioctl)
                    (dv, __SERIAL_PLAT_SET_FLOW_CONTROL, param, __NULL, 0, __NULL, 0));

    }

    return __DEV_UNK_IOCTL;
}
i32 __serialInit ( __PDEVICE  dv,
__PVOID  params 
)

Initialization.

Called from __deviceInit() to initialize the serial device driver.

Parameters:
dvPointer to a device.
paramsPointer to __SERIAL_CONFIG structure.
Returns:
__DEV_OK on success, otherwise __DEV_ERROR.

Definition at line 168 of file serial.c.

{
    __PSERIAL_PDB pd = dv->dv_pdb;
    __PSERIAL_CONFIG config = (__PSERIAL_CONFIG) params;

    if (config == __NULL)
    {
        /* Use default values */
        pd->pd_rxlen = __SERIAL_MINRXBUFLEN;
        pd->pd_txlen = __SERIAL_MINTXBUFLEN;
    } else {
        pd->pd_rxlen = config->rxsize;
        pd->pd_txlen = config->txsize;
    }

    if (pd->pd_rxlen < __SERIAL_MINRXBUFLEN) pd->pd_rxlen = __SERIAL_MINRXBUFLEN;
    if (pd->pd_txlen < __SERIAL_MINTXBUFLEN) pd->pd_txlen = __SERIAL_MINTXBUFLEN;
    
    if (dv->dv_rxev) __memSet(dv->dv_rxev, 0, sizeof(__EVENT));
    if (dv->dv_txev) __memSet(dv->dv_txev, 0, sizeof(__EVENT));

    if ((pd->pd_rxbuf = __heapAlloc(pd->pd_rxlen)) == __NULL) return __DEV_ERROR;
    if ((pd->pd_txbuf = __heapAlloc(pd->pd_txlen)) == __NULL)
    {
        __heapFree(pd->pd_rxbuf);
        return __DEV_ERROR;
    }
    
    return __DEV_OK;
}

Here is the call graph for this function:

Serial device driver de-initialization.

Called from __deviceDeinit().

Parameters:
dvPointer to a device.
Returns:
__DEV_OK on success, otherwise __DEV_ERROR.

Definition at line 208 of file serial.c.

{
    __PSERIAL_PDB   pd = dv->dv_pdb;

    /* Check if still opened */
    if (dv->dv_opcnt != 0) return __DEV_ERROR;

    if (pd != __NULL) {
        if (pd->pd_rxbuf != __NULL) __heapFree(pd->pd_rxbuf);
        if (pd->pd_txbuf != __NULL) __heapFree(pd->pd_txbuf);
    }
    return __DEV_OK;
}

Here is the call graph for this function:

i32 __serialOpen ( __PDEVICE  dv,
u32  baudrate 
)

Serial device driver open function.

Called from __deviceOpen() to open the serial device.

Parameters:
dvPointer to a device.
baudrateDesired baud rate.
Returns:
__DEV_OK on success, otherwise __DEV_ERROR.

Definition at line 234 of file serial.c.

{
    __PSERIAL_PDB pd = dv->dv_pdb;

    /* Platform should configure the UART with the pd->pd_mode value */
    pd->pd_mode = __SERIAL_8_N_1;
    pd->pd_baud = baudrate;

    /*  Init hardware */
    if (((dv->dv_plat_ioctl)(dv, __SERIAL_PLAT_INIT_HW,
        0, __NULL, 0, __NULL, 0)) != __DEV_OK) return __DEV_ERROR;

    /* Set TX/RX interrupt vector */
    if  (((dv->dv_plat_ioctl)(dv,   __SERIAL_PLAT_SET_IRQ,
        0, __NULL, 0, __NULL, 0)) != __DEV_OK) return __DEV_ERROR;

    return __DEV_OK;
}

Serial device driver close function.

Called from __deviceClose() to close the serial device.

Parameters:
dvPointer to a device.
Returns:
__DEV_OK on success, otherwise __DEV_ERROR.

Definition at line 262 of file serial.c.

{
    /*  De-init hardware */
    (dv->dv_plat_ioctl)(dv, __SERIAL_PLAT_DEINIT_HW,
                            0, __NULL, 0, __NULL, 0);

    /* Disable TX/RX interrupt vector */
    (dv->dv_plat_ioctl)(dv, __SERIAL_PLAT_RESET_IRQ,
                        0, __NULL, 0, __NULL, 0);

    return __DEV_OK;
}

i32 __serialSize ( __PDEVICE  dv,
u8  mode 
)

Returns the count of the serial unsent/unread bytes.

Called from __deviceSize().

Parameters:
dvPointer to a device.
modeParameter defining on which buffer operate.
  • __DEV_RXSIZE Get the RX buffer unread bytes.
  • __DEV_TXSIZE Get the TX buffer unsent bytes.
Returns:
the serial unsent/unread bytes. -1 on error.

Definition at line 287 of file serial.c.

{
    __PSERIAL_PDB   pd = dv->dv_pdb;

    if (mode == __DEV_RXSIZE) return(pd->pd_rxcnt);
    if (mode == __DEV_TXSIZE) return(pd->pd_txcnt);
    return __DEV_ERROR;
}

i32 __serialRead ( __PDEVICE  dv,
__PVOID  buf,
u16  qty 
)

Serial device driver read function.

Read from the RX buffer if there is data available, otherwise it will wait on an event until receives data. Called from __deviceRead().

Parameters:
dvPointer to a device.
bufPointer to a buffer to receive the data.
qtyRequired quantity to read.
Returns:
Bytes read or -1 on error.

Definition at line 309 of file serial.c.

{
    u16 cnt = 0;
    __PSTRING   p = buf;
    __PSERIAL_PDB   pd = dv->dv_pdb;

    while (cnt < qty)
    {
        if (pd->pd_rxcnt > 0)
        {
            *p++ = *(pd->pd_rxbuf + pd->pd_rbidx);
            if (++pd->pd_rbidx >= pd->pd_rxlen) pd->pd_rbidx = 0;
            --pd->pd_rxcnt;
            ++cnt;
        } else
        {
            if (!dv->dv_rxev) return cnt;
            __eventReset(dv->dv_rxev);
            if (__eventWait(dv->dv_rxev,(u32) pd->pd_rxtmo) == __EVRET_TIMEOUT)
            {
                return cnt;
            }
        }
    }
    return cnt;
}

Here is the call graph for this function:

Serial device driver flush function.

Flush remaining unsent bytes through the UART. Called from __deviceFlush().

Parameters:
dvPointer to a device.
Returns:
__DEV_OK on success, __DEV_TIMEOUT on timeout.

Definition at line 345 of file serial.c.

{
    __PSERIAL_PDB pd = dv->dv_pdb;

    /* something to send? */
    if (!pd->pd_txcnt) return __DEV_OK;

    if (dv->dv_txev) __eventReset(dv->dv_txev);

    /*  Init transmission */
    (dv->dv_plat_ioctl)(dv, __SERIAL_PLAT_INIT_TX,
                        0, __NULL, 0, __NULL, 0);

    if (!dv->dv_txev) return 0;
    if (__eventWait(dv->dv_txev, pd->pd_txtmo) == __EVRET_SUCCESS) return __DEV_OK;

    return __DEV_TIMEOUT;
}

Here is the call graph for this function:

i32 __serialWrite ( __PDEVICE  dv,
__CONST __PVOID  buf,
u16  qty 
)

Serial device driver write function.

Writes to the TX buffer. Called from __deviceWrite().

Parameters:
dvPointer to a device.
bufPointer to the buffer containing data.
qtyQuantity of bytes to write.
Returns:
Bytes written or -1 on error.

Definition at line 375 of file serial.c.

{
    u16 cnt = 0;
    u8* p = (u8*) buf;
    __PSERIAL_PDB pd = dv->dv_pdb;

    while (cnt < qty)
    {
        if (pd->pd_txcnt < pd->pd_txlen)
        {
            *(pd->pd_txbuf + pd->pd_tbidx) = *p++;
            if (++pd->pd_tbidx >= pd->pd_txlen) pd->pd_tbidx = 0;
            ++pd->pd_txcnt;
            ++cnt;
        } else
        {
            if (__serialFlush(dv) != __DEV_OK)
            {
                return __DEV_ERROR;
            }
        }
    }
    return cnt;
}

Here is the call graph for this function:

 All Data Structures Files Functions Variables Typedefs Defines