MySensors Library & Examples  2.3.2
MyHwLinuxGeneric.h
1 /*
2  * The MySensors Arduino library handles the wireless radio link and protocol
3  * between your home built sensors/actuators and HA controller of choice.
4  * The sensors forms a self healing radio network with optional repeaters. Each
5  * repeater and gateway builds a routing tables in EEPROM which keeps track of the
6  * network topology allowing messages to be routed to nodes.
7  *
8  * Created by Henrik Ekblad <[email protected]>
9  * Copyright (C) 2013-2019 Sensnology AB
10  * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
11  *
12  * Documentation: http://www.mysensors.org
13  * Support Forum: http://forum.mysensors.org
14  *
15  * This program is free software; you can redistribute it and/or
16  * modify it under the terms of the GNU General Public License
17  * version 2 as published by the Free Software Foundation.
18  */
19 
20 #ifndef MyHwLinuxGeneric_h
21 #define MyHwLinuxGeneric_h
22 
23 #include <cstdlib>
24 #include <pthread.h>
25 #include "SerialPort.h"
26 #include "StdInOutStream.h"
27 #include <SPI.h>
28 #include <errno.h>
29 #include <stdarg.h>
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <syscall.h>
33 #include <unistd.h>
34 #include "SoftEeprom.h"
35 #include "log.h"
36 #include "config.h"
37 
38 #define CRYPTO_LITTLE_ENDIAN
39 
40 #ifdef MY_LINUX_SERIAL_PORT
41 #ifdef MY_LINUX_SERIAL_IS_PTY
43 #else
45 #endif
46 #else
48 #endif
49 
50 #ifndef MY_SERIALDEVICE
51 #define MY_SERIALDEVICE Serial
52 #endif
53 
54 // Define these as macros (do nothing)
55 #define hwWatchdogReset()
56 #define hwReboot()
57 #define hwGetSleepRemaining() (0ul)
58 
59 inline void hwDigitalWrite(uint8_t, uint8_t);
60 inline int hwDigitalRead(uint8_t);
61 inline void hwPinMode(uint8_t, uint8_t);
62 
63 bool hwInit(void);
64 inline void hwReadConfigBlock(void *buf, void *addr, size_t length);
65 inline void hwWriteConfigBlock(void *buf, void *addr, size_t length);
66 inline uint8_t hwReadConfig(const int addr);
67 inline void hwWriteConfig(const int addr, uint8_t value);
68 inline void hwRandomNumberInit(void);
69 ssize_t hwGetentropy(void *__buffer, size_t __length);
70 #define MY_HW_HAS_GETENTROPY
71 inline uint32_t hwMillis(void);
72 
73 // SOFTSPI
74 #ifdef MY_SOFTSPI
75 #error Soft SPI is not available on this architecture!
76 #endif
77 #define hwSPI SPI
78 
79 #ifdef MY_RF24_IRQ_PIN
80 static pthread_mutex_t hw_mutex = PTHREAD_MUTEX_INITIALIZER;
81 
82 static __inline__ void __hwUnlock(const uint8_t *__s)
83 {
84  pthread_mutex_unlock(&hw_mutex);
85  (void)__s;
86 }
87 
88 static __inline__ void __hwLock()
89 {
90  pthread_mutex_lock(&hw_mutex);
91 }
92 #endif
93 
94 #if defined(DOXYGEN)
95 #define ATOMIC_BLOCK_CLEANUP
96 #elif defined(MY_RF24_IRQ_PIN)
97 #define ATOMIC_BLOCK_CLEANUP uint8_t __atomic_loop \
98  __attribute__((__cleanup__( __hwUnlock ))) = 1
99 #else
100 #define ATOMIC_BLOCK_CLEANUP
101 #endif /* DOXYGEN */
102 
103 #if defined(DOXYGEN)
104 #define ATOMIC_BLOCK
105 #elif defined(MY_RF24_IRQ_PIN)
106 #define ATOMIC_BLOCK for ( ATOMIC_BLOCK_CLEANUP, __hwLock(); \
107  __atomic_loop ; __atomic_loop = 0 )
108 #else
109 #define ATOMIC_BLOCK
110 #endif /* DOXYGEN */
111 
112 #ifndef DOXYGEN
113 #define MY_CRITICAL_SECTION ATOMIC_BLOCK
114 #endif /* DOXYGEN */
115 
116 #endif
StdInOutStream
A class that prints to stdout and reads from stdin.
Definition: StdInOutStream.h:31
SerialPort
Definition: SerialPort.h:31
MY_LINUX_SERIAL_PORT
#define MY_LINUX_SERIAL_PORT
Serial device port.
Definition: MyConfig.h:2240