diff --git a/Example/Example_btb/Motherboard_Demo.7z b/Example/Example_btb/Motherboard_Demo.7z index 56660d9..395f2eb 100644 Binary files a/Example/Example_btb/Motherboard_Demo.7z and b/Example/Example_btb/Motherboard_Demo.7z differ diff --git a/Example/Example_btb/【必读】例程功能说明.xlsx b/Example/Example_btb/【必读】例程功能说明.xlsx index 0c32275..4c2f536 100644 Binary files a/Example/Example_btb/【必读】例程功能说明.xlsx and b/Example/Example_btb/【必读】例程功能说明.xlsx differ diff --git a/Example/Example_dual_camera/Motherboard_Demo.7z b/Example/Example_dual_camera/Motherboard_Demo.7z index dcfbd25..6629cdb 100644 Binary files a/Example/Example_dual_camera/Motherboard_Demo.7z and b/Example/Example_dual_camera/Motherboard_Demo.7z differ diff --git a/Example/Example_general/Motherboard_Demo.7z b/Example/Example_general/Motherboard_Demo.7z index e12f4f3..8daaf3a 100644 Binary files a/Example/Example_general/Motherboard_Demo.7z and b/Example/Example_general/Motherboard_Demo.7z differ diff --git a/Example/Example说明.txt b/Example/Example说明.txt index 7cd16d3..51d9362 100644 --- a/Example/Example说明.txt +++ b/Example/Example说明.txt @@ -1,3 +1,8 @@ Example_dual_camera // 双摄主板例程 Example_general //通用主板例程 -Example_btb //btb缩微主板例程 \ No newline at end of file +Example_btb //btb缩微主板例程 + +例程的主要作用只是告诉大家如何使用各种库函数 +因此例程内的库文件不一定是最新的,当通过库例程学习完之后 +请使用Seekfree_TC264_Opensource_Library开源库进行开发。 +开源库链接:https://gitee.com/seekfree/TC264_Library \ No newline at end of file diff --git a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/doc/version.txt b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/doc/version.txt index 1c4f7d4..f0dbfea 100644 --- a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/doc/version.txt +++ b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.4.4 + ޸printfضеĺ궨 + WIFI_SPI V3.4.3 ips200pro ޸zf_device_config.hļԶع⺯Ч diff --git a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_components/printf_redirect.c b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_components/printf_redirect.c index c44d826..299da76 100644 --- a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_components/printf_redirect.c +++ b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_components/printf_redirect.c @@ -45,7 +45,7 @@ //------------------------------------------------------------------------------------------------------------------- int fputc(int ch, FILE *stream) { - uart_write_byte(DEBUG_UART_INDEX, (char)ch); + uart_write_byte(PRINTF_USE_UART, (char)ch); return (ch); } @@ -71,7 +71,7 @@ int _write(int fd, char *buf, int len) int fgetc(FILE *f) { #if PRINTF_OUTPUT_TYPE == 0 - return uart_read_byte(DEBUG_UART_INDEX); + return uart_read_byte(PRINTF_USE_UART); #else uint8 buf; wifi_spi_read_buffer(&buf, 1); diff --git a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.c b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.c index b51c600..8e5a20d 100644 --- a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.c +++ b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.c @@ -24,7 +24,7 @@ * ļ zf_device_wifi_spi * ˾ ɶɿƼ޹˾ * 汾Ϣ 鿴 libraries/doc ļ version ļ 汾˵ -* ADS v1.9.20 +* ADS v1.10.2 * ƽ̨ TC264D * https://seekfree.taobao.com/ * @@ -63,6 +63,21 @@ #define SOCKET_CONNECT_TIME_OUT 50000 // λ #define OTHER_TIME_OUT 1000 // λ +#if ((WIFI_SPI_RECVIVE_SIZE < 32) || (WIFI_SPI_RECVIVE_SIZE > 4088)) + #error "WIFI_SPI_RECVIVE_SIZE must be >= 32 or <= 4088" +#endif + +#if (WIFI_SPI_RECVIVE_SIZE >= WIFI_SPI_RECVIVE_FIFO_SIZE) + #error "WIFI_SPI_RECVIVE_FIFO_SIZE must be > WIFI_SPI_RECVIVE_SIZE" +#endif + + +#if (WIFI_SPI_TRANSFER_SIZE != 4088) + #error "WIFI_SPI_TRANSFER_SIZE must be == 4088" +#endif + + + char wifi_spi_version[12]; // ģ̼汾Ϣ char wifi_spi_mac_addr[20]; // ģMACַϢ char wifi_spi_ip_addr_port[25]; // ģIPַ˿Ϣ @@ -271,8 +286,6 @@ static uint8 wifi_spi_get_version (void) { memcpy(wifi_spi_version, temp_packets.buffer, temp_packets.head.length); } - return_state = (return_state == 0) ? (WIFI_SPI_REPLY_VERSION != temp_packets.head.command) : 1; - return return_state; } @@ -293,8 +306,6 @@ static uint8 wifi_spi_get_mac_addr (void) { memcpy(wifi_spi_mac_addr, temp_packets.buffer, temp_packets.head.length); } - return_state = (return_state == 0) ? (WIFI_SPI_REPLY_MAC_ADDR != temp_packets.head.command) : 1; - return return_state; } @@ -316,7 +327,77 @@ static uint8 wifi_spi_get_ip_addr_port (void) { memcpy(wifi_spi_ip_addr_port, temp_packets.buffer, temp_packets.head.length); } - return_state = (return_state == 0) ? (WIFI_SPI_REPLY_IP_ADDR != temp_packets.head.command) : 1; + return return_state; +} + +//------------------------------------------------------------------------------------------------------------------- +// WIFI SPI ȡϵͳʱ +// ˵ time_format ʱʽ +// ز *buffer ʱַַ СҪ30ֽ +// ز buffer_size С +// ز uint8 ״̬ 0-ɹ 1- +// ʹʾ +// עϢ Ҫȵܻ֮ȡȷʱ䣬ڵ֮ǰҪȷWIFIģҪյѾȫ +// עϢ WIFI SPI ߰汾֧ +// עϢ ϢΪַϢֱprintfֲ鿴 +//------------------------------------------------------------------------------------------------------------------- +uint8 wifi_spi_get_time (wifi_spi_time_enum time_format, char *buffer, uint8 buffer_size) +{ + uint8 return_state = 1; + wifi_spi_packets_struct temp_packets; + uint8 send_cmd, receive_cmd; + + // ʱ30ֽ + // ģ̼V2汾 + if((30 <= buffer_size) && (!strncmp(wifi_spi_version, "V2", 2))) + { + send_cmd = WIFI_SPI_GET_TIME1 + time_format - WIFI_SPI_UTC_0; + receive_cmd = WIFI_SPI_REPLY_TIME1 + time_format - WIFI_SPI_UTC_0; + + return_state = wifi_spi_get_parameter(send_cmd, &temp_packets, OTHER_TIME_OUT); + if((0 == return_state) && (receive_cmd == temp_packets.head.command)) + { + return_state = (uint8)strncmp((const char *)temp_packets.buffer, "OK", 2); + if(0 == return_state) + { + memcpy(buffer, &temp_packets.buffer[3], temp_packets.head.length - 3); + buffer[temp_packets.head.length - 3] = 0; + } + } + } + return return_state; +} + +//------------------------------------------------------------------------------------------------------------------- +// WIFI SPI ɨȵ +// ˵ *buffer ɨ赽ȵϢ źǿȣÿźǿȺһз +// ˵ buffer_size ij +// ز uint8 ״̬ 0-ɹ 1- +// ʹʾ +// עϢ WIFI SPI ߰汾֧ +// עϢ ϢΪַϢֱprintfֲ鿴 +// עϢ ÿһаһwifi +//------------------------------------------------------------------------------------------------------------------- +uint8 wifi_spi_wifi_scan (char *buffer, uint16 buffer_size) +{ + uint8 return_state; + + // ģV2汾Ĺִ̼֧˹ + if(!strncmp(wifi_spi_version, "V2", 2)) + { + return_state = wifi_spi_set_parameter(WIFI_SPI_SET_WIFI_SCAN, NULL, 0, WIFI_CONNECT_TIME_OUT); + + if(0 == return_state) + { + #if (0 == WIFI_SPI_READ_TRANSFER) + wifi_spi_send_buffer(NULL, 0); + #endif + while(0 == wifi_spi_read_buffer((uint8 *)buffer, buffer_size)) + { + system_delay_ms(10); + } + } + } return return_state; } @@ -505,7 +586,7 @@ uint32 wifi_spi_send_buffer (const uint8 *buffer, uint32 length) while(length) { - send_length = length > WIFI_SPI_TRANSFER_SIZE ? (uint16)WIFI_SPI_TRANSFER_SIZE : (uint16)length; + send_length = (uint16) (length > WIFI_SPI_TRANSFER_SIZE ? WIFI_SPI_TRANSFER_SIZE : length); if(wifi_spi_wait_idle(OTHER_TIME_OUT)) { @@ -555,6 +636,18 @@ uint32 wifi_spi_send_buffer (const uint8 *buffer, uint32 length) return length; } +//------------------------------------------------------------------------------------------------------------------- +// WIFI SPI ַͺͬ +// ˵ *string Ҫ͵ַ +// ز void +// ʹʾ wifi_spi_send_string("123"); +// עϢ +//------------------------------------------------------------------------------------------------------------------- +void wifi_spi_send_string(const char *string) +{ + wifi_spi_send_buffer((uint8*)string, strlen(string)); +} + //------------------------------------------------------------------------------------------------------------------- // WIFI SPI ȡ // ˵ *buff ջ @@ -566,32 +659,57 @@ uint32 wifi_spi_send_buffer (const uint8 *buffer, uint32 length) uint32 wifi_spi_read_buffer (uint8 *buffer, uint32 length) { zf_assert(NULL != buffer); - uint32 data_len = length; + uint32 fifo_read_length; + uint32 write_length = 0; + wifi_spi_packets_struct temp_packets; + + // жFIFOǷݣȴFIFOȡ + if(fifo_used(&wifi_spi_fifo)) + { + fifo_read_length = fifo_used(&wifi_spi_fifo); + fifo_read_length = length < fifo_read_length ? length : fifo_read_length; + fifo_read_buffer(&wifi_spi_fifo, buffer, &fifo_read_length, FIFO_READ_AND_CLEAN); + + buffer += fifo_read_length; + length -= fifo_read_length; + write_length += fifo_read_length; + } #if(1 == WIFI_SPI_READ_TRANSFER) - - wifi_spi_packets_struct temp_packets; - // WIFI SPI״̬жϻ߳ѾͨѶ򱾴βܷ if(WIFI_SPI_IDLE == wifi_spi_mutex) { - // ͨѶ״̬Ϊæ - wifi_spi_mutex = WIFI_SPI_BUSY; + wifi_spi_mutex = WIFI_SPI_BUSY; // ͨѶ״̬Ϊæ - // ͨѶ鿴ģǷδȡ do { - if(wifi_spi_wait_idle(OTHER_TIME_OUT)) + if( (WIFI_SPI_RECVIVE_SIZE > wifi_spi_fifo.size) || // ռ䲻ٶȡ + (wifi_spi_wait_idle(OTHER_TIME_OUT)) // ʱ˳ + ) { break; } + temp_packets.head.command = WIFI_SPI_DATA; temp_packets.head.length = 0; wifi_spi_transfer_command(&temp_packets, WIFI_SPI_RECVIVE_SIZE); // յİǷ - if((WIFI_SPI_REPLY_DATA_START == temp_packets.head.command) || (WIFI_SPI_REPLY_DATA_END == temp_packets.head.command)) + if( ((WIFI_SPI_REPLY_DATA_START == temp_packets.head.command) || (WIFI_SPI_REPLY_DATA_END == temp_packets.head.command)) && + (temp_packets.head.length) + ) { - // յ - if(temp_packets.head.length) + if(length) + { + fifo_read_length = length >= temp_packets.head.length ? temp_packets.head.length : length; + memcpy(buffer, temp_packets.buffer, fifo_read_length); + buffer += fifo_read_length; + length -= fifo_read_length; + write_length += fifo_read_length; + if(fifo_read_length < temp_packets.head.length) // ⲿ岻ಿдFIFO + { + fifo_write_buffer(&wifi_spi_fifo, temp_packets.buffer + fifo_read_length, temp_packets.head.length - fifo_read_length); + } + } + else // ȫдFIFO { fifo_write_buffer(&wifi_spi_fifo, temp_packets.buffer, temp_packets.head.length); } @@ -599,10 +717,9 @@ uint32 wifi_spi_read_buffer (uint8 *buffer, uint32 length) }while(WIFI_SPI_REPLY_DATA_START == temp_packets.head.command); wifi_spi_mutex = WIFI_SPI_IDLE; } -#endif +#endif - fifo_read_buffer(&wifi_spi_fifo, buffer, &data_len, FIFO_READ_AND_CLEAN); - return data_len; + return write_length; } //------------------------------------------------------------------------------------------------------------------- @@ -618,7 +735,7 @@ uint8 wifi_spi_init (char *wifi_ssid, char *pass_word) uint8 return_state = 0; fifo_init(&wifi_spi_fifo, FIFO_DATA_8BIT, wifi_spi_buffer, WIFI_SPI_RECVIVE_FIFO_SIZE); - spi_init(WIFI_SPI_INDEX, SPI_MODE0, WIFI_SPI_SPEED, WIFI_SPI_SCK_PIN, WIFI_SPI_MOSI_PIN, WIFI_SPI_MISO_PIN, SPI_CS_NULL);//ӲSPIʼ + spi_init(WIFI_SPI_INDEX, SPI_MODE3, WIFI_SPI_SPEED, WIFI_SPI_SCK_PIN, WIFI_SPI_MOSI_PIN, WIFI_SPI_MISO_PIN, SPI_CS_NULL);//ӲSPIʼ gpio_init(WIFI_SPI_CS_PIN, GPO, 1, GPO_PUSH_PULL); gpio_init(WIFI_SPI_RST_PIN, GPO, 1, GPO_PUSH_PULL); gpio_init(WIFI_SPI_INT_PIN, GPI, 0, GPI_PULL_DOWN); @@ -644,7 +761,11 @@ uint8 wifi_spi_init (char *wifi_ssid, char *pass_word) // MACַϢַʽwifi_spi_mac_addr wifi_spi_get_mac_addr(); - + if(NULL == wifi_ssid) + { + // ʼʱҪWIFI + break; + } return_state = wifi_spi_wifi_connect(wifi_ssid, pass_word); if(return_state) { diff --git a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.h b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.h index b045ff7..cc7db18 100644 --- a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.h +++ b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_dual_camera_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.h @@ -55,7 +55,7 @@ #define WIFI_SPI_INDEX (SPI_3 ) // ʹõSPI -#define WIFI_SPI_SPEED (10 * 1000 * 1000 ) // Ӳ SPI +#define WIFI_SPI_SPEED (20 * 1000 * 1000 ) // Ӳ SPI #define WIFI_SPI_SCK_PIN (SPI3_SCLK_P22_3 ) // SPI_SCK #define WIFI_SPI_MOSI_PIN (SPI3_MOSI_P22_0 ) // SPI_MOSI #define WIFI_SPI_MISO_PIN (SPI3_MISO_P22_1 ) // SPI_MISO IPSûMISOţȻҪ壬spiijʼʱҪʹ @@ -84,6 +84,7 @@ + typedef enum { // ͵ @@ -95,10 +96,15 @@ typedef enum WIFI_SPI_SET_WIFI_INFORMATION = 0x10, // WIFIϢ WIFI_SPI_SET_SOCKET_INFORMATION = 0x11, // SOCKETϢ + WIFI_SPI_SET_WIFI_SCAN = 0x12, // ʼɨWIFI + WIFI_SPI_SET_READ_LENGTH = 0x13, // ȡ WIFI_SPI_GET_VERSION = 0x20, // ȡģ汾 WIFI_SPI_GET_MAC_ADDR = 0x21, // ȡģMACַ WIFI_SPI_GET_IP_ADDR = 0x22, // ȡģIPַ + WIFI_SPI_GET_TIME1 = 0x23, // ȡʱ ʽ1 + WIFI_SPI_GET_TIME2 = 0x24, // ȡʱ ʽ2 + WIFI_SPI_GET_TIME3 = 0x25, // ȡʱ ʽ3 // ӻش WIFI_SPI_REPLY_OK = 0x80, // ӻӦȷ @@ -110,6 +116,9 @@ typedef enum WIFI_SPI_REPLY_VERSION = 0xA0, // ӻظ̼汾 WIFI_SPI_REPLY_MAC_ADDR = 0xA1, // ӻظMACַϢ WIFI_SPI_REPLY_IP_ADDR = 0xA2, // ӻظIPַ˿ں + WIFI_SPI_REPLY_TIME1 = 0xA3, // ӻظʱ + WIFI_SPI_REPLY_TIME2 = 0xA4, // ӻظʱ + WIFI_SPI_REPLY_TIME3 = 0xA5, // ӻظʱ WIFI_SPI_INVALID2 = 0xFF // Чݰ }wifi_spi_packets_command_enum; @@ -134,19 +143,28 @@ typedef struct uint8 buffer[WIFI_SPI_RECVIVE_SIZE]; // }wifi_spi_packets_struct; - +typedef enum +{ + WIFI_SPI_UTC_0 = 1, // ʱ + WIFI_SPI_GMT, // ʱ תΪGMTʽ׺GMT һڶԽƶ˴ģʹ + WIFI_SPI_UTC_8, // ʱ +}wifi_spi_time_enum; + extern char wifi_spi_version[12]; // ̼汾 ַ extern char wifi_spi_mac_addr[20]; // ģMACַ ַ extern char wifi_spi_ip_addr_port[25]; // IPַ˿ں ַ -uint8 wifi_spi_wifi_connect (char *wifi_ssid, char *pass_word); -uint8 wifi_spi_socket_connect (char *transport_type, char *ip_addr, char *port, char *local_port); -uint8 wifi_spi_socket_disconnect (void); -uint8 wifi_spi_udp_send_now (void); -uint32 wifi_spi_send_buffer (const uint8 *buff, uint32 length); -uint32 wifi_spi_read_buffer (uint8 *buffer, uint32 length); +uint8 wifi_spi_get_time (wifi_spi_time_enum time_format, char *buffer, uint8 buffer_size); +uint8 wifi_spi_wifi_scan (char *buffer, uint16 buffer_size); +uint8 wifi_spi_wifi_connect (char *wifi_ssid, char *pass_word); +uint8 wifi_spi_socket_connect (char *transport_type, char *ip_addr, char *port, char *local_port); +uint8 wifi_spi_socket_disconnect (void); +uint8 wifi_spi_udp_send_now (void); +uint32 wifi_spi_send_buffer (const uint8 *buff, uint32 length); +void wifi_spi_send_string (const char *string); +uint32 wifi_spi_read_buffer (uint8 *buffer, uint32 length); -uint8 wifi_spi_init (char *wifi_ssid, char *pass_word); +uint8 wifi_spi_init (char *wifi_ssid, char *pass_word); #endif diff --git a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/doc/version.txt b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/doc/version.txt index 1e222a3..a31b325 100644 --- a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/doc/version.txt +++ b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/doc/version.txt @@ -1,3 +1,6 @@ +V3.4.2 + ޸printfضеĺ궨 + WIFI_SPI V3.4.1 ޸Ĵڷ麯еķ ޸ips200proע diff --git a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_components/printf_redirect.c b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_components/printf_redirect.c index c44d826..299da76 100644 --- a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_components/printf_redirect.c +++ b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_components/printf_redirect.c @@ -45,7 +45,7 @@ //------------------------------------------------------------------------------------------------------------------- int fputc(int ch, FILE *stream) { - uart_write_byte(DEBUG_UART_INDEX, (char)ch); + uart_write_byte(PRINTF_USE_UART, (char)ch); return (ch); } @@ -71,7 +71,7 @@ int _write(int fd, char *buf, int len) int fgetc(FILE *f) { #if PRINTF_OUTPUT_TYPE == 0 - return uart_read_byte(DEBUG_UART_INDEX); + return uart_read_byte(PRINTF_USE_UART); #else uint8 buf; wifi_spi_read_buffer(&buf, 1); diff --git a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.c b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.c index b51c600..8e5a20d 100644 --- a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.c +++ b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.c @@ -24,7 +24,7 @@ * ļ zf_device_wifi_spi * ˾ ɶɿƼ޹˾ * 汾Ϣ 鿴 libraries/doc ļ version ļ 汾˵ -* ADS v1.9.20 +* ADS v1.10.2 * ƽ̨ TC264D * https://seekfree.taobao.com/ * @@ -63,6 +63,21 @@ #define SOCKET_CONNECT_TIME_OUT 50000 // λ #define OTHER_TIME_OUT 1000 // λ +#if ((WIFI_SPI_RECVIVE_SIZE < 32) || (WIFI_SPI_RECVIVE_SIZE > 4088)) + #error "WIFI_SPI_RECVIVE_SIZE must be >= 32 or <= 4088" +#endif + +#if (WIFI_SPI_RECVIVE_SIZE >= WIFI_SPI_RECVIVE_FIFO_SIZE) + #error "WIFI_SPI_RECVIVE_FIFO_SIZE must be > WIFI_SPI_RECVIVE_SIZE" +#endif + + +#if (WIFI_SPI_TRANSFER_SIZE != 4088) + #error "WIFI_SPI_TRANSFER_SIZE must be == 4088" +#endif + + + char wifi_spi_version[12]; // ģ̼汾Ϣ char wifi_spi_mac_addr[20]; // ģMACַϢ char wifi_spi_ip_addr_port[25]; // ģIPַ˿Ϣ @@ -271,8 +286,6 @@ static uint8 wifi_spi_get_version (void) { memcpy(wifi_spi_version, temp_packets.buffer, temp_packets.head.length); } - return_state = (return_state == 0) ? (WIFI_SPI_REPLY_VERSION != temp_packets.head.command) : 1; - return return_state; } @@ -293,8 +306,6 @@ static uint8 wifi_spi_get_mac_addr (void) { memcpy(wifi_spi_mac_addr, temp_packets.buffer, temp_packets.head.length); } - return_state = (return_state == 0) ? (WIFI_SPI_REPLY_MAC_ADDR != temp_packets.head.command) : 1; - return return_state; } @@ -316,7 +327,77 @@ static uint8 wifi_spi_get_ip_addr_port (void) { memcpy(wifi_spi_ip_addr_port, temp_packets.buffer, temp_packets.head.length); } - return_state = (return_state == 0) ? (WIFI_SPI_REPLY_IP_ADDR != temp_packets.head.command) : 1; + return return_state; +} + +//------------------------------------------------------------------------------------------------------------------- +// WIFI SPI ȡϵͳʱ +// ˵ time_format ʱʽ +// ز *buffer ʱַַ СҪ30ֽ +// ز buffer_size С +// ز uint8 ״̬ 0-ɹ 1- +// ʹʾ +// עϢ Ҫȵܻ֮ȡȷʱ䣬ڵ֮ǰҪȷWIFIģҪյѾȫ +// עϢ WIFI SPI ߰汾֧ +// עϢ ϢΪַϢֱprintfֲ鿴 +//------------------------------------------------------------------------------------------------------------------- +uint8 wifi_spi_get_time (wifi_spi_time_enum time_format, char *buffer, uint8 buffer_size) +{ + uint8 return_state = 1; + wifi_spi_packets_struct temp_packets; + uint8 send_cmd, receive_cmd; + + // ʱ30ֽ + // ģ̼V2汾 + if((30 <= buffer_size) && (!strncmp(wifi_spi_version, "V2", 2))) + { + send_cmd = WIFI_SPI_GET_TIME1 + time_format - WIFI_SPI_UTC_0; + receive_cmd = WIFI_SPI_REPLY_TIME1 + time_format - WIFI_SPI_UTC_0; + + return_state = wifi_spi_get_parameter(send_cmd, &temp_packets, OTHER_TIME_OUT); + if((0 == return_state) && (receive_cmd == temp_packets.head.command)) + { + return_state = (uint8)strncmp((const char *)temp_packets.buffer, "OK", 2); + if(0 == return_state) + { + memcpy(buffer, &temp_packets.buffer[3], temp_packets.head.length - 3); + buffer[temp_packets.head.length - 3] = 0; + } + } + } + return return_state; +} + +//------------------------------------------------------------------------------------------------------------------- +// WIFI SPI ɨȵ +// ˵ *buffer ɨ赽ȵϢ źǿȣÿźǿȺһз +// ˵ buffer_size ij +// ز uint8 ״̬ 0-ɹ 1- +// ʹʾ +// עϢ WIFI SPI ߰汾֧ +// עϢ ϢΪַϢֱprintfֲ鿴 +// עϢ ÿһаһwifi +//------------------------------------------------------------------------------------------------------------------- +uint8 wifi_spi_wifi_scan (char *buffer, uint16 buffer_size) +{ + uint8 return_state; + + // ģV2汾Ĺִ̼֧˹ + if(!strncmp(wifi_spi_version, "V2", 2)) + { + return_state = wifi_spi_set_parameter(WIFI_SPI_SET_WIFI_SCAN, NULL, 0, WIFI_CONNECT_TIME_OUT); + + if(0 == return_state) + { + #if (0 == WIFI_SPI_READ_TRANSFER) + wifi_spi_send_buffer(NULL, 0); + #endif + while(0 == wifi_spi_read_buffer((uint8 *)buffer, buffer_size)) + { + system_delay_ms(10); + } + } + } return return_state; } @@ -505,7 +586,7 @@ uint32 wifi_spi_send_buffer (const uint8 *buffer, uint32 length) while(length) { - send_length = length > WIFI_SPI_TRANSFER_SIZE ? (uint16)WIFI_SPI_TRANSFER_SIZE : (uint16)length; + send_length = (uint16) (length > WIFI_SPI_TRANSFER_SIZE ? WIFI_SPI_TRANSFER_SIZE : length); if(wifi_spi_wait_idle(OTHER_TIME_OUT)) { @@ -555,6 +636,18 @@ uint32 wifi_spi_send_buffer (const uint8 *buffer, uint32 length) return length; } +//------------------------------------------------------------------------------------------------------------------- +// WIFI SPI ַͺͬ +// ˵ *string Ҫ͵ַ +// ز void +// ʹʾ wifi_spi_send_string("123"); +// עϢ +//------------------------------------------------------------------------------------------------------------------- +void wifi_spi_send_string(const char *string) +{ + wifi_spi_send_buffer((uint8*)string, strlen(string)); +} + //------------------------------------------------------------------------------------------------------------------- // WIFI SPI ȡ // ˵ *buff ջ @@ -566,32 +659,57 @@ uint32 wifi_spi_send_buffer (const uint8 *buffer, uint32 length) uint32 wifi_spi_read_buffer (uint8 *buffer, uint32 length) { zf_assert(NULL != buffer); - uint32 data_len = length; + uint32 fifo_read_length; + uint32 write_length = 0; + wifi_spi_packets_struct temp_packets; + + // жFIFOǷݣȴFIFOȡ + if(fifo_used(&wifi_spi_fifo)) + { + fifo_read_length = fifo_used(&wifi_spi_fifo); + fifo_read_length = length < fifo_read_length ? length : fifo_read_length; + fifo_read_buffer(&wifi_spi_fifo, buffer, &fifo_read_length, FIFO_READ_AND_CLEAN); + + buffer += fifo_read_length; + length -= fifo_read_length; + write_length += fifo_read_length; + } #if(1 == WIFI_SPI_READ_TRANSFER) - - wifi_spi_packets_struct temp_packets; - // WIFI SPI״̬жϻ߳ѾͨѶ򱾴βܷ if(WIFI_SPI_IDLE == wifi_spi_mutex) { - // ͨѶ״̬Ϊæ - wifi_spi_mutex = WIFI_SPI_BUSY; + wifi_spi_mutex = WIFI_SPI_BUSY; // ͨѶ״̬Ϊæ - // ͨѶ鿴ģǷδȡ do { - if(wifi_spi_wait_idle(OTHER_TIME_OUT)) + if( (WIFI_SPI_RECVIVE_SIZE > wifi_spi_fifo.size) || // ռ䲻ٶȡ + (wifi_spi_wait_idle(OTHER_TIME_OUT)) // ʱ˳ + ) { break; } + temp_packets.head.command = WIFI_SPI_DATA; temp_packets.head.length = 0; wifi_spi_transfer_command(&temp_packets, WIFI_SPI_RECVIVE_SIZE); // յİǷ - if((WIFI_SPI_REPLY_DATA_START == temp_packets.head.command) || (WIFI_SPI_REPLY_DATA_END == temp_packets.head.command)) + if( ((WIFI_SPI_REPLY_DATA_START == temp_packets.head.command) || (WIFI_SPI_REPLY_DATA_END == temp_packets.head.command)) && + (temp_packets.head.length) + ) { - // յ - if(temp_packets.head.length) + if(length) + { + fifo_read_length = length >= temp_packets.head.length ? temp_packets.head.length : length; + memcpy(buffer, temp_packets.buffer, fifo_read_length); + buffer += fifo_read_length; + length -= fifo_read_length; + write_length += fifo_read_length; + if(fifo_read_length < temp_packets.head.length) // ⲿ岻ಿдFIFO + { + fifo_write_buffer(&wifi_spi_fifo, temp_packets.buffer + fifo_read_length, temp_packets.head.length - fifo_read_length); + } + } + else // ȫдFIFO { fifo_write_buffer(&wifi_spi_fifo, temp_packets.buffer, temp_packets.head.length); } @@ -599,10 +717,9 @@ uint32 wifi_spi_read_buffer (uint8 *buffer, uint32 length) }while(WIFI_SPI_REPLY_DATA_START == temp_packets.head.command); wifi_spi_mutex = WIFI_SPI_IDLE; } -#endif +#endif - fifo_read_buffer(&wifi_spi_fifo, buffer, &data_len, FIFO_READ_AND_CLEAN); - return data_len; + return write_length; } //------------------------------------------------------------------------------------------------------------------- @@ -618,7 +735,7 @@ uint8 wifi_spi_init (char *wifi_ssid, char *pass_word) uint8 return_state = 0; fifo_init(&wifi_spi_fifo, FIFO_DATA_8BIT, wifi_spi_buffer, WIFI_SPI_RECVIVE_FIFO_SIZE); - spi_init(WIFI_SPI_INDEX, SPI_MODE0, WIFI_SPI_SPEED, WIFI_SPI_SCK_PIN, WIFI_SPI_MOSI_PIN, WIFI_SPI_MISO_PIN, SPI_CS_NULL);//ӲSPIʼ + spi_init(WIFI_SPI_INDEX, SPI_MODE3, WIFI_SPI_SPEED, WIFI_SPI_SCK_PIN, WIFI_SPI_MOSI_PIN, WIFI_SPI_MISO_PIN, SPI_CS_NULL);//ӲSPIʼ gpio_init(WIFI_SPI_CS_PIN, GPO, 1, GPO_PUSH_PULL); gpio_init(WIFI_SPI_RST_PIN, GPO, 1, GPO_PUSH_PULL); gpio_init(WIFI_SPI_INT_PIN, GPI, 0, GPI_PULL_DOWN); @@ -644,7 +761,11 @@ uint8 wifi_spi_init (char *wifi_ssid, char *pass_word) // MACַϢַʽwifi_spi_mac_addr wifi_spi_get_mac_addr(); - + if(NULL == wifi_ssid) + { + // ʼʱҪWIFI + break; + } return_state = wifi_spi_wifi_connect(wifi_ssid, pass_word); if(return_state) { diff --git a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.h b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.h index eea8a78..e0913bd 100644 --- a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.h +++ b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/libraries/zf_device/zf_device_wifi_spi.h @@ -95,10 +95,15 @@ typedef enum WIFI_SPI_SET_WIFI_INFORMATION = 0x10, // WIFIϢ WIFI_SPI_SET_SOCKET_INFORMATION = 0x11, // SOCKETϢ + WIFI_SPI_SET_WIFI_SCAN = 0x12, // ʼɨWIFI + WIFI_SPI_SET_READ_LENGTH = 0x13, // ȡ WIFI_SPI_GET_VERSION = 0x20, // ȡģ汾 WIFI_SPI_GET_MAC_ADDR = 0x21, // ȡģMACַ WIFI_SPI_GET_IP_ADDR = 0x22, // ȡģIPַ + WIFI_SPI_GET_TIME1 = 0x23, // ȡʱ ʽ1 + WIFI_SPI_GET_TIME2 = 0x24, // ȡʱ ʽ2 + WIFI_SPI_GET_TIME3 = 0x25, // ȡʱ ʽ3 // ӻش WIFI_SPI_REPLY_OK = 0x80, // ӻӦȷ @@ -110,6 +115,9 @@ typedef enum WIFI_SPI_REPLY_VERSION = 0xA0, // ӻظ̼汾 WIFI_SPI_REPLY_MAC_ADDR = 0xA1, // ӻظMACַϢ WIFI_SPI_REPLY_IP_ADDR = 0xA2, // ӻظIPַ˿ں + WIFI_SPI_REPLY_TIME1 = 0xA3, // ӻظʱ + WIFI_SPI_REPLY_TIME2 = 0xA4, // ӻظʱ + WIFI_SPI_REPLY_TIME3 = 0xA5, // ӻظʱ WIFI_SPI_INVALID2 = 0xFF // Чݰ }wifi_spi_packets_command_enum; @@ -134,19 +142,27 @@ typedef struct uint8 buffer[WIFI_SPI_RECVIVE_SIZE]; // }wifi_spi_packets_struct; - +typedef enum +{ + WIFI_SPI_UTC_0 = 1, // ʱ + WIFI_SPI_GMT, // ʱ תΪGMTʽ׺GMT һڶԽƶ˴ģʹ + WIFI_SPI_UTC_8, // ʱ +}wifi_spi_time_enum; + extern char wifi_spi_version[12]; // ̼汾 ַ extern char wifi_spi_mac_addr[20]; // ģMACַ ַ extern char wifi_spi_ip_addr_port[25]; // IPַ˿ں ַ -uint8 wifi_spi_wifi_connect (char *wifi_ssid, char *pass_word); -uint8 wifi_spi_socket_connect (char *transport_type, char *ip_addr, char *port, char *local_port); -uint8 wifi_spi_socket_disconnect (void); -uint8 wifi_spi_udp_send_now (void); -uint32 wifi_spi_send_buffer (const uint8 *buff, uint32 length); -uint32 wifi_spi_read_buffer (uint8 *buffer, uint32 length); +uint8 wifi_spi_get_time (wifi_spi_time_enum time_format, char *buffer, uint8 buffer_size); +uint8 wifi_spi_wifi_scan (char *buffer, uint16 buffer_size); +uint8 wifi_spi_wifi_connect (char *wifi_ssid, char *pass_word); +uint8 wifi_spi_socket_connect (char *transport_type, char *ip_addr, char *port, char *local_port); +uint8 wifi_spi_socket_disconnect (void); +uint8 wifi_spi_udp_send_now (void); +uint32 wifi_spi_send_buffer (const uint8 *buff, uint32 length); +void wifi_spi_send_string (const char *string); +uint32 wifi_spi_read_buffer (uint8 *buffer, uint32 length); -uint8 wifi_spi_init (char *wifi_ssid, char *pass_word); +uint8 wifi_spi_init (char *wifi_ssid, char *pass_word); #endif - diff --git a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/user/cpu0_main.c b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/user/cpu0_main.c index 38b466d..322fe70 100644 --- a/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/user/cpu0_main.c +++ b/Seekfree_TC264_Opensource_Library/Seekfree_TC264_general_Opensource_Library/Seekfree_TC264_Opensource_Library/user/cpu0_main.c @@ -49,7 +49,6 @@ int core0_main(void) - // ˴дû ʼ cpu_wait_event_ready(); // ȴкijʼ while (TRUE)