Program C Ansi Programming Embedded Systems in C and C++ phần 5

Tham khảo tài liệu 'program c ansi programming embedded systems in c and c++ phần 5', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | Function crcInit Description Initialize the CRC lookup table. This table is used by crcCompute to make CRC computation faster. Notes The mod-2 binary long division is implemented here. Returns None defined. void crcInit void width remainder width dividend int bit Perform binary long division a bit at a time. for dividend 0 dividend 256 dividend Initialize the remainder. remainder dividend WIDTH - 8 Shift and XOR with the polynomial. for bit 0 bit 8 bit Try to divide the current data bit. if remainder TOPBIT remainder remainder 1 A POLYNOMIAL else remainder remainder 1 Save the result in the table. crcTable dividend remainder crcInit Finally we arrive at the actual workhorse routine crcCompute. This is a routine that you can call over and over from your application to compute and verify CRC checksums. An additional benefit of splitting the computation between crcInit and crcCompute is that the crcInit function need not be executed on the embedded system. Instead this function can be run in advance-on any computer-to produce the contents of the lookup table. The values in the table can then be stored in ROM requiring only 256 bytes of storage and referenced over and over by crcCompute. Function crcCompute Description Compute the CRC checksum of a binary message block. Notes This function expects that crcInit has been called first to initialize the CRC lookup table. Returns The CRC of the data. width crcCompute unsigned char message unsigned int nBytes unsigned int offset unsigned char byte width remainder INITIAL_REMAINDER Divide the message by the polynomial a byte at a time. for offset 0 offset nBytes offset byte remainder WIDTH - 8 A message offset remainder crcTable byte A remainder 8 The final remainder is the CRC result. return remainder A FINAL_XOR_VALUE crcCompute Working with Flash Memory From the programmer s viewpoint Flash is arguably the most complicated memory device ever invented. The hardware interface has improved somewhat since the original .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
172    74    4    29-04-2024
1    83    1    29-04-2024
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.