2016-10-27 18:28:01 +02:00
|
|
|
#ifndef _SSS7_H_
|
|
|
|
#define _SSS7_H_
|
|
|
|
|
2016-11-26 18:27:04 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2016-11-21 12:48:29 +01:00
|
|
|
#include <stdint.h>
|
2016-10-27 18:28:01 +02:00
|
|
|
|
2016-12-01 00:14:40 +01:00
|
|
|
#ifdef SSS7_THREADED
|
|
|
|
#define sss7_shared_modfier _Atomic
|
|
|
|
#else
|
2016-11-30 22:47:26 +01:00
|
|
|
#define sss7_shared_modfier volatile
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
2016-10-27 18:28:01 +02:00
|
|
|
enum sss7State {
|
|
|
|
SSS7_IDLE,
|
|
|
|
SSS7_TX_HEADER,
|
|
|
|
SSS7_TX_PAYLOAD,
|
|
|
|
SSS7_TX_CRC,
|
|
|
|
|
|
|
|
SSS7_RX_HEADER,
|
|
|
|
SSS7_RX_PAYLOAD,
|
|
|
|
SSS7_RX_CRC
|
|
|
|
};
|
|
|
|
|
2016-10-27 23:35:24 +02:00
|
|
|
const static uint8_t SSS7_HEADER[] = {0xAA, 0xFE};
|
2016-12-01 00:16:42 +01:00
|
|
|
const static uint16_t sss7_timeout = 150;
|
2016-11-21 09:42:22 +01:00
|
|
|
const static uint16_t sss7_timeout_increment = 1;
|
2016-10-27 18:28:01 +02:00
|
|
|
|
|
|
|
#define SSS7_PAYLOAD_SIZE 16
|
2016-11-29 19:18:42 +01:00
|
|
|
#define SSS7_RX_BUFFER_SIZE 2
|
2016-10-27 18:28:01 +02:00
|
|
|
|
2016-11-21 09:42:22 +01:00
|
|
|
|
2016-11-30 22:47:26 +01:00
|
|
|
extern sss7_shared_modfier enum sss7State sss7_state;
|
|
|
|
extern sss7_shared_modfier uint8_t sss7_tx_failed;
|
2016-12-02 01:58:00 +01:00
|
|
|
extern sss7_shared_modfier uint8_t sss7_rx_buffer_write;
|
|
|
|
extern sss7_shared_modfier uint8_t sss7_rx_buffer_read;
|
2016-10-27 18:28:01 +02:00
|
|
|
|
2016-11-30 22:47:26 +01:00
|
|
|
|
2016-11-20 02:24:07 +01:00
|
|
|
void sss7_process_rx(void);
|
|
|
|
void sss7_process_tx(void);
|
2016-11-21 09:42:22 +01:00
|
|
|
void sss7_process_ticks(uint16_t ticks);
|
2016-11-20 02:24:07 +01:00
|
|
|
|
2016-11-21 11:58:09 +01:00
|
|
|
extern void uart_put_byte(uint8_t byte);
|
|
|
|
extern uint8_t uart_get_byte(void);
|
|
|
|
|
2016-11-20 02:24:07 +01:00
|
|
|
|
2016-10-27 23:35:24 +02:00
|
|
|
void sss7_init(void);
|
2016-10-27 18:28:01 +02:00
|
|
|
|
2016-10-27 23:35:24 +02:00
|
|
|
static inline uint8_t sss7_can_send(void) {
|
2016-10-27 18:28:01 +02:00
|
|
|
return sss7_state == SSS7_IDLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void sss7_send(uint8_t msg[SSS7_PAYLOAD_SIZE]);
|
|
|
|
|
2016-10-27 23:35:24 +02:00
|
|
|
static inline uint8_t sss7_send_failed(void) {
|
2016-10-30 02:04:35 +02:00
|
|
|
return sss7_tx_failed;
|
2016-10-27 18:28:01 +02:00
|
|
|
}
|
|
|
|
|
2016-10-27 23:35:24 +02:00
|
|
|
static inline uint8_t sss7_has_received(void) {
|
2016-11-29 19:18:42 +01:00
|
|
|
return sss7_rx_buffer_read != sss7_rx_buffer_write;
|
2016-10-27 18:28:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void sss7_get_received(uint8_t msg[SSS7_PAYLOAD_SIZE]);
|
|
|
|
|
2016-11-26 18:27:04 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-10-27 18:28:01 +02:00
|
|
|
#endif
|