@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,167 @@
|
|
|
1
|
+
# Embedded Systems Examples
|
|
2
|
+
|
|
3
|
+
This directory contains C examples demonstrating embedded systems programming best practices for microcontrollers.
|
|
4
|
+
|
|
5
|
+
## Examples
|
|
6
|
+
|
|
7
|
+
### 1. gpio-control.c
|
|
8
|
+
Demonstrates GPIO (General Purpose Input/Output) control:
|
|
9
|
+
- Memory-mapped I/O for hardware registers
|
|
10
|
+
- Volatile keyword for hardware access
|
|
11
|
+
- Bit manipulation techniques
|
|
12
|
+
- Hardware abstraction layer pattern
|
|
13
|
+
- LED control and button reading
|
|
14
|
+
|
|
15
|
+
**Key Concepts:**
|
|
16
|
+
- Always use `volatile` for hardware registers
|
|
17
|
+
- Use bit manipulation for register access
|
|
18
|
+
- Implement hardware abstraction layers
|
|
19
|
+
- Atomic register operations with BSRR
|
|
20
|
+
|
|
21
|
+
### 2. timer-isr.c
|
|
22
|
+
Demonstrates timer interrupt service routines:
|
|
23
|
+
- Timer configuration for periodic interrupts
|
|
24
|
+
- ISR implementation best practices
|
|
25
|
+
- Volatile variables for ISR/main communication
|
|
26
|
+
- Minimal ISR execution time
|
|
27
|
+
- Timeout and delay functions
|
|
28
|
+
|
|
29
|
+
**Key Concepts:**
|
|
30
|
+
- Keep ISRs short and fast
|
|
31
|
+
- Use `volatile` for ISR-shared variables
|
|
32
|
+
- Clear interrupt flags in ISR
|
|
33
|
+
- No blocking operations in ISRs
|
|
34
|
+
- Defer processing to main loop
|
|
35
|
+
|
|
36
|
+
### 3. uart-communication.c
|
|
37
|
+
Demonstrates UART serial communication:
|
|
38
|
+
- UART initialization and configuration
|
|
39
|
+
- Interrupt-driven reception
|
|
40
|
+
- Circular buffer implementation
|
|
41
|
+
- Non-blocking I/O
|
|
42
|
+
- Error handling
|
|
43
|
+
|
|
44
|
+
**Key Concepts:**
|
|
45
|
+
- Use circular buffers for data buffering
|
|
46
|
+
- Interrupt-driven reception
|
|
47
|
+
- Polling for transmission
|
|
48
|
+
- Handle overrun and framing errors
|
|
49
|
+
- Non-blocking API design
|
|
50
|
+
|
|
51
|
+
## Building
|
|
52
|
+
|
|
53
|
+
These examples are designed for ARM Cortex-M microcontrollers. Adjust register addresses and build commands for your specific hardware.
|
|
54
|
+
|
|
55
|
+
### For ARM Cortex-M (e.g., STM32)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Using arm-none-eabi-gcc
|
|
59
|
+
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -O2 -Wall -Wextra \
|
|
60
|
+
-o gpio-control.elf gpio-control.c
|
|
61
|
+
|
|
62
|
+
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -O2 -Wall -Wextra \
|
|
63
|
+
-o timer-isr.elf timer-isr.c
|
|
64
|
+
|
|
65
|
+
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -O2 -Wall -Wextra \
|
|
66
|
+
-o uart-communication.elf uart-communication.c
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### For Simulation/Testing
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Compile for host (for structure/syntax checking only)
|
|
73
|
+
gcc -Wall -Wextra -std=c99 -c gpio-control.c
|
|
74
|
+
gcc -Wall -Wextra -std=c99 -c timer-isr.c
|
|
75
|
+
gcc -Wall -Wextra -std=c99 -c uart-communication.c
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Hardware Requirements
|
|
79
|
+
|
|
80
|
+
- ARM Cortex-M microcontroller (STM32, NXP, etc.)
|
|
81
|
+
- JTAG/SWD debugger
|
|
82
|
+
- LED and button for GPIO example
|
|
83
|
+
- UART-to-USB adapter for UART example
|
|
84
|
+
|
|
85
|
+
## Register Addresses
|
|
86
|
+
|
|
87
|
+
**IMPORTANT:** The register addresses in these examples are for demonstration purposes. You MUST adjust them for your specific microcontroller:
|
|
88
|
+
|
|
89
|
+
- **STM32F1**: Check STM32F1xx reference manual
|
|
90
|
+
- **STM32F4**: Check STM32F4xx reference manual
|
|
91
|
+
- **NXP LPC**: Check LPC user manual
|
|
92
|
+
- **Nordic nRF**: Check nRF product specification
|
|
93
|
+
|
|
94
|
+
## Best Practices Demonstrated
|
|
95
|
+
|
|
96
|
+
1. **Volatile Usage**
|
|
97
|
+
- All hardware registers marked `volatile`
|
|
98
|
+
- ISR-shared variables marked `volatile`
|
|
99
|
+
- Prevents compiler optimization issues
|
|
100
|
+
|
|
101
|
+
2. **ISR Design**
|
|
102
|
+
- Minimal execution time
|
|
103
|
+
- No blocking operations
|
|
104
|
+
- Clear interrupt flags
|
|
105
|
+
- Use flags for main loop communication
|
|
106
|
+
|
|
107
|
+
3. **Memory Safety**
|
|
108
|
+
- No dynamic allocation
|
|
109
|
+
- Fixed-size buffers
|
|
110
|
+
- Bounds checking
|
|
111
|
+
- Circular buffer overflow protection
|
|
112
|
+
|
|
113
|
+
4. **Hardware Abstraction**
|
|
114
|
+
- Clean API separation
|
|
115
|
+
- Register access encapsulation
|
|
116
|
+
- Portable code structure
|
|
117
|
+
|
|
118
|
+
5. **Error Handling**
|
|
119
|
+
- Check buffer full/empty conditions
|
|
120
|
+
- Handle UART errors
|
|
121
|
+
- Validate pin numbers
|
|
122
|
+
|
|
123
|
+
## Common Pitfalls to Avoid
|
|
124
|
+
|
|
125
|
+
1. **Forgetting `volatile`**
|
|
126
|
+
```c
|
|
127
|
+
// WRONG
|
|
128
|
+
uint32_t *reg = (uint32_t *)0x40020000;
|
|
129
|
+
|
|
130
|
+
// CORRECT
|
|
131
|
+
volatile uint32_t *reg = (volatile uint32_t *)0x40020000;
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
2. **Long ISRs**
|
|
135
|
+
```c
|
|
136
|
+
// WRONG - Too much work in ISR
|
|
137
|
+
void TIM2_IRQHandler(void) {
|
|
138
|
+
process_data(); // Long operation
|
|
139
|
+
send_uart(); // Blocking
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// CORRECT - Set flag and defer
|
|
143
|
+
void TIM2_IRQHandler(void) {
|
|
144
|
+
data_ready = true; // Just set flag
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
3. **Non-atomic Operations**
|
|
149
|
+
```c
|
|
150
|
+
// WRONG - Not atomic on 8-bit MCU
|
|
151
|
+
volatile uint32_t counter;
|
|
152
|
+
counter++; // May be interrupted mid-operation
|
|
153
|
+
|
|
154
|
+
// CORRECT - Disable interrupts or use atomic operations
|
|
155
|
+
__disable_irq();
|
|
156
|
+
counter++;
|
|
157
|
+
__enable_irq();
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
## References
|
|
161
|
+
|
|
162
|
+
- ARM Cortex-M Programming Guide
|
|
163
|
+
- MISRA C:2012 Guidelines for Embedded Systems
|
|
164
|
+
- Embedded C Coding Standard (Barr Group)
|
|
165
|
+
- Microcontroller vendor reference manuals
|
|
166
|
+
- "Making Embedded Systems" by Elecia White
|
|
167
|
+
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file gpio-control.c
|
|
3
|
+
* @brief Example demonstrating GPIO control for embedded systems
|
|
4
|
+
*
|
|
5
|
+
* This example shows:
|
|
6
|
+
* - Memory-mapped I/O for hardware registers
|
|
7
|
+
* - Volatile keyword usage for hardware access
|
|
8
|
+
* - Bit manipulation for GPIO control
|
|
9
|
+
* - Hardware abstraction layer pattern
|
|
10
|
+
* - Safe register access
|
|
11
|
+
*
|
|
12
|
+
* Target: Generic ARM Cortex-M microcontroller
|
|
13
|
+
* Note: This is a demonstration. Actual addresses depend on your hardware.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
#include <stdint.h>
|
|
17
|
+
#include <stdbool.h>
|
|
18
|
+
|
|
19
|
+
// Example GPIO register addresses (adjust for your hardware)
|
|
20
|
+
#define GPIO_BASE_ADDR 0x40020000UL
|
|
21
|
+
#define GPIOA_MODER (*(volatile uint32_t *)(GPIO_BASE_ADDR + 0x00))
|
|
22
|
+
#define GPIOA_ODR (*(volatile uint32_t *)(GPIO_BASE_ADDR + 0x14))
|
|
23
|
+
#define GPIOA_IDR (*(volatile uint32_t *)(GPIO_BASE_ADDR + 0x10))
|
|
24
|
+
#define GPIOA_BSRR (*(volatile uint32_t *)(GPIO_BASE_ADDR + 0x18))
|
|
25
|
+
|
|
26
|
+
// GPIO pin definitions
|
|
27
|
+
#define LED_PIN 5
|
|
28
|
+
#define BUTTON_PIN 13
|
|
29
|
+
|
|
30
|
+
// GPIO modes
|
|
31
|
+
typedef enum {
|
|
32
|
+
GPIO_MODE_INPUT = 0x00,
|
|
33
|
+
GPIO_MODE_OUTPUT = 0x01,
|
|
34
|
+
GPIO_MODE_AF = 0x02,
|
|
35
|
+
GPIO_MODE_ANALOG = 0x03
|
|
36
|
+
} gpio_mode_t;
|
|
37
|
+
|
|
38
|
+
// GPIO states
|
|
39
|
+
typedef enum {
|
|
40
|
+
GPIO_LOW = 0,
|
|
41
|
+
GPIO_HIGH = 1
|
|
42
|
+
} gpio_state_t;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @brief Initialize a GPIO pin
|
|
46
|
+
* @param pin Pin number (0-15)
|
|
47
|
+
* @param mode GPIO mode
|
|
48
|
+
*/
|
|
49
|
+
void gpio_init(uint8_t pin, gpio_mode_t mode) {
|
|
50
|
+
if (pin > 15) {
|
|
51
|
+
return; // Invalid pin
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Clear mode bits for this pin
|
|
55
|
+
uint32_t temp = GPIOA_MODER;
|
|
56
|
+
temp &= ~(0x3UL << (pin * 2));
|
|
57
|
+
|
|
58
|
+
// Set new mode
|
|
59
|
+
temp |= ((uint32_t)mode << (pin * 2));
|
|
60
|
+
GPIOA_MODER = temp;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* @brief Set GPIO pin state
|
|
65
|
+
* @param pin Pin number (0-15)
|
|
66
|
+
* @param state Desired state (HIGH/LOW)
|
|
67
|
+
*/
|
|
68
|
+
void gpio_write(uint8_t pin, gpio_state_t state) {
|
|
69
|
+
if (pin > 15) {
|
|
70
|
+
return; // Invalid pin
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Use BSRR for atomic bit set/reset
|
|
74
|
+
if (state == GPIO_HIGH) {
|
|
75
|
+
GPIOA_BSRR = (1UL << pin); // Set bit
|
|
76
|
+
} else {
|
|
77
|
+
GPIOA_BSRR = (1UL << (pin + 16)); // Reset bit
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @brief Read GPIO pin state
|
|
83
|
+
* @param pin Pin number (0-15)
|
|
84
|
+
* @return Current pin state
|
|
85
|
+
*/
|
|
86
|
+
gpio_state_t gpio_read(uint8_t pin) {
|
|
87
|
+
if (pin > 15) {
|
|
88
|
+
return GPIO_LOW; // Invalid pin
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return (GPIOA_IDR & (1UL << pin)) ? GPIO_HIGH : GPIO_LOW;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* @brief Toggle GPIO pin state
|
|
96
|
+
* @param pin Pin number (0-15)
|
|
97
|
+
*/
|
|
98
|
+
void gpio_toggle(uint8_t pin) {
|
|
99
|
+
if (pin > 15) {
|
|
100
|
+
return; // Invalid pin
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Read current state and toggle
|
|
104
|
+
uint32_t current = GPIOA_ODR;
|
|
105
|
+
GPIOA_ODR = current ^ (1UL << pin);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @brief Simple delay function (busy-wait)
|
|
110
|
+
* @param count Delay count (hardware-dependent)
|
|
111
|
+
*
|
|
112
|
+
* Note: In production, use hardware timers instead
|
|
113
|
+
*/
|
|
114
|
+
void delay(volatile uint32_t count) {
|
|
115
|
+
while (count--) {
|
|
116
|
+
__asm__ volatile ("nop"); // Prevent optimization
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* @brief LED blink example
|
|
122
|
+
*/
|
|
123
|
+
void led_blink_example(void) {
|
|
124
|
+
// Initialize LED pin as output
|
|
125
|
+
gpio_init(LED_PIN, GPIO_MODE_OUTPUT);
|
|
126
|
+
|
|
127
|
+
// Blink LED 10 times
|
|
128
|
+
for (int i = 0; i < 10; i++) {
|
|
129
|
+
gpio_write(LED_PIN, GPIO_HIGH);
|
|
130
|
+
delay(500000);
|
|
131
|
+
gpio_write(LED_PIN, GPIO_LOW);
|
|
132
|
+
delay(500000);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* @brief Button-controlled LED example
|
|
138
|
+
*/
|
|
139
|
+
void button_led_example(void) {
|
|
140
|
+
// Initialize button pin as input
|
|
141
|
+
gpio_init(BUTTON_PIN, GPIO_MODE_INPUT);
|
|
142
|
+
|
|
143
|
+
// Initialize LED pin as output
|
|
144
|
+
gpio_init(LED_PIN, GPIO_MODE_OUTPUT);
|
|
145
|
+
|
|
146
|
+
// Read button and control LED
|
|
147
|
+
for (int i = 0; i < 100; i++) {
|
|
148
|
+
gpio_state_t button_state = gpio_read(BUTTON_PIN);
|
|
149
|
+
gpio_write(LED_PIN, button_state);
|
|
150
|
+
delay(10000);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* @brief Main function
|
|
156
|
+
*/
|
|
157
|
+
int main(void) {
|
|
158
|
+
// Example 1: LED blink
|
|
159
|
+
led_blink_example();
|
|
160
|
+
|
|
161
|
+
// Example 2: Button-controlled LED
|
|
162
|
+
button_led_example();
|
|
163
|
+
|
|
164
|
+
// Infinite loop (typical for embedded systems)
|
|
165
|
+
while (1) {
|
|
166
|
+
gpio_toggle(LED_PIN);
|
|
167
|
+
delay(1000000);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
return 0; // Never reached
|
|
171
|
+
}
|
|
172
|
+
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file timer-isr.c
|
|
3
|
+
* @brief Example demonstrating timer interrupt service routine (ISR)
|
|
4
|
+
*
|
|
5
|
+
* This example shows:
|
|
6
|
+
* - Timer configuration for periodic interrupts
|
|
7
|
+
* - Interrupt service routine implementation
|
|
8
|
+
* - Volatile variables for ISR communication
|
|
9
|
+
* - Atomic operations
|
|
10
|
+
* - Minimal ISR execution time
|
|
11
|
+
*
|
|
12
|
+
* Target: Generic ARM Cortex-M microcontroller
|
|
13
|
+
* Note: This is a demonstration. Actual addresses depend on your hardware.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
#include <stdint.h>
|
|
17
|
+
#include <stdbool.h>
|
|
18
|
+
|
|
19
|
+
// Timer register addresses (example for STM32-like MCU)
|
|
20
|
+
#define TIM2_BASE 0x40000000UL
|
|
21
|
+
#define TIM2_CR1 (*(volatile uint32_t *)(TIM2_BASE + 0x00))
|
|
22
|
+
#define TIM2_DIER (*(volatile uint32_t *)(TIM2_BASE + 0x0C))
|
|
23
|
+
#define TIM2_SR (*(volatile uint32_t *)(TIM2_BASE + 0x10))
|
|
24
|
+
#define TIM2_CNT (*(volatile uint32_t *)(TIM2_BASE + 0x24))
|
|
25
|
+
#define TIM2_PSC (*(volatile uint32_t *)(TIM2_BASE + 0x28))
|
|
26
|
+
#define TIM2_ARR (*(volatile uint32_t *)(TIM2_BASE + 0x2C))
|
|
27
|
+
|
|
28
|
+
// Timer control bits
|
|
29
|
+
#define TIM_CR1_CEN (1UL << 0) // Counter enable
|
|
30
|
+
#define TIM_DIER_UIE (1UL << 0) // Update interrupt enable
|
|
31
|
+
#define TIM_SR_UIF (1UL << 0) // Update interrupt flag
|
|
32
|
+
|
|
33
|
+
// NVIC (Nested Vectored Interrupt Controller)
|
|
34
|
+
#define NVIC_ISER0 (*(volatile uint32_t *)0xE000E100UL)
|
|
35
|
+
#define TIM2_IRQn 28
|
|
36
|
+
|
|
37
|
+
// Shared variables between ISR and main (must be volatile)
|
|
38
|
+
static volatile uint32_t tick_count = 0;
|
|
39
|
+
static volatile bool timer_flag = false;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @brief Initialize timer for 1ms periodic interrupts
|
|
43
|
+
* @param sysclk System clock frequency in Hz
|
|
44
|
+
*/
|
|
45
|
+
void timer_init(uint32_t sysclk) {
|
|
46
|
+
// Disable timer during configuration
|
|
47
|
+
TIM2_CR1 &= ~TIM_CR1_CEN;
|
|
48
|
+
|
|
49
|
+
// Configure prescaler for 1kHz (1ms) tick
|
|
50
|
+
// PSC = (sysclk / desired_freq) - 1
|
|
51
|
+
TIM2_PSC = (sysclk / 1000) - 1;
|
|
52
|
+
|
|
53
|
+
// Auto-reload value for 1ms period
|
|
54
|
+
TIM2_ARR = 1000 - 1;
|
|
55
|
+
|
|
56
|
+
// Clear counter
|
|
57
|
+
TIM2_CNT = 0;
|
|
58
|
+
|
|
59
|
+
// Enable update interrupt
|
|
60
|
+
TIM2_DIER |= TIM_DIER_UIE;
|
|
61
|
+
|
|
62
|
+
// Enable TIM2 interrupt in NVIC
|
|
63
|
+
NVIC_ISER0 |= (1UL << TIM2_IRQn);
|
|
64
|
+
|
|
65
|
+
// Start timer
|
|
66
|
+
TIM2_CR1 |= TIM_CR1_CEN;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @brief Timer interrupt service routine
|
|
71
|
+
*
|
|
72
|
+
* IMPORTANT ISR Rules:
|
|
73
|
+
* - Keep execution time minimal
|
|
74
|
+
* - No blocking operations
|
|
75
|
+
* - No printf/malloc/etc
|
|
76
|
+
* - Use volatile for shared variables
|
|
77
|
+
* - Clear interrupt flag
|
|
78
|
+
*/
|
|
79
|
+
void TIM2_IRQHandler(void) {
|
|
80
|
+
// Check if update interrupt occurred
|
|
81
|
+
if (TIM2_SR & TIM_SR_UIF) {
|
|
82
|
+
// Clear interrupt flag (MUST do this!)
|
|
83
|
+
TIM2_SR &= ~TIM_SR_UIF;
|
|
84
|
+
|
|
85
|
+
// Increment tick counter (atomic on 32-bit ARM)
|
|
86
|
+
tick_count++;
|
|
87
|
+
|
|
88
|
+
// Set flag for main loop
|
|
89
|
+
timer_flag = true;
|
|
90
|
+
|
|
91
|
+
// Minimal work in ISR - defer processing to main loop
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @brief Get current tick count (thread-safe)
|
|
97
|
+
* @return Current tick count
|
|
98
|
+
*/
|
|
99
|
+
uint32_t get_tick_count(void) {
|
|
100
|
+
// Reading 32-bit value is atomic on ARM Cortex-M
|
|
101
|
+
return tick_count;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @brief Delay for specified milliseconds
|
|
106
|
+
* @param ms Milliseconds to delay
|
|
107
|
+
*/
|
|
108
|
+
void delay_ms(uint32_t ms) {
|
|
109
|
+
uint32_t start = get_tick_count();
|
|
110
|
+
while ((get_tick_count() - start) < ms) {
|
|
111
|
+
// Wait
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* @brief Check and clear timer flag
|
|
117
|
+
* @return true if flag was set, false otherwise
|
|
118
|
+
*/
|
|
119
|
+
bool check_timer_flag(void) {
|
|
120
|
+
if (timer_flag) {
|
|
121
|
+
timer_flag = false; // Clear flag
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* @brief Example: Periodic task execution
|
|
129
|
+
*/
|
|
130
|
+
void periodic_task_example(void) {
|
|
131
|
+
uint32_t last_tick = 0;
|
|
132
|
+
const uint32_t TASK_PERIOD_MS = 100; // Run every 100ms
|
|
133
|
+
|
|
134
|
+
while (1) {
|
|
135
|
+
uint32_t current_tick = get_tick_count();
|
|
136
|
+
|
|
137
|
+
if ((current_tick - last_tick) >= TASK_PERIOD_MS) {
|
|
138
|
+
last_tick = current_tick;
|
|
139
|
+
|
|
140
|
+
// Execute periodic task
|
|
141
|
+
// (In real code, toggle LED, read sensor, etc.)
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// Check for timer events
|
|
145
|
+
if (check_timer_flag()) {
|
|
146
|
+
// Handle 1ms timer event
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @brief Example: Timeout detection
|
|
153
|
+
*/
|
|
154
|
+
bool wait_with_timeout(uint32_t timeout_ms) {
|
|
155
|
+
uint32_t start = get_tick_count();
|
|
156
|
+
|
|
157
|
+
while (1) {
|
|
158
|
+
// Check timeout
|
|
159
|
+
if ((get_tick_count() - start) >= timeout_ms) {
|
|
160
|
+
return false; // Timeout occurred
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Check for event (example: button press)
|
|
164
|
+
// if (event_occurred()) {
|
|
165
|
+
// return true;
|
|
166
|
+
// }
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @brief Main function
|
|
172
|
+
*/
|
|
173
|
+
int main(void) {
|
|
174
|
+
// Initialize timer (assuming 72MHz system clock)
|
|
175
|
+
timer_init(72000000);
|
|
176
|
+
|
|
177
|
+
// Example 1: Simple delay
|
|
178
|
+
delay_ms(1000); // 1 second delay
|
|
179
|
+
|
|
180
|
+
// Example 2: Periodic task execution
|
|
181
|
+
// periodic_task_example(); // Uncomment to run
|
|
182
|
+
|
|
183
|
+
// Example 3: Timeout detection
|
|
184
|
+
bool success = wait_with_timeout(5000); // 5 second timeout
|
|
185
|
+
|
|
186
|
+
// Main loop
|
|
187
|
+
while (1) {
|
|
188
|
+
// Process timer events
|
|
189
|
+
if (check_timer_flag()) {
|
|
190
|
+
// Handle 1ms tick
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Other main loop tasks
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
return 0; // Never reached
|
|
197
|
+
}
|
|
198
|
+
|