m2m_hw_uart_ioctl

M2M_T_HW_UART_RESULT m2m_hw_uart_ioctl(M2M_T_HW_UART_HANDLE handle,

INT32 arg, INT32 value)

 

Description: the function configures the UART port features using "arg" parameter (selector) and the "value" parameter (option).

 

Parameters:
handle: UART port handle
arg:    selector of the UART port feature, refer to the tables below
value: option related to the selected UART feature, refer to the tables below

 

 

arg: sets the UART feature

value: sets the option related to the selected UART feature

M2M_HW_UART_IO_BLOCKING_SET

valid for TX and RX

 

M2M_HW_UART_IO_BLOCKING_ON: sets blocking to ON, default mode.

 

TX: The API returns the control when "len" bytes have been moved to the UART transmitter buffer. "len_sent" points to the number of bytes moved, and it is equal to "len".

 

Note: the task that uses this mode could be blocked if  UART transmitter buffer has no more room until RTS line of the host is not ready (hardware flow control).

 

RX: The API returns the control when "len" or more bytes have been received. "len_read" is the number of bytes moved into the buffer, it is equal to "len".

Bytes exceeding "len" remain in the UART receiver buffer. You can delete them using the following function:

m2m_hw_uart_ioctl (handle, M2M_UART_CLEAR_RX, (INT32)

M2M_HW_UART_IO_NO_ARG)

 

 

M2M_HW_UART_IO_BLOCKING_OFF: sets blocking to OFF

 

TX: The API tries to move "len" bytes in UART transmitter buffer, in accordance with the available resources. In any case, returns immediately the control. "len_sent" points to the number of bytes actually moved into UART transmitter buffer

 

RX: The API collects "len" bytes if they are available in the UART receiver buffer, and returns immediately the control. "len_read" is the number of available bytes moved from UART receiver buffer into the allocated buffer pointed by "buffer".

 

 

M2M_HW_UART_IO_BLOCKING_RELEASE: releases both pending RX and TX activities, and set blocking to OFF. The new mode is blocking OFF

 

 

 

 

 

Example M2M_HW_UART_IO_BLOCKING_ON:

 

/* Set the next RX and TX activities in blocking ON */

m2m_hw_uart_ioctl (fd, M2M_HW_UART_IO_BLOCKING_SET, (INT32) M2M_HW_UART_IO_BLOCKING_ON);

 

/* Start RX and TX activities */

m2m_hw_uart_read (fd, buffer_rx, len_rx, &len_read);

m2m_hw_uart_write (fd, buffer_tx, len_tx, &len_sent);

 

 

Example M2M_HW_UART_IO_BLOCKING_OFF:

 

/* Set the next RX and TX activities in blocking OFF */

m2m_hw_uart_ioctl (fd, M2M_HW_UART_IO_BLOCKING_SET, (INT32) M2M_HW_UART_IO_BLOCKING_OFF);

 

/* Start RX and TX activities */

m2m_hw_uart_read (fd, buffer_rx, len_rx, &len_read);

m2m_hw_uart_write (fd, buffer_tx, len_tx, &len_sent);

 

 

Example M2M_HW_UART_IO_BLOCKING_RELEASE:

 

Task N:

...........

/* Set RX and TX activities in blocking ON mode */

m2m_hw_uart_ioctl (fd, M2M_HW_UART_IO_BLOCKING_SET, (INT32) M2M_HW_UART_IO_BLOCKING_ON);

...........

/* Start RX and TX activities */

m2m_hw_uart_read (fd, buffer_rx, len_rx, &len_read);

m2m_hw_uart_write (fd, buffer_tx, len_tx, &len_sent);

...........

 

Task M:

 

/* RX and TX pending activites are released */

...........

m2m_hw_uart_ioctl (fd, M2M_HW_UART_IO_BLOCKING_SET, (INT32) M2M_HW_UART_IO_BLOCKING_RELEASE);

...........

...........

 

Task N:

 

/* After releasing, start again RX and TX activities. Now, they are in blocking OFF mode  */

m2m_hw_uart_read (fd, buffer_read, len, &len_read);

m2m_hw_uart_write (fd, buffer_write, len, &len_sent);

...........

 

 

arg: sets the UART feature

value: sets the option related to the selected UART feature

M2M_HW_UART_RX_BLOCKING_SET

valid only for RX

M2M_HW_UART_IO_BLOCKING_ON: sets blocking to ON only for RX activity, default.

M2M_HW_UART_IO_BLOCKING_OFF: sets blocking to OFF only for RX activity.

M2M_HW_UART_IO_BLOCKING_RELEASE releases RX pending activity if any, and lets unchanged the blocking mode.

 

 

 

Example M2M_HW_UART_IO_BLOCKING_ON:

 

/* Set the next RX activity in blocking OFF */

m2m_hw_uart_ioctl (fd, M2M_HW_UART_RX_BLOCKING_SET, (INT32) M2M_HW_UART_IO_BLOCKING_OFF);

 

/* Start RX activity */

m2m_hw_uart_read (fd, buffer_rx, len_rx, &len_read);

 

 

Example M2M_HW_UART_IO_BLOCKING_RELEASE:

 

Task N:

...........

/* Set RX activity in blocking ON mode */

m2m_hw_uart_ioctl (fd, M2M_HW_UART_RX_BLOCKING_SET, (INT32) M2M_HW_UART_IO_BLOCKING_ON);

...........

/* Start RX activity */

m2m_hw_uart_read (fd, buffer_read, len, &len_read);

...........

 

Task M:

 

/* RX pending activity is released */

...........

m2m_hw_uart_ioctl (fd, M2M_HW_UART_RX_BLOCKING_SET, (INT32) M2M_HW_UART_IO_BLOCKING_RELEASE);

...........

...........

 

Task N:

 

/* After releasing, start again RX activities. RX blocking mode remains unchanged, therfore –in this example– remains in blocking ON mode  */

m2m_hw_uart_read (fd, buffer_read, len, &len_read);

...........

 

arg: sets the UART feature

value: sets the option related to the selected UART feature

M2M_HW_UART_TX_BLOCKING_SET

valid only for TX

M2M_HW_UART_IO_BLOCKING_ON: sets blocking to ON only for TX activity, default.

M2M_HW_UART_IO_BLOCKING_OFF: sets blocking to OFF only for TX activity

M2M_HW_UART_IO_BLOCKING_RELEASE: releases TX pending activity if any, and lets unchanged the blocking mode.

 

Refer to the previous M2M_HW_UART_RX_BLOCKING_SET examples.

 

arg: sets the UART feature

value: sets the option related to the selected UART feature

M2M_HW_UART_IO_AT_MODE_SET

Set AT command mode

M2M_HW_UART_IO_AT_MODE_OFF: default option. It routes the data received from the UART to the user AppZone application as they are, see document [4]/[8].

M2M_HW_UART_IO_AT_MODE_ON: this option routes the data received from the UART to AT1 parser by means of AZ1 logical port, see document [4]/[8]. In addition, it sets RX in blocking OFF, and TX blocking mode is unchanged.

 

Example M2M_HW_UART_IO_AT_MODE_SET:

void M2M_main(…)

{

  ......

 /* It is not mandatory to set the RX and TX blocking  mode to OFF */

 m2m_hw_uart_ioctl( uart_fd, M2M_HW_UART_IO_BLOCKING_SET, M2M_HW_UART_IO_BLOCKING_OFF );

 

 /* Sets RX in blocking OFF, and TX blocking mode is unchanged */

 m2m_hw_uart_ioctl (uart_fd, M2M_HW_UART_IO_AT_MODE_SET, M2M_HW_UART_IO_AT_MODE_ON);

 ......

}

 

/* The results of the entered AT commands are managed by the M2M_onReceiveResultCmd(…) callback function

    contained in the M2M_atRsp.c file, refer to document [1] */ 

INT32 M2M_onReceiveResultCmd (…)

{

·

}

 

 

 

 

arg: sets the UART feature

value: sets the option related to the selected UART feature

M2M_HW_UART_CLEAR_RX

Clear the RX buffer of the UART channel

M2M_HW_UART_IO_NO_ARG: the m2m_hw_uart_ioctl function uses an "arg" parameter that does not need options.

 

Example M2M_HW_UART_CLEAR_RX:

 

m2m_hw_uart_ioctl (handle, M2M_HW_UART_CLEAR_RX, (INT32) M2M_HW_UART_IO_NO_ARG);

 

 

arg: sets the UART feature

value: sets the option related to the selected UART feature

M2M_HW_UART_IO_RCV_FUNC

Indicates that the value parameter is a callback to manage received data

static INT32 hw_uart_read_cb ( M2M_T_HW_UART_HANDLE handle, CHAR  *buffer, INT32 len )

 

 

Example M2M_HW_UART_IO_RCV_FUNC:

 

static INT32 hw_uart_read_cb ( M2M_T_HW_UART_HANDLE handle, CHAR *buffer, INT32 len )

{

  CHAR serRxStr[ 128 ];

 

  strncpy( serRxStr, buffer, len );

  serRxStr[len]= 0;

  PRINT(serRxStr);

 

  return M2M_HW_UART_RESULT_SUCCESS;

}

 

void M2M_main(…)

{

 ·

 m2m_hw_uart_ioctl (handle, M2M_HW_UART_IO_RCV_FUNC,  (INT32) hw_uart_read_cb);

 ·

}

 

 

 

 

arg: sets the UART feature

value: sets the option related to the selected UART feature

M2M_HW_UART_IO_HW_OPTION_GET

Get the UART setting

Get the UART setting: baudrate, databits, stop_bits, flow_ctrl, and parity.

See M2M_T_HW_UART_IO_HW_OPTIONS structure

M2M_HW_UART_IO_HW_OPTION_SET

Set the UART setting

Set the UART: baudrate, databits, stop_bits, flow_ctrl, and parity.

See M2M_T_HW_UART_IO_HW_OPTIONS structure

 

Example M2M_HW_UART_IO_HW_OPTION_GET:

 

m2m_hw_uart_ioctl (handle, M2M_HW_UART_IO_HW_OPTIONS_GET, (INT32) &setting);

 

 

Example M2M_HW_UART_IO_HW_OPTION_SET:

 

m2m_hw_uart_ioctl (handle, M2M_HW_UART_IO_HW_OPTIONS_SET, (INT32) &setting);

 

 

Return value:
         refer to M2M_T_HW_UART_RESULT enum