
IoT के लिए अति-हल्का RTOS जिसमें प्रीएम्प्टिव शेड्यूलिंग, TLS/DTLS, MQTT, CoAP, POSIX संगतता और MPU-आधारित मेमोरी सुरक्षा शामिल है। कर्नेल 10 KB से कम।
एक अति-हल्का रियल-टाइम ऑपरेटिंग सिस्टम जो संसाधन-सीमित IoT और एम्बेडेड उपकरणों के लिए है।
कर्नेल फुटप्रिंट 10 KB से कम, न्यूनतम RAM 2 KB, प्रीएम्प्टिव प्रायोरिटी-आधारित शेड्यूलिंग।
| श्रेणी | विवरण |
|---|---|
| कर्नेल | प्रीएम्प्टिव प्रायोरिटी-आधारित शेड्यूलिंग (256 स्तर), समान प्रायोरिटी में राउंड-रॉबिन, बिटमैप के माध्यम से O(1) प्रायोरिटी लुकअप, प्रायोरिटी इनहेरिटेंस |
| सिंक्रोनाइज़ेशन | म्यूटेक्स (प्रायोरिटी इनहेरिटेंस के साथ), सेमाफोर, कंडीशन वेरिएबल, इवेंट ग्रुप्स, मैसेज क्यूज़ |
| सॉफ्टवेयर टाइमर | वन-शॉट और ऑटो-रिलोड, मिलीसेकंड परिशुद्धता, रनटाइम पर अवधि बदलना |
| मेमोरी | तत्काल कोलेसिंग के साथ फर्स्ट-फिट आवंटक (8 KB हीप, 8-बाइट संरेखित), स्टैक ओवरफ़्लो डिटेक्शन, प्रति-कार्य हाई-वॉटर मार्क |
| शेल | VT100 इंटरैक्टिव शेल — 23 बिल्ट-इन कमांड, कमांड हिस्ट्री (↑↓), टैब कम्प्लीशन, पूर्ण लाइन एडिटर |
| POSIX अनुकूलता | pthreads (create/join/detach/exit, mutex, cond var) · BSD सॉकेट API (socket/bind/listen/accept/connect/send/recv, inet_pton/ntop, htons/htonl) |
| फ़ाइल सिस्टम | जर्नलिंग ब्लॉक-डिवाइस FS (WAL, क्रैश रिकवरी), COW ब्लॉक शेयरिंग, परमाणु स्नैपशॉट, POSIX-जैसी API |
| नेटवर्क | ईथरनेट, IPv4, ICMP, UDP, TCP, HTTP क्लाइंट/सर्वर, DNS |
| TLS / DTLS | TCP पर TLS 1.2/1.3, UDP पर DTLS 1.2 (mbedTLS बैकएंड) |
| MQTT | पूर्ण MQTT 3.1.1 — इन-फ्लाइट रीट्री टेबल के साथ QoS 0/1/2, ऑफ़लाइन क्यू, एक्सपोनेन्शियल बैक-ऑफ़ के साथ ऑटो-रीकनेक्ट |
| CoAP | RFC 7252 अनुरूप क्लाइंट/सर्वर, ऑब्ज़र्व पैटर्न |
| OTA | A/B पार्टीशन फ़र्मवेयर अपडेट, CRC32 सत्यापन, रोलबैक |
| वॉचडॉग | हार्डवेयर और सॉफ्टवेयर वॉचडॉग, प्रति-कार्य टाइमआउट मॉनिटरिंग |
| पावर | आइडल / स्लीप / डीप-स्लीप मोड, टिकलेस आइडल, CPU फ़्रीक्वेंसी स्केलिंग |
| सुरक्षा | MPU-आधारित मेमोरी प्रोटेक्शन, सिक्योर बूट समर्थन |
| HAL | जेनेरिक हार्डवेयर एब्स्ट्रैक्शन लेयर — ARM Cortex-M / RISC-V / AVR; कंपाइल-टाइम आर्किटेक्चर चयन, परिधीय op-टेबल्स |
| आर्किटेक्चर | उदाहरण |
|---|---|
| ARM Cortex-M (M0/M0+/M3/M4/M7) | STM32, nRF52, Raspberry Pi Pico |
| RISC-V (RV32I) | ESP32-C3 |
| AVR (प्रयोगात्मक) | ATmega |
sudo apt-get install -y gcc-arm-none-eabi binutils-arm-none-eabi
sudo apt-get install -y qemu-system
स्थापना की पुष्टि करें:```bash
arm-none-eabi-gcc --version # 10.x or later
qemu-system-arm --version # 6.x or later
make
make ARCH=cortex-m0 # Cortex-M0/M0+ make ARCH=cortex-m7 # Cortex-M7 make ARCH=riscv32 # RISC-V RV32I (uses riscv32-unknown-elf-gcc) make ARCH=avr5 # AVR ATmega (uses avr-gcc)
make EXAMPLE=blink_led # LED blink + task scheduler demo make EXAMPLE=event_groups # Event group AND/OR/NOT/SYNC demo make EXAMPLE=iot_sensor # Multi-sensor IoT node make EXAMPLE=shell_demo # Interactive UART shell make EXAMPLE=mqtt_demo # MQTT publish/subscribe make EXAMPLE=condition_variable # Producer/consumer
make example-blink make example-events make example-shell make example-mqtt make example-iot
make size # Print ROM/RAM usage
बिल्ड आर्टिफैक्ट्स `build/` में रखे गए हैं:
| फ़ाइल | विवरण |
|---|---|
| `build/tinyos.elf` | ELF इमेज जिसमें डीबग सिंबल हैं |
| `build/tinyos.bin` | फ्लैशिंग के लिए रॉ बाइनरी |
| `build/tinyos.map` | लिंकर मैप (सिंबल आकार) |
### QEMU पर चलाएँ
TinyOS QEMU `mps2-an385` टार्गेट (ARM Cortex-M3, 4 MB फ्लैश, 4 MB RAM) पर चलता है:```bash
# Run indefinitely (Ctrl-A X to quit)
qemu-system-arm \
-machine mps2-an385 \
-cpu cortex-m3 \
-nographic \
-kernel build/tinyos.elf
# Run for a fixed duration (e.g. 10 seconds)
timeout 10 qemu-system-arm \
-machine mps2-an385 \
-cpu cortex-m3 \
-nographic \
-kernel build/tinyos.elf
# Debug: trace interrupts
qemu-system-arm \
-machine mps2-an385 \
-cpu cortex-m3 \
-nographic \
-d int \
-kernel build/tinyos.elf
इंटरप्ट ट्रेस से अपेक्षित आउटपुट: repeated successful exception return पंक्तियाँ पुष्टि करती हैं कि शेड्यूलर चल रहा है, SysTick टिक कर रहा है, और PendSV कॉन्टेक्स्ट स्विच स्वच्छ रूप से पूर्ण हो रहे हैं।```bash
openocd -f interface/stlink.cfg -f target/stm32f4x.cfg
-c "program build/tinyos.bin verify reset exit 0x08000000"
pyocd flash --target cortex_m build/tinyos.bin
### TLS (mbedTLS) के साथ बनाएँ
TLS समर्थन स्वचालित रूप से सक्षम होता है जब mbedTLS `~/mbedtls` पर मौजूद होता है।
एक अलग पथ का उपयोग करने के लिए:```bash
# Clone and build mbedTLS
git clone https://github.com/Mbed-TLS/mbedtls ~/mbedtls
make -C ~/mbedtls
# Build TinyOS with TLS
make MBEDTLS_DIR=~/mbedtls
न्यूनतम कार्य उदाहरण:```c #include "tinyos.h"
void my_task(void param) { while (1) { / work */ os_task_delay_ms(100); } }
int main(void) { tcb_t task; os_init(); os_task_create(&task, "my_task", my_task, NULL, PRIORITY_NORMAL); os_start(); }
---
## API अवलोकन
### कार्य प्रबंधन```c
os_task_create(tcb, name, entry, param, priority)
os_task_delete(task)
os_task_suspend(task) / os_task_resume(task)
os_task_delay(ticks) / os_task_delay_ms(ms)
os_task_set_priority(task, priority)
os_task_get_stats(task, stats)
os_task_get_stats_by_index(index, stats) /* iterate all tasks by index */
os_task_find_by_name(name) /* returns tcb_t*, NULL if not found */
os_get_system_stats(stats)
os_get_memory_stats(&free, &used, &allocs, &frees)
os_mutex_init(mutex) / os_mutex_lock(mutex, timeout) / os_mutex_unlock(mutex) os_semaphore_init(sem, count) / os_semaphore_wait(sem, timeout) / os_semaphore_post(sem) os_cond_init(cond) / os_cond_wait(cond, mutex, timeout) os_cond_signal(cond) / os_cond_broadcast(cond) os_event_group_set_bits(eg, bits) / os_event_group_wait_bits(eg, bits, opts, out, timeout) os_queue_init(q, buf, item_size, max) / os_queue_send(q, item, timeout) os_queue_receive(q, item, timeout) / os_queue_peek(q, item, timeout)
### टाइमर```c
os_timer_create(timer, name, type, period_ms, callback, param)
os_timer_start(timer) / os_timer_stop(timer) / os_timer_reset(timer)
os_timer_change_period(timer, ms) / os_timer_get_remaining_ms(timer)
/* Register custom commands before calling shell_start() */ shell_register_cmd(name, handler_fn, help_text)
/* Provide UART I/O callbacks and start the shell task */ shell_io_t io = { .getc = uart_getc, .puts = uart_puts }; shell_start(&io)
/* Change the prompt at any time */ shell_set_prompt("mydevice> ")
/* Execute a single line programmatically */ shell_exec(line)
**कस्टम कमांड उदाहरण:**```c
static int cmd_led(int argc, char *argv[]) {
if (argc < 2) return 1; /* non-zero → prints usage */
bool on = (strcmp(argv[1], "on") == 0);
gpio_write(LED_PIN, on);
return 0;
}
/* In main(), before shell_start(): */
shell_register_cmd("led", cmd_led, "led <on|off> Toggle LED");