[WIP] Add syntax check for rust and C\C++ code (#108)
* proof of concept * fix syntax for rust and add auto fix syntax * fix syntax for C * fix bug with files owner * add information to wiki * try to add ci * format code from master * even more format fixes * change docker to docker-compose * Exclude ./target_*/build directories from format check * Run rustfmt only on project files * add ulimit setup for long clang list * merge * fix rustfmt, exclude target Inc directory * sync with master * abspath Co-authored-by: aanper <mail@s3f.ru> Co-authored-by: Vadim Kaushan <admin@disasm.info>
This commit is contained in:
@@ -10,18 +10,17 @@ GPIO and HAL implementations
|
||||
|
||||
void app_gpio_init(GpioPin gpio, GpioMode mode) {
|
||||
if(gpio.pin != 0) {
|
||||
|
||||
switch(mode) {
|
||||
case GpioModeInput:
|
||||
printf("[GPIO] %s%d input\n", gpio.port, gpio.pin);
|
||||
case GpioModeInput:
|
||||
printf("[GPIO] %s%d input\n", gpio.port, gpio.pin);
|
||||
break;
|
||||
|
||||
case GpioModeOutput:
|
||||
printf("[GPIO] %s%d push pull\n", gpio.port, gpio.pin);
|
||||
case GpioModeOutput:
|
||||
printf("[GPIO] %s%d push pull\n", gpio.port, gpio.pin);
|
||||
break;
|
||||
|
||||
case GpioModeOpenDrain:
|
||||
printf("[GPIO] %s%d open drain\n", gpio.port, gpio.pin);
|
||||
case GpioModeOpenDrain:
|
||||
printf("[GPIO] %s%d open drain\n", gpio.port, gpio.pin);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -44,13 +43,14 @@ void HAL_GPIO_WritePin(const char* port, uint32_t pin, HAL_GPIO_PIN_STATE state)
|
||||
printf("[GPIO] set pin %s:%d = %d\n", port, pin, state);
|
||||
}
|
||||
|
||||
HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef* hspi, uint8_t *pData, uint16_t size, uint32_t Timeout) {
|
||||
HAL_StatusTypeDef
|
||||
HAL_SPI_Transmit(SPI_HandleTypeDef* hspi, uint8_t* pData, uint16_t size, uint32_t Timeout) {
|
||||
printf("[SPI] write %d to %s: ", size, *hspi);
|
||||
for(size_t i = 0; i < size; i++) {
|
||||
printf("%02X ", pData[i]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -10,12 +10,8 @@ Dummy hal for local fw build
|
||||
|
||||
UART_HandleTypeDef DEBUG_UART = 0;
|
||||
|
||||
uint16_t HAL_UART_Transmit(
|
||||
UART_HandleTypeDef* handle,
|
||||
uint8_t* bufer,
|
||||
uint16_t size,
|
||||
uint32_t wait_ms
|
||||
) {
|
||||
uint16_t
|
||||
HAL_UART_Transmit(UART_HandleTypeDef* handle, uint8_t* bufer, uint16_t size, uint32_t wait_ms) {
|
||||
uint16_t res = write(1, (const char*)bufer, size);
|
||||
return res;
|
||||
}
|
@@ -16,7 +16,7 @@ void osDelay(uint32_t ms) {
|
||||
// temporary struct to pass function ptr and param to wrapper
|
||||
typedef struct {
|
||||
TaskFunction_t func;
|
||||
void * param;
|
||||
void* param;
|
||||
} PthreadTask;
|
||||
|
||||
void* pthread_wrapper(void* p) {
|
||||
@@ -24,21 +24,19 @@ void* pthread_wrapper(void* p) {
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, 0x00);
|
||||
|
||||
PthreadTask* task = (PthreadTask*)p;
|
||||
|
||||
|
||||
task->func(task->param);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TaskHandle_t xTaskCreateStatic(
|
||||
TaskFunction_t pxTaskCode,
|
||||
const char * const pcName,
|
||||
const uint32_t ulStackDepth,
|
||||
void * const pvParameters,
|
||||
UBaseType_t uxPriority,
|
||||
StackType_t * const puxStackBuffer,
|
||||
StaticTask_t * const pxTaskBuffer
|
||||
) {
|
||||
TaskHandle_t xTaskCreateStatic(TaskFunction_t pxTaskCode,
|
||||
const char* const pcName,
|
||||
const uint32_t ulStackDepth,
|
||||
void* const pvParameters,
|
||||
UBaseType_t uxPriority,
|
||||
StackType_t* const puxStackBuffer,
|
||||
StaticTask_t* const pxTaskBuffer) {
|
||||
TaskHandle_t thread = malloc(sizeof(TaskHandle_t));
|
||||
PthreadTask* task = malloc(sizeof(PthreadTask));
|
||||
|
||||
@@ -51,14 +49,13 @@ TaskHandle_t xTaskCreateStatic(
|
||||
}
|
||||
|
||||
void vTaskDelete(TaskHandle_t xTask) {
|
||||
|
||||
if(xTask == NULL) {
|
||||
// kill itself
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
// maybe thread already join
|
||||
if (pthread_kill(*xTask, 0) == ESRCH) return;
|
||||
if(pthread_kill(*xTask, 0) == ESRCH) return;
|
||||
|
||||
// send thread_child signal to stop it сигнал, который ее завершает
|
||||
pthread_cancel(*xTask);
|
||||
@@ -78,20 +75,16 @@ TaskHandle_t xTaskGetCurrentTaskHandle(void) {
|
||||
|
||||
bool task_equal(TaskHandle_t a, TaskHandle_t b) {
|
||||
if(a == NULL || b == NULL) return false;
|
||||
|
||||
|
||||
return pthread_equal(*a, *b) != 0;
|
||||
}
|
||||
|
||||
BaseType_t xQueueSend(
|
||||
QueueHandle_t xQueue, const void * pvItemToQueue, TickType_t xTicksToWait
|
||||
) {
|
||||
BaseType_t xQueueSend(QueueHandle_t xQueue, const void* pvItemToQueue, TickType_t xTicksToWait) {
|
||||
// TODO: add implementation
|
||||
return pdTRUE;
|
||||
}
|
||||
|
||||
BaseType_t xQueueReceive(
|
||||
QueueHandle_t xQueue, void *pvBuffer, TickType_t xTicksToWait
|
||||
) {
|
||||
BaseType_t xQueueReceive(QueueHandle_t xQueue, void* pvBuffer, TickType_t xTicksToWait) {
|
||||
// TODO: add implementation
|
||||
osDelay(100);
|
||||
|
||||
@@ -100,12 +93,10 @@ BaseType_t xQueueReceive(
|
||||
|
||||
static uint32_t queue_global_id = 0;
|
||||
|
||||
QueueHandle_t xQueueCreateStatic(
|
||||
UBaseType_t uxQueueLength,
|
||||
UBaseType_t uxItemSize,
|
||||
uint8_t* pucQueueStorageBuffer,
|
||||
StaticQueue_t *pxQueueBuffer
|
||||
) {
|
||||
QueueHandle_t xQueueCreateStatic(UBaseType_t uxQueueLength,
|
||||
UBaseType_t uxItemSize,
|
||||
uint8_t* pucQueueStorageBuffer,
|
||||
StaticQueue_t* pxQueueBuffer) {
|
||||
// TODO: check this implementation
|
||||
int* msgid = malloc(sizeof(int));
|
||||
|
||||
@@ -117,11 +108,9 @@ QueueHandle_t xQueueCreateStatic(
|
||||
return (QueueHandle_t)msgid;
|
||||
}
|
||||
|
||||
SemaphoreHandle_t xSemaphoreCreateCountingStatic(
|
||||
UBaseType_t uxMaxCount,
|
||||
UBaseType_t uxInitialCount,
|
||||
StaticSemaphore_t* pxSemaphoreBuffer
|
||||
) {
|
||||
SemaphoreHandle_t xSemaphoreCreateCountingStatic(UBaseType_t uxMaxCount,
|
||||
UBaseType_t uxInitialCount,
|
||||
StaticSemaphore_t* pxSemaphoreBuffer) {
|
||||
pxSemaphoreBuffer->type = SemaphoreTypeCounting;
|
||||
pxSemaphoreBuffer->take_counter = 0;
|
||||
pxSemaphoreBuffer->give_counter = 0;
|
||||
@@ -136,24 +125,23 @@ SemaphoreHandle_t xSemaphoreCreateMutexStatic(StaticSemaphore_t* pxMutexBuffer)
|
||||
return pxMutexBuffer;
|
||||
}
|
||||
|
||||
|
||||
BaseType_t xSemaphoreTake(volatile SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait) {
|
||||
if(xSemaphore == NULL) return pdFALSE;
|
||||
|
||||
if (xSemaphore->type == SemaphoreTypeMutex) {
|
||||
if (xTicksToWait == portMAX_DELAY) {
|
||||
if (pthread_mutex_lock(&xSemaphore->mutex) == 0) {
|
||||
if(xSemaphore->type == SemaphoreTypeMutex) {
|
||||
if(xTicksToWait == portMAX_DELAY) {
|
||||
if(pthread_mutex_lock(&xSemaphore->mutex) == 0) {
|
||||
return pdTRUE;
|
||||
} else {
|
||||
return pdFALSE;
|
||||
}
|
||||
} else {
|
||||
TickType_t ticks = xTicksToWait;
|
||||
while (ticks >= 0) {
|
||||
if (pthread_mutex_trylock(&xSemaphore->mutex) == 0) {
|
||||
while(ticks >= 0) {
|
||||
if(pthread_mutex_trylock(&xSemaphore->mutex) == 0) {
|
||||
return pdTRUE;
|
||||
}
|
||||
if (ticks > 0) {
|
||||
if(ticks > 0) {
|
||||
osDelay(1);
|
||||
}
|
||||
ticks--;
|
||||
@@ -167,10 +155,8 @@ BaseType_t xSemaphoreTake(volatile SemaphoreHandle_t xSemaphore, TickType_t xTic
|
||||
|
||||
TickType_t ticks = xTicksToWait;
|
||||
|
||||
while(
|
||||
xSemaphore->take_counter != xSemaphore->give_counter
|
||||
&& (ticks > 0 || xTicksToWait == portMAX_DELAY)
|
||||
) {
|
||||
while(xSemaphore->take_counter != xSemaphore->give_counter &&
|
||||
(ticks > 0 || xTicksToWait == portMAX_DELAY)) {
|
||||
osDelay(1);
|
||||
ticks--;
|
||||
}
|
||||
@@ -183,8 +169,8 @@ BaseType_t xSemaphoreTake(volatile SemaphoreHandle_t xSemaphore, TickType_t xTic
|
||||
BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore) {
|
||||
if(xSemaphore == NULL) return pdFALSE;
|
||||
|
||||
if (xSemaphore->type == SemaphoreTypeMutex) {
|
||||
if (pthread_mutex_unlock(&xSemaphore->mutex) == 0) {
|
||||
if(xSemaphore->type == SemaphoreTypeMutex) {
|
||||
if(pthread_mutex_unlock(&xSemaphore->mutex) == 0) {
|
||||
return pdTRUE;
|
||||
} else {
|
||||
return pdFALSE;
|
||||
@@ -202,20 +188,18 @@ static pthread_key_t tls_keys[TLS_ITEM_COUNT];
|
||||
static pthread_once_t tls_keys_once = PTHREAD_ONCE_INIT;
|
||||
|
||||
static void create_tls_keys() {
|
||||
for (size_t i = 0; i < TLS_ITEM_COUNT; i++) {
|
||||
for(size_t i = 0; i < TLS_ITEM_COUNT; i++) {
|
||||
pthread_key_create(&tls_keys[i], NULL);
|
||||
}
|
||||
}
|
||||
|
||||
void* pvTaskGetThreadLocalStoragePointer(
|
||||
TaskHandle_t xTaskToQuery, BaseType_t xIndex
|
||||
) {
|
||||
void* pvTaskGetThreadLocalStoragePointer(TaskHandle_t xTaskToQuery, BaseType_t xIndex) {
|
||||
// Non-current task TLS access is not allowed
|
||||
if (xTaskToQuery != NULL) {
|
||||
if(xTaskToQuery != NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (xIndex >= TLS_ITEM_COUNT) {
|
||||
if(xIndex >= TLS_ITEM_COUNT) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -224,15 +208,13 @@ void* pvTaskGetThreadLocalStoragePointer(
|
||||
return pthread_getspecific(tls_keys[xIndex]);
|
||||
}
|
||||
|
||||
void vTaskSetThreadLocalStoragePointer(
|
||||
TaskHandle_t xTaskToSet, BaseType_t xIndex, void *pvValue
|
||||
) {
|
||||
void vTaskSetThreadLocalStoragePointer(TaskHandle_t xTaskToSet, BaseType_t xIndex, void* pvValue) {
|
||||
// Non-current task TLS access is not allowed
|
||||
if (xTaskToSet != NULL) {
|
||||
if(xTaskToSet != NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (xIndex >= TLS_ITEM_COUNT) {
|
||||
if(xIndex >= TLS_ITEM_COUNT) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user