/*---------------------------------------------------------------------------*/ static void set_rime_addr(void) { uint8_t *addr_long = NULL; uint16_t addr_short = 0; char i; __xdata unsigned char * macp = &X_IEEE_ADDR; PUTSTRING("Rime is 0x"); PUTHEX(sizeof(rimeaddr_t)); PUTSTRING(" bytes long\n"); PUTSTRING("Reading MAC from Info Page\n"); for(i = (RIMEADDR_SIZE - 1); i >= 0; --i) { rimeaddr_node_addr.u8[i] = *macp; macp++; } /* Now the address is stored MSB first */ #if STARTUP_VERBOSE PUTSTRING("Rime configured with address "); for(i = 0; i < RIMEADDR_SIZE - 1; i++) { PUTHEX(rimeaddr_node_addr.u8[i]); PUTCHAR(':'); } PUTHEX(rimeaddr_node_addr.u8[i]); PUTCHAR('\n'); #endif cc2530_rf_set_addr(IEEE802154_PANID); }
void PSDataColorSeparate(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc) { uint32 row; int breaklen = MAXLINE, cc, s, maxs; unsigned char *tf_buf; unsigned char *cp, c; (void) w; tf_buf = (unsigned char *) _TIFFmalloc(tf_bytesperrow); if (tf_buf == NULL) { TIFFError(filename, "No space for scanline buffer"); return; } maxs = (samplesperpixel > nc ? nc : samplesperpixel); for (row = 0; row < h; row++) { for (s = 0; s < maxs; s++) { if (TIFFReadScanline(tif, tf_buf, row, s) < 0) break; for (cp = tf_buf, cc = 0; cc < tf_bytesperrow; cc++) { DOBREAK(breaklen, 1, fd); c = *cp++; PUTHEX(c,fd); } } } _TIFFfree((char *) tf_buf); }
void PSDataColorContig(FILE* fd, TIFF* tif, uint32 w, uint32 h, int nc) { uint32 row; int breaklen = MAXLINE, cc, es = samplesperpixel - nc; unsigned char *tf_buf; unsigned char *cp, c; (void) w; tf_buf = (unsigned char *) _TIFFmalloc(tf_bytesperrow); if (tf_buf == NULL) { TIFFError(filename, "No space for scanline buffer"); return; } for (row = 0; row < h; row++) { if (TIFFReadScanline(tif, tf_buf, row, 0) < 0) break; cp = tf_buf; if (alpha) { int adjust; cc = 0; for (; cc < tf_bytesperrow; cc += samplesperpixel) { DOBREAK(breaklen, nc, fd); /* * For images with alpha, matte against * a white background; i.e. * Cback * (1 - Aimage) * where Cback = 1. */ adjust = 255 - cp[nc]; switch (nc) { case 4: c = *cp++ + adjust; PUTHEX(c,fd); case 3: c = *cp++ + adjust; PUTHEX(c,fd); case 2: c = *cp++ + adjust; PUTHEX(c,fd); case 1: c = *cp++ + adjust; PUTHEX(c,fd); } cp += es; } } else { cc = 0; for (; cc < tf_bytesperrow; cc += samplesperpixel) { DOBREAK(breaklen, nc, fd); switch (nc) { case 4: c = *cp++; PUTHEX(c,fd); case 3: c = *cp++; PUTHEX(c,fd); case 2: c = *cp++; PUTHEX(c,fd); case 1: c = *cp++; PUTHEX(c,fd); } cp += es; } } } _TIFFfree((char *) tf_buf); }
/*---------------------------------------------------------------------------*/ static void set_rime_addr(void) { uint8_t *addr_long = NULL; uint16_t addr_short = 0; int8_t i; #ifdef SDCC __xdata unsigned char * macp = &X_IEEE_ADDR; #else volatile unsigned char * macp = &X_IEEE_ADDR; // IEEE地址 位于XDATA 780C #endif PUTSTRING("Rime is 0x"); PUTHEX(sizeof(rimeaddr_t)); PUTSTRING(" bytes long\r\n"); PUTSTRING("Reading MAC from Info Page\r\n"); // 从INFO中取MAC地址, for(i = (RIMEADDR_SIZE - 1); i >= 0; --i) { rimeaddr_node_addr.u8[i] = *macp; macp++; } /* Now the address is stored MSB first */ #if STARTUP_VERBOSE // 显示MAC地址 PUTSTRING("Rime configured with address "); for(i = 0; i < RIMEADDR_SIZE - 1; i++) { PUTHEX(rimeaddr_node_addr.u8[i]); PUTCHAR(':'); } PUTHEX(rimeaddr_node_addr.u8[i]); PUTCHAR('\r');PUTCHAR('\n'); PUTSTRING("**************************************\r\n"); #endif cc2530_rf_set_addr(IEEE802154_PANID); // 设置PANID }
/*---------------------------------------------------------------------------*/ static int prepare(const void *payload, unsigned short payload_len) { uint8_t i; PUTSTRING("RF: Prepare 0x"); PUTHEX(payload_len + CHECKSUM_LEN); PUTSTRING(" bytes\n"); /* * When we transmit in very quick bursts, make sure previous transmission * is not still in progress before re-writing to the TX FIFO */ while(FSMSTAT1 & FSMSTAT1_TX_ACTIVE); if((rf_flags & RX_ACTIVE) == 0) { on(); } CC2530_CSP_ISFLUSHTX(); PUTSTRING("RF: data = "); /* Send the phy length byte first */ RFD = payload_len + CHECKSUM_LEN; /* Payload plus FCS */ for(i = 0; i < payload_len; i++) { RFD = ((unsigned char*) (payload))[i]; PUTHEX(((unsigned char*)(payload))[i]); } PUTSTRING("\n"); /* Leave space for the FCS */ RFD = 0; RFD = 0; return 0; }
/*---------------------------------------------------------------------------*/ static int read(void *buf, unsigned short bufsize) { uint8_t i; uint8_t len; uint8_t crc_corr; int8_t rssi; PUTSTRING("RF: Read\n"); /* Check the length */ len = RFD; /* Check for validity */ if(len > CC2530_RF_MAX_PACKET_LEN) { /* Oops, we must be out of sync. */ PUTSTRING("RF: bad sync\n"); RIMESTATS_ADD(badsynch); CC2530_CSP_ISFLUSHRX(); return 0; } if(len <= CC2530_RF_MIN_PACKET_LEN) { PUTSTRING("RF: too short\n"); RIMESTATS_ADD(tooshort); CC2530_CSP_ISFLUSHRX(); return 0; } if(len - CHECKSUM_LEN > bufsize) { PUTSTRING("RF: too long\n"); RIMESTATS_ADD(toolong); CC2530_CSP_ISFLUSHRX(); return 0; } #if CC2530_RF_CONF_HEXDUMP /* If we reach here, chances are the FIFO is holding a valid frame */ uart0_writeb(magic[0]); uart0_writeb(magic[1]); uart0_writeb(magic[2]); uart0_writeb(magic[3]); uart0_writeb(len); #endif RF_RX_LED_ON(); PUTSTRING("RF: read (0x"); PUTHEX(len); PUTSTRING(" bytes) = "); len -= CHECKSUM_LEN; for(i = 0; i < len; ++i) { ((unsigned char*)(buf))[i] = RFD; #if CC2530_RF_CONF_HEXDUMP uart0_writeb(((unsigned char*)(buf))[i]); #endif PUTHEX(((unsigned char*)(buf))[i]); } PUTSTRING("\n"); /* Read the RSSI and CRC/Corr bytes */ rssi = ((int8_t) RFD) - 45; crc_corr = RFD; #if CC2530_RF_CONF_HEXDUMP uart0_writeb(rssi); uart0_writeb(crc_corr); #endif /* MS bit CRC OK/Not OK, 7 LS Bits, Correlation value */ if(crc_corr & CRC_BIT_MASK) { packetbuf_set_attr(PACKETBUF_ATTR_RSSI, rssi); packetbuf_set_attr(PACKETBUF_ATTR_LINK_QUALITY, crc_corr & LQI_BIT_MASK); RIMESTATS_ADD(llrx); } else { RIMESTATS_ADD(badcrc); CC2530_CSP_ISFLUSHRX(); RF_RX_LED_OFF(); return 0; } /* If FIFOP==1 and FIFO==0 then we had a FIFO overflow at some point. */ if((FSMSTAT1 & (FSMSTAT1_FIFO | FSMSTAT1_FIFOP)) == FSMSTAT1_FIFOP) { /* * If we reach here means that there might be more intact packets in the * FIFO despite the overflow. This can happen with bursts of small packets. * * Only flush if the FIFO is actually empty. If not, then next pass we will * pick up one more packet or flush due to an error. */ if(!RXFIFOCNT) { CC2530_CSP_ISFLUSHRX(); } } RF_RX_LED_OFF(); return (len); }
/*---------------------------------------------------------------------------*/ static void set_rime_addr(void) { uint8_t *addr_long = NULL; uint16_t addr_short = 0; char i; #if SHORTCUTS_CONF_FLASH_READ __code unsigned char * macp; #else static uint8_t ft_buffer[8]; #endif PUTSTRING("Rime is 0x"); PUTHEX(sizeof(rimeaddr_t)); PUTSTRING(" bytes long\n"); if(node_id == 0) { PUTSTRING("Reading MAC from flash\n"); #if SHORTCUTS_CONF_FLASH_READ /* * The MAC is always stored in 0x1FFF8 of our flash. This maps to address * 0xFFF8 of our CODE segment, when BANK3 is selected. * Switch to BANK3, read 8 bytes starting at 0xFFF8 and restore last BANK * Since we are called from main(), this MUST be BANK1 or something is very * wrong. This code can be used even without banking */ /* Don't interrupt us to make sure no BANK switching happens while working */ DISABLE_INTERRUPTS(); /* Switch to BANK3, map CODE: 0x8000 – 0xFFFF to FLASH: 0x18000 – 0x1FFFF */ FMAP = 3; /* Set our pointer to the correct address and fetch 8 bytes of MAC */ macp = (__code unsigned char *) 0xFFF8; for(i = (RIMEADDR_SIZE - 1); i >= 0; --i) { rimeaddr_node_addr.u8[i] = *macp; macp++; } /* Remap 0x8000 – 0xFFFF to BANK1 */ FMAP = 1; ENABLE_INTERRUPTS(); #else /* * Or use the more generic flash_read() routine which can read from any * address of our flash */ flash_read(ft_buffer, 0x1FFF8, 8); /* Flip the byte order and store MSB first */ for(i = (RIMEADDR_SIZE - 1); i >= 0; --i) { rimeaddr_node_addr.u8[RIMEADDR_SIZE - 1 - i] = ft_buffer[i]; } #endif } else { PUTSTRING("Setting manual address from node_id\n"); rimeaddr_node_addr.u8[RIMEADDR_SIZE - 1] = node_id >> 8; rimeaddr_node_addr.u8[RIMEADDR_SIZE - 2] = node_id & 0xff; } /* Now the address is stored MSB first */ #if STARTUP_VERBOSE PUTSTRING("Rime configured with address "); for(i = 0; i < RIMEADDR_SIZE - 1; i++) { PUTHEX(rimeaddr_node_addr.u8[i]); PUTCHAR(':'); } PUTHEX(rimeaddr_node_addr.u8[i]); PUTCHAR('\n'); #endif /* Set the cc2430 RF addresses */ #if (RIMEADDR_SIZE==8) addr_short = (rimeaddr_node_addr.u8[6] * 256) + rimeaddr_node_addr.u8[7]; addr_long = (uint8_t *) &rimeaddr_node_addr; #else addr_short = (rimeaddr_node_addr.u8[0] * 256) + rimeaddr_node_addr.u8[1]; #endif cc2430_rf_set_addr(IEEE802154_PANID, addr_short, addr_long); }
void PSRawDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h) { uint32 *bc; uint32 bufsize; int breaklen = MAXLINE, cc; uint16 fillorder; unsigned char *tf_buf; unsigned char *cp, c; tstrip_t s; #if defined( EXP_ASCII85ENCODER ) int ascii85_l; /* Length, in bytes, of ascii85_p[] data */ uint8 * ascii85_p = 0; /* Holds ASCII85 encoded data */ #endif (void) w; (void) h; TIFFGetFieldDefaulted(tif, TIFFTAG_FILLORDER, &fillorder); TIFFGetField(tif, TIFFTAG_STRIPBYTECOUNTS, &bc); /* * Find largest strip: */ bufsize = bc[0]; for ( s = 0; ++s < tf_numberstrips; ) { if ( bc[s] > bufsize ) bufsize = bc[s]; } tf_buf = (unsigned char*) _TIFFmalloc(bufsize); if (tf_buf == NULL) { TIFFError(filename, "No space for strip buffer"); return; } #if defined( EXP_ASCII85ENCODER ) if ( ascii85 ) { /* * Allocate a buffer to hold the ASCII85 encoded data. Note * that it is allocated with sufficient room to hold the * encoded data (5*bufsize/4) plus the EOD marker (+8) * and formatting line breaks. The line breaks are more * than taken care of by using 6*bufsize/4 rather than * 5*bufsize/4. */ ascii85_p = _TIFFmalloc( (bufsize+(bufsize/2)) + 8 ); if ( !ascii85_p ) { _TIFFfree( tf_buf ); TIFFError( filename, "Cannot allocate ASCII85 encoding buffer." ); return; } } #endif for (s = 0; s < tf_numberstrips; s++) { cc = TIFFReadRawStrip(tif, s, tf_buf, bc[s]); if (cc < 0) { TIFFError(filename, "Can't read strip"); break; } if (fillorder == FILLORDER_LSB2MSB) TIFFReverseBits(tf_buf, cc); if (!ascii85) { for (cp = tf_buf; cc > 0; cc--) { DOBREAK(breaklen, 1, fd); c = *cp++; PUTHEX(c, fd); } fputs(">\n", fd); breaklen = MAXLINE; } else { Ascii85Init(); #if defined( EXP_ASCII85ENCODER ) ascii85_l = Ascii85EncodeBlock( ascii85_p, 1, tf_buf, cc ); if ( ascii85_l > 0 ) fwrite( ascii85_p, ascii85_l, 1, fd ); #else for (cp = tf_buf; cc > 0; cc--) Ascii85Put(*cp++, fd); Ascii85Flush(fd); #endif /* EXP_ASCII85ENCODER */ } } _TIFFfree((char *) tf_buf); #if defined( EXP_ASCII85ENCODER ) if ( ascii85_p ) _TIFFfree( ascii85_p ); #endif }
void PSDataBW(FILE* fd, TIFF* tif, uint32 w, uint32 h) { int breaklen = MAXLINE; unsigned char* tf_buf; unsigned char* cp; tsize_t stripsize = TIFFStripSize(tif); tstrip_t s; #if defined( EXP_ASCII85ENCODER ) int ascii85_l; /* Length, in bytes, of ascii85_p[] data */ uint8 * ascii85_p = 0; /* Holds ASCII85 encoded data */ #endif (void) w; (void) h; tf_buf = (unsigned char *) _TIFFmalloc(stripsize); if (tf_buf == NULL) { TIFFError(filename, "No space for scanline buffer"); return; } #if defined( EXP_ASCII85ENCODER ) if ( ascii85 ) { /* * Allocate a buffer to hold the ASCII85 encoded data. Note * that it is allocated with sufficient room to hold the * encoded data (5*stripsize/4) plus the EOD marker (+8) * and formatting line breaks. The line breaks are more * than taken care of by using 6*stripsize/4 rather than * 5*stripsize/4. */ ascii85_p = _TIFFmalloc( (stripsize+(stripsize/2)) + 8 ); if ( !ascii85_p ) { _TIFFfree( tf_buf ); TIFFError( filename, "Cannot allocate ASCII85 encoding buffer." ); return; } } #endif if (ascii85) Ascii85Init(); for (s = 0; s < TIFFNumberOfStrips(tif); s++) { int cc = TIFFReadEncodedStrip(tif, s, tf_buf, stripsize); if (cc < 0) { TIFFError(filename, "Can't read strip"); break; } cp = tf_buf; if (photometric == PHOTOMETRIC_MINISWHITE) { for (cp += cc; --cp >= tf_buf;) *cp = ~*cp; cp++; } if (ascii85) { #if defined( EXP_ASCII85ENCODER ) ascii85_l = Ascii85EncodeBlock( ascii85_p, 1, cp, cc ); if ( ascii85_l > 0 ) fwrite( ascii85_p, ascii85_l, 1, fd ); #else while (cc-- > 0) Ascii85Put(*cp++, fd); #endif /* EXP_ASCII85_ENCODER */ } else { while (cc-- > 0) { unsigned char c = *cp++; DOBREAK(breaklen, 1, fd); PUTHEX(c, fd); } } } if ( !ascii85 ) { if ( level2 ) fputs(">\n", fd); } #if !defined( EXP_ASCII85ENCODER ) else Ascii85Flush(fd); #else if ( ascii85_p ) _TIFFfree( ascii85_p ); #endif _TIFFfree(tf_buf); }