Furi: core refactoring and CMSIS removal part 2 (#1410)
* Furi: rename and move core * Furi: drop CMSIS_OS header and unused api, partially refactor and cleanup the rest * Furi: CMSIS_OS drop and refactoring. * Furi: refactoring, remove cmsis legacy * Furi: fix incorrect assert on queue deallocation, cleanup timer * Furi: improve delay api, get rid of floats * hal: dropped furi_hal_crc * Furi: move DWT based delay to cortex HAL * Furi: update core documentation Co-authored-by: hedger <hedger@nanode.su>
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
#include <furi_hal.h>
|
||||
|
||||
#define CYFRAL_DATA_SIZE sizeof(uint16_t)
|
||||
#define CYFRAL_PERIOD (125 * furi_hal_delay_instructions_per_microsecond())
|
||||
#define CYFRAL_PERIOD (125 * furi_hal_cortex_instructions_per_microsecond())
|
||||
#define CYFRAL_0_LOW (CYFRAL_PERIOD * 0.66f)
|
||||
#define CYFRAL_0_HI (CYFRAL_PERIOD * 0.33f)
|
||||
#define CYFRAL_1_LOW (CYFRAL_PERIOD * 0.33f)
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#include <furi_hal.h>
|
||||
|
||||
#define METAKOM_DATA_SIZE sizeof(uint32_t)
|
||||
#define METAKOM_PERIOD (125 * furi_hal_delay_instructions_per_microsecond())
|
||||
#define METAKOM_PERIOD (125 * furi_hal_cortex_instructions_per_microsecond())
|
||||
#define METAKOM_0_LOW (METAKOM_PERIOD * 0.33f)
|
||||
#define METAKOM_0_HI (METAKOM_PERIOD * 0.66f)
|
||||
#define METAKOM_1_LOW (METAKOM_PERIOD * 0.66f)
|
||||
|
@@ -32,7 +32,7 @@ iButtonWorker* ibutton_worker_alloc() {
|
||||
worker->pulse_decoder = pulse_decoder_alloc();
|
||||
worker->protocol_cyfral = protocol_cyfral_alloc();
|
||||
worker->protocol_metakom = protocol_metakom_alloc();
|
||||
worker->messages = osMessageQueueNew(1, sizeof(iButtonMessage), NULL);
|
||||
worker->messages = furi_message_queue_alloc(1, sizeof(iButtonMessage));
|
||||
worker->mode_index = iButtonWorkerIdle;
|
||||
worker->last_dwt_value = 0;
|
||||
worker->read_cb = NULL;
|
||||
@@ -90,22 +90,26 @@ void ibutton_worker_emulate_set_callback(
|
||||
|
||||
void ibutton_worker_read_start(iButtonWorker* worker, iButtonKey* key) {
|
||||
iButtonMessage message = {.type = iButtonMessageRead, .data.key = key};
|
||||
furi_check(osMessageQueuePut(worker->messages, &message, 0, osWaitForever) == osOK);
|
||||
furi_check(
|
||||
furi_message_queue_put(worker->messages, &message, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
|
||||
void ibutton_worker_write_start(iButtonWorker* worker, iButtonKey* key) {
|
||||
iButtonMessage message = {.type = iButtonMessageWrite, .data.key = key};
|
||||
furi_check(osMessageQueuePut(worker->messages, &message, 0, osWaitForever) == osOK);
|
||||
furi_check(
|
||||
furi_message_queue_put(worker->messages, &message, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
|
||||
void ibutton_worker_emulate_start(iButtonWorker* worker, iButtonKey* key) {
|
||||
iButtonMessage message = {.type = iButtonMessageEmulate, .data.key = key};
|
||||
furi_check(osMessageQueuePut(worker->messages, &message, 0, osWaitForever) == osOK);
|
||||
furi_check(
|
||||
furi_message_queue_put(worker->messages, &message, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
|
||||
void ibutton_worker_stop(iButtonWorker* worker) {
|
||||
iButtonMessage message = {.type = iButtonMessageStop};
|
||||
furi_check(osMessageQueuePut(worker->messages, &message, 0, osWaitForever) == osOK);
|
||||
furi_check(
|
||||
furi_message_queue_put(worker->messages, &message, FuriWaitForever) == FuriStatusOk);
|
||||
}
|
||||
|
||||
void ibutton_worker_free(iButtonWorker* worker) {
|
||||
@@ -123,7 +127,7 @@ void ibutton_worker_free(iButtonWorker* worker) {
|
||||
encoder_cyfral_free(worker->encoder_cyfral);
|
||||
encoder_metakom_free(worker->encoder_metakom);
|
||||
|
||||
osMessageQueueDelete(worker->messages);
|
||||
furi_message_queue_free(worker->messages);
|
||||
|
||||
furi_thread_free(worker->thread);
|
||||
free(worker->key_data);
|
||||
@@ -136,7 +140,8 @@ void ibutton_worker_start_thread(iButtonWorker* worker) {
|
||||
|
||||
void ibutton_worker_stop_thread(iButtonWorker* worker) {
|
||||
iButtonMessage message = {.type = iButtonMessageEnd};
|
||||
furi_check(osMessageQueuePut(worker->messages, &message, 0, osWaitForever) == osOK);
|
||||
furi_check(
|
||||
furi_message_queue_put(worker->messages, &message, FuriWaitForever) == FuriStatusOk);
|
||||
furi_thread_join(worker->thread);
|
||||
}
|
||||
|
||||
@@ -148,7 +153,7 @@ void ibutton_worker_switch_mode(iButtonWorker* worker, iButtonWorkerMode mode) {
|
||||
|
||||
void ibutton_worker_notify_emulate(iButtonWorker* worker) {
|
||||
iButtonMessage message = {.type = iButtonMessageNotifyEmulate};
|
||||
furi_check(osMessageQueuePut(worker->messages, &message, 0, 0) == osOK);
|
||||
furi_check(furi_message_queue_put(worker->messages, &message, 0) == FuriStatusOk);
|
||||
}
|
||||
|
||||
void ibutton_worker_set_key_p(iButtonWorker* worker, iButtonKey* key) {
|
||||
@@ -159,14 +164,14 @@ static int32_t ibutton_worker_thread(void* thread_context) {
|
||||
iButtonWorker* worker = thread_context;
|
||||
bool running = true;
|
||||
iButtonMessage message;
|
||||
osStatus_t status;
|
||||
FuriStatus status;
|
||||
|
||||
ibutton_worker_modes[worker->mode_index].start(worker);
|
||||
|
||||
while(running) {
|
||||
status = osMessageQueueGet(
|
||||
worker->messages, &message, NULL, ibutton_worker_modes[worker->mode_index].quant);
|
||||
if(status == osOK) {
|
||||
status = furi_message_queue_get(
|
||||
worker->messages, &message, ibutton_worker_modes[worker->mode_index].quant);
|
||||
if(status == FuriStatusOk) {
|
||||
switch(message.type) {
|
||||
case iButtonMessageEnd:
|
||||
ibutton_worker_switch_mode(worker, iButtonWorkerIdle);
|
||||
@@ -195,7 +200,7 @@ static int32_t ibutton_worker_thread(void* thread_context) {
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else if(status == osErrorTimeout) {
|
||||
} else if(status == FuriStatusErrorTimeout) {
|
||||
ibutton_worker_modes[worker->mode_index].tick(worker);
|
||||
} else {
|
||||
furi_crash("iButton worker error");
|
||||
|
@@ -52,7 +52,7 @@ struct iButtonWorker {
|
||||
OneWireDevice* device;
|
||||
iButtonWriter* writer;
|
||||
iButtonWorkerMode mode_index;
|
||||
osMessageQueueId_t messages;
|
||||
FuriMessageQueue* messages;
|
||||
FuriThread* thread;
|
||||
|
||||
PulseDecoder* pulse_decoder;
|
||||
|
@@ -21,7 +21,7 @@ void ibutton_worker_mode_write_stop(iButtonWorker* worker);
|
||||
|
||||
const iButtonWorkerModeType ibutton_worker_modes[] = {
|
||||
{
|
||||
.quant = osWaitForever,
|
||||
.quant = FuriWaitForever,
|
||||
.start = ibutton_worker_mode_idle_start,
|
||||
.tick = ibutton_worker_mode_idle_tick,
|
||||
.stop = ibutton_worker_mode_idle_stop,
|
||||
@@ -86,7 +86,7 @@ bool ibutton_worker_read_comparator(iButtonWorker* worker) {
|
||||
furi_hal_rfid_comp_start();
|
||||
|
||||
// TODO: rework with thread events, "pulse_decoder_get_decoded_index_with_timeout"
|
||||
furi_hal_delay_ms(100);
|
||||
furi_delay_ms(100);
|
||||
int32_t decoded_index = pulse_decoder_get_decoded_index(worker->pulse_decoder);
|
||||
if(decoded_index >= 0) {
|
||||
pulse_decoder_get_data(
|
||||
@@ -121,7 +121,7 @@ bool ibutton_worker_read_comparator(iButtonWorker* worker) {
|
||||
bool ibutton_worker_read_dallas(iButtonWorker* worker) {
|
||||
bool result = false;
|
||||
onewire_host_start(worker->host);
|
||||
furi_hal_delay_ms(100);
|
||||
furi_delay_ms(100);
|
||||
FURI_CRITICAL_ENTER();
|
||||
if(onewire_host_search(worker->host, worker->key_data, NORMAL_SEARCH)) {
|
||||
onewire_host_reset_search(worker->host);
|
||||
|
@@ -11,13 +11,13 @@ struct iButtonWriter {
|
||||
|
||||
static void writer_write_one_bit(iButtonWriter* writer, bool value, uint32_t delay) {
|
||||
onewire_host_write_bit(writer->host, value);
|
||||
furi_hal_delay_us(delay);
|
||||
furi_delay_us(delay);
|
||||
}
|
||||
|
||||
static void writer_write_byte_ds1990(iButtonWriter* writer, uint8_t data) {
|
||||
for(uint8_t n_bit = 0; n_bit < 8; n_bit++) {
|
||||
onewire_host_write_bit(writer->host, data & 1);
|
||||
furi_hal_delay_us(5000);
|
||||
furi_delay_us(5000);
|
||||
data = data >> 1;
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ static bool writer_write_TM2004(iButtonWriter* writer, iButtonKey* key) {
|
||||
// TODO: check answer CRC
|
||||
|
||||
// pulse indicating that data is correct
|
||||
furi_hal_delay_us(600);
|
||||
furi_delay_us(600);
|
||||
writer_write_one_bit(writer, 1, 50000);
|
||||
|
||||
// read written key byte
|
||||
@@ -104,7 +104,7 @@ static bool writer_write_1990_1(iButtonWriter* writer, iButtonKey* key) {
|
||||
// unlock
|
||||
onewire_host_reset(writer->host);
|
||||
onewire_host_write(writer->host, RW1990_1_CMD_WRITE_RECORD_FLAG);
|
||||
furi_hal_delay_us(10);
|
||||
furi_delay_us(10);
|
||||
writer_write_one_bit(writer, 0, 5000);
|
||||
|
||||
// write key
|
||||
@@ -113,7 +113,7 @@ static bool writer_write_1990_1(iButtonWriter* writer, iButtonKey* key) {
|
||||
for(uint8_t i = 0; i < ibutton_key_get_data_size(key); i++) {
|
||||
// inverted key for RW1990.1
|
||||
writer_write_byte_ds1990(writer, ~ibutton_key_get_data_p(key)[i]);
|
||||
furi_hal_delay_us(30000);
|
||||
furi_delay_us(30000);
|
||||
}
|
||||
|
||||
// lock
|
||||
@@ -139,7 +139,7 @@ static bool writer_write_1990_2(iButtonWriter* writer, iButtonKey* key) {
|
||||
// unlock
|
||||
onewire_host_reset(writer->host);
|
||||
onewire_host_write(writer->host, RW1990_2_CMD_WRITE_RECORD_FLAG);
|
||||
furi_hal_delay_us(10);
|
||||
furi_delay_us(10);
|
||||
writer_write_one_bit(writer, 1, 5000);
|
||||
|
||||
// write key
|
||||
@@ -147,7 +147,7 @@ static bool writer_write_1990_2(iButtonWriter* writer, iButtonKey* key) {
|
||||
onewire_host_write(writer->host, RW1990_2_CMD_WRITE_ROM);
|
||||
for(uint8_t i = 0; i < ibutton_key_get_data_size(key); i++) {
|
||||
writer_write_byte_ds1990(writer, ibutton_key_get_data_p(key)[i]);
|
||||
furi_hal_delay_us(30000);
|
||||
furi_delay_us(30000);
|
||||
}
|
||||
|
||||
// lock
|
||||
@@ -191,7 +191,7 @@ static bool writer_write_TM01(
|
||||
//} else {
|
||||
for(uint8_t i = 0; i < key->get_type_data_size(); i++) {
|
||||
write_byte_ds1990(key->get_data()[i]);
|
||||
furi_hal_delay_us(10000);
|
||||
furi_delay_us(10000);
|
||||
}
|
||||
//}
|
||||
|
||||
@@ -271,9 +271,9 @@ void ibutton_writer_free(iButtonWriter* writer) {
|
||||
iButtonWriterResult ibutton_writer_write(iButtonWriter* writer, iButtonKey* key) {
|
||||
iButtonWriterResult result = iButtonWriterNoDetect;
|
||||
|
||||
osKernelLock();
|
||||
furi_kernel_lock();
|
||||
bool blank_present = onewire_host_reset(writer->host);
|
||||
osKernelUnlock();
|
||||
furi_kernel_unlock();
|
||||
|
||||
if(blank_present) {
|
||||
switch(ibutton_key_get_type(key)) {
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#include "protocol_cyfral.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <furi/check.h>
|
||||
#include <furi_hal_delay.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#define CYFRAL_DATA_SIZE 2
|
||||
#define CYFRAL_MAX_PERIOD_US 230
|
||||
@@ -104,7 +104,7 @@ static void cyfral_reset(void* context) {
|
||||
cyfral->nibble = 0;
|
||||
cyfral->data_valid = true;
|
||||
|
||||
cyfral->max_period = CYFRAL_MAX_PERIOD_US * furi_hal_delay_instructions_per_microsecond();
|
||||
cyfral->max_period = CYFRAL_MAX_PERIOD_US * furi_hal_cortex_instructions_per_microsecond();
|
||||
}
|
||||
|
||||
static bool cyfral_process_bit(
|
||||
|
@@ -1,8 +1,7 @@
|
||||
#include "protocol_metakom.h"
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <furi/check.h>
|
||||
#include <furi_hal_delay.h>
|
||||
#include <core/check.h>
|
||||
|
||||
#define METAKOM_DATA_SIZE 4
|
||||
#define METAKOM_PERIOD_SAMPLE_COUNT 10
|
||||
|
@@ -31,23 +31,23 @@ bool onewire_host_reset(OneWireHost* host) {
|
||||
furi_hal_ibutton_pin_high();
|
||||
do {
|
||||
if(--retries == 0) return 0;
|
||||
furi_hal_delay_us(2);
|
||||
furi_delay_us(2);
|
||||
} while(!furi_hal_ibutton_pin_get_level());
|
||||
|
||||
// pre delay
|
||||
furi_hal_delay_us(OWH_RESET_DELAY_PRE);
|
||||
furi_delay_us(OWH_RESET_DELAY_PRE);
|
||||
|
||||
// drive low
|
||||
furi_hal_ibutton_pin_low();
|
||||
furi_hal_delay_us(OWH_RESET_DRIVE);
|
||||
furi_delay_us(OWH_RESET_DRIVE);
|
||||
|
||||
// release
|
||||
furi_hal_ibutton_pin_high();
|
||||
furi_hal_delay_us(OWH_RESET_RELEASE);
|
||||
furi_delay_us(OWH_RESET_RELEASE);
|
||||
|
||||
// read and post delay
|
||||
r = !furi_hal_ibutton_pin_get_level();
|
||||
furi_hal_delay_us(OWH_RESET_DELAY_POST);
|
||||
furi_delay_us(OWH_RESET_DELAY_POST);
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -58,15 +58,15 @@ bool onewire_host_read_bit(OneWireHost* host) {
|
||||
|
||||
// drive low
|
||||
furi_hal_ibutton_pin_low();
|
||||
furi_hal_delay_us(OWH_READ_DRIVE);
|
||||
furi_delay_us(OWH_READ_DRIVE);
|
||||
|
||||
// release
|
||||
furi_hal_ibutton_pin_high();
|
||||
furi_hal_delay_us(OWH_READ_RELEASE);
|
||||
furi_delay_us(OWH_READ_RELEASE);
|
||||
|
||||
// read and post delay
|
||||
result = furi_hal_ibutton_pin_get_level();
|
||||
furi_hal_delay_us(OWH_READ_DELAY_POST);
|
||||
furi_delay_us(OWH_READ_DELAY_POST);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -94,19 +94,19 @@ void onewire_host_write_bit(OneWireHost* host, bool value) {
|
||||
if(value) {
|
||||
// drive low
|
||||
furi_hal_ibutton_pin_low();
|
||||
furi_hal_delay_us(OWH_WRITE_1_DRIVE);
|
||||
furi_delay_us(OWH_WRITE_1_DRIVE);
|
||||
|
||||
// release
|
||||
furi_hal_ibutton_pin_high();
|
||||
furi_hal_delay_us(OWH_WRITE_1_RELEASE);
|
||||
furi_delay_us(OWH_WRITE_1_RELEASE);
|
||||
} else {
|
||||
// drive low
|
||||
furi_hal_ibutton_pin_low();
|
||||
furi_hal_delay_us(OWH_WRITE_0_DRIVE);
|
||||
furi_delay_us(OWH_WRITE_0_DRIVE);
|
||||
|
||||
// release
|
||||
furi_hal_ibutton_pin_high();
|
||||
furi_hal_delay_us(OWH_WRITE_0_RELEASE);
|
||||
furi_delay_us(OWH_WRITE_0_RELEASE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -2,8 +2,7 @@
|
||||
#include "one_wire_slave_i.h"
|
||||
#include "one_wire_device.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal_delay.h>
|
||||
#include <furi_hal_ibutton.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#define OWS_RESET_MIN 270
|
||||
#define OWS_RESET_MAX 960
|
||||
@@ -39,14 +38,14 @@ struct OneWireSlave {
|
||||
uint32_t onewire_slave_wait_while_gpio_is(OneWireSlave* bus, uint32_t time, const bool pin_value) {
|
||||
UNUSED(bus);
|
||||
uint32_t start = DWT->CYCCNT;
|
||||
uint32_t time_ticks = time * furi_hal_delay_instructions_per_microsecond();
|
||||
uint32_t time_ticks = time * furi_hal_cortex_instructions_per_microsecond();
|
||||
uint32_t time_captured;
|
||||
|
||||
do {
|
||||
time_captured = DWT->CYCCNT;
|
||||
if(furi_hal_ibutton_pin_get_level() != pin_value) {
|
||||
uint32_t remaining_time = time_ticks - (time_captured - start);
|
||||
remaining_time /= furi_hal_delay_instructions_per_microsecond();
|
||||
remaining_time /= furi_hal_cortex_instructions_per_microsecond();
|
||||
return remaining_time;
|
||||
}
|
||||
} while((time_captured - start) < time_ticks);
|
||||
@@ -60,7 +59,7 @@ bool onewire_slave_show_presence(OneWireSlave* bus) {
|
||||
|
||||
// show presence
|
||||
furi_hal_ibutton_pin_low();
|
||||
furi_hal_delay_us(OWS_PRESENCE_MIN);
|
||||
furi_delay_us(OWS_PRESENCE_MIN);
|
||||
furi_hal_ibutton_pin_high();
|
||||
|
||||
// somebody also can show presence
|
||||
@@ -127,7 +126,7 @@ bool onewire_slave_send_bit(OneWireSlave* bus, bool value) {
|
||||
}
|
||||
|
||||
// hold line for ZERO or ONE time
|
||||
furi_hal_delay_us(time);
|
||||
furi_delay_us(time);
|
||||
furi_hal_ibutton_pin_high();
|
||||
|
||||
return true;
|
||||
@@ -213,7 +212,7 @@ static void exti_cb(void* context) {
|
||||
|
||||
if(input_state) {
|
||||
uint32_t pulse_length =
|
||||
(DWT->CYCCNT - pulse_start) / furi_hal_delay_instructions_per_microsecond();
|
||||
(DWT->CYCCNT - pulse_start) / furi_hal_cortex_instructions_per_microsecond();
|
||||
if(pulse_length >= OWS_RESET_MIN) {
|
||||
if(pulse_length <= OWS_RESET_MAX) {
|
||||
// reset cycle ok
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "pulse_decoder.h"
|
||||
#include <string.h>
|
||||
#include <furi/check.h>
|
||||
#include <core/check.h>
|
||||
|
||||
#define MAX_PROTOCOL 5
|
||||
|
||||
|
Reference in New Issue
Block a user