Skip to content

osal: add liteos_m osal#301

Merged
sakumisu merged 1 commit intocherry-embedded:masterfrom
huohongpeng:master
Apr 4, 2025
Merged

osal: add liteos_m osal#301
sakumisu merged 1 commit intocherry-embedded:masterfrom
huohongpeng:master

Conversation

@huohongpeng
Copy link
Copy Markdown
Contributor

@huohongpeng huohongpeng commented Apr 3, 2025

  • support liteos_m

Summary by CodeRabbit

  • New Features
    • Introduced a new OS abstraction layer for USB operations on LiteOS.
    • Enabled support for thread operations, semaphores, mutexes, message queues, timers, and critical section management.
    • Enhanced overall system stability with robust error handling and dynamic memory management.

- support liteos_m

Signed-off-by: Hongpeng Huo <[email protected]>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 3, 2025

Walkthrough

This pull request introduces a new OS abstraction layer for USB operations in a LiteOS environment. The file osal/usb_osal_liteos_m.c implements functions for thread, semaphore, mutex, message queue, and timer management. It also provides critical section handling, sleep, and dynamic memory management with robust error logging and checks. Each functionality interfaces with underlying LiteOS system calls to manage resources effectively.

Changes

File Change Summary
osal/usb_osal_liteos_m.c - Added OS abstraction layer for LiteOS covering:
Thread Management: usb_osal_thread_create, usb_osal_thread_delete
Semaphore Operations: usb_osal_sem_create, usb_osal_sem_delete, usb_osal_sem_take, usb_osal_sem_give, usb_osal_sem_reset
Mutex Functions: usb_osal_mutex_create, usb_osal_mutex_delete, usb_osal_mutex_take, usb_osal_mutex_give
Message Queue Operations: usb_osal_mq_create, usb_osal_mq_delete, usb_osal_mq_send, usb_osal_mq_recv
Timer Management: usb_osal_timer_create, usb_osal_timer_delete, usb_osal_timer_start, usb_osal_timer_stop
Critical Section & Memory: usb_osal_enter_critical_section, usb_osal_leave_critical_section, usb_osal_msleep, usb_osal_malloc, usb_osal_free

Sequence Diagram(s)

sequenceDiagram
    participant USB as USB Module
    participant OSAL as USB OSAL (LiteOS)
    participant Kernel as LiteOS Kernel
    USB->>OSAL: usb_osal_thread_create(name, stack_size, prio, entry, args)
    OSAL->>Kernel: LOS_TaskCreate(task_params)
    Kernel-->>OSAL: Task created or error
    OSAL-->>USB: Return thread handle or handle error
Loading
sequenceDiagram
    participant USB as USB Module
    participant OSAL as USB OSAL (LiteOS)
    participant Kernel as LiteOS Kernel
    USB->>OSAL: usb_osal_timer_start(timer)
    OSAL->>Kernel: Start software timer
    Kernel-->>OSAL: Timer started status
    OSAL-->>USB: Acknowledge timer start
Loading

Poem

Oh, how my code hops in delight,
Threads and timers in line so bright.
Semaphores and mutexes hold the fort tight,
Message queues and memory—everything’s just right.
I scamper through the bytes with a bunny's cheer,
Celebrating changes with a twitch of my ear! 🐰✨

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
osal/usb_osal_liteos_m.c (2)

38-39: Refactor repeated while (1) error handling for maintainability.
Each time an error occurs, the code logs the error and goes into an infinite loop, which may make debugging or error recovery difficult. Consider centralizing the error handling or returning an error code to allow upper layers a chance to handle the failure gracefully instead of hanging the system.

Also applies to: 48-49, 66-67, 81-82, 96-97, 137-138, 152-153, 185-186, 200-201, 259-260, 281-282, 296-297, 310-311


42-42: Ensure null termination when copying thread name.
strncpy(t->name, name, sizeof(t->name)) may not null-terminate if name exceeds t->name. Consider a safer pattern:

-    strncpy(t->name, name, sizeof(t->name));
+    strncpy(t->name, name, sizeof(t->name) - 1);
+    t->name[sizeof(t->name) - 1] = '\0';
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f25f79 and d7b5675.

📒 Files selected for processing (1)
  • osal/usb_osal_liteos_m.c (1 hunks)
🔇 Additional comments (3)
osal/usb_osal_liteos_m.c (3)

123-126: Clarify the purpose of this empty usb_osal_sem_reset function.
The function has no implementation. If a reset mechanism is needed, implement the logic here. Otherwise, you can safely remove it to prevent confusion.


210-213: Good approach for interrupt context.
Using non-blocking calls (LOS_NO_WAIT) when OS_INT_ACTIVE is set prevents deadlocks or waits in interrupt context. This is a well-considered design choice.


31-33:

Details

❓ Verification inconclusive

Confirm pointer size alignment for .uwArg = (UINT32)args.
Casting a pointer to UINT32 may cause truncation or undefined behavior if running on a 64-bit architecture. If LiteOS is strictly 32-bit, this should be fine; otherwise, consider using a 64-bit argument field or an appropriate pointer-to-integer cast mechanism.

We can scan for all references to .uwArg to ensure usage aligns with a 32-bit environment:


🏁 Script executed:

#!/bin/bash
fd -e c -e h | xargs rg '\.uwArg'

Length of output: 91


Action Required: Verify 32-bit Environment for Pointer Cast Alignment

The search confirms that the only reference to .uwArg is in osal/usb_osal_liteos_m.c where the pointer is cast to UINT32. This suggests the current design assumes a 32-bit address space. However, to prevent potential truncation issues on a 64-bit system, please double-check that LiteOS is strictly 32-bit. If there’s any chance the code might run in a 64-bit environment, consider revising the cast mechanism or expanding the argument field accordingly.

@sakumisu sakumisu merged commit 339a99a into cherry-embedded:master Apr 4, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants