A board support package for the LPC4088 Display Module.

Dependencies:   DM_HttpServer DM_USBHost

Dependents:   lpc4088_displaymodule_emwin lpc4088_displaymodule_demo_sphere sampleGUI sampleEmptyGUI ... more

Fork of DMSupport by EmbeddedArtists AB

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers <title>crc.cpp Source File</title>

crc.cpp

00001 /*
00002  *  Copyright 2014 Embedded Artists AB
00003  *
00004  *  Licensed under the Apache License, Version 2.0 (the "License");
00005  *  you may not use this file except in compliance with the License.
00006  *  You may obtain a copy of the License at
00007  *
00008  *    http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  *  Unless required by applicable law or agreed to in writing, software
00011  *  distributed under the License is distributed on an "AS IS" BASIS,
00012  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  *  See the License for the specific language governing permissions and
00014  *  limitations under the License.
00015  */
00016  
00017 
00018 /******************************************************************************
00019  * Includes
00020  *****************************************************************************/
00021 
00022 #include "mbed.h"
00023 #include "crc.h"
00024 
00025 
00026 /******************************************************************************
00027  * Defines and typedefs
00028  *****************************************************************************/
00029 
00030 #define NUM_CRC_BUFF_ENTRIES  (100)
00031 
00032 #define CRC32_INIT()  do { LPC_CRC->MODE = 0x00000036; LPC_CRC->SEED = 0xffffffff; } while(0)
00033 
00034 #define CRC32_WRITE8(__val)   LPC_CRC->WR_DATA_BYTE.DATA = (uint8_t)(__val)
00035 #define CRC32_WRITE16(__val)  LPC_CRC->WR_DATA_WORD.DATA = (uint16_t)(__val)
00036 #define CRC32_WRITE32(__val)  LPC_CRC->WR_DATA_DWORD.DATA = (__val)
00037 
00038 #define CRC32_SUM()           LPC_CRC->SUM
00039 
00040 /******************************************************************************
00041  * External global variables
00042  *****************************************************************************/
00043 
00044 /******************************************************************************
00045  * Local variables
00046  *****************************************************************************/
00047 
00048 /******************************************************************************
00049  * Local Functions
00050  *****************************************************************************/
00051 
00052 
00053 /******************************************************************************
00054  * Public Functions
00055  *****************************************************************************/
00056 
00057 uint32_t crc_File(FILE* f)
00058 {
00059   uint32_t* buff = (uint32_t*)malloc(sizeof(uint32_t)*NUM_CRC_BUFF_ENTRIES);
00060   if (buff != NULL) {
00061     CRC32_INIT();
00062     fseek(f, 0, SEEK_SET);
00063     memset(buff, 0, sizeof(uint32_t)*NUM_CRC_BUFF_ENTRIES);
00064     int numRead = fread(buff, sizeof(uint32_t), NUM_CRC_BUFF_ENTRIES, f);
00065     while (numRead > 0) {
00066       for (int i = 0; i < numRead; i++) {
00067         CRC32_WRITE32(buff[i]);
00068       }
00069       numRead = fread(buff, sizeof(uint32_t), NUM_CRC_BUFF_ENTRIES, f);
00070     }
00071     free(buff);
00072     return CRC32_SUM();
00073   }
00074   return 0;
00075 }
00076 
00077 uint32_t crc_Buffer(const uint32_t* data, uint32_t size)
00078 {
00079   CRC32_INIT();
00080   for (uint32_t i = 0; i < size; i++) {
00081     CRC32_WRITE32(data[i]);
00082   }
00083   return CRC32_SUM();
00084 }
00085