Ethernet test for ECE 4180 and others to find your IP address and do a simple HTTP GET request over port 80.

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Committer:
mkersh3
Date:
Thu Apr 04 05:26:09 2013 +0000
Revision:
0:e7ca326e76ee
Ethernet Test for ECE4180 and others to find their IP Address and do a simple HTTP GET request over port 80.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mkersh3 0:e7ca326e76ee 1 /* Copyright (c) 2012 mbed.org */
mkersh3 0:e7ca326e76ee 2 #ifndef MAIL_H
mkersh3 0:e7ca326e76ee 3 #define MAIL_H
mkersh3 0:e7ca326e76ee 4
mkersh3 0:e7ca326e76ee 5 #include <stdint.h>
mkersh3 0:e7ca326e76ee 6 #include <string.h>
mkersh3 0:e7ca326e76ee 7
mkersh3 0:e7ca326e76ee 8 #include "cmsis_os.h"
mkersh3 0:e7ca326e76ee 9
mkersh3 0:e7ca326e76ee 10 namespace rtos {
mkersh3 0:e7ca326e76ee 11
mkersh3 0:e7ca326e76ee 12 /*! The Mail class allow to control, send, receive, or wait for mail.
mkersh3 0:e7ca326e76ee 13 A mail is a memory block that is send to a thread or interrupt service routine.
mkersh3 0:e7ca326e76ee 14 \tparam T data type of a single message element.
mkersh3 0:e7ca326e76ee 15 \tparam queue_sz maximum number of messages in queue.
mkersh3 0:e7ca326e76ee 16 */
mkersh3 0:e7ca326e76ee 17 template<typename T, uint32_t queue_sz>
mkersh3 0:e7ca326e76ee 18 class Mail {
mkersh3 0:e7ca326e76ee 19 public:
mkersh3 0:e7ca326e76ee 20 /*! Create and Initialise Mail queue. */
mkersh3 0:e7ca326e76ee 21 Mail() {
mkersh3 0:e7ca326e76ee 22 #ifdef CMSIS_OS_RTX
mkersh3 0:e7ca326e76ee 23 memset(_mail_q, 0, sizeof(_mail_q));
mkersh3 0:e7ca326e76ee 24 _mail_p[0] = _mail_q;
mkersh3 0:e7ca326e76ee 25
mkersh3 0:e7ca326e76ee 26 memset(_mail_m, 0, sizeof(_mail_m));
mkersh3 0:e7ca326e76ee 27 _mail_p[1] = _mail_m;
mkersh3 0:e7ca326e76ee 28
mkersh3 0:e7ca326e76ee 29 _mail_def.pool = _mail_p;
mkersh3 0:e7ca326e76ee 30 _mail_def.queue_sz = queue_sz;
mkersh3 0:e7ca326e76ee 31 _mail_def.item_sz = sizeof(T);
mkersh3 0:e7ca326e76ee 32 #endif
mkersh3 0:e7ca326e76ee 33 _mail_id = osMailCreate(&_mail_def, NULL);
mkersh3 0:e7ca326e76ee 34 }
mkersh3 0:e7ca326e76ee 35
mkersh3 0:e7ca326e76ee 36 /*! Allocate a memory block of type T
mkersh3 0:e7ca326e76ee 37 \param millisec timeout value or 0 in case of no time-out. (default: 0).
mkersh3 0:e7ca326e76ee 38 \return pointer to memory block that can be filled with mail or NULL in case error.
mkersh3 0:e7ca326e76ee 39 */
mkersh3 0:e7ca326e76ee 40 T* alloc(uint32_t millisec=0) {
mkersh3 0:e7ca326e76ee 41 return (T*)osMailAlloc(_mail_id, millisec);
mkersh3 0:e7ca326e76ee 42 }
mkersh3 0:e7ca326e76ee 43
mkersh3 0:e7ca326e76ee 44 /*! Allocate a memory block of type T and set memory block to zero.
mkersh3 0:e7ca326e76ee 45 \param millisec timeout value or 0 in case of no time-out. (default: 0).
mkersh3 0:e7ca326e76ee 46 \return pointer to memory block that can be filled with mail or NULL in case error.
mkersh3 0:e7ca326e76ee 47 */
mkersh3 0:e7ca326e76ee 48 T* calloc(uint32_t millisec=0) {
mkersh3 0:e7ca326e76ee 49 return (T*)osMailCAlloc(_mail_id, millisec);
mkersh3 0:e7ca326e76ee 50 }
mkersh3 0:e7ca326e76ee 51
mkersh3 0:e7ca326e76ee 52 /*! Put a mail in the queue.
mkersh3 0:e7ca326e76ee 53 \param mptr memory block previously allocated with Mail::alloc or Mail::calloc.
mkersh3 0:e7ca326e76ee 54 \return status code that indicates the execution status of the function.
mkersh3 0:e7ca326e76ee 55 */
mkersh3 0:e7ca326e76ee 56 osStatus put(T *mptr) {
mkersh3 0:e7ca326e76ee 57 return osMailPut(_mail_id, (void*)mptr);
mkersh3 0:e7ca326e76ee 58 }
mkersh3 0:e7ca326e76ee 59
mkersh3 0:e7ca326e76ee 60 /*! Get a mail from a queue.
mkersh3 0:e7ca326e76ee 61 \param millisec timeout value or 0 in case of no time-out. (default: osWaitForever).
mkersh3 0:e7ca326e76ee 62 \return event that contains mail information or error code.
mkersh3 0:e7ca326e76ee 63 */
mkersh3 0:e7ca326e76ee 64 osEvent get(uint32_t millisec=osWaitForever) {
mkersh3 0:e7ca326e76ee 65 return osMailGet(_mail_id, millisec);
mkersh3 0:e7ca326e76ee 66 }
mkersh3 0:e7ca326e76ee 67
mkersh3 0:e7ca326e76ee 68 /*! Free a memory block from a mail.
mkersh3 0:e7ca326e76ee 69 \param mptr pointer to the memory block that was obtained with Mail::get.
mkersh3 0:e7ca326e76ee 70 \return status code that indicates the execution status of the function.
mkersh3 0:e7ca326e76ee 71 */
mkersh3 0:e7ca326e76ee 72 osStatus free(T *mptr) {
mkersh3 0:e7ca326e76ee 73 return osMailFree(_mail_id, (void*)mptr);
mkersh3 0:e7ca326e76ee 74 }
mkersh3 0:e7ca326e76ee 75
mkersh3 0:e7ca326e76ee 76 private:
mkersh3 0:e7ca326e76ee 77 osMailQId _mail_id;
mkersh3 0:e7ca326e76ee 78 osMailQDef_t _mail_def;
mkersh3 0:e7ca326e76ee 79 #ifdef CMSIS_OS_RTX
mkersh3 0:e7ca326e76ee 80 uint32_t _mail_q[4+(queue_sz)];
mkersh3 0:e7ca326e76ee 81 uint32_t _mail_m[3+((sizeof(T)+3)/4)*(queue_sz)];
mkersh3 0:e7ca326e76ee 82 void *_mail_p[2];
mkersh3 0:e7ca326e76ee 83 #endif
mkersh3 0:e7ca326e76ee 84 };
mkersh3 0:e7ca326e76ee 85
mkersh3 0:e7ca326e76ee 86 }
mkersh3 0:e7ca326e76ee 87
mkersh3 0:e7ca326e76ee 88 #endif
mkersh3 0:e7ca326e76ee 89