moved all third-party lib to separate folder

This commit is contained in:
2021-02-27 19:32:58 +01:00
committed by Robin Mueller
parent 264191415f
commit fa81b06bea
138 changed files with 22 additions and 2 deletions

View File

@ -0,0 +1,33 @@
/*
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdint.h>
#include <csp/arch/csp_malloc.h>
/* FreeRTOS includes */
#include <FreeRTOS.h>
void * csp_malloc(size_t size) {
return pvPortMalloc(size);
}
void csp_free(void *ptr) {
vPortFree(ptr);
}

View File

@ -0,0 +1,66 @@
/*
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdint.h>
/* FreeRTOS includes */
#include <FreeRTOS.h>
#include <queue.h>
/* CSP includes */
#include <csp/csp.h>
#include <csp/arch/csp_queue.h>
csp_queue_handle_t csp_queue_create(int length, size_t item_size) {
return xQueueCreate(length, item_size);
}
void csp_queue_remove(csp_queue_handle_t queue) {
vQueueDelete(queue);
}
int csp_queue_enqueue(csp_queue_handle_t handle, void * value, uint32_t timeout) {
if (timeout != CSP_MAX_DELAY)
timeout = timeout / portTICK_RATE_MS;
return xQueueSendToBack(handle, value, timeout);
}
int csp_queue_enqueue_isr(csp_queue_handle_t handle, void * value, CSP_BASE_TYPE * task_woken) {
return xQueueSendToBackFromISR(handle, value, task_woken);
}
int csp_queue_dequeue(csp_queue_handle_t handle, void * buf, uint32_t timeout) {
if (timeout != CSP_MAX_DELAY)
timeout = timeout / portTICK_RATE_MS;
return xQueueReceive(handle, buf, timeout);
}
int csp_queue_dequeue_isr(csp_queue_handle_t handle, void * buf, CSP_BASE_TYPE * task_woken) {
return xQueueReceiveFromISR(handle, buf, task_woken);
}
int csp_queue_size(csp_queue_handle_t handle) {
return uxQueueMessagesWaiting(handle);
}
int csp_queue_size_isr(csp_queue_handle_t handle) {
return uxQueueMessagesWaitingFromISR(handle);
}

View File

@ -0,0 +1,96 @@
/*
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdint.h>
/* FreeRTOS includes */
#include <FreeRTOS.h>
#include <semphr.h>
/* CSP includes */
#include <csp/csp.h>
#include <csp/arch/csp_malloc.h>
#include <csp/arch/csp_semaphore.h>
#include <csp/arch/csp_queue.h>
int csp_mutex_create(csp_mutex_t * mutex) {
*mutex = xSemaphoreCreateMutex();
if (*mutex) {
return CSP_SEMAPHORE_OK;
} else {
return CSP_SEMAPHORE_ERROR;
}
}
int csp_mutex_remove(csp_mutex_t * mutex) {
return csp_bin_sem_remove(mutex);
}
int csp_mutex_lock(csp_mutex_t * mutex, uint32_t timeout) {
return csp_bin_sem_wait(mutex, timeout);
}
int csp_mutex_unlock(csp_mutex_t * mutex) {
return csp_bin_sem_post(mutex);
}
int csp_bin_sem_create(csp_bin_sem_handle_t * sem) {
vSemaphoreCreateBinary(*sem);
return CSP_SEMAPHORE_OK;
}
int csp_bin_sem_remove(csp_bin_sem_handle_t * sem) {
if ((sem != NULL) && (*sem != NULL)) {
csp_queue_remove(*sem);
}
return CSP_SEMAPHORE_OK;
}
int csp_bin_sem_wait(csp_bin_sem_handle_t * sem, uint32_t timeout) {
csp_log_lock("Wait: %p", sem);
if (timeout != CSP_MAX_DELAY)
timeout = timeout / portTICK_RATE_MS;
if (xSemaphoreTake(*sem, timeout) == pdPASS) {
return CSP_SEMAPHORE_OK;
} else {
return CSP_SEMAPHORE_ERROR;
}
}
int csp_bin_sem_post(csp_bin_sem_handle_t * sem) {
csp_log_lock("Post: %p", sem);
if (xSemaphoreGive(*sem) == pdPASS) {
return CSP_SEMAPHORE_OK;
} else {
return CSP_SEMAPHORE_ERROR;
}
}
int csp_bin_sem_post_isr(csp_bin_sem_handle_t * sem, CSP_BASE_TYPE * task_woken) {
csp_log_lock("Post: %p", sem);
if (xSemaphoreGiveFromISR(*sem, task_woken) == pdPASS) {
return CSP_SEMAPHORE_OK;
} else {
return CSP_SEMAPHORE_ERROR;
}
}

View File

@ -0,0 +1,139 @@
/*
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdio.h>
#include <stdint.h>
#include <FreeRTOS.h>
#include <task.h>
#include <csp/csp.h>
#include <csp/csp_error.h>
#include <csp/arch/csp_system.h>
int csp_sys_tasklist(char * out) {
#if (tskKERNEL_VERSION_MAJOR < 8)
vTaskList((signed portCHAR *) out);
#else
vTaskList(out);
#endif
return CSP_ERR_NONE;
}
int csp_sys_tasklist_size(void) {
return 40 * uxTaskGetNumberOfTasks();
}
uint32_t csp_sys_memfree(void) {
uint32_t total = 0, max = UINT32_MAX, size;
void * pmem;
/* If size_t is less than 32 bits, start with 10 KiB */
size = sizeof(uint32_t) > sizeof(size_t) ? 10000 : 1000000;
while (1) {
pmem = pvPortMalloc(size + total);
if (pmem == NULL) {
max = size + total;
size = size / 2;
} else {
total += size;
if (total + size >= max)
size = size / 2;
vPortFree(pmem);
}
if (size < 32) break;
}
return total;
}
int csp_sys_reboot(void) {
extern void __attribute__((weak)) cpu_set_reset_cause(unsigned int);
if (cpu_set_reset_cause)
cpu_set_reset_cause(1);
extern void __attribute__((weak)) cpu_reset(void);
if (cpu_reset) {
cpu_reset();
while (1);
}
csp_log_error("Failed to reboot");
return CSP_ERR_INVAL;
}
int csp_sys_shutdown(void) {
extern void __attribute__((weak)) cpu_shutdown(void);
if (cpu_shutdown) {
cpu_shutdown();
while (1);
}
csp_log_error("Failed to shutdown");
return CSP_ERR_INVAL;
}
void csp_sys_set_color(csp_color_t color) {
unsigned int color_code, modifier_code;
switch (color & COLOR_MASK_COLOR) {
case COLOR_BLACK:
color_code = 30; break;
case COLOR_RED:
color_code = 31; break;
case COLOR_GREEN:
color_code = 32; break;
case COLOR_YELLOW:
color_code = 33; break;
case COLOR_BLUE:
color_code = 34; break;
case COLOR_MAGENTA:
color_code = 35; break;
case COLOR_CYAN:
color_code = 36; break;
case COLOR_WHITE:
color_code = 37; break;
case COLOR_RESET:
default:
color_code = 0; break;
}
switch (color & COLOR_MASK_MODIFIER) {
case COLOR_BOLD:
modifier_code = 1; break;
case COLOR_UNDERLINE:
modifier_code = 2; break;
case COLOR_BLINK:
modifier_code = 3; break;
case COLOR_HIDE:
modifier_code = 4; break;
case COLOR_NORMAL:
default:
modifier_code = 0; break;
}
printf("\033[%u;%um", modifier_code, color_code);
}

View File

@ -0,0 +1,38 @@
/*
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <FreeRTOS.h>
#include <task.h>
/* CSP includes */
#include <csp/csp.h>
#include <csp/arch/csp_thread.h>
int csp_thread_create(csp_thread_return_t (* routine)(void *), const char * const thread_name, unsigned short stack_depth, void * parameters, unsigned int priority, csp_thread_handle_t * handle) {
#if (tskKERNEL_VERSION_MAJOR >= 8)
portBASE_TYPE ret = xTaskCreate(routine, thread_name, stack_depth, parameters, priority, handle);
#else
portBASE_TYPE ret = xTaskCreate(routine, (signed char *) thread_name, stack_depth, parameters, priority, handle);
#endif
if (ret != pdTRUE)
return CSP_ERR_NOMEM;
return CSP_ERR_NONE;
}

View File

@ -0,0 +1,46 @@
/*
Cubesat Space Protocol - A small network-layer protocol designed for Cubesats
Copyright (C) 2012 Gomspace ApS (http://www.gomspace.com)
Copyright (C) 2012 AAUSAT3 Project (http://aausat3.space.aau.dk)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <stdint.h>
/* FreeRTOS includes */
#include <FreeRTOS.h>
#include <task.h>
/* CSP includes */
#include <csp/csp.h>
#include <csp/arch/csp_time.h>
uint32_t csp_get_ms(void) {
return (uint32_t)(xTaskGetTickCount() * (1000/configTICK_RATE_HZ));
}
uint32_t csp_get_ms_isr(void) {
return (uint32_t)(xTaskGetTickCountFromISR() * (1000/configTICK_RATE_HZ));
}
uint32_t csp_get_s(void) {
return (uint32_t)(xTaskGetTickCount()/configTICK_RATE_HZ);
}
uint32_t csp_get_s_isr(void) {
return (uint32_t)(xTaskGetTickCountFromISR()/configTICK_RATE_HZ);
}