/* ---------------------------------------------------------------------------
 * BpPort.h - v0.1                                 (c) 2008 Micro-key bv
 * ---------------------------------------------------------------------------
 * Micro-key bv
 * Industrieweg 28, 9804 TG Noordhorn
 * Postbus 92, 9800 AB Zuidhorn
 * The Netherlands
 * Tel: +31 594 503020
 * Fax: +31 594 505825
 * Email: support@microkey.nl
 * Web: www.microkey.nl
 * ---------------------------------------------------------------------------
 * Description: 
 * ---------------------------------------------------------------------------
 * Version(s):  0.1, Jan 29, 2008, FSc
 *                   Creation.
 * ---------------------------------------------------------------------------
 */
#ifndef __BPPORT_H__
#define __BPPORT_H__
/** \file BpPort.h 
    \brief 
*/

/* ---------------------------------------------------------------------------
 * System include files.
 * ---------------------------------------------------------------------------
 */
#include <malloc.h>
#include <pthread.h>
#include <unistd.h>   // Required for usleep
#include <mqueue.h>

/* ---------------------------------------------------------------------------
 * Application include files.
 * ---------------------------------------------------------------------------
 */
#include "types.h"

/* ---------------------------------------------------------------------------
 * Constant and macro definitions.
 * ---------------------------------------------------------------------------
 */


/* ---------------------------------------------------------------------------
 * Type definitions.
 * ---------------------------------------------------------------------------
 */
typedef pthread_t xTaskHandle;
//typedef mqd_t xQueueHandle;
typedef long portTickType;

/* ---------------------------------------------------------------------------
 * Variable declarations.
 * ---------------------------------------------------------------------------
 */

/* ---------------------------------------------------------------------------
 * Function declarations.
 * ---------------------------------------------------------------------------
 */
//void *pvPortMalloc( size_t xWantedSize );
#define pvPortMalloc(wantedsize)    malloc(wantedsize)

//void vPortFree( void *pv );
#define vPortFree(buffer)           free(buffer)

//
//   signed portBASE_TYPE xTaskCreate( pdTASK_CODE pvTaskCode, 
//	const signed portCHAR * pcName, 
//	unsigned portSHORT usStackDepth, 
//	void *pvParameters, 
//	unsigned portBASE_TYPE uxPriority, 
//	xTaskHandle *pvCreatedTask );
//
//   extern int pthread_create (pthread_t *__restrict __newthread,
//			   __const pthread_attr_t *__restrict __attr,
//			   void *(*__start_routine) (void *),
//			   void *__restrict __arg) __THROW __nonnull ((1, 3));
//
#define xTaskCreate(start_function, name, stackdepth, params, priority, handle) \
                pthread_create(handle, NULL, start_function, params)

//
//   void vTaskDelete( xTaskHandle pxTask );
//
//   void pthread_exit(void *value_ptr);  
//
// note: Het deleten van een taak moet nog worden uitgezocht. Waarschijnlijk kan de thread niet zomaar gestopt worden
#define vTaskDelete( a ) 				// pthread_exit( a )

//
//   portTickType xTaskGetTickCount( void );
//
//   ?
//
portTickType xTaskGetTickCount();

//
// 
//
//   void usleep(unsigned long usec);
//
#define vTaskDelay( msec )                  usleep( 1000 * msec );

//
//   xQueueHandle xQueueCreate( unsigned portBASE_TYPE uxQueueLength, unsigned portBASE_TYPE uxItemSize );
//
//   extern mqd_t mq_open (const char *__name, int __oflag, ...) __THROW;
//

//
//   signed portBASE_TYPE xQueueGenericReceive( xQueueHandle xQueue, const void * const pvBuffer, portTickType xTicksToWait, portBASE_TYPE xJustPeek );
//
//   #define xQueueReceive( xQueue, pvBuffer, xTicksToWait ) xQueueGenericReceive( xQueue, pvBuffer, xTicksToWait, pdFALSE )
//
//    /* Receive the oldest from highest priority messages in message queue
//       MQDES.  */
//   extern ssize_t mq_receive (mqd_t __mqdes, char *__msg_ptr, size_t __msg_len,
//			   unsigned int *__msg_prio);
//
//#define xQueueReceive( handle, buffer, ticks2wait ) 

//
//   signed portBASE_TYPE xQueueGenericSend( xQueueHandle xQueue, const void * const pvItemToQueue, portTickType xTicksToWait, portBASE_TYPE xCopyPosition );
//
//   #define xQueueSendToBack( xQueue, pvItemToQueue, xTicksToWait ) xQueueGenericSend( xQueue, pvItemToQueue, xTicksToWait, queueSEND_TO_BACK )
//
//   /* Add message pointed by MSG_PTR to message queue MQDES.  */
//   extern int mq_send (mqd_t __mqdes, const char *__msg_ptr, size_t __msg_len,
//		    unsigned int __msg_prio);
//

#endif /* __BPPORT_H__ */

