Initial commit: TXW82x FPV v2.7.0.7-42229 SDK + project sources
This commit is contained in:
23
sdk/lib/net/mqtt/kawaii/platform/txw/platform_memory.c
Normal file
23
sdk/lib/net/mqtt/kawaii/platform/txw/platform_memory.c
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-14 22:02:07
|
||||
* @LastEditTime: 2020-04-27 16:32:58
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#include "platform_memory.h"
|
||||
|
||||
void *platform_memory_alloc(size_t size)
|
||||
{
|
||||
return os_zalloc(size);
|
||||
}
|
||||
|
||||
void *platform_memory_calloc(size_t num, size_t size)
|
||||
{
|
||||
return os_calloc(num, size);
|
||||
}
|
||||
|
||||
void platform_memory_free(void *ptr)
|
||||
{
|
||||
os_free(ptr);
|
||||
}
|
||||
17
sdk/lib/net/mqtt/kawaii/platform/txw/platform_memory.h
Normal file
17
sdk/lib/net/mqtt/kawaii/platform/txw/platform_memory.h
Normal file
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-14 22:06:35
|
||||
* @LastEditTime: 2020-04-27 16:27:29
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#ifndef _PLATFORM_MEMORY_H_
|
||||
#define _PLATFORM_MEMORY_H_
|
||||
|
||||
#include "basic_include.h"
|
||||
|
||||
void *platform_memory_alloc(size_t size);
|
||||
void *platform_memory_calloc(size_t num, size_t size);
|
||||
void platform_memory_free(void *ptr);
|
||||
|
||||
#endif
|
||||
33
sdk/lib/net/mqtt/kawaii/platform/txw/platform_mutex.c
Normal file
33
sdk/lib/net/mqtt/kawaii/platform/txw/platform_mutex.c
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-15 18:27:19
|
||||
* @LastEditTime: 2020-04-27 22:22:27
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#include "platform_mutex.h"
|
||||
|
||||
int platform_mutex_init(platform_mutex_t* m)
|
||||
{
|
||||
return os_mutex_init(&m->lock);
|
||||
}
|
||||
|
||||
int platform_mutex_lock(platform_mutex_t* m)
|
||||
{
|
||||
return os_mutex_lock(&m->lock, osWaitForever);
|
||||
}
|
||||
|
||||
int platform_mutex_trylock(platform_mutex_t* m)
|
||||
{
|
||||
return os_mutex_lock(&m->lock, 0);
|
||||
}
|
||||
|
||||
int platform_mutex_unlock(platform_mutex_t* m)
|
||||
{
|
||||
return os_mutex_unlock(&m->lock);
|
||||
}
|
||||
|
||||
int platform_mutex_destroy(platform_mutex_t* m)
|
||||
{
|
||||
return os_mutex_del(&m->lock);
|
||||
}
|
||||
23
sdk/lib/net/mqtt/kawaii/platform/txw/platform_mutex.h
Normal file
23
sdk/lib/net/mqtt/kawaii/platform/txw/platform_mutex.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-15 18:31:33
|
||||
* @LastEditTime: 2020-04-27 17:04:46
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#ifndef _PLATFORM_MUTEX_H_
|
||||
#define _PLATFORM_MUTEX_H_
|
||||
|
||||
#include "basic_include.h"
|
||||
|
||||
typedef struct platform_mutex {
|
||||
struct os_mutex lock;
|
||||
} platform_mutex_t;
|
||||
|
||||
int platform_mutex_init(platform_mutex_t* m);
|
||||
int platform_mutex_lock(platform_mutex_t* m);
|
||||
int platform_mutex_trylock(platform_mutex_t* m);
|
||||
int platform_mutex_unlock(platform_mutex_t* m);
|
||||
int platform_mutex_destroy(platform_mutex_t* m);
|
||||
|
||||
#endif
|
||||
129
sdk/lib/net/mqtt/kawaii/platform/txw/platform_net_socket.c
Normal file
129
sdk/lib/net/mqtt/kawaii/platform/txw/platform_net_socket.c
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2020-01-10 23:45:59
|
||||
* @LastEditTime: 2020-06-05 17:13:00
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#include "platform_net_socket.h"
|
||||
#include "mqtt_error.h"
|
||||
|
||||
int platform_net_socket_connect(const char *host, const char *port, int proto)
|
||||
{
|
||||
int fd = -1;
|
||||
int ret = MQTT_SOCKET_UNKNOWN_HOST_ERROR;
|
||||
struct addrinfo hints, *addr_list, *cur;
|
||||
|
||||
/* Do name resolution with both IPv6 and IPv4 */
|
||||
os_memset(&hints, 0, sizeof(hints));
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_socktype = (proto == PLATFORM_NET_PROTO_UDP) ? SOCK_DGRAM : SOCK_STREAM;
|
||||
hints.ai_protocol = (proto == PLATFORM_NET_PROTO_UDP) ? IPPROTO_UDP : IPPROTO_TCP;
|
||||
|
||||
if (getaddrinfo(host, port, &hints, &addr_list) != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
for (cur = addr_list; cur != NULL; cur = cur->ai_next) {
|
||||
fd = socket(cur->ai_family, cur->ai_socktype, cur->ai_protocol);
|
||||
if (fd < 0) {
|
||||
ret = MQTT_SOCKET_FAILED_ERROR;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (connect(fd, cur->ai_addr, cur->ai_addrlen) == 0) {
|
||||
ret = fd;
|
||||
break;
|
||||
}
|
||||
|
||||
close(fd);
|
||||
ret = MQTT_CONNECT_FAILED_ERROR;
|
||||
}
|
||||
|
||||
freeaddrinfo(addr_list);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int platform_net_socket_recv(int fd, void *buf, size_t len, int flags)
|
||||
{
|
||||
return recv(fd, buf, len, flags);
|
||||
}
|
||||
|
||||
int platform_net_socket_recv_timeout(int fd, unsigned char *buf, int len, int timeout)
|
||||
{
|
||||
int nread;
|
||||
int nleft = len;
|
||||
unsigned char *ptr;
|
||||
ptr = buf;
|
||||
|
||||
struct timeval tv = {
|
||||
timeout / 1000,
|
||||
(timeout % 1000) * 1000
|
||||
};
|
||||
|
||||
if (tv.tv_sec < 0 || (tv.tv_sec == 0 && tv.tv_usec <= 0)) {
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 100;
|
||||
}
|
||||
|
||||
platform_net_socket_setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(struct timeval));
|
||||
|
||||
while (nleft > 0) {
|
||||
nread = platform_net_socket_recv(fd, ptr, nleft, 0);
|
||||
if (nread < 0) {
|
||||
return -1;
|
||||
} else if (nread == 0) {
|
||||
break;
|
||||
}
|
||||
|
||||
nleft -= nread;
|
||||
ptr += nread;
|
||||
}
|
||||
return len - nleft;
|
||||
}
|
||||
ssize_t write_check_tcp(int fd, const void* buf, size_t n)
|
||||
{
|
||||
return write(fd, buf, n);
|
||||
}
|
||||
|
||||
int platform_net_socket_write(int fd, void *buf, size_t len)
|
||||
{
|
||||
return write_check_tcp(fd, buf, len);
|
||||
}
|
||||
|
||||
int platform_net_socket_write_timeout(int fd, unsigned char *buf, int len, int timeout)
|
||||
{
|
||||
struct timeval tv = {
|
||||
timeout / 1000,
|
||||
(timeout % 1000) * 1000
|
||||
};
|
||||
|
||||
if (tv.tv_sec < 0 || (tv.tv_sec == 0 && tv.tv_usec <= 0)) {
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 100;
|
||||
}
|
||||
|
||||
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char *)&tv,sizeof(struct timeval));
|
||||
|
||||
return write_check_tcp(fd, buf, len);
|
||||
}
|
||||
|
||||
int platform_net_socket_close(int fd)
|
||||
{
|
||||
return close(fd);
|
||||
}
|
||||
|
||||
int platform_net_socket_set_block(int fd)
|
||||
{
|
||||
return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, F_GETFL) & ~O_NONBLOCK);
|
||||
}
|
||||
|
||||
int platform_net_socket_set_nonblock(int fd)
|
||||
{
|
||||
return fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, F_GETFL) | O_NONBLOCK);
|
||||
}
|
||||
|
||||
int platform_net_socket_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen)
|
||||
{
|
||||
return setsockopt(fd, level, optname, optval, optlen);
|
||||
}
|
||||
31
sdk/lib/net/mqtt/kawaii/platform/txw/platform_net_socket.h
Normal file
31
sdk/lib/net/mqtt/kawaii/platform/txw/platform_net_socket.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-15 13:39:00
|
||||
* @LastEditTime: 2020-04-27 23:46:54
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#ifndef _PLATFORM_NET_SOCKET_H_
|
||||
#define _PLATFORM_NET_SOCKET_H_
|
||||
|
||||
#include "basic_include.h"
|
||||
#include "lwip/opt.h"
|
||||
#include "lwip/sys.h"
|
||||
#include "lwip/api.h"
|
||||
#include "lwip/sockets.h"
|
||||
#include "lwip/netdb.h"
|
||||
|
||||
#define PLATFORM_NET_PROTO_TCP 0 /**< The TCP transport protocol */
|
||||
#define PLATFORM_NET_PROTO_UDP 1 /**< The UDP transport protocol */
|
||||
|
||||
int platform_net_socket_connect(const char *host, const char *port, int proto);
|
||||
int platform_net_socket_recv(int fd, void *buf, size_t len, int flags);
|
||||
int platform_net_socket_recv_timeout(int fd, unsigned char *buf, int len, int timeout);
|
||||
int platform_net_socket_write(int fd, void *buf, size_t len);
|
||||
int platform_net_socket_write_timeout(int fd, unsigned char *buf, int len, int timeout);
|
||||
int platform_net_socket_close(int fd);
|
||||
int platform_net_socket_set_block(int fd);
|
||||
int platform_net_socket_set_nonblock(int fd);
|
||||
int platform_net_socket_setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen);
|
||||
|
||||
#endif /* _PLATFORM_NET_SOCKET_H_ */
|
||||
78
sdk/lib/net/mqtt/kawaii/platform/txw/platform_thread.c
Normal file
78
sdk/lib/net/mqtt/kawaii/platform/txw/platform_thread.c
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-23 19:26:27
|
||||
* @LastEditTime: 2020-09-23 08:53:43
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#include "platform_thread.h"
|
||||
#include "platform_memory.h"
|
||||
|
||||
platform_thread_t *platform_thread_init( const char *name,
|
||||
void (*entry)(void *),
|
||||
void * const param,
|
||||
unsigned int stack_size,
|
||||
unsigned int priority,
|
||||
unsigned int tick)
|
||||
{
|
||||
platform_thread_t *thread = NULL;
|
||||
void *stack = NULL; //124 = sizeof(ktask_t)
|
||||
|
||||
thread = platform_memory_alloc(sizeof(platform_thread_t));
|
||||
if(thread == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
thread->task = (struct os_task *)platform_memory_alloc(sizeof(struct os_task));
|
||||
if (thread->task == NULL) {
|
||||
os_printf("[%s]:task malloc failed!!!\n",__FUNCTION__);
|
||||
platform_memory_free(thread->task);
|
||||
return NULL;
|
||||
}
|
||||
stack = platform_memory_alloc(stack_size+124);
|
||||
if (stack == NULL) {
|
||||
os_printf("[%s]:stack malloc failed!!!\n",__FUNCTION__);
|
||||
platform_memory_free(thread->task);
|
||||
platform_memory_free(thread);
|
||||
return NULL;
|
||||
}
|
||||
os_task_init((const uint8 *)name, thread->task, entry, (uint32)param);
|
||||
os_task_set_priority(thread->task, priority);
|
||||
os_task_set_stack(thread->task, stack, stack_size+124); //124 = sizeof(ktask_t)
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
void platform_thread_startup(platform_thread_t* thread)
|
||||
{
|
||||
if (thread && thread->task) {
|
||||
os_task_run(thread->task);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void platform_thread_stop(platform_thread_t* thread)
|
||||
{
|
||||
if (thread && thread->task) {
|
||||
os_task_suspend(thread->task);
|
||||
}
|
||||
}
|
||||
|
||||
void platform_thread_start(platform_thread_t* thread)
|
||||
{
|
||||
if (thread && thread->task) {
|
||||
os_task_resume(thread->task);
|
||||
}
|
||||
}
|
||||
|
||||
void platform_thread_destroy(platform_thread_t* thread)
|
||||
{
|
||||
if (thread && thread->task) {
|
||||
os_task_del(thread->task);
|
||||
if (thread->task->stack) {
|
||||
platform_memory_free(thread->task->stack);
|
||||
}
|
||||
platform_memory_free(thread->task);
|
||||
platform_memory_free(thread);
|
||||
}
|
||||
}
|
||||
28
sdk/lib/net/mqtt/kawaii/platform/txw/platform_thread.h
Normal file
28
sdk/lib/net/mqtt/kawaii/platform/txw/platform_thread.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-15 18:31:44
|
||||
* @LastEditTime: 2020-04-27 17:04:25
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#ifndef _PLATFORM_THREAD_H_
|
||||
#define _PLATFORM_THREAD_H_
|
||||
|
||||
#include "basic_include.h"
|
||||
|
||||
typedef struct platform_thread {
|
||||
struct os_task *task;
|
||||
} platform_thread_t;
|
||||
|
||||
platform_thread_t *platform_thread_init( const char *name,
|
||||
void (*entry)(void *),
|
||||
void * const param,
|
||||
unsigned int stack_size,
|
||||
unsigned int priority,
|
||||
unsigned int tick);
|
||||
void platform_thread_startup(platform_thread_t* thread);
|
||||
void platform_thread_stop(platform_thread_t* thread);
|
||||
void platform_thread_start(platform_thread_t* thread);
|
||||
void platform_thread_destroy(platform_thread_t* thread);
|
||||
|
||||
#endif
|
||||
62
sdk/lib/net/mqtt/kawaii/platform/txw/platform_timer.c
Normal file
62
sdk/lib/net/mqtt/kawaii/platform/txw/platform_timer.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-10 22:16:41
|
||||
* @LastEditTime: 2020-04-27 22:35:34
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
|
||||
#include "platform_timer.h"
|
||||
|
||||
static uint32_t platform_uptime_ms(void)
|
||||
{
|
||||
return os_jiffies_to_msecs(os_jiffies());
|
||||
}
|
||||
|
||||
void platform_timer_init(platform_timer_t* timer)
|
||||
{
|
||||
timer->time = 0;
|
||||
}
|
||||
|
||||
void platform_timer_cutdown(platform_timer_t* timer, unsigned int timeout)
|
||||
{
|
||||
timer->time = platform_uptime_ms();
|
||||
timer->time += timeout;
|
||||
}
|
||||
|
||||
char platform_timer_is_expired(platform_timer_t* timer)
|
||||
{
|
||||
return platform_uptime_ms() > timer->time ? 1 : 0;
|
||||
}
|
||||
|
||||
int platform_timer_remain(platform_timer_t* timer)
|
||||
{
|
||||
uint32_t now;
|
||||
|
||||
now = platform_uptime_ms();
|
||||
if (timer->time <= now) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return timer->time - now;
|
||||
}
|
||||
|
||||
unsigned long platform_timer_now(void)
|
||||
{
|
||||
return (unsigned long) platform_uptime_ms();
|
||||
}
|
||||
|
||||
void platform_timer_usleep(unsigned long usec)
|
||||
{
|
||||
|
||||
uint32_t tick= 0;
|
||||
|
||||
if (usec != 0) {
|
||||
tick = usec / 1000;
|
||||
|
||||
if (tick == 0)
|
||||
tick = 1;
|
||||
}
|
||||
|
||||
os_sleep_ms(tick);
|
||||
}
|
||||
24
sdk/lib/net/mqtt/kawaii/platform/txw/platform_timer.h
Normal file
24
sdk/lib/net/mqtt/kawaii/platform/txw/platform_timer.h
Normal file
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* @Author: jiejie
|
||||
* @Github: https://github.com/jiejieTop
|
||||
* @Date: 2019-12-10 22:18:32
|
||||
* @LastEditTime: 2020-04-27 17:15:58
|
||||
* @Description: the code belongs to jiejie, please keep the author information and source code according to the license.
|
||||
*/
|
||||
#ifndef _PLATFORM_TIMER_H_
|
||||
#define _PLATFORM_TIMER_H_
|
||||
|
||||
#include "basic_include.h"
|
||||
|
||||
typedef struct platform_timer {
|
||||
uint32_t time;
|
||||
} platform_timer_t;
|
||||
|
||||
void platform_timer_init(platform_timer_t* timer);
|
||||
void platform_timer_cutdown(platform_timer_t* timer, unsigned int timeout);
|
||||
char platform_timer_is_expired(platform_timer_t* timer);
|
||||
int platform_timer_remain(platform_timer_t* timer);
|
||||
unsigned long platform_timer_now(void);
|
||||
void platform_timer_usleep(unsigned long usec);
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user