Attached is a code from one user of the MPLAB Device blocks for Simulink with Simulink who kindly permits to publish it. It uses multiple "C function Call" block to use theses functions from the simulink model. It targets a dsPIC 33EP256MC506.
It is provided "as-is" for reference, to be adapted for other uses.
Note a more complex alternative available on the forum based on the CAN-open source.