sss7modem/software/sss7core/sss7.h

109 lines
2.9 KiB
C
Raw Permalink Normal View History

2016-10-27 18:28:01 +02:00
#ifndef _SSS7_H_
#define _SSS7_H_
2016-12-02 23:44:57 +01:00
#include <stdint.h>
// In case this is used on arduino
#ifdef __cplusplus
extern "C" {
#endif
2016-12-02 23:44:57 +01:00
// sss7 for linux uses pthreads, which works better with _Atomic here
2016-12-01 00:14:40 +01:00
#ifdef SSS7_THREADED
#define sss7_shared_modfier _Atomic
#else
#define sss7_shared_modfier volatile
#endif
2016-10-27 18:28:01 +02:00
enum sss7State {
2016-12-02 23:44:57 +01:00
SSS7_IDLE, // Idle state, waiting for something to happen
SSS7_TX_HEADER, // Sending the first header byte has started,
// waiting for it to complete, to send the second byte
SSS7_TX_PAYLOAD, // Sending the paylaod of the frame
SSS7_TX_CRC, // Sending the last paylaod by has started,
// waiting for the it to complete, to send crc byte
2016-12-22 19:00:53 +01:00
SSS7_TX_FINALIZE, // Wait until the crc byte has been read back
2016-12-02 23:44:57 +01:00
SSS7_RX_HEADER, // First header byte has been reived, waiting for the second one
SSS7_RX_PAYLOAD, // Receiving payload bytes
SSS7_RX_CRC // Last payload byte has been received, waiting for crc byte
2016-10-27 18:28:01 +02:00
};
2016-12-02 23:44:57 +01:00
// SSS7 Frame header
const static uint8_t SSS7_HEADER[] = {0xAA, 0xFE};
2016-12-02 23:44:57 +01:00
// Receive Timeout in milliseconds
2016-12-01 00:16:42 +01:00
const static uint16_t sss7_timeout = 150;
2016-12-02 23:44:57 +01:00
// TODO: Check if this is still neede
2016-11-21 09:42:22 +01:00
const static uint16_t sss7_timeout_increment = 1;
2016-10-27 18:28:01 +02:00
2016-12-02 23:44:57 +01:00
// Size of the payload
2016-10-27 18:28:01 +02:00
#define SSS7_PAYLOAD_SIZE 16
2016-12-02 23:44:57 +01:00
// Payloads in rx buffer
#define SSS7_RX_BUFFER_SIZE 2
2016-10-27 18:28:01 +02:00
2016-11-21 09:42:22 +01:00
2016-12-02 23:44:57 +01:00
// See sss7.c for more information
// State variable
extern sss7_shared_modfier enum sss7State sss7_state;
2016-12-02 23:44:57 +01:00
// Transmission failed flag
extern sss7_shared_modfier uint8_t sss7_tx_failed;
2016-12-02 23:44:57 +01:00
// rx buffer write position
extern sss7_shared_modfier uint8_t sss7_rx_buffer_write;
2016-12-02 23:44:57 +01:00
// tx buffer read postion
extern sss7_shared_modfier uint8_t sss7_rx_buffer_read;
2016-10-27 18:28:01 +02:00
2016-12-02 23:44:57 +01:00
// See sss7.c for more information
// Receive handler
void sss7_process_rx(void);
2016-12-02 23:44:57 +01:00
// Transmit handler
void sss7_process_tx(void);
2016-12-02 23:44:57 +01:00
// Timeout hanlder
2016-11-21 09:42:22 +01:00
void sss7_process_ticks(uint16_t ticks);
2016-12-02 23:44:57 +01:00
// Funtion to abstract sending byte with the uart
// Hardware dependent and has to be provided by the concrete implementation
2016-11-21 11:58:09 +01:00
extern void uart_put_byte(uint8_t byte);
2016-12-02 23:44:57 +01:00
// Funtion to abstract reading a byte from the uart
// Hardware dependent and has to be provided by the concrete implementation
extern uint8_t uart_get_byte(void);
2016-12-02 23:44:57 +01:00
// Initialization function, see sss7.c
void sss7_init(void);
2016-10-27 18:28:01 +02:00
2016-12-02 23:44:57 +01:00
// Checks if the sss7 statemachine is idle and can start sending a frame
static inline uint8_t sss7_can_send(void) {
2016-10-27 18:28:01 +02:00
return sss7_state == SSS7_IDLE;
}
2016-12-02 23:44:57 +01:00
// Function for starting the transmission of a frame, see sss7.c
2016-10-27 18:28:01 +02:00
void sss7_send(uint8_t msg[SSS7_PAYLOAD_SIZE]);
2016-12-02 23:44:57 +01:00
// Readonly accessor to sss7_tx_failed
static inline uint8_t sss7_send_failed(void) {
return sss7_tx_failed;
2016-10-27 18:28:01 +02:00
}
2016-12-02 23:44:57 +01:00
// Checks if there is an unread payload inside the rx buffer
static inline uint8_t sss7_has_received(void) {
return sss7_rx_buffer_read != sss7_rx_buffer_write;
2016-10-27 18:28:01 +02:00
}
2016-12-02 23:44:57 +01:00
// Function to retrieve payloads from the rx buffer, see sss7.c
2016-10-27 18:28:01 +02:00
void sss7_get_received(uint8_t msg[SSS7_PAYLOAD_SIZE]);
#ifdef __cplusplus
}
#endif
2016-10-27 18:28:01 +02:00
#endif