-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
112 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
.include "ch395.inc" | ||
|
||
.export _ch395_retran_period | ||
.import ch395_retran_period | ||
.export _ch395_set_retran_period | ||
.import ch395_set_retran_period | ||
|
||
.proc _ch395_retran_period | ||
.proc _ch395_set_retran_period | ||
;;@proto void ch395_retran_period(unsigned int period); | ||
;;@brief Retran period | ||
;;@```c | ||
;;@` ch395_retran_period(1000); | ||
;;@` ch395_set_retran_period(1000); | ||
;;@``` | ||
jmp ch395_retran_period | ||
jmp ch395_set_retran_period | ||
.endproc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,93 @@ | ||
#include <stdio.h> | ||
#include "ch395.h" | ||
|
||
int dhcp_enable() { | ||
unsigned char val; | ||
unsigned int retry; | ||
|
||
ch395_dhcp_enable(CH395_DHCP_ENABLE_VAL); | ||
|
||
retry = 0; | ||
while (1) { | ||
val = ch395_get_glob_int_status(); | ||
printf("%d,",val); | ||
if ((val & CH395_GINT_STAT_DHCP) == CH395_GINT_STAT_DHCP) break; | ||
retry ++; | ||
printf("#"); | ||
if (retry == 29000) { | ||
printf("Unable to start dhcp"); | ||
return 4; | ||
} | ||
} | ||
|
||
printf("Dhcp started"); | ||
} | ||
|
||
int main() { | ||
unsigned int port = 80; | ||
unsigned int retry; | ||
unsigned char ip[]= { 54, 36, 50, 190 }; | ||
unsigned char val; | ||
unsigned char myip[20]; | ||
|
||
val = ch395_check_exist(); | ||
if (val == CH395_DETECTED) { | ||
val = ch395_get_ic_ver(); | ||
printf("Ch395 found ! Version : %d. Initialize chip ...\n", val); | ||
ch395_init(); | ||
} | ||
else { | ||
if (val != CH395_DETECTED) { | ||
printf("CH395 not found exiting ...\n"); | ||
return 1; | ||
} | ||
|
||
printf("IP : %d.%d.%d.%d\n",ip[0],ip[1],ip[2],ip[3]); | ||
val = ch395_get_ic_ver(); | ||
printf("Ch395 found ! Version : %d. Initialize chip ...\n", val); | ||
ch395_init(); | ||
retry = 0; | ||
while (1) { | ||
val = ch395_get_cmd_status(); | ||
if (val == 0) break; | ||
retry++; | ||
if (retry == 2000) { | ||
printf("Impossible to init ch395\n"); | ||
return 2; | ||
}; | ||
} | ||
|
||
printf("Initialized, checking cable\n"); | ||
|
||
retry = 0; | ||
while (1) { | ||
val = ch395_get_phy_status(); | ||
|
||
if ( val != CH395_PHY_DISCONN) | ||
break; | ||
retry ++; | ||
if (retry == 9000) { | ||
printf("Cable is disconnected\n"); | ||
return 3; | ||
}; | ||
} | ||
printf("Cable is connected, Starting dhcp\n"); | ||
|
||
val = ch395_get_dhcp_status(); | ||
if (val == CH395_DHCP_STATUS_ENABLED) | ||
printf("DHCP Already enabled\n"); | ||
else | ||
dhcp_enable(); | ||
|
||
|
||
ch395_get_ip_inf(myip); | ||
|
||
printf("My IP : %d.%d.%d.%d\n",myip[0],myip[1],myip[2],myip[3]); | ||
|
||
printf("IP dest : %d.%d.%d.%d:%d\n",ip[0],ip[1],ip[2],ip[3],port); | ||
|
||
ch395_set_proto_type_sn(CH395_PROTO_TYPE_TCP,0); | ||
|
||
ch395_set_ip_addr_sn(ip,0); | ||
ch395_set_des_port_sn(port,0); | ||
ch395_set_sour_port_sn(200,0) | ||
|
||
|
||
ch395_open_socket_sn(0); | ||
|
||
val = ch395_get_socket_status_sn(0); | ||
|
||
} | ||
} |