takashi kadono / Mbed OS Nucleo_446

Dependencies:   ssd1331

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers pn512_timer.c Source File

pn512_timer.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2014-2018, ARM Limited, All Rights Reserved
00003  * SPDX-License-Identifier: Apache-2.0
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License"); you may
00006  * not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  * http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
00013  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 /**
00018  * \file pn512_timer.c
00019  * \copyright Copyright (c) ARM Ltd 2014
00020  * \author Donatien Garnier
00021  */
00022 
00023 #include "stack/nfc_errors.h"
00024 
00025 #include "pn512_timer.h"
00026 #include "pn512_registers.h"
00027 
00028 void pn512_timer_config(pn512_t *pPN512, bool autostart, uint16_t prescaler, uint16_t countdown_value)
00029 {
00030     pn512_timer_stop(pPN512); //just in case...
00031 
00032     pn512_register_write(pPN512, PN512_REG_TRELOADLOW, countdown_value & 0xFF);
00033     pn512_register_write(pPN512, PN512_REG_TRELOADHIGH, (countdown_value >> 8) & 0xFF);
00034 
00035     pn512_register_write(pPN512, PN512_REG_TPRESCALERLOW, prescaler & 0xFF);
00036     pn512_register_write(pPN512, PN512_REG_TMODE_TPRESCALERHIGH, (autostart ? 0x80 : 0x00) | ((prescaler >> 8) & 0x0F));
00037 }
00038 
00039 void pn512_timer_start(pn512_t *pPN512)
00040 {
00041     //The control register also contains the initiator bit that we must set correctly
00042     switch (pPN512->framing) {
00043         case nfc_framing_initiator_a_106:
00044         case nfc_framing_initiator_f_212:
00045         case nfc_framing_initiator_f_424:
00046             pn512_register_write(pPN512, PN512_REG_CONTROL, 0x50);
00047             break;
00048         case nfc_framing_target_mode_detector:
00049         case nfc_framing_target_a_106:
00050         case nfc_framing_target_f_212:
00051         case nfc_framing_target_f_424:
00052         default:
00053             pn512_register_write(pPN512, PN512_REG_CONTROL, 0x40);
00054             break;
00055     }
00056 }
00057 
00058 void pn512_timer_stop(pn512_t *pPN512)
00059 {
00060     //The control register also contains the initiator bit that we must set correctly
00061     switch (pPN512->framing) {
00062         case nfc_framing_initiator_a_106:
00063         case nfc_framing_initiator_f_212:
00064         case nfc_framing_initiator_f_424:
00065             pn512_register_write(pPN512, PN512_REG_CONTROL, 0x90);
00066             break;
00067         case nfc_framing_target_mode_detector:
00068         case nfc_framing_target_a_106:
00069         case nfc_framing_target_f_212:
00070         case nfc_framing_target_f_424:
00071         default:
00072             pn512_register_write(pPN512, PN512_REG_CONTROL, 0x80);
00073             break;
00074     }
00075 }