@@ -67,31 +67,200 @@ typedef void (*can_irq_handler)(uintptr_t context, CanIrqType type);
6767
6868typedef struct can_s can_t ;
6969
70+ /** Initialize the CAN peripheral. It sets the default parameters for CAN
71+ * peripheral, and configures its specifieds pins.
72+ *
73+ * @param obj CAN object
74+ * @param rd The CAN RD pin name
75+ * @param td The CAN TD pin name
76+ */
7077void can_init (can_t * obj , PinName rd , PinName td );
78+
79+ /** Initialize the CAN peripheral. It sets the default parameters for CAN
80+ * peripheral, and configures its specifieds pins.
81+ *
82+ * @param obj The CAN object
83+ * @param pinmap pointer to structure which holds static pinmap
84+ */
7185void can_init_direct (can_t * obj , const can_pinmap_t * pinmap );
86+
87+ /** Initialize the CAN peripheral. It sets the default parameters for CAN
88+ * peripheral, and configures its specifieds pins.
89+ *
90+ * @param obj CAN object
91+ * @param rd The CAN RD pin name
92+ * @param td The CAN TD pin name
93+ * @param hz The bus frequency
94+ */
7295void can_init_freq (can_t * obj , PinName rd , PinName td , int hz );
96+
97+ /** Initialize the CAN peripheral. It sets the default parameters for CAN
98+ * peripheral, and configures its specifieds pins.
99+ *
100+ * @param obj CAN object
101+ * @param pinmap pointer to structure which holds static pinmap
102+ * @param hz The bus frequency
103+ */
73104void can_init_freq_direct (can_t * obj , const can_pinmap_t * pinmap , int hz );
105+
106+ /** Release the CAN peripheral, not currently invoked. It requires further
107+ * resource management.
108+ *
109+ * @param obj The CAN object
110+ */
74111void can_free (can_t * obj );
112+
113+ /** Configure the CAN bus frequency
114+ *
115+ * @param obj The CAN object
116+ * @param hz The bus frequency
117+ */
75118int can_frequency (can_t * obj , int hz );
76119
120+ /** Initialize the CAN IRQ handler
121+ *
122+ * @param obj The CAN object
123+ * @param handler The handler to be attached to CAN IRQ
124+ * @param context The context to be passed back to the handler (context != 0, 0 is reserved)
125+ */
77126void can_irq_init (can_t * obj , can_irq_handler handler , uintptr_t context );
127+
128+ /** Release the CAN object
129+ *
130+ * @param obj The CAN object
131+ */
78132void can_irq_free (can_t * obj );
133+
134+ /** Enable/disable the CAN IRQ event
135+ *
136+ * @param obj The CAN object
137+ * @param irq The CAN IRQ event
138+ * @param enable The enable flag
139+ */
79140void can_irq_set (can_t * obj , CanIrqType irq , uint32_t enable );
80141
81- int can_write (can_t * obj , CAN_Message , int cc );
142+ /** Write a CAN message to the bus.
143+ *
144+ * @param obj The CAN object
145+ * @param msg The CAN message to write.
146+ *
147+ * @return 0 if write failed,
148+ * 1 if write was successful
149+ */
150+ int can_write (can_t * obj , CAN_Message msg );
151+
152+ /** Read a CAN message from the bus.
153+ *
154+ * @param obj CAN object
155+ * @param msg A CAN message to read to.
156+ * @param handle message filter handle (0 for any message).
157+ *
158+ * @return 0 if no message arrived,
159+ * 1 if message arrived
160+ */
82161int can_read (can_t * obj , CAN_Message * msg , int handle );
162+
163+ /** Change CAN operation to the specified mode.
164+ *
165+ * @param obj The CAN object
166+ * @param mode The new operation mode (MODE_NORMAL, MODE_SILENT, MODE_TEST_LOCAL, MODE_TEST_GLOBAL, MODE_TEST_SILENT).
167+ *
168+ * @return 0 if mode change failed or unsupported,
169+ * 1 if mode change was successful
170+ */
83171int can_mode (can_t * obj , CanMode mode );
172+
173+ /** Filter out incomming messages.
174+ *
175+ * @param obj The CAN object
176+ * @param id the id to filter on.
177+ * @param mask the mask applied to the id.
178+ * @param format format to filter on (Default CANAny).
179+ * @param handle message filter handle (Optional).
180+ *
181+ * @return 0 if filter change failed or unsupported,
182+ * new filter handle if successful
183+ */
84184int can_filter (can_t * obj , uint32_t id , uint32_t mask , CANFormat format , int32_t handle );
185+
186+ /** Reset CAN interface.
187+ *
188+ * @param obj CAN object
189+ *
190+ * To use after error overflow.
191+ */
85192void can_reset (can_t * obj );
193+
194+ /** Detects read errors - Used to detect read overflow errors.
195+ *
196+ * @param obj CAN object
197+ * @return number of read errors
198+ */
86199unsigned char can_rderror (can_t * obj );
200+
201+ /** Detects write errors - Used to detect write overflow errors.
202+ *
203+ * @param obj CAN object
204+ * @return number of write errors
205+ */
87206unsigned char can_tderror (can_t * obj );
207+
208+ /** Puts or removes the CAN interface into silent monitoring mode.
209+ *
210+ * @param obj CAN object
211+ * @param silent boolean indicating whether to go into silent mode or not.
212+ */
88213void can_monitor (can_t * obj , int silent );
89214
90215#if DEVICE_CAN_FD
216+ /** Initialize the CAN FD peripheral. It sets the default parameters for CAN FD
217+ * peripheral, and configures its specifieds pins.
218+ *
219+ * @param obj CAN object
220+ * @param rd The CAN RD pin name
221+ * @param td The CAN TD pin name
222+ * @param hz The bus frequency of nominal phase
223+ * @param data_hz The bus frequency of data phase, the CAN object is put into Classical CAN mode if this parameter is zero
224+ */
91225void canfd_init_freq (can_t * obj , PinName rd , PinName td , int hz , int data_hz );
226+
227+ /** Initialize the CAN FD peripheral. It sets the default parameters for CAN FD
228+ * peripheral, and configures its specifieds pins.
229+ *
230+ * @param obj CAN object
231+ * @param pinmap pointer to structure which holds static pinmap
232+ * @param hz The bus frequency of nominal phase
233+ * @param data_hz The bus frequency of data phase, the CAN object is put into Classical CAN mode if this parameter is zero
234+ */
92235void canfd_init_freq_direct (can_t * obj , const can_pinmap_t * pinmap , int hz , int data_hz );
236+
237+ /** Configure the CAN FD bus frequency
238+ *
239+ * @param obj The CAN object
240+ * @param hz The bus frequency of nominal phase
241+ * @param data_hz The bus frequency of data phase, the CAN object is put into Classical CAN mode if this parameter is zero
242+ */
93243int canfd_frequency (can_t * obj , int hz , int data_hz );
94- int canfd_write (can_t * obj , CANFD_Message , int cc );
244+
245+ /** Write a CAN FD Message to the bus.
246+ *
247+ * @param obj The CAN object
248+ * @param msg The CAN FD Message to write.
249+ *
250+ * @return 0 if write failed,
251+ * 1 if write was successful
252+ */
253+ int canfd_write (can_t * obj , CANFD_Message msg );
254+
255+ /** Read a Classical CAN or CAN FD Message from the bus.
256+ *
257+ * @param obj CAN object
258+ * @param msg A Classical CAN or CAN FD Message to read to.
259+ * @param handle message filter handle (0 for any message).
260+ *
261+ * @return 0 if no message arrived,
262+ * 1 if message arrived
263+ */
95264int canfd_read (can_t * obj , CANFD_Message * msg , int handle );
96265#endif
97266
0 commit comments