rusefi/firmware/global.h

141 lines
2.9 KiB
C
Raw Normal View History

2015-07-10 06:01:56 -07:00
/*
* @file global.h
*
2018-12-24 19:17:13 -08:00
* Global utility header file for firmware
2018-09-16 17:28:23 -07:00
*
2018-12-24 19:57:36 -08:00
* Simulator and unit tests have their own version of this header
*
* While this header contains 'EXTERN_ENGINE' and 'DECLARE_ENGINE_PARAMETER_SIGNATURE' magic,
* this header is not allowed to actually include higher-level engine related headers
*
2015-07-10 06:01:56 -07:00
* @date May 27, 2013
2017-01-03 03:05:22 -08:00
* @author Andrey Belomutskiy, (c) 2012-2017
2015-07-10 06:01:56 -07:00
*/
#ifndef GLOBAL_H_
#define GLOBAL_H_
2017-03-21 11:58:14 -07:00
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
2015-07-10 06:01:56 -07:00
#include <ch.h>
#include <hal.h>
// this is about MISRA not liking 'time.h'. todo: figure out something
#if defined __GNUC__
// GCC
#include <sys/types.h>
#define ALWAYS_INLINE __attribute__((always_inline)) inline
2015-07-10 06:01:56 -07:00
#else
// IAR
typedef unsigned int time_t;
// todo: what's the IAR option?
#define ALWAYS_INLINE INLINE
#endif
2018-09-16 20:10:06 -07:00
#include "common_headers.h"
2015-07-10 06:01:56 -07:00
#include "io_pins.h"
2018-09-16 20:10:06 -07:00
#ifdef __cplusplus
#include "cli_registry.h"
#include "eficonsole.h"
#endif /* __cplusplus */
#include "chprintf.h"
2018-09-16 19:00:14 -07:00
2015-07-10 06:01:56 -07:00
/* definition to expand macro then apply to pragma message */
#define VALUE_TO_STRING(x) #x
#define VALUE(x) VALUE_TO_STRING(x)
#define VAR_NAME_VALUE(var) #var "=" VALUE(var)
// project-wide default thread stack size
// see also PORT_INT_REQUIRED_STACK
#define UTILITY_THREAD_STACK_SIZE 400
#define EFI_ERROR_CODE 0xffffffff
2017-05-03 18:24:18 -07:00
#if EFI_USE_CCM && defined __GNUC__
#define MAIN_RAM __attribute__((section(".ram0")))
#elif defined __GNUC__
#define MAIN_RAM
#else
#define MAIN_RAM @ ".ram0"
#endif
2017-05-17 17:29:22 -07:00
/**
* rusEfi is placing some of data structures into CCM memory simply
* in order to use that memory - no magic about which RAM is faster etc.
*
* Please note that DMA does not work with CCM memory
*/
#if defined(STM32F7XX)
#undef EFI_USE_CCM
// todo: DTCM == CCM on STM32F7?
//#define CCM_RAM ".ram3"
#else /* defined(STM32F4XX) */
#define CCM_RAM ".ram4"
#endif /* defined(STM32F4XX) */
#if EFI_USE_CCM
#if defined __GNUC__
#define CCM_OPTIONAL __attribute__((section(CCM_RAM)))
#else // non-gcc
#define CCM_OPTIONAL @ CCM_RAM
2015-07-10 06:01:56 -07:00
#endif
#else /* !EFI_USE_CCM */
#define CCM_OPTIONAL
#endif /* EFI_USE_CCM */
2015-07-10 06:01:56 -07:00
/**
* low-level function is used here to reduce stack usage
*/
#define ON_FATAL_ERROR() \
palWritePad(LED_ERROR_PORT, LED_ERROR_PIN, 1); \
2017-01-26 20:03:04 -08:00
turnAllPinsOff(); \
2018-07-26 12:51:06 -07:00
enginePins.communicationLedPin.setValue(1);
2015-07-10 06:01:56 -07:00
2017-03-21 11:58:14 -07:00
/*
* Stack debugging
* See also getMaxUsedStack()
2017-03-21 11:58:14 -07:00
*/
int getRemainingStack(thread_t *otp);
2015-07-10 06:01:56 -07:00
#ifdef __cplusplus
}
#endif /* __cplusplus */
2018-09-16 19:00:14 -07:00
// 168 ticks in microsecond
2018-12-26 18:35:52 -08:00
#define US_TO_NT_MULTIPLIER (CORE_CLOCK / 1000000)
2018-09-16 19:00:14 -07:00
/**
* converts efitimeus_t to efitick_t
*/
#define US2NT(us) (((efitime_t)(us))*US_TO_NT_MULTIPLIER)
/**
* converts efitick_t to efitimeus_t
*/
#define NT2US(nt) ((nt) / US_TO_NT_MULTIPLIER)
#define Delay(ms) chThdSleepMilliseconds(ms)
#ifdef __cplusplus
extern "C"
{
#endif
bool lockAnyContext(void);
void unlockAnyContext(void);
#ifdef __cplusplus
}
#endif
2015-07-10 06:01:56 -07:00
#endif /* GLOBAL_H_ */
2018-09-16 19:00:14 -07:00