helpfor studient
Dependents: STM32_F103-C8T6basecanblink_led
Fork of mbed-dev by
targets/TARGET_NUVOTON/TARGET_NUC472/can_api.c@160:d5399cc887bb, 2017-03-14 (annotated)
- Committer:
- <>
- Date:
- Tue Mar 14 16:40:56 2017 +0000
- Revision:
- 160:d5399cc887bb
- Parent:
- 150:02e0a0aed4ec
- Child:
- 161:2cc1468da177
This updates the lib to the mbed lib v138
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 150:02e0a0aed4ec | 1 | /* mbed Microcontroller Library |
<> | 150:02e0a0aed4ec | 2 | * Copyright (c) 2015-2016 Nuvoton |
<> | 150:02e0a0aed4ec | 3 | * |
<> | 150:02e0a0aed4ec | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 150:02e0a0aed4ec | 5 | * you may not use this file except in compliance with the License. |
<> | 150:02e0a0aed4ec | 6 | * You may obtain a copy of the License at |
<> | 150:02e0a0aed4ec | 7 | * |
<> | 150:02e0a0aed4ec | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 150:02e0a0aed4ec | 9 | * |
<> | 150:02e0a0aed4ec | 10 | * Unless required by applicable law or agreed to in writing, software |
<> | 150:02e0a0aed4ec | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 150:02e0a0aed4ec | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 150:02e0a0aed4ec | 13 | * See the License for the specific language governing permissions and |
<> | 150:02e0a0aed4ec | 14 | * limitations under the License. |
<> | 150:02e0a0aed4ec | 15 | */ |
<> | 150:02e0a0aed4ec | 16 | |
<> | 150:02e0a0aed4ec | 17 | #include "can_api.h" |
<> | 150:02e0a0aed4ec | 18 | #include "nuc472_gpio.h" |
<> | 150:02e0a0aed4ec | 19 | #include "nuc472_can.h" |
<> | 150:02e0a0aed4ec | 20 | |
<> | 150:02e0a0aed4ec | 21 | #if DEVICE_CAN |
<> | 150:02e0a0aed4ec | 22 | #include <string.h> |
<> | 150:02e0a0aed4ec | 23 | #include "cmsis.h" |
<> | 150:02e0a0aed4ec | 24 | #include "pinmap.h" |
<> | 150:02e0a0aed4ec | 25 | #include "PeripheralPins.h" |
<> | 150:02e0a0aed4ec | 26 | #include "nu_modutil.h" |
<> | 150:02e0a0aed4ec | 27 | #include "nu_miscutil.h" |
<> | 150:02e0a0aed4ec | 28 | #include "nu_bitutil.h" |
<> | 160:d5399cc887bb | 29 | #include "mbed_critical.h" |
<> | 150:02e0a0aed4ec | 30 | |
<> | 150:02e0a0aed4ec | 31 | #define NU_CAN_DEBUG 0 |
<> | 150:02e0a0aed4ec | 32 | #define CAN_NUM 2 |
<> | 150:02e0a0aed4ec | 33 | |
<> | 150:02e0a0aed4ec | 34 | static uint32_t can_irq_ids[CAN_NUM] = {0}; |
<> | 150:02e0a0aed4ec | 35 | static can_irq_handler can0_irq_handler; |
<> | 150:02e0a0aed4ec | 36 | static can_irq_handler can1_irq_handler; |
<> | 150:02e0a0aed4ec | 37 | |
<> | 150:02e0a0aed4ec | 38 | |
<> | 150:02e0a0aed4ec | 39 | static const struct nu_modinit_s can_modinit_tab[] = { |
<> | 150:02e0a0aed4ec | 40 | {CAN_0, CAN0_MODULE, 0, 0, CAN0_RST, CAN0_IRQn, NULL}, |
<> | 150:02e0a0aed4ec | 41 | {CAN_1, CAN1_MODULE, 0, 0, CAN1_RST, CAN1_IRQn, NULL}, |
<> | 150:02e0a0aed4ec | 42 | |
<> | 150:02e0a0aed4ec | 43 | {NC, 0, 0, 0, 0, (IRQn_Type) 0, NULL} |
<> | 150:02e0a0aed4ec | 44 | }; |
<> | 150:02e0a0aed4ec | 45 | |
<> | 150:02e0a0aed4ec | 46 | |
<> | 150:02e0a0aed4ec | 47 | void can_init(can_t *obj, PinName rd, PinName td) |
<> | 150:02e0a0aed4ec | 48 | { |
<> | 150:02e0a0aed4ec | 49 | uint32_t can_td = (CANName)pinmap_peripheral(td, PinMap_CAN_TD); |
<> | 150:02e0a0aed4ec | 50 | uint32_t can_rd = (CANName)pinmap_peripheral(rd, PinMap_CAN_RD); |
<> | 150:02e0a0aed4ec | 51 | obj->can = (CANName)pinmap_merge(can_td, can_rd); |
<> | 150:02e0a0aed4ec | 52 | MBED_ASSERT((int)obj->can != NC); |
<> | 150:02e0a0aed4ec | 53 | |
<> | 150:02e0a0aed4ec | 54 | const struct nu_modinit_s *modinit = get_modinit(obj->can, can_modinit_tab); |
<> | 150:02e0a0aed4ec | 55 | MBED_ASSERT(modinit != NULL); |
<> | 150:02e0a0aed4ec | 56 | MBED_ASSERT(modinit->modname == obj->can); |
<> | 150:02e0a0aed4ec | 57 | |
<> | 150:02e0a0aed4ec | 58 | // Reset this module |
<> | 150:02e0a0aed4ec | 59 | SYS_ResetModule(modinit->rsetidx); |
<> | 150:02e0a0aed4ec | 60 | |
<> | 150:02e0a0aed4ec | 61 | // Enable IP clock |
<> | 150:02e0a0aed4ec | 62 | CLK_EnableModuleClock(modinit->clkidx); |
<> | 150:02e0a0aed4ec | 63 | |
<> | 150:02e0a0aed4ec | 64 | if(obj->can == CAN_1) { |
<> | 150:02e0a0aed4ec | 65 | obj->index = 1; |
<> | 150:02e0a0aed4ec | 66 | } |
<> | 150:02e0a0aed4ec | 67 | else |
<> | 150:02e0a0aed4ec | 68 | obj->index = 0; |
<> | 150:02e0a0aed4ec | 69 | |
<> | 150:02e0a0aed4ec | 70 | pinmap_pinout(td, PinMap_CAN_TD); |
<> | 150:02e0a0aed4ec | 71 | pinmap_pinout(rd, PinMap_CAN_RD); |
<> | 150:02e0a0aed4ec | 72 | |
<> | 150:02e0a0aed4ec | 73 | /* For NCU 472 mbed Board Transmitter Setting (RS Pin) */ |
<> | 150:02e0a0aed4ec | 74 | GPIO_SetMode(PA, BIT2| BIT3, GPIO_MODE_OUTPUT); |
<> | 150:02e0a0aed4ec | 75 | PA2 = 0x00; |
<> | 150:02e0a0aed4ec | 76 | PA3 = 0x00; |
<> | 150:02e0a0aed4ec | 77 | |
<> | 150:02e0a0aed4ec | 78 | CAN_Open((CAN_T *)obj->can, 500000, CAN_NORMAL_MODE); |
<> | 150:02e0a0aed4ec | 79 | |
<> | 150:02e0a0aed4ec | 80 | can_filter(obj, 0, 0, CANStandard, 0); |
<> | 150:02e0a0aed4ec | 81 | } |
<> | 150:02e0a0aed4ec | 82 | |
<> | 150:02e0a0aed4ec | 83 | |
<> | 150:02e0a0aed4ec | 84 | void can_free(can_t *obj) |
<> | 150:02e0a0aed4ec | 85 | { |
<> | 150:02e0a0aed4ec | 86 | |
<> | 150:02e0a0aed4ec | 87 | const struct nu_modinit_s *modinit = get_modinit(obj->can, can_modinit_tab); |
<> | 150:02e0a0aed4ec | 88 | |
<> | 150:02e0a0aed4ec | 89 | MBED_ASSERT(modinit != NULL); |
<> | 150:02e0a0aed4ec | 90 | MBED_ASSERT(modinit->modname == obj->can); |
<> | 150:02e0a0aed4ec | 91 | |
<> | 150:02e0a0aed4ec | 92 | // Reset this module |
<> | 150:02e0a0aed4ec | 93 | SYS_ResetModule(modinit->rsetidx); |
<> | 150:02e0a0aed4ec | 94 | |
<> | 150:02e0a0aed4ec | 95 | CLK_DisableModuleClock(modinit->clkidx); |
<> | 150:02e0a0aed4ec | 96 | } |
<> | 150:02e0a0aed4ec | 97 | |
<> | 150:02e0a0aed4ec | 98 | int can_frequency(can_t *obj, int hz) |
<> | 150:02e0a0aed4ec | 99 | { |
<> | 150:02e0a0aed4ec | 100 | CAN_SetBaudRate((CAN_T *)obj->can, hz); |
<> | 150:02e0a0aed4ec | 101 | |
<> | 150:02e0a0aed4ec | 102 | return CAN_GetCANBitRate((CAN_T *)obj->can); |
<> | 150:02e0a0aed4ec | 103 | } |
<> | 150:02e0a0aed4ec | 104 | |
<> | 150:02e0a0aed4ec | 105 | static void can_irq(CANName name, int id) |
<> | 150:02e0a0aed4ec | 106 | { |
<> | 150:02e0a0aed4ec | 107 | |
<> | 150:02e0a0aed4ec | 108 | CAN_T *can = (CAN_T *)NU_MODBASE(name); |
<> | 150:02e0a0aed4ec | 109 | uint32_t u8IIDRstatus; |
<> | 150:02e0a0aed4ec | 110 | |
<> | 150:02e0a0aed4ec | 111 | u8IIDRstatus = can->IIDR; |
<> | 150:02e0a0aed4ec | 112 | |
<> | 150:02e0a0aed4ec | 113 | if(u8IIDRstatus == 0x00008000) { /* Check Status Interrupt Flag (Error status Int and Status change Int) */ |
<> | 150:02e0a0aed4ec | 114 | /**************************/ |
<> | 150:02e0a0aed4ec | 115 | /* Status Change interrupt*/ |
<> | 150:02e0a0aed4ec | 116 | /**************************/ |
<> | 150:02e0a0aed4ec | 117 | if(can->STATUS & CAN_STATUS_RXOK_Msk) { |
<> | 150:02e0a0aed4ec | 118 | can->STATUS &= ~CAN_STATUS_RXOK_Msk; /* Clear Rx Ok status*/ |
<> | 150:02e0a0aed4ec | 119 | if(id) |
<> | 150:02e0a0aed4ec | 120 | can1_irq_handler(can_irq_ids[id] , IRQ_RX); |
<> | 150:02e0a0aed4ec | 121 | else |
<> | 150:02e0a0aed4ec | 122 | can0_irq_handler(can_irq_ids[id], IRQ_RX); |
<> | 150:02e0a0aed4ec | 123 | } |
<> | 150:02e0a0aed4ec | 124 | |
<> | 150:02e0a0aed4ec | 125 | if(can->STATUS & CAN_STATUS_TXOK_Msk) { |
<> | 150:02e0a0aed4ec | 126 | can->STATUS &= ~CAN_STATUS_TXOK_Msk; /* Clear Tx Ok status*/ |
<> | 150:02e0a0aed4ec | 127 | if(id) |
<> | 150:02e0a0aed4ec | 128 | can1_irq_handler(can_irq_ids[id] , IRQ_TX); |
<> | 150:02e0a0aed4ec | 129 | else |
<> | 150:02e0a0aed4ec | 130 | can0_irq_handler(can_irq_ids[id], IRQ_TX); |
<> | 150:02e0a0aed4ec | 131 | |
<> | 150:02e0a0aed4ec | 132 | } |
<> | 150:02e0a0aed4ec | 133 | |
<> | 150:02e0a0aed4ec | 134 | /**************************/ |
<> | 150:02e0a0aed4ec | 135 | /* Error Status interrupt */ |
<> | 150:02e0a0aed4ec | 136 | /**************************/ |
<> | 150:02e0a0aed4ec | 137 | if(can->STATUS & CAN_STATUS_EWARN_Msk) { |
<> | 150:02e0a0aed4ec | 138 | if(id) |
<> | 150:02e0a0aed4ec | 139 | can1_irq_handler(can_irq_ids[id] , IRQ_ERROR); |
<> | 150:02e0a0aed4ec | 140 | else |
<> | 150:02e0a0aed4ec | 141 | can0_irq_handler(can_irq_ids[id], IRQ_ERROR); |
<> | 150:02e0a0aed4ec | 142 | } |
<> | 150:02e0a0aed4ec | 143 | |
<> | 150:02e0a0aed4ec | 144 | if(can->STATUS & CAN_STATUS_BOFF_Msk) { |
<> | 150:02e0a0aed4ec | 145 | if(id) |
<> | 150:02e0a0aed4ec | 146 | can1_irq_handler(can_irq_ids[id] , IRQ_BUS); |
<> | 150:02e0a0aed4ec | 147 | else |
<> | 150:02e0a0aed4ec | 148 | can0_irq_handler(can_irq_ids[id], IRQ_BUS); |
<> | 150:02e0a0aed4ec | 149 | } |
<> | 150:02e0a0aed4ec | 150 | } else if (u8IIDRstatus!=0) { |
<> | 150:02e0a0aed4ec | 151 | |
<> | 150:02e0a0aed4ec | 152 | if(id) |
<> | 150:02e0a0aed4ec | 153 | can1_irq_handler(can_irq_ids[id] , IRQ_OVERRUN); |
<> | 150:02e0a0aed4ec | 154 | else |
<> | 150:02e0a0aed4ec | 155 | can0_irq_handler(can_irq_ids[id], IRQ_OVERRUN); |
<> | 150:02e0a0aed4ec | 156 | |
<> | 150:02e0a0aed4ec | 157 | CAN_CLR_INT_PENDING_BIT(can, ((can->IIDR) -1)); /* Clear Interrupt Pending */ |
<> | 150:02e0a0aed4ec | 158 | |
<> | 150:02e0a0aed4ec | 159 | } else if(can->WU_STATUS == 1) { |
<> | 150:02e0a0aed4ec | 160 | |
<> | 150:02e0a0aed4ec | 161 | can->WU_STATUS = 0; /* Write '0' to clear */ |
<> | 150:02e0a0aed4ec | 162 | if(id) |
<> | 150:02e0a0aed4ec | 163 | can1_irq_handler(can_irq_ids[id] , IRQ_WAKEUP); |
<> | 150:02e0a0aed4ec | 164 | else |
<> | 150:02e0a0aed4ec | 165 | can0_irq_handler(can_irq_ids[id], IRQ_WAKEUP); |
<> | 150:02e0a0aed4ec | 166 | } |
<> | 150:02e0a0aed4ec | 167 | } |
<> | 150:02e0a0aed4ec | 168 | |
<> | 150:02e0a0aed4ec | 169 | void CAN0_IRQHandler(void) |
<> | 150:02e0a0aed4ec | 170 | { |
<> | 150:02e0a0aed4ec | 171 | can_irq(CAN_0, 0); |
<> | 150:02e0a0aed4ec | 172 | } |
<> | 150:02e0a0aed4ec | 173 | |
<> | 150:02e0a0aed4ec | 174 | void CAN1_IRQHandler(void) |
<> | 150:02e0a0aed4ec | 175 | { |
<> | 150:02e0a0aed4ec | 176 | can_irq(CAN_1, 1); |
<> | 150:02e0a0aed4ec | 177 | } |
<> | 150:02e0a0aed4ec | 178 | |
<> | 150:02e0a0aed4ec | 179 | void can_irq_init(can_t *obj, can_irq_handler handler, uint32_t id) |
<> | 150:02e0a0aed4ec | 180 | { |
<> | 150:02e0a0aed4ec | 181 | if(obj->index) |
<> | 150:02e0a0aed4ec | 182 | can1_irq_handler = handler; |
<> | 150:02e0a0aed4ec | 183 | else |
<> | 150:02e0a0aed4ec | 184 | can0_irq_handler = handler; |
<> | 150:02e0a0aed4ec | 185 | can_irq_ids[obj->index] = id; |
<> | 150:02e0a0aed4ec | 186 | |
<> | 150:02e0a0aed4ec | 187 | } |
<> | 150:02e0a0aed4ec | 188 | |
<> | 150:02e0a0aed4ec | 189 | void can_irq_free(can_t *obj) |
<> | 150:02e0a0aed4ec | 190 | { |
<> | 150:02e0a0aed4ec | 191 | CAN_DisableInt((CAN_T *)obj->can, (CAN_CON_IE_Msk|CAN_CON_SIE_Msk|CAN_CON_EIE_Msk)); |
<> | 150:02e0a0aed4ec | 192 | |
<> | 150:02e0a0aed4ec | 193 | can_irq_ids[obj->index] = 0; |
<> | 150:02e0a0aed4ec | 194 | |
<> | 150:02e0a0aed4ec | 195 | if(!obj->index) |
<> | 150:02e0a0aed4ec | 196 | NVIC_DisableIRQ(CAN0_IRQn); |
<> | 150:02e0a0aed4ec | 197 | else |
<> | 150:02e0a0aed4ec | 198 | NVIC_DisableIRQ(CAN1_IRQn); |
<> | 150:02e0a0aed4ec | 199 | |
<> | 150:02e0a0aed4ec | 200 | |
<> | 150:02e0a0aed4ec | 201 | } |
<> | 150:02e0a0aed4ec | 202 | |
<> | 150:02e0a0aed4ec | 203 | void can_irq_set(can_t *obj, CanIrqType irq, uint32_t enable) |
<> | 150:02e0a0aed4ec | 204 | { |
<> | 150:02e0a0aed4ec | 205 | |
<> | 150:02e0a0aed4ec | 206 | CAN_EnterInitMode((CAN_T*)obj->can); |
<> | 150:02e0a0aed4ec | 207 | |
<> | 150:02e0a0aed4ec | 208 | ((CAN_T *)(obj->can))->CON = (((CAN_T *)(obj->can))->CON ) | ((enable != 0 )? CAN_CON_IE_Msk :0); |
<> | 150:02e0a0aed4ec | 209 | |
<> | 150:02e0a0aed4ec | 210 | switch (irq) |
<> | 150:02e0a0aed4ec | 211 | { |
<> | 150:02e0a0aed4ec | 212 | case IRQ_ERROR: |
<> | 150:02e0a0aed4ec | 213 | case IRQ_BUS: |
<> | 150:02e0a0aed4ec | 214 | case IRQ_PASSIVE: |
<> | 150:02e0a0aed4ec | 215 | ((CAN_T *)(obj->can))->CON = (((CAN_T *)(obj->can))->CON) |CAN_CON_EIE_Msk; |
<> | 150:02e0a0aed4ec | 216 | ((CAN_T *)(obj->can))->CON = (((CAN_T *)(obj->can))->CON) |CAN_CON_SIE_Msk; |
<> | 150:02e0a0aed4ec | 217 | break; |
<> | 150:02e0a0aed4ec | 218 | |
<> | 150:02e0a0aed4ec | 219 | case IRQ_RX: |
<> | 150:02e0a0aed4ec | 220 | case IRQ_TX: |
<> | 150:02e0a0aed4ec | 221 | case IRQ_OVERRUN: |
<> | 150:02e0a0aed4ec | 222 | case IRQ_WAKEUP: |
<> | 150:02e0a0aed4ec | 223 | ((CAN_T *)(obj->can))->CON = (((CAN_T *)(obj->can))->CON) |CAN_CON_SIE_Msk; |
<> | 150:02e0a0aed4ec | 224 | break; |
<> | 150:02e0a0aed4ec | 225 | |
<> | 150:02e0a0aed4ec | 226 | default: |
<> | 150:02e0a0aed4ec | 227 | break; |
<> | 150:02e0a0aed4ec | 228 | |
<> | 150:02e0a0aed4ec | 229 | } |
<> | 150:02e0a0aed4ec | 230 | |
<> | 150:02e0a0aed4ec | 231 | CAN_LeaveInitMode((CAN_T*)obj->can); |
<> | 150:02e0a0aed4ec | 232 | |
<> | 150:02e0a0aed4ec | 233 | if(!obj->index) |
<> | 150:02e0a0aed4ec | 234 | { |
<> | 150:02e0a0aed4ec | 235 | NVIC_SetVector(CAN0_IRQn, (uint32_t)&CAN0_IRQHandler); |
<> | 150:02e0a0aed4ec | 236 | NVIC_EnableIRQ(CAN0_IRQn); |
<> | 150:02e0a0aed4ec | 237 | } |
<> | 150:02e0a0aed4ec | 238 | else |
<> | 150:02e0a0aed4ec | 239 | { |
<> | 150:02e0a0aed4ec | 240 | NVIC_SetVector(CAN1_IRQn, (uint32_t)&CAN1_IRQHandler); |
<> | 150:02e0a0aed4ec | 241 | NVIC_EnableIRQ(CAN1_IRQn); |
<> | 150:02e0a0aed4ec | 242 | } |
<> | 150:02e0a0aed4ec | 243 | |
<> | 150:02e0a0aed4ec | 244 | } |
<> | 150:02e0a0aed4ec | 245 | |
<> | 150:02e0a0aed4ec | 246 | int can_write(can_t *obj, CAN_Message msg, int cc) |
<> | 150:02e0a0aed4ec | 247 | { |
<> | 150:02e0a0aed4ec | 248 | STR_CANMSG_T CMsg; |
<> | 150:02e0a0aed4ec | 249 | |
<> | 150:02e0a0aed4ec | 250 | CMsg.IdType = (uint32_t)msg.format; |
<> | 150:02e0a0aed4ec | 251 | CMsg.FrameType = (uint32_t)!msg.type; |
<> | 150:02e0a0aed4ec | 252 | CMsg.Id = msg.id; |
<> | 150:02e0a0aed4ec | 253 | CMsg.DLC = msg.len; |
<> | 150:02e0a0aed4ec | 254 | memcpy((void *)&CMsg.Data[0],(const void *)&msg.data[0], (unsigned int)8); |
<> | 150:02e0a0aed4ec | 255 | |
<> | 150:02e0a0aed4ec | 256 | return CAN_Transmit((CAN_T *)(obj->can), cc, &CMsg); |
<> | 150:02e0a0aed4ec | 257 | } |
<> | 150:02e0a0aed4ec | 258 | |
<> | 150:02e0a0aed4ec | 259 | int can_read(can_t *obj, CAN_Message *msg, int handle) |
<> | 150:02e0a0aed4ec | 260 | { |
<> | 150:02e0a0aed4ec | 261 | STR_CANMSG_T CMsg; |
<> | 150:02e0a0aed4ec | 262 | |
<> | 150:02e0a0aed4ec | 263 | if(!CAN_Receive((CAN_T *)(obj->can), handle, &CMsg)) |
<> | 150:02e0a0aed4ec | 264 | return 0; |
<> | 150:02e0a0aed4ec | 265 | |
<> | 150:02e0a0aed4ec | 266 | msg->format = (CANFormat)CMsg.IdType; |
<> | 150:02e0a0aed4ec | 267 | msg->type = (CANType)!CMsg.FrameType; |
<> | 150:02e0a0aed4ec | 268 | msg->id = CMsg.Id; |
<> | 150:02e0a0aed4ec | 269 | msg->len = CMsg.DLC; |
<> | 150:02e0a0aed4ec | 270 | memcpy(&msg->data[0], &CMsg.Data[0], 8); |
<> | 150:02e0a0aed4ec | 271 | |
<> | 150:02e0a0aed4ec | 272 | return 1; |
<> | 150:02e0a0aed4ec | 273 | } |
<> | 150:02e0a0aed4ec | 274 | |
<> | 150:02e0a0aed4ec | 275 | int can_mode(can_t *obj, CanMode mode) |
<> | 150:02e0a0aed4ec | 276 | { |
<> | 150:02e0a0aed4ec | 277 | int success = 0; |
<> | 150:02e0a0aed4ec | 278 | switch (mode) |
<> | 150:02e0a0aed4ec | 279 | { |
<> | 150:02e0a0aed4ec | 280 | case MODE_RESET: |
<> | 150:02e0a0aed4ec | 281 | CAN_LeaveTestMode((CAN_T*)obj->can); |
<> | 150:02e0a0aed4ec | 282 | success = 1; |
<> | 150:02e0a0aed4ec | 283 | break; |
<> | 150:02e0a0aed4ec | 284 | |
<> | 150:02e0a0aed4ec | 285 | case MODE_NORMAL: |
<> | 150:02e0a0aed4ec | 286 | CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_BASIC_Msk); |
<> | 150:02e0a0aed4ec | 287 | success = 1; |
<> | 150:02e0a0aed4ec | 288 | break; |
<> | 150:02e0a0aed4ec | 289 | |
<> | 150:02e0a0aed4ec | 290 | case MODE_SILENT: |
<> | 150:02e0a0aed4ec | 291 | CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_SILENT_Msk); |
<> | 150:02e0a0aed4ec | 292 | success = 1; |
<> | 150:02e0a0aed4ec | 293 | break; |
<> | 150:02e0a0aed4ec | 294 | |
<> | 150:02e0a0aed4ec | 295 | case MODE_TEST_LOCAL: |
<> | 150:02e0a0aed4ec | 296 | case MODE_TEST_GLOBAL: |
<> | 150:02e0a0aed4ec | 297 | CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_LBACK_Msk); |
<> | 150:02e0a0aed4ec | 298 | success = 1; |
<> | 150:02e0a0aed4ec | 299 | break; |
<> | 150:02e0a0aed4ec | 300 | |
<> | 150:02e0a0aed4ec | 301 | case MODE_TEST_SILENT: |
<> | 150:02e0a0aed4ec | 302 | CAN_EnterTestMode((CAN_T*)(obj->can), CAN_TEST_SILENT_Msk | CAN_TEST_LBACK_Msk); |
<> | 150:02e0a0aed4ec | 303 | success = 1; |
<> | 150:02e0a0aed4ec | 304 | break; |
<> | 150:02e0a0aed4ec | 305 | |
<> | 150:02e0a0aed4ec | 306 | default: |
<> | 150:02e0a0aed4ec | 307 | success = 0; |
<> | 150:02e0a0aed4ec | 308 | break; |
<> | 150:02e0a0aed4ec | 309 | |
<> | 150:02e0a0aed4ec | 310 | } |
<> | 150:02e0a0aed4ec | 311 | |
<> | 150:02e0a0aed4ec | 312 | |
<> | 150:02e0a0aed4ec | 313 | return success; |
<> | 150:02e0a0aed4ec | 314 | } |
<> | 150:02e0a0aed4ec | 315 | |
<> | 150:02e0a0aed4ec | 316 | int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle) |
<> | 150:02e0a0aed4ec | 317 | { |
<> | 150:02e0a0aed4ec | 318 | return CAN_SetRxMsg((CAN_T *)(obj->can), handle , (uint32_t)format, id); |
<> | 150:02e0a0aed4ec | 319 | } |
<> | 150:02e0a0aed4ec | 320 | |
<> | 150:02e0a0aed4ec | 321 | |
<> | 150:02e0a0aed4ec | 322 | void can_reset(can_t *obj) |
<> | 150:02e0a0aed4ec | 323 | { |
<> | 150:02e0a0aed4ec | 324 | const struct nu_modinit_s *modinit = get_modinit(obj->can, can_modinit_tab); |
<> | 150:02e0a0aed4ec | 325 | |
<> | 150:02e0a0aed4ec | 326 | MBED_ASSERT(modinit != NULL); |
<> | 150:02e0a0aed4ec | 327 | MBED_ASSERT(modinit->modname == obj->can); |
<> | 150:02e0a0aed4ec | 328 | |
<> | 150:02e0a0aed4ec | 329 | // Reset this module |
<> | 150:02e0a0aed4ec | 330 | SYS_ResetModule(modinit->rsetidx); |
<> | 150:02e0a0aed4ec | 331 | |
<> | 150:02e0a0aed4ec | 332 | } |
<> | 150:02e0a0aed4ec | 333 | |
<> | 150:02e0a0aed4ec | 334 | unsigned char can_rderror(can_t *obj) |
<> | 150:02e0a0aed4ec | 335 | { |
<> | 150:02e0a0aed4ec | 336 | CAN_T *can = (CAN_T *)(obj->can); |
<> | 150:02e0a0aed4ec | 337 | return ((can->ERR>>8)&0xFF); |
<> | 150:02e0a0aed4ec | 338 | } |
<> | 150:02e0a0aed4ec | 339 | |
<> | 150:02e0a0aed4ec | 340 | unsigned char can_tderror(can_t *obj) |
<> | 150:02e0a0aed4ec | 341 | { |
<> | 150:02e0a0aed4ec | 342 | CAN_T *can = (CAN_T *)(obj->can); |
<> | 150:02e0a0aed4ec | 343 | return ((can->ERR)&0xFF); |
<> | 150:02e0a0aed4ec | 344 | } |
<> | 150:02e0a0aed4ec | 345 | |
<> | 150:02e0a0aed4ec | 346 | void can_monitor(can_t *obj, int silent) |
<> | 150:02e0a0aed4ec | 347 | { |
<> | 150:02e0a0aed4ec | 348 | CAN_EnterTestMode((CAN_T *)(obj->can), CAN_TEST_SILENT_Msk); |
<> | 150:02e0a0aed4ec | 349 | } |
<> | 150:02e0a0aed4ec | 350 | |
<> | 150:02e0a0aed4ec | 351 | #endif // DEVICE_CAN |