These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frank26080115 0:bf7b9fba3924 1 /***********************************************************************//**
frank26080115 0:bf7b9fba3924 2 * @file can_self_test.c
frank26080115 0:bf7b9fba3924 3 * @purpose This example used to test Self-test mode
frank26080115 0:bf7b9fba3924 4 * @version 1.0
frank26080115 0:bf7b9fba3924 5 * @date 18. June. 2010
frank26080115 0:bf7b9fba3924 6 * @author NXP MCU SW Application Team
frank26080115 0:bf7b9fba3924 7 *---------------------------------------------------------------------
frank26080115 0:bf7b9fba3924 8 * Software that is described herein is for illustrative purposes only
frank26080115 0:bf7b9fba3924 9 * which provides customers with programming information regarding the
frank26080115 0:bf7b9fba3924 10 * products. This software is supplied "AS IS" without any warranties.
frank26080115 0:bf7b9fba3924 11 * NXP Semiconductors assumes no responsibility or liability for the
frank26080115 0:bf7b9fba3924 12 * use of the software, conveys no license or title under any patent,
frank26080115 0:bf7b9fba3924 13 * copyright, or mask work right to the product. NXP Semiconductors
frank26080115 0:bf7b9fba3924 14 * reserves the right to make changes in the software without
frank26080115 0:bf7b9fba3924 15 * notification. NXP Semiconductors also make no representation or
frank26080115 0:bf7b9fba3924 16 * warranty that such application will be suitable for the specified
frank26080115 0:bf7b9fba3924 17 * use without further testing or modification.
frank26080115 0:bf7b9fba3924 18 **********************************************************************/
frank26080115 0:bf7b9fba3924 19 #include "lpc17xx_can.h"
frank26080115 0:bf7b9fba3924 20 #include "lpc17xx_libcfg.h"
frank26080115 0:bf7b9fba3924 21 #include "debug_frmwrk.h"
frank26080115 0:bf7b9fba3924 22
frank26080115 0:bf7b9fba3924 23 /* Example group ----------------------------------------------------------- */
frank26080115 0:bf7b9fba3924 24 /** @defgroup CAN_seft_test CAN_self_test
frank26080115 0:bf7b9fba3924 25 * @ingroup CAN_Examples
frank26080115 0:bf7b9fba3924 26 * @{
frank26080115 0:bf7b9fba3924 27 */
frank26080115 0:bf7b9fba3924 28 /************************** PRIVATE VARIABLES *************************/
frank26080115 0:bf7b9fba3924 29 uint8_t menu[]=
frank26080115 0:bf7b9fba3924 30 "*******************************************************************************\n\r"
frank26080115 0:bf7b9fba3924 31 "Hello NXP Semiconductors \n\r"
frank26080115 0:bf7b9fba3924 32 "CAN Self-test demo \n\r"
frank26080115 0:bf7b9fba3924 33 "\t - MCU: LPC17xx \n\r"
frank26080115 0:bf7b9fba3924 34 "\t - Core: ARM CORTEX-M3 \n\r"
frank26080115 0:bf7b9fba3924 35 "\t - Communicate via: UART0 - 115200 bps \n\r"
frank26080115 0:bf7b9fba3924 36 "Use only CAN1 peripherals to test\n\r"
frank26080115 0:bf7b9fba3924 37 "This example used to test Self test mode\n\r"
frank26080115 0:bf7b9fba3924 38 "*******************************************************************************\n\r";
frank26080115 0:bf7b9fba3924 39
frank26080115 0:bf7b9fba3924 40 /** CAN variable definition **/
frank26080115 0:bf7b9fba3924 41 CAN_MSG_Type TXMsg, RXMsg; // messages for test Bypass mode
frank26080115 0:bf7b9fba3924 42 uint32_t CANRxCount, CANTxCount = 0;
frank26080115 0:bf7b9fba3924 43
frank26080115 0:bf7b9fba3924 44 /************************** PRIVATE FUNCTIONS *************************/
frank26080115 0:bf7b9fba3924 45 void CAN_IRQHandler(void);
frank26080115 0:bf7b9fba3924 46
frank26080115 0:bf7b9fba3924 47 void CAN_InitMessage(void);
frank26080115 0:bf7b9fba3924 48 void PrintMessage(CAN_MSG_Type* msg);
frank26080115 0:bf7b9fba3924 49 void print_menu();
frank26080115 0:bf7b9fba3924 50 Bool Check_Message(CAN_MSG_Type* TX_Msg, CAN_MSG_Type* RX_Msg);
frank26080115 0:bf7b9fba3924 51
frank26080115 0:bf7b9fba3924 52
frank26080115 0:bf7b9fba3924 53 /*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
frank26080115 0:bf7b9fba3924 54 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 55 * @brief CAN_IRQ Handler, control receive message operation
frank26080115 0:bf7b9fba3924 56 * param[in] none
frank26080115 0:bf7b9fba3924 57 * @return none
frank26080115 0:bf7b9fba3924 58 **********************************************************************/
frank26080115 0:bf7b9fba3924 59 void CAN_IRQHandler()
frank26080115 0:bf7b9fba3924 60 {
frank26080115 0:bf7b9fba3924 61 uint8_t IntStatus;
frank26080115 0:bf7b9fba3924 62 // uint32_t data1;
frank26080115 0:bf7b9fba3924 63 /* Get CAN status */
frank26080115 0:bf7b9fba3924 64 IntStatus = CAN_GetCTRLStatus(LPC_CAN1, CANCTRL_STS);
frank26080115 0:bf7b9fba3924 65 //check receive buffer status
frank26080115 0:bf7b9fba3924 66 if((IntStatus>>0)&0x01)
frank26080115 0:bf7b9fba3924 67 {
frank26080115 0:bf7b9fba3924 68 CAN_ReceiveMsg(LPC_CAN1,&RXMsg);
frank26080115 0:bf7b9fba3924 69 _DBG_("Received buffer:");
frank26080115 0:bf7b9fba3924 70 PrintMessage(&RXMsg);
frank26080115 0:bf7b9fba3924 71 //Validate received and transmited message
frank26080115 0:bf7b9fba3924 72 if(Check_Message(&TXMsg, &RXMsg))
frank26080115 0:bf7b9fba3924 73 _DBG_("Self test is SUCCESSFUL!!!");
frank26080115 0:bf7b9fba3924 74 else
frank26080115 0:bf7b9fba3924 75 _DBG_("Self test is FAIL!!!");
frank26080115 0:bf7b9fba3924 76 }
frank26080115 0:bf7b9fba3924 77 }
frank26080115 0:bf7b9fba3924 78
frank26080115 0:bf7b9fba3924 79 /*-------------------------PRIVATE FUNCTIONS----------------------------*/
frank26080115 0:bf7b9fba3924 80 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 81 * @brief Print Message via COM1
frank26080115 0:bf7b9fba3924 82 * param[in] msg: point to CAN_MSG_Type object that will be printed
frank26080115 0:bf7b9fba3924 83 * @return none
frank26080115 0:bf7b9fba3924 84 **********************************************************************/
frank26080115 0:bf7b9fba3924 85 void PrintMessage(CAN_MSG_Type* CAN_Msg)
frank26080115 0:bf7b9fba3924 86 {
frank26080115 0:bf7b9fba3924 87 uint32_t data;
frank26080115 0:bf7b9fba3924 88 _DBG("Message ID: ");
frank26080115 0:bf7b9fba3924 89 _DBH32(CAN_Msg->id);_DBG_("");
frank26080115 0:bf7b9fba3924 90 _DBG("Message length: ");
frank26080115 0:bf7b9fba3924 91 _DBH32(CAN_Msg->len);_DBG_(" BYTES");
frank26080115 0:bf7b9fba3924 92 _DBG("Message type: ");
frank26080115 0:bf7b9fba3924 93 if(CAN_Msg->type==DATA_FRAME)
frank26080115 0:bf7b9fba3924 94 {
frank26080115 0:bf7b9fba3924 95 _DBG_("DATA FRAME ");
frank26080115 0:bf7b9fba3924 96 }
frank26080115 0:bf7b9fba3924 97 else
frank26080115 0:bf7b9fba3924 98 _DBG_("REMOTE FRAME ");
frank26080115 0:bf7b9fba3924 99 _DBG("Message format: ");
frank26080115 0:bf7b9fba3924 100 if(CAN_Msg->format==STD_ID_FORMAT)
frank26080115 0:bf7b9fba3924 101 {
frank26080115 0:bf7b9fba3924 102 _DBG_("STANDARD ID FRAME FORMAT");
frank26080115 0:bf7b9fba3924 103 }
frank26080115 0:bf7b9fba3924 104 else
frank26080115 0:bf7b9fba3924 105 _DBG_("EXTENDED ID FRAME FORMAT");
frank26080115 0:bf7b9fba3924 106 _DBG("Message dataA: ");
frank26080115 0:bf7b9fba3924 107 data = (CAN_Msg->dataA[0])|(CAN_Msg->dataA[1]<<8)|(CAN_Msg->dataA[2]<<16)|(CAN_Msg->dataA[3]<<24);
frank26080115 0:bf7b9fba3924 108 _DBH32(data);_DBG_("");
frank26080115 0:bf7b9fba3924 109 data = (CAN_Msg->dataB[0])|(CAN_Msg->dataB[1]<<8)|(CAN_Msg->dataB[2]<<16)|(CAN_Msg->dataB[3]<<24);
frank26080115 0:bf7b9fba3924 110 _DBG("Message dataB: ");
frank26080115 0:bf7b9fba3924 111 _DBH32(data);_DBG_("");
frank26080115 0:bf7b9fba3924 112 _DBG_("");
frank26080115 0:bf7b9fba3924 113 }
frank26080115 0:bf7b9fba3924 114
frank26080115 0:bf7b9fba3924 115 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 116 * @brief Initialize transmit and receive message for Bypass operation
frank26080115 0:bf7b9fba3924 117 * @param[in] none
frank26080115 0:bf7b9fba3924 118 * @return none
frank26080115 0:bf7b9fba3924 119 **********************************************************************/
frank26080115 0:bf7b9fba3924 120 void CAN_InitMessage(void) {
frank26080115 0:bf7b9fba3924 121 TXMsg.format = EXT_ID_FORMAT;
frank26080115 0:bf7b9fba3924 122 TXMsg.id = 0x00001234;
frank26080115 0:bf7b9fba3924 123 TXMsg.len = 8;
frank26080115 0:bf7b9fba3924 124 TXMsg.type = DATA_FRAME;
frank26080115 0:bf7b9fba3924 125 TXMsg.dataA[0] = TXMsg.dataA[1] = TXMsg.dataA[2] = TXMsg.dataA[3] = 0x12;
frank26080115 0:bf7b9fba3924 126 TXMsg.dataB[0] = TXMsg.dataB[1] = TXMsg.dataB[2] = TXMsg.dataB[3] = 0x34;
frank26080115 0:bf7b9fba3924 127
frank26080115 0:bf7b9fba3924 128 RXMsg.format = 0x00;
frank26080115 0:bf7b9fba3924 129 RXMsg.id = 0x00;
frank26080115 0:bf7b9fba3924 130 RXMsg.len = 0x00;
frank26080115 0:bf7b9fba3924 131 RXMsg.type = 0x00;
frank26080115 0:bf7b9fba3924 132 RXMsg.dataA[0] = RXMsg.dataA[1] = RXMsg.dataA[2] = RXMsg.dataA[3] = 0x00000000;
frank26080115 0:bf7b9fba3924 133 RXMsg.dataB[0] = RXMsg.dataA[1] = RXMsg.dataA[2] = RXMsg.dataA[3] = 0x00000000;
frank26080115 0:bf7b9fba3924 134 }
frank26080115 0:bf7b9fba3924 135
frank26080115 0:bf7b9fba3924 136 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 137 * @brief print menu
frank26080115 0:bf7b9fba3924 138 * @param[in] none
frank26080115 0:bf7b9fba3924 139 * @return none
frank26080115 0:bf7b9fba3924 140 **********************************************************************/
frank26080115 0:bf7b9fba3924 141 void print_menu()
frank26080115 0:bf7b9fba3924 142 {
frank26080115 0:bf7b9fba3924 143 _DBG_(menu);
frank26080115 0:bf7b9fba3924 144 }
frank26080115 0:bf7b9fba3924 145
frank26080115 0:bf7b9fba3924 146 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 147 * @brief Compare two message
frank26080115 0:bf7b9fba3924 148 * @param[in] Tx_Msg transmit message
frank26080115 0:bf7b9fba3924 149 * @param[in] Rx_Msg receive message
frank26080115 0:bf7b9fba3924 150 * @return Bool should be:
frank26080115 0:bf7b9fba3924 151 * - TRUE: if two message is the same
frank26080115 0:bf7b9fba3924 152 * - FALSE: if two message is different
frank26080115 0:bf7b9fba3924 153 **********************************************************************/
frank26080115 0:bf7b9fba3924 154 Bool Check_Message(CAN_MSG_Type* TX_Msg, CAN_MSG_Type* RX_Msg)
frank26080115 0:bf7b9fba3924 155 {
frank26080115 0:bf7b9fba3924 156 uint8_t i;
frank26080115 0:bf7b9fba3924 157 if((TXMsg.format != RXMsg.format)|(TXMsg.id != RXMsg.id)|(TXMsg.len != RXMsg.len)\
frank26080115 0:bf7b9fba3924 158 |(TXMsg.type != RXMsg.type))
frank26080115 0:bf7b9fba3924 159 return FALSE;
frank26080115 0:bf7b9fba3924 160 for(i=0;i<4;i++)
frank26080115 0:bf7b9fba3924 161 {
frank26080115 0:bf7b9fba3924 162 if((TXMsg.dataA[i]!=RXMsg.dataA[i])|(TXMsg.dataB[i]!=RXMsg.dataB[i]))
frank26080115 0:bf7b9fba3924 163 return FALSE;
frank26080115 0:bf7b9fba3924 164 }
frank26080115 0:bf7b9fba3924 165 return TRUE;
frank26080115 0:bf7b9fba3924 166 }
frank26080115 0:bf7b9fba3924 167 /*-------------------------MAIN FUNCTION------------------------------*/
frank26080115 0:bf7b9fba3924 168 /*********************************************************************//**
frank26080115 0:bf7b9fba3924 169 * @brief c_entry: Main CAN program body
frank26080115 0:bf7b9fba3924 170 * @param[in] none
frank26080115 0:bf7b9fba3924 171 * @return int
frank26080115 0:bf7b9fba3924 172 **********************************************************************/
frank26080115 0:bf7b9fba3924 173 int c_entry(void) { /* Main Program */
frank26080115 0:bf7b9fba3924 174
frank26080115 0:bf7b9fba3924 175 /* Initialize debug via UART0
frank26080115 0:bf7b9fba3924 176 * – 115200bps
frank26080115 0:bf7b9fba3924 177 * – 8 data bit
frank26080115 0:bf7b9fba3924 178 * – No parity
frank26080115 0:bf7b9fba3924 179 * – 1 stop bit
frank26080115 0:bf7b9fba3924 180 * – No flow control
frank26080115 0:bf7b9fba3924 181 */
frank26080115 0:bf7b9fba3924 182 debug_frmwrk_init();
frank26080115 0:bf7b9fba3924 183 print_menu();
frank26080115 0:bf7b9fba3924 184
frank26080115 0:bf7b9fba3924 185 /* Initialize CAN1 peripheral
frank26080115 0:bf7b9fba3924 186 * Note: Self-test mode doesn't require pin selection
frank26080115 0:bf7b9fba3924 187 */
frank26080115 0:bf7b9fba3924 188 CAN_Init(LPC_CAN1, 125000);
frank26080115 0:bf7b9fba3924 189
frank26080115 0:bf7b9fba3924 190 //Enable self-test mode
frank26080115 0:bf7b9fba3924 191 CAN_ModeConfig(LPC_CAN1, CAN_SELFTEST_MODE, ENABLE);
frank26080115 0:bf7b9fba3924 192
frank26080115 0:bf7b9fba3924 193 //Enable Interrupt
frank26080115 0:bf7b9fba3924 194 CAN_IRQCmd(LPC_CAN1, CANINT_RIE, ENABLE);
frank26080115 0:bf7b9fba3924 195 CAN_IRQCmd(LPC_CAN1, CANINT_TIE1, ENABLE);
frank26080115 0:bf7b9fba3924 196
frank26080115 0:bf7b9fba3924 197 //Enable CAN Interrupt
frank26080115 0:bf7b9fba3924 198 NVIC_EnableIRQ(CAN_IRQn);
frank26080115 0:bf7b9fba3924 199 CAN_SetAFMode(LPC_CANAF,CAN_AccBP);
frank26080115 0:bf7b9fba3924 200 CAN_InitMessage();
frank26080115 0:bf7b9fba3924 201 _DBG_("Transmitted buffer:");
frank26080115 0:bf7b9fba3924 202 PrintMessage(&TXMsg);
frank26080115 0:bf7b9fba3924 203
frank26080115 0:bf7b9fba3924 204 /** To test Bypass Mode: we send infinite messages to CAN2 and check
frank26080115 0:bf7b9fba3924 205 * receive process via COM1
frank26080115 0:bf7b9fba3924 206 */
frank26080115 0:bf7b9fba3924 207 CAN_SendMsg(LPC_CAN1, &TXMsg);
frank26080115 0:bf7b9fba3924 208 LPC_CAN1->CMR |=(1<<4); //Self Reception Request
frank26080115 0:bf7b9fba3924 209
frank26080115 0:bf7b9fba3924 210 while (1);
frank26080115 0:bf7b9fba3924 211 }
frank26080115 0:bf7b9fba3924 212
frank26080115 0:bf7b9fba3924 213 /* With ARM and GHS toolsets, the entry point is main() - this will
frank26080115 0:bf7b9fba3924 214 allow the linker to generate wrapper code to setup stacks, allocate
frank26080115 0:bf7b9fba3924 215 heap area, and initialize and copy code and data segments. For GNU
frank26080115 0:bf7b9fba3924 216 toolsets, the entry point is through __start() in the crt0_gnu.asm
frank26080115 0:bf7b9fba3924 217 file, and that startup code will setup stacks and data */
frank26080115 0:bf7b9fba3924 218 int main(void) {
frank26080115 0:bf7b9fba3924 219 return c_entry();
frank26080115 0:bf7b9fba3924 220 }
frank26080115 0:bf7b9fba3924 221
frank26080115 0:bf7b9fba3924 222 #ifdef DEBUG
frank26080115 0:bf7b9fba3924 223 /*******************************************************************************
frank26080115 0:bf7b9fba3924 224 * @brief Reports the name of the source file and the source line number
frank26080115 0:bf7b9fba3924 225 * where the CHECK_PARAM error has occurred.
frank26080115 0:bf7b9fba3924 226 * @param[in] file Pointer to the source file name
frank26080115 0:bf7b9fba3924 227 * @param[in] line assert_param error line source number
frank26080115 0:bf7b9fba3924 228 * @return None
frank26080115 0:bf7b9fba3924 229 *******************************************************************************/
frank26080115 0:bf7b9fba3924 230 void check_failed(uint8_t *file, uint32_t line) {
frank26080115 0:bf7b9fba3924 231 /* User can add his own implementation to report the file name and line number,
frank26080115 0:bf7b9fba3924 232 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
frank26080115 0:bf7b9fba3924 233
frank26080115 0:bf7b9fba3924 234 /* Infinite loop */
frank26080115 0:bf7b9fba3924 235 while (1)
frank26080115 0:bf7b9fba3924 236 ;
frank26080115 0:bf7b9fba3924 237 }
frank26080115 0:bf7b9fba3924 238 #endif
frank26080115 0:bf7b9fba3924 239
frank26080115 0:bf7b9fba3924 240 /*
frank26080115 0:bf7b9fba3924 241 * @}
frank26080115 0:bf7b9fba3924 242 */