Trond Enger / d7a_1x

Fork of d7a_1x by WizziLab

include/d7a_modem.h

Committer:
Jeej
Date:
2016-08-30
Revision:
43:28202405094d
Parent:
34:1311cc53201a
Child:
45:b85384e7d825

File content as of revision 43:28202405094d:

#ifndef _D7A_MODEM_H_
#define _D7A_MODEM_H_


enum {
    WM_ERR_COM_LINK=10,
    WM_ERR_NOT_READY,
};
// Msg/Cmd exchanged on CMD FLOW ID
enum {
    WM_READY,
};



//======================================================================
// MODEM commands over COM port
//======================================================================
typedef enum
{
    /// Soft-reset Modem Device
    /// ARGS: none
    WM_CMD_RST                      = 0x01,
    /// Start D7A communication stack
    /// ARGS: none TODO: pass number of fifos ?
    WM_CMD_D7A_STACK_START          = 0x02,
    /// Stop D7A communication stack
    /// ARGS: none
    WM_CMD_D7A_STACK_STOP           = 0x03,
    /// Register a File for notification
    /// ARGS: register_file_param_t
    WM_CMD_REGISTER_FILE            = 0x04,
    /// Notify a (previously registered) file
    /// ARGS: notify_file_param_t
    WM_CMD_NOTIFY_FILE              = 0x05,
    WM_CMD_CREATE_FILE              = 0x06,
    WM_CMD_DECLARE_FILE             = 0x07,
    WM_CMD_START_STACK              = 0x08,
    WM_CMD_STOP_STACK               = 0x09,

    /// Send by the Modem Device after a command has been executed/taken
    /// into account, and the Modem is ready to handle a new command.
    /// Can be used as a command that will be instantly answered with WM_CMD_READY
    /// ARGS: none
    WM_CMD_READY                    = 0x80,

    /// Send by the Modem Device after a (re)boot.
    /// ARGS: boot_status_t
    WM_CMD_BOOT                     = 0x81,

} wm_cmd_t;

typedef union {
    uint32_t w;
    struct {
        uint32_t cause          : 8;
        uint32_t rfu            : 8;
        uint32_t nb_boot        :16;
    } bf;
} boot_status_t;

typedef struct {
    union {
        uint8_t      b[8];
        uint32_t     w[2];
    } uid;
    uint8_t calib;
} wm_status_t;


typedef struct {
    uint8_t  fid;
    uint8_t  type;
    uint8_t  afid;
    uint8_t  ifid;
    uint8_t  prop;
    uint8_t  perm;
    uint32_t size;
    uint32_t alloc;
} register_file_param_t;

void d7a_modem_open(PinName reset_pin = NC);
void d7a_modem_reset(void);
bool d7a_modem_wait_ready(uint32_t millisec = osWaitForever);
void d7a_modem_new_pkt(d7a_com_rx_msg_t* pkt);
d7a_com_rx_msg_t* d7a_modem_wait_pkt(uint32_t millisec = osWaitForever);
void d7a_modem_msg(uint8_t value, uint8_t* buf, uint8_t len);
bool d7a_modem_register(register_file_param_t* file_infos);
bool d7a_modem_start(void);
bool d7a_modem_stop(void);
void d7a_modem_print_infos(void);


#endif