In this paper, we present a model-driven approach to RTOS-based embedded software development and an automated tool that can produce RTOS-specific code. Our contributions are two fold. First, we defined generic RTOS APIs (Application Programming Interfaces) that can capture most of typical RTOS services but are not bound to any specific RTOS. The generic RTOS APIs can be used as a means for describing application’s RTOSrelated behavior at an early design stage. We then developed an automated transformation tool that can generate functional code by transforming generic RTOS APIs into RTOS-specific APIs. Our tool, called TransPI, is able to produce ‘C’ code aimed at POSIX-compliant RTOSs, and is also configurable to target other RTOSs that do not conform to the POSIX standard.