Changes to make mx13224 work with Contiki From: Jon Smirl --- .gitignore | 8 apps/ping6/ping6.c | 3 apps/webserver/httpd-cgi.c | 9 apps/webserver/webserver.c | 3 core/net/hc.c | 4 core/net/mac/frame802154.c | 2 core/net/mac/frame802154.h | 8 core/net/mac/lpp.c | 2 core/net/mac/sicslowmac.c | 1 core/net/resolv.c | 2 core/net/rime/collect.c | 10 core/net/rime/mesh.h | 2 core/net/rime/rimeaddr.h | 2 core/net/rime/route-discovery.c | 4 core/net/rime/rudolph0.c | 4 core/net/rime/rudolph1.c | 2 core/net/sicslowpan.c | 6 core/net/sicslowpan.h | 4 core/net/tcpdump.c | 8 core/net/tcpip.c | 2 core/net/uip-fw-drv.c | 2 core/net/uip-icmp6.h | 2 core/net/uip-nd6-io.c | 2 core/net/uip-nd6.c | 2 core/net/uip-nd6.h | 20 - core/net/uip-netif.c | 6 core/net/uip.h | 42 + core/net/uip6.c | 11 cpu/mc1322x/Makefile.mc1322x | 17 - cpu/mc1322x/clock.c | 15 cpu/mc1322x/dbg-io.c | 5 cpu/mc1322x/isr.c | 46 + cpu/mc1322x/isr.h | 16 cpu/mc1322x/maca.c | 714 ++++++++++++--------- cpu/mc1322x/maca.h | 9 cpu/mc1322x/uart1.c | 34 + cpu/mc1322x/utils.h | 8 examples/ping-ipv6/example-ping6.c | 2 examples/rime/Makefile | 6 examples/udp-receiver-ipv6/Makefile.target | 2 examples/udp-receiver-ipv6/example-udp-receiver.c | 3 examples/udp-sender-ipv6/Makefile.target | 2 examples/udp-sender-ipv6/example-udp-sender.c | 2 examples/webserver-ipv6/Makefile.target | 2 examples/webserver-ipv6/webserver6.c | 2 platform/mc1322x/contiki-conf.h | 44 + platform/mc1322x/contiki-mc1322x-main.c | 84 ++ platform/mc1322x/printf-arch.c | 4 48 files changed, 746 insertions(+), 444 deletions(-) diff --git a/.gitignore b/.gitignore index 65a6460..acce90d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,15 @@ *.map *.png *.log +*.bin +*.map +*.png +*.log +*.elf +*.ihex obj_mc1322x symbols.* Makefile.target +doc/html +patches-* diff --git a/apps/ping6/ping6.c b/apps/ping6/ping6.c index 4fdc16a..b76aed3 100644 --- a/apps/ping6/ping6.c +++ b/apps/ping6/ping6.c @@ -63,7 +63,8 @@ uip_ipaddr_t dest_addr; PROCESS(ping6_process, "PING6 process"); AUTOSTART_PROCESSES(&ping6_process); - + +#define scanf(a, b, ...) 0 /*---------------------------------------------------------------------------*/ static u8_t diff --git a/apps/webserver/httpd-cgi.c b/apps/webserver/httpd-cgi.c index d5acebf..4d7c272 100644 --- a/apps/webserver/httpd-cgi.c +++ b/apps/webserver/httpd-cgi.c @@ -138,7 +138,8 @@ static unsigned short generate_file_stats(void *arg) { char *f = (char *)arg; - return snprintf((char *)uip_appdata, uip_mss(), "%5u", httpd_fs_count(f)); + //return snprintf((char *)uip_appdata, uip_mss(), "%5u", httpd_fs_count(f)); + return sprintf((char *)uip_appdata, "%5u", httpd_fs_count(f)); } /*---------------------------------------------------------------------------*/ static @@ -161,7 +162,7 @@ make_tcp_stats(void *arg) #if UIP_CONF_IPV6 char buf[48]; httpd_sprint_ip6(conn->ripaddr, buf); - return snprintf((char *)uip_appdata, uip_mss(), + return sprintf((char *)uip_appdata, "%d%s:%u%s%u%u%c %c\r\n", htons(conn->lport), buf, @@ -172,7 +173,7 @@ make_tcp_stats(void *arg) (uip_outstanding(conn))? '*':' ', (uip_stopped(conn))? '!':' '); #else - return snprintf((char *)uip_appdata, uip_mss(), + return sprintf((char *)uip_appdata, "%d%u.%u.%u.%u:%u%s%u%u%c %c\r\n", htons(conn->lport), conn->ripaddr.u8[0], @@ -211,7 +212,7 @@ make_processes(void *p) strncpy(name, ((struct process *)p)->name, 40); petsciiconv_toascii(name, 40); - return snprintf((char *)uip_appdata, uip_mss(), + return sprintf((char *)uip_appdata, "%p%s%p%s\r\n", p, name, *((char **)&(((struct process *)p)->thread)), diff --git a/apps/webserver/webserver.c b/apps/webserver/webserver.c index f9ee76b..996af87 100644 --- a/apps/webserver/webserver.c +++ b/apps/webserver/webserver.c @@ -98,13 +98,14 @@ webserver_log_file(uip_ipaddr_t *requester, char *file) memcpy(log, &log[LOG_WIDTH], LOG_WIDTH * (LOG_HEIGHT - 1)); /* Print out IP address of requesting host. */ +#if 0 size = sprintf(&log[LOG_WIDTH * (LOG_HEIGHT - 1)], "%d.%d.%d.%d: ", requester->u8[0], requester->u8[1], requester->u8[2], requester->u8[3]); - +#endif /* Copy filename into last line. */ strncpy(&log[LOG_WIDTH * (LOG_HEIGHT - 1) + size], file, LOG_WIDTH - size); diff --git a/core/net/hc.c b/core/net/hc.c index 2526fc5..2133256 100644 --- a/core/net/hc.c +++ b/core/net/hc.c @@ -50,7 +50,7 @@ struct hc_hdr { u16_t flagsport; uip_ipaddr_t srcipaddr; -}; +} __attribute__ ((__packed__)); struct udpip_hdr { /* IP header. */ @@ -69,7 +69,7 @@ struct udpip_hdr { destport; u16_t udplen; u16_t udpchksum; -}; +} __attribute__ ((__packed__)); #include diff --git a/core/net/mac/frame802154.c b/core/net/mac/frame802154.c index 91deff8..f035a5a 100644 --- a/core/net/mac/frame802154.c +++ b/core/net/mac/frame802154.c @@ -76,7 +76,7 @@ typedef struct { uint8_t src_pid_len; /**< Length (in bytes) of source PAN ID field */ uint8_t src_addr_len; /**< Length (in bytes) of source address field */ uint8_t aux_sec_len; /**< Length (in bytes) of aux security header field */ -} field_length_t; +} __attribute__ ((__packed__)) field_length_t; /*----------------------------------------------------------------------------*/ CC_INLINE static uint8_t diff --git a/core/net/mac/frame802154.h b/core/net/mac/frame802154.h index 3680063..cadd5ec 100644 --- a/core/net/mac/frame802154.h +++ b/core/net/mac/frame802154.h @@ -127,21 +127,21 @@ typedef struct { uint8_t dest_addr_mode; /**< 2 bit. Destination address mode, see 802.15.4 */ uint8_t frame_version; /**< 2 bit. 802.15.4 frame version */ uint8_t src_addr_mode; /**< 2 bit. Source address mode, see 802.15.4 */ -} frame802154_fcf_t; +} __attribute__ ((__packed__)) frame802154_fcf_t; /** \brief 802.15.4 security control bitfield. See section 7.6.2.2.1 in 802.15.4 specification */ typedef struct { uint8_t security_level; /**< 3 bit. security level */ uint8_t key_id_mode; /**< 2 bit. Key identifier mode */ uint8_t reserved; /**< 3 bit. Reserved bits */ -} frame802154_scf_t; +} __attribute__ ((__packed__)) frame802154_scf_t; /** \brief 802.15.4 Aux security header */ typedef struct { frame802154_scf_t security_control; /**< Security control bitfield */ uint32_t frame_counter; /**< Frame counter, used for security */ uint8_t key[9]; /**< The key itself, or an index to the key */ -} frame802154_aux_hdr_t; +} __attribute__ ((__packed__)) frame802154_aux_hdr_t; /** \brief Parameters used by the frame802154_create() function. These * parameters are used in the 802.15.4 frame header. See the 802.15.4 @@ -157,7 +157,7 @@ typedef struct { frame802154_aux_hdr_t aux_hdr; /**< Aux security header */ uint8_t *payload; /**< Pointer to 802.15.4 frame payload */ uint8_t payload_len; /**< Length of payload field */ -} frame802154_t; +} __attribute__ ((__packed__)) frame802154_t; /* Prototypes */ diff --git a/core/net/mac/lpp.c b/core/net/mac/lpp.c index ec20124..381325e 100644 --- a/core/net/mac/lpp.c +++ b/core/net/mac/lpp.c @@ -403,7 +403,7 @@ send_probe(void) /* Construct the announcements */ - adata = (struct announcement_msg *)((char *)hdr + sizeof(struct lpp_hdr)); + adata = (struct announcement_msg *)((long *)hdr + sizeof(struct lpp_hdr)/sizeof(long)); adata->num = 0; for(a = announcement_list(); a != NULL; a = a->next) { diff --git a/core/net/mac/sicslowmac.c b/core/net/mac/sicslowmac.c index d9f24dd..17e3241 100644 --- a/core/net/mac/sicslowmac.c +++ b/core/net/mac/sicslowmac.c @@ -150,6 +150,7 @@ send_packet(void) params.payload = packetbuf_dataptr(); params.payload_len = packetbuf_datalen(); + len = frame802154_hdrlen(¶ms); if(packetbuf_hdralloc(len)) { frame802154_create(¶ms, packetbuf_hdrptr(), len); diff --git a/core/net/resolv.c b/core/net/resolv.c index 86bf402..f97968a 100644 --- a/core/net/resolv.c +++ b/core/net/resolv.c @@ -104,7 +104,7 @@ struct dns_answer { u16_t ttl[2]; u16_t len; u16_t ipaddr[2]; -}; +} __attribute__ ((__packed__)); struct namemap { #define STATE_UNUSED 0 diff --git a/core/net/rime/collect.c b/core/net/rime/collect.c index b442423..26e6dbc 100644 --- a/core/net/rime/collect.c +++ b/core/net/rime/collect.c @@ -231,7 +231,7 @@ node_packet_received(struct runicast_conn *c, const rimeaddr_t *from, uint8_t seqno) { struct collect_conn *tc = (struct collect_conn *) - ((char *)c - offsetof(struct collect_conn, runicast_conn)); + ((long *)c - offsetof(struct collect_conn, runicast_conn)/sizeof(long)); int i; /* To protect against forwarding duplicate packets, we keep a list @@ -300,7 +300,7 @@ node_packet_sent(struct runicast_conn *c, const rimeaddr_t *to, uint8_t transmissions) { struct collect_conn *tc = (struct collect_conn *) - ((char *)c - offsetof(struct collect_conn, runicast_conn)); + ((long *)c - offsetof(struct collect_conn, runicast_conn)/sizeof(long)); PRINTF("%d.%d: sent to %d.%d after %d retransmissions\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], @@ -324,7 +324,7 @@ node_packet_timedout(struct runicast_conn *c, const rimeaddr_t *to, uint8_t transmissions) { struct collect_conn *tc = (struct collect_conn *) - ((char *)c - offsetof(struct collect_conn, runicast_conn)); + ((long *)c - offsetof(struct collect_conn, runicast_conn)/sizeof(long)); PRINTF("%d.%d: timedout after %d retransmissions\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], transmissions); @@ -346,7 +346,7 @@ adv_received(struct neighbor_discovery_conn *c, const rimeaddr_t *from, uint16_t rtmetric) { struct collect_conn *tc = (struct collect_conn *) - ((char *)c - offsetof(struct collect_conn, neighbor_discovery_conn)); + ((long *)c - offsetof(struct collect_conn, neighbor_discovery_conn)/sizeof(long)); struct neighbor *n; n = neighbor_find(from); @@ -368,7 +368,7 @@ received_announcement(struct announcement *a, const rimeaddr_t *from, uint16_t id, uint16_t value) { struct collect_conn *tc = (struct collect_conn *) - ((char *)a - offsetof(struct collect_conn, announcement)); + ((long *)a - offsetof(struct collect_conn, announcement)/sizeof(long)); struct neighbor *n; n = neighbor_find(from); diff --git a/core/net/rime/mesh.h b/core/net/rime/mesh.h index a2b4440..51b3179 100644 --- a/core/net/rime/mesh.h +++ b/core/net/rime/mesh.h @@ -86,7 +86,7 @@ struct mesh_conn { struct queuebuf *queued_data; rimeaddr_t queued_data_dest; const struct mesh_callbacks *cb; -}; +} __attribute__ ((__packed__)); /** * \brief Open a mesh connection diff --git a/core/net/rime/rimeaddr.h b/core/net/rime/rimeaddr.h index be2d640..1968508 100644 --- a/core/net/rime/rimeaddr.h +++ b/core/net/rime/rimeaddr.h @@ -65,7 +65,7 @@ typedef union { unsigned char u8[RIMEADDR_SIZE]; -} rimeaddr_t; +} __attribute__ ((__packed__)) rimeaddr_t; /** diff --git a/core/net/rime/route-discovery.c b/core/net/rime/route-discovery.c index ae67f90..c1a8b8b 100644 --- a/core/net/rime/route-discovery.c +++ b/core/net/rime/route-discovery.c @@ -167,7 +167,7 @@ rrep_packet_received(struct unicast_conn *uc, const rimeaddr_t *from) struct route_entry *rt; rimeaddr_t dest; struct route_discovery_conn *c = (struct route_discovery_conn *) - ((char *)uc - offsetof(struct route_discovery_conn, rrepconn)); + ((long *)uc - offsetof(struct route_discovery_conn, rrepconn)); PRINTF("%d.%d: rrep_packet_received from %d.%d towards %d.%d len %d\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], @@ -211,7 +211,7 @@ rreq_packet_received(struct netflood_conn *nf, const rimeaddr_t *from, { struct route_msg *msg = packetbuf_dataptr(); struct route_discovery_conn *c = (struct route_discovery_conn *) - ((char *)nf - offsetof(struct route_discovery_conn, rreqconn)); + ((long *)nf - offsetof(struct route_discovery_conn, rreqconn)); PRINTF("%d.%d: rreq_packet_received from %d.%d hops %d rreq_id %d last %d.%d/%d\n", rimeaddr_node_addr.u8[0], rimeaddr_node_addr.u8[1], diff --git a/core/net/rime/rudolph0.c b/core/net/rime/rudolph0.c index f3fa94e..7a48d99 100644 --- a/core/net/rime/rudolph0.c +++ b/core/net/rime/rudolph0.c @@ -162,8 +162,8 @@ static void recv_nack(struct polite_conn *polite) { struct rudolph0_conn *c = (struct rudolph0_conn *) - ((char *)polite - offsetof(struct rudolph0_conn, - nackc)); + ((long *)polite - offsetof(struct rudolph0_conn, + nackc)/sizeof(long)); struct rudolph0_datapacket *p = packetbuf_dataptr(); if(p->h.type == TYPE_NACK && c->state == STATE_SENDER) { diff --git a/core/net/rime/rudolph1.c b/core/net/rime/rudolph1.c index bf4dcbb..293310e 100644 --- a/core/net/rime/rudolph1.c +++ b/core/net/rime/rudolph1.c @@ -235,7 +235,7 @@ static void recv_ipolite(struct ipolite_conn *ipolite, const rimeaddr_t *from) { struct rudolph1_conn *c = (struct rudolph1_conn *) - ((char *)ipolite - offsetof(struct rudolph1_conn, ipolite)); + ((long *)ipolite - offsetof(struct rudolph1_conn, ipolite)/sizeof(long)); struct rudolph1_datapacket *p = packetbuf_dataptr(); PRINTF("%d.%d: Got ipolite type %d\n", diff --git a/core/net/sicslowpan.c b/core/net/sicslowpan.c index 23053d6..541b6db 100644 --- a/core/net/sicslowpan.c +++ b/core/net/sicslowpan.c @@ -1181,7 +1181,7 @@ output(uip_lladdr_t *localdest) */ /* Create 1st Fragment */ - PRINTFO("sicslowpan output: 1rst fragment "); + PRINTFO("sicslowpan output: first fragment "); /* move HC1/HC01/IPv6 header */ memmove(rime_ptr + SICSLOWPAN_FRAG1_HDR_LEN, rime_ptr, rime_hdr_len); @@ -1221,6 +1221,7 @@ output(uip_lladdr_t *localdest) ((SICSLOWPAN_DISPATCH_FRAGN << 8) | uip_len)); rime_payload_len = (MAC_MAX_PAYLOAD - rime_hdr_len) & 0xf8; while(processed_ip_len < uip_len){ +packetbuf_clear(); PRINTFO("sicslowpan output: fragment "); /* RIME_FRAG_BUF->offset = processed_ip_len >> 3; */ RIME_FRAG_PTR[RIME_FRAG_OFFSET] = processed_ip_len >> 3; @@ -1235,6 +1236,7 @@ output(uip_lladdr_t *localdest) memcpy(rime_ptr + rime_hdr_len, (void *)UIP_IP_BUF + processed_ip_len, rime_payload_len); packetbuf_set_datalen(rime_payload_len + rime_hdr_len); + send_packet(&dest); processed_ip_len += rime_payload_len; } @@ -1443,7 +1445,7 @@ input(const struct mac_driver *r) * the IP stack */ if(processed_ip_len == 0 || (processed_ip_len == sicslowpan_len)){ - PRINTFI("sicslowpan input: IP packet ready (length %d)\n", + PRINTF("sicslowpan input: IP packet ready (length %d)\n", sicslowpan_len); memcpy((void *)UIP_IP_BUF, (void *)SICSLOWPAN_IP_BUF, sicslowpan_len); uip_len = sicslowpan_len; diff --git a/core/net/sicslowpan.h b/core/net/sicslowpan.h index 00344ed..48e0844 100644 --- a/core/net/sicslowpan.h +++ b/core/net/sicslowpan.h @@ -186,7 +186,7 @@ struct sicslowpan_iphc_hdr { u8_t dispatch; u8_t encoding[2]; -}; +} __attribute__ ((__packed__)); /* struct sicslowpan_nhc_udp_comp_hdr { */ /* u8_t nhcid; */ @@ -201,7 +201,7 @@ struct sicslowpan_addr_context { u8_t used; u8_t number; u8_t prefix[8]; -}; +} __attribute__ ((__packed__)); /** * \name Address compressibility test functions diff --git a/core/net/tcpdump.c b/core/net/tcpdump.c index b1675df..cea9486 100644 --- a/core/net/tcpdump.c +++ b/core/net/tcpdump.c @@ -48,7 +48,7 @@ u16_t ipchksum; u8_t srcipaddr[4], destipaddr[4]; - }; + } __attribute__ ((__packed__)); #define TCP_FIN 0x01 #define TCP_SYN 0x02 @@ -81,7 +81,7 @@ struct tcpip_hdr { u16_t tcpchksum; u8_t urgp[2]; u8_t optdata[4]; -}; +} __attribute__ ((__packed__)); #define ICMP_ECHO_REPLY 0 #define ICMP_ECHO 8 @@ -103,7 +103,7 @@ struct icmpip_hdr { u8_t type, icode; u16_t icmpchksum; u16_t id, seqno; -}; +} __attribute__ ((__packed__)); /* The UDP and IP headers. */ @@ -125,7 +125,7 @@ struct udpip_hdr { destport; u16_t udplen; u16_t udpchksum; -}; +} __attribute__ ((__packed__)); #define ETHBUF ((struct eth_hdr *)&packet[0]) #define IPBUF ((struct ip_hdr *)&packet[0]) diff --git a/core/net/tcpip.c b/core/net/tcpip.c index 7bb8f45..2fd2c96 100644 --- a/core/net/tcpip.c +++ b/core/net/tcpip.c @@ -50,7 +50,7 @@ #include "net/uip-netif.h" #endif -#define DEBUG 0 +#define DEBUG 1 #if DEBUG #include #define PRINTF(...) printf(__VA_ARGS__) diff --git a/core/net/uip-fw-drv.c b/core/net/uip-fw-drv.c index f51ecac..0265709 100644 --- a/core/net/uip-fw-drv.c +++ b/core/net/uip-fw-drv.c @@ -42,7 +42,7 @@ PROCESS_THREAD(uip_fw_process, ev, data) { PROCESS_BEGIN(); - tcpip_set_outputfunc(uip_fw_output); + //tcpip_set_outputfunc(uip_fw_output); PROCESS_WAIT_UNTIL(ev == PROCESS_EVENT_EXIT); diff --git a/core/net/uip-icmp6.h b/core/net/uip-icmp6.h index 8ec2599..0972591 100644 --- a/core/net/uip-icmp6.h +++ b/core/net/uip-icmp6.h @@ -98,7 +98,7 @@ /** \brief ICMPv6 Error message constant part */ struct uip_icmp6_error{ u32_t param; -}; +} __attribute__ ((__packed__)); /** \name ICMPv6 RFC4443 Message processing and sending */ /** @{ */ diff --git a/core/net/uip-nd6-io.c b/core/net/uip-nd6-io.c index 16c1447..b926823 100644 --- a/core/net/uip-nd6-io.c +++ b/core/net/uip-nd6-io.c @@ -75,7 +75,7 @@ /*------------------------------------------------------------------*/ -#define DEBUG 0 +#define DEBUG 1 #if DEBUG #include #define PRINTF(...) printf(__VA_ARGS__) diff --git a/core/net/uip-nd6.c b/core/net/uip-nd6.c index 001e931..32b8560 100644 --- a/core/net/uip-nd6.c +++ b/core/net/uip-nd6.c @@ -74,7 +74,7 @@ #include -#define DEBUG 0 +#define DEBUG 1 #if DEBUG #include #define PRINTF(...) printf(__VA_ARGS__) diff --git a/core/net/uip-nd6.h b/core/net/uip-nd6.h index 6f592f0..cf9056b 100644 --- a/core/net/uip-nd6.h +++ b/core/net/uip-nd6.h @@ -235,7 +235,7 @@ extern struct etimer uip_nd6_timer_periodic; struct uip_nd6_ns { u32_t reserved; uip_ipaddr_t tgtipaddr; -}; +} __attribute__ ((__packed__)); /** * \brief A neighbor advertisement constant part. @@ -246,7 +246,7 @@ struct uip_nd6_na { u8_t flagsreserved; u8_t reserved[3]; uip_ipaddr_t tgtipaddr; -}; +} __attribute__ ((__packed__)); /** * \brief A router solicitation constant part @@ -255,7 +255,7 @@ struct uip_nd6_na { */ struct uip_nd6_rs { u32_t reserved; -}; +} __attribute__ ((__packed__)); /** * \brief A router advertisement constant part @@ -268,7 +268,7 @@ struct uip_nd6_ra { u16_t router_lifetime; u32_t reachable_time; u32_t retrans_timer; -}; +} __attribute__ ((__packed__)); /** * \brief A redirect message constant part @@ -279,7 +279,7 @@ struct uip_nd6_redirect { u32_t reserved; uip_ipaddr_t tgtipaddress; uip_ipaddr_t destipaddress; -}; +} __attribute__ ((__packed__)); /** @} */ /** @@ -291,7 +291,7 @@ struct uip_nd6_redirect { struct uip_nd6_opt_hdr { u8_t type; u8_t len; -}; +} __attribute__ ((__packed__)); /** \brief ND option prefix information */ struct uip_nd6_opt_prefix_info { @@ -303,7 +303,7 @@ struct uip_nd6_opt_prefix_info { u32_t preferredlt; u32_t reserved2; uip_ipaddr_t prefix; -}; +} __attribute__ ((__packed__)); /** \brief ND option MTU */ struct uip_nd6_opt_mtu { @@ -311,21 +311,21 @@ struct uip_nd6_opt_mtu { u8_t len; u16_t reserved; u32_t mtu; -}; +} __attribute__ ((__packed__)); /** \brief ND option: both TLLAO and SLLAO */ struct uip_nd6_opt_llao { u8_t type; u8_t len; uip_lladdr_t addr; -}; +} __attribute__ ((__packed__)); /** \struct Redirected header option */ struct uip_nd6_opt_redirected_hdr { u8_t type; u8_t len; u8_t reserved[6]; -}; +} __attribute__ ((__packed__)); /** @} */ /** diff --git a/core/net/uip-netif.c b/core/net/uip-netif.c index bf3106b..abebc1d 100644 --- a/core/net/uip-netif.c +++ b/core/net/uip-netif.c @@ -48,7 +48,7 @@ #include -#define DEBUG 0 +#define DEBUG 1 #if DEBUG #include #define PRINTF(...) printf(__VA_ARGS__) @@ -252,7 +252,7 @@ uip_netif_addr_autoconf_set(uip_ipaddr_t *ipaddr, uip_lladdr_t *lladdr) UIP_LOG("CAN NOT BUIL INTERFACE IDENTIFIER"); UIP_LOG("THE STACK IS GOING TO SHUT DOWN"); UIP_LOG("THE HOST WILL BE UNREACHABLE"); - exit(-1); + //exit(-1); #endif } @@ -408,7 +408,7 @@ uip_netif_dad_failed(uip_ipaddr_t *ipaddr) dad_ns = 0; } - exit(-1); + //exit(-1); } diff --git a/core/net/uip.h b/core/net/uip.h index 2b22f76..eeccec9 100644 --- a/core/net/uip.h +++ b/core/net/uip.h @@ -64,7 +64,7 @@ typedef union uip_ip6addr_t { u8_t u8[16]; /* Initializer, must come first!!! */ u16_t u16[8]; -} uip_ip6addr_t; +} __attribute__ ((__packed__)) uip_ip6addr_t; typedef uip_ip6addr_t uip_ipaddr_t; #else /* UIP_CONF_IPV6 */ @@ -74,7 +74,7 @@ typedef union uip_ip4addr_t { #if 0 u32_t u32; #endif -} uip_ip4addr_t; +} __attribute__ ((__packed__)) uip_ip4addr_t; typedef uip_ip4addr_t uip_ipaddr_t; #endif /* UIP_CONF_IPV6 */ @@ -84,21 +84,21 @@ typedef uip_ip4addr_t uip_ipaddr_t; /** \brief 16 bit 802.15.4 address */ struct uip_802154_shortaddr { u8_t addr[2]; -}; +} __attribute__ ((__packed__)); /** \brief 64 bit 802.15.4 address */ struct uip_802154_longaddr { u8_t addr[8]; -}; +} __attribute__ ((__packed__)); /** \brief 802.11 address */ struct uip_80211_addr { u8_t addr[6]; -}; +} __attribute__ ((__packed__)); /** \brief 802.3 address */ struct uip_eth_addr { u8_t addr[6]; -}; +} __attribute__ ((__packed__)); #if UIP_CONF_LL_802154 /** \brief 802.15.4 address */ @@ -1566,6 +1566,8 @@ void uip_process(u8_t flag); #define UIP_STOPPED 16 +#define PACKED __attribute__ ((__packed__)) + /* The TCP and IP headers. */ struct uip_tcpip_hdr { #if UIP_CONF_IPV6 @@ -1600,7 +1602,7 @@ struct uip_tcpip_hdr { u16_t tcpchksum; u8_t urgp[2]; u8_t optdata[4]; -}; +} PACKED; /* The ICMP and IP headers. */ struct uip_icmpip_hdr { @@ -1632,7 +1634,7 @@ struct uip_icmpip_hdr { u16_t id, seqno; u8_t payload[1]; #endif /* !UIP_CONF_IPV6 */ -}; +} PACKED; /* The UDP and IP headers. */ @@ -1663,7 +1665,7 @@ struct uip_udpip_hdr { destport; u16_t udplen; u16_t udpchksum; -}; +} PACKED; /* * In IPv6 the length of the L3 headers before the transport header is @@ -1692,7 +1694,7 @@ struct uip_ip_hdr { u16_t ipchksum; uip_ipaddr_t srcipaddr, destipaddr; #endif /* UIP_CONF_IPV6 */ -}; +} PACKED; /* @@ -1719,19 +1721,19 @@ struct uip_ip_hdr { struct uip_ext_hdr { u8_t next; u8_t len; -}; +} PACKED; /* Hop by Hop option header */ struct uip_hbho_hdr { u8_t next; u8_t len; -}; +} PACKED; /* destination option header */ struct uip_desto_hdr { u8_t next; u8_t len; -}; +} PACKED; /* We do not define structures for PAD1 and PADN options */ @@ -1748,7 +1750,7 @@ struct uip_routing_hdr { u8_t len; u8_t routing_type; u8_t seg_left; -}; +} PACKED; /* fragmentation header */ struct uip_frag_hdr { @@ -1756,7 +1758,7 @@ struct uip_frag_hdr { u8_t res; u16_t offsetresmore; u32_t id; -}; +} PACKED; /* * an option within the destination or hop by hop option headers @@ -1765,13 +1767,13 @@ struct uip_frag_hdr { struct uip_ext_hdr_opt { u8_t type; u8_t len; -}; +} PACKED; /* PADN option */ struct uip_ext_hdr_opt_padn { u8_t opt_type; u8_t opt_len; -}; +} PACKED; /* TCP header */ struct uip_tcp_hdr { @@ -1785,7 +1787,7 @@ struct uip_tcp_hdr { u16_t tcpchksum; u8_t urgp[2]; u8_t optdata[4]; -}; +} PACKED; /* The ICMP headers. */ struct uip_icmp_hdr { @@ -1794,7 +1796,7 @@ struct uip_icmp_hdr { #if !UIP_CONF_IPV6 u16_t id, seqno; #endif /* !UIP_CONF_IPV6 */ -}; +} PACKED; /* The UDP headers. */ @@ -1803,7 +1805,7 @@ struct uip_udp_hdr { u16_t destport; u16_t udplen; u16_t udpchksum; -}; +} PACKED; /** diff --git a/core/net/uip6.c b/core/net/uip6.c index a40fd9a..a0cb0fb 100644 --- a/core/net/uip6.c +++ b/core/net/uip6.c @@ -404,7 +404,7 @@ uip_udpchksum(void) void uip_init(void) { - + printf("uip_init\n"); uip_netif_init(); uip_nd6_init(); @@ -1368,6 +1368,15 @@ uip_process(u8_t flag) connection is bound to a remote port. Finally, if the connection is bound to a remote IP address, the source IP address of the packet is checked. */ +printf("uip_udp_conn %x uip_udp_conn->lport %x UIP_UDP_BUF->destport %x uip_udp_conn->rport %x UIP_UDP_BUF->srcport %x\n", +uip_udp_conn, uip_udp_conn->lport, UIP_UDP_BUF->destport, uip_udp_conn->rport, UIP_UDP_BUF->srcport); +printf("uip_udp_conn->ripaddr "); + PRINT6ADDR(&uip_udp_conn->ripaddr); + PRINTF("\n"); +printf("UIP_IP_BUF->srcipaddr "); + PRINT6ADDR(&UIP_IP_BUF->srcipaddr); + PRINTF("\n"); + if(uip_udp_conn->lport != 0 && UIP_UDP_BUF->destport == uip_udp_conn->lport && (uip_udp_conn->rport == 0 || diff --git a/cpu/mc1322x/Makefile.mc1322x b/cpu/mc1322x/Makefile.mc1322x index 1014ca2..5cea107 100644 --- a/cpu/mc1322x/Makefile.mc1322x +++ b/cpu/mc1322x/Makefile.mc1322x @@ -37,7 +37,7 @@ LINKERSCRIPT = $(CONTIKI_CPU)/mc1322x.lds STARTUP=${addprefix $(OBJECTDIR)/,startup.o} -ARCH_FLAGS= -mcpu=arm7tdmi-s -mthumb-interwork -march=armv4t -mtune=arm7tdmi-s -DCONFIG_ARM -D__ARM__ +ARCH_FLAGS= -mcpu=arm7tdmi-s -mthumb-interwork -march=armv4t -mtune=arm7tdmi-s -DCONFIG_ARM -D__ARM__ -Wcast-align THUMB_FLAGS=-mthumb -mcallee-super-interworking ARM_FLAGS= @@ -50,7 +50,7 @@ CFLAGSNO = -I. -I$(CONTIKI)/core -I$(CONTIKI_CPU) -I$(CONTIKI_CPU)/loader \ -Werror $(ARCH_FLAGS) -g CFLAGS += $(CFLAGSNO) -Os -DRUN_AS_SYSTEM -DROM_RUN -fno-strict-aliasing -fno-common -ffixed-r8 -msoft-float -DTEXT_BASE=$(TEXT_BASE) -fno-builtin-printf -fno-builtin-sprintf -LDFLAGS += -T $(LINKERSCRIPT) -nostartfiles -static +LDFLAGS += -T $(LINKERSCRIPT) -nostartfiles -static -Wl,-Map=contiki-$(TARGET).map,-export-dynamic AFLAGS := $(AFLAGS_DEBUG) -D__ASSEMBLY__ $(CPPFLAGS) -gstabs CDEPFLAGS = $(CFLAGS) -D __MAKING_DEPS__ @@ -81,17 +81,20 @@ CUSTOM_RULE_C_TO_CO=yes %.co: %.c $(CC) $(CFLAGS) $(THUMB_FLAGS) $< -c -o $@ +.PRECIOUS: %.bin +.PRECIOUS: %.ihex -%.ihex: %.$(TARGET) +%.ihex: %.elf $(OBJCOPY) $^ -O ihex $@ -%.bin: %.$(TARGET) +%.bin: %.elf $(OBJCOPY) -O binary $< $@ symbols.c: @${CONTIKI}/tools/make-empty-symbols -%.$(TARGET): %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a $(STARTUP) $(OBJECTDIR)/symbols.o - $(CC) $(LDFLAGS) $(CFLAGS) -nostartfiles -o $@ $(filter-out %.a,$^) $(filter %.a,$^) $(filter %.a,$^) - +%.elf: %.co $(PROJECT_OBJECTFILES) contiki-$(TARGET).a $(STARTUP) $(OBJECTDIR)/symbols.o + $(CC) $(LDFLAGS) $(CFLAGS) -nostartfiles -o $@ $(filter-out %.a,$^) $(filter %.a,$^) $(filter %.a,$^) +%.$(TARGET): %.elf %.bin %.ihex + @ diff --git a/cpu/mc1322x/clock.c b/cpu/mc1322x/clock.c index dabbbe0..8001a45 100644 --- a/cpu/mc1322x/clock.c +++ b/cpu/mc1322x/clock.c @@ -89,3 +89,18 @@ clock_time(void) return current_clock; } +unsigned long +clock_seconds(void) +{ + return 0; +} + +int raise(void) +{ + return 0; +} + +void uip_log(char *msg) +{ + printf("uip: %s\n", msg); +} diff --git a/cpu/mc1322x/dbg-io.c b/cpu/mc1322x/dbg-io.c index 1fd90cb..ce91713 100644 --- a/cpu/mc1322x/dbg-io.c +++ b/cpu/mc1322x/dbg-io.c @@ -32,8 +32,3 @@ puts(const char *s) return i; } -int -__sp(struct _reent *_ptr, int c, FILE *_p) { - dbg_putchar(c); - return c; -} diff --git a/cpu/mc1322x/isr.c b/cpu/mc1322x/isr.c index 180fbd3..f43da6f 100644 --- a/cpu/mc1322x/isr.c +++ b/cpu/mc1322x/isr.c @@ -14,25 +14,33 @@ __attribute__ ((section (".irq"))) __attribute__ ((interrupt("IRQ"))) void irq(void) { - volatile uint32_t tmp; - if(tmr_irq()) { - /* dispatch to individual timer isrs if they exist */ - /* timer isrs are responsible for determining if they - * caused an interrupt */ - /* and clearing their own interrupt flags */ - if(tmr0_isr != 0) { tmr0_isr(); } - if(tmr1_isr != 0) { tmr1_isr(); } - if(tmr2_isr != 0) { tmr2_isr(); } - if(tmr3_isr != 0) { tmr3_isr(); } - } - if(crm_irq()) { - PRINTF("crm irq\n\r"); - if(rtc_wu_evt() && (rtc_isr != 0)) { rtc_isr(); } - if(kbi_evnt(4) && (kbi4_isr != 0)) { kbi4_isr(); } - if(kbi_evnt(5) && (kbi5_isr != 0)) { kbi5_isr(); } - if(kbi_evnt(6) && (kbi6_isr != 0)) { kbi6_isr(); } - if(kbi_evnt(7) && (kbi7_isr != 0)) { kbi7_isr(); } - } + int pending; + while (pending = reg32(NIPEND)) { + if(bit_is_set(pending, INT_NUM_TMR)) { + /* dispatch to individual timer isrs if they exist */ + /* timer isrs are responsible for determining if they + * caused an interrupt */ + /* and clearing their own interrupt flags */ + if(tmr0_isr != 0) { tmr0_isr(); } + if(tmr1_isr != 0) { tmr1_isr(); } + if(tmr2_isr != 0) { tmr2_isr(); } + if(tmr3_isr != 0) { tmr3_isr(); } + } + if(bit_is_set(pending, INT_NUM_MACA)) { + if(maca_isr != 0) { maca_isr(); } + } + if(bit_is_set(pending, INT_NUM_UART1)) { + if(uart1_isr != 0) { uart1_isr(); } + } + if(bit_is_set(pending, INT_NUM_CRM)) { + PRINTF("crm irq\n\r"); + if(rtc_wu_evt() && (rtc_isr != 0)) { rtc_isr(); } + if(kbi_evnt(4) && (kbi4_isr != 0)) { kbi4_isr(); } + if(kbi_evnt(5) && (kbi5_isr != 0)) { kbi5_isr(); } + if(kbi_evnt(6) && (kbi6_isr != 0)) { kbi6_isr(); } + if(kbi_evnt(7) && (kbi7_isr != 0)) { kbi7_isr(); } + } + } } diff --git a/cpu/mc1322x/isr.h b/cpu/mc1322x/isr.h index 2b4a157..1c6de7c 100644 --- a/cpu/mc1322x/isr.h +++ b/cpu/mc1322x/isr.h @@ -8,11 +8,17 @@ #define INTBASE (0x80020000) #define INTCNTL_OFF (0x0) #define INTENNUM_OFF (0x8) +#define INTDISNUM_OFF (0xC) +#define INTENABLE_OFF (0x10) #define INTSRC_OFF (0x30) +#define NIPEND_OFF (0x38) #define INTCNTL (INTBASE + INTCNTL_OFF) #define INTENNUM (INTBASE + INTENNUM_OFF) -#define INTSRC (INTBASE + INTSRC_OFF) +#define INTDISNUM (INTBASE + INTDISNUM_OFF) +#define INTENABLE (INTBASE + INTENABLE_OFF) +#define INTSRC (INTBASE + INTSRC_OFF) +#define NIPEND (INTBASE + NIPEND_OFF) enum interrupt_nums { INT_NUM_ASM = 0, @@ -32,18 +38,16 @@ enum interrupt_nums { #define global_irq_enable() (clear_bit(reg32(INTCNTL),20)) #define enable_irq(irq) (reg32(INTENNUM) = INT_NUM_##irq) +#define disable_irq(irq) (reg32(INTDISNUM) = INT_NUM_##irq) -#define tmr_irq() (bit_is_set(reg32(INTSRC),INT_NUM_TMR)) extern void tmr0_isr(void) __attribute__((weak)); extern void tmr1_isr(void) __attribute__((weak)); extern void tmr2_isr(void) __attribute__((weak)); extern void tmr3_isr(void) __attribute__((weak)); - extern void rtc_isr(void) __attribute__((weak)); - -#define crm_irq() (bit_is_set(reg32(INTSRC),INT_NUM_CRM)) - +extern void uart1_isr(void) __attribute__((weak)); +extern void maca_isr(void) __attribute__((weak)); #endif diff --git a/cpu/mc1322x/maca.c b/cpu/mc1322x/maca.c index a1628bf..3b3ebd3 100644 --- a/cpu/mc1322x/maca.c +++ b/cpu/mc1322x/maca.c @@ -4,6 +4,7 @@ /* contiki */ #include "radio.h" #include "sys/process.h" +#include "lib/list.h" /* mc1322x */ #include "maca.h" @@ -16,8 +17,23 @@ #define MAX_PACKET_SIZE 127 #endif +#define MACA_CLOCK_DIV 95 + +void ResumeMACASync(int x); +static process_event_t event_data_ready; + static volatile uint8_t tx_buf[MAX_PACKET_SIZE] __attribute__ ((aligned (4))); -static volatile uint8_t rx_buf[MAX_PACKET_SIZE] __attribute__ ((aligned (4))); + +#define NUM_RX_BUFS 10 +struct packet_t { + struct packet_t *next; + int length; + uint8_t data[MAX_PACKET_SIZE]; +}; +static struct packet_t rx_buf[NUM_RX_BUFS]; + +LIST(rx_empty); +LIST(rx_full); static volatile uint8_t maca_request_on = 0; static volatile uint8_t maca_request_off = 0; @@ -36,11 +52,11 @@ static volatile uint8_t maca_request_off = 0; #define MACA_RAW_PREPEND 0xff #endif -#define led_red_on() do { set_bit(reg32(GPIO_DATA0),8); set_bit(reg32(GPIO_DATA0),23); } while (0) -#define led_red_off() do { clear_bit(reg32(GPIO_DATA0),8); clear_bit(reg32(GPIO_DATA0),23); } while (0) +#define led_red_on() do { set_bit(reg32(GPIO_DATA0), 8); set_bit(reg32(GPIO_DATA0), 23); } while (0) +#define led_red_off() do { clear_bit(reg32(GPIO_DATA0), 8); clear_bit(reg32(GPIO_DATA0), 23); } while (0) -#define led_green_on() do { set_bit(reg32(GPIO_DATA0),9); set_bit(reg32(GPIO_DATA0),24); } while (0) -#define led_green_off() do { clear_bit(reg32(GPIO_DATA0),9); clear_bit(reg32(GPIO_DATA0),24); } while(0) +#define led_green_on() do { set_bit(reg32(GPIO_DATA0), 9); set_bit(reg32(GPIO_DATA0), 24); } while (0) +#define led_green_off() do { clear_bit(reg32(GPIO_DATA0), 9); clear_bit(reg32(GPIO_DATA0), 24); } while(0) /* contiki mac driver */ @@ -73,23 +89,88 @@ int maca_off_request(void) { return 1; } +#undef PRINTF +#define PRINTF(...) printf(__VA_ARGS__) +static void decode_status(int status) { + switch(status) + { + case maca_cc_aborted: + { + PRINTF("maca: aborted\n\r"); + ResumeMACASync(1); + break; + + } + case maca_cc_not_completed: + { +// PRINTF("maca: not completed\n\r"); + ResumeMACASync(2); + break; + + } + case maca_cc_timeout: + { + PRINTF("maca: timeout\n\r"); + ResumeMACASync(3); + break; + + } + case maca_cc_no_ack: + { + PRINTF("maca: no ack\n\r"); + ResumeMACASync(4); + break; + + } + case maca_cc_ext_timeout: + { +// PRINTF("maca: ext timeout\n\r"); + ResumeMACASync(5); + break; + + } + case maca_cc_ext_pnd_timeout: + { + PRINTF("maca: ext pnd timeout\n\r"); + ResumeMACASync(6); + break; + } + case maca_cc_success: + { + //PRINTF("maca: success\n\r"); + break; + } + default: + { + PRINTF("status: %x", status); + ResumeMACASync(7); + + } + } +} +#undef PRINTF +#define PRINTF(...) + +static int radio_on = 0; -int maca_on(void) { - PRINTF("maca on\n\r"); -#ifdef DISABLE_RECEPTION - PRINTF("reception is disabled\n\r"); -#endif /*DISABLE_RECEPTION*/ +int maca_on(void) +{ + if (radio_on == 0) { + printf("turning phy on\n\r"); - /* turn the radio regulators back on */ - reg32(CRM_VREG_CNTL) = reg32(CRM_VREG_CNTL) | 0x00000078; + /* turn the radio regulators back on */ + reg32(CRM_VREG_CNTL) = reg32(CRM_VREG_CNTL) | 0x00000078; - /* reinitialize the phy */ - init_phy(); + /* reinitialize the phy */ + init_phy(); + radio_on = 1; + } return 1; } -int maca_off(void) { +int maca_off(void) +{ PRINTF("waiting to turn maca off"); while((reg32(MACA_STATUS) & 0x0000ffff) == maca_cc_not_completed) { PRINTF("."); @@ -99,91 +180,138 @@ int maca_off(void) { reg32(CRM_VREG_CNTL) = reg32(CRM_VREG_CNTL) & (~0x00000078); /* hold the maca in reset */ - set_bit(reg32(MACA_RESET),maca_reset_rst); + set_bit(reg32(MACA_RESET), maca_reset_rst); + radio_on = 0; return 1; } +static int post_receive() { + struct packet_t *packet; + /* this sets the rxlen field */ + /* this is undocumented but very important */ + /* you will not receive anything without setting it */ + reg32(MACA_TXLEN) = (MAX_PACKET_SIZE << 16); + packet = list_head(rx_empty); + if (packet == NULL) + printf("### out of receive buffers #####\n"); + reg32(MACA_DMARX) = (uint32_t)&packet->data[0]; + /* with timeout */ + reg32(MACA_SFTCLK) = reg32(MACA_CLK) - 1; + reg32(MACA_TMREN) = (1 << maca_tmren_sft); + /* start the receive sequence */ + reg32(MACA_CONTROL) = ( (1 << maca_ctrl_asap) | + (1 << maca_ctrl_auto) | + (1 << maca_ctrl_prm) | + (maca_ctrl_seq_rx)); +} + /* it appears that the mc1332x radio cannot */ /* receive packets where the last three bits of the first byte */ /* is equal to 2 --- even in promiscuous mode */ int maca_read(void *buf, unsigned short bufsize) { - uint32_t i; + uint32_t i, offset; volatile uint32_t rx_size; - rx_size = reg32(MACA_GETRXLVL) - 4; - if(rx_size < bufsize) bufsize = rx_size; + struct packet_t *packet; + + packet = list_pop(rx_full); + if (!packet) + return 0; + + if(packet->length > bufsize) + packet->length = bufsize; + #if MACA_RAW_MODE - PRINTF("maca read: in raw mode bufsize 0x%0x \n\r",bufsize); - PRINTF("maca read: \n\r"); - for(i=2; i<=bufsize; i++) { - ((uint8_t *)buf)[i-2] = rx_buf[i]; -#else - PRINTF("maca read: bufsize 0x%0x \n\r",bufsize); - PRINTF("maca read: \n\r"); - for(i=1; i<=bufsize; i++) { - ((uint8_t *)buf)[i-1] = rx_buf[i]; + offset = 2; +#else + offset = 1; #endif - PRINTF(" %02x",rx_buf[i]); + //PRINTF("maca read size %d: ", packet->length); + for(i = offset; i <= packet->length; i++) { + ((uint8_t *)buf)[i - offset] = packet->data[i]; + //PRINTF(" %02x", packet->data[i]); } - PRINTF("\n\r"); - return bufsize; + //PRINTF("\n"); + + list_add(rx_empty, packet); + return packet->length; } +volatile int wait = 0; + int maca_send(const void *payload, unsigned short payload_len) { - volatile uint32_t i,j; + volatile uint32_t i, j; volatile uint32_t retry; volatile uint32_t len; + struct packet_t *packet; + int status; - maca_on(); len = payload_len; + maca_on(); + + while (wait != 0) {}; +// printf("*"); + /* wait for maca to finish what it's doing */ - while(status_is_not_completed()); + disable_irq(MACA); + + ResumeMACASync(1); + + /* why do I need this delay loop? */ + /* send fails if I remove it */ + for (j = 0; j < 5000; j++) {} + led_red_on(); - ResumeMACASync(); /* the mc1322x promiscuous mode doen't appear to be entirely promiscuous */ /* in MACA_RAW_MODE, all transmitted packets are prepended with MACA_RAW_PREPEND */ /* received packets get stripped of this */ /* i.e. it's "raw" with respect to the upper layers of RIME */ #if MACA_RAW_MODE - PRINTF("maca: in raw mode sending 0x%0x + %d bytes\n\r", MACA_RAW_PREPEND, payload_len); + PRINTF("maca: in raw mode sending 0x%0x + %d bytes\n", MACA_RAW_PREPEND, payload_len); tx_buf[0] = MACA_RAW_PREPEND; len++; - for(i=1; i<=payload_len; i++) { + for(i = 1; i <= payload_len; i++) { /* copy payload into tx buf */ - tx_buf[i] = ((uint8_t *)payload)[i-1]; - PRINTF(" %02x",((uint8_t *)payload)[i-1]); + tx_buf[i] = ((uint8_t *)payload)[i - 1]; + PRINTF(" %02x", ((uint8_t *)payload)[i - 1]); } #else - PRINTF("maca: sending %d bytes\n\r", payload_len); - for(i=0; idata[0]; reg32(MACA_TMREN) = 0; /* do the transmit */ - reg32(MACA_CONTROL) = ( (1<length = reg32(MACA_GETRXLVL) - 2; + list_add(rx_full, packet); + //printf("data ind %x %d\n", packet, packet->length); + } + if (filter_failed_irq()) { + printf("filter failed\n"); + ResumeMACASync(12); + reg32(MACA_CLRIRQ) = (1 << maca_irq_flt); + } + if (checksum_failed_irq()) { + printf("checksum failed\n"); + ResumeMACASync(13); + reg32(MACA_CLRIRQ) = (1 << maca_irq_crc); + } + if(action_complete_irq()) { + //printf("action comp %d\n", wait); + wait = 0; + reg32(MACA_CLRIRQ) = (1 << maca_irq_acpl); + status &= 0x0000ffff; + decode_status(status); + } + if (bit_is_set(status, maca_status_ovr)) + printf("ISR overrun\n"); + if (bit_is_set(status, maca_status_busy)) + printf("ISR busy\n"); + if (bit_is_set(status, maca_status_crc)) + printf("ISR crc\n"); + if (bit_is_set(status, maca_status_to)) + printf("ISR timeout\n"); + + i = reg32(MACA_IRQ); + if (i != 0) + printf("MACA IRQ %x\n", i); + + post_receive(); +} + PROCESS_THREAD(maca_process, ev, data) { volatile uint32_t i; @@ -203,136 +378,42 @@ PROCESS_THREAD(maca_process, ev, data) PROCESS_BEGIN(); - reg32(MACA_CONTROL) = ((1<>12); + reg32(RF_BASE + 8) = or; + reg32(RF_BASE + 12) = 0x00ffffff; + reg32(RF_BASE + 16) = (((uint32_t)0x00ffffff) >> 12); reg32(RF_BASE) = 16; /* good luck and godspeed */ } @@ -405,66 +483,82 @@ void flyback_init(void) { #define MAX_SEQ1 2 const uint32_t addr_seq1[MAX_SEQ1] = { - 0x80003048, + 0x80003048, 0x8000304c, }; const uint32_t data_seq1[MAX_SEQ1] = { - 0x00000f78, + 0x00000f78, 0x00607707, }; #define MAX_SEQ2 2 const uint32_t addr_seq2[MAX_SEQ2] = { - 0x8000a050, - 0x8000a054, + 0x8000a050, + 0x8000a054, }; const uint32_t data_seq2[MAX_SEQ2] = { 0x0000047b, - 0x0000007b, + 0x0000007b, }; #define MAX_CAL3_SEQ1 3 -const uint32_t addr_cal3_seq1[MAX_CAL3_SEQ1] = { 0x80009400,0x80009a04,0x80009a00, }; -const uint32_t data_cal3_seq1[MAX_CAL3_SEQ1] = {0x00020017,0x8185a0a4,0x8c900025, }; +const uint32_t addr_cal3_seq1[MAX_CAL3_SEQ1] = { 0x80009400, 0x80009a04, 0x80009a00, }; +const uint32_t data_cal3_seq1[MAX_CAL3_SEQ1] = {0x00020017, 0x8185a0a4, 0x8c900025, }; #define MAX_CAL3_SEQ2 2 -const uint32_t addr_cal3_seq2[MAX_CAL3_SEQ2] = { 0x80009a00,0x80009a00,}; -const uint32_t data_cal3_seq2[MAX_CAL3_SEQ2] = { 0x8c900021,0x8c900027,}; +const uint32_t addr_cal3_seq2[MAX_CAL3_SEQ2] = { 0x80009a00, 0x80009a00, }; +const uint32_t data_cal3_seq2[MAX_CAL3_SEQ2] = { 0x8c900021, 0x8c900027, }; #define MAX_CAL3_SEQ3 1 const uint32_t addr_cal3_seq3[MAX_CAL3_SEQ3] = { 0x80009a00 }; const uint32_t data_cal3_seq3[MAX_CAL3_SEQ3] = { 0x8c900000 }; #define MAX_CAL5 4 -const uint32_t addr_cal5[MAX_CAL5] = { - 0x80009400, - 0x8000a050, - 0x8000a054, +const uint32_t addr_cal5[MAX_CAL5] = { + 0x80009400, + 0x8000a050, + 0x8000a054, 0x80003048, }; const uint32_t data_cal5[MAX_CAL5] = { 0x00000017, - 0x00000000, + 0x00000000, 0x00000000, 0x00000f00, }; #define MAX_DATA 43 -const uint32_t addr_reg_rep[MAX_DATA] = { 0x80004118,0x80009204,0x80009208,0x8000920c,0x80009210,0x80009300,0x80009304,0x80009308,0x8000930c,0x80009310,0x80009314,0x80009318,0x80009380,0x80009384,0x80009388,0x8000938c,0x80009390,0x80009394,0x8000a008,0x8000a018,0x8000a01c,0x80009424,0x80009434,0x80009438,0x8000943c,0x80009440,0x80009444,0x80009448,0x8000944c,0x80009450,0x80009460,0x80009464,0x8000947c,0x800094e0,0x800094e4,0x800094e8,0x800094ec,0x800094f0,0x800094f4,0x800094f8,0x80009470,0x8000981c,0x80009828 }; - -const uint32_t data_reg_rep[MAX_DATA] = { 0x00180012,0x00000605,0x00000504,0x00001111,0x0fc40000,0x20046000,0x4005580c,0x40075801,0x4005d801,0x5a45d800,0x4a45d800,0x40044000,0x00106000,0x00083806,0x00093807,0x0009b804,0x000db800,0x00093802,0x00000015,0x00000002,0x0000000f,0x0000aaa0,0x01002020,0x016800fe,0x8e578248,0x000000dd,0x00000946,0x0000035a,0x00100010,0x00000515,0x00397feb,0x00180358,0x00000455,0x00000001,0x00020003,0x00040014,0x00240034,0x00440144,0x02440344,0x04440544,0x0ee7fc00,0x00000082,0x0000002a }; - +const uint32_t addr_reg_rep[MAX_DATA] = { 0x80004118, 0x80009204, 0x80009208, 0x8000920c, + 0x80009210, 0x80009300, 0x80009304, 0x80009308, 0x8000930c, 0x80009310, 0x80009314, + 0x80009318, 0x80009380, 0x80009384, 0x80009388, 0x8000938c, 0x80009390, 0x80009394, + 0x8000a008, 0x8000a018, 0x8000a01c, 0x80009424, 0x80009434, 0x80009438, 0x8000943c, + 0x80009440, 0x80009444, 0x80009448, 0x8000944c, 0x80009450, 0x80009460, 0x80009464, + 0x8000947c, 0x800094e0, 0x800094e4, 0x800094e8, 0x800094ec, 0x800094f0, 0x800094f4, + 0x800094f8, 0x80009470, 0x8000981c, 0x80009828 }; + +const uint32_t data_reg_rep[MAX_DATA] = { 0x00180012, 0x00000605, 0x00000504, 0x00001111, + 0x0fc40000, 0x20046000, 0x4005580c, 0x40075801, 0x4005d801, 0x5a45d800, 0x4a45d800, + 0x40044000, 0x00106000, 0x00083806, 0x00093807, 0x0009b804, 0x000db800, 0x00093802, + 0x00000015, 0x00000002, 0x0000000f, 0x0000aaa0, 0x01002020, 0x016800fe, 0x8e578248, + 0x000000dd, 0x00000946, 0x0000035a, 0x00100010, 0x00000515, 0x00397feb, 0x00180358, + 0x00000455, 0x00000001, 0x00020003, 0x00040014, 0x00240034, 0x00440144, 0x02440344, + 0x04440544, 0x0ee7fc00, 0x00000082, 0x0000002a }; /* has been tested and it good */ -void vreg_init(void) { +void vreg_init(void) +{ volatile uint32_t i; + reg32(0x80003000) = 0x00000018; /* set default state */ reg32(0x80003048) = 0x00000f04; /* bypass the buck */ - for(i=0; i<0x161a8; i++) { continue; } /* wait for the bypass to take */ -// while((((*(volatile uint32_t *)(0x80003018))>>17) & 1) !=1) { continue; } /* wait for the bypass to take */ + for(i = 0; i<0x161a8; i++) { continue; } /* wait for the bypass to take */ + + /* wait for the bypass to take */ +// while((((*(volatile uint32_t *)(0x80003018))>>17) & 1) !=1) { continue; } + reg32(0x80003048) = 0x00000ff8; /* start the regulators */ } @@ -474,7 +568,6 @@ void vreg_init(void) { #define _INIT_CTOV_WORD_2 0x023126e9 uint8_t get_ctov( uint32_t r0, uint32_t r1 ) { - r0 = r0 * _INIT_CTOV_WORD_1; r0 += ( r1 << 22 ); r0 += _INIT_CTOV_WORD_2; @@ -509,54 +602,57 @@ uint8_t ctov[16] = { void radio_init(void) { volatile uint32_t i; /* sequence 1 */ - for(i=0; i>17) & 1) !=1) { continue; } /* wait for the bypass to take */ + for(i = 0; i < 0x161a8; i++) { continue; } /* wait for the bypass to take */ + + /* wait for the bypass to take */ +// while((((*(volatile uint32_t *)(0x80003018))>>17) & 1) !=1) { continue; } + reg32(0x80003048) = 0x00000fa4; /* start the regulators */ - for(i=0; i<0x161a8; i++) { continue; } /* wait for the bypass to take */ + for(i = 0; i < 0x161a8; i++) { continue; } /* wait for the bypass to take */ init_from_flash(0x1F000); - PRINTF("radio_init: ctov parameter 0x%x\n\r",ram_values[3]); - for(i=0; i<16; i++) { - ctov[i] = get_ctov(i,ram_values[3]); - PRINTF("radio_init: ctov[%d] = 0x%x\n\r",i,ctov[i]); + PRINTF("radio_init: ctov parameter 0x%x\n\r", ram_values[3]); + for(i = 0; i < 16; i++) { + ctov[i] = get_ctov(i, ram_values[3]); + PRINTF("radio_init: ctov[%d] = 0x%x\n\r", i, ctov[i]); } } @@ -633,7 +729,7 @@ const uint32_t AIMVAL[19] = { #define ADDR_POW3 ADDR_POW1 + 64 void set_power(uint8_t power) { reg32(ADDR_POW1) = PSMVAL[power]; - reg32(ADDR_POW2) = (ADDR_POW1>>18) | PAVAL[power]; + reg32(ADDR_POW2) = (ADDR_POW1 >> 18) | PAVAL[power]; reg32(ADDR_POW3) = AIMVAL[power]; } @@ -672,15 +768,16 @@ const uint32_t VCODivF[16] = { 0x00b55555, 0x00eaaaaa, 0x01200000, - 0x01555555, + 0x01555555, }; /* tested good */ #define ADDR_CHAN1 0x80009800 -#define ADDR_CHAN2 (ADDR_CHAN1+12) -#define ADDR_CHAN3 (ADDR_CHAN1+16) -#define ADDR_CHAN4 (ADDR_CHAN1+48) -void set_channel(uint8_t chan) { +#define ADDR_CHAN2 (ADDR_CHAN1 + 12) +#define ADDR_CHAN3 (ADDR_CHAN1 + 16) +#define ADDR_CHAN4 (ADDR_CHAN1 + 48) +void set_channel(uint8_t chan) +{ volatile uint32_t tmp; tmp = reg32(ADDR_CHAN1); @@ -699,7 +796,7 @@ void set_channel(uint8_t chan) { reg32(ADDR_CHAN4) = tmp; tmp = tmp & 0xffffe0ff; - tmp = tmp | (((ctov[chan])<<8)&0x1F00); + tmp = tmp | (((ctov[chan]) << 8) & 0x1F00); reg32(ADDR_CHAN4) = tmp; /* duh! */ } @@ -708,13 +805,13 @@ void set_channel(uint8_t chan) { #define ENTRY_EOF 0x00000e0f /* processes up to 4 words of initialization entries */ /* returns the number of words processed */ -uint32_t exec_init_entry(volatile uint32_t *entries, uint8_t *valbuf) +uint32_t exec_init_entry(volatile uint32_t *entries, uint8_t *valbuf) { volatile uint32_t i; if(entries[0] <= ROM_END) { if (entries[0] == 0) { /* do delay command*/ - for(i=0; i= 16) && (entries[0] < 0xfff1)) { /* store bytes in valbuf */ - valbuf[(entries[0]>>4)-1] = entries[1]; + valbuf[(entries[0] >> 4) - 1] = entries[1]; return 2; } else if (entries[0] == ENTRY_EOF) { // puts("init_entry: eof "); @@ -732,7 +829,7 @@ uint32_t exec_init_entry(volatile uint32_t *entries, uint8_t *valbuf) /* invalid command code */ return 0; } - } else { /* address isn't in ROM space */ + } else { /* address isn't in ROM space */ /* do store value in address command */ reg32(entries[0]) = entries[1]; return 2; @@ -741,85 +838,88 @@ uint32_t exec_init_entry(volatile uint32_t *entries, uint8_t *valbuf) #define FLASH_INIT_MAGIC 0x00000abc -uint32_t init_from_flash(uint32_t addr) { - nvm_type_t type=0; +uint32_t init_from_flash(uint32_t addr) +{ + nvm_type_t type = 0; nvm_err_t err; volatile uint32_t buf[8]; volatile uint16_t len; - volatile uint32_t i=0,j; + volatile uint32_t i = 0, j; err = nvm_detect(NVM_INTERFACE_INTERNAL, &type); nvm_setsvar(0); err = nvm_read(NVM_INTERFACE_INTERNAL, type, (uint8_t *)buf, addr, 8); - i+=8; + i += 8; if(buf[0] == FLASH_INIT_MAGIC) { len = buf[1] & 0x0000ffff; - while(i> 8) << 2; - /* write "last warmdown data" to current TSM step to shutdown rx */ - LastWarmdownData = (*((volatile uint32_t *)(0x80009300 + LastWarmdownStep))); - (*((volatile uint32_t *)(0x80009300 + LastWarmupStep))) = LastWarmdownData; - - /* Abort */ - reg32(MACA_CONTROL) = maca_ctrl_seq_abort; - - /* Wait ~8us */ - for (clk = reg32(MACA_CLK), i = 0; reg32(MACA_CLK) - clk < 3 && i < 300; i++); - - /* NOP */ - reg32(MACA_CONTROL) = maca_ctrl_seq_nop; - - /* Wait ~8us */ - for (clk = reg32(MACA_CLK), i = 0; reg32(MACA_CLK) - clk < 3 && i < 300; i++); - +void ResumeMACASync(int x) +{ + uint32_t clk, TsmRxSteps, LastWarmupStep, LastWarmupData, LastWarmdownStep, LastWarmdownData; +// bool_t tmpIsrStatus; + volatile uint32_t i; + + //printf("RM %d\n", x); + +// ITC_DisableInterrupt(gMacaInt_c); +// AppInterrupts_ProtectFromMACAIrq(tmpIsrStatus); <- Original from MAC code, but not sure how is it implemented - /* restore original "last warmup step" data to TSM (VERY IMPORTANT!!!) */ - (*((volatile uint32_t *)(0x80009300 + LastWarmupStep))) = LastWarmupData; + /* Manual TSM modem shutdown */ - /* Clear all MACA interrupts - we should have gotten the ABORT IRQ */ - reg32(MACA_CLRIRQ) = 0xffff; + reg32(MACA_CLRIRQ) = 0xFFFF; - /* need to */ - /* renable interrupts if they were enabled */ + /* read TSM_RX_STEPS */ + TsmRxSteps = (*((volatile uint32_t *)(0x80009204))); + + /* isolate the RX_WU_STEPS */ + /* shift left to align with 32-bit addressing */ + LastWarmupStep = (TsmRxSteps & 0x1f) << 2; + /* Read "current" TSM step and save this value for later */ + LastWarmupData = (*((volatile uint32_t *)(0x80009300 + LastWarmupStep))); + + /* isolate the RX_WD_STEPS */ + /* right-shift bits down to bit 0 position */ + /* left-shift to align with 32-bit addressing */ + LastWarmdownStep = ((TsmRxSteps & 0x1f00) >> 8) << 2; + /* write "last warmdown data" to current TSM step to shutdown rx */ + LastWarmdownData = (*((volatile uint32_t *)(0x80009300 + LastWarmdownStep))); + (*((volatile uint32_t *)(0x80009300 + LastWarmupStep))) = LastWarmdownData; + + /* Abort */ + reg32(MACA_CONTROL) = maca_ctrl_seq_abort; + + /* Wait ~8us */ + for (clk = reg32(MACA_CLK), i = 0; reg32(MACA_CLK) - clk < 3 && i < 300; i++); + + /* NOP */ + reg32(MACA_CONTROL) = maca_ctrl_seq_nop; + + /* Wait ~8us */ + for (clk = reg32(MACA_CLK), i = 0; reg32(MACA_CLK) - clk < 3 && i < 300; i++); + + + /* restore original "last warmup step" data to TSM (VERY IMPORTANT!!!) */ + (*((volatile uint32_t *)(0x80009300 + LastWarmupStep))) = LastWarmupData; + + /* Clear all MACA interrupts - we should have gotten the ABORT IRQ */ + while (!action_complete_irq()) {}; + reg32(MACA_CLRIRQ) = (1 << maca_irq_acpl); + + /* need to */ + /* renable interrupts if they were enabled */ } -#if 0 -#endif + diff --git a/cpu/mc1322x/maca.h b/cpu/mc1322x/maca.h index 88d4d50..f65791b 100644 --- a/cpu/mc1322x/maca.h +++ b/cpu/mc1322x/maca.h @@ -153,7 +153,13 @@ enum maca_tmren_bits { maca_tmren_sft = 2, }; - +enum maca_status_bits { + maca_status_ovr = 12, + maca_status_busy = 13, + maca_status_crc = 14, + maca_status_to = 15, +}; + #define action_complete_irq() bit_is_set(reg32(MACA_IRQ),maca_irq_acpl) #define filter_failed_irq() bit_is_set(reg32(MACA_IRQ),maca_irq_flt) #define checksum_failed_irq() bit_is_set(reg32(MACA_IRQ),maca_irq_crc) @@ -165,7 +171,6 @@ enum maca_tmren_bits { void reset_maca(void); void init_phy(void); void vreg_init(void); -void ResumeMACASync(void); void radio_init(void); uint32_t init_from_flash(uint32_t addr); void set_power(uint8_t power); diff --git a/cpu/mc1322x/uart1.c b/cpu/mc1322x/uart1.c index 3400d35..421d0aa 100644 --- a/cpu/mc1322x/uart1.c +++ b/cpu/mc1322x/uart1.c @@ -2,6 +2,10 @@ #include "uart1.h" #include "utils.h" #include "gpio.h" +#include "isr.h" + +char tx_buf[1024]; +int head, tail; void uart1_init(void) { uint8_t i; @@ -23,11 +27,37 @@ void uart1_init(void) { reg32(UART1_CON) = 0x00000003; /* enable receive and transmit */ reg32(GPIO_FUNC_SEL0) = ( (0x01 << (14*2)) | (0x01 << (15*2)) ); /* set GPIO15-14 to UART (UART1 TX and RX)*/ + /* interrupt when 28 bytes are free */ + reg32(UT1CON) = 28; + + head = tail = 0; +} + +void uart1_isr(void) { + while( reg32(UT1CON) != 0 ) { + if (head == tail) { + disable_irq(UART1); + return; + } + reg32(UART1_DATA) = tx_buf[tail]; + tail++; + if (tail >= sizeof(tx_buf)) + tail = 0; + } + enable_irq(UART1); } int uart1_putchar(int c) { - while( reg32(UT1CON) == 31 ); - reg32(UART1_DATA) = c; + int h = head; + h = head + 1; + if (h >= sizeof(tx_buf)) + h = 0; + if (h == tail) /* drop chars when no room */ + return; + tx_buf[head] = c; + head = h; + + uart1_isr(); return c; } diff --git a/cpu/mc1322x/utils.h b/cpu/mc1322x/utils.h index f05a87a..33e43e4 100644 --- a/cpu/mc1322x/utils.h +++ b/cpu/mc1322x/utils.h @@ -8,9 +8,9 @@ #define reg32(x) (*(volatile uint32_t *)(x)) #define reg16(x) (*(volatile uint16_t *)(x)) -#define bit(bit) (1<> bit) == 1) -#define clear_bit(val,bit) (val=(val & ~(1<> bit) == 1) +#define clear_bit(val, bit) (val = (val & ~(1 << bit))) +#define set_bit(val, bit) (val = (val | (1 << bit))) #endif /* UTILS_H */ diff --git a/examples/ping-ipv6/example-ping6.c b/examples/ping-ipv6/example-ping6.c index a5dc227..1772926 100644 --- a/examples/ping-ipv6/example-ping6.c +++ b/examples/ping-ipv6/example-ping6.c @@ -29,5 +29,5 @@ #include "ping6.h" /*---------------------------------------------------------------------------*/ -AUTOSTART_PROCESSES(&ping6_process); +//AUTOSTART_PROCESSES(&ping6_process); /*---------------------------------------------------------------------------*/ diff --git a/examples/rime/Makefile b/examples/rime/Makefile index 6299334..efe75a6 100644 --- a/examples/rime/Makefile +++ b/examples/rime/Makefile @@ -1,7 +1,7 @@ CONTIKI = ../.. -ifndef TARGET -TARGET=netsim -endif + +DEFAULT_TARGET=netsim + all: example-abc example-mesh example-collect example-trickle example-polite \ example-rudolph0 example-rudolph1 example-rudolph2 example-rucb \ example-runicast example-unicast diff --git a/examples/udp-receiver-ipv6/Makefile.target b/examples/udp-receiver-ipv6/Makefile.target index 0d5d95e..6a38520 100644 --- a/examples/udp-receiver-ipv6/Makefile.target +++ b/examples/udp-receiver-ipv6/Makefile.target @@ -1 +1 @@ -TARGET = minimal-net +TARGET = mc1322x diff --git a/examples/udp-receiver-ipv6/example-udp-receiver.c b/examples/udp-receiver-ipv6/example-udp-receiver.c index 809d371..60f14df 100644 --- a/examples/udp-receiver-ipv6/example-udp-receiver.c +++ b/examples/udp-receiver-ipv6/example-udp-receiver.c @@ -85,11 +85,12 @@ PROCESS_THREAD(udp_process_receiver, ev, data) UDP_ADDR_A,UDP_ADDR_B,UDP_ADDR_C,UDP_ADDR_D, UDP_ADDR_E,UDP_ADDR_F,UDP_ADDR_G,UDP_ADDR_H); #else /* UDP_ADDR_A */ - uip_ip6addr(&ipaddr,0xFE80,0,0,0,0x2022,0x2222,0x2222,0x2222); + uip_ip6addr(&ipaddr,0xFE80,0,0,0,0x2,0x01ff,0xfe01,0x0101); #endif /* UDP_ADDR_A */ udpconn = udp_new(&ipaddr, HTONS(0xF0B0+1), NULL); udp_bind(udpconn, HTONS(0xF0B0)); +printf("updconn %x lport %x rport %x\n", udpconn, udpconn->lport, udpconn->rport); PRINTF("Created connection with remote peer "); PRINT6ADDR(&udpconn->ripaddr); diff --git a/examples/udp-sender-ipv6/Makefile.target b/examples/udp-sender-ipv6/Makefile.target index 0d5d95e..6a38520 100644 --- a/examples/udp-sender-ipv6/Makefile.target +++ b/examples/udp-sender-ipv6/Makefile.target @@ -1 +1 @@ -TARGET = minimal-net +TARGET = mc1322x diff --git a/examples/udp-sender-ipv6/example-udp-sender.c b/examples/udp-sender-ipv6/example-udp-sender.c index 80e997f..76da8cc 100644 --- a/examples/udp-sender-ipv6/example-udp-sender.c +++ b/examples/udp-sender-ipv6/example-udp-sender.c @@ -101,7 +101,7 @@ PROCESS_THREAD(udp_process_sender, ev, data) UDP_ADDR_A,UDP_ADDR_B,UDP_ADDR_C,UDP_ADDR_D, UDP_ADDR_E,UDP_ADDR_F,UDP_ADDR_G,UDP_ADDR_H); #else /* UDP_ADDR_A */ - uip_ip6addr(&ipaddr,0xfe80,0,0,0,0x6466,0x6666,0x6666,0x6666); + uip_ip6addr(&ipaddr,0xFE80,0,0,0,0x2,0x03ff,0xfe03,0x0303); #endif /* UDP_ADDR_A */ /* new connection with remote host */ diff --git a/examples/webserver-ipv6/Makefile.target b/examples/webserver-ipv6/Makefile.target index 0d5d95e..6a38520 100644 --- a/examples/webserver-ipv6/Makefile.target +++ b/examples/webserver-ipv6/Makefile.target @@ -1 +1 @@ -TARGET = minimal-net +TARGET = mc1322x diff --git a/examples/webserver-ipv6/webserver6.c b/examples/webserver-ipv6/webserver6.c index 240a1fb..cdd87e3 100644 --- a/examples/webserver-ipv6/webserver6.c +++ b/examples/webserver-ipv6/webserver6.c @@ -34,5 +34,5 @@ #include "webserver-nogui.h" /*---------------------------------------------------------------------------*/ -AUTOSTART_PROCESSES(&webserver_nogui_process); +//AUTOSTART_PROCESSES(&webserver_nogui_process); /*---------------------------------------------------------------------------*/ diff --git a/platform/mc1322x/contiki-conf.h b/platform/mc1322x/contiki-conf.h index 85f6d34..729ca50 100644 --- a/platform/mc1322x/contiki-conf.h +++ b/platform/mc1322x/contiki-conf.h @@ -79,9 +79,51 @@ typedef int32_t s32_t; #define QUEUEBUF_CONF_NUM 8 #define RIMEADDR_CONF_SIZE 8 -#define PACKETBUF_CONF_SIZE 96 #define PACKETBUF_CONF_HDR_SIZE 64 +/* 0 for IPv6, or 1 for HC1, 2 for HC01 */ +#define SICSLOWPAN_CONF_COMPRESSION_IPV6 0 +#define SICSLOWPAN_CONF_COMPRESSION_HC1 1 +#define SICSLOWPAN_CONF_COMPRESSION_HC01 2 + +#define SICSLOWPAN_CONF_COMPRESSION SICSLOWPAN_CONF_COMPRESSION_HC01 +#define SICSLOWPAN_CONF_MAX_ADDR_CONTEXTS 2 +#define SICSLOWPAN_CONF_FRAG 1 + +#define SICSLOWPAN_CONF_CONVENTIONAL_MAC 1 + +#define SICSLOWPAN_CONF_MAXAGE 5 + +#define UIP_CONF_LL_802154 1 +#define UIP_CONF_LLH_LEN 0 + +#define UIP_CONF_MAX_CONNECTIONS 2 +#define UIP_CONF_MAX_LISTENPORTS 2 +#define UIP_CONF_UDP_CONNS 2 + +#define UIP_CONF_IP_FORWARD 0 +#define UIP_CONF_FWCACHE_SIZE 0 + +#define UIP_CONF_IPV6 1 +#define UIP_CONF_IPV6_CHECKS 1 +#define UIP_CONF_IPV6_QUEUE_PKT 1 +#define UIP_CONF_IPV6_REASSEMBLY 0 +#define UIP_CONF_NETIF_MAX_ADDRESSES 3 +#define UIP_CONF_ND6_MAX_PREFIXES 3 +#define UIP_CONF_ND6_MAX_NEIGHBORS 4 +#define UIP_CONF_ND6_MAX_DEFROUTERS 2 +#define UIP_CONF_ICMP6 1 + +#define UIP_CONF_UDP 1 +#define UIP_CONF_UDP_CHECKSUMS 1 + +#define UIP_CONF_TCP 1 +#define UIP_CONF_TCP_SPLIT 1 + +#define UIP_CONF_LOGGING 1 + +#define WITH_UIP6 1 + typedef uint32_t clock_time_t; typedef unsigned char u8_t; typedef unsigned short u16_t; diff --git a/platform/mc1322x/contiki-mc1322x-main.c b/platform/mc1322x/contiki-mc1322x-main.c index fa5aabb..35bd233 100644 --- a/platform/mc1322x/contiki-mc1322x-main.c +++ b/platform/mc1322x/contiki-mc1322x-main.c @@ -32,6 +32,7 @@ */ #include +#include #include @@ -58,6 +59,17 @@ #include "nvm.h" #include "kbi.h" +#define DEBUG 1 +#if DEBUG +#include +#define PRINTF(...) printf(__VA_ARGS__) +#define PRINT6ADDR(addr) PRINTF(" %02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x ", ((u8_t *)addr)[0], ((u8_t *)addr)[1], ((u8_t *)addr)[2], ((u8_t *)addr)[3], ((u8_t *)addr)[4], ((u8_t *)addr)[5], ((u8_t *)addr)[6], ((u8_t *)addr)[7], ((u8_t *)addr)[8], ((u8_t *)addr)[9], ((u8_t *)addr)[10], ((u8_t *)addr)[11], ((u8_t *)addr)[12], ((u8_t *)addr)[13], ((u8_t *)addr)[14], ((u8_t *)addr)[15]) +#define PRINTLLADDR(lladdr) PRINTF(" %02x:%02x:%02x:%02x:%02x:%02x ",(lladdr)->addr[0], (lladdr)->addr[1], (lladdr)->addr[2], (lladdr)->addr[3],(lladdr)->addr[4], (lladdr)->addr[5]) +#else +#define PRINTF(...) +#define PRINT6ADDR(addr) +#define PRINTLLADDR(addr) +#endif #ifndef RIMEADDR_NVM #define RIMEADDR_NVM 0x1E000 @@ -74,6 +86,8 @@ #define PRINTF(...) #endif +#define RF_CHANNEL 24 + void init_lowlevel(void) { @@ -111,7 +125,7 @@ init_lowlevel(void) set_power(0x0f); /* 0dbm */ // set_power(0x0); - set_channel(0); /* channel 11 */ + set_channel(RF_CHANNEL - 11); /* Zero is channel 11 */ #if USE_32KHZ_XTAL enable_32khz_xtal(); @@ -187,7 +201,7 @@ main(void) // rime_init(nullmac_init(&maca_driver)); // rime_init(xmac_init(&maca_driver)); // rime_init(lpp_init(&maca_driver)); - rime_init(sicslowmac_init(&maca_driver)); +// rime_init(sicslowmac_init(&maca_driver)); #if !(USE_32KHZ_XTAL) PRINTF("setting xmac to use calibrated rtc value\n"); @@ -210,16 +224,76 @@ main(void) } printf("%d\n", addr.u8[i]); - /* Autostart processes */ - autostart_start(autostart_processes); - //Give ourselves a prefix //init_net(); printf("\n\r********BOOTING CONTIKI*********\n\r"); +#if WITH_UIP6 + memcpy(&uip_lladdr.addr, &addr.u8, 8); + sicslowpan_init(sicslowmac_init(&maca_driver)); + process_start(&tcpip_process, NULL); + printf(" %s channel %u\n", sicslowmac_driver.name, RF_CHANNEL); +#if UIP_CONF_ROUTER + rime_init(rime_udp_init(NULL)); + uip_router_register(&rimeroute); +#endif /* UIP_CONF_ROUTER */ +#else /* WITH_UIP6 */ +#if WITH_NULLMAC + rime_init(nullmac_init(&maca_driver)); +#else /* WITH_NULLMAC */ + rime_init(xmac_init(&maca_driver)); +#endif /* WITH_NULLMAC */ + printf(" %s channel %u\n", rime_mac->name, RF_CHANNEL); +#endif /* WITH_UIP6 */ + +#if PROFILE_CONF_ON + profile_init(); +#endif /* PROFILE_CONF_ON */ + +#if TIMESYNCH_CONF_ENABLED + timesynch_init(); + timesynch_set_authority_level(rimeaddr_node_addr.u8[0]); +#endif /* TIMESYNCH_CONF_ENABLED */ + +#if WITH_UIP + process_start(&tcpip_process, NULL); + //process_start(&uip_fw_process, NULL); /* Start IP output */ + //process_start(&slip_process, NULL); + + //slip_set_input_callback(set_gateway); + +// { +// uip_ipaddr_t hostaddr, netmask; + +// uip_init(); + +// uip_ipaddr(&hostaddr, 172,16, +// rimeaddr_node_addr.u8[0],rimeaddr_node_addr.u8[1]); +// uip_ipaddr(&netmask, 255,255,0,0); + //uip_ipaddr_copy(&meshif.ipaddr, &hostaddr); + + //uip_sethostaddr(&hostaddr); + //uip_setnetmask(&netmask); + //uip_over_mesh_set_net(&hostaddr, &netmask); + /* uip_fw_register(&slipif);*/ + //uip_over_mesh_set_gateway_netif(&slipif); + //uip_fw_default(&meshif); + //uip_over_mesh_init(UIP_OVER_MESH_CHANNEL); +// printf("uIP started with IP address %d.%d.%d.%d\n", +// uip_ipaddr_to_quad(&hostaddr)); +// } +#endif /* WITH_UIP */ + + PRINTF("Local IPv6 address: "); + PRINT6ADDR(&uip_netif_physical_if.addresses[0].ipaddr); + PRINTF("\n"); + printf("System online.\n\r"); + /* Autostart processes */ + autostart_start(autostart_processes); + /* Main scheduler loop */ while(1) { process_run(); diff --git a/platform/mc1322x/printf-arch.c b/platform/mc1322x/printf-arch.c index 9ca6958..dd7596b 100644 --- a/platform/mc1322x/printf-arch.c +++ b/platform/mc1322x/printf-arch.c @@ -366,8 +366,9 @@ out: return pc; } + +#define BLOCK_MEM_SIZE 1024 -/* int sprintf( char *out, const char *format, ... ) { int retval = 0; @@ -383,7 +384,6 @@ int sprintf( char *out, const char *format, ... ) return retval; } -*/ static uint8_t ll;