wl_module.h


1
/*
2
  Copyright (c) 2011 by Ernst Buchmann 
3
  
4
  Code based on the work of Stefan Engelke and Brennan Ball
5
  
6
    Permission is hereby granted, free of charge, to any person 
7
    obtaining a copy of this software and associated documentation 
8
    files (the "Software"), to deal in the Software without 
9
    restriction, including without limitation the rights to use, copy, 
10
    modify, merge, publish, distribute, sublicense, and/or sell copies 
11
    of the Software, and to permit persons to whom the Software is 
12
    furnished to do so, subject to the following conditions:
13
14
    The above copyright notice and this permission notice shall be 
15
    included in all copies or substantial portions of the Software.
16
17
    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
18
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
19
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
20
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 
21
    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 
22
    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
23
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
24
    DEALINGS IN THE SOFTWARE.
25
26
    
27
*/
28
29
#ifndef _WL_MODULE_H_
30
#define _WL_MODULE_H_
31
32
#include <avr/io.h>
33
34
//Externe Variable deklarieren
35
extern volatile uint8_t PTX;
36
37
// WL-Module settings
38
#define wl_module_CH      2
39
#define wl_module_PAYLOAD    32
40
#define wl_module_RF_DR_HIGH  0    //0 = 1Mbps, 1 = 2Mpbs
41
#define wl_module_RF_SETUP    (RF_SETUP_RF_PWR_0 | RF_SETUP_RF_DR_250)  
42
#define wl_module_CONFIG    ( (1<<MASK_RX_DR) | (1<<EN_CRC) | (1<<CRCO) )
43
#define wl_module_TX_NR_0    0
44
#define wl_module_TX_NR_1    1
45
#define wl_module_TX_NR_2    2
46
#define wl_module_TX_NR_3    3
47
#define wl_module_TX_NR_4    4
48
#define wl_module_TX_NR_5    5
49
50
// Pin definitions for chip select and chip enabled of the wl-module
51
#define CE  PINB0
52
#define CSN PINB1
53
54
// Definitions for selecting and enabling wl_module module
55
#define wl_module_CSN_hi     PORTB |=  (1<<CSN);
56
#define wl_module_CSN_lo     PORTB &= ~(1<<CSN);
57
#define wl_module_CE_hi      PORTB |=  (1<<CE);
58
#define wl_module_CE_lo      PORTB &= ~(1<<CE);
59
60
// Defines for setting the wl_module registers for transmitting or receiving mode
61
#define TX_POWERUP wl_module_config_register(CONFIG, wl_module_CONFIG | ( (1<<PWR_UP) | (0<<PRIM_RX) ) )
62
#define RX_POWERUP wl_module_config_register(CONFIG, wl_module_CONFIG | ( (1<<PWR_UP) | (1<<PRIM_RX) ) )
63
64
// Public standard functions
65
extern void wl_module_init();
66
extern void wl_module_config();
67
extern void wl_module_send(uint8_t * value, uint8_t len);
68
extern void wl_module_set_RADDR(uint8_t * adr);
69
extern void wl_module_set_TADDR(uint8_t * adr);
70
extern uint8_t wl_module_data_ready();
71
//extern void wl_module_get_data(uint8_t * data);
72
extern uint8_t wl_module_get_data(uint8_t * data);      //Gibt die Werte des STATUS-Registers zurück
73
74
//Public functions
75
76
extern uint8_t wl_module_get_status();
77
extern uint8_t wl_module_get_rx_pipe_reading_status();
78
extern uint8_t wl_module_get_one_byte(uint8_t command);
79
extern void wl_module_set_rx_pw(unsigned char payloadwidth, unsigned char rxpipenum);
80
extern uint8_t wl_module_get_rx_pw(uint8_t rxpipenum);
81
extern void wl_module_set_tx_addr(uint8_t * address, uint8_t len);
82
extern void wl_module_set_rx_addr(uint8_t * address, uint8_t len, uint8_t rxpipenum);
83
extern void wl_module_tx_config(uint8_t tx_nr);
84
extern void wl_module_rx_config();
85
extern void wl_module_get_rx_addr(uint8_t * data, uint8_t rxpipenum, uint8_t len);
86
extern uint8_t wl_module_get_rx_pipe();
87
extern uint8_t wl_module_get_rx_pipe_from_status(uint8_t status);
88
extern uint8_t wl_module_fifo_tx_empty();  //returns true if TX_EMPTY bit in FIFO_STATUS register is set, false otherwise
89
extern uint8_t wl_module_fifo_rx_empty();
90
extern uint8_t wl_module_get_rf_ch();
91
extern uint8_t wl_module_get_rf_setup();
92
extern uint8_t wl_module_get_plos_cnt();
93
extern uint8_t wl_module_get_arc_cnt();
94
extern void wl_module_set_as_tx();      //activate module with existing config
95
extern void wl_module_power_down();      //powers down the module with existing config
96
97
// Public extended functions
98
extern void wl_module_config_register(uint8_t reg, uint8_t value);
99
extern void wl_module_read_register(uint8_t reg, uint8_t * value, uint8_t len);
100
extern void wl_module_write_register(uint8_t reg, uint8_t * value, uint8_t len);
101
102
#endif /* _SETUP_NRF24L01_H_ */