Trond Enger / d7a_1x

Fork of d7a_1x by WizziLab

Committer:
Jeej
Date:
Tue Aug 30 16:59:12 2016 +0000
Revision:
43:28202405094d
Child:
45:b85384e7d825
New version of the API.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jeej 43:28202405094d 1 #include "mbed.h"
Jeej 43:28202405094d 2 #include "rtos.h"
Jeej 43:28202405094d 3 #include "dbg.h"
Jeej 43:28202405094d 4 #include "d7a.h"
Jeej 43:28202405094d 5 #include "d7a_com.h"
Jeej 43:28202405094d 6 #include "d7a_common.h"
Jeej 43:28202405094d 7 #include "d7a_fs.h"
Jeej 43:28202405094d 8 #include "d7a_modem.h"
Jeej 43:28202405094d 9 #include "d7a_sys.h"
Jeej 43:28202405094d 10 #include "d7a_alp.h"
Jeej 43:28202405094d 11
Jeej 43:28202405094d 12
Jeej 43:28202405094d 13 //======================================================================
Jeej 43:28202405094d 14 // d7a_open
Jeej 43:28202405094d 15 //----------------------------------------------------------------------
Jeej 43:28202405094d 16 /// @brief Open D7A driver and start the modem
Jeej 43:28202405094d 17 /// @param d7a_com_config_t* Com port configuration structure
Jeej 43:28202405094d 18 /// @param PinName Reset pin
Jeej 43:28202405094d 19 /// @param d7a_fs_callbacks_t* File system callbacks (You declare files if this is not specified)
Jeej 43:28202405094d 20 //======================================================================
Jeej 43:28202405094d 21 void d7a_open(const d7a_com_config_t* com_config, PinName reset_pin, const d7a_fs_callbacks_t* fs_callbacks)
Jeej 43:28202405094d 22 {
Jeej 43:28202405094d 23 d7a_com_open(com_config);
Jeej 43:28202405094d 24 d7a_sys_open();
Jeej 43:28202405094d 25 d7a_fs_open(fs_callbacks);
Jeej 43:28202405094d 26 d7a_modem_open(reset_pin);
Jeej 43:28202405094d 27 }
Jeej 43:28202405094d 28
Jeej 43:28202405094d 29 //======================================================================
Jeej 43:28202405094d 30 // d7a_close
Jeej 43:28202405094d 31 //----------------------------------------------------------------------
Jeej 43:28202405094d 32 /// @brief Close D7A driver and stop the modem
Jeej 43:28202405094d 33 //======================================================================
Jeej 43:28202405094d 34 void d7a_close(void)
Jeej 43:28202405094d 35 {
Jeej 43:28202405094d 36 // TODO
Jeej 43:28202405094d 37 //d7a_modem_close();
Jeej 43:28202405094d 38 //d7a_fs_close();
Jeej 43:28202405094d 39 //d7a_sys_close();
Jeej 43:28202405094d 40 d7a_com_close();
Jeej 43:28202405094d 41 }
Jeej 43:28202405094d 42
Jeej 43:28202405094d 43
Jeej 43:28202405094d 44 //======================================================================
Jeej 43:28202405094d 45 // d7a_start
Jeej 43:28202405094d 46 //----------------------------------------------------------------------
Jeej 43:28202405094d 47 /// @brief Start the modem
Jeej 43:28202405094d 48 /// @return bool true if error
Jeej 43:28202405094d 49 //======================================================================
Jeej 43:28202405094d 50 bool d7a_start(void)
Jeej 43:28202405094d 51 {
Jeej 43:28202405094d 52 return d7a_modem_start();
Jeej 43:28202405094d 53 }
Jeej 43:28202405094d 54
Jeej 43:28202405094d 55 //======================================================================
Jeej 43:28202405094d 56 // d7a_stop
Jeej 43:28202405094d 57 //----------------------------------------------------------------------
Jeej 43:28202405094d 58 /// @brief Stop the modem (goes to low power)
Jeej 43:28202405094d 59 /// @return bool true if error
Jeej 43:28202405094d 60 //======================================================================
Jeej 43:28202405094d 61 bool d7a_stop(void)
Jeej 43:28202405094d 62 {
Jeej 43:28202405094d 63 return d7a_modem_stop();
Jeej 43:28202405094d 64 }
Jeej 43:28202405094d 65
Jeej 43:28202405094d 66 //======================================================================
Jeej 43:28202405094d 67 // d7a_create
Jeej 43:28202405094d 68 //----------------------------------------------------------------------
Jeej 43:28202405094d 69 /// @brief Creates a file on the modem
Jeej 43:28202405094d 70 /// @param d7a_fs_storage_t Type of file
Jeej 43:28202405094d 71 /// @param d7a_fs_perm_t Access permissions
Jeej 43:28202405094d 72 /// @param uint32_t Length of the created file
Jeej 43:28202405094d 73 /// @param uint32_t Maximum size of the file
Jeej 43:28202405094d 74 /// @param uint8_t File ID to an eventual Action file
Jeej 43:28202405094d 75 /// @param uint8_t File ID to an eventual Interface file
Jeej 43:28202405094d 76 /// @return bool true if error
Jeej 43:28202405094d 77 //======================================================================
Jeej 43:28202405094d 78 bool d7a_create(const uint8_t file_id, d7a_fs_storage_t prop, d7a_fs_perm_t perm, uint32_t size, uint32_t alloc, uint8_t action_file, uint8_t interface)
Jeej 43:28202405094d 79 {
Jeej 43:28202405094d 80 register_file_param_t file_infos = {
Jeej 43:28202405094d 81 .fid = file_id,
Jeej 43:28202405094d 82 .type = UNKNOWN,
Jeej 43:28202405094d 83 .afid = action_file,
Jeej 43:28202405094d 84 .ifid = interface,
Jeej 43:28202405094d 85 .prop = (uint8_t)prop,
Jeej 43:28202405094d 86 .perm = (uint8_t)perm,
Jeej 43:28202405094d 87 .size = size,
Jeej 43:28202405094d 88 .alloc = alloc,
Jeej 43:28202405094d 89 };
Jeej 43:28202405094d 90
Jeej 43:28202405094d 91 return d7a_modem_register(&file_infos);
Jeej 43:28202405094d 92 }
Jeej 43:28202405094d 93
Jeej 43:28202405094d 94 //======================================================================
Jeej 43:28202405094d 95 // d7a_declare
Jeej 43:28202405094d 96 //----------------------------------------------------------------------
Jeej 43:28202405094d 97 /// @brief Declare a file stocked on the host to the modem (need to have implemented the fs_callbacks)
Jeej 43:28202405094d 98 /// @param uint8_t File ID of file to declare
Jeej 43:28202405094d 99 /// @param d7a_fs_storage_t Type of file
Jeej 43:28202405094d 100 /// @param d7a_fs_perm_t Access permissions
Jeej 43:28202405094d 101 /// @param uint32_t Length of the created file
Jeej 43:28202405094d 102 /// @param uint32_t Maximum size of the file
Jeej 43:28202405094d 103 /// @param uint8_t File ID to an eventual Action file
Jeej 43:28202405094d 104 /// @param uint8_t File ID to an eventual Interface file
Jeej 43:28202405094d 105 /// @return bool true if error
Jeej 43:28202405094d 106 //======================================================================
Jeej 43:28202405094d 107 bool d7a_declare(const uint8_t file_id, d7a_fs_storage_t prop, d7a_fs_perm_t perm, uint32_t length, uint32_t alloc, uint8_t action_file, uint8_t interface)
Jeej 43:28202405094d 108 {
Jeej 43:28202405094d 109 register_file_param_t file_infos = {
Jeej 43:28202405094d 110 .fid = file_id,
Jeej 43:28202405094d 111 .type = HOST+UNKNOWN,
Jeej 43:28202405094d 112 .afid = action_file,
Jeej 43:28202405094d 113 .ifid = interface,
Jeej 43:28202405094d 114 .prop = (uint8_t)prop,
Jeej 43:28202405094d 115 .perm = (uint8_t)perm,
Jeej 43:28202405094d 116 .size = length,
Jeej 43:28202405094d 117 .alloc = alloc,
Jeej 43:28202405094d 118 };
Jeej 43:28202405094d 119
Jeej 43:28202405094d 120 return d7a_modem_register(&file_infos);
Jeej 43:28202405094d 121 }
Jeej 43:28202405094d 122
Jeej 43:28202405094d 123 //======================================================================
Jeej 43:28202405094d 124 // d7a_read
Jeej 43:28202405094d 125 //----------------------------------------------------------------------
Jeej 43:28202405094d 126 /// @brief Read data from a file
Jeej 43:28202405094d 127 /// @param uint8_t File ID of file to read
Jeej 43:28202405094d 128 /// @param uint32_t Offset from which to start reading
Jeej 43:28202405094d 129 /// @param uint32_t Size of data to read
Jeej 43:28202405094d 130 /// @param uint8_t* Buffer to retrieve data
Jeej 43:28202405094d 131 /// @param uint8_t Retry policy
Jeej 43:28202405094d 132 /// @return bool true if error
Jeej 43:28202405094d 133 //======================================================================
Jeej 43:28202405094d 134 bool d7a_read(const uint8_t file_id, const uint32_t offset, const uint32_t size, const uint8_t* buf, d7a_addressee_t* addressee, uint8_t retry)
Jeej 43:28202405094d 135 {
Jeej 43:28202405094d 136 return (d7a_alp_read_file(file_id, offset, size, buf, addressee, retry) == 0)? false : true;
Jeej 43:28202405094d 137 }
Jeej 43:28202405094d 138
Jeej 43:28202405094d 139 //======================================================================
Jeej 43:28202405094d 140 // d7a_write
Jeej 43:28202405094d 141 //----------------------------------------------------------------------
Jeej 43:28202405094d 142 /// @brief Write data to a file
Jeej 43:28202405094d 143 /// @param uint8_t File ID of file to write
Jeej 43:28202405094d 144 /// @param uint32_t Offset from which to start writing
Jeej 43:28202405094d 145 /// @param uint32_t Size of data to write
Jeej 43:28202405094d 146 /// @param uint8_t* Buffer of the data to write
Jeej 43:28202405094d 147 /// @return bool true if error
Jeej 43:28202405094d 148 //======================================================================
Jeej 43:28202405094d 149 bool d7a_write(const uint8_t file_id, const uint32_t offset, const uint32_t size, const uint8_t* const buf, d7a_addressee_t* addressee, uint8_t retry, bool resp)
Jeej 43:28202405094d 150 {
Jeej 43:28202405094d 151 return (d7a_alp_write_file(file_id, offset, size, buf, addressee, retry, resp) == 0)? false : true;
Jeej 43:28202405094d 152 }