123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577 |
- #ifndef NRF_ATFIFO_H__
- #error This is internal file. Do not include this file in your program.
- #endif
- #ifndef NRF_ATFIFO_INTERNAL_H__
- #define NRF_ATFIFO_INTERNAL_H__
- #include <stddef.h>
- #include "nrf.h"
- #include "app_util.h"
- #include "nordic_common.h"
- #if ((__CORTEX_M >= 0x03U) || (__CORTEX_SC >= 300U)) == 0
- #error Unsupported core version
- #endif
- STATIC_ASSERT(offsetof(nrf_atfifo_postag_pos_t, wr) == 0)
- STATIC_ASSERT(offsetof(nrf_atfifo_postag_pos_t, rd) == 2)
- static bool nrf_atfifo_wspace_req(nrf_atfifo_t * const p_fifo, nrf_atfifo_postag_t * const p_old_tail)
- static void nrf_atfifo_wspace_close(nrf_atfifo_t * const p_fifo)
- static bool nrf_atfifo_rspace_req(nrf_atfifo_t * const p_fifo, nrf_atfifo_postag_t * const p_old_head)
- static void nrf_atfifo_rspace_close(nrf_atfifo_t * const p_fifo)
- static bool nrf_atfifo_space_clear(nrf_atfifo_t * const p_fifo)
- #if defined ( __CC_ARM )
- __ASM bool nrf_atfifo_wspace_req(nrf_atfifo_t * const p_fifo, nrf_atfifo_postag_t * const p_old_tail)
- {
-
- push {r4, r5}
- nrf_atfifo_wspace_req_repeat
-
- ldrex r2, [r0, #__cpp(offsetof(nrf_atfifo_t, tail))]
-
- uxth r3, r2
-
- ldrh r4, [r0, #__cpp(offsetof(nrf_atfifo_t, item_size))]
- add r3, r4
- ldrh r4, [r0, #__cpp(offsetof(nrf_atfifo_t, buf_size))]
- cmp r3, r4
- it hs
- subhs r3, r3, r4
-
- ldrh r4, [r0, #__cpp(offsetof(nrf_atfifo_t, head) + offsetof(nrf_atfifo_postag_pos_t, wr))]
- cmp r3, r4
- ittt eq
- clrexeq
- moveq r0, #__cpp(false)
- beq nrf_atfifo_wspace_req_exit
-
-
- pkhbt r3, r3, r2
-
- strex r4, r3, [r0, #__cpp(offsetof(nrf_atfifo_t, tail))]
- cmp r4, #0
- bne nrf_atfifo_wspace_req_repeat
-
- mov r0, #__cpp(true)
- nrf_atfifo_wspace_req_exit
-
- str r2, [r1]
- pop {r4, r5}
- bx lr
- }
- __ASM void nrf_atfifo_wspace_close(nrf_atfifo_t * const p_fifo)
- {
-
- nrf_atfifo_wspace_close_repeat
- ldrex r2, [r0, #__cpp(offsetof(nrf_atfifo_t, tail))]
-
- pkhbt r2, r2, r2, lsl #16
- strex r1, r2, [r0, #__cpp(offsetof(nrf_atfifo_t, tail))]
- cmp r1, #0
- bne nrf_atfifo_wspace_close_repeat
- bx lr
- }
- __ASM bool nrf_atfifo_rspace_req(nrf_atfifo_t * const p_fifo, nrf_atfifo_postag_t * const p_old_head)
- {
-
- push {r4, r5}
- nrf_atfifo_rspace_req_repeat
-
- ldrex r2, [r0, #__cpp(offsetof(nrf_atfifo_t, head))]
-
- uxth r3, r2, ror #16
-
- ldrh r4, [r0, #__cpp(offsetof(nrf_atfifo_t, tail) + offsetof(nrf_atfifo_postag_pos_t, rd))]
- cmp r3, r4
- ittt eq
- clrexeq
- moveq r0, #__cpp(false)
- beq nrf_atfifo_rspace_req_exit
-
- ldrh r4, [r0, #__cpp(offsetof(nrf_atfifo_t, item_size))]
- add r3, r4
- ldrh r4, [r0, #__cpp(offsetof(nrf_atfifo_t, buf_size))]
- cmp r3, r4
- it hs
- subhs r3, r3, r4
-
-
- pkhbt r3, r2, r3, lsl #16
-
- strex r4, r3, [r0, #__cpp(offsetof(nrf_atfifo_t, head))]
- cmp r4, #0
- bne nrf_atfifo_rspace_req_repeat
-
- mov r0, #__cpp(true)
- nrf_atfifo_rspace_req_exit
-
- str r2, [r1]
- pop {r4, r5}
- bx lr
- }
- __ASM void nrf_atfifo_rspace_close(nrf_atfifo_t * const p_fifo)
- {
-
- nrf_atfifo_rspace_close_repeat
- ldrex r2, [r0, #__cpp(offsetof(nrf_atfifo_t, head))]
-
- pkhtb r2, r2, r2, asr #16
- strex r1, r2, [r0, #__cpp(offsetof(nrf_atfifo_t, head))]
- cmp r1, #0
- bne nrf_atfifo_rspace_close_repeat
- bx lr
- }
- __ASM bool nrf_atfifo_space_clear(nrf_atfifo_t * const p_fifo)
- {
-
- mov r3, r0
- nrf_atfifo_space_clear_repeat
-
- ldrex r2, [r3, #__cpp(offsetof(nrf_atfifo_t, head))]
- ldrh r1, [r3, #__cpp(offsetof(nrf_atfifo_t, tail) + offsetof(nrf_atfifo_postag_pos_t, rd))]
- cmp r2, r2, ror #16
-
- mov r0, #__cpp(false)
-
- itett ne
- uxthne r2, r2
- orreq r1, r1, r1, lsl #16
- orrne r1, r2, r1, lsl #16
-
- bne nrf_atfifo_space_clear_head_test_skip
-
- ldr r2, [r3, #__cpp(offsetof(nrf_atfifo_t, tail))]
- cmp r2, r2, ror #16
-
- it eq
- moveq r0, #__cpp(true)
- nrf_atfifo_space_clear_head_test_skip
-
- strex r2, r1, [r3, #__cpp(offsetof(nrf_atfifo_t, head))]
- cmp r2, #0
- bne nrf_atfifo_space_clear_repeat
- bx lr
- }
- #elif defined ( __ICCARM__ ) || defined ( __GNUC__ )
- bool nrf_atfifo_wspace_req(nrf_atfifo_t * const p_fifo, nrf_atfifo_postag_t * const p_old_tail)
- {
- volatile bool ret
- volatile uint32_t old_tail
- uint32_t new_tail
- uint32_t temp
- __ASM volatile(
-
- "1: \n"
- " ldrex %[old_tail], [%[p_fifo], %[offset_tail]] \n"
- " uxth %[new_tail], %[old_tail] \n"
- " \n"
- " ldrh %[temp], [%[p_fifo], %[offset_item_size]] \n"
- " add %[new_tail], %[temp] \n"
- " ldrh %[temp], [%[p_fifo], %[offset_buf_size]] \n"
- " cmp %[new_tail], %[temp] \n"
- " it hs \n"
- " subhs %[new_tail], %[new_tail], %[temp] \n"
- " \n"
- " ldrh %[temp], [%[p_fifo], %[offset_head_wr]] \n"
- " cmp %[new_tail], %[temp] \n"
- " ittt eq \n"
- " clrexeq \n"
- " moveq %[ret], %[false_val] \n"
- " beq.n 2f \n"
- " \n"
- " pkhbt %[new_tail], %[new_tail], %[old_tail] \n"
- " \n"
- " strex %[temp], %[new_tail], [%[p_fifo], %[offset_tail]] \n"
- " cmp %[temp], #0 \n"
- " bne.n 1b \n"
- " \n"
- " mov %[ret], %[true_val] \n"
- "2: \n"
- :
- [ret] "=r"(ret),
- [temp] "=&r"(temp),
- [old_tail]"=&r"(old_tail),
- [new_tail]"=&r"(new_tail)
- :
- [p_fifo] "r"(p_fifo),
- [offset_tail] "J"(offsetof(nrf_atfifo_t, tail)),
- [offset_head_wr] "J"(offsetof(nrf_atfifo_t, head) + offsetof(nrf_atfifo_postag_pos_t, wr)),
- [offset_item_size]"J"(offsetof(nrf_atfifo_t, item_size)),
- [offset_buf_size] "J"(offsetof(nrf_atfifo_t, buf_size)),
- [true_val] "I"(true),
- [false_val] "I"(false)
- :
- "cc")
- p_old_tail->tag = old_tail
- UNUSED_VARIABLE(new_tail)
- UNUSED_VARIABLE(temp)
- return ret
- }
- void nrf_atfifo_wspace_close(nrf_atfifo_t * const p_fifo)
- {
- uint32_t temp
- uint32_t new_tail
- __ASM volatile(
-
- "1: \n"
- " ldrex %[new_tail], [%[p_fifo], %[offset_tail]] \n"
- " pkhbt %[new_tail],%[new_tail], %[new_tail], lsl #16 \n"
- " \n"
- " strex %[temp], %[new_tail], [%[p_fifo], %[offset_tail]] \n"
- " cmp %[temp], #0 \n"
- " bne.n 1b \n"
- :
- [temp] "=&r"(temp),
- [new_tail] "=&r"(new_tail)
- :
- [p_fifo] "r"(p_fifo),
- [offset_tail] "J"(offsetof(nrf_atfifo_t, tail))
- :
- "cc")
- UNUSED_VARIABLE(temp)
- UNUSED_VARIABLE(new_tail)
- }
- bool nrf_atfifo_rspace_req(nrf_atfifo_t * const p_fifo, nrf_atfifo_postag_t * const p_old_head)
- {
- volatile bool ret
- volatile uint32_t old_head
- uint32_t new_head
- uint32_t temp
- __ASM volatile(
-
- "1: \n"
- " ldrex %[old_head], [%[p_fifo], %[offset_head]] \n"
- " uxth %[new_head], %[old_head], ror #16 \n"
- " \n"
- " ldrh %[temp], [%[p_fifo], %[offset_tail_rd]] \n"
- " cmp %[new_head], %[temp] \n"
- " ittt eq \n"
- " clrexeq \n"
- " moveq %[ret], %[false_val] \n"
- " beq.n 2f \n"
- " \n"
- " ldrh %[temp], [%[p_fifo], %[offset_item_size]] \n"
- " add %[new_head], %[temp] \n"
- " ldrh %[temp], [%[p_fifo], %[offset_buf_size]] \n"
- " cmp %[new_head], %[temp] \n"
- " it hs \n"
- " subhs %[new_head], %[new_head], %[temp] \n"
- " \n"
- " pkhbt %[new_head], %[old_head], %[new_head], lsl #16 \n"
- " \n"
- " strex %[temp], %[new_head], [%[p_fifo], %[offset_head]] \n"
- " cmp %[temp], #0 \n"
- " bne.n 1b \n"
- " \n"
- " mov %[ret], %[true_val] \n"
- "2: \n"
- :
- [ret] "=r"(ret),
- [temp] "=&r"(temp),
- [old_head]"=&r"(old_head),
- [new_head]"=&r"(new_head)
- :
- [p_fifo] "r"(p_fifo),
- [offset_head] "J"(offsetof(nrf_atfifo_t, head)),
- [offset_tail_rd] "J"(offsetof(nrf_atfifo_t, tail) + offsetof(nrf_atfifo_postag_pos_t, rd)),
- [offset_item_size]"J"(offsetof(nrf_atfifo_t, item_size)),
- [offset_buf_size] "J"(offsetof(nrf_atfifo_t, buf_size)),
- [true_val] "I"(true),
- [false_val] "I"(false)
- :
- "cc")
- p_old_head->tag = old_head
- UNUSED_VARIABLE(new_head)
- UNUSED_VARIABLE(temp)
- return ret
- }
- void nrf_atfifo_rspace_close(nrf_atfifo_t * const p_fifo)
- {
- uint32_t temp
- uint32_t new_head
- __ASM volatile(
-
- "1: \n"
- " ldrex %[new_head], [%[p_fifo], %[offset_head]] \n"
- " pkhtb %[new_head],%[new_head], %[new_head], asr #16 \n"
- " \n"
- " strex %[temp], %[new_head], [%[p_fifo], %[offset_head]] \n"
- " cmp %[temp], #0 \n"
- " bne.n 1b \n"
- :
- [temp] "=&r"(temp),
- [new_head] "=&r"(new_head)
- :
- [p_fifo] "r"(p_fifo),
- [offset_head] "J"(offsetof(nrf_atfifo_t, head))
- :
- "cc")
- UNUSED_VARIABLE(temp)
- UNUSED_VARIABLE(new_head)
- }
- bool nrf_atfifo_space_clear(nrf_atfifo_t * const p_fifo)
- {
- volatile bool ret
- uint32_t old_head
- uint32_t new_head
- __ASM volatile(
- "1: \n"
- " ldrex %[old_head], [%[p_fifo], %[offset_head]] \n"
- " ldrh %[new_head], [%[p_fifo], %[offset_tail_rd]] \n"
- " cmp %[old_head], %[old_head], ror #16 \n"
- " \n"
- " mov %[ret], %[false_val] \n"
- " \n"
- " itett ne \n"
- " uxthne %[old_head], %[old_head] \n"
- " orreq %[new_head], %[new_head], %[new_head], lsl #16 \n"
- " orrne %[new_head], %[old_head], %[new_head], lsl #16 \n"
- " \n"
- " bne.n 2f \n"
- " \n"
- " ldr %[old_head], [%[p_fifo], %[offset_tail]] \n"
- " cmp %[old_head], %[old_head], ror #16 \n"
- " it eq \n"
- " moveq %[ret], %[true_val] \n"
- " \n"
- "2: \n"
- " strex %[old_head], %[new_head], [%[p_fifo], %[offset_head]] \n"
- " cmp %[old_head], #0 \n"
- " bne.n 1b \n"
- :
- [ret] "=&r"(ret),
- [old_head] "=&r"(old_head),
- [new_head] "=&r"(new_head)
- :
- [p_fifo] "r"(p_fifo),
- [offset_head] "J"(offsetof(nrf_atfifo_t, head)),
- [offset_tail] "J"(offsetof(nrf_atfifo_t, tail)),
- [offset_tail_rd] "J"(offsetof(nrf_atfifo_t, tail) + offsetof(nrf_atfifo_postag_pos_t, rd)),
- [true_val] "I"(true),
- [false_val] "I"(false)
- :
- "cc")
- UNUSED_VARIABLE(old_head)
- UNUSED_VARIABLE(new_head)
- return ret
- }
- #else
- #error Unsupported compiler
- #endif
- #endif
|