Paparazzi UAS  v4.0.4_stable-3-gf39211a
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
max3100_hw.h
Go to the documentation of this file.
1 #ifndef MAX3100_H
2 #define MAX3100_H
3 
4 #include <stdbool.h>
5 #include "std.h"
6 #include "mcu_periph/spi_arch.h"
7 #include "led.h"
8 
9 /* Pin configuration for max3100 IRQ */
10 // #define MAX3100_IRQ_PIN 7
11 #if MAX3100_IRQ_PIN == 7
12 #define MAX3100_IRQ_PINSEL PINSEL0
13 #define MAX3100_IRQ_PINSEL_BIT 14
14 #define MAX3100_IRQ_PINSEL_VAL 0x3
15 #define MAX3100_IRQ_EINT 2
16 #define MAX3100_VIC_EINT VIC_EINT2
17 #elif MAX3100_IRQ_PIN == 16
18 #define MAX3100_IRQ_PINSEL PINSEL1
19 #define MAX3100_IRQ_PINSEL_BIT 0
20 #define MAX3100_IRQ_PINSEL_VAL 0x1
21 #define MAX3100_IRQ_EINT 0
22 #define MAX3100_VIC_EINT VIC_EINT0
23 #else
24 #error "Define MAX3100_IRQ_PIN"
25 #endif
26 
27 #define MAX3100_SS_PORT 0
28 #define MAX3100_SS_PIN 20
29 
30 #define MAX3100_IO__(port, reg) IO ## port ## reg
31 #define MAX3100_IO_(port, reg) MAX3100_IO__(port, reg)
32 
33 #define MAX3100_SS_IOCLR MAX3100_IO_(MAX3100_SS_PORT, CLR)
34 #define MAX3100_SS_IODIR MAX3100_IO_(MAX3100_SS_PORT, DIR)
35 #define MAX3100_SS_IOSET MAX3100_IO_(MAX3100_SS_PORT, SET)
36 
38 #define MAX3100_STATUS_IDLE 0
39 #define MAX3100_STATUS_WRITING 1
40 #define MAX3100_STATUS_READING 2
41 
42 extern volatile uint8_t max3100_status;
43 extern volatile bool max3100_data_available;
44 extern volatile bool max3100_transmit_buffer_empty; // Max3100 ready to receive data on SPI
45 
47 #define MAX3100_TX_BUF_LEN 256
48 #define MAX3100_RX_BUF_LEN 256
49 
52 
55 
56 extern volatile uint8_t read_byte1, read_byte2;
57 extern bool read_bytes;
58 
59 #define Max3100Select() { \
60  SetBit(MAX3100_SS_IOCLR, MAX3100_SS_PIN); \
61  }
62 
63 #define Max3100Unselect() { \
64  SetBit(MAX3100_SS_IOSET, MAX3100_SS_PIN); \
65  }
66 
67 #define MAX3100_WRITE_CONF ((1U<<15) | (1U<<14))
68 #define MAX3100_READ_CONF ((0U<<15) | (1U<<14))
69 #define MAX3100_WRITE_DATA ((1U<<15) | (0U<<14))
70 #define MAX3100_READ_DATA ((0U<<15) | (0U<<14))
71 
72 /* Datasheet page 12 */
73 #if MAX3100_FOSC == 1843200
74 #define MAX3100_B115200 0x0
75 #define MAX3100_B57600 0x1
76 #define MAX3100_B19200 0x9
77 #define MAX3100_B9600 0xA
78 #elif MAX3100_FOSC == 3686400
79 #define MAX3100_B9600 0xB
80 #else
81 #error "MAX3100_FOSC must be defined to 1843200 or 3686400"
82 #endif
83 
84 #define MAX3100_BIT_NOT_RM (1U<<10)
85 #define MAX3100_BIT_NOT_TM (1U<<11)
86 #define MAX3100_BIT_NOT_FEN (1U<<13)
87 #define MAX3100_T_BIT 14
88 #define MAX3100_R_BIT 15
89 
91 #define Uart3100Init() {} /* Already initialized as a module */
92 #define Uart3100CheckFreeSpace(_len) (((int16_t)max3100_tx_extract_idx - max3100_tx_insert_idx + MAX3100_TX_BUF_LEN - 1) % MAX3100_TX_BUF_LEN >= _len)
93 
94 #define Uart3100Transmit(_x) { max3100_putchar(_x); }
95 #define Uart3100SendMessage() {}
96 #define Uart3100Getch() ({\
97  uint8_t ret = max3100_rx_buf[max3100_rx_extract_idx]; \
98  max3100_rx_extract_idx++; /* Since size=256 */ \
99  ret; \
100 })
101 
102 #define Uart3100ChAvailable() (max3100_rx_extract_idx != max3100_rx_insert_idx)
103 
104 static inline void max3100_transmit(uint16_t data) {
105  Max3100Select();
106  SpiClearRti();
107  SpiEnableRti(); /* enable rx fifo time out */
108  SpiEnable();
109  // SSPDR = data >> 8;
110  // SSPDR = data & 0xff;
111  SSPDR = data;
112 }
113 
114 #define Max3100TransmitConf(_conf) max3100_transmit((_conf) | MAX3100_WRITE_CONF)
115 #define Max3100TransmitData(_data) max3100_transmit((_data) | MAX3100_WRITE_DATA)
116 #define Max3100ReadData() max3100_transmit(MAX3100_READ_DATA)
117 
118 
119 static inline void max3100_read_data(void) {
120  Max3100ReadData();
122 }
123 
124 static inline void max3100_flush( void ) {
129  max3100_tx_extract_idx++; /* automatic overflow since len=256 */
132  }
133 }
134 
136 static inline void max3100_putconfchar(char c) {
139 }
140 
141 static inline void max3100_putchar(char c) {
143  max3100_tx_insert_idx++; /* automatic overflow since len=256 */
144  /* flushed in the next event */
145 }
146 
147 extern void max3100_init( void );
148 extern void max3100_debug( void );
149 
150 static inline void max3100_event( void ) {
151  if (read_bytes) {
152  read_bytes = false;
153  max3100_debug();
154  }
157  max3100_data_available = false;
159  } else
160  max3100_flush();
161  }
162 }
163 
164 
165 #endif /* MAX3100_H */
unsigned short uint16_t
Definition: types.h:16
#define Max3100TransmitConf(_conf)
Definition: max3100_hw.h:114
static void max3100_transmit(uint16_t data)
Definition: max3100_hw.h:104
volatile uint8_t max3100_tx_extract_idx
Definition: max3100_hw.c:37
#define MAX3100_STATUS_WRITING
Definition: max3100_hw.h:39
#define MAX3100_TX_BUF_LEN
I/O Buffers.
Definition: max3100_hw.h:47
volatile uint8_t max3100_tx_insert_idx
Definition: max3100_hw.c:37
void max3100_debug(void)
Definition: max3100_hw.c:163
#define SpiClearRti()
Definition: spi_arch.h:84
volatile uint8_t max3100_tx_buf[MAX3100_TX_BUF_LEN]
Definition: max3100_hw.c:40
volatile uint8_t max3100_rx_buf[MAX3100_RX_BUF_LEN]
Definition: max3100_hw.c:41
volatile uint8_t read_byte2
#define Max3100Select()
Definition: max3100_hw.h:59
static void max3100_event(void)
Definition: max3100_hw.h:150
volatile uint8_t read_byte1
#define SpiEnable()
Definition: spi_arch.h:68
bool read_bytes
Definition: max3100_hw.c:44
volatile uint8_t max3100_rx_insert_idx
Definition: max3100_hw.c:38
#define Max3100ReadData()
Definition: max3100_hw.h:116
volatile bool max3100_data_available
Definition: max3100_hw.c:34
unsigned char uint8_t
Definition: types.h:14
#define SSPDR
Definition: LPC21xx.h:224
#define Max3100TransmitData(_data)
Definition: max3100_hw.h:115
static void max3100_flush(void)
Definition: max3100_hw.h:124
#define MAX3100_STATUS_IDLE
Max3100 protocol status.
Definition: max3100_hw.h:38
#define MAX3100_STATUS_READING
Definition: max3100_hw.h:40
void max3100_init(void)
#define SpiEnableRti()
Definition: spi_arch.h:76
arch independent LED (Light Emitting Diodes) API
static void max3100_putchar(char c)
Definition: max3100_hw.h:141
volatile bool max3100_transmit_buffer_empty
Definition: max3100_hw.c:35
static void max3100_putconfchar(char c)
Warning: No bufferring; SPI must be available.
Definition: max3100_hw.h:136
volatile uint8_t max3100_status
Definition: max3100_hw.c:33
volatile uint8_t max3100_rx_extract_idx
Definition: max3100_hw.c:38
static void max3100_read_data(void)
Definition: max3100_hw.h:119
static struct point c
Definition: discsurvey.c:13
#define MAX3100_RX_BUF_LEN
Definition: max3100_hw.h:48