Contiki 3.x
hal.c
Go to the documentation of this file.
1 /* Copyright (c) 2008, Swedish Institute of Computer Science
2  * All rights reserved.
3  *
4  * Additional fixes for AVR contributed by:
5  *
6  * Colin O'Flynn coflynn@newae.com
7  * Eric Gnoske egnoske@gmail.com
8  * Blake Leverett bleverett@gmail.com
9  * Mike Vidales mavida404@gmail.com
10  * Kevin Brown kbrown3@uccs.edu
11  * Nate Bohlmann nate@elfwerks.com
12  *
13  * All rights reserved.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are met:
17  *
18  * * Redistributions of source code must retain the above copyright
19  * notice, this list of conditions and the following disclaimer.
20  * * Redistributions in binary form must reproduce the above copyright
21  * notice, this list of conditions and the following disclaimer in
22  * the documentation and/or other materials provided with the
23  * distribution.
24  * * Neither the name of the copyright holders nor the names of
25  * contributors may be used to endorse or promote products derived
26  * from this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
32  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38  * POSSIBILITY OF SUCH DAMAGE.
39  *
40 */
41 
42 /**
43  * \addtogroup wireless
44  * @{
45 */
46 
47 /**
48  * \defgroup hal RF230 hardware level drivers
49  * @{
50  */
51 
52 /**
53  * \file
54  * This file contains low-level radio driver code.
55  */
56 
57 
58 
59 /*============================ INCLUDE =======================================*/
60 #include <stdlib.h>
61 
62 #include "hal.h"
63 #include "at86rf230_registermap.h"
64 /*============================ MACROS ========================================*/
65 
66 /*
67  * Macros defined for the radio transceiver's access modes.
68  *
69  * These functions are implemented as macros since they are used very often.
70  */
71 #define HAL_DUMMY_READ (0x00) /**< Dummy value for the SPI. */
72 
73 #define HAL_TRX_CMD_RW (0xC0) /**< Register Write (short mode). */
74 #define HAL_TRX_CMD_RR (0x80) /**< Register Read (short mode). */
75 #define HAL_TRX_CMD_FW (0x60) /**< Frame Transmit Mode (long mode). */
76 #define HAL_TRX_CMD_FR (0x20) /**< Frame Receive Mode (long mode). */
77 #define HAL_TRX_CMD_SW (0x40) /**< SRAM Write. */
78 #define HAL_TRX_CMD_SR (0x00) /**< SRAM Read. */
79 #define HAL_TRX_CMD_RADDRM (0x7F) /**< Register Address Mask. */
80 
81 #define HAL_CALCULATED_CRC_OK (0) /**< CRC calculated over the frame including the CRC field should be 0. */
82 /*============================ TYPDEFS =======================================*/
83 /*============================ VARIABLES =====================================*/
84 /** \brief This is a file internal variable that contains the 16 MSB of the
85  * system time.
86  *
87  * The system time (32-bit) is the current time in microseconds. For the
88  * AVR microcontroller implementation this is solved by using a 16-bit
89  * timer (Timer1) with a clock frequency of 1MHz. The hal_system_time is
90  * incremented when the 16-bit timer overflows, representing the 16 MSB.
91  * The timer value it self (TCNT1) is then the 16 LSB.
92  *
93  * \see hal_get_system_time
94  */
95 static uint16_t hal_system_time = 0;
96 
97 /*Flag section.*/
98 static uint8_t volatile hal_bat_low_flag; /**< BAT_LOW flag. */
99 static uint8_t volatile hal_pll_lock_flag; /**< PLL_LOCK flag. */
100 
101 /*Callbacks.*/
102 
103 /** \brief This function is called when a rx_start interrupt is signaled.
104  *
105  * If this function pointer is set to something else than NULL, it will
106  * be called when a RX_START event is signaled. The function takes two
107  * parameters: timestamp in IEEE 802.15.4 symbols (16 us resolution) and
108  * frame length. The event handler will be called in the interrupt domain,
109  * so the function must be kept short and not be blocking! Otherwise the
110  * system performance will be greatly degraded.
111  *
112  * \see hal_set_rx_start_event_handler
113  */
114 static hal_rx_start_isr_event_handler_t rx_start_callback;
115 
116 /** \brief This function is called when a trx_end interrupt is signaled.
117  *
118  * If this function pointer is set to something else than NULL, it will
119  * be called when a TRX_END event is signaled. The function takes one
120  * parameter: timestamp in IEEE 802.15.4 symbols (16 us resolution).
121  * The event handler will be called in the interrupt domain,
122  * so the function must not block!
123  *
124  * \see hal_set_trx_end_event_handler
125  */
126 static hal_trx_end_isr_event_handler_t trx_end_callback;
127 /*============================ PROTOTYPES ====================================*/
128 /*============================ IMPLEMENTATION ================================*/
129 
130 /** \brief This function initializes the Hardware Abstraction Layer.
131  */
132 void
133 hal_init(void)
134 {
135  /*Reset variables used in file.*/
136  hal_system_time = 0;
137  hal_reset_flags();
138 
139  /*IO Specific Initialization.*/
140  DDR_SLP_TR |= (1 << SLP_TR); /* Enable SLP_TR as output. */
141  DDR_RST |= (1 << RST); /* Enable RST as output. */
142 
143  /*SPI Specific Initialization.*/
144  /* Set SS, CLK and MOSI as output. */
145  HAL_DDR_SPI |= (1 << HAL_DD_SS) | (1 << HAL_DD_SCK) | (1 << HAL_DD_MOSI);
146  HAL_PORT_SPI |= (1 << HAL_DD_SS) | (1 << HAL_DD_SCK); /* Set SS and CLK high */
147  /* Run SPI at max speed */
148  SPCR = (1 << SPE) | (1 << MSTR); /* Enable SPI module and master operation. */
149  SPSR = (1 << SPI2X); /* Enable doubled SPI speed in master mode. */
150 
151  /*TIMER1 Specific Initialization.*/
152  TCCR1B = HAL_TCCR1B_CONFIG; /* Set clock prescaler */
153  TIFR1 |= (1 << ICF1); /* Clear Input Capture Flag. */
154  HAL_ENABLE_OVERFLOW_INTERRUPT(); /* Enable Timer1 overflow interrupt. */
155  hal_enable_trx_interrupt(); /* Enable interrupts from the radio transceiver. */
156 }
157 
158 /*----------------------------------------------------------------------------*/
159 /** \brief This function reset the interrupt flags and interrupt event handlers
160  * (Callbacks) to their default value.
161  */
162 void
164 {
166 
167  /* Reset Flags. */
168  hal_bat_low_flag = 0;
169  hal_pll_lock_flag = 0;
170 
171  /* Reset Associated Event Handlers. */
172  rx_start_callback = NULL;
173  trx_end_callback = NULL;
174 
176 }
177 
178 /*----------------------------------------------------------------------------*/
179 /** \brief This function returns the current value of the BAT_LOW flag.
180  *
181  * The BAT_LOW flag is incremented each time a BAT_LOW event is signaled from the
182  * radio transceiver. This way it is possible for the end user to poll the flag
183  * for new event occurances.
184  */
185 uint8_t
187 {
188  return hal_bat_low_flag;
189 }
190 
191 /*----------------------------------------------------------------------------*/
192 /** \brief This function clears the BAT_LOW flag.
193  */
194 void
196 {
198  hal_bat_low_flag = 0;
200 }
201 
202 /*----------------------------------------------------------------------------*/
203 /** \brief This function is used to set new TRX_END event handler, overriding
204  * old handler reference.
205  */
208 {
209  return trx_end_callback;
210 }
211 
212 /*----------------------------------------------------------------------------*/
213 /** \brief This function is used to set new TRX_END event handler, overriding
214  * old handler reference.
215  */
216 void
218 {
220  trx_end_callback = trx_end_callback_handle;
222 }
223 
224 /*----------------------------------------------------------------------------*/
225 /** \brief Remove event handler reference.
226  */
227 void
229 {
231  trx_end_callback = NULL;
233 }
234 
235 /*----------------------------------------------------------------------------*/
236 /** \brief This function returns the active RX_START event handler
237  *
238  * \return Current RX_START event handler registered.
239  */
242 {
243  return rx_start_callback;
244 }
245 
246 /*----------------------------------------------------------------------------*/
247 /** \brief This function is used to set new RX_START event handler, overriding
248  * old handler reference.
249  */
250 void
252 {
254  rx_start_callback = rx_start_callback_handle;
256 }
257 
258 /*----------------------------------------------------------------------------*/
259 /** \brief Remove event handler reference.
260  */
261 void
263 {
265  rx_start_callback = NULL;
267 }
268 
269 /*----------------------------------------------------------------------------*/
270 /** \brief This function returns the current value of the PLL_LOCK flag.
271  *
272  * The PLL_LOCK flag is incremented each time a PLL_LOCK event is signaled from the
273  * radio transceiver. This way it is possible for the end user to poll the flag
274  * for new event occurances.
275  */
276 uint8_t
278 {
279  return hal_pll_lock_flag;
280 }
281 
282 /*----------------------------------------------------------------------------*/
283 /** \brief This function clears the PLL_LOCK flag.
284  */
285 void
287 {
289  hal_pll_lock_flag = 0;
291 }
292 
293 /*----------------------------------------------------------------------------*/
294 /** \brief This function reads data from one of the radio transceiver's registers.
295  *
296  * \param address Register address to read from. See datasheet for register
297  * map.
298  *
299  * \see Look at the at86rf230_registermap.h file for register address definitions.
300  *
301  * \returns The actual value of the read register.
302  */
303 uint8_t
304 hal_register_read(uint8_t address)
305 {
306  /* Add the register read command to the register address. */
307  address &= HAL_TRX_CMD_RADDRM;
308  address |= HAL_TRX_CMD_RR;
309 
310  uint8_t register_value = 0;
311 
313 
314  HAL_SS_LOW(); /* Start the SPI transaction by pulling the Slave Select low. */
315 
316  /*Send Register address and read register content.*/
317  SPDR = address;
318  while ((SPSR & (1 << SPIF)) == 0) {;}
319  register_value = SPDR;
320 
321  SPDR = register_value;
322  while ((SPSR & (1 << SPIF)) == 0) {;}
323  register_value = SPDR;
324 
325  HAL_SS_HIGH(); /* End the transaction by pulling the Slave Select High. */
326 
328 
329  return register_value;
330 }
331 
332 /*----------------------------------------------------------------------------*/
333 /** \brief This function writes a new value to one of the radio transceiver's
334  * registers.
335  *
336  * \see Look at the at86rf230_registermap.h file for register address definitions.
337  *
338  * \param address Address of register to write.
339  * \param value Value to write.
340  */
341 void
342 hal_register_write(uint8_t address, uint8_t value)
343 {
344  /* Add the Register Write command to the address. */
345  address = HAL_TRX_CMD_RW | (HAL_TRX_CMD_RADDRM & address);
346 
348 
349  HAL_SS_LOW(); /* Start the SPI transaction by pulling the Slave Select low. */
350 
351  /*Send Register address and write register content.*/
352  SPDR = address;
353  while ((SPSR & (1 << SPIF)) == 0) {;}
354  uint8_t dummy_read = SPDR;
355 
356  SPDR = value;
357  while ((SPSR & (1 << SPIF)) == 0) {;}
358  dummy_read = SPDR;
359 
360  HAL_SS_HIGH(); /* End the transaction by pulling the Slave Slect High. */
361 
363 }
364 
365 /*----------------------------------------------------------------------------*/
366 /** \brief This function reads the value of a specific subregister.
367  *
368  * \see Look at the at86rf230_registermap.h file for register and subregister
369  * definitions.
370  *
371  * \param address Main register's address.
372  * \param mask Bit mask of the subregister.
373  * \param position Bit position of the subregister
374  * \retval Value of the read subregister.
375  */
376 uint8_t
377 hal_subregister_read(uint8_t address, uint8_t mask, uint8_t position)
378 {
379  /* Read current register value and mask out subregister. */
380  uint8_t register_value = hal_register_read(address);
381  register_value &= mask;
382  register_value >>= position; /* Align subregister value. */
383 
384  return register_value;
385 }
386 
387 /*----------------------------------------------------------------------------*/
388 /** \brief This function writes a new value to one of the radio transceiver's
389  * subregisters.
390  *
391  * \see Look at the at86rf230_registermap.h file for register and subregister
392  * definitions.
393  *
394  * \param address Main register's address.
395  * \param mask Bit mask of the subregister.
396  * \param position Bit position of the subregister
397  * \param value Value to write into the subregister.
398  */
399 void
400 hal_subregister_write(uint8_t address, uint8_t mask, uint8_t position,
401  uint8_t value)
402 {
403  /* Read current register value and mask area outside the subregister. */
404  uint8_t register_value = hal_register_read(address);
405  register_value &= ~mask;
406 
407  /* Start preparing the new subregister value. shift in place and mask. */
408  value <<= position;
409  value &= mask;
410 
411  value |= register_value; /* Set the new subregister value. */
412 
413  /* Write the modified register value. */
414  hal_register_write(address, value);
415 }
416 
417 /*----------------------------------------------------------------------------*/
418 /** \brief This function will upload a frame from the radio transceiver's frame
419  * buffer.
420  *
421  * If the frame currently available in the radio transceiver's frame buffer
422  * is out of the defined bounds. Then the frame length, lqi value and crc
423  * be set to zero. This is done to indicate an error.
424  *
425  * \param rx_frame Pointer to the data structure where the frame is stored.
426  * \param rx_callback Pointer to callback function for receiving one byte at a time.
427  */
428 void
429 hal_frame_read(hal_rx_frame_t *rx_frame, rx_callback_t rx_callback)
430 {
431  uint8_t *rx_data=0;
432 
433  /* check that we have either valid frame pointer or callback pointer */
434  if (!rx_frame && !rx_callback)
435  return;
436 
438 
439  HAL_SS_LOW();
440 
441  /*Send frame read command.*/
442  SPDR = HAL_TRX_CMD_FR;
443  while ((SPSR & (1 << SPIF)) == 0) {;}
444  uint8_t frame_length = SPDR;
445 
446  /*Read frame length.*/
447  SPDR = frame_length;
448  while ((SPSR & (1 << SPIF)) == 0) {;}
449  frame_length = SPDR;
450 
451  /*Check for correct frame length.*/
452  if ((frame_length >= HAL_MIN_FRAME_LENGTH) && (frame_length <= HAL_MAX_FRAME_LENGTH)){
453  uint16_t crc = 0;
454  if (rx_frame){
455  rx_data = (rx_frame->data);
456  rx_frame->length = frame_length; /* Store frame length. */
457  } else {
458  rx_callback(frame_length);
459  }
460  /*Upload frame buffer to data pointer. Calculate CRC.*/
461  SPDR = frame_length;
462  while ((SPSR & (1 << SPIF)) == 0) {;}
463 
464  do{
465  uint8_t tempData = SPDR;
466  SPDR = 0; /* dummy write */
467 
468  if (rx_frame){
469  *rx_data++ = tempData;
470  } else {
471  rx_callback(tempData);
472  }
473 
474  crc = _crc_ccitt_update(crc, tempData);
475 
476  while ((SPSR & (1 << SPIF)) == 0) {;}
477 
478  } while (--frame_length > 0);
479 
480  /*Read LQI value for this frame.*/
481  if (rx_frame){
482  rx_frame->lqi = SPDR;
483  } else {
484  rx_callback(SPDR);
485  }
486 
487  HAL_SS_HIGH();
488 
489  /*Check calculated crc, and set crc field in hal_rx_frame_t accordingly.*/
490  if (rx_frame){
491  rx_frame->crc = (crc == HAL_CALCULATED_CRC_OK);
492  } else {
493  rx_callback(crc != HAL_CALCULATED_CRC_OK);
494  }
495  } else {
496  HAL_SS_HIGH();
497 
498  if (rx_frame){
499  rx_frame->length = 0;
500  rx_frame->lqi = 0;
501  rx_frame->crc = false;
502  }
503  }
504 
506 }
507 
508 /*----------------------------------------------------------------------------*/
509 /** \brief This function will download a frame to the radio transceiver's frame
510  * buffer.
511  *
512  * \param write_buffer Pointer to data that is to be written to frame buffer.
513  * \param length Length of data. The maximum length is 127 bytes.
514  */
515 void
516 hal_frame_write(uint8_t *write_buffer, uint8_t length)
517 {
518  length &= HAL_TRX_CMD_RADDRM; /* Truncate length to maximum frame length. */
519 
521 
522  HAL_SS_LOW(); /* Initiate the SPI transaction. */
523 
524  /*SEND FRAME WRITE COMMAND AND FRAME LENGTH.*/
525  SPDR = HAL_TRX_CMD_FW;
526  while ((SPSR & (1 << SPIF)) == 0) {;}
527  uint8_t dummy_read = SPDR;
528 
529  SPDR = length;
530  while ((SPSR & (1 << SPIF)) == 0) {;}
531  dummy_read = SPDR;
532 
533  /* Download to the Frame Buffer. */
534  do{
535  SPDR = *write_buffer++;
536  --length;
537 
538  while ((SPSR & (1 << SPIF)) == 0) {;}
539 
540  dummy_read = SPDR;
541  } while (length > 0);
542 
543  HAL_SS_HIGH(); /* Terminate SPI transaction. */
544 
546 }
547 
548 /*----------------------------------------------------------------------------*/
549 /** \brief Read SRAM
550  *
551  * This function reads from the SRAM of the radio transceiver.
552  *
553  * \param address Address in the TRX's SRAM where the read burst should start
554  * \param length Length of the read burst
555  * \param data Pointer to buffer where data is stored.
556  */
557 void
558 hal_sram_read(uint8_t address, uint8_t length, uint8_t *data)
559 {
561 
562  HAL_SS_LOW(); /* Initiate the SPI transaction. */
563 
564  /*Send SRAM read command.*/
565  SPDR = HAL_TRX_CMD_SR;
566  while ((SPSR & (1 << SPIF)) == 0) {;}
567  uint8_t dummy_read = SPDR;
568 
569  /*Send address where to start reading.*/
570  SPDR = address;
571  while ((SPSR & (1 << SPIF)) == 0) {;}
572 
573  dummy_read = SPDR;
574 
575  /*Upload the chosen memory area.*/
576  do{
577  SPDR = HAL_DUMMY_READ;
578  while ((SPSR & (1 << SPIF)) == 0) {;}
579  *data++ = SPDR;
580  } while (--length > 0);
581 
582  HAL_SS_HIGH();
583 
585 }
586 
587 /*----------------------------------------------------------------------------*/
588 /** \brief Write SRAM
589  *
590  * This function writes into the SRAM of the radio transceiver.
591  *
592  * \param address Address in the TRX's SRAM where the write burst should start
593  * \param length Length of the write burst
594  * \param data Pointer to an array of bytes that should be written
595  */
596 void
597 hal_sram_write(uint8_t address, uint8_t length, uint8_t *data)
598 {
600 
601  HAL_SS_LOW();
602 
603  /*Send SRAM write command.*/
604  SPDR = HAL_TRX_CMD_SW;
605  while ((SPSR & (1 << SPIF)) == 0) {;}
606  uint8_t dummy_read = SPDR;
607 
608  /*Send address where to start writing to.*/
609  SPDR = address;
610  while ((SPSR & (1 << SPIF)) == 0) {;}
611  dummy_read = SPDR;
612 
613  /*Upload the chosen memory area.*/
614  do{
615  SPDR = *data++;
616  while ((SPSR & (1 << SPIF)) == 0) {;}
617  dummy_read = SPDR;
618  } while (--length > 0);
619 
620  HAL_SS_HIGH();
621 
623 }
624 
625 /*----------------------------------------------------------------------------*/
626 /* This #if compile switch is used to provide a "standard" function body for the */
627 /* doxygen documentation. */
628 #if defined(DOXYGEN)
629 /** \brief ISR for the radio IRQ line, triggered by the input capture.
630  * This is the interrupt service routine for timer1.ICIE1 input capture.
631  * It is triggered of a rising edge on the radio transceivers IRQ line.
632  */
633 void RADIO_VECT(void);
634 #else /* !DOXYGEN */
635 ISR(RADIO_VECT)
636 {
637  /*The following code reads the current system time. This is done by first
638  reading the hal_system_time and then adding the 16 LSB directly from the
639  TCNT1 register.
640  */
641  uint32_t isr_timestamp = hal_system_time;
642  isr_timestamp <<= 16;
643  isr_timestamp |= TCNT1;
644 
645  /*Read Interrupt source.*/
646  HAL_SS_LOW();
647 
648  /*Send Register address and read register content.*/
649  SPDR = RG_IRQ_STATUS | HAL_TRX_CMD_RR;
650 
651  /* This is the second part of the convertion of system time to a 16 us time
652  base. The division is moved here so we can spend less time waiting for SPI
653  data.
654  */
655  isr_timestamp /= HAL_US_PER_SYMBOL; /* Divide so that we get time in 16us resolution. */
656  isr_timestamp &= HAL_SYMBOL_MASK;
657 
658  while ((SPSR & (1 << SPIF)) == 0) {;}
659  uint8_t interrupt_source = SPDR; /* The interrupt variable is used as a dummy read. */
660 
661  SPDR = interrupt_source;
662  while ((SPSR & (1 << SPIF)) == 0) {;}
663  interrupt_source = SPDR; /* The interrupt source is read. */
664 
665  HAL_SS_HIGH();
666 
667  /*Handle the incomming interrupt. Prioritized.*/
668  if ((interrupt_source & HAL_RX_START_MASK)){
669  if(rx_start_callback != NULL){
670  /* Read Frame length and call rx_start callback. */
671  HAL_SS_LOW();
672 
673  SPDR = HAL_TRX_CMD_FR;
674  while ((SPSR & (1 << SPIF)) == 0) {;}
675  uint8_t frame_length = SPDR;
676 
677  SPDR = frame_length; /* frame_length used for dummy data */
678  while ((SPSR & (1 << SPIF)) == 0) {;}
679  frame_length = SPDR;
680 
681  HAL_SS_HIGH();
682 
683  rx_start_callback(isr_timestamp, frame_length);
684  }
685  } else if (interrupt_source & HAL_TRX_END_MASK){
686  if(trx_end_callback != NULL){
687  trx_end_callback(isr_timestamp);
688  }
689  } else if (interrupt_source & HAL_TRX_UR_MASK){
690  ;
691  } else if (interrupt_source & HAL_PLL_UNLOCK_MASK){
692  ;
693  } else if (interrupt_source & HAL_PLL_LOCK_MASK){
694  hal_pll_lock_flag++;
695  ;
696  } else if (interrupt_source & HAL_BAT_LOW_MASK){
697  /* Disable BAT_LOW interrupt to prevent endless interrupts. The interrupt */
698  /* will continously be asserted while the supply voltage is less than the */
699  /* user-defined voltage threshold. */
700  uint8_t trx_isr_mask = hal_register_read(RG_IRQ_MASK);
701  trx_isr_mask &= ~HAL_BAT_LOW_MASK;
702  hal_register_write(RG_IRQ_MASK, trx_isr_mask);
703  hal_bat_low_flag++; /* Increment BAT_LOW flag. */
704  } else {
705  ;
706  }
707 }
708 # endif /* defined(DOXYGEN) */
709 
710 /*----------------------------------------------------------------------------*/
711 /* This #if compile switch is used to provide a "standard" function body for the */
712 /* doxygen documentation. */
713 #if defined(DOXYGEN)
714 /** \brief Timer Overflow ISR
715  * This is the interrupt service routine for timer1 overflow.
716  */
717 void TIMER1_OVF_vect(void);
718 #else /* !DOXYGEN */
719 ISR(TIMER1_OVF_vect)
720 {
721  hal_system_time++;
722 }
723 #endif
724 
725 /** @} */
726 /** @} */
727 
728 /*EOF*/
void hal_reset_flags(void)
This function reset the interrupt flags and interrupt event handlers (Callbacks) to their default val...
Definition: hal.c:163
#define HAL_DD_SCK
Data Direction bit for SCK.
Definition: hal.h:262
#define DDR_RST
Data Direction Register that corresponds to the port where RST is.
Definition: hal.h:252
#define HAL_TRX_CMD_FW
Frame Transmit Mode (long mode).
Definition: hal.c:75
uint8_t hal_get_bat_low_flag(void)
This function returns the current value of the BAT_LOW flag.
Definition: hal.c:186
uint8_t lqi
LQI value for received frame.
Definition: hal.h:354
#define RG_IRQ_MASK
Offset for register IRQ_MASK.
#define hal_enable_trx_interrupt()
Enable the interrupt from the radio transceiver.
Definition: hal.h:322
uint8_t hal_register_read(uint8_t address)
This function reads data from one of the radio transceiver&#39;s registers.
Definition: hal.c:304
#define RG_IRQ_STATUS
Offset for register IRQ_STATUS.
void hal_clear_pll_lock_flag(void)
This function clears the PLL_LOCK flag.
Definition: hal.c:286
void hal_clear_bat_low_flag(void)
This function clears the BAT_LOW flag.
Definition: hal.c:195
hal_trx_end_isr_event_handler_t hal_get_trx_end_event_handler(void)
This function is used to set new TRX_END event handler, overriding old handler reference.
Definition: hal.c:207
#define HAL_BAT_LOW_MASK
Mask for the BAT_LOW interrupt.
Definition: hal.h:335
#define HAL_DUMMY_READ
Dummy value for the SPI.
Definition: hal.c:71
#define HAL_CALCULATED_CRC_OK
CRC calculated over the frame including the CRC field should be 0.
Definition: hal.c:81
#define HAL_DD_SS
Data Direction bit for SS.
Definition: hal.h:261
#define HAL_TRX_CMD_SW
SRAM Write.
Definition: hal.c:77
#define AVR_ENTER_CRITICAL_REGION()
This macro will protect the following code from interrupts.
Definition: hal.h:313
#define DDR_SLP_TR
Data Direction Register that corresponds to the port where SLP_TR is connected.
Definition: hal.h:245
#define AVR_LEAVE_CRITICAL_REGION()
This macro must always be used in conjunction with AVR_ENTER_CRITICAL_REGION so that interrupts are e...
Definition: hal.h:317
void hal_clear_rx_start_event_handler(void)
Remove event handler reference.
Definition: hal.c:262
uint8_t length
Length of frame.
Definition: hal.h:352
uint8_t hal_get_pll_lock_flag(void)
This function returns the current value of the PLL_LOCK flag.
Definition: hal.c:277
uint8_t hal_subregister_read(uint8_t address, uint8_t mask, uint8_t position)
This function reads the value of a specific subregister.
Definition: hal.c:377
#define NULL
The null pointer.
This file contains low-level radio driver code.
void hal_init(void)
This function initializes the Hardware Abstraction Layer.
Definition: hal.c:133
This struct defines the rx data container.
Definition: hal.h:351
void hal_subregister_write(uint8_t address, uint8_t mask, uint8_t position, uint8_t value)
This function writes a new value to one of the radio transceiver&#39;s subregisters.
Definition: hal.c:400
#define HAL_SS_LOW()
MACRO for pulling SS low.
Definition: hal.h:269
uint8_t data[HAL_MAX_FRAME_LENGTH]
Actual frame data.
Definition: hal.h:353
void hal_sram_read(uint8_t address, uint8_t length, uint8_t *data)
Read SRAM.
Definition: hal.c:558
bool crc
Flag - did CRC pass for received frame?
Definition: hal.h:355
void hal_frame_read(hal_rx_frame_t *rx_frame, rx_callback_t rx_callback)
This function will upload a frame from the radio transceiver&#39;s frame buffer.
Definition: hal.c:429
#define RST
Pin number that corresponds to the RST pin.
Definition: hal.h:251
#define HAL_TRX_CMD_RR
Register Read (short mode).
Definition: hal.c:74
void(* hal_trx_end_isr_event_handler_t)(uint32_t const isr_timestamp)
RRX_END event handler callback type.
Definition: hal.h:362
#define HAL_PLL_LOCK_MASK
Mask for the PLL_LOCK interrupt.
Definition: hal.h:340
void hal_sram_write(uint8_t address, uint8_t length, uint8_t *data)
Write SRAM.
Definition: hal.c:597
#define HAL_TRX_CMD_SR
SRAM Read.
Definition: hal.c:78
This file contains the register definitions for the AT86RF230.
#define HAL_RX_START_MASK
Mask for the RX_START interrupt.
Definition: hal.h:338
#define HAL_TRX_UR_MASK
Mask for the TRX_UR interrupt.
Definition: hal.h:336
#define HAL_TRX_CMD_RADDRM
Register Address Mask.
Definition: hal.c:79
void hal_frame_write(uint8_t *write_buffer, uint8_t length)
This function will download a frame to the radio transceiver&#39;s frame buffer.
Definition: hal.c:516
#define HAL_TRX_CMD_RW
Register Write (short mode).
Definition: hal.c:73
#define HAL_PLL_UNLOCK_MASK
Mask for the PLL_UNLOCK interrupt.
Definition: hal.h:339
void RADIO_VECT(void)
ISR for the radio IRQ line, triggered by the input capture.
void hal_set_rx_start_event_handler(hal_rx_start_isr_event_handler_t rx_start_callback_handle)
This function is used to set new RX_START event handler, overriding old handler reference.
Definition: hal.c:251
hal_rx_start_isr_event_handler_t hal_get_rx_start_event_handler(void)
This function returns the active RX_START event handler.
Definition: hal.c:241
#define HAL_MAX_FRAME_LENGTH
A frame should no more than 127 bytes.
Definition: hal.h:343
void hal_clear_trx_end_event_handler(void)
Remove event handler reference.
Definition: hal.c:228
#define HAL_DDR_SPI
Data Direction Register for PORTB.
Definition: hal.h:260
#define HAL_PORT_SPI
The SPI module is located on PORTB.
Definition: hal.h:259
#define HAL_TRX_CMD_FR
Frame Receive Mode (long mode).
Definition: hal.c:76
void hal_register_write(uint8_t address, uint8_t value)
This function writes a new value to one of the radio transceiver&#39;s registers.
Definition: hal.c:342
#define HAL_DD_MOSI
Data Direction bit for MOSI.
Definition: hal.h:263
#define SLP_TR
Pin number that corresponds to the SLP_TR pin.
Definition: hal.h:244
#define HAL_MIN_FRAME_LENGTH
A frame should be at least 3 bytes.
Definition: hal.h:342
#define HAL_TRX_END_MASK
Mask for the TRX_END interrupt.
Definition: hal.h:337
#define HAL_SS_HIGH()
MACRO for pulling SS high.
Definition: hal.h:268
void TIMER1_OVF_vect(void)
Timer Overflow ISR This is the interrupt service routine for timer1 overflow.
void hal_set_trx_end_event_handler(hal_trx_end_isr_event_handler_t trx_end_callback_handle)
This function is used to set new TRX_END event handler, overriding old handler reference.
Definition: hal.c:217
void(* hal_rx_start_isr_event_handler_t)(uint32_t const isr_timestamp, uint8_t const frame_length)
RX_START event handler callback type.
Definition: hal.h:359