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,18 @@
This directory contains files specific to the windows port of libcsp.
To compile and create a static library, execute:
python waf configure --with-os=windows build
from the root of this project. Note python must be in PATH.
The build requirements are:
* Windows Vista SP1
* A recent version of MinGW _or_ MinGW-w64
* Windows API headers
* cPython 2.5 or newer
What provides the Windows API headers depends on the development environment:
Using MinGW: Headers provided by w32api package. windows_glue.h header is needed because these headers do not declare condition variables.
Using MinGW-w64: Headers should be available in the default configuration. You may have to compile the distribution from source. windows_glue.h should not be needed.

View File

@ -0,0 +1,9 @@
#include <stdlib.h>
void * csp_malloc(size_t size) {
return malloc(size);
}
void csp_free(void * ptr) {
free(ptr);
}

View File

@ -0,0 +1,40 @@
#include <stdint.h>
#include <csp/csp.h>
#include <csp/arch/csp_queue.h>
#include "windows_queue.h"
csp_queue_handle_t csp_queue_create(int length, size_t item_size) {
return windows_queue_create(length, item_size);
}
void csp_queue_remove(csp_queue_handle_t queue) {
windows_queue_delete(queue);
}
int csp_queue_enqueue(csp_queue_handle_t handle, void *value, uint32_t timeout) {
return windows_queue_enqueue(handle, value, timeout);
}
int csp_queue_enqueue_isr(csp_queue_handle_t handle, void * value, CSP_BASE_TYPE * task_woken) {
if( task_woken != NULL )
*task_woken = 0;
return windows_queue_enqueue(handle, value, 0);
}
int csp_queue_dequeue(csp_queue_handle_t handle, void *buf, uint32_t timeout) {
return windows_queue_dequeue(handle, buf, timeout);
}
int csp_queue_dequeue_isr(csp_queue_handle_t handle, void * buf, CSP_BASE_TYPE * task_woken) {
if( task_woken != NULL )
*task_woken = 0;
return windows_queue_dequeue(handle, buf, 0);
}
int csp_queue_size(csp_queue_handle_t handle) {
return windows_queue_items(handle);
}
int csp_queue_size_isr(csp_queue_handle_t handle) {
return windows_queue_items(handle);
}

View File

@ -0,0 +1,74 @@
#include <Windows.h>
#include <csp/csp.h>
#include <csp/arch/csp_semaphore.h>
int csp_mutex_create(csp_mutex_t * mutex) {
HANDLE mutexHandle = CreateMutex(NULL, FALSE, FALSE);
if( mutexHandle == NULL ) {
return CSP_MUTEX_ERROR;
}
*mutex = mutexHandle;
return CSP_MUTEX_OK;
}
int csp_mutex_remove(csp_mutex_t * mutex) {
if( !CloseHandle(*mutex) ) {
return CSP_MUTEX_ERROR;
}
return CSP_MUTEX_OK;
}
int csp_mutex_lock(csp_mutex_t * mutex, uint32_t timeout) {
if(WaitForSingleObject(*mutex, timeout) == WAIT_OBJECT_0) {
return CSP_MUTEX_OK;
}
return CSP_MUTEX_ERROR;
}
int csp_mutex_unlock(csp_mutex_t * mutex) {
if( !ReleaseMutex(*mutex) ) {
return CSP_MUTEX_ERROR;
}
return CSP_MUTEX_OK;
}
int csp_bin_sem_create(csp_bin_sem_handle_t * sem) {
HANDLE semHandle = CreateSemaphore(NULL, 1, 1, NULL);
if( semHandle == NULL ) {
return CSP_SEMAPHORE_ERROR;
}
*sem = semHandle;
return CSP_SEMAPHORE_OK;
}
int csp_bin_sem_remove(csp_bin_sem_handle_t * sem) {
if( !CloseHandle(*sem) ) {
return CSP_SEMAPHORE_ERROR;
}
return CSP_SEMAPHORE_OK;
}
int csp_bin_sem_wait(csp_bin_sem_handle_t * sem, uint32_t timeout) {
if( WaitForSingleObject(*sem, timeout) == WAIT_OBJECT_0 ) {
return CSP_SEMAPHORE_OK;
}
return CSP_SEMAPHORE_ERROR;
}
int csp_bin_sem_post(csp_bin_sem_handle_t * sem) {
if( !ReleaseSemaphore(*sem, 1, NULL) ) {
return CSP_SEMAPHORE_ERROR;
}
return CSP_SEMAPHORE_OK;
}
int csp_bin_sem_post_isr(csp_bin_sem_handle_t * sem, CSP_BASE_TYPE * task_woken) {
if( task_woken != NULL ) {
*task_woken = 0;
}
return csp_bin_sem_post(sem);
}

View File

@ -0,0 +1,60 @@
/*
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 <string.h>
#include <Windows.h>
#include <csp/csp.h>
#include <csp/csp_error.h>
#include <csp/arch/csp_system.h>
int csp_sys_tasklist(char * out) {
strcpy(out, "Tasklist not available on Windows");
return CSP_ERR_NONE;
}
uint32_t csp_sys_memfree(void) {
MEMORYSTATUSEX statex;
statex.dwLength = sizeof(statex);
GlobalMemoryStatusEx(&statex);
DWORDLONG freePhysicalMem = statex.ullAvailPhys;
size_t total = (size_t) freePhysicalMem;
return (uint32_t)total;
}
int csp_sys_reboot(void) {
/* TODO: Fix reboot on Windows */
csp_log_error("Failed to reboot");
return CSP_ERR_INVAL;
}
int csp_sys_shutdown(void) {
/* TODO: Fix shutdown on Windows */
csp_log_error("Failed to shutdown");
return CSP_ERR_INVAL;
}
void csp_sys_set_color(csp_color_t color) {
/* TODO: Add Windows color output here */
}

View File

@ -0,0 +1,11 @@
#include <Windows.h>
#include <process.h>
#include <csp/arch/csp_thread.h>
int csp_thread_create(csp_thread_return_t (* routine)(void *)__attribute__((stdcall)), const char * const thread_name, unsigned short stack_depth, void * parameters, unsigned int priority, csp_thread_handle_t * handle) {
HANDLE taskHandle = (HANDLE) _beginthreadex(NULL, stack_depth, routine, parameters, 0, 0);
if( taskHandle == 0 )
return CSP_ERR_NOMEM; // Failure
*handle = taskHandle;
return CSP_ERR_NONE;
}

View File

@ -0,0 +1,20 @@
#include <Windows.h>
#include <stdint.h>
#include <csp/arch/csp_time.h>
uint32_t csp_get_ms(void) {
return (uint32_t)GetTickCount();
}
uint32_t csp_get_ms_isr(void) {
return csp_get_ms();
}
uint32_t csp_get_s(void) {
uint32_t time_ms = csp_get_ms();
return time_ms/1000;
}
uint32_t csp_get_s_isr(void) {
return csp_get_s();
}

View File

@ -0,0 +1,23 @@
#ifndef WINDOWS_GLUE_H
#define WINDOWS_GLUE_H
#include <Windows.h>
#undef interface
#if (_WIN32_WINNT >= 0x0600)
#define RTL_CONDITION_VARIABLE_INIT 0
#define RTL_CONDITION_VARIABLE_LOCKMODE_SHARED 1
#define CONDITION_VARIABLE_INIT RTL_CONDITION_VARIABLE_INIT
#define CONDITION_VARIABLE_LOCKMODE_SHARED RTL_CONDITION_VARIABLE_LOCKMODE_SHARED
typedef PVOID RTL_CONDITION_VARIABLE;
typedef RTL_CONDITION_VARIABLE CONDITION_VARIABLE, *PCONDITION_VARIABLE;
WINBASEAPI VOID WINAPI InitializeConditionVariable(PCONDITION_VARIABLE ConditionVariable);
WINBASEAPI WINBOOL WINAPI SleepConditionVariableCS(PCONDITION_VARIABLE ConditionVariable, PCRITICAL_SECTION CriticalSection, DWORD dwMilliseconds);
WINBASEAPI VOID WINAPI WakeAllConditionVariable(PCONDITION_VARIABLE ConditionVariable);
WINBASEAPI VOID WINAPI WakeConditionVariable(PCONDITION_VARIABLE ConditionVariable);
#endif // _WIN#"_WINNT
#endif

View File

@ -0,0 +1,91 @@
#include "windows_queue.h"
#include "windows_glue.h"
#include <Windows.h>
static int queueFull(windows_queue_t * queue) {
return queue->items == queue->size;
}
static int queueEmpty(windows_queue_t * queue) {
return queue->items == 0;
}
windows_queue_t * windows_queue_create(int length, size_t item_size) {
windows_queue_t *queue = (windows_queue_t*)malloc(sizeof(windows_queue_t));
if(queue == NULL)
goto queue_malloc_failed;
queue->buffer = malloc(length*item_size);
if(queue->buffer == NULL)
goto buffer_malloc_failed;
queue->size = length;
queue->item_size = item_size;
queue->items = 0;
queue->head_idx = 0;
InitializeCriticalSection(&(queue->mutex));
InitializeConditionVariable(&(queue->cond_full));
InitializeConditionVariable(&(queue->cond_empty));
goto queue_init_success;
buffer_malloc_failed:
free(queue);
queue = NULL;
queue_malloc_failed:
queue_init_success:
return queue;
}
void windows_queue_delete(windows_queue_t * q) {
if(q==NULL) return;
DeleteCriticalSection(&(q->mutex));
free(q->buffer);
free(q);
}
int windows_queue_enqueue(windows_queue_t * queue, void * value, int timeout) {
int offset;
EnterCriticalSection(&(queue->mutex));
while(queueFull(queue)) {
int ret = SleepConditionVariableCS(&(queue->cond_full), &(queue->mutex), timeout);
if( !ret ) {
LeaveCriticalSection(&(queue->mutex));
return ret == WAIT_TIMEOUT ? WINDOWS_QUEUE_FULL : WINDOWS_QUEUE_ERROR;
}
}
offset = ((queue->head_idx+queue->items) % queue->size) * queue->item_size;
memcpy((unsigned char*)queue->buffer + offset, value, queue->item_size);
queue->items++;
LeaveCriticalSection(&(queue->mutex));
WakeAllConditionVariable(&(queue->cond_empty));
return WINDOWS_QUEUE_OK;
}
int windows_queue_dequeue(windows_queue_t * queue, void * buf, int timeout) {
EnterCriticalSection(&(queue->mutex));
while(queueEmpty(queue)) {
int ret = SleepConditionVariableCS(&(queue->cond_empty), &(queue->mutex), timeout);
if( !ret ) {
LeaveCriticalSection(&(queue->mutex));
return ret == WAIT_TIMEOUT ? WINDOWS_QUEUE_EMPTY : WINDOWS_QUEUE_ERROR;
}
}
memcpy(buf, (unsigned char*)queue->buffer+(queue->head_idx%queue->size*queue->item_size), queue->item_size);
queue->items--;
queue->head_idx = (queue->head_idx + 1) % queue->size;
LeaveCriticalSection(&(queue->mutex));
WakeAllConditionVariable(&(queue->cond_full));
return WINDOWS_QUEUE_OK;
}
int windows_queue_items(windows_queue_t * queue) {
int items;
EnterCriticalSection(&(queue->mutex));
items = queue->items;
LeaveCriticalSection(&(queue->mutex));
return items;
}

View File

@ -0,0 +1,41 @@
#ifndef _WINDOWS_QUEUE_H_
#define _WINDOWS_QUEUE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <Windows.h>
#include "windows_glue.h"
#undef interface
#include <csp/arch/csp_queue.h>
#define WINDOWS_QUEUE_ERROR CSP_QUEUE_ERROR
#define WINDOWS_QUEUE_EMPTY CSP_QUEUE_ERROR
#define WINDOWS_QUEUE_FULL CSP_QUEUE_ERROR
#define WINDOWS_QUEUE_OK CSP_QUEUE_OK
typedef struct windows_queue_s {
void * buffer;
int size;
int item_size;
int items;
int head_idx;
CRITICAL_SECTION mutex;
CONDITION_VARIABLE cond_full;
CONDITION_VARIABLE cond_empty;
} windows_queue_t;
windows_queue_t * windows_queue_create(int length, size_t item_size);
void windows_queue_delete(windows_queue_t * q);
int windows_queue_enqueue(windows_queue_t * queue, void * value, int timeout);
int windows_queue_dequeue(windows_queue_t * queue, void * buf, int timeout);
int windows_queue_items(windows_queue_t * queue);
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif // _WINDOWS_QUEUE_H_