00001 /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved. 00002 * 00003 * The information contained herein is confidential property of Nordic 00004 * Semiconductor ASA.Terms and conditions of usage are described in detail 00005 * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 00006 * 00007 * Licensees are granted free, non-transferable use of the information. NO 00008 * WARRENTY of ANY KIND is provided. This heading must NOT be removed from 00009 * the file. 00010 * 00011 * $LastChangedRevision: 133 $ 00012 */ 00013 00018 #include "nrf24le1.h" 00019 #include "hal_rtc.h" 00020 #include "nordic_common.h" 00021 00022 void hal_rtc_capture(void) 00023 { 00024 RTC2CON |= BIT_4; // Set "sfrCapture" bit(Trig. sig.) 00025 } 00026 00027 void hal_rtc_radio_capture_enable(bool en) 00028 { 00029 if(en) 00030 { 00031 RTC2CON |= BIT_3; // Set "enableExtCapture" bit 00032 } 00033 else 00034 { 00035 RTC2CON &= ~BIT_3; // Clear "enableExtCapture" bit 00036 } 00037 } 00038 00039 void hal_rtc_set_compare_mode(hal_rtc_compare_mode_t mode) 00040 { 00041 RTC2CON = (RTC2CON & 0xF9) | ((mode << 1) & ~0xF9); // Set "compareMode" bits 00042 } 00043 00044 void hal_rtc_start(bool en) 00045 { 00046 if(en) 00047 { 00048 RTC2CON |= BIT_0; // Set "rtc2Enable" bit 00049 } 00050 else 00051 { 00052 RTC2CON &= ~BIT_0; // Clear "rtc2Enable" bit 00053 } 00054 } 00055 00056 void hal_rtc_set_compare_value(uint16_t value) 00057 { 00058 uint8_t compare_status; 00059 compare_status = (RTC2CON & (BIT_1 | BIT_2)); // Save "compareMode" bits 00060 RTC2CON &= ~(BIT_1 | BIT_2); // Disable compare 00061 RTC2CMP0 = LSB(value); // Write LSB 00062 RTC2CMP1 = MSB(value); // Write MSB 00063 RTC2CON |= compare_status; // Update compare status 00064 } 00065 00066 uint16_t hal_rtc_get_compare_value(void) 00067 { 00068 uint8_t compare_status; 00069 uint16_t value; // Create temporary output variable 00070 compare_status = (RTC2CON & (BIT_1 | BIT_2)); // Save "compareMode" bits 00071 RTC2CON &= ~(BIT_1 | BIT_2); // Disable compare 00072 value = RTC2CMP1; // Read MSB 00073 value <<= 8; // Shift to correct position 00074 value |= RTC2CMP0; // Add LSB 00075 RTC2CON |= compare_status; // Update compare status 00076 return value; // Return compare value 00077 } 00078 00079 uint16_t hal_rtc_get_capture_value(void) 00080 { 00081 uint8_t capture_status; 00082 uint16_t value; // Create temporary output variable 00083 capture_status = (RTC2CON & BIT_3); // Save "compareMode" bits 00084 RTC2CON &= ~BIT_3; // Disable compare 00085 value = RTC2CPT01; // Read MSB 00086 value <<= 8; // Shift to correct position 00087 value |= RTC2CPT00; // Add LSB 00088 RTC2CON |= capture_status; // Update external capture status 00089 return value; // Return timer value 00090 } 00091 00092 uint8_t hal_rtc_get_capture_clock_cycles(void) 00093 { 00094 return RTC2CPT10; // Return register 00095 }