From d5cbcd417c6ef270d3c2983d9e06d4ddec75d227 Mon Sep 17 00:00:00 2001 From: jede Date: Tue, 9 Apr 2024 22:04:22 +0200 Subject: [PATCH] fix --- docs/api/2024.2/assembly/index.html | 18 +++++++++++++++--- docs/api/assembly/index.html | 18 +++++++++++++++--- docs/api/search/search_index.json | 2 +- docs/api/sitemap.xml.gz | Bin 127 -> 127 bytes docs/code/2024.2/assembly.md | 24 +++++++++++++++++++++--- docs/code/assembly.md | 24 +++++++++++++++++++++--- 6 files changed, 73 insertions(+), 13 deletions(-) diff --git a/docs/api/2024.2/assembly/index.html b/docs/api/2024.2/assembly/index.html index 6460b4f..55258a4 100644 --- a/docs/api/2024.2/assembly/index.html +++ b/docs/api/2024.2/assembly/index.html @@ -1556,7 +1556,7 @@

ch395_set_des_port_sn

Example

 lda #$01
- ldx #80
+ ldy #80
  ldx #$00
  jsr ch395_set_des_port_sn
  rts
@@ -1663,7 +1663,17 @@ 

ch395_set_proto_type_sn

Input

  • Accumulator : Socket id
  • +
  • X Register : Proto mode
+

Modify

+
    +
  • Y Register tmp
  • +
+

Example

+
 lda #$00 ; Socket
+ ldx #CH395_PROTO_TYPE_TCP
+ jsr ch395_set_proto_type_sn
+

ch395_set_retran_count

Description

@@ -1702,8 +1712,8 @@

ch395_set_sour_port_sn

Input

  • Accumulator : Socket id
  • -
  • Y Register : Low ptr address
  • -
  • X Register : High ptr address
  • +
  • Y Register : Low port
  • +
  • X Register : High port

Modify

    @@ -1724,6 +1734,8 @@

    ch395_set_ttl


ch395_tcp_connect_sn

+

Description

+

Performs tcp connect

Input

  • Accumulator : Socket id
  • diff --git a/docs/api/assembly/index.html b/docs/api/assembly/index.html index 1277fc6..f2ae2d2 100644 --- a/docs/api/assembly/index.html +++ b/docs/api/assembly/index.html @@ -1210,7 +1210,7 @@

    ch395_set_des_port_sn

Example

 lda #$01
- ldx #80
+ ldy #80
  ldx #$00
  jsr ch395_set_des_port_sn
  rts
@@ -1317,7 +1317,17 @@ 

ch395_set_proto_type_sn

Input

  • Accumulator : Socket id
  • +
  • X Register : Proto mode
+

Modify

+
    +
  • Y Register tmp
  • +
+

Example

+
 lda #$00 ; Socket
+ ldx #CH395_PROTO_TYPE_TCP
+ jsr ch395_set_proto_type_sn
+

ch395_set_retran_count

Description

@@ -1356,8 +1366,8 @@

ch395_set_sour_port_sn

Input

  • Accumulator : Socket id
  • -
  • Y Register : Low ptr address
  • -
  • X Register : High ptr address
  • +
  • Y Register : Low port
  • +
  • X Register : High port

Modify

    @@ -1378,6 +1388,8 @@

    ch395_set_ttl


ch395_tcp_connect_sn

+

Description

+

Performs tcp connect

Input

  • Accumulator : Socket id
  • diff --git a/docs/api/search/search_index.json b/docs/api/search/search_index.json index be3cacd..6d74715 100644 --- a/docs/api/search/search_index.json +++ b/docs/api/search/search_index.json @@ -1 +1 @@ -{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Introduction","text":"

    This lib is used to manage ch395 chip for 6502 cpu

    "},{"location":"assembly/","title":"Assembly","text":""},{"location":"assembly/#assembly","title":"Assembly","text":""},{"location":"assembly/#ch395_check_exist","title":"ch395_check_exist","text":"

    Description

    This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.

    Modify

    • Accumulator

    Returns

    • Accumulator : Returns '#CH395_DETECTED' if it exists

    Example

     jsr ch395_check_exist\ncmp #CH395_DETECTED\nbeq ch395_connected\nrts\nch395_connected:\n
    "},{"location":"assembly/#ch395_clear_recv_buf_sn","title":"ch395_clear_recv_buf_sn","text":"

    Description

    This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.

    Input

    • Accumulator : Socket id

    Modify

    • Accumulator
    • Y Register

    Example

     lda #CH395_SOCKET1 ; Socket ID\njsr ch395_clear_recv_buf_sn\n
    "},{"location":"assembly/#ch395_close_socket_sn","title":"ch395_close_socket_sn","text":"

    Description

    This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.

    Input

    • Accumulator : The id of the socket to close

    Modify

    • Y Register

    Example

     lda #$01 ; Socket ID\njsr ch395_close_socket_sn\n
    "},{"location":"assembly/#ch395_dhcp_enable","title":"ch395_dhcp_enable","text":"

    Description

    This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status

    Input

    • Accumulator : The mode to activate DHCP mode

    Modify

    • X Register
    "},{"location":"assembly/#ch395_enter_sleep","title":"ch395_enter_sleep","text":"

    Description

    This command enables CH395 chip in a low-power sleep suspended state. When MCU writes a new command to CH395 (no data input command, such as CMD_GET_IC_VER), it will exit the low-power state. For the parallel port and SPI interface communication modes, active SCS chip selection will also cause CH395 to exit the low-power state, so MCU shall immediately disable the SCS chip selection after sending the command CMD_ENTER_SLEEP. In sleep state, MAC and PHY of CH395 will be in power off mode and disconnect Ethernet. Typically, it takes several milliseconds for CH395 to exit the low-power state.

    Does not work

    "},{"location":"assembly/#ch395_get_cmd_status","title":"ch395_get_cmd_status","text":"

    Description

    This command is used to get the command execution status. CH395 will output 1 byte of data, which is the command execution state. The command execution status is as follows:

    Example

     jsr ch395_get_cmd_status\n; Check A for STATUS\nrts\n

    Modify

    • Accumulator
    "},{"location":"assembly/#ch395_get_dhcp_status","title":"ch395_get_dhcp_status","text":"

    Description

    Get dhcp status

    Example

     jsr ch395_get_dhcp_status\n; Check A for dhcp status\nrts\n

    Modify

    • Accumulator
    "},{"location":"assembly/#ch395_get_glob_int_status_all","title":"ch395_get_glob_int_status_all","text":"

    Description

    This command is used to get the global interrupt status. CH395 will output 2 bytes of global interrupt status after receiving this command. Global interrupt status is defined as follows:

    Does not work

    "},{"location":"assembly/#ch395_get_glob_int_status","title":"ch395_get_glob_int_status","text":"

    Description

    This command is used to get the global interrupt status. CH395 will output 1 byte of global interrupt status after receiving this command. Global interrupt status is defined as follows:

    Bit Name Description

    7 GINT_STAT_SOCK3 Socket3 interrupt

    6 GINT_STAT_SOCK2 Socket2 interrupt

    5 GINT_STAT_SOCK1 Socket1 interrupt

    4 GINT_STAT_SOCK0 Socket0 interrupt

    3 GINT_STAT_DHCP DHCP interrupt

    2 GINT_STAT_PHY_CHANGE PHY status change interrupt

    1 GINT_STAT_IP_CONFLI IP conflict

    0 GINT_STAT_UNREACH Inaccessible interrupt

    \u2460 GINT_STAT_UNREACH: Inaccessible interrupt. When CH395 receives ICMP inaccessible interrupt

    message, it saves the IP address, port and protocol type of the inaccessible IP packet in the inaccessible

    information table, and then generates an interrupt. When the MCU receives the interrupt, it can send the

    command GET_UNREACH_IPPORT to get the inaccessible information.

    \u2461 GINT_STAT_IP_CONFLI: IP conflict interrupt. This interrupt is generated when CH395 detects that its

    IP address is the same as that of other network devices in the same network segment.

    \u2462 GINT_STAT_PHY_CHANGE: PHY change interrupt. This interrupt is generated when PHY connection

    of CH395 changes, for example, PHY state changes from the connected state to the disconnected state or

    from the disconnected state to the connected state. MCU can send GET_PHY_STATUS command to get

    the current PHY connection status.

    \u2463 GINT_STAT_DHCP: DHCP interrupt. If MCU enables DHCP function of CH395, CH395 will generate

    this interrupt. MCU can send the command CMD_GET_DHCP_STATUS to get the DHCP status. If the

    status is 0, it will indicate success; otherwise, it will indicate timeout failure.

    \u2464 GINT_STAT_SOCK0 - GINT_STAT_SOCK3: Socket interrupt. When there is an interrupt event in

    Socket, CH395 will generate this interrupt. MCU needs to send GET_INT_STATUS_SN to get the

    interrupt status of Socket. Please refer to GET_INT_STATUS_SN.

    When this command is completed, CH395 will set INT# pin to high level and clear the global interrupt

    status

    Modify

    • Accumulator

    Returns

    • Accumulator : Status

    Example

     jsr ch395_get_glob_int_status\n; check accumulator to get interrupts states\n
    "},{"location":"assembly/#ch395_get_ic_ver","title":"ch395_get_ic_ver","text":"

    Description

    This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text

    Modify

    • Accumulator

    Returns

    • Accumulator : Version

    Example

     jsr ch395_get_ic_ver\n; Check A for version\nrts\n
    "},{"location":"assembly/#ch395_get_int_status_sn","title":"ch395_get_int_status_sn","text":"

    Description

    This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index value. After receiving this command, CH395 will output 1 byte of Socket interrupt code. The interrupt code bits are defined as follows:

    Input

    • Accumulator : Socket id

    Modify

    • Accumulator
    • X Register

    Returns

    • Accumulator : Status of selected socket

    Example

     lda #CH395_SOCKET1 ; Check socket 1\njsr ch395_get_int_status_sn\n; Check interrupt type\nand #CH395_SINT_STAT_SEND_OK\ncmp #CH395_SINT_STAT_SEND_OK\nbeq @send_ok\nrts\n
    "},{"location":"assembly/#ch395_get_ip_inf","title":"ch395_get_ip_inf","text":"

    Description

    Get ip info

    Input

    • Accumulator : the ptr to modify (Ptr must be 20 bytes length)
    • X Register : the ptr to modify (Ptr must be 20 bytes length)

    Modify

    • Accumulator
    • X Register
    • Y Register
    • RESTmp value
    "},{"location":"assembly/#ch395_get_mac_adress","title":"ch395_get_mac_adress","text":"

    Description

    Get mac address

    Input

    • Accumulator : the ptr
    • X Register : the ptr

    Modify

    • Accumulator
    • X Register
    • Y Register
    • RESTmp value

    Returns

    • Accumulator : the content of ptr modified

    • X Register : the content of ptr modified

    "},{"location":"assembly/#ch395_get_phy_status","title":"ch395_get_phy_status","text":"

    Description

    This command is used to get PHY connection status. After receiving this command, CH395 will query the current PHY connection status and output 1-byte PHY connection status code: PHY is disconnected when the connection status code is 01H; PHY connection is 10M full duplex when the connection status code is 02H; PHY connection is 10M half duplex when the connection status code is 04H. PHY connection is 100M full duplex when the connection status code is 08H; PHY connection is 100M half duplex when the connection status code is 10H

    Modify

    • Accumulator

    Returns

    • Accumulator : The physical status

    Example

     jsr ch395_get_phy_status\n; Check A physical status\nrts\n
    "},{"location":"assembly/#ch395_get_recv_len_sn","title":"ch395_get_recv_len_sn","text":"

    Description

    Get the length received from socket

    Input

    • Accumulator : Socket id

    Example

     lda #$01 ; Socket 1\njsr ch395_get_recv_len_sn\n; check A and X for length received\nch395_connected:\n

    Modify

    • Accumulator
    • X Register

    Returns

    • Accumulator : The length

    • X Register : The length

    "},{"location":"assembly/#ch395_get_remot_ipp_sn","title":"ch395_get_remot_ipp_sn","text":"

    Description

    This command is used to get the remote IP address and port number. It is necessary to input 1 byte of Socket index value. CH395 will output 4 bytes of IP address and 2 bytes of port number (low bytes in front). After Socket works in TCP Server mode and the connection is established, MCU can get the remote IP address and port number through this command

    Input

    • Accumulator : The Socket for the ip to get
    • X Register : The ptr (high) to store the ip
    • Y Register : The ptr (low) to store the ip

    Modify

    • Accumulator
    • X Register
    • Y Register
    • RES

    Example

     lda #$01 ; Socket 1\nldx #<ip_dest\nldy #>ip_dest\njsr ch395_get_remot_ipp_sn\nrts\nipdest:\n.byte 192,168,0,1\n
    "},{"location":"assembly/#ch395_get_socket_status_sn","title":"ch395_get_socket_status_sn","text":"

    Description

    This command is used to get Socket status. It is necessary to input a 1 byte of Socket index value. CH395 will output a 2-byte status code when receiving this command. The first status code is the status code of Socket. The status code of Socket is defined as follows:

    Input

    • Accumulator : Socket id

    Modify

    • X Register
    • Accumulator

    Returns

    • Accumulator : The status

    • X Register : The state

    Example

     lda #$01 ; Socket 1\njsr ch395_get_socket_status_sn\n; check A and X for the state\ncmp #CH395_SOCKET_CLOSED\nbeq @soclet is closed\n
    "},{"location":"assembly/#ch395_get_unreach_ipport","title":"ch395_get_unreach_ipport","text":"

    Description

    This command is used to get an inaccessible IP, ports and protocol type. CH395 will generate an inaccessible interrupt when an inaccessible message is received. MCU can use this command to get inaccessible information. After receiving this command, CH395 will output 1 byte of inaccessible code, 1 byte of protocol type, 2 bytes of port number (low bytes in front), and 4 bytes of IP in turn. MCU can judge whether the protocol, port or IP is inaccessible according to the inaccessible codes. For inaccessible codes, refer to RFC792 (CH395INC.H defines four common inaccessible codes).

    Does not work

    "},{"location":"assembly/#ch395_init","title":"ch395_init","text":"

    Description

    This command is used to initialize CH395, including initializing MAC, PHY and TCP/IP stack of CH395. Generally, it takes 350mS to execute the command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status.

    Modify

    • Accumulator Description

    Reset ch395

    Example

     jsr ch395_init\n; Wait a bit\n
    "},{"location":"assembly/#ch395_open_socket_sn","title":"ch395_open_socket_sn","text":"

    Description

    This command is used to open Socket and use the necessary steps of Socket. It is necessary to input 1 byte of Socket index value. After sending this command, MCU shall send GET_CMD_STATUS to query the command execution status. After opening Socket in UDP, IPRAW or MACRAW mode and returning successfully, data transmission can be performed. Before this command is sent, necessary settings must be made for destination IP, protocol type, source port, destination port, etc. Please refer to 8.3 Application Reference Steps for detailed steps.

    Input

    • Accumulator : Socket id

    Modify

    • Y Register
    "},{"location":"assembly/#ch395_read_recv_buf_sn","title":"ch395_read_recv_buf_sn","text":"

    Description

    This command is used to read data from Socket receive buffer. It is necessary to input 1 byte of Socket index value and 2 bytes of length (low bytes in front). CH395 will output several bytes of data stream based on the length value. In actual application, the command RECV_LEN_SN can be firstly sent to get the actual effective length of the current buffer. The length of the read data can be less than the actual effective length of the buffer, the unread data is still reserved in the receive buffer, and MCU can continue to read through this command. In MACRAW mode, the processing modes are different. In MACRAW mode, the receive buffer is a frame buffer, which can cache only 1 frame of Ethernet data. After CH395 processes the command READ_RECV_BUF_SN, Socket0 receive buffer will be cleared, so MCU shall read all valid data of the buffer at a time.

    Input

    • Accumulator : Socket id
    • Y Register : Length low
    • X Register : length high
    • RES : tr to fill

    Modify

    • RESBtmp value
    "},{"location":"assembly/#ch395_reset_all","title":"ch395_reset_all","text":"

    Description

    This command enables CH395 to perform a hardware reset. Typically, hardware reset is completed within 50mS.

    Example

     jsr ch395_reset_all\n; Wait a bit\n
    "},{"location":"assembly/#ch395_set_baudrate","title":"ch395_set_baudrate","text":"

    Description

    This command is used to set the baud rate of CH395 for serial communication. When CH395 works in serial communication mode, the default communication baud rate is set by the level combination of SDO, SDI and SCK pins (refer to Section 6.4 of this datasheet) after reset. When these pins are suspended, the baud rate is 9600bps by default. If MCU supports high communication speed, the serial communication baud rate can be dynamically regulated through this command. This command requires the input of three data, namely, baudrate coefficient 0, baud rate coefficient 1 and baud rate coefficient 2. The following table shows the corresponding relationship with baud rates.

    "},{"location":"assembly/#ch395_set_des_port_sn","title":"ch395_set_des_port_sn","text":"

    Description

    This command is used to set the Socket destination port. It is necessary to input 1 byte of Socket index value and 2 bytes of destination port (the low bytes are in front). When Socket works in UDP or TCP Client mode, this value must be set.

    Input

    • Accumulator : Socketid
    • Y Register : Low int
    • X Register : high int

    Modify

    • REStmp

    Example

     lda #$01\nldx #80\nldx #$00\njsr ch395_set_des_port_sn\nrts\n
    "},{"location":"assembly/#ch395_set_fun_para","title":"ch395_set_fun_para","text":"

    Description

    Set fun para

    Input

    • Accumulator : Value

    Modify

    • Y Register
    • Accumulator
    "},{"location":"assembly/#ch395_set_gwip_addr","title":"ch395_set_gwip_addr","text":"

    Description

    This command is used to set the gateway address for CH395. It is necessary to input 4 bytes of IP address

    Does not work

    "},{"location":"assembly/#ch395_set_ip_addr","title":"ch395_set_ip_addr","text":"

    Description

    This command is used to set IP address for CH395. It is necessary to input 4 bytes of IP address, with low bytes of IP in front. For all commands including IP input or output in this datasheet, IP low bytes are in front. This will not be explained below

    Does not work

    "},{"location":"assembly/#ch395_set_ip_addr_sn","title":"ch395_set_ip_addr_sn","text":"

    Description

    This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent

    Input

    • Accumulator : Socket id
    • Y Register : low ptr ip
    • X Register : high ptr ip

    Modify

    • REStmp
    "},{"location":"assembly/#ch395_set_ipraw_pro_sn","title":"ch395_set_ipraw_pro_sn","text":"

    Description

    Set ipraw protocol on socket

    Input

    • Accumulator : Socket id
    • X Register : the mode proto

    Modify

    • Y Register
    "},{"location":"assembly/#ch395_set_mac_adress","title":"ch395_set_mac_adress","text":"

    Description

    This command is used to set MAC address for CH395. It is necessary to input 6 bytes of MAC, with low bytes of MAC address in front. CH395 chip will store MAC address in the internal EEPROM. It will take 100mS to execute this command.MAC address assigned by IEEE has been burned when CH395 chip is delivered. If it is not necessary, please do not set MAC address

    Input

    • Accumulator : Low ptr mac adress
    • X Register : High ptr mac adress

    Modify

    • Accumulator
    • Y Register
    • RESTmp
    "},{"location":"assembly/#ch395_set_mac_filt","title":"ch395_set_mac_filt","text":"

    Does not work

    "},{"location":"assembly/#ch395_set_mask_addr","title":"ch395_set_mask_addr","text":"

    Description

    This command is used to set the subnet mask for CH395. It is necessary to input 4 bytes of mask for this command. It is 255.255.255.0 by default and may not be set

    Does not work

    "},{"location":"assembly/#ch395_set_phy","title":"ch395_set_phy","text":"

    Description

    This command is used to set Ethernet PHY connection mode of CH395. The connection mode is automated negotiation mode by default. This command needs to input 1 byte of data, which is the connection mode code: Disconnect PHY when the connection mode code is 01H; PHY is 10M full duplex when the connection mode code is 02H; PHY is 10M half duplex when the connection mode code is 04H; PHY is 100M full duplex when the connection mode code is 08H; PHY is 100M half duplex when the connection mode code is 10H; PHY is automated negotiation when the connection mode code is 20H. When CH395 receives this command, it will reset MAC and PHY and reconnect according to the newly set connection mode. If Ethernet is already connected, it will be disconnected and reconnected.

    Does not work

    "},{"location":"assembly/#ch395_set_proto_type_sn","title":"ch395_set_proto_type_sn","text":"

    Description

    This command is used to set the working mode of Socket. It is necessary to input 1 byte of Socket index value and 1 byte of working mode. The working mode is defined as follows:

    Code Name Description

    03H PROTO_TYPE_TCP TCP mode

    02H PROTO_TYPE_UDP UDP mode

    01H PROTO_TYPE_MAC_RAW MAC original message mode

    00H PROTO_TYPE_IP_RAW IP original message mode

    This command must be executed before CMD_OPEN_SOCKET_SN. Refer to 8.3 Application Reference

    Steps for detailed steps.

    Input

    • Accumulator : Socket id
    "},{"location":"assembly/#ch395_set_retran_count","title":"ch395_set_retran_count","text":"

    Description

    This command is used to set the number of retries. It is necessary to input 1 byte of number of retries. The allowable maximum value is 20. If the input data is more than 20, it will be processed as 20. The default number of retries is 12, and retries are only valid in TCP mode.

    Input

    • Accumulator : Retran period

    Modify

    • X Register
    "},{"location":"assembly/#ch395_set_retran_period","title":"ch395_set_retran_period","text":"

    Description

    This command is used to set the retry cycle. It is necessary to input 2 bytes of number of cycles of (with low bytes in front) in milliseconds. The allowable maximum value is 1000. The total retry time is N * M, N is the number of retries, and M is the retry cycle. The default retry cycle is 500MS and retries are only valid in TCP mode.

    Input

    • Accumulator : Period
    • X Register : Period

    Modify

    • Y Register

    Example

     lda #$FF\nldx #$FF\njsr ch395_retran_period\nrts\n
    "},{"location":"assembly/#ch395_set_sour_port_sn","title":"ch395_set_sour_port_sn","text":"

    Description

    This command is used to set the source port of Socket. It is necessary to input 1 byte of Socket index value and 2 bytes of source port (low bytes in front). If two or more Sockets are in the same mode, the source port numbers must not be the same. For example, Socket 0 is in UDP mode, the source port number is 600, and Socket 1 is also in UDP mode. The source port number 600 cannot be used again, otherwise it may cause the0 opening failure.

    Input

    • Accumulator : Socket id
    • Y Register : Low ptr address
    • X Register : High ptr address

    Modify

    • RES
    "},{"location":"assembly/#ch395_set_ttl","title":"ch395_set_ttl","text":"

    Description

    This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128

    Input

    • Accumulator : Socket ID
    • X Register : TTL value

    Modify

    • Y Register
    "},{"location":"assembly/#ch395_tcp_connect_sn","title":"ch395_tcp_connect_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"assembly/#ch395_tcp_disconnect_sn","title":"ch395_tcp_disconnect_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"assembly/#ch395_tcp_listen_sn","title":"ch395_tcp_listen_sn","text":"

    Description

    This command is only valid in TCP mode, enabling the Socket to be in the monitoring mode, namely, TCP Server mode. It is necessary to input a 1 byte of Socket index value. This command must be executed after OPEN_SOCKET_SN. After sending this command, MCU shall send GET_CMD_STATUS to query the 0command execution status. In TCP Server mode, the Socket will always detect connection events, and the interrupt SINT_STAT_CONNECT will be generated until the connection is successful. Only one connection can be 0established for each Socket. If an eligible connection event is received again, Socket will send TCP RESET to the remote end tried to be connected.

    "},{"location":"assembly/#ch395_write_send_buf_sn","title":"ch395_write_send_buf_sn","text":"

    Description

    This command is used to write data to Socket transmit buffer. It is necessary to input 1 byte of Socket index value, 2 bytes of length (low bytes in front) and several bytes of data stream. The length of input data must not be larger than the size of transmit buffer. However, in MACRAW mode, the maximum length of input data can only be 1514, and any redundant data will be discarded. After the external MCU writes the data, CH395 will encapsulate the data packet according to the working mode of Socket, and then send it. Before MCU receives SINT_STAT_SENBUF_FREE, it is not allowed to write data into Socket transmit buffer again

    Input

    • Accumulator : Socket ID
    • Y Register : Low length
    • X Register : High length
    • RESB : Adress ptr to read

    Modify

    • RESTmp

    Example

    "},{"location":"c/","title":"C","text":""},{"location":"c/#c","title":"C","text":""},{"location":"c/#unsigned-char-ch395_check_exist","title":"unsigned char ch395_check_exist();","text":"

    Description

    This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.

    "},{"location":"c/#void-ch395_clear_recv_buf_snunsigned-char-id_socket","title":"void ch395_clear_recv_buf_sn(unsigned char ID_SOCKET)","text":"

    Description

    This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.

    "},{"location":"c/#void-ch395_close_socket_snunsigned-char-socketid","title":"void ch395_close_socket_sn(unsigned char socketid)","text":"

    Description

    This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.

    Input

    "},{"location":"c/#void-ch395_dhcp_enable","title":"void ch395_dhcp_enable()","text":"

    Description

    This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status

    Description

    Get cmd status

    "},{"location":"c/#unsigned-char-ch395_get_cmd_status","title":"unsigned char ch395_get_cmd_status();","text":""},{"location":"c/#unsigned-char-ch395_get_dhcp_status","title":"unsigned char ch395_get_dhcp_status();","text":"

    Description

    Get dhcp status

    "},{"location":"c/#unsigned-int-ch395_get_glob_int_status","title":"unsigned int ch395_get_glob_int_status();","text":"

    Description

    Get General interrupt Status

    "},{"location":"c/#unsigned-char-ch395_get_ic_ver","title":"unsigned char ch395_get_ic_ver();","text":"

    Description

    This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text

    ;;@inputA Socket id ;;@modifyA ;;@modifyX ;;@returnsA Status of selected socket ;;@ca65 ;;@` lda #CH395_SOCKET1 ; Check socket 1 ;;@` jsr ch395_get_int_status_sn ;;@` ; Check interrupt type ;;@` and #CH395_SINT_STAT_SEND_OK ;;@` cmp #CH395_SINT_STAT_SEND_OK ;;@` beq @send_ok ;;@` rts ;;@ ldx #CH395_GET_INT_STATUS_SN stx CH395_COMMAND_PORT sta CH395_DATA_PORT lda CH395_DATA_PORT rts endproc

    "},{"location":"c/#unsigned-char-ch395_get_int_status_snunsigned-char-id_socket","title":"unsigned char ch395_get_int_status_sn(unsigned char ID_SOCKET);","text":"

    Description

    Check interrupt socket status

    Input

    "},{"location":"c/#void-ch395_get_ip_infunsigned-char-ip_infos","title":"void ch395_get_ip_inf(unsigned char ip_infos[]);","text":"

    Description

    Get ip info : ip_infos must be 20 bytes length)

    "},{"location":"c/#void-ch395_get_mac_adressunsigned-char-macaddress","title":"void ch395_get_mac_adress(unsigned char macaddress[]);","text":"

    Description

    Get mac address

    "},{"location":"c/#unsigned-char-ch395_get_phy_status","title":"unsigned char ch395_get_phy_status();","text":"

    Description

    Get physical status

    "},{"location":"c/#void-ch395_get_recv_len_snunsigned-char-id_socket","title":"void ch395_get_recv_len_sn(unsigned char ID_SOCKET)","text":"

    Description

    Get the length received from socket

    Input

    "},{"location":"c/#void-ch395_get_remot_ipp_snunsigned-char-ptr-unsigned-char-socket","title":"void ch395_get_remot_ipp_sn(unsigned char *ptr, unsigned char socket);","text":"

    Description

    Get remote ip connected to the socket

    Input

    "},{"location":"c/#unsigned-int-ch395_get_socket_status_snunsigned-char-id_socket","title":"unsigned int ch395_get_socket_status_sn(unsigned char ID_SOCKET);","text":"

    Description

    Returns in A socket status (close/open ... )

    Input

    "},{"location":"c/#void-ch395_init","title":"void ch395_init();","text":"

    Description

    ;;@brief This command is used to initialize CH395, including initializing MAC, PHY and TCP/IP stack of CH395. Generally, it takes 350mS to execute the command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status.

    "},{"location":"c/#void-ch395_open_socket_snunsigned-char-id_socket","title":"void ch395_open_socket_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"c/#void-ch395_read_recv_buf_snunsigned-char-buffer-unsigned-int-ptr2unsigned-char-id_socket","title":"void ch395_read_recv_buf_sn(unsigned char *buffer, unsigned int ptr2,unsigned char ID_SOCKET);","text":"

    Input

    "},{"location":"c/#void-ch395_reset_all","title":"void ch395_reset_all()","text":"

    Description

    Reset ch395

    "},{"location":"c/#void-ch395_set_des_port_snunsigned-int-port-unsigned-char-id_socket","title":"void ch395_set_des_port_sn(unsigned int port, unsigned char ID_SOCKET);","text":"

    Description

    Set dest port socket

    Input

    "},{"location":"c/#void-ch395_set_fun_paraunsigned-char-flag","title":"void ch395_set_fun_para(unsigned char flag)","text":"

    Description

    Set fun para

    Description

    Set gateway ip addr

    Description

    This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent

    "},{"location":"c/#void-ch395_set_ip_addr_snunsigned-char-ip_addr-unsigned-char-id_socket","title":"void ch395_set_ip_addr_sn(unsigned char ip_addr[], unsigned char ID_SOCKET)","text":""},{"location":"c/#void-ch395_set_ipraw_pro_snunsigned-char-id_socket","title":"void ch395_set_ipraw_pro_sn(unsigned char ID_SOCKET);","text":"

    Description

    Set ipraw protocol on socket

    Input

    "},{"location":"c/#void-ch395_set_mac_adressunsigned-char-macaddress","title":"void ch395_set_mac_adress(unsigned char macaddress[]);","text":""},{"location":"c/#void-ch395_set_proto_type_snunsigned-char-proto-unsigned-char-id_socket","title":"void ch395_set_proto_type_sn(unsigned char proto, unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"c/#void-ch395_set_retran_countunsigned-int-period","title":"void ch395_set_retran_count(unsigned int period);","text":"

    Description

    Set retran period

    "},{"location":"c/#void-ch395_retran_periodunsigned-int-period","title":"void ch395_retran_period(unsigned int period);","text":"

    Description

    Retran period

    "},{"location":"c/#void-ch395_set_sour_port_snunsigned-int-portunsigned-char-id_socket","title":"void ch395_set_sour_port_sn(unsigned int port,unsigned char ID_SOCKET)","text":"

    Description

    Set source socket

    Input

    Description

    This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128

    "},{"location":"c/#ch395_set_ttlunsigned-char-id_socket-unsigned-char-ttl_value","title":"ch395_set_ttl(unsigned char ID_SOCKET, unsigned char ttl_value);","text":""},{"location":"c/#void-ch395_tcp_connect_snunsigned-char-id_socket","title":"void ch395_tcp_connect_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"c/#void-ch395_tcp_disconnect_snunsigned-char-id_socket","title":"void ch395_tcp_disconnect_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"c/#void-ch395_tcp_listen_snunsigned-char-id_socket","title":"void ch395_tcp_listen_sn(unsigned char ID_SOCKET)","text":""},{"location":"c/#void-ch395_write_send_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_write_send_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"

    Description

    Send data to socketid [Not working]

    Input

    "},{"location":"2024.1/assembly/","title":"Assembly","text":""},{"location":"2024.1/assembly/#assembly","title":"Assembly","text":""},{"location":"2024.1/assembly/#ch395_check_exist","title":"ch395_check_exist","text":"

    Description

    Checks if ch395 exists

    Example

     jsr ch395_get_glob_int_status\ncmp #CH395_DETECTED\nbeq ch395_connected\nrts\nch395_connected:\n

    Modify

    • Accumulator

    Returns

    • Accumulator : Returns #CH395_DETECTED if it exists
    "},{"location":"2024.1/assembly/#ch395_clear_recv_buf_sn","title":"ch395_clear_recv_buf_sn","text":"

    Description

    Clear receive buffer

    Input

    • Accumulator : Socket id

    Modify

    • Accumulator
    • Y Register

    Example

     lda #CH395_SOCKET1 ; Socket ID\njsr ch395_clear_recv_buf_sn\n
    "},{"location":"2024.1/assembly/#ch395_close_socket_sn","title":"ch395_close_socket_sn","text":"

    Description

    Close socket

    Input

    • Accumulator : The id of the socket to close

    Modify

    • Y Register

    Example

     lda #$01 ; Socket ID\njsr ch395_close_socket_sn\n
    "},{"location":"2024.1/assembly/#ch395_dhcp_enable","title":"ch395_dhcp_enable","text":"

    Description

    Enable or not dhcp

    Input

    • Accumulator : The mode to activate DHCP mode

    Modify

    • X Register
    "},{"location":"2024.1/assembly/#ch395_get_cmd_status","title":"ch395_get_cmd_status","text":"

    Description

    Get cmd status

    Example

     jsr ch395_get_cmd_status\n; Check A for STATUS\nrts\n

    Modify

    • Accumulator
    "},{"location":"2024.1/assembly/#ch395_get_dhcp_status","title":"ch395_get_dhcp_status","text":"

    Description

    Get dhcp status

    Example

     jsr ch395_get_dhcp_status\n; Check A for dhcp status\nrts\n

    Modify

    • Accumulator
    "},{"location":"2024.1/assembly/#ch395_get_glob_int_status","title":"ch395_get_glob_int_status","text":"

    Description

    Get General interrupt Status

    Modify

    • Accumulator

    Example

     jsr ch395_get_glob_int_status\n; check accumulator to get interrupts states\n
    "},{"location":"2024.1/assembly/#ch395_get_ic_ver","title":"ch395_get_ic_ver","text":"

    Description

    Get ch395 firmware version

    Example

     jsr ch395_get_ic_ver\n; Check A for version\nrts\n

    Modify

    • Accumulator
    "},{"location":"2024.1/assembly/#ch395_get_int_status_sn","title":"ch395_get_int_status_sn","text":"

    Description

    Check interrupt socket status

    Input

    • Accumulator : Socket id

    Modify

    • Accumulator
    • X Register

    Returns

    • Accumulator : Status of selected socket

    Example

     lda #CH395_SOCKET1 ; Check socket 1\njsr ch395_get_int_status_sn\n; Check interrupt type\nrts\n
    "},{"location":"2024.1/assembly/#ch395_get_ip_inf","title":"ch395_get_ip_inf","text":"

    Description

    Get ip info

    Input

    • Accumulator : the ptr to modify
    • X Register : the ptr to modify

    Modify

    • Accumulator
    • X Register
    • Y Register
    "},{"location":"2024.1/assembly/#ch395_get_mac_adress","title":"ch395_get_mac_adress","text":"

    Description

    Get mac address

    Input

    • Accumulator : the ptr
    • X Register : the ptr

    Modify

    • Accumulator
    • X Register
    • Y Register

    Returns

    • Accumulator : the content of ptr modified

    • X Register : the content of ptr modified

    "},{"location":"2024.1/assembly/#ch395_get_phy_status","title":"ch395_get_phy_status","text":"

    Description

    Get physical status

    Modify

    • Accumulator

    Returns

    • Accumulator : The physical status

    Example

     jsr ch395_get_phy_status\n; Check A physical status\nrts\n
    "},{"location":"2024.1/assembly/#ch395_get_recv_len_sn","title":"ch395_get_recv_len_sn","text":"

    Description

    Get the length received from socket

    Input

    • Accumulator : Socket id

    Example

     lda #$01 ; Socket 1\njsr ch395_get_recv_len_sn\n; check A and X for length received\nch395_connected:\n

    Modify

    • Accumulator
    • X Register

    Returns

    • Accumulator : The length

    • X Register : The length

    "},{"location":"2024.1/assembly/#ch395_get_remot_ipp_sn","title":"ch395_get_remot_ipp_sn","text":"

    Description

    Get remote ip connected to the socket

    Input

    • Accumulator : The Socket for the ip to get
    • X Register : The ptr (high) to store the ip
    • Y Register : The ptr (low) to store the ip

    Modify

    • Accumulator
    • X Register
    • Y Register
    "},{"location":"2024.1/assembly/#ch395_get_socket_status_sn","title":"ch395_get_socket_status_sn","text":"

    Description

    Returns in A socket status (close/open ...)

    Input

    • Accumulator : Socket id

    Modify

    • X Register
    • Accumulator

    Returns

    • Accumulator : The status

    • X Register : The state

    Example

     lda #$01 ; Socket 1\njsr ch395_get_socket_status_sn\n; check A and X for the state\n
    "},{"location":"2024.1/assembly/#ch395_init","title":"ch395_init","text":"

    Description

    Initialize ch395

    Modify

    • Accumulator Description

    Reset ch395

    Example

     jsr ch395_init\n; Wait a bit\n
    "},{"location":"2024.1/assembly/#ch395_open_socket_sn","title":"ch395_open_socket_sn","text":"

    Description

    Open socket from arg

    Input

    • Accumulator : Socket id

    Modify

    • Y Register
    "},{"location":"2024.1/assembly/#ch395_read_recv_buf_sn","title":"ch395_read_recv_buf_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_reset_all","title":"ch395_reset_all","text":"

    Description

    Reset ch395

    Example

     jsr ch395_reset_all\n; Wait a bit\n
    "},{"location":"2024.1/assembly/#ch395_retran_period","title":"ch395_retran_period","text":"

    Description

    Retran period

    Input

    • Accumulator : Period
    • X Register : Period

    Modify

    • Y Register

    Example

     lda #$FF\nldx #$FF\njsr ch395_retran_period\nrts\n
    "},{"location":"2024.1/assembly/#ch395_set_des_port_sn","title":"ch395_set_des_port_sn","text":"

    Description

    Set dest port socket

    Input

    • Accumulator : Socketid
    • Y Register : Low int
    • X Register : high int

    Example

     lda #$01\nldx #80\nldx #$00\njsr ch395_set_des_port_sn\nrts\n
    "},{"location":"2024.1/assembly/#ch395_set_fun_para","title":"ch395_set_fun_para","text":"

    Description

    Set fun para

    Input

    • Accumulator : Value

    Modify

    • Y Register
    • Accumulator
    "},{"location":"2024.1/assembly/#ch395_set_gwip_addr","title":"ch395_set_gwip_addr","text":"

    Description

    Set gateway ip addr

    "},{"location":"2024.1/assembly/#ch395_set_ip_addr","title":"ch395_set_ip_addr","text":"

    Description

    Set ip row

    "},{"location":"2024.1/assembly/#ch395_set_ip_addr_sn","title":"ch395_set_ip_addr_sn","text":"

    Description

    Set Socket Ip address to connect with

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_set_ipraw_pro_sn","title":"ch395_set_ipraw_pro_sn","text":"

    Description

    Set ipraw protocol on socket

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_set_mac_adress","title":"ch395_set_mac_adress","text":"

    Description

    Set mac address

    "},{"location":"2024.1/assembly/#ch395_set_proto_type_sn","title":"ch395_set_proto_type_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_set_retran_count","title":"ch395_set_retran_count","text":"

    Description

    Set retran period

    Input

    • Accumulator : Retran period
    "},{"location":"2024.1/assembly/#ch395_set_sour_port_sn","title":"ch395_set_sour_port_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_tcp_connect_sn","title":"ch395_tcp_connect_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_tcp_disconnect_sn","title":"ch395_tcp_disconnect_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_tcp_listen_sn","title":"ch395_tcp_listen_sn","text":"

    Description

    TCP listen socket

    "},{"location":"2024.1/assembly/#ch395_write_send_buf_sn","title":"ch395_write_send_buf_sn","text":"

    Description

    Send data to socketid

    Input

    • Accumulator : Socket ID
    • Y Register : Low length
    • X Register : High length
    "},{"location":"2024.1/c/","title":"C","text":""},{"location":"2024.1/c/#c","title":"C","text":""},{"location":"2024.1/c/#unsigned-char-ch395_check_exist","title":"unsigned char ch395_check_exist();","text":"

    Description

    Checks if ch395 exists

    "},{"location":"2024.1/c/#void-ch395_clear_recv_buf_snunsigned-char-id_socket","title":"void ch395_clear_recv_buf_sn(unsigned char ID_SOCKET)","text":"

    Description

    Clear receive buffer

    "},{"location":"2024.1/c/#oid-ch395_close_socket_snunsigned-char-socketid","title":"oid ch395_close_socket_sn(unsigned char socketid)","text":"

    Description

    Close socket

    Input

    "},{"location":"2024.1/c/#unsigned-char-ch395_get_dhcp_status","title":"unsigned char ch395_get_dhcp_status();","text":"

    Description

    Get dhcp status

    "},{"location":"2024.1/c/#unsigned-int-ch395_get_glob_int_status","title":"unsigned int ch395_get_glob_int_status();","text":"

    Description

    Get General interrupt Status

    "},{"location":"2024.1/c/#unsigned-char-ch395_get_ic_ver","title":"unsigned char ch395_get_ic_ver();","text":"

    Description

    Get ch395 firmware version

    "},{"location":"2024.1/c/#unsigned-char-ch395_get_int_status_snunsigned-char-id_socket","title":"unsigned char ch395_get_int_status_sn(unsigned char ID_SOCKET);","text":"

    Description

    Check interrupt socket status

    Input

    "},{"location":"2024.1/c/#void-ch395_get_ip_infunsigned-char-ip_infos","title":"void ch395_get_ip_inf(unsigned char ip_infos[]);","text":"

    Description

    Get ip info

    "},{"location":"2024.1/c/#void-ch395_get_mac_adressunsigned-char-macaddress","title":"void ch395_get_mac_adress(unsigned char macaddress[]);","text":"

    Description

    Get mac address

    "},{"location":"2024.1/c/#unsigned-char-ch395_get_phy_status","title":"unsigned char ch395_get_phy_status();","text":"

    Description

    Get physical status

    "},{"location":"2024.1/c/#void-ch395_get_recv_len_snunsigned-char-id_socket","title":"void ch395_get_recv_len_sn(unsigned char ID_SOCKET)","text":"

    Description

    Get the length received from socket

    Input

    "},{"location":"2024.1/c/#void-ch395_get_remot_ipp_snunsigned-char-ptr-unsigned-char-socket","title":"void ch395_get_remot_ipp_sn(unsigned char *ptr, unsigned char socket);","text":"

    Description

    Get remote ip connected to the socket

    Input

    "},{"location":"2024.1/c/#unsigned-int-ch395_get_socket_status_snunsigned-char-id_socket","title":"unsigned int ch395_get_socket_status_sn(unsigned char ID_SOCKET);","text":"

    Description

    Returns in A socket status (close/open ... )

    Input

    "},{"location":"2024.1/c/#void-ch395_init","title":"void ch395_init();","text":"

    Description

    Initialize ch395

    "},{"location":"2024.1/c/#void-ch395_open_socket_snunsigned-char-id_socket","title":"void ch395_open_socket_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.1/c/#void-ch395_read_recv_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_read_recv_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"

    Input

    "},{"location":"2024.1/c/#void-ch395_reset_all","title":"void ch395_reset_all()","text":"

    Description

    Reset ch395

    "},{"location":"2024.1/c/#void-ch395_retran_periodunsigned-int-period","title":"void ch395_retran_period(unsigned int period);","text":"

    Description

    Retran period

    "},{"location":"2024.1/c/#void-ch395_set_des_port_snunsigned-int-port-unsigned-char-id_socket","title":"void ch395_set_des_port_sn(unsigned int port, unsigned char ID_SOCKET);","text":"

    Description

    Set dest port socket

    Input

    "},{"location":"2024.1/c/#void-ch395_set_fun_paraunsigned-char-flag","title":"void ch395_set_fun_para(unsigned char flag)","text":"

    Description

    Set fun para

    Description

    Set gateway ip addr

    Description

    Set ip addr

    "},{"location":"2024.1/c/#void-ch395_set_ip_addr_snunsigned-char-ip_addr-unsigned-char-id_socket","title":"void ch395_set_ip_addr_sn(unsigned char ip_addr[], unsigned char ID_SOCKET)","text":""},{"location":"2024.1/c/#void-ch395_set_ipraw_pro_snunsigned-char-id_socket","title":"void ch395_set_ipraw_pro_sn(unsigned char ID_SOCKET);","text":"

    Description

    Set ipraw protocol on socket

    Input

    "},{"location":"2024.1/c/#void-ch395_set_mac_adressunsigned-char-macaddress","title":"void ch395_set_mac_adress(unsigned char macaddress[]);","text":""},{"location":"2024.1/c/#void-ch395_set_proto_type_snunsigned-char-protounsigned-char-id_socket","title":"void ch395_set_proto_type_sn(unsigned char proto,unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.1/c/#void-ch395_set_retran_countunsigned-int-period","title":"void ch395_set_retran_count(unsigned int period);","text":"

    Description

    Set retran period

    "},{"location":"2024.1/c/#void-ch395_set_sour_port_snunsigned-int-portunsigned-char-id_socket","title":"void ch395_set_sour_port_sn(unsigned int port,unsigned char ID_SOCKET)","text":"

    Description

    Set source socket

    Input

    "},{"location":"2024.1/c/#void-ch395_tcp_connect_snunsigned-char-id_socket","title":"void ch395_tcp_connect_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.1/c/#void-ch395_tcp_disconnect_snunsigned-char-id_socket","title":"void ch395_tcp_disconnect_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.1/c/#void-ch395_tcp_listen_snunsigned-char-id_socket","title":"void ch395_tcp_listen_sn(unsigned char ID_SOCKET)","text":""},{"location":"2024.1/c/#void-ch395_write_send_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_write_send_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"

    Description

    Send data to socketid

    Input

    "},{"location":"2024.2/assembly/","title":"Assembly","text":""},{"location":"2024.2/assembly/#assembly","title":"Assembly","text":""},{"location":"2024.2/assembly/#ch395_check_exist","title":"ch395_check_exist","text":"

    Description

    This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.

    Modify

    • Accumulator

    Returns

    • Accumulator : Returns '#CH395_DETECTED' if it exists

    Example

     jsr ch395_check_exist\ncmp #CH395_DETECTED\nbeq ch395_connected\nrts\nch395_connected:\n
    "},{"location":"2024.2/assembly/#ch395_clear_recv_buf_sn","title":"ch395_clear_recv_buf_sn","text":"

    Description

    This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.

    Input

    • Accumulator : Socket id

    Modify

    • Accumulator
    • Y Register

    Example

     lda #CH395_SOCKET1 ; Socket ID\njsr ch395_clear_recv_buf_sn\n
    "},{"location":"2024.2/assembly/#ch395_close_socket_sn","title":"ch395_close_socket_sn","text":"

    Description

    This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.

    Input

    • Accumulator : The id of the socket to close

    Modify

    • Y Register

    Example

     lda #$01 ; Socket ID\njsr ch395_close_socket_sn\n
    "},{"location":"2024.2/assembly/#ch395_dhcp_enable","title":"ch395_dhcp_enable","text":"

    Description

    This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status

    Input

    • Accumulator : The mode to activate DHCP mode

    Modify

    • X Register
    "},{"location":"2024.2/assembly/#ch395_enter_sleep","title":"ch395_enter_sleep","text":"

    Description

    This command enables CH395 chip in a low-power sleep suspended state. When MCU writes a new command to CH395 (no data input command, such as CMD_GET_IC_VER), it will exit the low-power state. For the parallel port and SPI interface communication modes, active SCS chip selection will also cause CH395 to exit the low-power state, so MCU shall immediately disable the SCS chip selection after sending the command CMD_ENTER_SLEEP. In sleep state, MAC and PHY of CH395 will be in power off mode and disconnect Ethernet. Typically, it takes several milliseconds for CH395 to exit the low-power state.

    Does not work

    "},{"location":"2024.2/assembly/#ch395_get_cmd_status","title":"ch395_get_cmd_status","text":"

    Description

    This command is used to get the command execution status. CH395 will output 1 byte of data, which is the command execution state. The command execution status is as follows:

    Example

     jsr ch395_get_cmd_status\n; Check A for STATUS\nrts\n

    Modify

    • Accumulator
    "},{"location":"2024.2/assembly/#ch395_get_dhcp_status","title":"ch395_get_dhcp_status","text":"

    Description

    Get dhcp status

    Example

     jsr ch395_get_dhcp_status\n; Check A for dhcp status\nrts\n

    Modify

    • Accumulator
    "},{"location":"2024.2/assembly/#ch395_get_glob_int_status_all","title":"ch395_get_glob_int_status_all","text":"

    Description

    This command is used to get the global interrupt status. CH395 will output 2 bytes of global interrupt status after receiving this command. Global interrupt status is defined as follows:

    Does not work

    "},{"location":"2024.2/assembly/#ch395_get_glob_int_status","title":"ch395_get_glob_int_status","text":"

    Description

    This command is used to get the global interrupt status. CH395 will output 1 byte of global interrupt status after receiving this command. Global interrupt status is defined as follows:

    Bit Name Description

    7 GINT_STAT_SOCK3 Socket3 interrupt

    6 GINT_STAT_SOCK2 Socket2 interrupt

    5 GINT_STAT_SOCK1 Socket1 interrupt

    4 GINT_STAT_SOCK0 Socket0 interrupt

    3 GINT_STAT_DHCP DHCP interrupt

    2 GINT_STAT_PHY_CHANGE PHY status change interrupt

    1 GINT_STAT_IP_CONFLI IP conflict

    0 GINT_STAT_UNREACH Inaccessible interrupt

    \u2460 GINT_STAT_UNREACH: Inaccessible interrupt. When CH395 receives ICMP inaccessible interrupt

    message, it saves the IP address, port and protocol type of the inaccessible IP packet in the inaccessible

    information table, and then generates an interrupt. When the MCU receives the interrupt, it can send the

    command GET_UNREACH_IPPORT to get the inaccessible information.

    \u2461 GINT_STAT_IP_CONFLI: IP conflict interrupt. This interrupt is generated when CH395 detects that its

    IP address is the same as that of other network devices in the same network segment.

    \u2462 GINT_STAT_PHY_CHANGE: PHY change interrupt. This interrupt is generated when PHY connection

    of CH395 changes, for example, PHY state changes from the connected state to the disconnected state or

    from the disconnected state to the connected state. MCU can send GET_PHY_STATUS command to get

    the current PHY connection status.

    \u2463 GINT_STAT_DHCP: DHCP interrupt. If MCU enables DHCP function of CH395, CH395 will generate

    this interrupt. MCU can send the command CMD_GET_DHCP_STATUS to get the DHCP status. If the

    status is 0, it will indicate success; otherwise, it will indicate timeout failure.

    \u2464 GINT_STAT_SOCK0 - GINT_STAT_SOCK3: Socket interrupt. When there is an interrupt event in

    Socket, CH395 will generate this interrupt. MCU needs to send GET_INT_STATUS_SN to get the

    interrupt status of Socket. Please refer to GET_INT_STATUS_SN.

    When this command is completed, CH395 will set INT# pin to high level and clear the global interrupt

    status

    Modify

    • Accumulator

    Returns

    • Accumulator : Status

    Example

     jsr ch395_get_glob_int_status\n; check accumulator to get interrupts states\n
    "},{"location":"2024.2/assembly/#ch395_get_ic_ver","title":"ch395_get_ic_ver","text":"

    Description

    This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text

    Modify

    • Accumulator

    Returns

    • Accumulator : Version

    Example

     jsr ch395_get_ic_ver\n; Check A for version\nrts\n
    "},{"location":"2024.2/assembly/#ch395_get_int_status_sn","title":"ch395_get_int_status_sn","text":"

    Description

    This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index value. After receiving this command, CH395 will output 1 byte of Socket interrupt code. The interrupt code bits are defined as follows:

    Input

    • Accumulator : Socket id

    Modify

    • Accumulator
    • X Register

    Returns

    • Accumulator : Status of selected socket

    Example

     lda #CH395_SOCKET1 ; Check socket 1\njsr ch395_get_int_status_sn\n; Check interrupt type\nand #CH395_SINT_STAT_SEND_OK\ncmp #CH395_SINT_STAT_SEND_OK\nbeq @send_ok\nrts\n
    "},{"location":"2024.2/assembly/#ch395_get_ip_inf","title":"ch395_get_ip_inf","text":"

    Description

    Get ip info

    Input

    • Accumulator : the ptr to modify (Ptr must be 20 bytes length)
    • X Register : the ptr to modify (Ptr must be 20 bytes length)

    Modify

    • Accumulator
    • X Register
    • Y Register
    • RESTmp value
    "},{"location":"2024.2/assembly/#ch395_get_mac_adress","title":"ch395_get_mac_adress","text":"

    Description

    Get mac address

    Input

    • Accumulator : the ptr
    • X Register : the ptr

    Modify

    • Accumulator
    • X Register
    • Y Register
    • RESTmp value

    Returns

    • Accumulator : the content of ptr modified

    • X Register : the content of ptr modified

    "},{"location":"2024.2/assembly/#ch395_get_phy_status","title":"ch395_get_phy_status","text":"

    Description

    This command is used to get PHY connection status. After receiving this command, CH395 will query the current PHY connection status and output 1-byte PHY connection status code: PHY is disconnected when the connection status code is 01H; PHY connection is 10M full duplex when the connection status code is 02H; PHY connection is 10M half duplex when the connection status code is 04H. PHY connection is 100M full duplex when the connection status code is 08H; PHY connection is 100M half duplex when the connection status code is 10H

    Modify

    • Accumulator

    Returns

    • Accumulator : The physical status

    Example

     jsr ch395_get_phy_status\n; Check A physical status\nrts\n
    "},{"location":"2024.2/assembly/#ch395_get_recv_len_sn","title":"ch395_get_recv_len_sn","text":"

    Description

    Get the length received from socket

    Input

    • Accumulator : Socket id

    Example

     lda #$01 ; Socket 1\njsr ch395_get_recv_len_sn\n; check A and X for length received\nch395_connected:\n

    Modify

    • Accumulator
    • X Register

    Returns

    • Accumulator : The length

    • X Register : The length

    "},{"location":"2024.2/assembly/#ch395_get_remot_ipp_sn","title":"ch395_get_remot_ipp_sn","text":"

    Description

    This command is used to get the remote IP address and port number. It is necessary to input 1 byte of Socket index value. CH395 will output 4 bytes of IP address and 2 bytes of port number (low bytes in front). After Socket works in TCP Server mode and the connection is established, MCU can get the remote IP address and port number through this command

    Input

    • Accumulator : The Socket for the ip to get
    • X Register : The ptr (high) to store the ip
    • Y Register : The ptr (low) to store the ip

    Modify

    • Accumulator
    • X Register
    • Y Register
    • RES

    Example

     lda #$01 ; Socket 1\nldx #<ip_dest\nldy #>ip_dest\njsr ch395_get_remot_ipp_sn\nrts\nipdest:\n.byte 192,168,0,1\n
    "},{"location":"2024.2/assembly/#ch395_get_socket_status_sn","title":"ch395_get_socket_status_sn","text":"

    Description

    This command is used to get Socket status. It is necessary to input a 1 byte of Socket index value. CH395 will output a 2-byte status code when receiving this command. The first status code is the status code of Socket. The status code of Socket is defined as follows:

    Input

    • Accumulator : Socket id

    Modify

    • X Register
    • Accumulator

    Returns

    • Accumulator : The status

    • X Register : The state

    Example

     lda #$01 ; Socket 1\njsr ch395_get_socket_status_sn\n; check A and X for the state\ncmp #CH395_SOCKET_CLOSED\nbeq @soclet is closed\n
    "},{"location":"2024.2/assembly/#ch395_get_unreach_ipport","title":"ch395_get_unreach_ipport","text":"

    Description

    This command is used to get an inaccessible IP, ports and protocol type. CH395 will generate an inaccessible interrupt when an inaccessible message is received. MCU can use this command to get inaccessible information. After receiving this command, CH395 will output 1 byte of inaccessible code, 1 byte of protocol type, 2 bytes of port number (low bytes in front), and 4 bytes of IP in turn. MCU can judge whether the protocol, port or IP is inaccessible according to the inaccessible codes. For inaccessible codes, refer to RFC792 (CH395INC.H defines four common inaccessible codes).

    Does not work

    "},{"location":"2024.2/assembly/#ch395_init","title":"ch395_init","text":"

    Description

    This command is used to initialize CH395, including initializing MAC, PHY and TCP/IP stack of CH395. Generally, it takes 350mS to execute the command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status.

    Modify

    • Accumulator Description

    Reset ch395

    Example

     jsr ch395_init\n; Wait a bit\n
    "},{"location":"2024.2/assembly/#ch395_open_socket_sn","title":"ch395_open_socket_sn","text":"

    Description

    This command is used to open Socket and use the necessary steps of Socket. It is necessary to input 1 byte of Socket index value. After sending this command, MCU shall send GET_CMD_STATUS to query the command execution status. After opening Socket in UDP, IPRAW or MACRAW mode and returning successfully, data transmission can be performed. Before this command is sent, necessary settings must be made for destination IP, protocol type, source port, destination port, etc. Please refer to 8.3 Application Reference Steps for detailed steps.

    Input

    • Accumulator : Socket id

    Modify

    • Y Register
    "},{"location":"2024.2/assembly/#ch395_read_recv_buf_sn","title":"ch395_read_recv_buf_sn","text":"

    Description

    This command is used to read data from Socket receive buffer. It is necessary to input 1 byte of Socket index value and 2 bytes of length (low bytes in front). CH395 will output several bytes of data stream based on the length value. In actual application, the command RECV_LEN_SN can be firstly sent to get the actual effective length of the current buffer. The length of the read data can be less than the actual effective length of the buffer, the unread data is still reserved in the receive buffer, and MCU can continue to read through this command. In MACRAW mode, the processing modes are different. In MACRAW mode, the receive buffer is a frame buffer, which can cache only 1 frame of Ethernet data. After CH395 processes the command READ_RECV_BUF_SN, Socket0 receive buffer will be cleared, so MCU shall read all valid data of the buffer at a time.

    Input

    • Accumulator : Socket id
    • Y Register : Length low
    • X Register : length high
    • RES : tr to fill

    Modify

    • RESBtmp value
    "},{"location":"2024.2/assembly/#ch395_reset_all","title":"ch395_reset_all","text":"

    Description

    This command enables CH395 to perform a hardware reset. Typically, hardware reset is completed within 50mS.

    Example

     jsr ch395_reset_all\n; Wait a bit\n
    "},{"location":"2024.2/assembly/#ch395_set_baudrate","title":"ch395_set_baudrate","text":"

    Description

    This command is used to set the baud rate of CH395 for serial communication. When CH395 works in serial communication mode, the default communication baud rate is set by the level combination of SDO, SDI and SCK pins (refer to Section 6.4 of this datasheet) after reset. When these pins are suspended, the baud rate is 9600bps by default. If MCU supports high communication speed, the serial communication baud rate can be dynamically regulated through this command. This command requires the input of three data, namely, baudrate coefficient 0, baud rate coefficient 1 and baud rate coefficient 2. The following table shows the corresponding relationship with baud rates.

    "},{"location":"2024.2/assembly/#ch395_set_des_port_sn","title":"ch395_set_des_port_sn","text":"

    Description

    This command is used to set the Socket destination port. It is necessary to input 1 byte of Socket index value and 2 bytes of destination port (the low bytes are in front). When Socket works in UDP or TCP Client mode, this value must be set.

    Input

    • Accumulator : Socketid
    • Y Register : Low int
    • X Register : high int

    Modify

    • REStmp

    Example

     lda #$01\nldx #80\nldx #$00\njsr ch395_set_des_port_sn\nrts\n
    "},{"location":"2024.2/assembly/#ch395_set_fun_para","title":"ch395_set_fun_para","text":"

    Description

    Set fun para

    Input

    • Accumulator : Value

    Modify

    • Y Register
    • Accumulator
    "},{"location":"2024.2/assembly/#ch395_set_gwip_addr","title":"ch395_set_gwip_addr","text":"

    Description

    This command is used to set the gateway address for CH395. It is necessary to input 4 bytes of IP address

    Does not work

    "},{"location":"2024.2/assembly/#ch395_set_ip_addr","title":"ch395_set_ip_addr","text":"

    Description

    This command is used to set IP address for CH395. It is necessary to input 4 bytes of IP address, with low bytes of IP in front. For all commands including IP input or output in this datasheet, IP low bytes are in front. This will not be explained below

    Does not work

    "},{"location":"2024.2/assembly/#ch395_set_ip_addr_sn","title":"ch395_set_ip_addr_sn","text":"

    Description

    This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent

    Input

    • Accumulator : Socket id
    • Y Register : low ptr ip
    • X Register : high ptr ip

    Modify

    • REStmp
    "},{"location":"2024.2/assembly/#ch395_set_ipraw_pro_sn","title":"ch395_set_ipraw_pro_sn","text":"

    Description

    Set ipraw protocol on socket

    Input

    • Accumulator : Socket id
    • X Register : the mode proto

    Modify

    • Y Register
    "},{"location":"2024.2/assembly/#ch395_set_mac_adress","title":"ch395_set_mac_adress","text":"

    Description

    This command is used to set MAC address for CH395. It is necessary to input 6 bytes of MAC, with low bytes of MAC address in front. CH395 chip will store MAC address in the internal EEPROM. It will take 100mS to execute this command.MAC address assigned by IEEE has been burned when CH395 chip is delivered. If it is not necessary, please do not set MAC address

    Input

    • Accumulator : Low ptr mac adress
    • X Register : High ptr mac adress

    Modify

    • Accumulator
    • Y Register
    • RESTmp
    "},{"location":"2024.2/assembly/#ch395_set_mac_filt","title":"ch395_set_mac_filt","text":"

    Does not work

    "},{"location":"2024.2/assembly/#ch395_set_mask_addr","title":"ch395_set_mask_addr","text":"

    Description

    This command is used to set the subnet mask for CH395. It is necessary to input 4 bytes of mask for this command. It is 255.255.255.0 by default and may not be set

    Does not work

    "},{"location":"2024.2/assembly/#ch395_set_phy","title":"ch395_set_phy","text":"

    Description

    This command is used to set Ethernet PHY connection mode of CH395. The connection mode is automated negotiation mode by default. This command needs to input 1 byte of data, which is the connection mode code: Disconnect PHY when the connection mode code is 01H; PHY is 10M full duplex when the connection mode code is 02H; PHY is 10M half duplex when the connection mode code is 04H; PHY is 100M full duplex when the connection mode code is 08H; PHY is 100M half duplex when the connection mode code is 10H; PHY is automated negotiation when the connection mode code is 20H. When CH395 receives this command, it will reset MAC and PHY and reconnect according to the newly set connection mode. If Ethernet is already connected, it will be disconnected and reconnected.

    Does not work

    "},{"location":"2024.2/assembly/#ch395_set_proto_type_sn","title":"ch395_set_proto_type_sn","text":"

    Description

    This command is used to set the working mode of Socket. It is necessary to input 1 byte of Socket index value and 1 byte of working mode. The working mode is defined as follows:

    Code Name Description

    03H PROTO_TYPE_TCP TCP mode

    02H PROTO_TYPE_UDP UDP mode

    01H PROTO_TYPE_MAC_RAW MAC original message mode

    00H PROTO_TYPE_IP_RAW IP original message mode

    This command must be executed before CMD_OPEN_SOCKET_SN. Refer to 8.3 Application Reference

    Steps for detailed steps.

    Input

    • Accumulator : Socket id
    "},{"location":"2024.2/assembly/#ch395_set_retran_count","title":"ch395_set_retran_count","text":"

    Description

    This command is used to set the number of retries. It is necessary to input 1 byte of number of retries. The allowable maximum value is 20. If the input data is more than 20, it will be processed as 20. The default number of retries is 12, and retries are only valid in TCP mode.

    Input

    • Accumulator : Retran period

    Modify

    • X Register
    "},{"location":"2024.2/assembly/#ch395_set_retran_period","title":"ch395_set_retran_period","text":"

    Description

    This command is used to set the retry cycle. It is necessary to input 2 bytes of number of cycles of (with low bytes in front) in milliseconds. The allowable maximum value is 1000. The total retry time is N * M, N is the number of retries, and M is the retry cycle. The default retry cycle is 500MS and retries are only valid in TCP mode.

    Input

    • Accumulator : Period
    • X Register : Period

    Modify

    • Y Register

    Example

     lda #$FF\nldx #$FF\njsr ch395_retran_period\nrts\n
    "},{"location":"2024.2/assembly/#ch395_set_sour_port_sn","title":"ch395_set_sour_port_sn","text":"

    Description

    This command is used to set the source port of Socket. It is necessary to input 1 byte of Socket index value and 2 bytes of source port (low bytes in front). If two or more Sockets are in the same mode, the source port numbers must not be the same. For example, Socket 0 is in UDP mode, the source port number is 600, and Socket 1 is also in UDP mode. The source port number 600 cannot be used again, otherwise it may cause the0 opening failure.

    Input

    • Accumulator : Socket id
    • Y Register : Low ptr address
    • X Register : High ptr address

    Modify

    • RES
    "},{"location":"2024.2/assembly/#ch395_set_ttl","title":"ch395_set_ttl","text":"

    Description

    This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128

    Input

    • Accumulator : Socket ID
    • X Register : TTL value

    Modify

    • Y Register
    "},{"location":"2024.2/assembly/#ch395_tcp_connect_sn","title":"ch395_tcp_connect_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"2024.2/assembly/#ch395_tcp_disconnect_sn","title":"ch395_tcp_disconnect_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"2024.2/assembly/#ch395_tcp_listen_sn","title":"ch395_tcp_listen_sn","text":"

    Description

    This command is only valid in TCP mode, enabling the Socket to be in the monitoring mode, namely, TCP Server mode. It is necessary to input a 1 byte of Socket index value. This command must be executed after OPEN_SOCKET_SN. After sending this command, MCU shall send GET_CMD_STATUS to query the 0command execution status. In TCP Server mode, the Socket will always detect connection events, and the interrupt SINT_STAT_CONNECT will be generated until the connection is successful. Only one connection can be 0established for each Socket. If an eligible connection event is received again, Socket will send TCP RESET to the remote end tried to be connected.

    "},{"location":"2024.2/assembly/#ch395_write_send_buf_sn","title":"ch395_write_send_buf_sn","text":"

    Description

    This command is used to write data to Socket transmit buffer. It is necessary to input 1 byte of Socket index value, 2 bytes of length (low bytes in front) and several bytes of data stream. The length of input data must not be larger than the size of transmit buffer. However, in MACRAW mode, the maximum length of input data can only be 1514, and any redundant data will be discarded. After the external MCU writes the data, CH395 will encapsulate the data packet according to the working mode of Socket, and then send it. Before MCU receives SINT_STAT_SENBUF_FREE, it is not allowed to write data into Socket transmit buffer again

    Input

    • Accumulator : Socket ID
    • Y Register : Low length
    • X Register : High length
    • RESB : Adress ptr to read

    Modify

    • RESTmp

    Example

    "},{"location":"2024.2/c/","title":"C","text":""},{"location":"2024.2/c/#c","title":"C","text":""},{"location":"2024.2/c/#unsigned-char-ch395_check_exist","title":"unsigned char ch395_check_exist();","text":"

    Description

    This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.

    "},{"location":"2024.2/c/#void-ch395_clear_recv_buf_snunsigned-char-id_socket","title":"void ch395_clear_recv_buf_sn(unsigned char ID_SOCKET)","text":"

    Description

    This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.

    "},{"location":"2024.2/c/#void-ch395_close_socket_snunsigned-char-socketid","title":"void ch395_close_socket_sn(unsigned char socketid)","text":"

    Description

    This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.

    Input

    "},{"location":"2024.2/c/#void-ch395_dhcp_enable","title":"void ch395_dhcp_enable()","text":"

    Description

    This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status

    Description

    Get cmd status

    "},{"location":"2024.2/c/#unsigned-char-ch395_get_cmd_status","title":"unsigned char ch395_get_cmd_status();","text":""},{"location":"2024.2/c/#unsigned-char-ch395_get_dhcp_status","title":"unsigned char ch395_get_dhcp_status();","text":"

    Description

    Get dhcp status

    "},{"location":"2024.2/c/#unsigned-int-ch395_get_glob_int_status","title":"unsigned int ch395_get_glob_int_status();","text":"

    Description

    Get General interrupt Status

    "},{"location":"2024.2/c/#unsigned-char-ch395_get_ic_ver","title":"unsigned char ch395_get_ic_ver();","text":"

    Description

    This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text

    ;;@inputA Socket id ;;@modifyA ;;@modifyX ;;@returnsA Status of selected socket ;;@ca65 ;;@` lda #CH395_SOCKET1 ; Check socket 1 ;;@` jsr ch395_get_int_status_sn ;;@` ; Check interrupt type ;;@` and #CH395_SINT_STAT_SEND_OK ;;@` cmp #CH395_SINT_STAT_SEND_OK ;;@` beq @send_ok ;;@` rts ;;@ ldx #CH395_GET_INT_STATUS_SN stx CH395_COMMAND_PORT sta CH395_DATA_PORT lda CH395_DATA_PORT rts endproc

    "},{"location":"2024.2/c/#unsigned-char-ch395_get_int_status_snunsigned-char-id_socket","title":"unsigned char ch395_get_int_status_sn(unsigned char ID_SOCKET);","text":"

    Description

    Check interrupt socket status

    Input

    "},{"location":"2024.2/c/#void-ch395_get_ip_infunsigned-char-ip_infos","title":"void ch395_get_ip_inf(unsigned char ip_infos[]);","text":"

    Description

    Get ip info : ip_infos must be 20 bytes length)

    "},{"location":"2024.2/c/#void-ch395_get_mac_adressunsigned-char-macaddress","title":"void ch395_get_mac_adress(unsigned char macaddress[]);","text":"

    Description

    Get mac address

    "},{"location":"2024.2/c/#unsigned-char-ch395_get_phy_status","title":"unsigned char ch395_get_phy_status();","text":"

    Description

    Get physical status

    "},{"location":"2024.2/c/#void-ch395_get_recv_len_snunsigned-char-id_socket","title":"void ch395_get_recv_len_sn(unsigned char ID_SOCKET)","text":"

    Description

    Get the length received from socket

    Input

    "},{"location":"2024.2/c/#void-ch395_get_remot_ipp_snunsigned-char-ptr-unsigned-char-socket","title":"void ch395_get_remot_ipp_sn(unsigned char *ptr, unsigned char socket);","text":"

    Description

    Get remote ip connected to the socket

    Input

    "},{"location":"2024.2/c/#unsigned-int-ch395_get_socket_status_snunsigned-char-id_socket","title":"unsigned int ch395_get_socket_status_sn(unsigned char ID_SOCKET);","text":"

    Description

    Returns in A socket status (close/open ... )

    Input

    "},{"location":"2024.2/c/#void-ch395_init","title":"void ch395_init();","text":"

    Description

    ;;@brief This command is used to initialize CH395, including initializing MAC, PHY and TCP/IP stack of CH395. Generally, it takes 350mS to execute the command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status.

    "},{"location":"2024.2/c/#void-ch395_open_socket_snunsigned-char-id_socket","title":"void ch395_open_socket_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.2/c/#void-ch395_read_recv_buf_snunsigned-char-buffer-unsigned-int-ptr2unsigned-char-id_socket","title":"void ch395_read_recv_buf_sn(unsigned char *buffer, unsigned int ptr2,unsigned char ID_SOCKET);","text":"

    Input

    "},{"location":"2024.2/c/#void-ch395_reset_all","title":"void ch395_reset_all()","text":"

    Description

    Reset ch395

    "},{"location":"2024.2/c/#void-ch395_set_des_port_snunsigned-int-port-unsigned-char-id_socket","title":"void ch395_set_des_port_sn(unsigned int port, unsigned char ID_SOCKET);","text":"

    Description

    Set dest port socket

    Input

    "},{"location":"2024.2/c/#void-ch395_set_fun_paraunsigned-char-flag","title":"void ch395_set_fun_para(unsigned char flag)","text":"

    Description

    Set fun para

    Description

    Set gateway ip addr

    Description

    This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent

    "},{"location":"2024.2/c/#void-ch395_set_ip_addr_snunsigned-char-ip_addr-unsigned-char-id_socket","title":"void ch395_set_ip_addr_sn(unsigned char ip_addr[], unsigned char ID_SOCKET)","text":""},{"location":"2024.2/c/#void-ch395_set_ipraw_pro_snunsigned-char-id_socket","title":"void ch395_set_ipraw_pro_sn(unsigned char ID_SOCKET);","text":"

    Description

    Set ipraw protocol on socket

    Input

    "},{"location":"2024.2/c/#void-ch395_set_mac_adressunsigned-char-macaddress","title":"void ch395_set_mac_adress(unsigned char macaddress[]);","text":""},{"location":"2024.2/c/#void-ch395_set_proto_type_snunsigned-char-proto-unsigned-char-id_socket","title":"void ch395_set_proto_type_sn(unsigned char proto, unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.2/c/#void-ch395_set_retran_countunsigned-int-period","title":"void ch395_set_retran_count(unsigned int period);","text":"

    Description

    Set retran period

    "},{"location":"2024.2/c/#void-ch395_retran_periodunsigned-int-period","title":"void ch395_retran_period(unsigned int period);","text":"

    Description

    Retran period

    "},{"location":"2024.2/c/#void-ch395_set_sour_port_snunsigned-int-portunsigned-char-id_socket","title":"void ch395_set_sour_port_sn(unsigned int port,unsigned char ID_SOCKET)","text":"

    Description

    Set source socket

    Input

    Description

    This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128

    "},{"location":"2024.2/c/#ch395_set_ttlunsigned-char-id_socket-unsigned-char-ttl_value","title":"ch395_set_ttl(unsigned char ID_SOCKET, unsigned char ttl_value);","text":""},{"location":"2024.2/c/#void-ch395_tcp_connect_snunsigned-char-id_socket","title":"void ch395_tcp_connect_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.2/c/#void-ch395_tcp_disconnect_snunsigned-char-id_socket","title":"void ch395_tcp_disconnect_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.2/c/#void-ch395_tcp_listen_snunsigned-char-id_socket","title":"void ch395_tcp_listen_sn(unsigned char ID_SOCKET)","text":""},{"location":"2024.2/c/#void-ch395_write_send_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_write_send_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"

    Description

    Send data to socketid [Not working]

    Input

    "}]} \ No newline at end of file +{"config":{"lang":["en"],"separator":"[\\s\\-]+","pipeline":["stopWordFilter"]},"docs":[{"location":"","title":"Introduction","text":"

    This lib is used to manage ch395 chip for 6502 cpu

    "},{"location":"assembly/","title":"Assembly","text":""},{"location":"assembly/#assembly","title":"Assembly","text":""},{"location":"assembly/#ch395_check_exist","title":"ch395_check_exist","text":"

    Description

    This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.

    Modify

    • Accumulator

    Returns

    • Accumulator : Returns '#CH395_DETECTED' if it exists

    Example

     jsr ch395_check_exist\ncmp #CH395_DETECTED\nbeq ch395_connected\nrts\nch395_connected:\n
    "},{"location":"assembly/#ch395_clear_recv_buf_sn","title":"ch395_clear_recv_buf_sn","text":"

    Description

    This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.

    Input

    • Accumulator : Socket id

    Modify

    • Accumulator
    • Y Register

    Example

     lda #CH395_SOCKET1 ; Socket ID\njsr ch395_clear_recv_buf_sn\n
    "},{"location":"assembly/#ch395_close_socket_sn","title":"ch395_close_socket_sn","text":"

    Description

    This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.

    Input

    • Accumulator : The id of the socket to close

    Modify

    • Y Register

    Example

     lda #$01 ; Socket ID\njsr ch395_close_socket_sn\n
    "},{"location":"assembly/#ch395_dhcp_enable","title":"ch395_dhcp_enable","text":"

    Description

    This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status

    Input

    • Accumulator : The mode to activate DHCP mode

    Modify

    • X Register
    "},{"location":"assembly/#ch395_enter_sleep","title":"ch395_enter_sleep","text":"

    Description

    This command enables CH395 chip in a low-power sleep suspended state. When MCU writes a new command to CH395 (no data input command, such as CMD_GET_IC_VER), it will exit the low-power state. For the parallel port and SPI interface communication modes, active SCS chip selection will also cause CH395 to exit the low-power state, so MCU shall immediately disable the SCS chip selection after sending the command CMD_ENTER_SLEEP. In sleep state, MAC and PHY of CH395 will be in power off mode and disconnect Ethernet. Typically, it takes several milliseconds for CH395 to exit the low-power state.

    Does not work

    "},{"location":"assembly/#ch395_get_cmd_status","title":"ch395_get_cmd_status","text":"

    Description

    This command is used to get the command execution status. CH395 will output 1 byte of data, which is the command execution state. The command execution status is as follows:

    Example

     jsr ch395_get_cmd_status\n; Check A for STATUS\nrts\n

    Modify

    • Accumulator
    "},{"location":"assembly/#ch395_get_dhcp_status","title":"ch395_get_dhcp_status","text":"

    Description

    Get dhcp status

    Example

     jsr ch395_get_dhcp_status\n; Check A for dhcp status\nrts\n

    Modify

    • Accumulator
    "},{"location":"assembly/#ch395_get_glob_int_status_all","title":"ch395_get_glob_int_status_all","text":"

    Description

    This command is used to get the global interrupt status. CH395 will output 2 bytes of global interrupt status after receiving this command. Global interrupt status is defined as follows:

    Does not work

    "},{"location":"assembly/#ch395_get_glob_int_status","title":"ch395_get_glob_int_status","text":"

    Description

    This command is used to get the global interrupt status. CH395 will output 1 byte of global interrupt status after receiving this command. Global interrupt status is defined as follows:

    Bit Name Description

    7 GINT_STAT_SOCK3 Socket3 interrupt

    6 GINT_STAT_SOCK2 Socket2 interrupt

    5 GINT_STAT_SOCK1 Socket1 interrupt

    4 GINT_STAT_SOCK0 Socket0 interrupt

    3 GINT_STAT_DHCP DHCP interrupt

    2 GINT_STAT_PHY_CHANGE PHY status change interrupt

    1 GINT_STAT_IP_CONFLI IP conflict

    0 GINT_STAT_UNREACH Inaccessible interrupt

    \u2460 GINT_STAT_UNREACH: Inaccessible interrupt. When CH395 receives ICMP inaccessible interrupt

    message, it saves the IP address, port and protocol type of the inaccessible IP packet in the inaccessible

    information table, and then generates an interrupt. When the MCU receives the interrupt, it can send the

    command GET_UNREACH_IPPORT to get the inaccessible information.

    \u2461 GINT_STAT_IP_CONFLI: IP conflict interrupt. This interrupt is generated when CH395 detects that its

    IP address is the same as that of other network devices in the same network segment.

    \u2462 GINT_STAT_PHY_CHANGE: PHY change interrupt. This interrupt is generated when PHY connection

    of CH395 changes, for example, PHY state changes from the connected state to the disconnected state or

    from the disconnected state to the connected state. MCU can send GET_PHY_STATUS command to get

    the current PHY connection status.

    \u2463 GINT_STAT_DHCP: DHCP interrupt. If MCU enables DHCP function of CH395, CH395 will generate

    this interrupt. MCU can send the command CMD_GET_DHCP_STATUS to get the DHCP status. If the

    status is 0, it will indicate success; otherwise, it will indicate timeout failure.

    \u2464 GINT_STAT_SOCK0 - GINT_STAT_SOCK3: Socket interrupt. When there is an interrupt event in

    Socket, CH395 will generate this interrupt. MCU needs to send GET_INT_STATUS_SN to get the

    interrupt status of Socket. Please refer to GET_INT_STATUS_SN.

    When this command is completed, CH395 will set INT# pin to high level and clear the global interrupt

    status

    Modify

    • Accumulator

    Returns

    • Accumulator : Status

    Example

     jsr ch395_get_glob_int_status\n; check accumulator to get interrupts states\n
    "},{"location":"assembly/#ch395_get_ic_ver","title":"ch395_get_ic_ver","text":"

    Description

    This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text

    Modify

    • Accumulator

    Returns

    • Accumulator : Version

    Example

     jsr ch395_get_ic_ver\n; Check A for version\nrts\n
    "},{"location":"assembly/#ch395_get_int_status_sn","title":"ch395_get_int_status_sn","text":"

    Description

    This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index value. After receiving this command, CH395 will output 1 byte of Socket interrupt code. The interrupt code bits are defined as follows:

    Input

    • Accumulator : Socket id

    Modify

    • Accumulator
    • X Register

    Returns

    • Accumulator : Status of selected socket

    Example

     lda #CH395_SOCKET1 ; Check socket 1\njsr ch395_get_int_status_sn\n; Check interrupt type\nand #CH395_SINT_STAT_SEND_OK\ncmp #CH395_SINT_STAT_SEND_OK\nbeq @send_ok\nrts\n
    "},{"location":"assembly/#ch395_get_ip_inf","title":"ch395_get_ip_inf","text":"

    Description

    Get ip info

    Input

    • Accumulator : the ptr to modify (Ptr must be 20 bytes length)
    • X Register : the ptr to modify (Ptr must be 20 bytes length)

    Modify

    • Accumulator
    • X Register
    • Y Register
    • RESTmp value
    "},{"location":"assembly/#ch395_get_mac_adress","title":"ch395_get_mac_adress","text":"

    Description

    Get mac address

    Input

    • Accumulator : the ptr
    • X Register : the ptr

    Modify

    • Accumulator
    • X Register
    • Y Register
    • RESTmp value

    Returns

    • Accumulator : the content of ptr modified

    • X Register : the content of ptr modified

    "},{"location":"assembly/#ch395_get_phy_status","title":"ch395_get_phy_status","text":"

    Description

    This command is used to get PHY connection status. After receiving this command, CH395 will query the current PHY connection status and output 1-byte PHY connection status code: PHY is disconnected when the connection status code is 01H; PHY connection is 10M full duplex when the connection status code is 02H; PHY connection is 10M half duplex when the connection status code is 04H. PHY connection is 100M full duplex when the connection status code is 08H; PHY connection is 100M half duplex when the connection status code is 10H

    Modify

    • Accumulator

    Returns

    • Accumulator : The physical status

    Example

     jsr ch395_get_phy_status\n; Check A physical status\nrts\n
    "},{"location":"assembly/#ch395_get_recv_len_sn","title":"ch395_get_recv_len_sn","text":"

    Description

    Get the length received from socket

    Input

    • Accumulator : Socket id

    Example

     lda #$01 ; Socket 1\njsr ch395_get_recv_len_sn\n; check A and X for length received\nch395_connected:\n

    Modify

    • Accumulator
    • X Register

    Returns

    • Accumulator : The length

    • X Register : The length

    "},{"location":"assembly/#ch395_get_remot_ipp_sn","title":"ch395_get_remot_ipp_sn","text":"

    Description

    This command is used to get the remote IP address and port number. It is necessary to input 1 byte of Socket index value. CH395 will output 4 bytes of IP address and 2 bytes of port number (low bytes in front). After Socket works in TCP Server mode and the connection is established, MCU can get the remote IP address and port number through this command

    Input

    • Accumulator : The Socket for the ip to get
    • X Register : The ptr (high) to store the ip
    • Y Register : The ptr (low) to store the ip

    Modify

    • Accumulator
    • X Register
    • Y Register
    • RES

    Example

     lda #$01 ; Socket 1\nldx #<ip_dest\nldy #>ip_dest\njsr ch395_get_remot_ipp_sn\nrts\nipdest:\n.byte 192,168,0,1\n
    "},{"location":"assembly/#ch395_get_socket_status_sn","title":"ch395_get_socket_status_sn","text":"

    Description

    This command is used to get Socket status. It is necessary to input a 1 byte of Socket index value. CH395 will output a 2-byte status code when receiving this command. The first status code is the status code of Socket. The status code of Socket is defined as follows:

    Input

    • Accumulator : Socket id

    Modify

    • X Register
    • Accumulator

    Returns

    • Accumulator : The status

    • X Register : The state

    Example

     lda #$01 ; Socket 1\njsr ch395_get_socket_status_sn\n; check A and X for the state\ncmp #CH395_SOCKET_CLOSED\nbeq @soclet is closed\n
    "},{"location":"assembly/#ch395_get_unreach_ipport","title":"ch395_get_unreach_ipport","text":"

    Description

    This command is used to get an inaccessible IP, ports and protocol type. CH395 will generate an inaccessible interrupt when an inaccessible message is received. MCU can use this command to get inaccessible information. After receiving this command, CH395 will output 1 byte of inaccessible code, 1 byte of protocol type, 2 bytes of port number (low bytes in front), and 4 bytes of IP in turn. MCU can judge whether the protocol, port or IP is inaccessible according to the inaccessible codes. For inaccessible codes, refer to RFC792 (CH395INC.H defines four common inaccessible codes).

    Does not work

    "},{"location":"assembly/#ch395_init","title":"ch395_init","text":"

    Description

    This command is used to initialize CH395, including initializing MAC, PHY and TCP/IP stack of CH395. Generally, it takes 350mS to execute the command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status.

    Modify

    • Accumulator Description

    Reset ch395

    Example

     jsr ch395_init\n; Wait a bit\n
    "},{"location":"assembly/#ch395_open_socket_sn","title":"ch395_open_socket_sn","text":"

    Description

    This command is used to open Socket and use the necessary steps of Socket. It is necessary to input 1 byte of Socket index value. After sending this command, MCU shall send GET_CMD_STATUS to query the command execution status. After opening Socket in UDP, IPRAW or MACRAW mode and returning successfully, data transmission can be performed. Before this command is sent, necessary settings must be made for destination IP, protocol type, source port, destination port, etc. Please refer to 8.3 Application Reference Steps for detailed steps.

    Input

    • Accumulator : Socket id

    Modify

    • Y Register
    "},{"location":"assembly/#ch395_read_recv_buf_sn","title":"ch395_read_recv_buf_sn","text":"

    Description

    This command is used to read data from Socket receive buffer. It is necessary to input 1 byte of Socket index value and 2 bytes of length (low bytes in front). CH395 will output several bytes of data stream based on the length value. In actual application, the command RECV_LEN_SN can be firstly sent to get the actual effective length of the current buffer. The length of the read data can be less than the actual effective length of the buffer, the unread data is still reserved in the receive buffer, and MCU can continue to read through this command. In MACRAW mode, the processing modes are different. In MACRAW mode, the receive buffer is a frame buffer, which can cache only 1 frame of Ethernet data. After CH395 processes the command READ_RECV_BUF_SN, Socket0 receive buffer will be cleared, so MCU shall read all valid data of the buffer at a time.

    Input

    • Accumulator : Socket id
    • Y Register : Length low
    • X Register : length high
    • RES : tr to fill

    Modify

    • RESBtmp value
    "},{"location":"assembly/#ch395_reset_all","title":"ch395_reset_all","text":"

    Description

    This command enables CH395 to perform a hardware reset. Typically, hardware reset is completed within 50mS.

    Example

     jsr ch395_reset_all\n; Wait a bit\n
    "},{"location":"assembly/#ch395_set_baudrate","title":"ch395_set_baudrate","text":"

    Description

    This command is used to set the baud rate of CH395 for serial communication. When CH395 works in serial communication mode, the default communication baud rate is set by the level combination of SDO, SDI and SCK pins (refer to Section 6.4 of this datasheet) after reset. When these pins are suspended, the baud rate is 9600bps by default. If MCU supports high communication speed, the serial communication baud rate can be dynamically regulated through this command. This command requires the input of three data, namely, baudrate coefficient 0, baud rate coefficient 1 and baud rate coefficient 2. The following table shows the corresponding relationship with baud rates.

    "},{"location":"assembly/#ch395_set_des_port_sn","title":"ch395_set_des_port_sn","text":"

    Description

    This command is used to set the Socket destination port. It is necessary to input 1 byte of Socket index value and 2 bytes of destination port (the low bytes are in front). When Socket works in UDP or TCP Client mode, this value must be set.

    Input

    • Accumulator : Socketid
    • Y Register : Low int
    • X Register : high int

    Modify

    • REStmp

    Example

     lda #$01\nldy #80\nldx #$00\njsr ch395_set_des_port_sn\nrts\n
    "},{"location":"assembly/#ch395_set_fun_para","title":"ch395_set_fun_para","text":"

    Description

    Set fun para

    Input

    • Accumulator : Value

    Modify

    • Y Register
    • Accumulator
    "},{"location":"assembly/#ch395_set_gwip_addr","title":"ch395_set_gwip_addr","text":"

    Description

    This command is used to set the gateway address for CH395. It is necessary to input 4 bytes of IP address

    Does not work

    "},{"location":"assembly/#ch395_set_ip_addr","title":"ch395_set_ip_addr","text":"

    Description

    This command is used to set IP address for CH395. It is necessary to input 4 bytes of IP address, with low bytes of IP in front. For all commands including IP input or output in this datasheet, IP low bytes are in front. This will not be explained below

    Does not work

    "},{"location":"assembly/#ch395_set_ip_addr_sn","title":"ch395_set_ip_addr_sn","text":"

    Description

    This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent

    Input

    • Accumulator : Socket id
    • Y Register : low ptr ip
    • X Register : high ptr ip

    Modify

    • REStmp
    "},{"location":"assembly/#ch395_set_ipraw_pro_sn","title":"ch395_set_ipraw_pro_sn","text":"

    Description

    Set ipraw protocol on socket

    Input

    • Accumulator : Socket id
    • X Register : the mode proto

    Modify

    • Y Register
    "},{"location":"assembly/#ch395_set_mac_adress","title":"ch395_set_mac_adress","text":"

    Description

    This command is used to set MAC address for CH395. It is necessary to input 6 bytes of MAC, with low bytes of MAC address in front. CH395 chip will store MAC address in the internal EEPROM. It will take 100mS to execute this command.MAC address assigned by IEEE has been burned when CH395 chip is delivered. If it is not necessary, please do not set MAC address

    Input

    • Accumulator : Low ptr mac adress
    • X Register : High ptr mac adress

    Modify

    • Accumulator
    • Y Register
    • RESTmp
    "},{"location":"assembly/#ch395_set_mac_filt","title":"ch395_set_mac_filt","text":"

    Does not work

    "},{"location":"assembly/#ch395_set_mask_addr","title":"ch395_set_mask_addr","text":"

    Description

    This command is used to set the subnet mask for CH395. It is necessary to input 4 bytes of mask for this command. It is 255.255.255.0 by default and may not be set

    Does not work

    "},{"location":"assembly/#ch395_set_phy","title":"ch395_set_phy","text":"

    Description

    This command is used to set Ethernet PHY connection mode of CH395. The connection mode is automated negotiation mode by default. This command needs to input 1 byte of data, which is the connection mode code: Disconnect PHY when the connection mode code is 01H; PHY is 10M full duplex when the connection mode code is 02H; PHY is 10M half duplex when the connection mode code is 04H; PHY is 100M full duplex when the connection mode code is 08H; PHY is 100M half duplex when the connection mode code is 10H; PHY is automated negotiation when the connection mode code is 20H. When CH395 receives this command, it will reset MAC and PHY and reconnect according to the newly set connection mode. If Ethernet is already connected, it will be disconnected and reconnected.

    Does not work

    "},{"location":"assembly/#ch395_set_proto_type_sn","title":"ch395_set_proto_type_sn","text":"

    Description

    This command is used to set the working mode of Socket. It is necessary to input 1 byte of Socket index value and 1 byte of working mode. The working mode is defined as follows:

    Code Name Description

    03H PROTO_TYPE_TCP TCP mode

    02H PROTO_TYPE_UDP UDP mode

    01H PROTO_TYPE_MAC_RAW MAC original message mode

    00H PROTO_TYPE_IP_RAW IP original message mode

    This command must be executed before CMD_OPEN_SOCKET_SN. Refer to 8.3 Application Reference

    Steps for detailed steps.

    Input

    • Accumulator : Socket id
    • X Register : Proto mode

    Modify

    • Y Register tmp

    Example

     lda #$00 ; Socket\nldx #CH395_PROTO_TYPE_TCP\njsr ch395_set_proto_type_sn\n
    "},{"location":"assembly/#ch395_set_retran_count","title":"ch395_set_retran_count","text":"

    Description

    This command is used to set the number of retries. It is necessary to input 1 byte of number of retries. The allowable maximum value is 20. If the input data is more than 20, it will be processed as 20. The default number of retries is 12, and retries are only valid in TCP mode.

    Input

    • Accumulator : Retran period

    Modify

    • X Register
    "},{"location":"assembly/#ch395_set_retran_period","title":"ch395_set_retran_period","text":"

    Description

    This command is used to set the retry cycle. It is necessary to input 2 bytes of number of cycles of (with low bytes in front) in milliseconds. The allowable maximum value is 1000. The total retry time is N * M, N is the number of retries, and M is the retry cycle. The default retry cycle is 500MS and retries are only valid in TCP mode.

    Input

    • Accumulator : Period
    • X Register : Period

    Modify

    • Y Register

    Example

     lda #$FF\nldx #$FF\njsr ch395_retran_period\nrts\n
    "},{"location":"assembly/#ch395_set_sour_port_sn","title":"ch395_set_sour_port_sn","text":"

    Description

    This command is used to set the source port of Socket. It is necessary to input 1 byte of Socket index value and 2 bytes of source port (low bytes in front). If two or more Sockets are in the same mode, the source port numbers must not be the same. For example, Socket 0 is in UDP mode, the source port number is 600, and Socket 1 is also in UDP mode. The source port number 600 cannot be used again, otherwise it may cause the0 opening failure.

    Input

    • Accumulator : Socket id
    • Y Register : Low port
    • X Register : High port

    Modify

    • RES
    "},{"location":"assembly/#ch395_set_ttl","title":"ch395_set_ttl","text":"

    Description

    This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128

    Input

    • Accumulator : Socket ID
    • X Register : TTL value

    Modify

    • Y Register
    "},{"location":"assembly/#ch395_tcp_connect_sn","title":"ch395_tcp_connect_sn","text":"

    Description

    Performs tcp connect

    Input

    • Accumulator : Socket id
    "},{"location":"assembly/#ch395_tcp_disconnect_sn","title":"ch395_tcp_disconnect_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"assembly/#ch395_tcp_listen_sn","title":"ch395_tcp_listen_sn","text":"

    Description

    This command is only valid in TCP mode, enabling the Socket to be in the monitoring mode, namely, TCP Server mode. It is necessary to input a 1 byte of Socket index value. This command must be executed after OPEN_SOCKET_SN. After sending this command, MCU shall send GET_CMD_STATUS to query the 0command execution status. In TCP Server mode, the Socket will always detect connection events, and the interrupt SINT_STAT_CONNECT will be generated until the connection is successful. Only one connection can be 0established for each Socket. If an eligible connection event is received again, Socket will send TCP RESET to the remote end tried to be connected.

    "},{"location":"assembly/#ch395_write_send_buf_sn","title":"ch395_write_send_buf_sn","text":"

    Description

    This command is used to write data to Socket transmit buffer. It is necessary to input 1 byte of Socket index value, 2 bytes of length (low bytes in front) and several bytes of data stream. The length of input data must not be larger than the size of transmit buffer. However, in MACRAW mode, the maximum length of input data can only be 1514, and any redundant data will be discarded. After the external MCU writes the data, CH395 will encapsulate the data packet according to the working mode of Socket, and then send it. Before MCU receives SINT_STAT_SENBUF_FREE, it is not allowed to write data into Socket transmit buffer again

    Input

    • Accumulator : Socket ID
    • Y Register : Low length
    • X Register : High length
    • RESB : Adress ptr to read

    Modify

    • RESTmp

    Example

    "},{"location":"c/","title":"C","text":""},{"location":"c/#c","title":"C","text":""},{"location":"c/#unsigned-char-ch395_check_exist","title":"unsigned char ch395_check_exist();","text":"

    Description

    This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.

    "},{"location":"c/#void-ch395_clear_recv_buf_snunsigned-char-id_socket","title":"void ch395_clear_recv_buf_sn(unsigned char ID_SOCKET)","text":"

    Description

    This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.

    "},{"location":"c/#void-ch395_close_socket_snunsigned-char-socketid","title":"void ch395_close_socket_sn(unsigned char socketid)","text":"

    Description

    This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.

    Input

    "},{"location":"c/#void-ch395_dhcp_enable","title":"void ch395_dhcp_enable()","text":"

    Description

    This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status

    Description

    Get cmd status

    "},{"location":"c/#unsigned-char-ch395_get_cmd_status","title":"unsigned char ch395_get_cmd_status();","text":""},{"location":"c/#unsigned-char-ch395_get_dhcp_status","title":"unsigned char ch395_get_dhcp_status();","text":"

    Description

    Get dhcp status

    "},{"location":"c/#unsigned-int-ch395_get_glob_int_status","title":"unsigned int ch395_get_glob_int_status();","text":"

    Description

    Get General interrupt Status

    "},{"location":"c/#unsigned-char-ch395_get_ic_ver","title":"unsigned char ch395_get_ic_ver();","text":"

    Description

    This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text

    ;;@inputA Socket id ;;@modifyA ;;@modifyX ;;@returnsA Status of selected socket ;;@ca65 ;;@` lda #CH395_SOCKET1 ; Check socket 1 ;;@` jsr ch395_get_int_status_sn ;;@` ; Check interrupt type ;;@` and #CH395_SINT_STAT_SEND_OK ;;@` cmp #CH395_SINT_STAT_SEND_OK ;;@` beq @send_ok ;;@` rts ;;@ ldx #CH395_GET_INT_STATUS_SN stx CH395_COMMAND_PORT sta CH395_DATA_PORT lda CH395_DATA_PORT rts endproc

    "},{"location":"c/#unsigned-char-ch395_get_int_status_snunsigned-char-id_socket","title":"unsigned char ch395_get_int_status_sn(unsigned char ID_SOCKET);","text":"

    Description

    Check interrupt socket status

    Input

    "},{"location":"c/#void-ch395_get_ip_infunsigned-char-ip_infos","title":"void ch395_get_ip_inf(unsigned char ip_infos[]);","text":"

    Description

    Get ip info : ip_infos must be 20 bytes length)

    "},{"location":"c/#void-ch395_get_mac_adressunsigned-char-macaddress","title":"void ch395_get_mac_adress(unsigned char macaddress[]);","text":"

    Description

    Get mac address

    "},{"location":"c/#unsigned-char-ch395_get_phy_status","title":"unsigned char ch395_get_phy_status();","text":"

    Description

    Get physical status

    "},{"location":"c/#void-ch395_get_recv_len_snunsigned-char-id_socket","title":"void ch395_get_recv_len_sn(unsigned char ID_SOCKET)","text":"

    Description

    Get the length received from socket

    Input

    "},{"location":"c/#void-ch395_get_remot_ipp_snunsigned-char-ptr-unsigned-char-socket","title":"void ch395_get_remot_ipp_sn(unsigned char *ptr, unsigned char socket);","text":"

    Description

    Get remote ip connected to the socket

    Input

    "},{"location":"c/#unsigned-int-ch395_get_socket_status_snunsigned-char-id_socket","title":"unsigned int ch395_get_socket_status_sn(unsigned char ID_SOCKET);","text":"

    Description

    Returns in A socket status (close/open ... )

    Input

    "},{"location":"c/#void-ch395_init","title":"void ch395_init();","text":"

    Description

    ;;@brief This command is used to initialize CH395, including initializing MAC, PHY and TCP/IP stack of CH395. Generally, it takes 350mS to execute the command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status.

    "},{"location":"c/#void-ch395_open_socket_snunsigned-char-id_socket","title":"void ch395_open_socket_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"c/#void-ch395_read_recv_buf_snunsigned-char-buffer-unsigned-int-ptr2unsigned-char-id_socket","title":"void ch395_read_recv_buf_sn(unsigned char *buffer, unsigned int ptr2,unsigned char ID_SOCKET);","text":"

    Input

    "},{"location":"c/#void-ch395_reset_all","title":"void ch395_reset_all()","text":"

    Description

    Reset ch395

    "},{"location":"c/#void-ch395_set_des_port_snunsigned-int-port-unsigned-char-id_socket","title":"void ch395_set_des_port_sn(unsigned int port, unsigned char ID_SOCKET);","text":"

    Description

    Set dest port socket

    Input

    "},{"location":"c/#void-ch395_set_fun_paraunsigned-char-flag","title":"void ch395_set_fun_para(unsigned char flag)","text":"

    Description

    Set fun para

    Description

    Set gateway ip addr

    Description

    This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent

    "},{"location":"c/#void-ch395_set_ip_addr_snunsigned-char-ip_addr-unsigned-char-id_socket","title":"void ch395_set_ip_addr_sn(unsigned char ip_addr[], unsigned char ID_SOCKET)","text":""},{"location":"c/#void-ch395_set_ipraw_pro_snunsigned-char-id_socket","title":"void ch395_set_ipraw_pro_sn(unsigned char ID_SOCKET);","text":"

    Description

    Set ipraw protocol on socket

    Input

    "},{"location":"c/#void-ch395_set_mac_adressunsigned-char-macaddress","title":"void ch395_set_mac_adress(unsigned char macaddress[]);","text":""},{"location":"c/#void-ch395_set_proto_type_snunsigned-char-proto-unsigned-char-id_socket","title":"void ch395_set_proto_type_sn(unsigned char proto, unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"c/#void-ch395_set_retran_countunsigned-int-period","title":"void ch395_set_retran_count(unsigned int period);","text":"

    Description

    Set retran period

    "},{"location":"c/#void-ch395_retran_periodunsigned-int-period","title":"void ch395_retran_period(unsigned int period);","text":"

    Description

    Retran period

    "},{"location":"c/#void-ch395_set_sour_port_snunsigned-int-portunsigned-char-id_socket","title":"void ch395_set_sour_port_sn(unsigned int port,unsigned char ID_SOCKET)","text":"

    Description

    Set source socket

    Input

    Description

    This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128

    "},{"location":"c/#ch395_set_ttlunsigned-char-id_socket-unsigned-char-ttl_value","title":"ch395_set_ttl(unsigned char ID_SOCKET, unsigned char ttl_value);","text":""},{"location":"c/#void-ch395_tcp_connect_snunsigned-char-id_socket","title":"void ch395_tcp_connect_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"c/#void-ch395_tcp_disconnect_snunsigned-char-id_socket","title":"void ch395_tcp_disconnect_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"c/#void-ch395_tcp_listen_snunsigned-char-id_socket","title":"void ch395_tcp_listen_sn(unsigned char ID_SOCKET)","text":""},{"location":"c/#void-ch395_write_send_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_write_send_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"

    Description

    Send data to socketid [Not working]

    Input

    "},{"location":"2024.1/assembly/","title":"Assembly","text":""},{"location":"2024.1/assembly/#assembly","title":"Assembly","text":""},{"location":"2024.1/assembly/#ch395_check_exist","title":"ch395_check_exist","text":"

    Description

    Checks if ch395 exists

    Example

     jsr ch395_get_glob_int_status\ncmp #CH395_DETECTED\nbeq ch395_connected\nrts\nch395_connected:\n

    Modify

    • Accumulator

    Returns

    • Accumulator : Returns #CH395_DETECTED if it exists
    "},{"location":"2024.1/assembly/#ch395_clear_recv_buf_sn","title":"ch395_clear_recv_buf_sn","text":"

    Description

    Clear receive buffer

    Input

    • Accumulator : Socket id

    Modify

    • Accumulator
    • Y Register

    Example

     lda #CH395_SOCKET1 ; Socket ID\njsr ch395_clear_recv_buf_sn\n
    "},{"location":"2024.1/assembly/#ch395_close_socket_sn","title":"ch395_close_socket_sn","text":"

    Description

    Close socket

    Input

    • Accumulator : The id of the socket to close

    Modify

    • Y Register

    Example

     lda #$01 ; Socket ID\njsr ch395_close_socket_sn\n
    "},{"location":"2024.1/assembly/#ch395_dhcp_enable","title":"ch395_dhcp_enable","text":"

    Description

    Enable or not dhcp

    Input

    • Accumulator : The mode to activate DHCP mode

    Modify

    • X Register
    "},{"location":"2024.1/assembly/#ch395_get_cmd_status","title":"ch395_get_cmd_status","text":"

    Description

    Get cmd status

    Example

     jsr ch395_get_cmd_status\n; Check A for STATUS\nrts\n

    Modify

    • Accumulator
    "},{"location":"2024.1/assembly/#ch395_get_dhcp_status","title":"ch395_get_dhcp_status","text":"

    Description

    Get dhcp status

    Example

     jsr ch395_get_dhcp_status\n; Check A for dhcp status\nrts\n

    Modify

    • Accumulator
    "},{"location":"2024.1/assembly/#ch395_get_glob_int_status","title":"ch395_get_glob_int_status","text":"

    Description

    Get General interrupt Status

    Modify

    • Accumulator

    Example

     jsr ch395_get_glob_int_status\n; check accumulator to get interrupts states\n
    "},{"location":"2024.1/assembly/#ch395_get_ic_ver","title":"ch395_get_ic_ver","text":"

    Description

    Get ch395 firmware version

    Example

     jsr ch395_get_ic_ver\n; Check A for version\nrts\n

    Modify

    • Accumulator
    "},{"location":"2024.1/assembly/#ch395_get_int_status_sn","title":"ch395_get_int_status_sn","text":"

    Description

    Check interrupt socket status

    Input

    • Accumulator : Socket id

    Modify

    • Accumulator
    • X Register

    Returns

    • Accumulator : Status of selected socket

    Example

     lda #CH395_SOCKET1 ; Check socket 1\njsr ch395_get_int_status_sn\n; Check interrupt type\nrts\n
    "},{"location":"2024.1/assembly/#ch395_get_ip_inf","title":"ch395_get_ip_inf","text":"

    Description

    Get ip info

    Input

    • Accumulator : the ptr to modify
    • X Register : the ptr to modify

    Modify

    • Accumulator
    • X Register
    • Y Register
    "},{"location":"2024.1/assembly/#ch395_get_mac_adress","title":"ch395_get_mac_adress","text":"

    Description

    Get mac address

    Input

    • Accumulator : the ptr
    • X Register : the ptr

    Modify

    • Accumulator
    • X Register
    • Y Register

    Returns

    • Accumulator : the content of ptr modified

    • X Register : the content of ptr modified

    "},{"location":"2024.1/assembly/#ch395_get_phy_status","title":"ch395_get_phy_status","text":"

    Description

    Get physical status

    Modify

    • Accumulator

    Returns

    • Accumulator : The physical status

    Example

     jsr ch395_get_phy_status\n; Check A physical status\nrts\n
    "},{"location":"2024.1/assembly/#ch395_get_recv_len_sn","title":"ch395_get_recv_len_sn","text":"

    Description

    Get the length received from socket

    Input

    • Accumulator : Socket id

    Example

     lda #$01 ; Socket 1\njsr ch395_get_recv_len_sn\n; check A and X for length received\nch395_connected:\n

    Modify

    • Accumulator
    • X Register

    Returns

    • Accumulator : The length

    • X Register : The length

    "},{"location":"2024.1/assembly/#ch395_get_remot_ipp_sn","title":"ch395_get_remot_ipp_sn","text":"

    Description

    Get remote ip connected to the socket

    Input

    • Accumulator : The Socket for the ip to get
    • X Register : The ptr (high) to store the ip
    • Y Register : The ptr (low) to store the ip

    Modify

    • Accumulator
    • X Register
    • Y Register
    "},{"location":"2024.1/assembly/#ch395_get_socket_status_sn","title":"ch395_get_socket_status_sn","text":"

    Description

    Returns in A socket status (close/open ...)

    Input

    • Accumulator : Socket id

    Modify

    • X Register
    • Accumulator

    Returns

    • Accumulator : The status

    • X Register : The state

    Example

     lda #$01 ; Socket 1\njsr ch395_get_socket_status_sn\n; check A and X for the state\n
    "},{"location":"2024.1/assembly/#ch395_init","title":"ch395_init","text":"

    Description

    Initialize ch395

    Modify

    • Accumulator Description

    Reset ch395

    Example

     jsr ch395_init\n; Wait a bit\n
    "},{"location":"2024.1/assembly/#ch395_open_socket_sn","title":"ch395_open_socket_sn","text":"

    Description

    Open socket from arg

    Input

    • Accumulator : Socket id

    Modify

    • Y Register
    "},{"location":"2024.1/assembly/#ch395_read_recv_buf_sn","title":"ch395_read_recv_buf_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_reset_all","title":"ch395_reset_all","text":"

    Description

    Reset ch395

    Example

     jsr ch395_reset_all\n; Wait a bit\n
    "},{"location":"2024.1/assembly/#ch395_retran_period","title":"ch395_retran_period","text":"

    Description

    Retran period

    Input

    • Accumulator : Period
    • X Register : Period

    Modify

    • Y Register

    Example

     lda #$FF\nldx #$FF\njsr ch395_retran_period\nrts\n
    "},{"location":"2024.1/assembly/#ch395_set_des_port_sn","title":"ch395_set_des_port_sn","text":"

    Description

    Set dest port socket

    Input

    • Accumulator : Socketid
    • Y Register : Low int
    • X Register : high int

    Example

     lda #$01\nldx #80\nldx #$00\njsr ch395_set_des_port_sn\nrts\n
    "},{"location":"2024.1/assembly/#ch395_set_fun_para","title":"ch395_set_fun_para","text":"

    Description

    Set fun para

    Input

    • Accumulator : Value

    Modify

    • Y Register
    • Accumulator
    "},{"location":"2024.1/assembly/#ch395_set_gwip_addr","title":"ch395_set_gwip_addr","text":"

    Description

    Set gateway ip addr

    "},{"location":"2024.1/assembly/#ch395_set_ip_addr","title":"ch395_set_ip_addr","text":"

    Description

    Set ip row

    "},{"location":"2024.1/assembly/#ch395_set_ip_addr_sn","title":"ch395_set_ip_addr_sn","text":"

    Description

    Set Socket Ip address to connect with

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_set_ipraw_pro_sn","title":"ch395_set_ipraw_pro_sn","text":"

    Description

    Set ipraw protocol on socket

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_set_mac_adress","title":"ch395_set_mac_adress","text":"

    Description

    Set mac address

    "},{"location":"2024.1/assembly/#ch395_set_proto_type_sn","title":"ch395_set_proto_type_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_set_retran_count","title":"ch395_set_retran_count","text":"

    Description

    Set retran period

    Input

    • Accumulator : Retran period
    "},{"location":"2024.1/assembly/#ch395_set_sour_port_sn","title":"ch395_set_sour_port_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_tcp_connect_sn","title":"ch395_tcp_connect_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_tcp_disconnect_sn","title":"ch395_tcp_disconnect_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"2024.1/assembly/#ch395_tcp_listen_sn","title":"ch395_tcp_listen_sn","text":"

    Description

    TCP listen socket

    "},{"location":"2024.1/assembly/#ch395_write_send_buf_sn","title":"ch395_write_send_buf_sn","text":"

    Description

    Send data to socketid

    Input

    • Accumulator : Socket ID
    • Y Register : Low length
    • X Register : High length
    "},{"location":"2024.1/c/","title":"C","text":""},{"location":"2024.1/c/#c","title":"C","text":""},{"location":"2024.1/c/#unsigned-char-ch395_check_exist","title":"unsigned char ch395_check_exist();","text":"

    Description

    Checks if ch395 exists

    "},{"location":"2024.1/c/#void-ch395_clear_recv_buf_snunsigned-char-id_socket","title":"void ch395_clear_recv_buf_sn(unsigned char ID_SOCKET)","text":"

    Description

    Clear receive buffer

    "},{"location":"2024.1/c/#oid-ch395_close_socket_snunsigned-char-socketid","title":"oid ch395_close_socket_sn(unsigned char socketid)","text":"

    Description

    Close socket

    Input

    "},{"location":"2024.1/c/#unsigned-char-ch395_get_dhcp_status","title":"unsigned char ch395_get_dhcp_status();","text":"

    Description

    Get dhcp status

    "},{"location":"2024.1/c/#unsigned-int-ch395_get_glob_int_status","title":"unsigned int ch395_get_glob_int_status();","text":"

    Description

    Get General interrupt Status

    "},{"location":"2024.1/c/#unsigned-char-ch395_get_ic_ver","title":"unsigned char ch395_get_ic_ver();","text":"

    Description

    Get ch395 firmware version

    "},{"location":"2024.1/c/#unsigned-char-ch395_get_int_status_snunsigned-char-id_socket","title":"unsigned char ch395_get_int_status_sn(unsigned char ID_SOCKET);","text":"

    Description

    Check interrupt socket status

    Input

    "},{"location":"2024.1/c/#void-ch395_get_ip_infunsigned-char-ip_infos","title":"void ch395_get_ip_inf(unsigned char ip_infos[]);","text":"

    Description

    Get ip info

    "},{"location":"2024.1/c/#void-ch395_get_mac_adressunsigned-char-macaddress","title":"void ch395_get_mac_adress(unsigned char macaddress[]);","text":"

    Description

    Get mac address

    "},{"location":"2024.1/c/#unsigned-char-ch395_get_phy_status","title":"unsigned char ch395_get_phy_status();","text":"

    Description

    Get physical status

    "},{"location":"2024.1/c/#void-ch395_get_recv_len_snunsigned-char-id_socket","title":"void ch395_get_recv_len_sn(unsigned char ID_SOCKET)","text":"

    Description

    Get the length received from socket

    Input

    "},{"location":"2024.1/c/#void-ch395_get_remot_ipp_snunsigned-char-ptr-unsigned-char-socket","title":"void ch395_get_remot_ipp_sn(unsigned char *ptr, unsigned char socket);","text":"

    Description

    Get remote ip connected to the socket

    Input

    "},{"location":"2024.1/c/#unsigned-int-ch395_get_socket_status_snunsigned-char-id_socket","title":"unsigned int ch395_get_socket_status_sn(unsigned char ID_SOCKET);","text":"

    Description

    Returns in A socket status (close/open ... )

    Input

    "},{"location":"2024.1/c/#void-ch395_init","title":"void ch395_init();","text":"

    Description

    Initialize ch395

    "},{"location":"2024.1/c/#void-ch395_open_socket_snunsigned-char-id_socket","title":"void ch395_open_socket_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.1/c/#void-ch395_read_recv_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_read_recv_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"

    Input

    "},{"location":"2024.1/c/#void-ch395_reset_all","title":"void ch395_reset_all()","text":"

    Description

    Reset ch395

    "},{"location":"2024.1/c/#void-ch395_retran_periodunsigned-int-period","title":"void ch395_retran_period(unsigned int period);","text":"

    Description

    Retran period

    "},{"location":"2024.1/c/#void-ch395_set_des_port_snunsigned-int-port-unsigned-char-id_socket","title":"void ch395_set_des_port_sn(unsigned int port, unsigned char ID_SOCKET);","text":"

    Description

    Set dest port socket

    Input

    "},{"location":"2024.1/c/#void-ch395_set_fun_paraunsigned-char-flag","title":"void ch395_set_fun_para(unsigned char flag)","text":"

    Description

    Set fun para

    Description

    Set gateway ip addr

    Description

    Set ip addr

    "},{"location":"2024.1/c/#void-ch395_set_ip_addr_snunsigned-char-ip_addr-unsigned-char-id_socket","title":"void ch395_set_ip_addr_sn(unsigned char ip_addr[], unsigned char ID_SOCKET)","text":""},{"location":"2024.1/c/#void-ch395_set_ipraw_pro_snunsigned-char-id_socket","title":"void ch395_set_ipraw_pro_sn(unsigned char ID_SOCKET);","text":"

    Description

    Set ipraw protocol on socket

    Input

    "},{"location":"2024.1/c/#void-ch395_set_mac_adressunsigned-char-macaddress","title":"void ch395_set_mac_adress(unsigned char macaddress[]);","text":""},{"location":"2024.1/c/#void-ch395_set_proto_type_snunsigned-char-protounsigned-char-id_socket","title":"void ch395_set_proto_type_sn(unsigned char proto,unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.1/c/#void-ch395_set_retran_countunsigned-int-period","title":"void ch395_set_retran_count(unsigned int period);","text":"

    Description

    Set retran period

    "},{"location":"2024.1/c/#void-ch395_set_sour_port_snunsigned-int-portunsigned-char-id_socket","title":"void ch395_set_sour_port_sn(unsigned int port,unsigned char ID_SOCKET)","text":"

    Description

    Set source socket

    Input

    "},{"location":"2024.1/c/#void-ch395_tcp_connect_snunsigned-char-id_socket","title":"void ch395_tcp_connect_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.1/c/#void-ch395_tcp_disconnect_snunsigned-char-id_socket","title":"void ch395_tcp_disconnect_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.1/c/#void-ch395_tcp_listen_snunsigned-char-id_socket","title":"void ch395_tcp_listen_sn(unsigned char ID_SOCKET)","text":""},{"location":"2024.1/c/#void-ch395_write_send_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_write_send_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"

    Description

    Send data to socketid

    Input

    "},{"location":"2024.2/assembly/","title":"Assembly","text":""},{"location":"2024.2/assembly/#assembly","title":"Assembly","text":""},{"location":"2024.2/assembly/#ch395_check_exist","title":"ch395_check_exist","text":"

    Description

    This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.

    Modify

    • Accumulator

    Returns

    • Accumulator : Returns '#CH395_DETECTED' if it exists

    Example

     jsr ch395_check_exist\ncmp #CH395_DETECTED\nbeq ch395_connected\nrts\nch395_connected:\n
    "},{"location":"2024.2/assembly/#ch395_clear_recv_buf_sn","title":"ch395_clear_recv_buf_sn","text":"

    Description

    This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.

    Input

    • Accumulator : Socket id

    Modify

    • Accumulator
    • Y Register

    Example

     lda #CH395_SOCKET1 ; Socket ID\njsr ch395_clear_recv_buf_sn\n
    "},{"location":"2024.2/assembly/#ch395_close_socket_sn","title":"ch395_close_socket_sn","text":"

    Description

    This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.

    Input

    • Accumulator : The id of the socket to close

    Modify

    • Y Register

    Example

     lda #$01 ; Socket ID\njsr ch395_close_socket_sn\n
    "},{"location":"2024.2/assembly/#ch395_dhcp_enable","title":"ch395_dhcp_enable","text":"

    Description

    This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status

    Input

    • Accumulator : The mode to activate DHCP mode

    Modify

    • X Register
    "},{"location":"2024.2/assembly/#ch395_enter_sleep","title":"ch395_enter_sleep","text":"

    Description

    This command enables CH395 chip in a low-power sleep suspended state. When MCU writes a new command to CH395 (no data input command, such as CMD_GET_IC_VER), it will exit the low-power state. For the parallel port and SPI interface communication modes, active SCS chip selection will also cause CH395 to exit the low-power state, so MCU shall immediately disable the SCS chip selection after sending the command CMD_ENTER_SLEEP. In sleep state, MAC and PHY of CH395 will be in power off mode and disconnect Ethernet. Typically, it takes several milliseconds for CH395 to exit the low-power state.

    Does not work

    "},{"location":"2024.2/assembly/#ch395_get_cmd_status","title":"ch395_get_cmd_status","text":"

    Description

    This command is used to get the command execution status. CH395 will output 1 byte of data, which is the command execution state. The command execution status is as follows:

    Example

     jsr ch395_get_cmd_status\n; Check A for STATUS\nrts\n

    Modify

    • Accumulator
    "},{"location":"2024.2/assembly/#ch395_get_dhcp_status","title":"ch395_get_dhcp_status","text":"

    Description

    Get dhcp status

    Example

     jsr ch395_get_dhcp_status\n; Check A for dhcp status\nrts\n

    Modify

    • Accumulator
    "},{"location":"2024.2/assembly/#ch395_get_glob_int_status_all","title":"ch395_get_glob_int_status_all","text":"

    Description

    This command is used to get the global interrupt status. CH395 will output 2 bytes of global interrupt status after receiving this command. Global interrupt status is defined as follows:

    Does not work

    "},{"location":"2024.2/assembly/#ch395_get_glob_int_status","title":"ch395_get_glob_int_status","text":"

    Description

    This command is used to get the global interrupt status. CH395 will output 1 byte of global interrupt status after receiving this command. Global interrupt status is defined as follows:

    Bit Name Description

    7 GINT_STAT_SOCK3 Socket3 interrupt

    6 GINT_STAT_SOCK2 Socket2 interrupt

    5 GINT_STAT_SOCK1 Socket1 interrupt

    4 GINT_STAT_SOCK0 Socket0 interrupt

    3 GINT_STAT_DHCP DHCP interrupt

    2 GINT_STAT_PHY_CHANGE PHY status change interrupt

    1 GINT_STAT_IP_CONFLI IP conflict

    0 GINT_STAT_UNREACH Inaccessible interrupt

    \u2460 GINT_STAT_UNREACH: Inaccessible interrupt. When CH395 receives ICMP inaccessible interrupt

    message, it saves the IP address, port and protocol type of the inaccessible IP packet in the inaccessible

    information table, and then generates an interrupt. When the MCU receives the interrupt, it can send the

    command GET_UNREACH_IPPORT to get the inaccessible information.

    \u2461 GINT_STAT_IP_CONFLI: IP conflict interrupt. This interrupt is generated when CH395 detects that its

    IP address is the same as that of other network devices in the same network segment.

    \u2462 GINT_STAT_PHY_CHANGE: PHY change interrupt. This interrupt is generated when PHY connection

    of CH395 changes, for example, PHY state changes from the connected state to the disconnected state or

    from the disconnected state to the connected state. MCU can send GET_PHY_STATUS command to get

    the current PHY connection status.

    \u2463 GINT_STAT_DHCP: DHCP interrupt. If MCU enables DHCP function of CH395, CH395 will generate

    this interrupt. MCU can send the command CMD_GET_DHCP_STATUS to get the DHCP status. If the

    status is 0, it will indicate success; otherwise, it will indicate timeout failure.

    \u2464 GINT_STAT_SOCK0 - GINT_STAT_SOCK3: Socket interrupt. When there is an interrupt event in

    Socket, CH395 will generate this interrupt. MCU needs to send GET_INT_STATUS_SN to get the

    interrupt status of Socket. Please refer to GET_INT_STATUS_SN.

    When this command is completed, CH395 will set INT# pin to high level and clear the global interrupt

    status

    Modify

    • Accumulator

    Returns

    • Accumulator : Status

    Example

     jsr ch395_get_glob_int_status\n; check accumulator to get interrupts states\n
    "},{"location":"2024.2/assembly/#ch395_get_ic_ver","title":"ch395_get_ic_ver","text":"

    Description

    This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text

    Modify

    • Accumulator

    Returns

    • Accumulator : Version

    Example

     jsr ch395_get_ic_ver\n; Check A for version\nrts\n
    "},{"location":"2024.2/assembly/#ch395_get_int_status_sn","title":"ch395_get_int_status_sn","text":"

    Description

    This command is used to get the interrupt status of Socket. It is necessary to input 1 byte of Socket index value. After receiving this command, CH395 will output 1 byte of Socket interrupt code. The interrupt code bits are defined as follows:

    Input

    • Accumulator : Socket id

    Modify

    • Accumulator
    • X Register

    Returns

    • Accumulator : Status of selected socket

    Example

     lda #CH395_SOCKET1 ; Check socket 1\njsr ch395_get_int_status_sn\n; Check interrupt type\nand #CH395_SINT_STAT_SEND_OK\ncmp #CH395_SINT_STAT_SEND_OK\nbeq @send_ok\nrts\n
    "},{"location":"2024.2/assembly/#ch395_get_ip_inf","title":"ch395_get_ip_inf","text":"

    Description

    Get ip info

    Input

    • Accumulator : the ptr to modify (Ptr must be 20 bytes length)
    • X Register : the ptr to modify (Ptr must be 20 bytes length)

    Modify

    • Accumulator
    • X Register
    • Y Register
    • RESTmp value
    "},{"location":"2024.2/assembly/#ch395_get_mac_adress","title":"ch395_get_mac_adress","text":"

    Description

    Get mac address

    Input

    • Accumulator : the ptr
    • X Register : the ptr

    Modify

    • Accumulator
    • X Register
    • Y Register
    • RESTmp value

    Returns

    • Accumulator : the content of ptr modified

    • X Register : the content of ptr modified

    "},{"location":"2024.2/assembly/#ch395_get_phy_status","title":"ch395_get_phy_status","text":"

    Description

    This command is used to get PHY connection status. After receiving this command, CH395 will query the current PHY connection status and output 1-byte PHY connection status code: PHY is disconnected when the connection status code is 01H; PHY connection is 10M full duplex when the connection status code is 02H; PHY connection is 10M half duplex when the connection status code is 04H. PHY connection is 100M full duplex when the connection status code is 08H; PHY connection is 100M half duplex when the connection status code is 10H

    Modify

    • Accumulator

    Returns

    • Accumulator : The physical status

    Example

     jsr ch395_get_phy_status\n; Check A physical status\nrts\n
    "},{"location":"2024.2/assembly/#ch395_get_recv_len_sn","title":"ch395_get_recv_len_sn","text":"

    Description

    Get the length received from socket

    Input

    • Accumulator : Socket id

    Example

     lda #$01 ; Socket 1\njsr ch395_get_recv_len_sn\n; check A and X for length received\nch395_connected:\n

    Modify

    • Accumulator
    • X Register

    Returns

    • Accumulator : The length

    • X Register : The length

    "},{"location":"2024.2/assembly/#ch395_get_remot_ipp_sn","title":"ch395_get_remot_ipp_sn","text":"

    Description

    This command is used to get the remote IP address and port number. It is necessary to input 1 byte of Socket index value. CH395 will output 4 bytes of IP address and 2 bytes of port number (low bytes in front). After Socket works in TCP Server mode and the connection is established, MCU can get the remote IP address and port number through this command

    Input

    • Accumulator : The Socket for the ip to get
    • X Register : The ptr (high) to store the ip
    • Y Register : The ptr (low) to store the ip

    Modify

    • Accumulator
    • X Register
    • Y Register
    • RES

    Example

     lda #$01 ; Socket 1\nldx #<ip_dest\nldy #>ip_dest\njsr ch395_get_remot_ipp_sn\nrts\nipdest:\n.byte 192,168,0,1\n
    "},{"location":"2024.2/assembly/#ch395_get_socket_status_sn","title":"ch395_get_socket_status_sn","text":"

    Description

    This command is used to get Socket status. It is necessary to input a 1 byte of Socket index value. CH395 will output a 2-byte status code when receiving this command. The first status code is the status code of Socket. The status code of Socket is defined as follows:

    Input

    • Accumulator : Socket id

    Modify

    • X Register
    • Accumulator

    Returns

    • Accumulator : The status

    • X Register : The state

    Example

     lda #$01 ; Socket 1\njsr ch395_get_socket_status_sn\n; check A and X for the state\ncmp #CH395_SOCKET_CLOSED\nbeq @soclet is closed\n
    "},{"location":"2024.2/assembly/#ch395_get_unreach_ipport","title":"ch395_get_unreach_ipport","text":"

    Description

    This command is used to get an inaccessible IP, ports and protocol type. CH395 will generate an inaccessible interrupt when an inaccessible message is received. MCU can use this command to get inaccessible information. After receiving this command, CH395 will output 1 byte of inaccessible code, 1 byte of protocol type, 2 bytes of port number (low bytes in front), and 4 bytes of IP in turn. MCU can judge whether the protocol, port or IP is inaccessible according to the inaccessible codes. For inaccessible codes, refer to RFC792 (CH395INC.H defines four common inaccessible codes).

    Does not work

    "},{"location":"2024.2/assembly/#ch395_init","title":"ch395_init","text":"

    Description

    This command is used to initialize CH395, including initializing MAC, PHY and TCP/IP stack of CH395. Generally, it takes 350mS to execute the command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status.

    Modify

    • Accumulator Description

    Reset ch395

    Example

     jsr ch395_init\n; Wait a bit\n
    "},{"location":"2024.2/assembly/#ch395_open_socket_sn","title":"ch395_open_socket_sn","text":"

    Description

    This command is used to open Socket and use the necessary steps of Socket. It is necessary to input 1 byte of Socket index value. After sending this command, MCU shall send GET_CMD_STATUS to query the command execution status. After opening Socket in UDP, IPRAW or MACRAW mode and returning successfully, data transmission can be performed. Before this command is sent, necessary settings must be made for destination IP, protocol type, source port, destination port, etc. Please refer to 8.3 Application Reference Steps for detailed steps.

    Input

    • Accumulator : Socket id

    Modify

    • Y Register
    "},{"location":"2024.2/assembly/#ch395_read_recv_buf_sn","title":"ch395_read_recv_buf_sn","text":"

    Description

    This command is used to read data from Socket receive buffer. It is necessary to input 1 byte of Socket index value and 2 bytes of length (low bytes in front). CH395 will output several bytes of data stream based on the length value. In actual application, the command RECV_LEN_SN can be firstly sent to get the actual effective length of the current buffer. The length of the read data can be less than the actual effective length of the buffer, the unread data is still reserved in the receive buffer, and MCU can continue to read through this command. In MACRAW mode, the processing modes are different. In MACRAW mode, the receive buffer is a frame buffer, which can cache only 1 frame of Ethernet data. After CH395 processes the command READ_RECV_BUF_SN, Socket0 receive buffer will be cleared, so MCU shall read all valid data of the buffer at a time.

    Input

    • Accumulator : Socket id
    • Y Register : Length low
    • X Register : length high
    • RES : tr to fill

    Modify

    • RESBtmp value
    "},{"location":"2024.2/assembly/#ch395_reset_all","title":"ch395_reset_all","text":"

    Description

    This command enables CH395 to perform a hardware reset. Typically, hardware reset is completed within 50mS.

    Example

     jsr ch395_reset_all\n; Wait a bit\n
    "},{"location":"2024.2/assembly/#ch395_set_baudrate","title":"ch395_set_baudrate","text":"

    Description

    This command is used to set the baud rate of CH395 for serial communication. When CH395 works in serial communication mode, the default communication baud rate is set by the level combination of SDO, SDI and SCK pins (refer to Section 6.4 of this datasheet) after reset. When these pins are suspended, the baud rate is 9600bps by default. If MCU supports high communication speed, the serial communication baud rate can be dynamically regulated through this command. This command requires the input of three data, namely, baudrate coefficient 0, baud rate coefficient 1 and baud rate coefficient 2. The following table shows the corresponding relationship with baud rates.

    "},{"location":"2024.2/assembly/#ch395_set_des_port_sn","title":"ch395_set_des_port_sn","text":"

    Description

    This command is used to set the Socket destination port. It is necessary to input 1 byte of Socket index value and 2 bytes of destination port (the low bytes are in front). When Socket works in UDP or TCP Client mode, this value must be set.

    Input

    • Accumulator : Socketid
    • Y Register : Low int
    • X Register : high int

    Modify

    • REStmp

    Example

     lda #$01\nldy #80\nldx #$00\njsr ch395_set_des_port_sn\nrts\n
    "},{"location":"2024.2/assembly/#ch395_set_fun_para","title":"ch395_set_fun_para","text":"

    Description

    Set fun para

    Input

    • Accumulator : Value

    Modify

    • Y Register
    • Accumulator
    "},{"location":"2024.2/assembly/#ch395_set_gwip_addr","title":"ch395_set_gwip_addr","text":"

    Description

    This command is used to set the gateway address for CH395. It is necessary to input 4 bytes of IP address

    Does not work

    "},{"location":"2024.2/assembly/#ch395_set_ip_addr","title":"ch395_set_ip_addr","text":"

    Description

    This command is used to set IP address for CH395. It is necessary to input 4 bytes of IP address, with low bytes of IP in front. For all commands including IP input or output in this datasheet, IP low bytes are in front. This will not be explained below

    Does not work

    "},{"location":"2024.2/assembly/#ch395_set_ip_addr_sn","title":"ch395_set_ip_addr_sn","text":"

    Description

    This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent

    Input

    • Accumulator : Socket id
    • Y Register : low ptr ip
    • X Register : high ptr ip

    Modify

    • REStmp
    "},{"location":"2024.2/assembly/#ch395_set_ipraw_pro_sn","title":"ch395_set_ipraw_pro_sn","text":"

    Description

    Set ipraw protocol on socket

    Input

    • Accumulator : Socket id
    • X Register : the mode proto

    Modify

    • Y Register
    "},{"location":"2024.2/assembly/#ch395_set_mac_adress","title":"ch395_set_mac_adress","text":"

    Description

    This command is used to set MAC address for CH395. It is necessary to input 6 bytes of MAC, with low bytes of MAC address in front. CH395 chip will store MAC address in the internal EEPROM. It will take 100mS to execute this command.MAC address assigned by IEEE has been burned when CH395 chip is delivered. If it is not necessary, please do not set MAC address

    Input

    • Accumulator : Low ptr mac adress
    • X Register : High ptr mac adress

    Modify

    • Accumulator
    • Y Register
    • RESTmp
    "},{"location":"2024.2/assembly/#ch395_set_mac_filt","title":"ch395_set_mac_filt","text":"

    Does not work

    "},{"location":"2024.2/assembly/#ch395_set_mask_addr","title":"ch395_set_mask_addr","text":"

    Description

    This command is used to set the subnet mask for CH395. It is necessary to input 4 bytes of mask for this command. It is 255.255.255.0 by default and may not be set

    Does not work

    "},{"location":"2024.2/assembly/#ch395_set_phy","title":"ch395_set_phy","text":"

    Description

    This command is used to set Ethernet PHY connection mode of CH395. The connection mode is automated negotiation mode by default. This command needs to input 1 byte of data, which is the connection mode code: Disconnect PHY when the connection mode code is 01H; PHY is 10M full duplex when the connection mode code is 02H; PHY is 10M half duplex when the connection mode code is 04H; PHY is 100M full duplex when the connection mode code is 08H; PHY is 100M half duplex when the connection mode code is 10H; PHY is automated negotiation when the connection mode code is 20H. When CH395 receives this command, it will reset MAC and PHY and reconnect according to the newly set connection mode. If Ethernet is already connected, it will be disconnected and reconnected.

    Does not work

    "},{"location":"2024.2/assembly/#ch395_set_proto_type_sn","title":"ch395_set_proto_type_sn","text":"

    Description

    This command is used to set the working mode of Socket. It is necessary to input 1 byte of Socket index value and 1 byte of working mode. The working mode is defined as follows:

    Code Name Description

    03H PROTO_TYPE_TCP TCP mode

    02H PROTO_TYPE_UDP UDP mode

    01H PROTO_TYPE_MAC_RAW MAC original message mode

    00H PROTO_TYPE_IP_RAW IP original message mode

    This command must be executed before CMD_OPEN_SOCKET_SN. Refer to 8.3 Application Reference

    Steps for detailed steps.

    Input

    • Accumulator : Socket id
    • X Register : Proto mode

    Modify

    • Y Register tmp

    Example

     lda #$00 ; Socket\nldx #CH395_PROTO_TYPE_TCP\njsr ch395_set_proto_type_sn\n
    "},{"location":"2024.2/assembly/#ch395_set_retran_count","title":"ch395_set_retran_count","text":"

    Description

    This command is used to set the number of retries. It is necessary to input 1 byte of number of retries. The allowable maximum value is 20. If the input data is more than 20, it will be processed as 20. The default number of retries is 12, and retries are only valid in TCP mode.

    Input

    • Accumulator : Retran period

    Modify

    • X Register
    "},{"location":"2024.2/assembly/#ch395_set_retran_period","title":"ch395_set_retran_period","text":"

    Description

    This command is used to set the retry cycle. It is necessary to input 2 bytes of number of cycles of (with low bytes in front) in milliseconds. The allowable maximum value is 1000. The total retry time is N * M, N is the number of retries, and M is the retry cycle. The default retry cycle is 500MS and retries are only valid in TCP mode.

    Input

    • Accumulator : Period
    • X Register : Period

    Modify

    • Y Register

    Example

     lda #$FF\nldx #$FF\njsr ch395_retran_period\nrts\n
    "},{"location":"2024.2/assembly/#ch395_set_sour_port_sn","title":"ch395_set_sour_port_sn","text":"

    Description

    This command is used to set the source port of Socket. It is necessary to input 1 byte of Socket index value and 2 bytes of source port (low bytes in front). If two or more Sockets are in the same mode, the source port numbers must not be the same. For example, Socket 0 is in UDP mode, the source port number is 600, and Socket 1 is also in UDP mode. The source port number 600 cannot be used again, otherwise it may cause the0 opening failure.

    Input

    • Accumulator : Socket id
    • Y Register : Low port
    • X Register : High port

    Modify

    • RES
    "},{"location":"2024.2/assembly/#ch395_set_ttl","title":"ch395_set_ttl","text":"

    Description

    This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128

    Input

    • Accumulator : Socket ID
    • X Register : TTL value

    Modify

    • Y Register
    "},{"location":"2024.2/assembly/#ch395_tcp_connect_sn","title":"ch395_tcp_connect_sn","text":"

    Description

    Performs tcp connect

    Input

    • Accumulator : Socket id
    "},{"location":"2024.2/assembly/#ch395_tcp_disconnect_sn","title":"ch395_tcp_disconnect_sn","text":"

    Input

    • Accumulator : Socket id
    "},{"location":"2024.2/assembly/#ch395_tcp_listen_sn","title":"ch395_tcp_listen_sn","text":"

    Description

    This command is only valid in TCP mode, enabling the Socket to be in the monitoring mode, namely, TCP Server mode. It is necessary to input a 1 byte of Socket index value. This command must be executed after OPEN_SOCKET_SN. After sending this command, MCU shall send GET_CMD_STATUS to query the 0command execution status. In TCP Server mode, the Socket will always detect connection events, and the interrupt SINT_STAT_CONNECT will be generated until the connection is successful. Only one connection can be 0established for each Socket. If an eligible connection event is received again, Socket will send TCP RESET to the remote end tried to be connected.

    "},{"location":"2024.2/assembly/#ch395_write_send_buf_sn","title":"ch395_write_send_buf_sn","text":"

    Description

    This command is used to write data to Socket transmit buffer. It is necessary to input 1 byte of Socket index value, 2 bytes of length (low bytes in front) and several bytes of data stream. The length of input data must not be larger than the size of transmit buffer. However, in MACRAW mode, the maximum length of input data can only be 1514, and any redundant data will be discarded. After the external MCU writes the data, CH395 will encapsulate the data packet according to the working mode of Socket, and then send it. Before MCU receives SINT_STAT_SENBUF_FREE, it is not allowed to write data into Socket transmit buffer again

    Input

    • Accumulator : Socket ID
    • Y Register : Low length
    • X Register : High length
    • RESB : Adress ptr to read

    Modify

    • RESTmp

    Example

    "},{"location":"2024.2/c/","title":"C","text":""},{"location":"2024.2/c/#c","title":"C","text":""},{"location":"2024.2/c/#unsigned-char-ch395_check_exist","title":"unsigned char ch395_check_exist();","text":"

    Description

    This command is used to test the communication interface and working state to check whether CH395 is working properly. This command needs to input 1 byte of data, which can be any data. If CH395 is working properly, the output data of CH395 will be the bitwise reverse of the input data. For example, if the input data is 57H, the output data will be A8H.

    "},{"location":"2024.2/c/#void-ch395_clear_recv_buf_snunsigned-char-id_socket","title":"void ch395_clear_recv_buf_sn(unsigned char ID_SOCKET)","text":"

    Description

    This command is used to clear the Socket receive buffer. It is necessary to input 1 byte of Socket index value. Upon receiving this command, CH395 will reset the receiving length of this Socket, and the receiving pointer will point to the buffer head.

    "},{"location":"2024.2/c/#void-ch395_close_socket_snunsigned-char-socketid","title":"void ch395_close_socket_sn(unsigned char socketid)","text":"

    Description

    This command is used to close Socket. It is necessary to input a 1 byte of Socket index value. After Socket is closed, the receive buffer and transmit buffer of Socket are emptied, but the configuration information is still reserved, and you just need to open the Socket again when using the Socket the next time. In TCP mode, CH395 will automatically disconnect TCP before turning off Socket.

    Input

    "},{"location":"2024.2/c/#void-ch395_dhcp_enable","title":"void ch395_dhcp_enable()","text":"

    Description

    This command is used to start or stop DHCP. It is necessary to input a 1-byte flag. If the flag is 1, it will indicate that DHCP is on; if the flag is 0, it will indicate that DHCP is off. CH395 must be initialized before DHCP is started. After DHCP is started, CH395 will broadcast DHCPDISCOVER message to the network to discover DHCP Server, request the address and other configuration parameters after finding DHCP Server, and then generate GINT_STAT_DHCP interrupt. MCU can send GET_DHCP_STATUS command to get DHCP status. If the status code is 0, it will indicate success, and MCU can send the command GET_IP_INF to get IP, MASK and other information. If the status code is 1, it will indicate error, which is generally caused by timeout, for example, no DHCP Server is found. DHCP is always in a working state after startup unless it receives a DHCP shutdown command from MCU. During this process, if DHCP Server reassigns a configuration to CH395 and the configuration is different from the original configuration, CH395 will still generate an interrupt. After timeout interrupt is generated, if DHCP Server is not found, CH395 will continue to send DHCPDISCOVER message at an interval of about 16 seconds. It takes about 20MS to execute this command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status

    Description

    Get cmd status

    "},{"location":"2024.2/c/#unsigned-char-ch395_get_cmd_status","title":"unsigned char ch395_get_cmd_status();","text":""},{"location":"2024.2/c/#unsigned-char-ch395_get_dhcp_status","title":"unsigned char ch395_get_dhcp_status();","text":"

    Description

    Get dhcp status

    "},{"location":"2024.2/c/#unsigned-int-ch395_get_glob_int_status","title":"unsigned int ch395_get_glob_int_status();","text":"

    Description

    Get General interrupt Status

    "},{"location":"2024.2/c/#unsigned-char-ch395_get_ic_ver","title":"unsigned char ch395_get_ic_ver();","text":"

    Description

    This command is used to get the chip and firmware versions. 1 byte of data returned is the version number, the bit 7 is 0, the bit 6 is 1, and the bits 5-0 are the version number. If the returned value is 41H, remove bits 7 and 6, and the version number will be 01H. It is called chip version in this text

    ;;@inputA Socket id ;;@modifyA ;;@modifyX ;;@returnsA Status of selected socket ;;@ca65 ;;@` lda #CH395_SOCKET1 ; Check socket 1 ;;@` jsr ch395_get_int_status_sn ;;@` ; Check interrupt type ;;@` and #CH395_SINT_STAT_SEND_OK ;;@` cmp #CH395_SINT_STAT_SEND_OK ;;@` beq @send_ok ;;@` rts ;;@ ldx #CH395_GET_INT_STATUS_SN stx CH395_COMMAND_PORT sta CH395_DATA_PORT lda CH395_DATA_PORT rts endproc

    "},{"location":"2024.2/c/#unsigned-char-ch395_get_int_status_snunsigned-char-id_socket","title":"unsigned char ch395_get_int_status_sn(unsigned char ID_SOCKET);","text":"

    Description

    Check interrupt socket status

    Input

    "},{"location":"2024.2/c/#void-ch395_get_ip_infunsigned-char-ip_infos","title":"void ch395_get_ip_inf(unsigned char ip_infos[]);","text":"

    Description

    Get ip info : ip_infos must be 20 bytes length)

    "},{"location":"2024.2/c/#void-ch395_get_mac_adressunsigned-char-macaddress","title":"void ch395_get_mac_adress(unsigned char macaddress[]);","text":"

    Description

    Get mac address

    "},{"location":"2024.2/c/#unsigned-char-ch395_get_phy_status","title":"unsigned char ch395_get_phy_status();","text":"

    Description

    Get physical status

    "},{"location":"2024.2/c/#void-ch395_get_recv_len_snunsigned-char-id_socket","title":"void ch395_get_recv_len_sn(unsigned char ID_SOCKET)","text":"

    Description

    Get the length received from socket

    Input

    "},{"location":"2024.2/c/#void-ch395_get_remot_ipp_snunsigned-char-ptr-unsigned-char-socket","title":"void ch395_get_remot_ipp_sn(unsigned char *ptr, unsigned char socket);","text":"

    Description

    Get remote ip connected to the socket

    Input

    "},{"location":"2024.2/c/#unsigned-int-ch395_get_socket_status_snunsigned-char-id_socket","title":"unsigned int ch395_get_socket_status_sn(unsigned char ID_SOCKET);","text":"

    Description

    Returns in A socket status (close/open ... )

    Input

    "},{"location":"2024.2/c/#void-ch395_init","title":"void ch395_init();","text":"

    Description

    ;;@brief This command is used to initialize CH395, including initializing MAC, PHY and TCP/IP stack of CH395. Generally, it takes 350mS to execute the command. MCU can send GET_CMD_STATUS to query whether the execution has finished and the execution status.

    "},{"location":"2024.2/c/#void-ch395_open_socket_snunsigned-char-id_socket","title":"void ch395_open_socket_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.2/c/#void-ch395_read_recv_buf_snunsigned-char-buffer-unsigned-int-ptr2unsigned-char-id_socket","title":"void ch395_read_recv_buf_sn(unsigned char *buffer, unsigned int ptr2,unsigned char ID_SOCKET);","text":"

    Input

    "},{"location":"2024.2/c/#void-ch395_reset_all","title":"void ch395_reset_all()","text":"

    Description

    Reset ch395

    "},{"location":"2024.2/c/#void-ch395_set_des_port_snunsigned-int-port-unsigned-char-id_socket","title":"void ch395_set_des_port_sn(unsigned int port, unsigned char ID_SOCKET);","text":"

    Description

    Set dest port socket

    Input

    "},{"location":"2024.2/c/#void-ch395_set_fun_paraunsigned-char-flag","title":"void ch395_set_fun_para(unsigned char flag)","text":"

    Description

    Set fun para

    Description

    Set gateway ip addr

    Description

    This command is used to set the destination IP address of Socket. It is necessary to input 1 byte of Socket index value and 4 bytes of destination IP address. When Socket works in IPRAW, UDP, or TCP Client mode, 0the destination IP must be set before the command CMD_OPEN_SOCKET_SN is sent

    "},{"location":"2024.2/c/#void-ch395_set_ip_addr_snunsigned-char-ip_addr-unsigned-char-id_socket","title":"void ch395_set_ip_addr_sn(unsigned char ip_addr[], unsigned char ID_SOCKET)","text":""},{"location":"2024.2/c/#void-ch395_set_ipraw_pro_snunsigned-char-id_socket","title":"void ch395_set_ipraw_pro_sn(unsigned char ID_SOCKET);","text":"

    Description

    Set ipraw protocol on socket

    Input

    "},{"location":"2024.2/c/#void-ch395_set_mac_adressunsigned-char-macaddress","title":"void ch395_set_mac_adress(unsigned char macaddress[]);","text":""},{"location":"2024.2/c/#void-ch395_set_proto_type_snunsigned-char-proto-unsigned-char-id_socket","title":"void ch395_set_proto_type_sn(unsigned char proto, unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.2/c/#void-ch395_set_retran_countunsigned-int-period","title":"void ch395_set_retran_count(unsigned int period);","text":"

    Description

    Set retran period

    "},{"location":"2024.2/c/#void-ch395_retran_periodunsigned-int-period","title":"void ch395_retran_period(unsigned int period);","text":"

    Description

    Retran period

    "},{"location":"2024.2/c/#void-ch395_set_sour_port_snunsigned-int-portunsigned-char-id_socket","title":"void ch395_set_sour_port_sn(unsigned int port,unsigned char ID_SOCKET)","text":"

    Description

    Set source socket

    Input

    Description

    This command is used to set Socket TTL. It is necessary to input 1 byte of Socket index value and 1 byte of TTL value. It shall be set after the Socket is opened, and the maximum value is 128

    "},{"location":"2024.2/c/#ch395_set_ttlunsigned-char-id_socket-unsigned-char-ttl_value","title":"ch395_set_ttl(unsigned char ID_SOCKET, unsigned char ttl_value);","text":""},{"location":"2024.2/c/#void-ch395_tcp_connect_snunsigned-char-id_socket","title":"void ch395_tcp_connect_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.2/c/#void-ch395_tcp_disconnect_snunsigned-char-id_socket","title":"void ch395_tcp_disconnect_sn(unsigned char ID_SOCKET)","text":"

    Input

    "},{"location":"2024.2/c/#void-ch395_tcp_listen_snunsigned-char-id_socket","title":"void ch395_tcp_listen_sn(unsigned char ID_SOCKET)","text":""},{"location":"2024.2/c/#void-ch395_write_send_buf_snunsigned-char-buffer-unsigned-int-lengthunsigned-char-id_socket","title":"void ch395_write_send_buf_sn(unsigned char *buffer, unsigned int length,unsigned char ID_SOCKET);","text":"

    Description

    Send data to socketid [Not working]

    Input

    "}]} \ No newline at end of file diff --git a/docs/api/sitemap.xml.gz b/docs/api/sitemap.xml.gz index 894de6fe541a6b2287ce9788bb0567b18804fe18..8c86900c855e57166aa3bc507e6f2b44f33c88f3 100644 GIT binary patch delta 13 Ucmb=gXP58h;INx7I+48s02*!s!Tq02_@1`v3p{ diff --git a/docs/code/2024.2/assembly.md b/docs/code/2024.2/assembly.md index 8b62807..2648b71 100644 --- a/docs/code/2024.2/assembly.md +++ b/docs/code/2024.2/assembly.md @@ -618,7 +618,7 @@ This command is used to set the Socket destination port. It is necessary to inpu ```ca65 lda #$01 - ldx #80 + ldy #80 ldx #$00 jsr ch395_set_des_port_sn rts @@ -777,6 +777,20 @@ Steps for detailed steps. ***Input*** * Accumulator : Socket id +* X Register : Proto mode + +***Modify*** + +* Y Register tmp + +***Example*** + +```ca65 + lda #$00 ; Socket + ldx #CH395_PROTO_TYPE_TCP + jsr ch395_set_proto_type_sn +``` + --- @@ -835,8 +849,8 @@ This command is used to set the source port of Socket. It is necessary to input ***Input*** * Accumulator : Socket id -* Y Register : Low ptr address -* X Register : High ptr address +* Y Register : Low port +* X Register : High port ***Modify*** @@ -865,6 +879,10 @@ This command is used to set Socket TTL. It is necessary to input 1 byte of Socke ## ch395_tcp_connect_sn +***Description*** + +Performs tcp connect + ***Input*** * Accumulator : Socket id diff --git a/docs/code/assembly.md b/docs/code/assembly.md index 8b62807..2648b71 100644 --- a/docs/code/assembly.md +++ b/docs/code/assembly.md @@ -618,7 +618,7 @@ This command is used to set the Socket destination port. It is necessary to inpu ```ca65 lda #$01 - ldx #80 + ldy #80 ldx #$00 jsr ch395_set_des_port_sn rts @@ -777,6 +777,20 @@ Steps for detailed steps. ***Input*** * Accumulator : Socket id +* X Register : Proto mode + +***Modify*** + +* Y Register tmp + +***Example*** + +```ca65 + lda #$00 ; Socket + ldx #CH395_PROTO_TYPE_TCP + jsr ch395_set_proto_type_sn +``` + --- @@ -835,8 +849,8 @@ This command is used to set the source port of Socket. It is necessary to input ***Input*** * Accumulator : Socket id -* Y Register : Low ptr address -* X Register : High ptr address +* Y Register : Low port +* X Register : High port ***Modify*** @@ -865,6 +879,10 @@ This command is used to set Socket TTL. It is necessary to input 1 byte of Socke ## ch395_tcp_connect_sn +***Description*** + +Performs tcp connect + ***Input*** * Accumulator : Socket id