Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upFeature/hal/nfc #1606
Conversation
@@ -618,7 +618,7 @@ const auto UARTE1_INTERRUPT_PRIORITY = APP_IRQ_PRIORITY_HIGHEST; | |||
Usart* getInstance(HAL_USART_Serial serial) { | |||
static Usart usartMap[] = { | |||
{NRF_UARTE0, uarte0InterruptHandler, UARTE0_INTERRUPT_PRIORITY, NRF_TIMER3, NRF_PPI_CHANNEL4, TX, RX, CTS, RTS}, | |||
{NRF_UARTE1, uarte1InterruptHandler, UARTE1_INTERRUPT_PRIORITY, NRF_TIMER4, NRF_PPI_CHANNEL5, TX1, RX1, CTS1, RTS1} | |||
{NRF_UARTE1, uarte1InterruptHandler, UARTE1_INTERRUPT_PRIORITY, NRF_TIMER1, NRF_PPI_CHANNEL5, TX1, RX1, CTS1, RTS1} |
This comment has been minimized.
This comment has been minimized.
avtolstoy
Nov 26, 2018
Member
NRF_TIMER1
cannot be used. It's already in use by Nordic 802.15.4 radio driver: https://github.com/particle-iot/openthread/blob/master/third_party/NordicSemiconductor/drivers/radio/nrf_802154_config.h#L133
This comment has been minimized.
This comment has been minimized.
YutingYou
Nov 27, 2018
Author
Contributor
We've run out of timer resource, I'd like to release the timer in button hal, we have below choice for button debounce timer, or you can add other suggestion:
- Use FreeRTOS timer in Device OS and use Timer 2 in bootloader
- Use a high-precision timer to make a general software timer just like
app timer
, then we can use it in Bootloader and Device OS - Add a software timer handler in
HAL_SysTick_Handler()
, if we start the button timer, we set a timer flag, then we check the flag inHAL_SysTick_Handler()
I'd prefer the third one, since the handler won't take a long time.
Timer resource:
RTC0: Softdevice
RTC1: FreeRTOS
RTC2: OpenThread
Timer0: Softdevice
Timer1: Radio
Timer2: Button_hal
Timer3: Usart
Timer4: Usart
This comment has been minimized.
This comment has been minimized.
avtolstoy
Nov 27, 2018
Member
Agreed, I don't think we have any other choice at the moment. Moreover on Gen 3 devices this shouldn't cause any issues for FreeRTOS, since FreeRTOS is run off of RTC timer instead of SysTick.
|
||
typedef void (*NfcEventCallback)(NfcEventType type, NfcEvent *event); | ||
|
||
int HAL_NFC_Type2_Init(void); |
This comment has been minimized.
This comment has been minimized.
avtolstoy
Nov 26, 2018
Member
While we do not have a formal style guide at present, I think lowercase snake_case
should be preferred for new HALs. This should apply both to function names and type names.
This comment has been minimized.
This comment has been minimized.
typedef void (*NfcEventCallback)(NfcEventType type, NfcEvent *event); | ||
|
||
int HAL_NFC_Type2_Init(void); | ||
int HAL_NFC_Type2_Set_Payload(const uint8_t *msg_buf, uint16_t msg_len); |
This comment has been minimized.
This comment has been minimized.
avtolstoy
Nov 26, 2018
Member
Can the payload in theory be more than 2^16 bytes (not taking into account our specific microcontroller)? If yes, I suggest we change this to size_t
. A reserved void*
argument here also sounds like a good idea.
This comment has been minimized.
This comment has been minimized.
int HAL_NFC_Type2_Set_Payload(const uint8_t *msg_buf, uint16_t msg_len); | ||
int HAL_NFC_Type2_Start_Emulation(void); | ||
int HAL_NFC_Type2_Stop_Emulation(void); | ||
int HAL_NFC_Type2_Set_Callback(NfcEventCallback callback); |
This comment has been minimized.
This comment has been minimized.
avtolstoy
Nov 26, 2018
Member
An additional void* ctx
argument and a change in NfcEventCallback
signature ((NfcEventType type, NfcEvent *event, void* ctx)
) sounds like a good idea.
This comment has been minimized.
This comment has been minimized.
d62d399
to
02cd1fe
This comment has been minimized.
This comment has been minimized.
@YutingYou Will the wiring API be a separate PR? Please also add a new dynalib exporting these new NFC functions, otherwise they will not be accessible in modular firmware from the user part. |
This comment has been minimized.
This comment has been minimized.
@avtolstoy wiring API will be a separate PR. Added dynalib support. |
This comment has been minimized.
This comment has been minimized.
llacom
commented
Jan 24, 2019
I'm trying to build the sample application. I copied the code in The error I get:
Those symbols were defined on
Now the symbols are in |
930fdb0
to
56fba06
0a15c7f
to
8dfffdf
|
||
typedef void (*nfc_event_callback_t)(nfc_event_type_t type, nfc_event_t *event, void* ctx); | ||
|
||
int hal_nfc_type2_init(void); |
This comment has been minimized.
This comment has been minimized.
|
||
int hal_nfc_type2_init(void); | ||
int hal_nfc_type2_set_payload(const void *msg_buf, size_t msg_len); | ||
int hal_nfc_type2_start_emulation(void); |
This comment has been minimized.
This comment has been minimized.
int hal_nfc_type2_init(void); | ||
int hal_nfc_type2_set_payload(const void *msg_buf, size_t msg_len); | ||
int hal_nfc_type2_start_emulation(void); | ||
int hal_nfc_type2_stop_emulation(void); |
This comment has been minimized.
This comment has been minimized.
int hal_nfc_type2_set_payload(const void *msg_buf, size_t msg_len); | ||
int hal_nfc_type2_start_emulation(void); | ||
int hal_nfc_type2_stop_emulation(void); | ||
int hal_nfc_type2_set_callback(nfc_event_callback_t callback); |
This comment has been minimized.
This comment has been minimized.
avtolstoy
Mar 4, 2019
Member
Any functions taking a callback should have a void* context
argument which should be stored along with the callback itself. The stored context
should be passed as an argument to the callback function.
|
||
static nfc_event_callback_t g_nfc_event_user_callback = NULL; | ||
|
||
static void nfc_type_2_callback(void * p_context, nfc_t2t_event_t event, const uint8_t * p_data, size_t data_length) { |
This comment has been minimized.
This comment has been minimized.
return records_.size() - 1; | ||
} | ||
|
||
int NdefMessage::addUriRecord(const char *uri, UriRecord::NfcUriType type) { |
This comment has been minimized.
This comment has been minimized.
return records_.size() - 1; | ||
} | ||
|
||
int NdefMessage::addLauchAppRecord(const char *androidPackageName) { |
This comment has been minimized.
This comment has been minimized.
return 0; | ||
} | ||
|
||
NfcTagType2 NFC; |
This comment has been minimized.
This comment has been minimized.
avtolstoy
Mar 4, 2019
Member
Consider using:
class NfcTagType2 {
public:
NfcTagType2& instance() {
static NfcTagType2 inst;
return inst;
}
protected:
NfcTagType2() {
...
}
}
#define NFC NfcTagType2::instance()
to save on flash space/RAM when the application is not using NFC
.
This comment has been minimized.
This comment has been minimized.
I posted on the community forum the attempt to build this branch on a Xenon before @avtolstoy requested the latest changes. @YutingYou I'm not much help at coding the device-os, but I'm ready to help with building, testing and documenting when changes are applied. Let me know if I can be of assistance. Thanks for your efforts with the NFC API. |
This comment has been minimized.
This comment has been minimized.
@llacom Sorry for the late reply, the HAL layer example is only for monolithic firmware, your issue is caused by I didn't export NFC functions as C function. It was fixed in the latest commit. The HAL example also uses some unexported function, so I'd suggest using wiring API to continue your test. @aroller You should meet the same issue as @llacom met, please try again, if you got any issue or suggestions, feel free to let me know. |
c12c0ed
to
0eea298
|
This comment has been minimized.
This comment has been minimized.
Sure thing, it seems there is no example for the new API, I'll look into it. |
YutingYou commentedNov 26, 2018
•
edited by technobly
Problem
Implement NFC Type 2 HAL driver
NOTE: This PR changed the timer used by USART, because NFC uses timer 4. Now we use timer 1 in USART driver.
Steps to Test
Example App
Update
NFC Wiring API Test
Example App
Note
References
Completeness