@turingcode/cli 0.3.14 → 0.3.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/create-cli.js +46 -31
- package/dist/core/mcp.d.ts +0 -10
- package/dist/core/mcp.js +0 -18
- package/dist/features/contract/command.js +64 -64
- package/dist/features/probe/program_project.js +3 -3
- package/dist/features/project/analysis_static.js +7 -6
- package/dist/features/project/command.d.ts +3 -1
- package/dist/features/project/command.js +15 -11
- package/dist/features/project/project_regenerate.js +4 -3
- package/dist/features/project/project_sync_from_server.js +4 -3
- package/dist/features/project/project_sync_to_server.js +36 -11
- package/dist/features/project/stm32_cubetools_download_drivers.js +5 -4
- package/dist/features/status/get_status.js +6 -3
- package/dist/features/syntax-check/command.d.ts +2 -0
- package/dist/features/syntax-check/command.js +8 -0
- package/dist/features/syntax-check/syntax_check.d.ts +3 -0
- package/dist/features/syntax-check/syntax_check.js +27 -0
- package/dist/features/tool/command.d.ts +2 -0
- package/dist/features/tool/command.js +58 -7
- package/dist/lib.d.ts +1 -1
- package/dist/lib.js +1 -1
- package/dist/stm32/analysis.d.ts +40 -4
- package/dist/stm32/analysis.js +61 -5
- package/dist/stm32/toolCommand.d.ts +1 -0
- package/dist/stm32/toolCommand.js +7 -2
- package/dist/stm32/utils/makeTempProject.d.ts +16 -0
- package/dist/stm32/utils/makeTempProject.js +79 -0
- package/dist/stm32/utils/project_utils.d.ts +36 -1
- package/dist/stm32/utils/project_utils.js +48 -2
- package/mods/claude/turingcode-skills/skills/AGENTS.md +0 -5
- package/mods/claude/turingcode-skills/skills/turingcode-cli/SKILL.md +48 -47
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/SKILL.md +50 -42
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/M_StatusEnum.md +24 -6
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/code/BusMutexRegistry.hpp +138 -0
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/code/Util_MutexManager.hpp +212 -0
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/driver/driver.md +72 -0
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/driver/driver_ic.md +125 -0
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/driver/driver_protocol.md +116 -0
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/driver/driver_rtos.md +130 -0
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/driver/driver_test.md +14 -0
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/storage.md +57 -57
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/tasks-and-interrupts.md +70 -70
- package/package.json +2 -2
- package/dist/features/project/analysis_syntax_check.d.ts +0 -3
- package/dist/features/project/analysis_syntax_check.js +0 -21
- package/mods/claude/turingcode-skills/skills/turingcode-firmware-code/references/driver.md +0 -97
|
@@ -1,70 +1,70 @@
|
|
|
1
|
-
# Tasks and interrupts
|
|
2
|
-
|
|
3
|
-
- Use this when writing ISRs, HAL callbacks, the main loop, RTOS tasks, DMA, or data shared between them.
|
|
4
|
-
|
|
5
|
-
## ISRs
|
|
6
|
-
|
|
7
|
-
- Only signal from an ISR: set an event bit, notify a task, or bump a counter. Do bus transfers, parsing and math in the loop or a task; in an ISR they block every lower-priority interrupt.
|
|
8
|
-
- Never call blocking HAL (`HAL_SPI_Transmit`, `HAL_Delay`, ...) or `printf` in an ISR.
|
|
9
|
-
- Use one event bit per source.
|
|
10
|
-
- Count events that must not be lost; bits merge when an event repeats before it's handled:
|
|
11
|
-
```cpp
|
|
12
|
-
while (this->_done != g_isr_count) { handle_event(); this->_done++; } // g_isr_count: volatile, ++ in the ISR
|
|
13
|
-
```
|
|
14
|
-
- Null-check globals in callbacks; they can fire before the object exists.
|
|
15
|
-
|
|
16
|
-
## Without an RTOS
|
|
17
|
-
|
|
18
|
-
- Set bits in a `volatile` event word in the ISR. In the loop, take and clear it with interrupts off, then work with them on:
|
|
19
|
-
```cpp
|
|
20
|
-
__disable_irq();
|
|
21
|
-
uint32_t events = g_events;
|
|
22
|
-
g_events = 0;
|
|
23
|
-
__enable_irq();
|
|
24
|
-
if (events & EVT_IMU_READY) imu->read_into_memory();
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## With FreeRTOS
|
|
28
|
-
|
|
29
|
-
- Notify the worker task from the ISR with `...FromISR` APIs, then yield:
|
|
30
|
-
```cpp
|
|
31
|
-
BaseType_t woken = pdFALSE;
|
|
32
|
-
xTaskNotifyFromISR(reader_task, EVT_IMU_READY, eSetBits, &woken);
|
|
33
|
-
portYIELD_FROM_ISR(woken);
|
|
34
|
-
```
|
|
35
|
-
- When an interrupt marks new data (UART RX event, data-ready pin, DMA complete), notify the task from it; don't make the task poll with `osDelay`. Poll only when no interrupt source exists, and say so in a comment.
|
|
36
|
-
- One notification can stand for several events: on each wake, handle everything pending (loop until no complete item is left).
|
|
37
|
-
- Set the task handle before enabling the IRQ, and reset it to `nullptr` if task creation fails.
|
|
38
|
-
- Give ISRs that call FreeRTOS an NVIC priority ≥ `configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY` (numerically).
|
|
39
|
-
- Wait with a timeout as a safety net; on timeout poll the source, so a missed edge (or data a parse step left behind) can't stall the task:
|
|
40
|
-
```cpp
|
|
41
|
-
if (xTaskNotifyWait(0, UINT32_MAX, &bits, pdMS_TO_TICKS(50)) != pdTRUE
|
|
42
|
-
&& HAL_GPIO_ReadPin(IMU_DRDY_GPIO_Port, IMU_DRDY_Pin)) bits |= EVT_IMU_READY;
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
## Shared data
|
|
46
|
-
|
|
47
|
-
- ISR ↔ loop or task: copy and clear under a critical section, then work on the copy. Use `taskENTER_CRITICAL()` with FreeRTOS, `__disable_irq()` without:
|
|
48
|
-
```cpp
|
|
49
|
-
taskENTER_CRITICAL();
|
|
50
|
-
size_t n = rx_len;
|
|
51
|
-
memcpy(local, rx_buf, n);
|
|
52
|
-
rx_len = 0;
|
|
53
|
-
taskEXIT_CRITICAL();
|
|
54
|
-
parse(local, n); // never parse rx_buf in place
|
|
55
|
-
```
|
|
56
|
-
- Task ↔ task: take a mutex with a timeout, never `portMAX_DELAY`. On timeout, skip this cycle.
|
|
57
|
-
|
|
58
|
-
## DMA
|
|
59
|
-
|
|
60
|
-
- Use static or member buffers, never locals; DMA keeps running after the call returns.
|
|
61
|
-
- Check the length against the buffer size before copying in.
|
|
62
|
-
- Take a semaphore (RTOS) or test-and-set a busy flag with interrupts off (bare-metal) before writing the buffer. Release it in the complete callback, and yourself if the start fails:
|
|
63
|
-
```cpp
|
|
64
|
-
if (HAL_UART_Transmit_DMA(this->_huart, this->_tx_buf, len) != HAL_OK) {
|
|
65
|
-
this->_tx_busy = false; // or this->_tx_sem.release()
|
|
66
|
-
return M_StatusEnum::M_ERROR;
|
|
67
|
-
}
|
|
68
|
-
```
|
|
69
|
-
- Enable both the DMA and the peripheral interrupt in the `.ioc`; UART TX completion comes from the USART IRQ.
|
|
70
|
-
- Check the generated `*_IRQHandler` calls `HAL_DMA_IRQHandler` / `HAL_UART_IRQHandler`. If empty, add it in USER CODE; otherwise the IRQ re-enters forever.
|
|
1
|
+
# Tasks and interrupts
|
|
2
|
+
|
|
3
|
+
- Use this when writing ISRs, HAL callbacks, the main loop, RTOS tasks, DMA, or data shared between them.
|
|
4
|
+
|
|
5
|
+
## ISRs
|
|
6
|
+
|
|
7
|
+
- Only signal from an ISR: set an event bit, notify a task, or bump a counter. Do bus transfers, parsing and math in the loop or a task; in an ISR they block every lower-priority interrupt.
|
|
8
|
+
- Never call blocking HAL (`HAL_SPI_Transmit`, `HAL_Delay`, ...) or `printf` in an ISR.
|
|
9
|
+
- Use one event bit per source.
|
|
10
|
+
- Count events that must not be lost; bits merge when an event repeats before it's handled:
|
|
11
|
+
```cpp
|
|
12
|
+
while (this->_done != g_isr_count) { handle_event(); this->_done++; } // g_isr_count: volatile, ++ in the ISR
|
|
13
|
+
```
|
|
14
|
+
- Null-check globals in callbacks; they can fire before the object exists.
|
|
15
|
+
|
|
16
|
+
## Without an RTOS
|
|
17
|
+
|
|
18
|
+
- Set bits in a `volatile` event word in the ISR. In the loop, take and clear it with interrupts off, then work with them on:
|
|
19
|
+
```cpp
|
|
20
|
+
__disable_irq();
|
|
21
|
+
uint32_t events = g_events;
|
|
22
|
+
g_events = 0;
|
|
23
|
+
__enable_irq();
|
|
24
|
+
if (events & EVT_IMU_READY) imu->read_into_memory();
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## With FreeRTOS
|
|
28
|
+
|
|
29
|
+
- Notify the worker task from the ISR with `...FromISR` APIs, then yield:
|
|
30
|
+
```cpp
|
|
31
|
+
BaseType_t woken = pdFALSE;
|
|
32
|
+
xTaskNotifyFromISR(reader_task, EVT_IMU_READY, eSetBits, &woken);
|
|
33
|
+
portYIELD_FROM_ISR(woken);
|
|
34
|
+
```
|
|
35
|
+
- When an interrupt marks new data (UART RX event, data-ready pin, DMA complete), notify the task from it; don't make the task poll with `osDelay`. Poll only when no interrupt source exists, and say so in a comment.
|
|
36
|
+
- One notification can stand for several events: on each wake, handle everything pending (loop until no complete item is left).
|
|
37
|
+
- Set the task handle before enabling the IRQ, and reset it to `nullptr` if task creation fails.
|
|
38
|
+
- Give ISRs that call FreeRTOS an NVIC priority ≥ `configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY` (numerically).
|
|
39
|
+
- Wait with a timeout as a safety net; on timeout poll the source, so a missed edge (or data a parse step left behind) can't stall the task:
|
|
40
|
+
```cpp
|
|
41
|
+
if (xTaskNotifyWait(0, UINT32_MAX, &bits, pdMS_TO_TICKS(50)) != pdTRUE
|
|
42
|
+
&& HAL_GPIO_ReadPin(IMU_DRDY_GPIO_Port, IMU_DRDY_Pin)) bits |= EVT_IMU_READY;
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Shared data
|
|
46
|
+
|
|
47
|
+
- ISR ↔ loop or task: copy and clear under a critical section, then work on the copy. Use `taskENTER_CRITICAL()` with FreeRTOS, `__disable_irq()` without:
|
|
48
|
+
```cpp
|
|
49
|
+
taskENTER_CRITICAL();
|
|
50
|
+
size_t n = rx_len;
|
|
51
|
+
memcpy(local, rx_buf, n);
|
|
52
|
+
rx_len = 0;
|
|
53
|
+
taskEXIT_CRITICAL();
|
|
54
|
+
parse(local, n); // never parse rx_buf in place
|
|
55
|
+
```
|
|
56
|
+
- Task ↔ task: take a mutex with a timeout, never `portMAX_DELAY`. On timeout, skip this cycle.
|
|
57
|
+
|
|
58
|
+
## DMA
|
|
59
|
+
|
|
60
|
+
- Use static or member buffers, never locals; DMA keeps running after the call returns.
|
|
61
|
+
- Check the length against the buffer size before copying in.
|
|
62
|
+
- Take a semaphore (RTOS) or test-and-set a busy flag with interrupts off (bare-metal) before writing the buffer. Release it in the complete callback, and yourself if the start fails:
|
|
63
|
+
```cpp
|
|
64
|
+
if (HAL_UART_Transmit_DMA(this->_huart, this->_tx_buf, len) != HAL_OK) {
|
|
65
|
+
this->_tx_busy = false; // or this->_tx_sem.release()
|
|
66
|
+
return M_StatusEnum::M_ERROR;
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
- Enable both the DMA and the peripheral interrupt in the `.ioc`; UART TX completion comes from the USART IRQ.
|
|
70
|
+
- Check the generated `*_IRQHandler` calls `HAL_DMA_IRQHandler` / `HAL_UART_IRQHandler`. If empty, add it in USER CODE; otherwise the IRQ re-enters forever.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@turingcode/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.15",
|
|
4
4
|
"description": "Turing Code toolkit for AI agents: check Markdown/CSV tables against table contracts, e.g. `turingcode table check`.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -42,4 +42,4 @@
|
|
|
42
42
|
"@types/yargs": "17.0.35",
|
|
43
43
|
"typescript": "7.0.2"
|
|
44
44
|
}
|
|
45
|
-
}
|
|
45
|
+
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { syntaxCheckProject } from '../../stm32/analysis.js';
|
|
2
|
-
import { callServer } from '../../stm32/context.js';
|
|
3
|
-
import { _defineTool } from '../../stm32/tool.js';
|
|
4
|
-
import { findStm32Project } from '../../stm32/utils/project_utils.js';
|
|
5
|
-
/** Syntax-checks files of the server copy; local project-relative paths are mapped to projects/<name>/. */
|
|
6
|
-
export default _defineTool({
|
|
7
|
-
name: 'analysis_syntax_check',
|
|
8
|
-
description: 'Check .c/.h/.cpp/.hpp files of your stm32 project for syntax errors on the TuringCode server \
|
|
9
|
-
(run `turingcode project sync` first to include local changes). Returns `file:line:col: severity: message` lines.',
|
|
10
|
-
properties: {
|
|
11
|
-
files: {
|
|
12
|
-
type: 'string',
|
|
13
|
-
description: 'Comma-separated project-relative files, globs or folders, e.g. Core/Src/main.c (default: Core,App)',
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
run: async (args) => {
|
|
17
|
-
const project = await findStm32Project();
|
|
18
|
-
const files = (args.files || 'Core,App').split(',').map(f => f.trim()).filter(Boolean);
|
|
19
|
-
return syntaxCheckProject(callServer, project, files);
|
|
20
|
-
},
|
|
21
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
# Writing and Editing an IC driver
|
|
2
|
-
|
|
3
|
-
- Use this when you want to create or edit driver for ICs or Protocols.
|
|
4
|
-
- If the project already has a COM driver or an IC base with similar names, inherit from it. Don't write a second one.
|
|
5
|
-
|
|
6
|
-
## Layers
|
|
7
|
-
|
|
8
|
-
- `COM_Driver` is the base for protocol drivers (`COM_SPI`, `COM_I2C`). Only these call HAL.
|
|
9
|
-
- `IC_Driver` is the base for IC drivers in `Drivers/<IC>/`. It talks to the chip only through a `COM_Driver*`.
|
|
10
|
-
|
|
11
|
-
## COM driver
|
|
12
|
-
|
|
13
|
-
- Used as a base class for communication protocols (I2C, SPI, ...)
|
|
14
|
-
- Subclasses implement transfers (read and write) using HAL or LL methods.
|
|
15
|
-
|
|
16
|
-
```cpp
|
|
17
|
-
class COM_Driver {
|
|
18
|
-
public:
|
|
19
|
-
virtual M_Status read(uint8_t reg, uint8_t* data, size_t len = 1) = 0;
|
|
20
|
-
virtual M_Status write(uint8_t reg, const uint8_t* data, size_t len) = 0;
|
|
21
|
-
|
|
22
|
-
M_Status write_bit(uint8_t reg, uint8_t bit, uint8_t value); // read-modify-write
|
|
23
|
-
M_Status write_verify(uint8_t reg, uint8_t value, size_t tries); // write, read back, compare
|
|
24
|
-
M_Status wait_for_register(uint8_t reg, uint8_t expected, size_t tries);
|
|
25
|
-
void set_address_mask(uint8_t write_or, uint8_t read_or); // e.g. SPI read bit 0x80
|
|
26
|
-
};
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
### Protocol driver
|
|
30
|
-
|
|
31
|
-
- Owns the HAL handle and chip select; the IC driver never sees them.
|
|
32
|
-
- Holds the bus mutex for the whole transfer, chip select included, so ICs sharing the bus don't interleave.
|
|
33
|
-
|
|
34
|
-
```cpp
|
|
35
|
-
class COM_SPI : public COM_Driver {
|
|
36
|
-
public:
|
|
37
|
-
COM_SPI(SPI_HandleTypeDef* hspi, GPIO_TypeDef* cs_port, uint16_t cs_pin);
|
|
38
|
-
M_Status read(uint8_t reg, uint8_t* data, size_t len = 1) override; // CS low, TX reg|read mask, RX data, CS high
|
|
39
|
-
M_Status write(uint8_t reg, const uint8_t* data, size_t len) override;
|
|
40
|
-
private:
|
|
41
|
-
SPI_HandleTypeDef* _hspi;
|
|
42
|
-
GPIO_TypeDef* _cs_port;
|
|
43
|
-
uint16_t _cs_pin;
|
|
44
|
-
};
|
|
45
|
-
```
|
|
46
|
-
|
|
47
|
-
## IC_Driver Class
|
|
48
|
-
|
|
49
|
-
- Base class used for all ICs
|
|
50
|
-
- Subclasses implement the virtual methods.
|
|
51
|
-
- A feature the IC lacks (eg: write into a temperature sensor) returns `M_StatusEnum::M_NOT_SUPPORTED`, never `M_StatusEnum::M_OK`.
|
|
52
|
-
- ICs of one family can share a templated base between the two for compile-time sample sizes, (eg: `template <size_t AXES, size_t BYTES_PER_AXIS> class IC_Sensor : public IC_Driver`).
|
|
53
|
-
|
|
54
|
-
```cpp
|
|
55
|
-
class IC_Driver {
|
|
56
|
-
public:
|
|
57
|
-
explicit IC_Driver(COM_Driver* com) : _com(com) {}
|
|
58
|
-
virtual M_Status init() = 0;
|
|
59
|
-
virtual M_Status reset() = 0;
|
|
60
|
-
virtual M_Status read(uint8_t* buf, size_t* index) = 0; // appends at buf[*index]
|
|
61
|
-
protected:
|
|
62
|
-
COM_Driver* com() { return this->_com; }
|
|
63
|
-
private:
|
|
64
|
-
COM_Driver* _com;
|
|
65
|
-
};
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### IC Sensor Driver
|
|
69
|
-
|
|
70
|
-
```cpp
|
|
71
|
-
class Sensor_ABC123 : public IC_Driver {
|
|
72
|
-
public:
|
|
73
|
-
using IC_Driver::IC_Driver;
|
|
74
|
-
M_Status init() override;
|
|
75
|
-
M_Status reset() override;
|
|
76
|
-
M_Status read(uint8_t* buf, size_t* index) override;
|
|
77
|
-
M_Status verify_id() { return this->com()->wait_for_register(ABC123_WHO_AM_I, ABC123_ID, 5); }
|
|
78
|
-
};
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
- It never calls HAL and never creates its COM driver. The owner wires the two together:
|
|
82
|
-
```cpp
|
|
83
|
-
COM_SPI spi_imu(&hspi1, IMU_CS_GPIO_Port, IMU_CS_Pin);
|
|
84
|
-
Sensor_ABC123 imu(&spi_imu);
|
|
85
|
-
```
|
|
86
|
-
|
|
87
|
-
## Register header
|
|
88
|
-
|
|
89
|
-
`abc123_regs.h`, plain C, in datasheet order:
|
|
90
|
-
```c
|
|
91
|
-
#define ABC123_WHO_AM_I 0x0F
|
|
92
|
-
#define ABC123_ID 0x6B
|
|
93
|
-
#define ABC123_CTRL1 0x10
|
|
94
|
-
#define ABC123_ODR_POS 4
|
|
95
|
-
#define ABC123_ODR_MASK (0x0F << ABC123_ODR_POS)
|
|
96
|
-
#define ABC123_SPI_READ 0x80
|
|
97
|
-
```
|