Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jedeoric committed Apr 12, 2024
1 parent 75050ea commit 36ca102
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 38 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ $(OBJECTS8): $(SOURCES8)

test:
$(CC) -ttelestrat -I src/include test/ch395.c target/telestrat/lib/ch395-8.lib -o ch395
cl65 -ttelestrat -I src/include test/getstate.c target/telestrat/lib/ch395-8.lib -o getstate

tool:
@mkdir -p target/telestrat/ch395cfg/
$(CC) -ttelestrat -I src/include tools/ch395cfg/src/main.c target/telestrat/lib/ch395-8.lib -o target/telestrat/ch395cfg/ch395cfg
#$(CC) -ttelestrat -I src/include tools/ch395cfg/src/telnetd.c target/telestrat/lib/ch395-8.lib -o target/telestrat/ch395cfg/telnetd
$(CC) -ttelestrat -I src/include tools/ch395cfg/src/wget.c target/telestrat/lib/ch395-8.lib -o target/telestrat/ch395cfg/wget


docs:
docs/builddocs.sh && cd docs && mkdocs build

Expand Down
62 changes: 31 additions & 31 deletions src/6502/ch395_get_int_status_sn.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@
.proc ch395_get_int_status_sn
;;@brief 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:
;;Bit Name Description
;;7 - Reserved
;;6 SINT_STAT_TIM_OUT Timeout
;;5 - Reserved
;;4 SINT_STAT_DISCONNECT TCP disconnected
;;3 SINT_STAT_CONNECT TCP connected
;;2 SINT_STAT_RECV Receive buffer not empty
;;1 SINT_STAT_SEND_OK Send Success
;;0 SINT_STAT_SENBUF_FREE Transmit buffer free
;;① SINT_STAT_SENBUF_FREE, transmit buffer free interrupt. After MCU writes data to the transmit
;;buffer of Socket, CH395 will quickly copy the data to the internal protocol stack or MAC buffer, in order
;;to encapsulate the data. When the data copying is finished, this interrupt will be generated. MCU can
;;continue to write the subsequent data to the transmit buffer. After MCU writes data to the transmit buffer
;;of Socket once, it must write the next data until the interruption is generated.
;;② SINT_STAT_SEND_OK, send OK interrupt. This interrupt indicates that the data packet is sent
;;successfully. This interrupt will be generated after Sokcet sends a packet of data successfully. After MCU
;;writes data to Socket buffer once, CH395 may encapsulate the data into several data packets for sending,
;;so several send OK interrupts may be generated.
;;③ SINT_STAT_CONNECT, TCP linkage interrupt, active only in TCP mode. It indicates that TCP
;;connection is successful, and MCU can transmit data only after the interrupt is generated.
;;④ SINT_STAT_DISCONNECT, TCP disconnection interrupt, only active in TCP mode, indicating TCP
;;disconnection.
;;⑤ SINT_STAT_TIM_OUT. This interrupt will be generated in TCP mode when a timeout occurs during a
;;TCP connection, disconnection, data sending and other processes. This interrupt will be generated if the
;;data is not sent successfully in IPRAW or UDP mode.
;;After the interrupts SINT_STAT_DISCONNECT and SINT_STAT_TIM_OUT are generated, CH395 takes
;;different actions depending on whether the FUN_PARA_FLAG_SOCKET_CLOSE bit is 1 or 0. If
;;FUN_PARA_FLAG_SOCKET_CLOSE is 0, CH395 will actively set the Socket state to the OFF state and
;;clear all relevant buffers after the above two interrupts are generated. Otherwise, it will not do any operation
;;on the Socket status and the relevant buffer, so as to facilitate the external MCU to read the residual data
;;after TCP is disconnected or timed out. When the external MCU reads the data, it must send a close
;;command to close the Socket
;;@explain A7 - Reserved
;;@explain 6 SINT_STAT_TIM_OUT Timeout
;;@explain 5 - Reserved
;;@explain 4 SINT_STAT_DISCONNECT TCP disconnected
;;@explain 3 SINT_STAT_CONNECT TCP connected
;;@explain 2 SINT_STAT_RECV Receive buffer not empty
;;@explain 1 SINT_STAT_SEND_OK Send Success
;;@explain 0 SINT_STAT_SENBUF_FREE Transmit buffer free
;;@explain ① SINT_STAT_SENBUF_FREE, transmit buffer free interrupt. After MCU writes data to the transmit
;;@explain buffer of Socket, CH395 will quickly copy the data to the internal protocol stack or MAC buffer, in order
;;@explain to encapsulate the data. When the data copying is finished, this interrupt will be generated. MCU can
;;@explain continue to write the subsequent data to the transmit buffer. After MCU writes data to the transmit buffer
;;@explain of Socket once, it must write the next data until the interruption is generated.
;;@explain ② SINT_STAT_SEND_OK, send OK interrupt. This interrupt indicates that the data packet is sent
;;@explain successfully. This interrupt will be generated after Sokcet sends a packet of data successfully. After MCU
;;@explain writes data to Socket buffer once, CH395 may encapsulate the data into several data packets for sending,
;;@explain so several send OK interrupts may be generated.
;;@explain ③ SINT_STAT_CONNECT, TCP linkage interrupt, active only in TCP mode. It indicates that TCP
;;@explain connection is successful, and MCU can transmit data only after the interrupt is generated.
;;@explain ④ SINT_STAT_DISCONNECT, TCP disconnection interrupt, only active in TCP mode, indicating TCP
;;@explain disconnection.
;;@explain ⑤ SINT_STAT_TIM_OUT. This interrupt will be generated in TCP mode when a timeout occurs during a
;;@explain TCP connection, disconnection, data sending and other processes. This interrupt will be generated if the
;;@explain data is not sent successfully in IPRAW or UDP mode.
;;@explain After the interrupts SINT_STAT_DISCONNECT and SINT_STAT_TIM_OUT are generated, CH395 takes
;;@explain different actions depending on whether the FUN_PARA_FLAG_SOCKET_CLOSE bit is 1 or 0. If
;;@explain FUN_PARA_FLAG_SOCKET_CLOSE is 0, CH395 will actively set the Socket state to the OFF state and
;;@explain clear all relevant buffers after the above two interrupts are generated. Otherwise, it will not do any operation
;;@explainon the Socket status and the relevant buffer, so as to facilitate the external MCU to read the residual data
;;@explainafter TCP is disconnected or timed out. When the external MCU reads the data, it must send a close
;;@explain command to close the Socket
;;
;;@inputA Socket id
;;@modifyA
Expand Down
13 changes: 6 additions & 7 deletions src/6502/ch395_write_send_buf_sn.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
;;@inputA Socket ID
;;@inputY Low length
;;@inputX High length
;;@inputMEM Ptr of the data to send
;;@inputMEM_RESB Adress ptr to read
;;@modifyMEM_RES Tmp
;;@```ca65
;;@sta RESB ; Ptr low to write
;;@sty RESB+1 ; ptr high to write
;;@sta RES ; Ptr low to write
;;@sty RES+1 ; ptr high to write
;;@ldy #<1000 ; Low length
;;@ldx #>1000 ; High length
;;@lda #$00 ; socket 0
Expand All @@ -21,7 +22,7 @@
;;@```

sty RESB ; Save low length
stx RESB+1 ; Save low length
stx RESB+1 ; Save high length

; A contains Socket

Expand All @@ -35,7 +36,7 @@ entry_point_c:
stx CH395_DATA_PORT ; set length high


lda RESB
ldx RESB+1
beq @decrement

@restart:
Expand All @@ -57,15 +58,13 @@ entry_point_c:
sta RES

@decrement:
ldx RESB+1
ldx #$00
ldy #$00

@L1:
lda (RES),y
sta CH395_DATA_PORT
iny
bne @L1
inc RES+1
dex
bpl @L1

Expand Down
96 changes: 96 additions & 0 deletions test/getstate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
#include <stdio.h>
#include "ch395.h"
#include <conio.h>


void display_state(){
unsigned char socket;
int valax;
unsigned char socket_state;
unsigned char socket_tcp_state;
for (socket=0;socket<8;socket ++)
{
printf("Socket %d: ",socket);
valax = ch395_get_socket_status_sn(socket);
socket_state = (unsigned char)(valax & 0xFF);
socket_tcp_state = (unsigned char)(valax >> 8);
if (socket_state == CH395_SOCKET_OPEN) {
printf("Opened");
}
if (socket_state== CH395_SOCKET_CLOSED) {
printf("Closed");
}
switch(socket_tcp_state){
case CH395_TCP_CLOSED:
printf(" TCP_CLOSED");
break;
case CH395_TCP_LISTEN:
printf(" TCP_LISTEN");
break;
case CH395_TCP_SYN_SENT:
printf(" TCP_SYN_SENT");
break;
case CH395_TCP_SYN_REVD:
printf(" TCP_SYN_REVD");
break;
case CH395_TCP_ESTABLISHED:
printf(" TCP_ESTABLISHED");
break;
case CH395_TCP_FIN_WAIT_1:
printf(" TCP_FIN_WAIT_1");
break;
case CH395_TCP_FIN_WAIT_2:
printf(" TCP_FIN_WAIT_2");
break;
case CH395_TCP_CLOSE_WAIT:
printf(" CLOSE_WAIT");
break;
case CH395_TCP_CLOSING:
printf(" TCP_CLOSING");
break;
case CH395_TCP_LAST_ACK:
printf(" LAST_ACK");
break;
case CH395_TCP_TIME_WAIT:
printf(" TCP_TIME_WAIT");
break;
}

printf("\n");
}
}

void menu(){
puts("r Refresh");
puts("c Close socket");
puts("q Quit");
}

int main() {

unsigned char key;
display_state();
menu();
while(1) {
key = cgetc();
if (key == 'r') {
display_state();
menu();
}
if (key == 'q') return 0;
if (key == 'c') {
printf("Id if the socket : ");
key = cgetc();
key = key - 0x30;
printf("Choice %d : \n",key);
printf("Closing socket %d\n", key);
ch395_close_socket_sn(key);
display_state();
menu();

}
}



}

0 comments on commit 36ca102

Please sign in to comment.