Mbed OS Reference
Loading...
Searching...
No Matches
pn512_irq.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2013-2018, ARM Limited, All Rights Reserved
3 * SPDX-License-Identifier: Apache-2.0
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may
6 * not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17/**
18 * \file pn512_irq.h
19 * \copyright Copyright (c) ARM Ltd 2013
20 * \author Donatien Garnier
21 */
22
23#ifndef PN512_IRQ_H_
24#define PN512_IRQ_H_
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30#include "stack/nfc_common.h"
31#include "pn512.h"
32#include "pn512_registers.h"
33
34#define PN512_IRQ_TX (1<<6)
35#define PN512_IRQ_RX (1<<5)
36#define PN512_IRQ_IDLE (1<<4)
37#define PN512_IRQ_HIGH_ALERT (1<<3)
38#define PN512_IRQ_LOW_ALERT (1<<2)
39#define PN512_IRQ_ERR (1<<1)
40#define PN512_IRQ_TIMER (1<<0)
41
42#define PN512_IRQ_SIGIN (1<<(4+8))
43#define PN512_IRQ_MODE (1<<(3+8))
44#define PN512_IRQ_CRC (1<<(2+8))
45#define PN512_IRQ_RF_ON (1<<(1+8))
46#define PN512_IRQ_RF_OFF (1<<(0+8))
47
48#define PN512_IRQ_NONE 0x00
49#define PN512_IRQ_ALL 0x1F7F
50
51#define PN512_REG_COMIEN_MASK 0x7F
52#define PN512_REG_COMIEN_VAL 0x00
53
54#define PN512_REG_DIVIEN_MASK 0x1F
55#define PN512_REG_DIVIEN_VAL 0x80
56
57#define PN512_REG_COMIRQ_MASK 0x7F
58#define PN512_REG_COMIRQ_CLEAR 0x00
59
60#define PN512_REG_DIVIRQ_MASK 0x1F
61#define PN512_REG_DIVIRQ_CLEAR 0x00
62
63/** \internal Set IRQ enable registers
64 * \param pPN512 pointer to pn512_t structure
65 * \param irqs MSB is DIVIEN value, LSB is COMIEN value
66 */
67static inline void pn512_irq_set(pn512_t *pPN512, uint16_t irqs) //ORed
68{
69 pn512_register_write(pPN512, PN512_REG_COMIEN, PN512_REG_COMIEN_VAL | (PN512_REG_COMIEN_MASK & (irqs & 0xFF)));
70 pn512_register_write(pPN512, PN512_REG_DIVIEN, PN512_REG_DIVIEN_VAL | (PN512_REG_DIVIEN_MASK & (irqs >> 8)));
71 pPN512->irqsEn = irqs;
72}
73
74/** \internal Get IRQ enable registers
75 * \param pPN512 pointer to pn512_t structure
76 * \return MSB is DIVIEN value, LSB is COMIEN value
77 */
78static inline uint16_t pn512_irq_enabled(pn512_t *pPN512) //ORed
79{
80 return pPN512->irqsEn /*(pn512_register_read(pPN512, PN512_REG_COMIEN_VAL) & PN512_REG_COMIEN_MASK)
81 | ((pn512_register_read(pPN512, PN512_REG_DIVIEN_VAL) & PN512_REG_DIVIEN_MASK) << 8)*/;
82}
83
84/** \internal Get IRQ status registers (masked with enabled IRQ register)
85 * \param pPN512 pointer to pn512_t structure
86 * \return MSB is DIVIRQ value, LSB is COMIRQ value
87 */
88static inline uint16_t pn512_irq_get(pn512_t *pPN512) //ORed
89{
90 return ((pn512_register_read(pPN512, PN512_REG_COMIRQ) & PN512_REG_COMIEN_MASK)
91 | ((pn512_register_read(pPN512, PN512_REG_DIVIRQ) & PN512_REG_DIVIEN_MASK) << 8)) & pPN512->irqsEn;
92}
93
94/** \internal Clear some interrupts
95 * \param pPN512 pointer to pn512_t structure
96 * \param irqs MSB is DIVIEN value, LSB is COMIEN value
97 */
98static inline void pn512_irq_clear(pn512_t *pPN512, uint16_t irqs)
99{
100 pn512_register_write(pPN512, PN512_REG_COMIRQ, PN512_REG_COMIRQ_CLEAR | (PN512_REG_COMIRQ_MASK & (irqs & 0xFF)));
101 pn512_register_write(pPN512, PN512_REG_DIVIRQ, PN512_REG_DIVIRQ_CLEAR | (PN512_REG_DIVIRQ_MASK & (irqs >> 8)));
102}
103
104#ifdef __cplusplus
105}
106#endif
107
108#endif /* PN512_IRQ_H_ */
Definition: pn512.h:53