Skip to content

Commit

Permalink
Refactor common defines between platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
valeros committed Jun 15, 2015
1 parent c05d414 commit bef0185
Show file tree
Hide file tree
Showing 13 changed files with 69 additions and 56 deletions.
59 changes: 20 additions & 39 deletions firmware/src/common/sa-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Copyright (C) 2015 OLogN Technologies AG
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as
it under the terms of the GNU General Public License version 2 as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
Expand All @@ -22,6 +22,7 @@ Copyright (C) 2015 OLogN Technologies AG
// common includes
//#include <memory.h> // for memcpy(), memset(), memcmp(). Note: their implementation may or may not be more effective than just by-byte operation on a particular target platform
#include <string.h> // for memmove()
#include "../hal/hal-platform.h"

#define SA_DEBUG

Expand All @@ -30,30 +31,21 @@ Copyright (C) 2015 OLogN Technologies AG
#define SA_USED_ENDIANNES SA_LITTLE_ENDIAN
//#define SA_USED_ENDIANNES SA_BIG_ENDIAN

// data types
#ifdef _MSC_VER
#define uint8_t unsigned char
#define int8_t char
#define uint16_t unsigned short
#define int16_t short
#else
#include "stdint.h"
#endif
#ifndef bool
#define bool uint8_t
#define true 1
#define false 0
#endif

#ifdef _MSC_VER
#define NOINLINE __declspec(noinline)
#define INLINE __inline
#define FORCE_INLINE __forceinline
#else
#ifndef INLINE
#define INLINE static inline
#endif
#ifndef NOINLINE
#define NOINLINE __attribute__ ((noinline))
#define FORCE_INLINE static inline __attribute__((always_inline))
#endif


#ifndef FORCE_INLINE
#define FORCE_INLINE static inline __attribute__((always_inline))
#endif

INLINE void zepto_memset( void* dest, uint8_t val, uint16_t cnt )
{
Expand All @@ -72,35 +64,24 @@ INLINE void zepto_memcpy( void* dest, const void* src, uint16_t cnt )
#define ZEPTO_MEMSET zepto_memset
#define ZEPTO_MEMCPY zepto_memcpy


#if !defined WINLNXCOMMON // TODO: this is a clear misuse of definitions; instead it should be a test that we build for a respective architecture
#define ZEPTO_PROGMEM_IN_USE // platform-specific; consider moving to project-level
#endif // WINLNXCOMMON

#ifdef ZEPTO_PROGMEM_IN_USE

#include <avr/pgmspace.h>

#define ZEPTO_PROGMEM __attribute__ ((progmem))
#define ZEPTO_PROG_CONSTANT_LOCATION ZEPTO_PROGMEM
#define ZEPTO_PROG_CONSTANT_READ_BYTE(x) pgm_read_byte(x)
/*INLINE void zepto_memcpy_from_progmem( void* dest, const void* src, uint16_t cnt )
{
uint8_t i;
for ( i=0; i<cnt; i++ )
((uint8_t*)dest)[i] = pgm_read_byte( ((uint8_t*)src) + i );
}*/
#define ZEPTO_MEMCPY_FROM_PROGMEM memcpy_PF

#else // ZEPTO_PROGMEM_IN_USE

#ifndef ZEPTO_PROG_CONSTANT_LOCATION
#define ZEPTO_PROG_CONSTANT_LOCATION
#define ZEPTO_PROG_CONSTANT_READ_BYTE(x) (*(x))
#define ZEPTO_MEMCPY_FROM_PROGMEM ZEPTO_MEMCPY

#endif // ZEPTO_PROGMEM_IN_USE
#endif

#ifndef ZEPTO_PROG_CONSTANT_READ_BYTE
#define ZEPTO_PROG_CONSTANT_READ_BYTE(x) (*(x))
#endif

#ifndef ZEPTO_MEMCPY_FROM_PROGMEM
#define ZEPTO_MEMCPY_FROM_PROGMEM ZEPTO_MEMCPY
#endif

// Master/Slave distinguishing bit; USED_AS_MASTER is assumed to be a preprocessor definition if necessary

Expand Down Expand Up @@ -143,7 +124,7 @@ INLINE void zepto_memcpy( void* dest, const void* src, uint16_t cnt )
#else
#define assert FORBIDDEN_CALL_OF_ASSERT
#define ZEPTO_DEBUG_ASSERT( x )
#define ZEPTO_RUNTIME_CHECK( x ) //TODO: define
#define ZEPTO_RUNTIME_CHECK( x ) //TODO: define
#endif

// counter system
Expand All @@ -159,7 +140,7 @@ extern const char* CTRS_NAMES_D[MAX_COUNTERS_CNT];
memset( COUNTERS, 0, sizeof(COUNTERS) ); \
memset( CTRS_NAMES, 0, sizeof(CTRS_NAMES) ); \
memset( COUNTERS_D, 0, sizeof(COUNTERS_D) ); \
memset( CTRS_NAMES_D, 0, sizeof(CTRS_NAMES_D) );
memset( CTRS_NAMES_D, 0, sizeof(CTRS_NAMES_D) );
void printCounters();
#define PRINT_COUNTERS() printCounters()
#define TEST_CTR_SYSTEM
Expand Down
6 changes: 6 additions & 0 deletions firmware/src/hal/hal-platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,14 @@ Copyright (C) 2015 OLogN Technologies AG
#if !defined __HAL_PLATFORM_H__
#define __HAL_PLATFORM_H__

#if defined ARDUINO && (!defined ENERGIA)
#include "platforms/arduino/hal-main.h"
#elif defined ENERGIA
#include "platforms/energia/hal-main.h"
#elif defined __MBED__
#include "platforms/mbed/hal-main.h"
#elif defined WINLNXCOMMON
#include "platforms/win-lnx-common/hal-main.h"
#endif

#endif // __HAL_PLATFORM_H__
8 changes: 8 additions & 0 deletions firmware/src/hal/hal-waiting.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ typedef struct _waiting_for
#define WAIT_RESULTED_IN_I2C 3
#define WAIT_RESULTED_IN_PINS 4

#ifdef __cplusplus
extern "C" {
#endif

uint8_t hal_wait_for( waiting_for* wf );

#ifdef __cplusplus
}
#endif

#endif // __SA_HAL_WAITING_H__
2 changes: 1 addition & 1 deletion firmware/src/hal/platforms/arduino/hal-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Copyright (C) 2015 OLogN Technologies AG

#if defined ARDUINO && (!defined ENERGIA)

#include "../../../common/sa-common.h"
#include "../../../sa-main.h"
#include "hal-main.h"

void setup()
Expand Down
11 changes: 9 additions & 2 deletions firmware/src/hal/platforms/arduino/hal-main.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@ Copyright (C) 2015 OLogN Technologies AG
#if !defined __HAL_PLATFORM_ARDUINO_MAIN_H__
#define __HAL_PLATFORM_ARDUINO_MAIN_H__

#include <avr/pgmspace.h>
#include <Arduino.h>
#include "../../../sa-main.h"
#include "stdint.h"
#include "hal-time-conversions.h"

#define ZEPTO_PROGMEM_IN_USE
#define ZEPTO_PROGMEM __attribute__ ((progmem))
#define ZEPTO_PROG_CONSTANT_LOCATION ZEPTO_PROGMEM
#define ZEPTO_PROG_CONSTANT_READ_BYTE(x) pgm_read_byte(x)
#define ZEPTO_MEMCPY_FROM_PROGMEM memcpy_PF

#endif // __HAL_PLATFORM_ARDUINO_MAIN_H__

#endif
#endif // ARDUINO && (!defined ENERGIA)
2 changes: 1 addition & 1 deletion firmware/src/hal/platforms/arduino/sa-commlayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ uint8_t tryGetMessage( MEMORY_HANDLE mem_h )
return 0;
}

uint8_t communication_initialize()
bool communication_initialize()
{
ZEPTO_DEBUG_ASSERT(0);
return false;
Expand Down
1 change: 1 addition & 0 deletions firmware/src/hal/platforms/energia/hal-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Copyright (C) 2015 OLogN Technologies AG

#ifdef ENERGIA

#include "../../../sa-main.h"
#include "hal-main.h"

void setup()
Expand Down
6 changes: 5 additions & 1 deletion firmware/src/hal/platforms/energia/hal-main.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ Copyright (C) 2015 OLogN Technologies AG
#define __HAL_PLATFORM_ENERGIA_MAIN_H__

#include <Energia.h>
#include "../../../sa-main.h"
#include "hal-time-conversions.h"

#define ZEPTO_PROGMEM_IN_USE
#define ZEPTO_PROGMEM __attribute__ ((progmem))
#define ZEPTO_PROG_CONSTANT_LOCATION ZEPTO_PROGMEM
#define ZEPTO_PROG_CONSTANT_READ_BYTE(x) pgm_read_byte(x)

#endif // __HAL_PLATFORM_ENERGIA_MAIN_H__

#endif
1 change: 1 addition & 0 deletions firmware/src/hal/platforms/win-lnx-common/hal-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Copyright (C) 2015 OLogN Technologies AG
#ifdef WINLNXCOMMON

#include "hal-main.h"
#include "../../../sa-main.h"

int main(int argc, char *argv[])
{
Expand Down
7 changes: 6 additions & 1 deletion firmware/src/hal/platforms/win-lnx-common/hal-main.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ Copyright (C) 2015 OLogN Technologies AG
#if !defined __HAL_PLATFORM_WINLNXCOMMON_MAIN_H__
#define __HAL_PLATFORM_WINLNXCOMMON_MAIN_H__

#include "../../../sa-main.h"
#include "hal-time-conversions.h"

#ifdef _MSC_VER
#define NOINLINE __declspec(noinline)
#define INLINE __inline
#define FORCE_INLINE __forceinline
#endif

#endif // __HAL_PLATFORM_WINLNXCOMMON_MAIN_H__

#endif
15 changes: 10 additions & 5 deletions firmware/src/hal/sa-commlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ Copyright (C) 2015 OLogN Technologies AG
#include "zepto-mem-mngmt-hal-spec.h"
#include "../common/zepto-mem-mngmt.h"

bool communication_initialize();
void communication_terminate();


// RET codes
#define COMMLAYER_RET_FAILED 0
#define COMMLAYER_RET_OK 1
Expand All @@ -37,9 +33,18 @@ void communication_terminate();

#define COMMLAYER_RET_FROM_COMMM_STACK 10

#ifdef __cplusplus
extern "C" {
#endif


bool communication_initialize();
void communication_terminate();
uint8_t sendMessage( MEMORY_HANDLE mem_h );
uint8_t tryGetMessage( MEMORY_HANDLE mem_h );

#ifdef __cplusplus
}
#endif

//uint8_t wait_for_communication_event( MEMORY_HANDLE mem_h, uint16_t timeout );
//uint8_t wait_for_communication_event( uint16_t timeout );
Expand Down
4 changes: 0 additions & 4 deletions firmware/src/hal/sa-hal-time-provider.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ unsigned short getTime();
}
#endif





// operations (to be added upon necessity)

INLINE void sa_hal_time_val_copy_from( sa_time_val* t1, const sa_time_val* t2 )
Expand Down
3 changes: 1 addition & 2 deletions firmware/src/sa-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Copyright (C) 2015 OLogN Technologies AG

#include "common/sa-common.h"
#include "common/sa-uint48.h"
#include "hal/hal-platform.h"
#include "hal/sa-hal-time-provider.h"
#include "hal/sa-commlayer.h"
#include "hal/hal-waiting.h"
Expand Down Expand Up @@ -99,7 +98,7 @@ int sa_main_loop()
// test setup values
// TODO: all code related to simulation and test generation MUST be moved out here ASAP!
bool wait_for_incoming_chain_with_timer = 0;
uint16_t wake_time_to_start_new_chain = 0;
uint16_t wake_time_to_start_new_chain = 0;
uint8_t wait_to_continue_processing = 0;
uint16_t wake_time_continue_processing = 0;
// END OF test setup values
Expand Down

0 comments on commit bef0185

Please sign in to comment.