void setPWM(uint8_t counter, uint8_t compare) { void* tcfg0 = get_addr(TCFG0); void* v_tcntb0 = tcfg0 + (TCNTB0 & MAP_MASK); void* v_tcmpb0 = tcfg0 + (TCMPB0 & MAP_MASK); *(REG v_tcntb0) = counter; *(REG v_tcmpb0) = compare; release_addr(tcfg0); }
static void verify_checksum (int argc, char *argv[]) { void *addr = NULL; char *bp, *ep; logChecksum *master, *checksums; unsigned short mcsum; int num_pages; if (argc != 1) { printf ("-ERR usage: vc <file>\n"); return; } addr = get_addr (argv[0]); if (addr == NULL) { return; } /* set up pointers */ bp = (char *) addr; ep = bp + SMR_LOG_FILE_DATA_SIZE; master = (logChecksum *) ep; checksums = master + 1; if (is_finalized (master)) { num_pages = SMR_LOG_NUM_CHECKSUM - 1; } else { num_pages = master->off; } printf ("num_pages:%d\n", num_pages); mcsum = crc16 ((char *) checksums, sizeof (logChecksum) * num_pages, 0); if (mcsum != master->checksum) { printf ("master checksum error. expected:0x%4x master:0x%4x\n", mcsum, master->checksum); } else { printf ("+OK checksum verified. 0x%4x\n", mcsum); } if (addr) { release_addr (addr); } }
static void bootp_reply(struct bootp_t *bp) { BOOTPClient *bc; struct mbuf *m; struct bootp_t *rbp; struct sockaddr_in saddr, daddr; struct in_addr dns_addr; int dhcp_msg_type, val; uint8_t *q; int freply_nack = 0; /* extract exact DHCP msg type */ dhcp_decode(bp->bp_vend, DHCP_OPT_LEN, &dhcp_msg_type); dprintf("bootp packet op=%d msgtype=%d\n", bp->bp_op, dhcp_msg_type); if (dhcp_msg_type == 0) dhcp_msg_type = DHCPREQUEST; /* Force reply for old BOOTP clients */ if (dhcp_msg_type == DHCPRELEASE) { release_addr(&bp->bp_ciaddr); dprintf("released addr=%08lx\n", ntohl(bp->bp_ciaddr.s_addr)); /* This message is not to be answered in any way. */ return; } if (dhcp_msg_type != DHCPDISCOVER && dhcp_msg_type != DHCPREQUEST) return; /* XXX: this is a hack to get the client mac address */ memcpy(client_ethaddr, bp->bp_hwaddr, 6); if ((m = m_get()) == NULL) return; m->m_data += if_maxlinkhdr; rbp = (struct bootp_t *)m->m_data; m->m_data += sizeof(struct udpiphdr); memset(rbp, 0, sizeof(struct bootp_t)); if (dhcp_msg_type == DHCPDISCOVER) { bc = get_new_addr(&daddr.sin_addr); if (!bc) { dprintf("no address left\n"); return; } memcpy(bc->macaddr, client_ethaddr, 6); } else { bc = find_addr(&daddr.sin_addr, bp->bp_hwaddr); if (!bc) { /* if never assigned, reply DHCPNACK to BROADCAST. (windows fix because it remembers its address). */ daddr.sin_addr.s_addr = htonl(0xffffffff); freply_nack = 1; dprintf("reply NACK\n"); } } dprintf("offered addr=%08lx\n", ntohl(daddr.sin_addr.s_addr)); saddr.sin_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS); saddr.sin_port = htons(BOOTP_SERVER); daddr.sin_port = htons(BOOTP_CLIENT); rbp->bp_op = BOOTP_REPLY; rbp->bp_xid = bp->bp_xid; rbp->bp_htype = 1; rbp->bp_hlen = 6; memcpy(rbp->bp_hwaddr, bp->bp_hwaddr, 6); if (freply_nack) rbp->bp_yiaddr.s_addr = htonl(0); /* When NACK, IP address is 0. */ else rbp->bp_yiaddr = daddr.sin_addr; /* Client IP address */ rbp->bp_siaddr = saddr.sin_addr; /* Server IP address */ q = rbp->bp_vend; memcpy(q, rfc1533_cookie, 4); q += 4; if (dhcp_msg_type == DHCPDISCOVER) { *q++ = RFC2132_MSG_TYPE; *q++ = 1; *q++ = DHCPOFFER; } else if (dhcp_msg_type == DHCPREQUEST) { *q++ = RFC2132_MSG_TYPE; *q++ = 1; if (freply_nack) *q++ = DHCPNACK; else *q++ = DHCPACK; } if (dhcp_msg_type == DHCPDISCOVER || ((dhcp_msg_type == DHCPREQUEST) && !freply_nack)) { *q++ = RFC2132_SRV_ID; *q++ = 4; memcpy(q, &saddr.sin_addr, 4); q += 4; *q++ = RFC1533_NETMASK; *q++ = 4; *q++ = 0xff; *q++ = 0xff; *q++ = 0xff; *q++ = 0x00; *q++ = RFC1533_GATEWAY; *q++ = 4; memcpy(q, &saddr.sin_addr, 4); q += 4; *q++ = RFC1533_DNS; *q++ = 4; dns_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_DNS); memcpy(q, &dns_addr, 4); q += 4; *q++ = RFC2132_LEASE_TIME; *q++ = 4; val = htonl(LEASE_TIME); memcpy(q, &val, 4); q += 4; if (*slirp_hostname) { val = strlen(slirp_hostname); *q++ = RFC1533_HOSTNAME; *q++ = val; memcpy(q, slirp_hostname, val); q += val; } } *q++ = RFC1533_END; m->m_len = sizeof(struct bootp_t) - sizeof(struct ip) - sizeof(struct udphdr); udp_output2(NULL, m, &saddr, &daddr, IPTOS_LOWDELAY); }