@mytechtoday/augment-extensions 1.4.0 → 1.5.0
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/augment-extensions/coding-standards/c/CHANGELOG.md +55 -0
- package/augment-extensions/coding-standards/c/LICENSE +22 -0
- package/augment-extensions/coding-standards/c/README.md +167 -0
- package/augment-extensions/coding-standards/c/config/defaults.json +26 -0
- package/augment-extensions/coding-standards/c/config/examples/embedded.yaml +25 -0
- package/augment-extensions/coding-standards/c/config/examples/systems.json +31 -0
- package/augment-extensions/coding-standards/c/config/schema.json +244 -0
- package/augment-extensions/coding-standards/c/docs/API.md +613 -0
- package/augment-extensions/coding-standards/c/docs/CONFIGURATION.md +259 -0
- package/augment-extensions/coding-standards/c/docs/USER_GUIDE.md +567 -0
- package/augment-extensions/coding-standards/c/examples/drivers/Makefile +33 -0
- package/augment-extensions/coding-standards/c/examples/drivers/README.md +192 -0
- package/augment-extensions/coding-standards/c/examples/drivers/dma-example.c +224 -0
- package/augment-extensions/coding-standards/c/examples/drivers/example.dts +64 -0
- package/augment-extensions/coding-standards/c/examples/drivers/platform-driver.c +174 -0
- package/augment-extensions/coding-standards/c/examples/embedded/README.md +167 -0
- package/augment-extensions/coding-standards/c/examples/embedded/gpio-control.c +172 -0
- package/augment-extensions/coding-standards/c/examples/embedded/timer-isr.c +198 -0
- package/augment-extensions/coding-standards/c/examples/embedded/uart-communication.c +212 -0
- package/augment-extensions/coding-standards/c/examples/kernel/Makefile +82 -0
- package/augment-extensions/coding-standards/c/examples/kernel/README.md +168 -0
- package/augment-extensions/coding-standards/c/examples/kernel/char-device.c +198 -0
- package/augment-extensions/coding-standards/c/examples/kernel/proc-file.c +131 -0
- package/augment-extensions/coding-standards/c/examples/kernel/simple-module.c +111 -0
- package/augment-extensions/coding-standards/c/examples/legacy/Makefile +62 -0
- package/augment-extensions/coding-standards/c/examples/legacy/README.md +255 -0
- package/augment-extensions/coding-standards/c/examples/legacy/c89-to-c11-migration.c +268 -0
- package/augment-extensions/coding-standards/c/examples/legacy/compatibility-layer.c +239 -0
- package/augment-extensions/coding-standards/c/examples/networking/Makefile +35 -0
- package/augment-extensions/coding-standards/c/examples/networking/README.md +207 -0
- package/augment-extensions/coding-standards/c/examples/networking/protocol-parser.c +270 -0
- package/augment-extensions/coding-standards/c/examples/networking/tcp-server.c +197 -0
- package/augment-extensions/coding-standards/c/examples/networking/udp-multicast.c +220 -0
- package/augment-extensions/coding-standards/c/examples/realtime/Makefile +53 -0
- package/augment-extensions/coding-standards/c/examples/realtime/README.md +199 -0
- package/augment-extensions/coding-standards/c/examples/realtime/deadline-monitoring.c +260 -0
- package/augment-extensions/coding-standards/c/examples/realtime/priority-scheduling.c +258 -0
- package/augment-extensions/coding-standards/c/examples/systems/Makefile +34 -0
- package/augment-extensions/coding-standards/c/examples/systems/README.md +123 -0
- package/augment-extensions/coding-standards/c/examples/systems/ipc-pipes.c +181 -0
- package/augment-extensions/coding-standards/c/examples/systems/process-management.c +153 -0
- package/augment-extensions/coding-standards/c/examples/systems/signal-handling.c +162 -0
- package/augment-extensions/coding-standards/c/module.json +149 -0
- package/augment-extensions/coding-standards/c/rules/categories/drivers.md +635 -0
- package/augment-extensions/coding-standards/c/rules/categories/embedded.md +510 -0
- package/augment-extensions/coding-standards/c/rules/categories/kernel.md +653 -0
- package/augment-extensions/coding-standards/c/rules/categories/legacy.md +526 -0
- package/augment-extensions/coding-standards/c/rules/categories/networking.md +735 -0
- package/augment-extensions/coding-standards/c/rules/categories/realtime.md +631 -0
- package/augment-extensions/coding-standards/c/rules/categories/systems.md +586 -0
- package/augment-extensions/coding-standards/c/rules/universal/const-correctness.md +275 -0
- package/augment-extensions/coding-standards/c/rules/universal/documentation.md +251 -0
- package/augment-extensions/coding-standards/c/rules/universal/error-handling.md +250 -0
- package/augment-extensions/coding-standards/c/rules/universal/header-guards.md +254 -0
- package/augment-extensions/coding-standards/c/rules/universal/memory-safety.md +233 -0
- package/augment-extensions/coding-standards/c/rules/universal/naming.md +146 -0
- package/augment-extensions/coding-standards/c/src/conflict-detector.ts +461 -0
- package/augment-extensions/coding-standards/c/src/prompt-generator.ts +307 -0
- package/augment-extensions/coding-standards/c/src/rule-evaluator.ts +307 -0
- package/augment-extensions/coding-standards/c/src/rule-override.ts +427 -0
- package/augment-extensions/coding-standards/c/src/template-engine.ts +217 -0
- package/augment-extensions/coding-standards/c/templates/prompts/drivers.txt +191 -0
- package/augment-extensions/coding-standards/c/templates/prompts/embedded.txt +164 -0
- package/augment-extensions/coding-standards/c/templates/prompts/kernel.txt +175 -0
- package/augment-extensions/coding-standards/c/templates/prompts/legacy.txt +280 -0
- package/augment-extensions/coding-standards/c/templates/prompts/networking.txt +259 -0
- package/augment-extensions/coding-standards/c/templates/prompts/realtime.txt +219 -0
- package/augment-extensions/coding-standards/c/templates/prompts/systems.txt +147 -0
- package/augment-extensions/coding-standards/c/tests/integration/category-specific.test.ts +356 -0
- package/augment-extensions/coding-standards/c/tests/integration/end-to-end-workflow.test.ts +377 -0
- package/augment-extensions/coding-standards/c/tests/performance/benchmarks.test.ts +407 -0
- package/augment-extensions/coding-standards/c/tests/unit/config-manager.test.ts +345 -0
- package/augment-extensions/coding-standards/c/tests/unit/conflict-detector.test.ts +294 -0
- package/augment-extensions/coding-standards/c/tests/unit/prompt-generator.test.ts +174 -0
- package/augment-extensions/coding-standards/c/tests/unit/registry.test.ts +313 -0
- package/augment-extensions/coding-standards/c/tests/unit/rule-evaluator.test.ts +318 -0
- package/augment-extensions/coding-standards/c/tests/unit/rule-override.test.ts +326 -0
- package/augment-extensions/coding-standards/c/tests/unit/template-engine.test.ts +314 -0
- package/augment-extensions/coding-standards/go/CHARACTER-COUNT-REPORT.md +135 -0
- package/augment-extensions/coding-standards/go/PHASE1-COMPLETION.md +146 -0
- package/augment-extensions/coding-standards/go/PHASE4-COMPLETION.md +184 -0
- package/augment-extensions/coding-standards/go/README.md +200 -0
- package/augment-extensions/coding-standards/go/VALIDATION-CHECKLIST.md +154 -0
- package/augment-extensions/coding-standards/go/config/examples/example-cli.json +15 -0
- package/augment-extensions/coding-standards/go/config/examples/example-microservices.json +21 -0
- package/augment-extensions/coding-standards/go/config/examples/example-multi-category.yaml +24 -0
- package/augment-extensions/coding-standards/go/config/examples/example-web.json +15 -0
- package/augment-extensions/coding-standards/go/config/schema.json +110 -0
- package/augment-extensions/coding-standards/go/docs/CATEGORIES.md +221 -0
- package/augment-extensions/coding-standards/go/docs/CONFIGURATION.md +198 -0
- package/augment-extensions/coding-standards/go/docs/TROUBLESHOOTING.md +285 -0
- package/augment-extensions/coding-standards/go/examples/cli/cobra-app.go +287 -0
- package/augment-extensions/coding-standards/go/examples/cloud-native-app.go +217 -0
- package/augment-extensions/coding-standards/go/examples/devops-tool.go +250 -0
- package/augment-extensions/coding-standards/go/examples/distributed-system.go +247 -0
- package/augment-extensions/coding-standards/go/examples/microservices/grpc-service.go +253 -0
- package/augment-extensions/coding-standards/go/examples/rest-api.go +270 -0
- package/augment-extensions/coding-standards/go/examples/web/http-server.go +224 -0
- package/augment-extensions/coding-standards/go/module.json +139 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/api-versioning.md +149 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/rate-limiting.md +209 -0
- package/augment-extensions/coding-standards/go/rules/categories/api-development/rest-api-design.md +183 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/cloud-config.md +193 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/health-checks.md +231 -0
- package/augment-extensions/coding-standards/go/rules/categories/cloud-native/kubernetes.md +180 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/automation.md +179 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/ci-cd-integration.md +147 -0
- package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/infrastructure-as-code.md +231 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/caching.md +150 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/consensus.md +187 -0
- package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/event-sourcing.md +246 -0
- package/augment-extensions/coding-standards/go/rules/cli/command-parsing.md +264 -0
- package/augment-extensions/coding-standards/go/rules/cli/configuration.md +268 -0
- package/augment-extensions/coding-standards/go/rules/cli/cross-platform.md +324 -0
- package/augment-extensions/coding-standards/go/rules/microservices/distributed-tracing.md +253 -0
- package/augment-extensions/coding-standards/go/rules/microservices/grpc.md +257 -0
- package/augment-extensions/coding-standards/go/rules/microservices/metrics.md +278 -0
- package/augment-extensions/coding-standards/go/rules/microservices/service-discovery.md +249 -0
- package/augment-extensions/coding-standards/go/rules/universal/code-organization.md +221 -0
- package/augment-extensions/coding-standards/go/rules/universal/documentation.md +269 -0
- package/augment-extensions/coding-standards/go/rules/universal/performance.md +323 -0
- package/augment-extensions/coding-standards/go/rules/universal/testing.md +162 -0
- package/augment-extensions/coding-standards/go/rules/web/graceful-shutdown.md +249 -0
- package/augment-extensions/coding-standards/go/rules/web/http-handlers.md +164 -0
- package/augment-extensions/coding-standards/go/rules/web/middleware.md +234 -0
- package/augment-extensions/coding-standards/go/rules/web/routing.md +251 -0
- package/augment-extensions/coding-standards/go/templates/prompts/api.md +160 -0
- package/augment-extensions/coding-standards/go/templates/prompts/cli.md +225 -0
- package/augment-extensions/coding-standards/go/templates/prompts/cloud-native.md +121 -0
- package/augment-extensions/coding-standards/go/templates/prompts/devops.md +146 -0
- package/augment-extensions/coding-standards/go/templates/prompts/distributed.md +133 -0
- package/augment-extensions/coding-standards/go/templates/prompts/microservices.md +225 -0
- package/augment-extensions/coding-standards/go/templates/prompts/web.md +181 -0
- package/augment-extensions/coding-standards/go/tests/integration/module-integration.test.ts +164 -0
- package/augment-extensions/coding-standards/go/tests/unit/category-selection.test.ts +147 -0
- package/augment-extensions/coding-standards/go/tests/unit/module-structure.test.ts +154 -0
- package/augment-extensions/coding-standards/go/tests/validate-character-count.ps1 +13 -0
- package/augment-extensions/coding-standards/go/tests/validate-examples.ps1 +148 -0
- package/augment-extensions/coding-standards/go/tests/validate-examples.sh +135 -0
- package/cli/dist/analysis/ast-parser.d.ts +47 -0
- package/cli/dist/analysis/ast-parser.d.ts.map +1 -0
- package/cli/dist/analysis/ast-parser.js +161 -0
- package/cli/dist/analysis/ast-parser.js.map +1 -0
- package/cli/dist/analysis/complexity-analyzer.d.ts +27 -0
- package/cli/dist/analysis/complexity-analyzer.d.ts.map +1 -0
- package/cli/dist/analysis/complexity-analyzer.js +189 -0
- package/cli/dist/analysis/complexity-analyzer.js.map +1 -0
- package/cli/dist/analysis/dependency-analyzer.d.ts +23 -0
- package/cli/dist/analysis/dependency-analyzer.d.ts.map +1 -0
- package/cli/dist/analysis/dependency-analyzer.js +237 -0
- package/cli/dist/analysis/dependency-analyzer.js.map +1 -0
- package/cli/dist/analysis/index.d.ts +9 -0
- package/cli/dist/analysis/index.d.ts.map +1 -0
- package/cli/dist/analysis/index.js +25 -0
- package/cli/dist/analysis/index.js.map +1 -0
- package/cli/dist/analysis/security-scanner.d.ts +11 -0
- package/cli/dist/analysis/security-scanner.d.ts.map +1 -0
- package/cli/dist/analysis/security-scanner.js +294 -0
- package/cli/dist/analysis/security-scanner.js.map +1 -0
- package/cli/dist/analysis/types.d.ts +151 -0
- package/cli/dist/analysis/types.d.ts.map +1 -0
- package/cli/dist/analysis/types.js +6 -0
- package/cli/dist/analysis/types.js.map +1 -0
- package/cli/dist/cli.js +24 -0
- package/cli/dist/cli.js.map +1 -1
- package/cli/dist/commands/code-analysis.d.ts +11 -0
- package/cli/dist/commands/code-analysis.d.ts.map +1 -0
- package/cli/dist/commands/code-analysis.js +412 -0
- package/cli/dist/commands/code-analysis.js.map +1 -0
- package/modules.md +99 -3
- package/package.json +14 -2
- package/cli/dist/commands/agent.d.ts +0 -37
- package/cli/dist/commands/agent.d.ts.map +0 -1
- package/cli/dist/commands/agent.js +0 -222
- package/cli/dist/commands/agent.js.map +0 -1
- package/cli/dist/commands/beads.d.ts +0 -64
- package/cli/dist/commands/beads.d.ts.map +0 -1
- package/cli/dist/commands/beads.js +0 -377
- package/cli/dist/commands/beads.js.map +0 -1
- package/cli/dist/commands/change.d.ts +0 -54
- package/cli/dist/commands/change.d.ts.map +0 -1
- package/cli/dist/commands/change.js +0 -243
- package/cli/dist/commands/change.js.map +0 -1
- package/cli/dist/commands/clean.d.ts +0 -15
- package/cli/dist/commands/clean.d.ts.map +0 -1
- package/cli/dist/commands/clean.js +0 -63
- package/cli/dist/commands/clean.js.map +0 -1
- package/cli/dist/commands/clone.d.ts +0 -15
- package/cli/dist/commands/clone.d.ts.map +0 -1
- package/cli/dist/commands/clone.js +0 -49
- package/cli/dist/commands/clone.js.map +0 -1
- package/cli/dist/commands/config.d.ts +0 -33
- package/cli/dist/commands/config.d.ts.map +0 -1
- package/cli/dist/commands/config.js +0 -166
- package/cli/dist/commands/config.js.map +0 -1
- package/cli/dist/commands/context.d.ts +0 -38
- package/cli/dist/commands/context.d.ts.map +0 -1
- package/cli/dist/commands/context.js +0 -205
- package/cli/dist/commands/context.js.map +0 -1
- package/cli/dist/commands/create.d.ts +0 -18
- package/cli/dist/commands/create.d.ts.map +0 -1
- package/cli/dist/commands/create.js +0 -178
- package/cli/dist/commands/create.js.map +0 -1
- package/cli/dist/commands/diff.d.ts +0 -19
- package/cli/dist/commands/diff.d.ts.map +0 -1
- package/cli/dist/commands/diff.js +0 -104
- package/cli/dist/commands/diff.js.map +0 -1
- package/cli/dist/commands/doctor.d.ts +0 -14
- package/cli/dist/commands/doctor.d.ts.map +0 -1
- package/cli/dist/commands/doctor.js +0 -62
- package/cli/dist/commands/doctor.js.map +0 -1
- package/cli/dist/commands/export.d.ts +0 -28
- package/cli/dist/commands/export.d.ts.map +0 -1
- package/cli/dist/commands/export.js +0 -135
- package/cli/dist/commands/export.js.map +0 -1
- package/cli/dist/commands/import.d.ts +0 -23
- package/cli/dist/commands/import.d.ts.map +0 -1
- package/cli/dist/commands/import.js +0 -118
- package/cli/dist/commands/import.js.map +0 -1
- package/cli/dist/commands/prompt.d.ts +0 -45
- package/cli/dist/commands/prompt.d.ts.map +0 -1
- package/cli/dist/commands/prompt.js +0 -223
- package/cli/dist/commands/prompt.js.map +0 -1
- package/cli/dist/commands/spec.d.ts +0 -57
- package/cli/dist/commands/spec.d.ts.map +0 -1
- package/cli/dist/commands/spec.js +0 -279
- package/cli/dist/commands/spec.js.map +0 -1
- package/cli/dist/commands/stats.d.ts +0 -18
- package/cli/dist/commands/stats.d.ts.map +0 -1
- package/cli/dist/commands/stats.js +0 -85
- package/cli/dist/commands/stats.js.map +0 -1
- package/cli/dist/commands/task.d.ts +0 -65
- package/cli/dist/commands/task.d.ts.map +0 -1
- package/cli/dist/commands/task.js +0 -282
- package/cli/dist/commands/task.js.map +0 -1
- package/cli/dist/commands/template.d.ts +0 -17
- package/cli/dist/commands/template.d.ts.map +0 -1
- package/cli/dist/commands/template.js +0 -55
- package/cli/dist/commands/template.js.map +0 -1
- package/cli/dist/utils/agent-config.d.ts +0 -129
- package/cli/dist/utils/agent-config.d.ts.map +0 -1
- package/cli/dist/utils/agent-config.js +0 -297
- package/cli/dist/utils/agent-config.js.map +0 -1
- package/cli/dist/utils/beads-graph.d.ts +0 -17
- package/cli/dist/utils/beads-graph.d.ts.map +0 -1
- package/cli/dist/utils/beads-graph.js +0 -150
- package/cli/dist/utils/beads-graph.js.map +0 -1
- package/cli/dist/utils/beads-integration.d.ts +0 -112
- package/cli/dist/utils/beads-integration.d.ts.map +0 -1
- package/cli/dist/utils/beads-integration.js +0 -312
- package/cli/dist/utils/beads-integration.js.map +0 -1
- package/cli/dist/utils/beads-reporter.d.ts +0 -17
- package/cli/dist/utils/beads-reporter.d.ts.map +0 -1
- package/cli/dist/utils/beads-reporter.js +0 -160
- package/cli/dist/utils/beads-reporter.js.map +0 -1
- package/cli/dist/utils/cache-manager.d.ts +0 -55
- package/cli/dist/utils/cache-manager.d.ts.map +0 -1
- package/cli/dist/utils/cache-manager.js +0 -150
- package/cli/dist/utils/cache-manager.js.map +0 -1
- package/cli/dist/utils/change-manager.d.ts +0 -70
- package/cli/dist/utils/change-manager.d.ts.map +0 -1
- package/cli/dist/utils/change-manager.js +0 -412
- package/cli/dist/utils/change-manager.js.map +0 -1
- package/cli/dist/utils/config-manager-enhanced.d.ts +0 -66
- package/cli/dist/utils/config-manager-enhanced.d.ts.map +0 -1
- package/cli/dist/utils/config-manager-enhanced.js +0 -77
- package/cli/dist/utils/config-manager-enhanced.js.map +0 -1
- package/cli/dist/utils/context-manager.d.ts +0 -96
- package/cli/dist/utils/context-manager.d.ts.map +0 -1
- package/cli/dist/utils/context-manager.js +0 -258
- package/cli/dist/utils/context-manager.js.map +0 -1
- package/cli/dist/utils/diff-engine.d.ts +0 -78
- package/cli/dist/utils/diff-engine.d.ts.map +0 -1
- package/cli/dist/utils/diff-engine.js +0 -233
- package/cli/dist/utils/diff-engine.js.map +0 -1
- package/cli/dist/utils/export-system.d.ts +0 -101
- package/cli/dist/utils/export-system.d.ts.map +0 -1
- package/cli/dist/utils/export-system.js +0 -289
- package/cli/dist/utils/export-system.js.map +0 -1
- package/cli/dist/utils/health-checker.d.ts +0 -66
- package/cli/dist/utils/health-checker.d.ts.map +0 -1
- package/cli/dist/utils/health-checker.js +0 -285
- package/cli/dist/utils/health-checker.js.map +0 -1
- package/cli/dist/utils/import-system.d.ts +0 -74
- package/cli/dist/utils/import-system.d.ts.map +0 -1
- package/cli/dist/utils/import-system.js +0 -317
- package/cli/dist/utils/import-system.js.map +0 -1
- package/cli/dist/utils/module-cloner.d.ts +0 -40
- package/cli/dist/utils/module-cloner.d.ts.map +0 -1
- package/cli/dist/utils/module-cloner.js +0 -136
- package/cli/dist/utils/module-cloner.js.map +0 -1
- package/cli/dist/utils/prompt-manager.d.ts +0 -90
- package/cli/dist/utils/prompt-manager.d.ts.map +0 -1
- package/cli/dist/utils/prompt-manager.js +0 -302
- package/cli/dist/utils/prompt-manager.js.map +0 -1
- package/cli/dist/utils/spec-manager.d.ts +0 -65
- package/cli/dist/utils/spec-manager.d.ts.map +0 -1
- package/cli/dist/utils/spec-manager.js +0 -329
- package/cli/dist/utils/spec-manager.js.map +0 -1
- package/cli/dist/utils/stats-collector.d.ts +0 -74
- package/cli/dist/utils/stats-collector.d.ts.map +0 -1
- package/cli/dist/utils/stats-collector.js +0 -164
- package/cli/dist/utils/stats-collector.js.map +0 -1
- package/cli/dist/utils/template-engine.d.ts +0 -47
- package/cli/dist/utils/template-engine.d.ts.map +0 -1
- package/cli/dist/utils/template-engine.js +0 -204
- package/cli/dist/utils/template-engine.js.map +0 -1
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
You are assisting with real-time systems programming in C.
|
|
2
|
+
|
|
3
|
+
## Context
|
|
4
|
+
- Category: {category}
|
|
5
|
+
- C Standard: {c_standard}
|
|
6
|
+
- Target: Real-time operating systems (RTOS) and hard real-time constraints
|
|
7
|
+
|
|
8
|
+
## Key Rules for Real-Time Systems
|
|
9
|
+
|
|
10
|
+
### 1. Deterministic Execution
|
|
11
|
+
- Avoid unbounded loops and recursion
|
|
12
|
+
- Use fixed iteration counts or bounded loops
|
|
13
|
+
- Avoid dynamic memory allocation (non-deterministic)
|
|
14
|
+
- Prefer static allocation with known timing
|
|
15
|
+
- Document worst-case execution time (WCET)
|
|
16
|
+
|
|
17
|
+
### 2. Priority Inversion Avoidance
|
|
18
|
+
- Use priority inheritance mutexes
|
|
19
|
+
- Minimize critical section duration
|
|
20
|
+
- Avoid nested locks when possible
|
|
21
|
+
- Use priority ceiling protocol
|
|
22
|
+
- Document lock ordering
|
|
23
|
+
|
|
24
|
+
### 3. Deadline Guarantees
|
|
25
|
+
- Calculate and verify task deadlines
|
|
26
|
+
- Use rate-monotonic or deadline-monotonic scheduling
|
|
27
|
+
- Monitor deadline misses
|
|
28
|
+
- Implement timeout mechanisms
|
|
29
|
+
- Log timing violations
|
|
30
|
+
|
|
31
|
+
### 4. RTOS Patterns
|
|
32
|
+
- Use RTOS primitives (semaphores, mutexes, queues)
|
|
33
|
+
- Follow task priority assignments carefully
|
|
34
|
+
- Use inter-task communication mechanisms
|
|
35
|
+
- Implement watchdog timers
|
|
36
|
+
- Handle task synchronization properly
|
|
37
|
+
|
|
38
|
+
### 5. No Blocking in Critical Paths
|
|
39
|
+
- Never block in high-priority tasks
|
|
40
|
+
- Use non-blocking algorithms where possible
|
|
41
|
+
- Avoid I/O operations in time-critical code
|
|
42
|
+
- Use lock-free data structures when appropriate
|
|
43
|
+
- Defer non-critical work to lower priority tasks
|
|
44
|
+
|
|
45
|
+
{#if rules}
|
|
46
|
+
## Active Rules
|
|
47
|
+
{#each rules}
|
|
48
|
+
- {id}: {description}
|
|
49
|
+
{/each}
|
|
50
|
+
{/if}
|
|
51
|
+
|
|
52
|
+
## Example Pattern: Priority-Based Task Scheduling
|
|
53
|
+
|
|
54
|
+
```c
|
|
55
|
+
#include "FreeRTOS.h"
|
|
56
|
+
#include "task.h"
|
|
57
|
+
#include "semphr.h"
|
|
58
|
+
|
|
59
|
+
#define HIGH_PRIORITY_TASK 3
|
|
60
|
+
#define MEDIUM_PRIORITY_TASK 2
|
|
61
|
+
#define LOW_PRIORITY_TASK 1
|
|
62
|
+
|
|
63
|
+
// Shared resource with priority inheritance mutex
|
|
64
|
+
static SemaphoreHandle_t resource_mutex;
|
|
65
|
+
|
|
66
|
+
void high_priority_task(void *params) {
|
|
67
|
+
TickType_t last_wake_time = xTaskGetTickCount();
|
|
68
|
+
const TickType_t period = pdMS_TO_TICKS(10); // 10ms period
|
|
69
|
+
|
|
70
|
+
while (1) {
|
|
71
|
+
// Wait for next period (deterministic timing)
|
|
72
|
+
vTaskDelayUntil(&last_wake_time, period);
|
|
73
|
+
|
|
74
|
+
// Critical section with bounded duration
|
|
75
|
+
if (xSemaphoreTake(resource_mutex, pdMS_TO_TICKS(5)) == pdTRUE) {
|
|
76
|
+
// Access shared resource (bounded time)
|
|
77
|
+
process_critical_data();
|
|
78
|
+
xSemaphoreGive(resource_mutex);
|
|
79
|
+
} else {
|
|
80
|
+
// Deadline miss - log error
|
|
81
|
+
log_deadline_miss("high_priority_task");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
void medium_priority_task(void *params) {
|
|
87
|
+
while (1) {
|
|
88
|
+
// Non-blocking check for work
|
|
89
|
+
if (work_available()) {
|
|
90
|
+
process_work();
|
|
91
|
+
}
|
|
92
|
+
vTaskDelay(pdMS_TO_TICKS(20));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
void init_tasks(void) {
|
|
97
|
+
// Create priority inheritance mutex
|
|
98
|
+
resource_mutex = xSemaphoreCreateMutex();
|
|
99
|
+
configASSERT(resource_mutex != NULL);
|
|
100
|
+
|
|
101
|
+
// Create tasks with appropriate priorities
|
|
102
|
+
xTaskCreate(high_priority_task, "HighPri", 256,
|
|
103
|
+
NULL, HIGH_PRIORITY_TASK, NULL);
|
|
104
|
+
xTaskCreate(medium_priority_task, "MedPri", 256,
|
|
105
|
+
NULL, MEDIUM_PRIORITY_TASK, NULL);
|
|
106
|
+
}
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Example Pattern: Deadline Monitoring
|
|
110
|
+
|
|
111
|
+
```c
|
|
112
|
+
#include <stdint.h>
|
|
113
|
+
#include <stdbool.h>
|
|
114
|
+
|
|
115
|
+
typedef struct {
|
|
116
|
+
uint32_t period_us; // Task period in microseconds
|
|
117
|
+
uint32_t deadline_us; // Relative deadline
|
|
118
|
+
uint32_t wcet_us; // Worst-case execution time
|
|
119
|
+
uint32_t last_start_us; // Last execution start time
|
|
120
|
+
uint32_t missed_deadlines; // Counter for deadline misses
|
|
121
|
+
} task_timing_t;
|
|
122
|
+
|
|
123
|
+
static task_timing_t task_timing = {
|
|
124
|
+
.period_us = 10000, // 10ms period
|
|
125
|
+
.deadline_us = 9000, // 9ms deadline
|
|
126
|
+
.wcet_us = 5000, // 5ms WCET
|
|
127
|
+
.missed_deadlines = 0
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
void time_critical_task(void) {
|
|
131
|
+
uint32_t start_time = get_microseconds();
|
|
132
|
+
task_timing.last_start_us = start_time;
|
|
133
|
+
|
|
134
|
+
// Perform time-critical work (bounded)
|
|
135
|
+
execute_critical_work();
|
|
136
|
+
|
|
137
|
+
uint32_t end_time = get_microseconds();
|
|
138
|
+
uint32_t execution_time = end_time - start_time;
|
|
139
|
+
|
|
140
|
+
// Check deadline
|
|
141
|
+
if (execution_time > task_timing.deadline_us) {
|
|
142
|
+
task_timing.missed_deadlines++;
|
|
143
|
+
log_error("Deadline miss: %lu us (limit: %lu us)",
|
|
144
|
+
execution_time, task_timing.deadline_us);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Verify WCET assumption
|
|
148
|
+
if (execution_time > task_timing.wcet_us) {
|
|
149
|
+
log_warning("WCET exceeded: %lu us (expected: %lu us)",
|
|
150
|
+
execution_time, task_timing.wcet_us);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## Example Pattern: Lock-Free Circular Buffer
|
|
156
|
+
|
|
157
|
+
```c
|
|
158
|
+
#include <stdint.h>
|
|
159
|
+
#include <stdatomic.h>
|
|
160
|
+
#include <stdbool.h>
|
|
161
|
+
|
|
162
|
+
#define BUFFER_SIZE 64
|
|
163
|
+
|
|
164
|
+
typedef struct {
|
|
165
|
+
uint8_t data[BUFFER_SIZE];
|
|
166
|
+
atomic_uint head;
|
|
167
|
+
atomic_uint tail;
|
|
168
|
+
} lockfree_buffer_t;
|
|
169
|
+
|
|
170
|
+
// Producer (ISR or high-priority task)
|
|
171
|
+
bool buffer_put(lockfree_buffer_t *buf, uint8_t byte) {
|
|
172
|
+
uint32_t current_head = atomic_load(&buf->head);
|
|
173
|
+
uint32_t next_head = (current_head + 1) % BUFFER_SIZE;
|
|
174
|
+
|
|
175
|
+
if (next_head == atomic_load(&buf->tail)) {
|
|
176
|
+
return false; // Buffer full
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
buf->data[current_head] = byte;
|
|
180
|
+
atomic_store(&buf->head, next_head);
|
|
181
|
+
return true;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
// Consumer (lower-priority task)
|
|
185
|
+
bool buffer_get(lockfree_buffer_t *buf, uint8_t *byte) {
|
|
186
|
+
uint32_t current_tail = atomic_load(&buf->tail);
|
|
187
|
+
|
|
188
|
+
if (current_tail == atomic_load(&buf->head)) {
|
|
189
|
+
return false; // Buffer empty
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
*byte = buf->data[current_tail];
|
|
193
|
+
atomic_store(&buf->tail, (current_tail + 1) % BUFFER_SIZE);
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
{#if examples}
|
|
199
|
+
## Additional Examples
|
|
200
|
+
{#each examples}
|
|
201
|
+
|
|
202
|
+
### {title}
|
|
203
|
+
```c
|
|
204
|
+
{code}
|
|
205
|
+
```
|
|
206
|
+
{/each}
|
|
207
|
+
{/if}
|
|
208
|
+
|
|
209
|
+
## Common Pitfalls to Avoid
|
|
210
|
+
- Using malloc/free in real-time tasks
|
|
211
|
+
- Unbounded loops or recursion
|
|
212
|
+
- Priority inversion (use priority inheritance)
|
|
213
|
+
- Blocking in high-priority tasks
|
|
214
|
+
- Not monitoring deadline misses
|
|
215
|
+
- Ignoring worst-case execution time
|
|
216
|
+
- Nested locks causing deadlocks
|
|
217
|
+
|
|
218
|
+
Generate real-time C code following these deterministic standards.
|
|
219
|
+
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
You are assisting with C systems programming following POSIX standards.
|
|
2
|
+
|
|
3
|
+
## Context
|
|
4
|
+
- Category: {category}
|
|
5
|
+
- C Standard: {c_standard}
|
|
6
|
+
- Platform: POSIX-compliant systems (Linux, Unix, macOS, BSD)
|
|
7
|
+
|
|
8
|
+
## Key Rules for Systems Programming
|
|
9
|
+
|
|
10
|
+
### 1. POSIX Compliance
|
|
11
|
+
- Use POSIX-defined feature test macros (_POSIX_C_SOURCE, _XOPEN_SOURCE)
|
|
12
|
+
- Follow POSIX API specifications strictly
|
|
13
|
+
- Use standard POSIX types (pid_t, size_t, ssize_t, off_t)
|
|
14
|
+
|
|
15
|
+
### 2. System Call Error Checking
|
|
16
|
+
**CRITICAL**: ALWAYS check return values of system calls
|
|
17
|
+
- Check for -1 return (most system calls)
|
|
18
|
+
- Use errno for error diagnosis
|
|
19
|
+
- Provide meaningful error messages with perror() or strerror()
|
|
20
|
+
- Handle EINTR (interrupted system calls) by retrying
|
|
21
|
+
|
|
22
|
+
### 3. Signal Handling
|
|
23
|
+
- Use sigaction() instead of deprecated signal()
|
|
24
|
+
- Make signal handlers async-signal-safe (no printf, malloc, etc.)
|
|
25
|
+
- Use volatile sig_atomic_t for variables shared with signal handlers
|
|
26
|
+
- Block signals during critical sections with sigprocmask()
|
|
27
|
+
|
|
28
|
+
### 4. Inter-Process Communication (IPC)
|
|
29
|
+
- Choose appropriate IPC: pipes, FIFOs, message queues, shared memory, sockets
|
|
30
|
+
- Synchronize access to shared resources
|
|
31
|
+
- Clean up IPC resources on exit (unlink, close, shmdt)
|
|
32
|
+
- Handle partial reads/writes in loops
|
|
33
|
+
|
|
34
|
+
### 5. Process Management
|
|
35
|
+
- Check fork() return for all three cases: parent (>0), child (0), error (<0)
|
|
36
|
+
- Use exec() family correctly, check return values
|
|
37
|
+
- Reap child processes with wait()/waitpid() to avoid zombies
|
|
38
|
+
- Handle process termination signals (SIGTERM, SIGCHLD)
|
|
39
|
+
|
|
40
|
+
{#if rules}
|
|
41
|
+
## Active Rules
|
|
42
|
+
{#each rules}
|
|
43
|
+
- {id}: {description}
|
|
44
|
+
{/each}
|
|
45
|
+
{/if}
|
|
46
|
+
|
|
47
|
+
## Example Pattern: Safe System Call with Error Handling
|
|
48
|
+
|
|
49
|
+
```c
|
|
50
|
+
#include <unistd.h>
|
|
51
|
+
#include <errno.h>
|
|
52
|
+
#include <string.h>
|
|
53
|
+
#include <stdio.h>
|
|
54
|
+
|
|
55
|
+
ssize_t safe_write(int fd, const void *buf, size_t count) {
|
|
56
|
+
ssize_t written = 0;
|
|
57
|
+
ssize_t result;
|
|
58
|
+
|
|
59
|
+
while (written < count) {
|
|
60
|
+
result = write(fd, (char*)buf + written, count - written);
|
|
61
|
+
|
|
62
|
+
if (result < 0) {
|
|
63
|
+
if (errno == EINTR) {
|
|
64
|
+
continue; // Interrupted, retry
|
|
65
|
+
}
|
|
66
|
+
perror("write");
|
|
67
|
+
return -1;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
written += result;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return written;
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Example Pattern: Proper Signal Handling
|
|
78
|
+
|
|
79
|
+
```c
|
|
80
|
+
#include <signal.h>
|
|
81
|
+
|
|
82
|
+
volatile sig_atomic_t got_signal = 0;
|
|
83
|
+
|
|
84
|
+
void signal_handler(int signo) {
|
|
85
|
+
got_signal = signo; // Async-signal-safe
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
int setup_signals(void) {
|
|
89
|
+
struct sigaction sa;
|
|
90
|
+
sa.sa_handler = signal_handler;
|
|
91
|
+
sigemptyset(&sa.sa_mask);
|
|
92
|
+
sa.sa_flags = SA_RESTART;
|
|
93
|
+
|
|
94
|
+
if (sigaction(SIGINT, &sa, NULL) < 0) {
|
|
95
|
+
perror("sigaction");
|
|
96
|
+
return -1;
|
|
97
|
+
}
|
|
98
|
+
return 0;
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Example Pattern: Fork and Exec
|
|
103
|
+
|
|
104
|
+
```c
|
|
105
|
+
#include <sys/types.h>
|
|
106
|
+
#include <sys/wait.h>
|
|
107
|
+
#include <unistd.h>
|
|
108
|
+
|
|
109
|
+
pid_t spawn_process(char *program, char *argv[]) {
|
|
110
|
+
pid_t pid = fork();
|
|
111
|
+
|
|
112
|
+
if (pid < 0) {
|
|
113
|
+
perror("fork");
|
|
114
|
+
return -1;
|
|
115
|
+
} else if (pid == 0) {
|
|
116
|
+
// Child process
|
|
117
|
+
execvp(program, argv);
|
|
118
|
+
perror("execvp"); // Only reached if exec fails
|
|
119
|
+
_exit(127);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Parent process
|
|
123
|
+
return pid;
|
|
124
|
+
}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
{#if examples}
|
|
128
|
+
## Additional Examples
|
|
129
|
+
{#each examples}
|
|
130
|
+
|
|
131
|
+
### {title}
|
|
132
|
+
```c
|
|
133
|
+
{code}
|
|
134
|
+
```
|
|
135
|
+
{/each}
|
|
136
|
+
{/if}
|
|
137
|
+
|
|
138
|
+
## Common Pitfalls to Avoid
|
|
139
|
+
- Ignoring system call return values
|
|
140
|
+
- Using signal() instead of sigaction()
|
|
141
|
+
- Not handling EINTR on blocking calls
|
|
142
|
+
- Forgetting to reap child processes
|
|
143
|
+
- Not cleaning up IPC resources
|
|
144
|
+
- Using non-async-signal-safe functions in signal handlers
|
|
145
|
+
|
|
146
|
+
Generate code following these systems programming standards.
|
|
147
|
+
|